Repository navigation
D100: package-wide visibility, internal paths, method privacy (#2186) - #2210
Merged
Merged
Conversation
added 7 commits
October 6, 2026 00:09
§18.3: cross-module access to a non-pub symbol is a compile error, for functions, types, constants and globals; a method is a function, and a call from another module reached a private one (BTreeMap.key_at, an unchecked raw-pointer helper, segfaulted from user code). The method call resolution checks the resolved method's pub flag and module; a method of a trait impl is reached through the trait and is exempt. Closes #2186
…e keeps it
The 2026-10-05 reseed restored link-compiler from the build store
('[cache] link-compiler: restored') without with.unstamped.dSYM, which no
target declared, and :install-user installed the compiler with no debug
info, blaming the SDK. stage1, stage2 and the release link declare the
dSYM where the SDK links dsymutil; the install message names what is
missing instead of guessing why.
…package (#2186) Spec v7.27 §18.3/§18.4 (D100): without `pub`, a declaration is visible throughout its package, and another package is refused. The frontend (Zcu.package_key_map) gives each module path its package: std, the nearest with.toml, else the program; Sema's pub check compares packages. `pub` is waived inside a package, the import is not. Methods are checked by package alone (reached through a value). Another module's C expansion stays an import (§18.2), reachable only by the c_import rule, never by package visibility. Privacy errors say 'private to its package (declared in …)' and a method error labels the declaration. The cross-package fixtures get a real package boundary (lib/visibility/with.toml); the per-file privacy tests follow the spec: a program's own modules see each other's private names. Closes #2186
D100's third point: an unchecked helper must not rely on privacy alone. slot_key/slot_value read through the runtime's pointer, which is null for a removed or out-of-range slot, and slot_take loaded an entry the runtime never wrote: undefined behavior for any std caller that skipped slot_live. Both backends now test the runtime's answer and panic with 'map slot holds no entry'. User code cannot reach them (Sema refuses the accessors outside std); std's own walks check slot_live first, so no test reaches the panic. BTreeMap.key_at, #2186's original segfault, is already an indexed (bounds-checked) read on main: BTreeMap.new().key_at(0) panics 'index out of bounds'.
…ent's tree §18.3 (spec v7.27): Resolve refuses a `use` whose target has a segment named `internal` unless the importer sits inside the tree rooted at that segment's parent; the standard library is one tree whichever spelling names it (lib/std, <embedded-std>), so std.tls, std.http and std.crypto keep importing std.internal.str_abi and a user program cannot. Both user-import sites are gated (a parsed use and an interface's use lines); the compiler-injected std.box import is not internal.
…s are reported The battery caught it: the gate lived in Resolve, whose diagnostics the frontend turns off (resolve_from_root_pool_with_prefix(..., false, ...)); it computed the right refusal (lldb: a 131-byte message for gadget.internal.core) into a muted channel, and both refusal tests checked ok. The frontend now walks every `use` of the merged program once the module graph is loaded (check_internal_imports_frontend), so one pass covers the eight places that load a module. The build's bundle-interface and pcre2 checks and tools/publish_private_symbols.w read the new 'private to its package (declared in …)' wording.
Contributor
Author
|
Battery GREEN on 8cc0a1c: gate rc=0 544s, uat rc=0 15s, battery-checks rc=0 890s. |
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.
Closes #2186.
D100 (spec v7.27, #2207), implementation, first layer:
pub, a declaration is visible throughout its package; another package is refused. The frontend gives each module its package (std; the nearestwith.toml; else the program), and Sema compares packages. Inside a packagepubis waived, the import is not. Methods are checked by package alone (A non-pub method is callable from another module (§18.3) #2186). Another module's C expansion stays an import (§18.2), never package-visible.internalpaths. A module under aninternalsegment is importable only from its parent's tree. The check runs in the frontend over everyuseof the loaded program. User programs cannot importstd.internal.*; std's own modules can.slot_key/slot_value/slot_takepanic on a dead slot in both backends. A non-pub method is callable from another module (§18.3) #2186'sBTreeMap.key_atsegfault is a bounds-checked read on main.with.tomlboundary.Measured: stage1 checks src/main.w clean (per-file privacy reported 31,102 errors).
Follow-ups filed: #2209 (field privacy), #2208 (std's raw-pointer helpers become
unsafe fn).Battery: GREEN on 8cc0a1c (gate 544s, uat 15s, battery-checks 890s).