Repository navigation
D100: a field without pub is private to its package (#2209) - #2212
Merged
Merged
Conversation
added 8 commits
October 6, 2026 01:36
§18.3 (spec v7.27): the rule covers fields. The parser accepts `pub` before a field; the flag rides in the field's alignment slot (FIELD_PUB_ALIGN_FLAG, bit 20: alignments are 0 or a power of two up to 65536), so every copy of the AST keeps it and the extras layout after the fields does not move. Sema strips the bit when it copies alignments and keeps the pub fields by (declaration, field name). A field read or a struct literal naming a field, from another package, is refused when the field is not pub. A distinct type's .value and a C type's fields are exempt (the language's unwrap; C has no privacy). The renderer and the bundle interface writer emit `pub` on exported fields. std marks its API fields pub: the std.cfg Stackify graph types and the code/offset/message of RegexError, ZipError, ZlibError; Vec's fields stay private. The compiler stops reading Vec's fields: empty Vec literals are Vec.new(), raw element addresses come from with_vec_get_ptr (bounds- checked), CiIR frees through with_vec_free, comptime's strtod reads CString through as_cstr().ptr(); all valid under the pinned seed. Vec gains pub as_ptr/as_mut_ptr/capacity for programs that need the buffer. Closes #2209
…ords and C mirrors export their fields - An alias no longer takes over the declaring node of the type it names (record_type_decl_tid), so a declaration's pub fields stay pub however the type is spelled (std.libc's mach_timebase_info_data_t hid them). - A field read through a Box is judged against the payload type. - Codegen masked the pub bit in two align-slot reads it had missed: a pub field became a 1 MiB alignment. The padded struct body now has to agree with TypeLayout's size or codegen stops with an ICE naming the struct. - C record fields are emitted pub (every C field is public); libc's C mirrors, std.build's result records, Context and the reflection records mark theirs pub. - comptime string concatenation passed the reference's address, not the Vec's, to the runtime. - Tests read representation through the public API (as_ptr, as_mut_ptr, as_cstr().ptr(), arena_vec_new_in) or a raw first-word read. - behav_d100_field_through_alias: an alias across a package boundary keeps pub fields readable and private ones refused.
…emanded result The uninferable-parameter diagnostic teaches "annotate the result binding" (#598, no turbofish), but generic free-function calls never read the demand: `var xs: ArenaVec[i32] = arena_vec_new_in(arena)` was refused. check_generic_call now matches the declared return type against the type the call is checked against (binding annotation, parameter, return, field) for parameters the arguments left unbound; a return type that does not match binds nothing. behav_generic_param_from_result covers each demand position.
The four migrated corpora (std.zl, std.re, std.tommyds, std.c_algorithms and the c_algorithms programs) re-promoted with the release compiler: the only change is `pub` on every C record field.
… Unit An audit of every std `pub type` with private fields and no methods: records whose fields are their whole interface mark them pub (std.build's FetchedSource, Artifact, DeclSummary, SourceSpan, DiagnosticSummary, EnvVar, LinkCommand, GeneratedSource, TestOptions, WorkspaceCompilePlan; HttpResponse, IndexSpec, ContextError, CancellationToken). Handles, iterators and contexts with accessors stay private. source-cache-tests' build.w read FetchedSource.rc.
…ields of record type default to that record's zero literal
- An alias no longer stands in for its target's declaration, so a struct
literal written through an alias is now checked for missing fields (it
was skipped). c_import gave a field of another imported record no
default, so `z_stream {}` in a facade failed: the field now defaults to
that record's zero literal, as C zero-initializes it (C11 6.7.9p10).
- build/zlib_gzip.w builds its str through StringBuilder's API.
- The runtime-workers fixture reads a Task's fiber id through the struct's
first word; the bundle-interface demo's Pair and Packet fields are pub.
- da_borrow_vec_drop_element reads the Vec's buffer through as_ptr().
- source-cache-tests prints the child's output when a fetch writes no
report, instead of panicking on the missing file.
…ce storage uses it
Ruled by Eric 2026-10-06. Sema: `T.zeroed()` on a C record (c_import or
@[repr(C)]) is the all-zero value when every field is zero-valid (integers,
floats, bool, raw pointers, nullable fn pointers, an enum with a 0
discriminant, Option whose None is tag 0, and unions/arrays/records of
those); otherwise it is refused naming the field. MIR lowers it to the
established zero operand. FacadeRender renders in-place storage as
`Repr.zeroed()` (§16.2b.3) instead of `Repr {}`, which compiled only
while an alias skipped the missing-field check. The c_import struct-field
default from the previous commit is reverted: it made union and callback
fields invalid.
Spec §16.2b.3 gains the zero-validity rule; decision log D101. Follow-ups:
#2214 (migrate {0}/memset to zeroed), #2215 (fn-pointer fields nullable?).
Tests: behav_c_record_zeroed, err_c_record_zeroed_fn_pointer,
err_c_record_zeroed_enum_without_zero.
Contributor
Author
|
Battery GREEN on 825f5b9 (based on main bde8954): gate 511s, uat 25s, battery-checks 916s. Since the first draft: alias no longer stands in for its target's declaration (closes the missing-field hole through aliases); D101 (Eric 2026-10-06) T.zeroed() on zero-valid C records, facade in-place storage renders Repr.zeroed(); std data-record audit; generic parameters infer from the demanded result. Follow-ups: #2213, #2214, #2215, #2216. |
ehartford
marked this pull request as ready for review
October 6, 2026 15:25
ehartford
pushed a commit
that referenced
this pull request
Oct 7, 2026
…nversions bind nothing, operands before the outer demand (D106) mission.md law 2 now states the two phases and the order; §4.9a carries the same sentence beside the value→Option conversion; D106 records the tension (law 2's "never solves a type variable" against #2212's generic result parameter and D103's "never in inference") and the inner-first ruling for `let x: Option[i32] = ident(3)` — `Some(ident(3))` at `T := i32`, never `ident(Some(3))`. The compiler already does this (measured on main); the fixture pins it with `ident` printing the size of the `T` it was instantiated at.
ehartford
added a commit
that referenced
this pull request
Oct 7, 2026
…nversions bind nothing, operands before the outer demand (D106) (#2241) mission.md law 2 now states the two phases and the order; §4.9a carries the same sentence beside the value→Option conversion; D106 records the tension (law 2's "never solves a type variable" against #2212's generic result parameter and D103's "never in inference") and the inner-first ruling for `let x: Option[i32] = ident(3)` — `Some(ident(3))` at `T := i32`, never `ident(Some(3))`. The compiler already does this (measured on main); the fixture pins it with `ident` printing the size of the `T` it was instantiated at. Co-authored-by: Eric Hartford <[email protected]>
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.
Fields follow D100's rule (§18.3): a field without
pubis visible throughout its package;pubexports it.pubbefore a field name, in both record forms; the bit rides in the field's align slot (FIELD_PUB_ALIGN_FLAG), masked at every alignment reader.field 'T.f' is private to its package). A Box is judged by its payload type; an alias no longer takes over its target's declaring node (it hid std.libc'smach_timebase_infofields behindmach_timebase_info_data_t). Distinct.valueand C-import types are exempt.as_ptr,as_mut_ptr,capacity; compiler sources use the runtime seam until a seed carries them.pubdiffers).var xs: ArenaVec[i32] = arena_vec_new_in(arena)), as the uninferable-parameter diagnostic already taught.Tests: err_d100_private_field_read, err_d100_private_field_literal, behav_d100_field_visibility, behav_d100_field_through_alias, behav_generic_param_from_result; representation-reading tests use the public API.
Stage1 corpus: 3395 files; the only failures are behav_1944_comptime_snapshot_memory and behav_rt_in_unit_check_lane, which fail identically under main's stage1 (bde8954).
Battery pending.