Repository navigation
import: keep the prelude out of module imports - #279
Merged
Merged
Conversation
A native Dang module import's namespace was the module's own type and value
scope, which hang off the prelude and the builtins, so `Lib.toString(1)`,
`Lib.Path("a")` and `let p: Lib.Path! = …` all resolved through it. Like a
schema import's, the namespace now holds only what the module defines.
Importers see the module's declarations alone: its type scope's primary
layer, behind an overlay with nothing beneath so it keeps an import's
identity instead of unifying like a record, and at runtime a copy of its
scope's own public frame. The module's own code keeps the prelude in scope
as before.
A top-level `let` was also reachable qualified (`Lib.salutation`,
`Lib.{{salutation}}`), though the docs promise `let`s stay private across
the boundary; checkMemberAccessible now rejects it, and it is left out of
the runtime namespace. The namespace prints as the import that loaded it
(`field "Path" not found in Lib`, `cannot compare Lib! with Lib2!`) rather
than as a record listing the module's `let`s.
Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
225bfa7
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://e7e51499.dang-3kk.pages.dev |
| Branch Preview URL: | https://dang-module-exports.dang-3kk.pages.dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A native Dang module import (
[imports.Lib] path = "./lib") now exposes only the module's own public declarations. Dang's builtins and prelude, which the module's own code still uses as usual, are no longer re-exported throughLib.Problem
The import's namespace was the module's own type scope and value scope. Both hang off the prelude and the builtins, so any of their names resolved through the import, both in type checking and at runtime:
Lib.toString(1)Lib.Path("a")let p: Lib.Path! = …The same leak let a module's top-level
letbe read qualified (Lib.salutation,Lib.{{salutation}}), even though the docs saylets stay private across the module boundary.Change
Lib == Lib2is stillcannot compare Lib! with Lib2!.checkMemberAccessiblerejects a module's top-levelletthrough its namespace, covering both.and{{ }}.lets. Examples:field "Path" not found in Libtype "Path" not found in Lib"salutation" is private to module Lib and cannot be accessed from another moduleInside the module, nothing changes: its code sees the prelude and builtins as before.
Tests
import_dang_qualified_builtincoversLib.toString(1).import_dang_qualified_preludecoversLib.Path("a/b").import_dang_qualified_prelude_typecoverslet p: Lib.Path! = ….import_dang_private_toplevelandimport_dang_private_toplevel_selectioncoverLib.salutationandLib.{{salutation}}.tests/importlibnow usestoStringandPathinternally.test_import_dang_module.dangchecks that those results reach importers through the module's ownpubnames.pkg/dang/import_dang_test.go:toString,print,Path,Random,JSONor itslets.Maintainer decisions
pubdeclarations, not the prelude or builtins; inside the module, the prelude stays visible as usual.