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
Allow exports from namespaces #1453
base: main
Are you sure you want to change the base?
Conversation
Change in memory usage detected by benchmark. Memory Report for 2c21d22
|
Benchmark for 2c21d22Click to view benchmark
|
Change in memory usage detected by benchmark. Memory Report for ef02ab3
|
Benchmark for ef02ab3Click to view benchmark
|
Change in memory usage detected by benchmark. Memory Report for 0e74389
|
Benchmark for 0e74389Click to view benchmark
|
Change in memory usage detected by benchmark. Memory Report for de39c3f
|
Benchmark for de39c3fClick to view benchmark
|
Change in memory usage detected by benchmark. Memory Report for a400509
|
ec590bb
to
0415cf3
Compare
Change in memory usage detected by benchmark. Memory Report for 18711a2
|
Benchmark for 18711a2Click to view benchmark
|
Change in memory usage detected by benchmark. Memory Report for 51c39ce
|
Benchmark for 51c39ceClick to view benchmark
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't have to be this PR, but just so I don't forget, we should make a note to update the syntax highlighting grammars (codemirror and TextMate) with the new keywords.
// bind all exported symbols in a follow-on step | ||
resolver.resolve_exports(package); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the behavior is ok here, but the method name and comment confused me.
Would "resolve and bind all imports and exports" be a more complete description of what's happening here?
#[diagnostic(code("Qsc.Resolve.ExportedNonItem"))] | ||
ExportedNonItem(#[label] Span), | ||
|
||
#[error("exporting external items is not yet supported")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to continue my crusade against the word "yet" in errors...
#[error("exporting external items is not yet supported")] | |
#[error("exporting external items is not supported")] |
#[error("export statements are only allowed in a namespace scope")] | ||
#[diagnostic(code("Qsc.Resolve.ExportFromNonNamespaceScope"))] | ||
ExportFromNonNamespaceScope(Span), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may want to tweak the error message here, for the user's sake. The word "namespace" won't make sense to them as we don't want them using the namespace
keyword anymore, and they won't know what "implicit namespaces" are.
Maybe just state what we don't want to happen, like:
#[error("export statements are only allowed in a namespace scope")] | |
#[diagnostic(code("Qsc.Resolve.ExportFromNonNamespaceScope"))] | |
ExportFromNonNamespaceScope(Span), | |
#[error("export statements are not allowed in a local scope")] | |
#[diagnostic(code("Qsc.Resolve.ExportFromLocalScope"))] | |
ExportFromLocalScope(Span), |
or
#[error("export statements are only allowed in a namespace scope")] | |
#[diagnostic(code("Qsc.Resolve.ExportFromNonNamespaceScope"))] | |
ExportFromNonNamespaceScope(Span), | |
#[error("export statements are not allowed in a callable body")] | |
#[diagnostic(code("Qsc.Resolve.ExportFromCallableBody"))] | |
ExportFromCallableBody(Span), |
or maybe something better if you can think of it.
@@ -262,6 +272,8 @@ pub enum ItemKind { | |||
Open(Idents, Option<Box<Ident>>), | |||
/// A `newtype` declaration. | |||
Ty(Box<Ident>, Box<TyDef>), | |||
/// An export declaration | |||
Export(ExportDecl), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do we handle common item properties, like doc comments, attributes and visibility modifiers, on export and import items?
/// doc comment!
@Config(Base)
internal import Bar.BarOperation;
I guess the current answer is that they don't cause any errors and have no effect, but is this desirable?
This PR introduces exports -- a namespace can export any symbol it has access to. External packages (consumers of this package) will only have access to explicitly exported items.
Next up will be imports, which will allow for importing of specific items.
How it works
Exports are a type of
Item
, and they appear inside of namespaces (implicit or explicit). Exports are paths, which are resolved to local item ids in the resolver. They are then bound to the scope of that namespace. After that, the exported item is added to the api surface of the namespace.When we support external package dependencies, we only want to allow importing of explicitly exported items. At that time, we will add a flag to the items to denote if they originate from an export.
This PR also supports export aliases:
export { Foo as Bar };