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

Export works without import #9683

Merged
merged 14 commits into from
Apr 12, 2024
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
6 changes: 0 additions & 6 deletions distribution/lib/Standard/AWS/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import project.AWS_Credential.AWS_Credential
import project.AWS_Region.AWS_Region
import project.Database.Redshift.Redshift_Details.Redshift_Details
import project.S3.S3
import project.S3.S3_File.S3_File

export project.AWS_Credential.AWS_Credential
export project.AWS_Region.AWS_Region
export project.Database.Redshift.Redshift_Details.Redshift_Details
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import project.Any.Any
import project.Nothing.Nothing
from project.Data.Boolean.Boolean import False, True

from project.Data.Boolean.Boolean export False, True

Expand Down
105 changes: 0 additions & 105 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
@@ -1,108 +1,3 @@
import project.Any.Any
import project.Data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very nice change!

import project.Data.Array.Array
import project.Data.Boolean
import project.Data.Decimal.Decimal
import project.Data.Filter_Condition.Filter_Action
import project.Data.Filter_Condition.Filter_Condition
import project.Data.Index_Sub_Range.Index_Sub_Range
import project.Data.Interval.Bound
import project.Data.Interval.Interval
import project.Data.Interval.Interval_Type
import project.Data.Json.JS_Object
import project.Data.Json.Json
import project.Data.List.List
import project.Data.Locale.Locale
import project.Data.Map.Map
import project.Data.Maybe.Maybe
import project.Data.Numbers
import project.Data.Numeric.Math_Context.Math_Context
import project.Data.Numeric.Math_Context.Unlimited
import project.Data.Numeric.Rounding_Mode.Rounding_Mode
import project.Data.Ordering.Comparable
import project.Data.Ordering.Default_Comparator
import project.Data.Ordering.Natural_Order
import project.Data.Ordering.Ordering
import project.Data.Pair.Pair
import project.Data.Range.Range
import project.Data.Regression
import project.Data.Set.Set
import project.Data.Sort_Direction.Sort_Direction
import project.Data.Statistics
import project.Data.Text.Case.Case
import project.Data.Text.Case_Sensitivity.Case_Sensitivity
import project.Data.Text.Encoding.Encoding
import project.Data.Text.Line_Ending_Style.Line_Ending_Style
import project.Data.Text.Location.Location
import project.Data.Text.Matching_Mode.Matching_Mode
import project.Data.Text.Normalization.Normalization
import project.Data.Text.Regex.Regex
import project.Data.Text.Text
import project.Data.Text.Text_Ordering.Text_Ordering
import project.Data.Text.Text_Sub_Range.Text_Sub_Range
import project.Data.Time.Date.Date
import project.Data.Time.Date_Period.Date_Period
import project.Data.Time.Date_Range.Date_Range
import project.Data.Time.Date_Time.Date_Time
import project.Data.Time.Date_Time_Formatter.Date_Time_Formatter
import project.Data.Time.Day_Of_Week.Day_Of_Week
import project.Data.Time.Duration.Duration
import project.Data.Time.Period.Period
import project.Data.Time.Time_Of_Day.Time_Of_Day
import project.Data.Time.Time_Period.Time_Period
import project.Data.Time.Time_Zone.Time_Zone
import project.Data.Vector.Vector
import project.Data.XML.XML_Document
import project.Data.XML.XML_Element
import project.Data.XML.XML_Error
import project.Data.XML.XML_Format.XML_Format
import project.Enso_Cloud.Enso_File.Enso_File
import project.Enso_Cloud.Enso_Secret.Enso_Secret
import project.Enso_Cloud.Enso_User.Enso_User
import project.Error.Error
import project.Errors
import project.Errors.Problem_Behavior.Problem_Behavior
import project.Function
import project.IO
import project.Math
import project.Meta
import project.Meta.Enso_Project.Project_Description
import project.Network.HTTP.Header.Header
import project.Network.HTTP.HTTP
import project.Network.HTTP.HTTP_Method.HTTP_Method
import project.Network.HTTP.HTTP_Status_Code.HTTP_Status_Code
import project.Network.HTTP.HTTP_Version.HTTP_Version
import project.Network.URI.URI
import project.Nothing.Nothing
import project.Panic.Panic
import project.Polyglot.Java
import project.Polyglot.Polyglot
import project.Random.Random
import project.Runtime
import project.System
import project.System.Environment
import project.System.File.Existing_File_Behavior.Existing_File_Behavior
import project.System.File.File
import project.System.File.File_Access.File_Access
import project.System.File.File_Permissions.File_Permissions
import project.System.File.File_Permissions.Permission
import project.System.File.Write_Extensions
import project.System.File_Format
import project.System.Platform
import project.System.Process
import project.System.Process.Exit_Code.Exit_Code
import project.Warning.Warning
from project.Data import Raw_Response
from project.Data.Index_Sub_Range.Index_Sub_Range import First, Last
from project.Data.Json.Extensions import all
from project.Data.Range.Extensions import all
from project.Data.Text.Extensions import all
from project.Data.Text.Regex import regex
from project.Errors.Problem_Behavior.Problem_Behavior import all
from project.Meta.Enso_Project import enso_project
from project.Network.Extensions import all
from project.System.File_Format.Plain_Text_Format import Plain_Text

