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
Resolution rules for nested parts with imports #3726
Comments
Can you elaborate on how
Is solved by your proposal? Does it required the part file to use import prefixes in some particular way to be safe from the parent library imports causing problems? I think we should have a mechanism where a part file can have a clean slate and not inherit any imports or import prefixes. (I think that should be the default, but it doesn't need to be the default for the mechanism to be worthwhile.) Can we use some syntax in the |
The full specification is in this PR: #3800 The part file imports always take precedence over inherited imports from the parent file. So do any name declared by the library itself, as always. Having the part file inherit the parent file's imports is necessary for backwards compatibility. Adding a way to have a part file not include the parent file's imports is definitely possible. Still, something like |
I do think that from a technical perspective, macros wouldn't actually need the ability to hide the parent imports, if they are also allowed their own prefixed imports. This would make some of the more string-based apis work (for example, But, I don't believe this is the behavior most people actually want for parts generally. So, I would not make it the default if it was only up to me. I would only make it an option, just to be less breaking for existing codegen. Which, isn't a super compelling case for the option either. |
This is an attempt to specify how nested part files with imports, and parent file import inheritance, should work.
This assumes that part files can contain import, export and part directives.
That could be the result of unifying part files and library augmentation files.
Recursive part files with imports
Goals:
The third item allows macros to create self-contained code that doesn't depend on inheriting imports (as long as the macro author cooperates, if they write raw strings into the generated code, anything can happen).
Assumptions:
Import scopes
A library introduces a declaration scope and an export scope, as usual.
A file with imports introduces two scopes:
A file without imports can be said to introduce those scopes as well, they're just empty. Per the goals, that should give the same effect.
Each import without a prefix introduces names and associated declarations into the file's import scope. As usual, those names can be conflicted if multiple imports introduce the same name.
Each prefix which there is an import for in the file, introduces a name into the declared prefix scope, bound to a scope/namespace for that prefix. (One entry and scope per different name, even if multiple imports use the same prefix name.)
Each import with a prefix introduces names and associated declarations in the the corresponding prefix-named scope. Again conflicted names are remembered as such.
Declarations in a file introduce declarations into the declaration scope of the library. Augmentations introduce augmentations to a declaration. (The declaration scope maps names to one declaration and a sequence of zero or more augmentations. The order of augmentation application isn't relevant here.)
With all this, we can define the scope conflict errors and lexical scopes for each file:
import
s.)That is:
part
path.Exports
An export in a part file is added to the export scope of the library, just as if it had occurred in the main library file. Any conflict is a compile-time error.
The text was updated successfully, but these errors were encountered: