Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't rename imported Main module that only imports names #3710

Merged
merged 5 commits into from
Sep 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@
representation, every atom has a type][3671]
- [main = "Hello World!" is valid Enso sample][3696]
- [Invalidate module's IR cache if imported module changed][3703]
- [Don't rename imported Main module that only imports names][3710]

[3227]: https://github.com/enso-org/enso/pull/3227
[3248]: https://github.com/enso-org/enso/pull/3248
Expand Down Expand Up @@ -401,6 +402,7 @@
[3671]: https://github.com/enso-org/enso/pull/3671
[3696]: https://github.com/enso-org/enso/pull/3696
[3696]: https://github.com/enso-org/enso/pull/3703
[3696]: https://github.com/enso-org/enso/pull/3710

# Enso 2.0.0-alpha.18 (2021-10-12)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all
import Standard.Base

import Standard.Base.Data.Json.Internal

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all hiding Number, Boolean, Array
import Standard.Base

import Standard.Base.Data.Numbers as Base_Number
import Standard.Base.Runtime.Ref
Expand Down
1 change: 1 addition & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all
import Standard.Base

## UNSTABLE
ADVANCED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ recover_errors ~body =
Returns all the columns in the table, including indices.

Index columns are placed before other columns.
Table.Table.all_columns : Vector
Table.Table.all_columns self =
Table.all_columns : Vector
Table.all_columns self =
index = self.index.catch_ []
index_columns = case index of
Vector.Vector -> index
Expand All @@ -103,8 +103,8 @@ Table.Table.all_columns self =

Arguments:
- text: the case-insensitive name of the searched column.
Table.Table.lookup_ignore_case : Text -> Column ! Nothing
Table.Table.lookup_ignore_case self name =
Table.lookup_ignore_case : Text -> Column ! Nothing
Table.lookup_ignore_case self name =
self.all_columns.find <| col->
col.name.equals_ignore_case name

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from Standard.Base import all

from Standard.Table import Table, Column
import Standard.Table
import Standard.Visualization.Helpers

## PRIVATE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all
import Standard.Base

## An ID used by the visualization system to identify different ways of
displaying data.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from Standard.Base import all

from Standard.Table import Table, Column
import Standard.Table

import Standard.Visualization.Helpers
from Standard.Base.Data.Index_Sub_Range import Sample

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ case object Imports extends IRPass {
name = newName.copy(parts = parts :+ mainModuleName),
rename = computeRename(
i.rename,
i.onlyNames.nonEmpty || i.isAll,
parts(1).asInstanceOf[IR.Name.Literal]
)
)
Expand All @@ -75,6 +76,7 @@ case object Imports extends IRPass {
name = newName.copy(parts = parts :+ mainModuleName),
rename = computeRename(
ex.rename,
ex.onlyNames.nonEmpty || ex.isAll,
parts(1).asInstanceOf[IR.Name.Literal]
)
)
Expand Down Expand Up @@ -113,8 +115,10 @@ case object Imports extends IRPass {

private def computeRename(
originalRename: Option[IR.Name.Literal],
onlyNamesOrAll: Boolean,
qualName: IR.Name.Literal
): Some[IR.Name.Literal] = Some(originalRename.getOrElse(qualName))
): Option[IR.Name.Literal] =
originalRename.orElse(Option.unless(onlyNamesOrAll)(qualName))

val currentProjectAlias = "project"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,36 @@ class ImportsTest extends CompilerTest {
|import Bar.Foo
|import Bar.Foo as Bar
|from Bar.Foo import Bar, Baz
|from Bar.Foo as Bar import Baz, Spam
|from Bar.Foo as Bar import Bar, Spam
|from Bar.Foo import all
|
|export Bar.Foo
|export Bar.Foo as Bar
|from Bar.Foo export Bar, Baz
|from Bar.Foo as Bar export all
|from Bar.Foo as Bar export Bar, Baz
|from Bar.Foo export all
|
|import Foo.Bar.Baz
|export Foo.Bar.Baz
|""".stripMargin.preprocessModule.analyse

"desugar project name imports correctly" in {
ir.imports.take(4).map(_.showCode()) shouldEqual List(
ir.imports.take(5).map(_.showCode()) shouldEqual List(
"import Bar.Foo.Main as Foo",
"import Bar.Foo.Main as Bar",
"from Bar.Foo.Main as Foo import Bar, Baz",
"from Bar.Foo.Main as Bar import Baz, Spam"
"from Bar.Foo.Main import Bar, Baz",
hubertp marked this conversation as resolved.
Show resolved Hide resolved
"from Bar.Foo.Main as Bar import Bar, Spam",
"from Bar.Foo.Main import all"
)
}

"desugar project name exports correctly" in {
ir.exports.take(4).map(_.showCode()) shouldEqual List(
ir.exports.take(5).map(_.showCode()) shouldEqual List(
"export Bar.Foo.Main as Foo",
"export Bar.Foo.Main as Bar",
"from Bar.Foo.Main as Foo export Bar, Baz",
"from Bar.Foo.Main as Bar export all"
"from Bar.Foo.Main export Bar, Baz",
"from Bar.Foo.Main as Bar export Bar, Baz",
"from Bar.Foo.Main export all"
)
}

Expand Down
1 change: 1 addition & 0 deletions test/Table_Tests/src/Database/Postgres_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Standard.Table as Materialized_Table
from Standard.Table.Data.Aggregate_Column import all hiding First

from Standard.Database import all
import Standard.Database
from Standard.Database.Errors import Sql_Error
from Standard.Database.Data.Sql import Sql_Type
from Standard.Database.Internal.Postgres.Pgpass import Pgpass_Entry_Data
Expand Down
1 change: 1 addition & 0 deletions test/Table_Tests/src/Database/Redshift_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Standard.Base.Runtime.Ref
import Standard.Table as Materialized_Table

from Standard.Database import all
import Standard.Database
from Standard.Database.Connection.Connection import Sql_Error

import Standard.Test
Expand Down
1 change: 1 addition & 0 deletions test/Table_Tests/src/Database/SQLite_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Standard.Base.Runtime.Ref
import Standard.Table as Materialized_Table

from Standard.Database import all
import Standard.Database
from Standard.Database.Errors import Sql_Error_Data

import Standard.Test
Expand Down
3 changes: 2 additions & 1 deletion test/Tests/src/Semantic/Meta_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all
import Standard.Base

import Standard.Base.System.Platform

Expand Down Expand Up @@ -84,7 +85,7 @@ spec = Test.group "Meta-Value Manipulation" <|
_ -> Nothing
Test.specify "should allow to get the source location of a frame" pending=location_pending <|
src = Meta.get_source_location 0
loc = "Meta_Spec.enso:86:15-40"
loc = "Meta_Spec.enso:87:15-40"
src.take (Last loc.length) . should_equal loc

Test.specify "should allow to get qualified type names of values" <|
Expand Down
2 changes: 1 addition & 1 deletion test/Visualization_Tests/src/Geo_Map_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from Standard.Base import all

from Standard.Table import Table
import Standard.Table

import Standard.Visualization.Geo_Map

Expand Down
2 changes: 1 addition & 1 deletion test/Visualization_Tests/src/Helpers_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from Standard.Base import all

from Standard.Table import Table
import Standard.Table

import Standard.Visualization.Helpers

Expand Down
1 change: 1 addition & 0 deletions test/Visualization_Tests/src/Histogram_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from Standard.Base import all

from Standard.Table import Table, Column
import Standard.Table

import Standard.Visualization.Histogram

Expand Down
1 change: 1 addition & 0 deletions test/Visualization_Tests/src/Id_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all
import Standard.Base

import Standard.Visualization

Expand Down
1 change: 1 addition & 0 deletions test/Visualization_Tests/src/Scatter_Plot_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from Standard.Base import all

from Standard.Table import Table, Column
import Standard.Table

import Standard.Visualization.Scatter_Plot

Expand Down
1 change: 1 addition & 0 deletions test/Visualization_Tests/src/Sql_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from Standard.Base import all

from Standard.Database import all
import Standard.Database

import Standard.Visualization.Sql.Visualization as Visualization

Expand Down
4 changes: 3 additions & 1 deletion test/Visualization_Tests/src/Table_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from Standard.Base import all

from Standard.Table import Table, Aggregate_Column
import Standard.Table

from Standard.Database import all
from Standard.Database import SQLite_Data
import Standard.Database
import Standard.Database.Data.Table as Database_Table

import Standard.Visualization.Table.Visualization as Visualization
Expand Down