export project.Any.Any
export project.Data
export project.Data.Array.Array
Expand Down
17 changes: 0 additions & 17 deletions distribution/lib/Standard/Database/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
@@ -1,20 +1,3 @@
import project.Column_Description.Column_Description
import project.Connection.Client_Certificate.Client_Certificate
import project.Connection.Connection_Options.Connection_Options
import project.Connection.Credentials.Credentials
import project.Connection.Database
import project.Connection.Postgres_Details.Postgres_Details
import project.Connection.SQLite_Details.In_Memory
import project.Connection.SQLite_Details.SQLite_Details
import project.Connection.SQLite_Format.SQLite_Format
import project.Connection.SSL_Mode.SSL_Mode
import project.SQL_Query.SQL_Query
import project.Update_Action.Update_Action
from project.Connection.Postgres_Details.Postgres_Details import Postgres
from project.Connection.SQLite_Details.SQLite_Details import SQLite
from project.Extensions.Upload_Database_Table import all
from project.Extensions.Upload_In_Memory_Table import all

export project.Column_Description.Column_Description
export project.Connection.Client_Certificate.Client_Certificate
export project.Connection.Connection_Options.Connection_Options
Expand Down
2 changes: 0 additions & 2 deletions distribution/lib/Standard/Geo/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ from Standard.Base import all

from Standard.Table import Table

import project.Geo_Json

from project.Geo_Json export geo_json_to_table

## UNSTABLE
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import project.Google_Analytics
import project.Google_Credential.Google_Credential
import project.Google_Sheets.Google_Sheets

export project.Google_Analytics
export project.Google_Credential.Google_Credential
export project.Google_Sheets.Google_Sheets
Expand Down
5 changes: 0 additions & 5 deletions distribution/lib/Standard/Image/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
from Standard.Base import all

import project.Image.Image
import project.Matrix.Matrix
import project.Read_Flag.Read_Flag
import project.Write_Flag.Write_Flag

export project.Image.Image
export project.Matrix.Matrix
export project.Read_Flag.Read_Flag
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import project.Snowflake_Details.Snowflake_Details
export project.Snowflake_Details.Snowflake_Details
29 changes: 0 additions & 29 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
@@ -1,34 +1,5 @@
from Standard.Base import all

