Skip to content

D100: package-wide visibility, internal paths, method privacy (#2186) - #2210

Merged
ehartford merged 7 commits into
mainfrom
method-privacy
Oct 6, 2026
Merged

ehartford merged 7 commits into
mainfrom
method-privacy

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Closes #2186.

D100 (spec v7.27, #2207), implementation, first layer:

  • Package-wide visibility. Without pub, a declaration is visible throughout its package; another package is refused. The frontend gives each module its package (std; the nearest with.toml; else the program), and Sema compares packages. Inside a package pub is 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.
  • internal paths. A module under an internal segment is importable only from its parent's tree. The check runs in the frontend over every use of the loaded program. User programs cannot import std.internal.*; std's own modules can.
  • No unchecked map slot reads. slot_key/slot_value/slot_take panic on a dead slot in both backends. A non-pub method is callable from another module (§18.3) #2186's BTreeMap.key_at segfault is a bounds-checked read on main.
  • Debug info survives the build store. A compiler link's dSYM is a declared output.
  • Tests written for per-file privacy now follow the spec; cross-package cases have a real with.toml boundary.

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).

Eric Hartford 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.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on 8cc0a1c: gate rc=0 544s, uat rc=0 15s, battery-checks rc=0 890s.

@ehartford
ehartford marked this pull request as ready for review October 6, 2026 08:07
@ehartford
ehartford merged commit bde8954 into main Oct 6, 2026
@ehartford
ehartford deleted the method-privacy branch October 6, 2026 08:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A non-pub method is callable from another module (§18.3)

1 participant