Skip to content

Commit

Permalink
Support module imports using a qualified name (#3608)
Browse files Browse the repository at this point in the history
This change allows for importing modules using a qualified name and deals with any conflicts on the way.
Given a module C defined at `A/B/C.enso` with
```
type C
type C a
```
it is now possible to import it as
```
import project.A
...
val x = A.B.C 10
```

Given a module located at `A/B/C/D.enso`, we will generate
intermediate, synthetic, modules that only import and export the successor module along the path.
For example, the contents of a synthetic module B will look like
```
import <namespace>.<pkg-name>.A.B.C
export <namespace>.<pkg-name>.A.B.C
```
If module B is defined already by the developer, the compiler will _inject_ the above statements to the IR.

Also removed the last elements of some lowercase name resolution that managed to survive recent
changes (`Meta.Enso_Project` would now be ambiguous with `enso_project` method).

Finally, added a pass that detects shadowing of the synthetic module by the type defined along the path.
We print a warning in such a situation.

Related to https://www.pivotaltracker.com/n/projects/2539304

# Important Notes
There was an additional request to fix the annoying problem with `from` imports that would always bring
the module into the scope. The changes in stdlib demonstrate how it is now possible to avoid the workaround of
```
from X.Y.Z as Z_Module import A, B
```
(i.e. `as Z_Module` part is almost always unnecessary).
  • Loading branch information
hubertp authored Jul 29, 2022
1 parent 206dbc4 commit d59714a
Show file tree
Hide file tree
Showing 62 changed files with 592 additions and 123 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@
- [Remove `here` and make method name resolution case-sensitive][3531]
- [Explicit `self`][3569]
- [Added benchmarking tool for the language server][3578]
- [Support module imports using a qualified name][3608]

[3227]: https://github.com/enso-org/enso/pull/3227
[3248]: https://github.com/enso-org/enso/pull/3248
Expand Down Expand Up @@ -332,6 +333,7 @@
[3538]: https://github.com/enso-org/enso/pull/3538
[3538]: https://github.com/enso-org/enso/pull/3569
[3578]: https://github.com/enso-org/enso/pull/3578
[3608]: https://github.com/enso-org/enso/pull/3608

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from Standard.Base import all
import Standard.Base.Data.Ordering.Natural_Order
from Standard.Base.Data.Text.Text_Ordering as Text_Ordering_Module import Text_Ordering
from Standard.Base.Data.Text.Text_Ordering import Text_Ordering

polyglot java import org.enso.base.ObjectComparator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ import Standard.Base.Data.Text.Matching_Mode
import Standard.Base.Data.Text.Case
import Standard.Base.Data.Text.Location
import Standard.Base.Data.Text.Line_Ending_Style
from Standard.Base.Data.Text.Span as Span_Module import Span
import Standard.Base.Data.Text.Span as Span_Module
import Standard.Base.Data.Text.Text_Sub_Range
from Standard.Base.Data.Text.Encoding as Encoding_Module import Encoding, Encoding_Error
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior, Report_Warning
from Standard.Base.Error.Problem_Behavior import Report_Warning
import Standard.Base.Data.Locale
import Standard.Base.Meta

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

import Standard.Base.Data.Locale
import Standard.Base.Data.Text.Regex
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior, Report_Warning
from Standard.Base.Error.Problem_Behavior import Problem_Behavior, Report_Warning
from Standard.Base.Error.Common import Wrapped_Dataflow_Error

## UNSTABLE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import Standard.Base.Data.Text.Regex.Option as Global_Option
import Standard.Base.Data.Text.Regex.Mode
import Standard.Base.Data.Text.Matching_Mode
import Standard.Base.Polyglot.Java
from Standard.Base.Data.Text.Span as Span_Module import Utf_16_Span

polyglot java import java.lang.IllegalArgumentException
polyglot java import java.lang.IndexOutOfBoundsException
Expand Down
4 changes: 1 addition & 3 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import project.IO
import project.Nothing
import project.Math
import project.Meta
import project.Meta.Enso_Project
import project.Polyglot
import project.Polyglot.Java
import project.Runtime
Expand Down Expand Up @@ -89,13 +88,12 @@ from project.Data.Range export all
https://www.pivotaltracker.com/story/show/181309938
from project.Data.Text.Extensions export Text, Line_Ending_Style, Case, Location
from project.Data.Text.Matching export Case_Insensitive, Text_Matcher, Regex_Matcher, No_Matches_Found
from project.Data.Text export all
from project.Data.Text export all hiding Encoding, Span, Text_Ordering
from project.Data.Text.Encoding export Encoding, Encoding_Error
from project.Data.Text.Text_Ordering export all
from project.Data.Text.Span export all
from project.Error.Common export all
from project.Function export all
from project.Meta.Enso_Project export all
from project.Nothing export all
from project.Polyglot export all
from project.Runtime.Extensions export all
7 changes: 2 additions & 5 deletions distribution/lib/Standard/Base/0.0.0-dev/src/System/File.enso
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@ import Standard.Base.System.File.File_Permissions
import Standard.Base.Error.Problem_Behavior
import Standard.Base.Data.Text.Matching_Mode
import Standard.Base.Data.Text.Text_Sub_Range
from Standard.Base.Data.Text.Encoding as Encoding_Module import Encoding, Encoding_Error
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior, Report_Warning
from Standard.Base.Error.Problem_Behavior import Report_Warning
import Standard.Base.Runtime.Resource
from Standard.Base.Runtime.Resource import Managed_Resource
from Standard.Base.Data.Time as Time_Module import Time

export Standard.Base.System.File.Option
from Standard.Base.Data.Time import Time

polyglot java import org.enso.base.Array_Utils
polyglot java import org.enso.base.Encoding_Utils
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from Standard.Base import all

from Standard.Database.Connection.Connection_Options as Connection_Options_Module import Connection_Options
from Standard.Database.Connection.Connection_Options import Connection_Options

import Standard.Database.Connection.Postgres
import Standard.Database.Connection.SQLite
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ from Standard.Base.Data.Numbers import Parse_Error

import Standard.Database.Data.Dialect
import Standard.Database.Connection.Connection
from Standard.Database.Connection.Credentials as Credentials_Module import Credentials
from Standard.Database.Connection.Credentials import Credentials
import Standard.Database.Connection.Connection_Options
import Standard.Database.Connection.SSL_Mode
from Standard.Database.Connection.SSL_Mode import all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ from Standard.Base import all

import Standard.Database.Data.Dialect
import Standard.Database.Connection.Connection
from Standard.Database.Connection.Credentials as Credentials_Module import Credentials
from Standard.Database.Connection.Credentials import Credentials
import Standard.Database.Connection.Connection_Options
import Standard.Database.Connection.SSL_Mode
from Standard.Database.Connection.SSL_Mode import all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Standard.Table.Data.Sort_Column

from Standard.Database.Data.Sql import Sql_Type
from Standard.Database.Data.Table import Integrity_Error
from Standard.Database.Error as Database_Errors import Unsupported_Database_Operation_Error
from Standard.Database.Error import Unsupported_Database_Operation_Error

type Column

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ from Standard.Base import all
import Standard.Base.Error.Common as Errors
from Standard.Table.Data.Aggregate_Column import all
from Standard.Database.Data.Sql import Sql_Type
import Standard.Database.Data.Sql
import Standard.Database.Data.Dialect
import Standard.Database.Data.Dialect.Helpers
import Standard.Database.Data.Internal.Base_Generator
import Standard.Database.Data.Internal.IR
from Standard.Database.Error as Database_Errors import Unsupported_Database_Operation_Error
from Standard.Database.Error import Unsupported_Database_Operation_Error

## PRIVATE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ from Standard.Base import all

from Standard.Table.Data.Aggregate_Column import all
from Standard.Database.Data.Sql import Sql_Type
import Standard.Database.Data.Sql
import Standard.Database.Data.Dialect
import Standard.Database.Data.Dialect.Helpers
import Standard.Database.Data.Internal.Base_Generator
import Standard.Database.Data.Internal.IR
from Standard.Database.Error as Database_Errors import Unsupported_Database_Operation_Error
from Standard.Database.Error import Unsupported_Database_Operation_Error

## PRIVATE

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from Standard.Base import all
from Standard.Base.Data.Text.Text_Ordering as Text_Ordering_Module import Text_Ordering
from Standard.Base.Data.Text.Text_Ordering import Text_Ordering

from Standard.Table.Data.Aggregate_Column import all
import Standard.Database.Data.Internal.IR
from Standard.Database.Data.Sql import Sql_Type
from Standard.Database.Error as Database_Errors import Unsupported_Database_Operation_Error
from Standard.Database.Error import Unsupported_Database_Operation_Error

## PRIVATE
Creates an `Internal_Column` that computes the specified statistic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Standard.Database.Data.Sql
import Standard.Database.Data.Internal.IR

from Standard.Database.Data.Sql import Sql_Type
from Standard.Database.Error as Database_Errors import Unsupported_Database_Operation_Error
from Standard.Database.Error import Unsupported_Database_Operation_Error

type Internal_Dialect

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

from Standard.Database.Data.Table as Table_Module import Table
from Standard.Database.Data.Column as Column_Module import Column
from Standard.Database.Data.Table import Table
from Standard.Database.Data.Column import Column

polyglot java import java.util.regex.Pattern

Expand Down
12 changes: 6 additions & 6 deletions distribution/lib/Standard/Database/0.0.0-dev/src/Data/Table.enso
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ import Standard.Base.System.File.Existing_File_Behavior

import Standard.Table.Data.Aggregate_Column
import Standard.Table.Internal.Aggregate_Column_Helper
from Standard.Database.Data.Column as Column_Module import Column, Aggregate_Column_Builder
from Standard.Database.Data.Column import Column, Aggregate_Column_Builder
from Standard.Database.Data.Internal.IR import Internal_Column
from Standard.Table.Data.Table import No_Such_Column_Error
from Standard.Table.Data.Column_Selector as Column_Selector_Module import Column_Selector, By_Index
from Standard.Base.Data.Text.Text_Ordering as Text_Ordering_Module import Text_Ordering
from Standard.Table.Data.Data_Formatter as Data_Formatter_Module import Data_Formatter
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior, Report_Warning
from Standard.Database.Error as Database_Errors import Unsupported_Database_Operation_Error
from Standard.Table.Data.Column_Selector import Column_Selector, By_Index
from Standard.Base.Data.Text.Text_Ordering import Text_Ordering
from Standard.Table.Data.Data_Formatter import Data_Formatter
from Standard.Base.Error.Problem_Behavior import Problem_Behavior, Report_Warning
from Standard.Database.Error import Unsupported_Database_Operation_Error
import Standard.Table.Data.Column_Name_Mapping
import Standard.Table.Data.Position
import Standard.Table.Data.Sort_Column_Selector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
Get the item name and price columns from the shop inventory.

import Standard.Examples
from Standard.Table.Data.Column_Selector as Column_Selector_Module import By_Name
from Standard.Table.Data.Column_Selector import By_Name

example_select =
Examples.inventory_table.select_columns (By_Name ["item_name", "price"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from Standard.Base import all

from Standard.Table.Data.Column as Column_Module import Column
from Standard.Table.Data.Column import Column
import Standard.Table.Data.Column_Selector
import Standard.Table.Data.Sort_Column_Selector

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

from Standard.Base.Data.Time as Time_Module import Time
from Standard.Base.Data.Time.Time_Of_Day as Time_Of_Day_Module import Time_Of_Day
from Standard.Table.Data.Column_Type_Selection as Column_Type_Selection_Module import Auto
from Standard.Base.Data.Time import Time
from Standard.Base.Data.Time.Time_Of_Day import Time_Of_Day
from Standard.Table.Data.Column_Type_Selection import Auto
import Standard.Base.Error.Common as Errors
import Standard.Base.Error.Problem_Behavior
import Standard.Table.Data.Storage
Expand Down
12 changes: 6 additions & 6 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Data/Table.enso
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import Standard.Table.Internal.Delimited_Reader
import Standard.Table.Internal.Delimited_Writer
import Standard.Table.Internal.Problem_Builder

from Standard.Table.Data.Column_Selector as Column_Selector_Module import Column_Selector, By_Index
from Standard.Table.Data.Column_Type_Selection as Column_Type_Selection_Module import Column_Type_Selection, Auto
from Standard.Table.Data.Data_Formatter as Data_Formatter_Module import Data_Formatter
from Standard.Base.Data.Text.Text_Ordering as Text_Ordering_Module import Text_Ordering
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior, Report_Warning
from Standard.Table.Errors as Error_Module import Missing_Input_Columns, Column_Indexes_Out_Of_Range, Duplicate_Type_Selector
from Standard.Table.Data.Column_Selector import Column_Selector, By_Index
from Standard.Table.Data.Column_Type_Selection import Column_Type_Selection, Auto
from Standard.Table.Data.Data_Formatter import Data_Formatter
from Standard.Base.Data.Text.Text_Ordering import Text_Ordering
from Standard.Base.Error.Problem_Behavior import Problem_Behavior, Report_Warning
from Standard.Table.Errors import Missing_Input_Columns, Column_Indexes_Out_Of_Range, Duplicate_Type_Selector
import Standard.Table.Data.Match_Columns

import Standard.Table.Data.Column_Name_Mapping
Expand Down
4 changes: 2 additions & 2 deletions distribution/lib/Standard/Table/0.0.0-dev/src/IO/Excel.enso
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from Standard.Base import all
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior
from Standard.Base.Error.Problem_Behavior import Problem_Behavior
import Standard.Base.System.File.Existing_File_Behavior
import Standard.Base.System.File.Option
from Standard.Table.IO.File_Format import Infer

import Standard.Table.Data.Table
from Standard.Table.Errors as Error_Module import Invalid_Location, Duplicate_Output_Column_Names, Invalid_Output_Column_Names, Range_Exceeded, Existing_Data, Column_Count_Mismatch, Column_Name_Mismatch
from Standard.Table.Errors import Invalid_Location, Duplicate_Output_Column_Names, Invalid_Output_Column_Names, Range_Exceeded, Existing_Data, Column_Count_Mismatch, Column_Name_Mismatch
import Standard.Base.Error.Common as Errors
import Standard.Table.Data.Match_Columns

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import Standard.Table
import Standard.Base.Error.Common as Errors
import Standard.Base.System
import Standard.Table.Data.Match_Columns
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior
from Standard.Base.Data.Text.Encoding as Encoding_Module import Encoding
from Standard.Base.Error.Problem_Behavior import Problem_Behavior
from Standard.Base.Data.Text.Encoding import Encoding
import Standard.Base.Runtime.Ref
import Standard.Table.Internal.Delimited_Reader
import Standard.Table.Internal.Delimited_Writer
from Standard.Table.Errors as Table_Errors import Unsupported_File_Type
from Standard.Table.Errors import Unsupported_File_Type

from Standard.Table.Data.Data_Formatter as Data_Formatter_Module import Data_Formatter
from Standard.Table.Data.Data_Formatter import Data_Formatter
import Standard.Table.IO.Excel as Excel_Module
import Standard.Table.IO.Quote_Style

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from Standard.Base import all
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior, Report_Warning
from Standard.Base.Error.Problem_Behavior import Problem_Behavior, Report_Warning

import Standard.Table.IO.File_Format

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

from Standard.Table.Data.Column as Column_Module import Column
from Standard.Table.Data.Column import Column
from Standard.Table.Data.Aggregate_Column import all
from Standard.Table.Data.Column_Selector as Column_Selector_Module import Column_Selector, By_Name, By_Index, By_Column
from Standard.Table.Data.Column_Selector import Column_Selector, By_Name, By_Index, By_Column
import Standard.Table.Internal.Problem_Builder
import Standard.Table.Internal.Unique_Name_Strategy
import Standard.Table.Internal.Table_Helpers
Expand All @@ -12,7 +12,7 @@ import Standard.Table.Data.Sort_Column

import Standard.Base.Data.Ordering.Comparator

from Standard.Table.Errors as Error_Module import Missing_Input_Columns, Column_Indexes_Out_Of_Range, No_Output_Columns, Duplicate_Output_Column_Names, Invalid_Output_Column_Names, Invalid_Aggregation, Floating_Point_Grouping, Unquoted_Delimiter, Additional_Warnings
from Standard.Table.Errors import Missing_Input_Columns, Column_Indexes_Out_Of_Range, No_Output_Columns, Duplicate_Output_Column_Names, Invalid_Output_Column_Names, Invalid_Aggregation, Floating_Point_Grouping, Unquoted_Delimiter, Additional_Warnings

polyglot java import org.enso.table.aggregations.Aggregator
polyglot java import org.enso.table.aggregations.Concatenate as ConcatenateAggregator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Standard.Table

import Standard.Base.Data.Statistics
import Standard.Base.Error.Common as Errors
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior, Ignore, Report_Error
from Standard.Table.Errors as Table_Errors import Duplicate_Output_Column_Names, Invalid_Output_Column_Names, Invalid_Row, Mismatched_Quote, Parser_Error, Additional_Invalid_Rows
from Standard.Base.Data.Text.Encoding as Encoding_Module import Encoding, Encoding_Error
from Standard.Base.Error.Problem_Behavior import Problem_Behavior, Ignore, Report_Error
from Standard.Table.Errors import Duplicate_Output_Column_Names, Invalid_Output_Column_Names, Invalid_Row, Mismatched_Quote, Parser_Error, Additional_Invalid_Rows
from Standard.Base.Data.Text.Encoding import Encoding, Encoding_Error
from Standard.Table.IO.File_Format import Infer
from Standard.Table.Data.Data_Formatter as Data_Formatter_Module import Data_Formatter
from Standard.Table.Data.Data_Formatter import Data_Formatter
import Standard.Table.IO.Quote_Style

polyglot java import org.enso.base.encoding.NewlineDetector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@ import Standard.Table

import Standard.Base.Error.Common as Errors
import Standard.Base.System
from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior
from Standard.Base.Error.Problem_Behavior import Problem_Behavior
import Standard.Base.System.File.Existing_File_Behavior
from Standard.Table.Errors as Table_Errors import Duplicate_Output_Column_Names, Invalid_Output_Column_Names, Invalid_Row, Mismatched_Quote, Parser_Error, Additional_Invalid_Rows, Column_Count_Mismatch, Column_Name_Mismatch
from Standard.Base.Data.Text.Encoding as Encoding_Module import Encoding, Encoding_Error
from Standard.Base.Data.Text.Encoding import Encoding, Encoding_Error
from Standard.Table.IO.File_Format import Infer
from Standard.Table.Data.Data_Formatter as Data_Formatter_Module import Data_Formatter
from Standard.Table.Data.Data_Formatter import Data_Formatter
import Standard.Table.Data.Storage
import Standard.Table.IO.Quote_Style
import Standard.Base.Data.Text.Line_Ending_Style
from Standard.Table.Internal.Delimited_Reader import Existing_Headers, No_Headers
import Standard.Table.Internal.Delimited_Reader
import Standard.Table.Data.Match_Columns

polyglot java import org.enso.table.write.DelimitedWriter
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from Standard.Base import all

from Standard.Base.Error.Problem_Behavior as Problem_Behavior_Module import Problem_Behavior, Report_Warning
from Standard.Base.Error.Problem_Behavior import Problem_Behavior, Report_Warning
import Standard.Base.Runtime.Ref
import Standard.Table.Internal.Vector_Builder

from Standard.Table.Errors as Error_Module import Missing_Input_Columns, Column_Indexes_Out_Of_Range, No_Output_Columns, Duplicate_Column_Selectors, Input_Indices_Already_Matched, Too_Many_Column_Names_Provided, Duplicate_Output_Column_Names, Invalid_Output_Column_Names, Column_Matched_By_Multiple_Selectors
from Standard.Table.Errors import Missing_Input_Columns, Column_Indexes_Out_Of_Range, No_Output_Columns, Duplicate_Column_Selectors, Input_Indices_Already_Matched, Too_Many_Column_Names_Provided, Duplicate_Output_Column_Names, Invalid_Output_Column_Names, Column_Matched_By_Multiple_Selectors

type Problem_Builder
type Problem_Builder oob_indices duplicate_column_selectors input_indices_already_matched missing_input_columns other
Expand Down
Loading

0 comments on commit d59714a

Please sign in to comment.