import project.Aggregate_Column.Aggregate_Column
import project.Blank_Selector.Blank_Selector
import project.Column.Column
import project.Column_Operation.Column_Operation
import project.Column_Ref.Column_Ref
import project.Data_Formatter.Data_Formatter
import project.Delimited.Delimited_Format.Delimited_Format
import project.Delimited.Quote_Style.Quote_Style
import project.Excel.Excel_Format.Excel_Format
import project.Excel.Excel_Range.Excel_Range
import project.Excel.Excel_Workbook.Excel_Workbook
import project.Join_Condition.Join_Condition
import project.Join_Kind.Join_Kind
import project.Match_Columns.Match_Columns
import project.Position.Position
import project.Prefix_Name.Prefix_Name
import project.Set_Mode.Set_Mode
import project.Simple_Expression.Simple_Calculation
import project.Simple_Expression.Simple_Expression
import project.Sort_Column.Sort_Column
import project.Table.Table
import project.Value_Type.Auto
import project.Value_Type.Bits
import project.Value_Type.Value_Type
from project.Constants import all
from project.Expression import expr
from project.Extensions.Column_Vector_Extensions import all
from project.Extensions.Table_Conversions import all

export project.Aggregate_Column.Aggregate_Column
export project.Blank_Selector.Blank_Selector
export project.Column.Column
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
from Standard.Base import all

import project.AI
import project.File_Upload
import project.Helpers
import project.Id.Id
import project.Preprocessor

export project.AI

export project.Helpers
Expand Down
85 changes: 48 additions & 37 deletions docs/syntax/imports.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,50 @@ code from modules.

## Qualified Names

Both imports and exports require the use of qualified module names. A qualified
In the following text, **entity** shall denote a module, a method (instance,
static, foreign), type, or a type constructor. In other words, an _entity_ is
anything that can be assigned to a variable.

