Repository navigation
Five compiler/stdlib defects from the examples/ survey (#1150) - #1284
Merged
Merged
Conversation
added 5 commits
September 22, 2026 08:25
… (String Types) The rule that safe With has no `&mut T` lives in specification §3.1; the three sites cited §15.1, which is String Types. The two tests that pin the message now pin the section too. (#1150 survey)
Spec §2.4: any receiver mode other than move on a Drop impl's `drop` is an error with a fix-it. The error existed (#642) but had no fix-it; it now adds `= help: write \`move fn drop()\``. A bare `fn drop()` in `impl Drop` is fine: the compiler gives it the trait's move receiver. (#1150 survey, examples/nebula)
The failed single-thread proof already labels the construct that introduced concurrency; its help said `Atomic[T]` generically. It now reads the global's binding type and offers `use Atomic[i32], wrap in Mutex, or assert with \`unsafe\``, the spec's worked example. (#1150)
…g file, with the remedy comptime_transform_module emitted every derive diagnostic against Sema.local_file_id, which is whatever file the pre-sema checked last, so a module's failed derive(Clone) pointed at a `use` line of the importer (examples/nebula). The loop now sets local_file_id to each declaration's own file, the field diagnostic sits on the field's type node, and a help line names the fix: derive or implement the trait for that type. (#1150)
…ib and compiler conform Spec §18.1: every public stdlib declaration is reachable by name. A `pub fn` whose parameter, return or owner type is private to its module is unreachable by construction, and nothing said so: std.time's `sleep(d: Duration)` and std.json's `JsonParser.new()` shipped that way (#1150 survey). collect_fn_decl now walks every pub signature's type nodes (named, generic and their arguments, pointer, reference, optional, slice, array, tuple, fn types, and the method owner) and reports each private type at its node, with the help `add \`pub\` to the declaration of 'T'`; type parameters, Self and primitives are exempt, and a private alias of a primitive is a hit. The check is run over every std module, the compiler, tools, build and the test corpus; each hit gets `pub` on the type: std.time Duration, std.json JsonParser, std.alloc TempArena, std.hash Hasher and DefaultHasher, std.thread JoinHandle, and in the compiler ProjectConfig, CompilationConfig, LockEntry, LockFile, Compilation, ConanLibraryScan, ComptimeValue, MirBody, MirModule and Sema. Five test programs declared private types behind pub fns and are made to conform (the C-ABI shape module emits byte-identical declares). examples/ has no hit.
This was referenced Sep 22, 2026
Closed
ehartford
added a commit
that referenced
this pull request
Sep 22, 2026
…ature (§18.1 check, #1284, meets #1283) (#1306) Main at 4b3a3c2 does not build: #1284 added the §18.1 check that a pub signature names only public types, and #1283 added with_channel_create, whose signature names the private alias ChannelDropFn in rt/channel_runtime.w. Each PR was green alone; the runtime objects compile in their own build targets, outside the check's sweep of lib/std, src and tools. The alias is public; :dev is green under the seed. Co-authored-by: Eric Hartford <[email protected]>
ehartford
added a commit
that referenced
this pull request
Sep 22, 2026
…ts lane in the battery (#1150) (#1308) * examples: fizzbuzz spells the mixed-arm match tail as f"{i}" (§18.2, D55 ruling 6; #1150) A match whose arms do not share a Display type yields nothing joinable; the spec's fix-it is the f-string. Example updated under the examples policy (D55 ruling 4). Compiles against the print-over-Display stage1; the installed compiler still rejects the str/&str join. * examples: ephemerality-and-lowering observes its tasks and synchronizes its globals (§14.7, §9.1c; #1150) The `let _ = task` detach spelling was retired (§14.7: statement position already means detach; a bound task must be observed). The example now demonstrates the replacement: an async main awaits the scope demo, the tracked tasks are bound and awaited, and the package test is itself async. The test's defer-order probes become Atomic counters, since the async test makes the program concurrent (§9.1c rule 2). Typed bindings feed the Atomic stores until #1287 is fixed. Rewritten under the examples policy (D55 ruling 4); the README's Zig-bootstrap commands are replaced with `with check`/`with test`. * examples: the ecs, service and nebula package tests follow the current spec (§3.1, §3.8, §7.4, D32; #1150) Constructors with no receiver move out of the extend block to top-level `fn Type.new` (§3.1 location rule); functions that only observe an array or a struct take `&T` (§3.8, the signature states ownership); the record-update test spells the record update it claims to test (`{ base with port }`, §7.4) instead of moving fields out one by one (D32, §2.2). Updated under the examples policy (D55 ruling 4). * examples: nebula rewritten to the current spec (§2.4, §3.1, §3.8, §7.2, §10.2, §10.9, §14.7, §14.10; #1150) - `move fn drop()` is the destructor receiver (§2.4); the Database constructor is a function of the type (`fn Database.open`, §3.1 location rule) and the methods use the keyword receiver forms. - Result[Unit, E] functions end with implicit Ok(()) (§10 happy path); main is `async fn main -> Result[Unit, AppError]` and propagates with `?` through `error AppError from DbError, SessionError` (§10.9) instead of hand-written wrapper variants and .expect(). - Functions that observe take `&T` (§3.8): parse_telemetry(&str) clones the bytes it keeps; parse_batch/compute_stats borrow their Vec; the status helpers borrow. - Tracked tasks are bound and awaited (§14.7); a receive uses `rx.recv() ?? break` (§10.4); insert_bulk is generic over SqlRecord. - The select-await race sleeps on the analyzer side so the shutdown branch wins (§14.10); a loser parked in recv() deadlocks the runtime (#1293). Needs #1284 for `Duration`. - The derives on Status/Telemetry are parked with a comment until #1288 (Debug on f64) and #1289 (derive on enums) are fixed; the batch and final-stats builders read 0 until #1290 (#1294) lands. - Package test: record update instead of field-by-field moves (D32). Rewritten under the examples policy (D55 ruling 4). pub marks needed: 0 new (the package already exported its cross-module names). * examples: json_test exercises std.json's safe document surface (§16.11, §11.8; #1150) The example drove the raw jsmn token API with `unsafe { json_parse(...) }`, `&raw mut` and a *mut JsonToken buffer — an application never writes unsafe (CLAUDE.md, `:user-programs-safe`). It now uses what std.json exports for applications: JsonDocument.parse, field views (.field/.raw), Deserialize for primitives and for @[derive(Serialize, Deserialize)] types (nested), and a JsonWriter round trip. The two incomplete-input cases are gone: the safe parse panics on malformed input instead of returning JSON_ERROR_PART. The source copy the round-trip compares against is spelled (`js.clone()`; parse takes an owned str). Rewritten under the examples policy (D55 ruling 4); 21 checks pass on the installed compiler. * examples: service rewritten to the current spec (§2.2, §3.1, §3.8, §7.2, §11.8, D32; #1150) - Builder setters are `move fn` and chain (`UserService.builder().with_config(cfg).build()`, §3.1); the constructors with no receiver are functions of the type (`fn UserService.builder`, `fn HttpResponse.ok` ...). - Mutating methods are `mut fn` (create_user, bump_*); request handling is `mut fn` on AppState instead of `&mut AppState` params. - Functions that observe take `&T` (§3.8): validate_create(&req) so the caller keeps the request for create_user; make_welcome_notification, describe_changes borrow their users. - A consumed request's fields vacate from a `var` base with `move` (§2.2, D32); Role and Priority opt into Copy (§11.8) since they are passed by value everywhere. - `pub` on every cross-module name (§18.3): 27 marks (types, methods, constructors, functions) across service.w and http.w; the compiler does not enforce §18.3 within a package today. - describe_changes and the postgres SET builder use the `var` desugaring of §7.2 until #1298 accepts a trailing `if`. Rewritten under the examples policy (D55 ruling 4); the demo prints its original output. Package test updated separately (d3bd2a8f). * examples: json-parser rewritten to the current spec (§2.2, §3.1, §3.8, §10, D22, D27; #1150) - `mut fn` receivers replace `self: &mut Self` (§3.1); the constructors are functions of the type (`fn Tokenizer.new`, `fn Parser.new`). - `Unit` replaces `void`; happy paths return the value and `?`/ `return Err(...)` carry the sad path (§10.2), with .Variant spelling. - The parser consumes its lookahead explicitly: `advance()` moves the current token out of the receiver (§2.2 vacate from a mut fn) and loads the next, and parse_value dispatches on the consumed token; the loops peek through `&self.current`. (A `match self.current:` moves the field out and blanks it, #1302.) - The tree is observed, never consumed (§3.8): json_to_string and the lookups take `&JsonValue`; json_get_field/json_get_index return Option[&JsonValue] views (D27) and the demo reads them with `if let`. A one-line kv_value helper stands in for `&entry.value` until #1297. - Byte literals replace the ASCII magic numbers, as match guards until a byte literal is accepted as a pattern (#1295); `-1.0` replaces `0.-1.0`; `bump` keeps an explicit Ok(()) until #1296. Rewritten under the examples policy (D55 ruling 4); the demo prints its original output (the error-case positions are the more precise ones the consuming parser reports). pub marks: 0 (single module). * examples: ecs rewritten to the current spec (§3.1, §3.4, §3.8, §7.2, §11.8, §18.3, D22, D27; #1150) - One generic DenseStorage[T] (`extend[T]`) replaces five copies; `get` returns a view (Option[&T]) and `remove` transfers the component out (D27: element access observes, remove transfers). Vec has no swap, so the hole is closed with `Vec.remove` and a re-index. - Systems state what they touch in their signatures (§3.8): the writers (input, player controller, movement, run_frame, spawning) are `mut fn` on World; the readers (collision, render, response, queries) take `&DenseStorage[...]`/`&World`, and run_collision returns its events. - Constructors are functions of the type (`fn World.new`, `fn Vec2.new`, `fn Entity.new`; pub ones with explicit return types); components and math types opt into Copy (§11.8); views that must survive a mutation are taken as typed independent copies (§3.4, D22 contextual Copy); entity_name returns Option[&str]. - `pub` on every cross-module name (§18.3): 68 marks across the six modules (the compiler does not enforce §18.3 within a package today). - World.spawn is spelled spawn_entity until #1303 (a user `spawn` method is intercepted by the scope builtin); DenseStorage.insert carries `-> Unit` until #1296; the spawn helpers return `with ... as mut` builders (§7.2) and so hand back empty Vecs until #1290 (#1294) lands, which is why the despawn demo currently prints nothing after its header. Package test updated separately (d3bd2a8f). Rewritten under the examples policy (D55 ruling 4); the demo otherwise prints its original output. * examples: async-auction rewritten to the current spec (§9.1c, §10.2, §14.7, §14.10, §14.11, §14.15; #1150) - Every bidder gets its own sender: `tx.clone()` per tracked task, the channel closes when the last sender drops (§14.15, D55 ruling 5). - The verification counters are Atomic[i32] (§9.1c rule 2): the program is concurrent, so bare mutated globals are not safe. - The stale "BUG DISCOVERED" workarounds are gone: `.await?` chains, Result.is_err(), task.cancel(), `select await biased` (§14.10) and await_all/await_first over a Vec of tasks (§14.11) are written the way the spec says; a receive is `rx.recv() ?? break`; Bid is Copy. Rewritten under the examples policy (D55 ruling 4). Needs #1283 and #1284 (both merged 2026-09-22); verified against a stage1 of the rebased tree. * examples: channels pipeline demo 3 is a fan-in through cloned senders (§14.15; #1150) Demo 3 read five values from a channel that only ever receives three, so the program hung (the survey's 'run hangs'). It now shows the thing its title promised: two producers feeding one channel through their own clones of the sender (§14.15, D55 ruling 5), and a consumer draining it. std.channel is imported so the Clone impl is in scope. Verified with a stage1 of this tree (post-#1283). Updated under the examples policy (D55 ruling 4). * build: examples-tests lane — every example is built, run and tested in the battery (#1150, D55 ruling 4) build/examples.w declares the lane's contract: the single-file examples are built with the release compiler and run, the packages are built in their directory and run, the package tests run under `with test`, and bench_demo.w is checked. Each step has a timeout and its stdout/stderr captured under out/test-graph/examples-tests; one red step fails the target, and the target is a dependency of :test, so a rotted example turns the battery red. The list is explicit, so untracked user work beside the examples (examples/spiral) is not on it. The four committed Mach-O build outputs (examples/hello, channels/pipeline, json-parser/json, service/src/main) are removed: the lane builds them under out/. * examples: the service router observes the request through references (§3.8, D32; #1150) `match (req.method, req.path)` moves two fields out of a request the handler still needs; main's D32 rule (#1301) now says so. The router matches `(&req.method, &req.path)` and hands the whole request on. --------- Co-authored-by: Eric Hartford <[email protected]>
This was referenced Sep 22, 2026
ehartford
added a commit
that referenced
this pull request
Sep 22, 2026
… every pub fn naming c_int or a header struct (#1309) The §18.1 check (#1284, SemaDecl.check_pub_signature_names_public_types) is correct: it resolves the named type in the same module and reads its pub flag. The migrator's single-file output was genuinely inconsistent: `--no-c-export` makes every non-static function `pub`, while the preamble emitted `type c_int = i32` (and every struct/typedef/enum rendering site in CImport.w emits `type X ...`) privately. So `pub fn verify() -> c_int` named a private alias, and every behav_migrate_*.w test went red on main. The multi-file corpus path never had the problem: it routes every type to defs.w and ci_migrate_publicize_shared_defs prefixes `pub` on each declaration there, which is why lib/std/{re,zl,c_algorithms,tommyds}/defs.w already carry `pub type c_int = i32`. The single-file path now applies the same rule to its type lines (ci_migrate_publicize_types): C has no type visibility, a migrated module's types are its public API, and static functions stay private as before. Corpus modules carry no `type` lines outside defs.w, so the pass is a no-op on them and no re-migration is needed. Verified under the fresh stage2: 26/26 test/behavior/behav_migrate_*.w pass; err_pub_fn_names_private_type, err_pub_method_on_private_type and pub_fn_generic_param_not_private still pass. Co-authored-by: Eric Hartford <[email protected]>
ehartford
added a commit
that referenced
this pull request
Sep 22, 2026
…annel_create, and the rebind fixture's private P under the §18.1 check (#1318) rt-decl-audit compares each exported runtime definition's signature text with its stdlib declaration; #1283's `with_channel_create` spelled its drop_fn parameter through the alias ChannelDropFn while lib/std/channel.w declares `*const fn(*mut u8) -> Unit`, so the audit reported one divergent decl. The definition now spells the type inline (the alias stays for the runtime's private accessors, private again — #1306 made it pub only for the §18.1 check, which no longer sees it in a pub signature). deep-debug-tool-tests' analyze-audit-rebind fixture (build.w) declared `type P` private and `pub fn P.set(...) -> P`; #1284's §18.1 check rejects that. The fixture's type is pub. Under the seed: :rt-decl-audit green, :deep-debug-tool-tests green. 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.
Fixes the five compiler/stdlib defects surfaced by the examples/ survey in #1150. One logical change per commit, each with a test.
examples/is untouched.pub fnsignature may name only public types (a1b509d5).collect_fn_declwalks every pub signature's type nodes (params, return, method owner; through generic args,&/*/?/slices/arrays/tuples/fn types) and reports a module-private type at its node with= help: add \pub` to the declaration of 'T'. Type params,Selfand primitives are exempt; a private alias of a primitive (type Duration = i32) is a hit. Stdlib hits fixed:std.time.Duration,std.json.JsonParser,std.alloc.TempArena,std.hash.Hasher/DefaultHasher,std.thread.JoinHandle(the last was in the prelude closure, so it hit every program). Compiler hits fixed bypubonProjectConfig,CompilationConfig,LockEntry,LockFile,Compilation,ConanLibraryScan,ComptimeValue,MirBody,MirModule,Sema. Five test programs conformed (the C-ABI shape module'sdeclares are byte-identical before/after). Sweeps: everystd.*module,src/main.w, every pub-fn file undertest/,tools/,build/, and all ofexamples/(no hit). Tests:test/compile_errors/err_pub_fn_names_private_type.w,err_pub_method_on_private_type.w,test/behavior/pub_fn_generic_param_not_private.w`.&mut Tdiagnostic cites §3.1, not §15.1 (4a95cb02), three sites;err_auto_ref_no_safe_mut_ref.wanderr_borrow_conflict.wnow pin the section.338222c5):= help: write \move fn drop()`. Verified there was none. Test:err_drop_impl_receiver_fixit.w. Note: a barefn drop()inimpl Dropis *not* a gap —analyzefacts show the compiler gives it the trait's move receiver (receiver=move`).e135d39f). Root cause:comptime_transform_moduleemitted againstSema.local_file_id, i.e. whatever file the pre-sema last checked, so a module's derive error rendered on the importer'suseline with the module's byte offsets. The loop now setslocal_file_idper declaration; the error sits on the field's type node with= help: add \@[derive(Clone)]` to the declaration of 'Status', or implement Clone for it. Whether bare enums satisfy Clone is unchanged. Tests:err_derive_clone_field_span.w(cross-file, pinstelemetry.w:6:30),err_derive_clone_field_help.w`.ca597600). The concurrency-site label (program may run concurrently here (async function call)) and a help already existed on main (a39e82e), so the survey's "only the label" claim did not reproduce; what differed from §9.1c's worked example was the genericAtomic[T]. The help is nowuse Atomic[i32], wrap in Mutex, or assert with \unsafe`from the global's binding type. Test:err_global_race_help_names_type.w`.Verification:
with check src/main.w,build :dev(stage1), the new and touched tests run under stage1, plus the sweeps above. No:fixpoint/:test/battery run yet.Found on the way, pre-existing on main and out of scope:
use std.crypto.poly1305/std.crypto.chacha20poly1305fail to check (15 "cannot assign an owned value to a reference-typed binding" inpoly1305_finish, already #1054);test/d_acceptance/behav_generic_sizeof_param.wfails onprint_i32needing an import.