Both imports and exports require the use of qualified entity names. A qualified
name consists of the library namespace (usually organization under which its
published) and the library name, followed by module names mirroring the source
tree of the library. For example the file `src/Stuff/Things/Util.enso` inside
the library `My_Lib` published by the user `wdanilo` would have the following
qualified name: `wdanilo.My_Lib.Stuff.Things.Util`. To facilitate library
renaming (or deciding on the publishing organization later in the development
cycle, or working on a project that won't be published) it is possible to use
the keyword `project` instead of namespace and project name, to import a file in
the same project. Therefore, the file `src/Varia/Tools/Manager.enso` in `My_Lib`
published (or not) by `wdanilo` may use `project.Stuff.Things.Util` to refer to
the previously mentioned file.
tree of the library, followed by an entity name within that module. For example
the file `src/Stuff/Things/Util.enso` inside the library `My_Lib` published by
the user `wdanilo` would have the following qualified name:
`wdanilo.My_Lib.Stuff.Things.Util` and the type `My_Type` within that module
would have the qualified name `wdanilo.My_Lib.Stuff.Things.Util.My_Type`. To
facilitate library renaming (or deciding on the publishing organization later in
the development cycle, or working on a project that won't be published) it is
possible to use the keyword `project` instead of namespace and project name, to
import a file in the same project. Therefore, the file
`src/Varia/Tools/Manager.enso` in `My_Lib` published (or not) by `wdanilo` may
use `project.Stuff.Things.Util` to refer to the previously mentioned file.

Currently, the `project` keyword works only in import and export statements.
Note that it is possible to export a symbol from the current project with the
`project` keyword without first importing it.
Comment on lines +49 to +51
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes in this PR are mentioned just in this paragraph. The rest of the diff to this documentation file is just an attempt to update the specification to correspond to the current functionality.


## Import Syntax

There are two main ways of importing a module into the current scope.

### Qualified Imports

These imports consist of the word `import` followed by a qualified name of a
module. This can by optionally followed by the `as` word, and a referent name of
the module as it should be visible in the importing scope.
These imports consist of the word `import` followed by a qualified name of an
entity. This can be optionally followed by the `as` word, and a referent name of
the entity as it should be visible in the importing scope.

The only name brought into scope by such an import is the name of the module (or
The only name brought into scope by such an import is the name of the entity (or
the name provided after the `as` keyword, if provided).

### Unqualified Imports

Unqualified imports are broken up into three main categories:

1. **Unrestricted Imports:** These import all symbols from the module into the
current scope. They consist of the keyword `from`, followed by a qualified
module name, followed by an optional rename part (using the `as` keyword),
then the keywords `import all`. For example:
1. **Unrestricted Imports:** These import all symbols (entities) from the module
(or from a type) into the current scope. They consist of the keyword `from`,
followed by a qualified module name, followed by an optional rename part
(using the `as` keyword), then the keywords `import all`. For example:
```
from Standard.Base.Data.List as Builtin_List import all
```
Expand All @@ -81,8 +91,9 @@ Unqualified imports are broken up into three main categories:
from Standard.Base.Data.List import all hiding Cons, Nil
```

Imports in Enso _may_ introduce ambiguous symbols, but this is not an error
until one of the ambiguous symbols is _used_ in Enso code.
Imports in Enso _may_ introduce ambiguous symbols, which is treated as a
compilation error. Ideally, the error should be delayed until one of the
ambiguous symbols is _used_ in Enso code.

## Export Syntax

Expand All @@ -92,44 +103,44 @@ appear in Enso as follows:

### Qualified Exports

These exports consist of the word `export` followed by a qualified name of a
module. This can by optionally followed by the `as` word, and a referent name of
the module as it should be visible in the exporting scope.
These exports consist of the word `export` followed by a qualified name of an
entity. This can be optionally followed by the `as` word, and a referent name of
the entity as it should be visible in the exporting scope.

The only name brought into scope by such an export is the name of the module (or
The only name brought into scope by such an export is the name of the entity (or
the name provided after the `as` keyword, if provided).

### Unqualified Exports

Unqualified exports are broken up into three main categories:

1. **Unrestricted Exports:** These export all symbols from the module into the
current scope. They consist of the keyword `from`, followed by a qualified
module name, followed by an optional rename part (using the `as` keyword),
then the keywords `export all`. For example:
1. **Unrestricted Exports:** These export all symbols from the module or type
into the current scope. They consist of the keyword `from`, followed by a
qualified module name, followed by an optional rename part (using the `as`
keyword), then the keywords `export all`. For example:
```
from Standard.Base.Data.List as Builtin_List export all
```
2. **Restricted Exports:** These export a specified set of names, behaving as
though they were redefined in the current scope. They consist of the keyword
`from`, followed by a qualified module name (with optional `as`-rename), then
the word `export` followed by a coma-separated list of names to be exported.
For example:
`from`, followed by a qualified module or type name (with optional
`as`-rename), then the word `export` followed by a coma-separated list of
names to be exported. For example:
```
from Standard.Base.Data.List export Cons, Nil, from_vector
```
3. **Hiding Exports:** These are the inverse of restricted exports, and export
_all_ symbols other than the named ones. They consist of the `from` keyword,
followed by a qualified module name (with optional `as`-rename), then the
words `export all hiding`, followed by a coma-separated list of names to be
excluded from the export. For example:
followed by a qualified module or type name (with optional `as`-rename), then
the words `export all hiding`, followed by a coma-separated list of names to
be excluded from the export. For example:
```
from Standard.Base.Data.List export all hiding from_vector, Nil
```

In essence, an export allows the user to "paste" the contents of the module
being exported into the module declaring the export. This means that exports
that create name clashes must be resolved at the _export_ site.
In essence, an export allows the user to "paste" the contents of the module or
type being exported into the module declaring the export. This means that
exports that create name clashes must be resolved at the _export_ site.

### Visibility of Export Bindings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ protected ImportResolverAlgorithm() {}

protected abstract String nameForType(ResolvedType e);

protected abstract java.util.List<Export> exportsFor(Module module, String impName);
/**
* Returns a list of all the exports from the module of the given symbol
*
* @param module the module to search for exports in
* @param symbol FQN symbol contained in the returned exports.
*/
protected abstract java.util.List<Export> exportsFor(Module module, String symbol);

protected abstract boolean isAll(Export ex);

Expand Down
Loading
Loading