Repository navigation
Sema/Frontend: engine corpora never ambient (§18.2); bundle interface fns keep their module identity (#1362) - #1377
Conversation
c4db9be to
24216b7
Compare
24216b7 to
3071f27
Compare
3071f27 to
9766033
Compare
…ed sizeof names its type argument (#1362) The seed-driven battery of main + #1377 went red on four emit-C targets (err_emit_c_dyn_trait_dispatch, err_emit_c_vec_get_disjoint, emit-c-smoke, cli-selfhost-edge-tests build-options-emit-c). None of them reached the construct it tests: under --emit-c the prelude's std.regex compiles std.re in-unit, and emission stopped in std.re first: emit-c could not resolve the type argument 'pcre2_real_code_8' of sizeof in 'find_minlength' (resolved from module 'test/compile_errors/err_emit_c_dyn_trait_dispatch.w') (lldb on the stage2: CCodegen.fail <- emit_builtin_generic_call_term <- emit_builtin_call_term <- emit_term <- emit_fn_body.) The refusals themselves key on nothing #1377 renamed. CCodegen never pointed sema.current_module_path at the function it emits, so resolve_type_level_arg_expr_frozen judged visibility from the compilation root. Before #1377 the root reached std.re.defs over the prelude edge by accident; engine corpora are no longer ambient (§18.2). This is the #705 class the LLVM backend fixed in Codegen.enter_decl. - emit_fn_body sets sema.current_module_path to the function's declaring module (fn_symbol_source_path). - global_decl_tid resolves a global's declared type in its declaring module (resolve_decl_type_frozen). Otherwise an extern var of an engine type failed to resolve and fell to the silent i32 fallback (filed #1429). - The sizeof/alignof failure names the type argument, the function and the module it was resolved from. The old message named none, so the red could not be read without lldb. native-compile-error-tests (889 files), emit-c-smoke and cli-selfhost-edge-tests are green driven by the seed. emit-c-test is red on a pre-#1377 compiler too, for another reason (#1434).
…red stderr instead of dying in ToolFs run_emit_c_smoke_action and run_build_helper_programs_action reported a failed subprocess by reading back its stderr capture with `fs.read_text(<absolute capture path>)`. ToolFs accepts only project-relative paths (tool_path_require_project_relative), so the report itself exited with "ToolFs path escapes project root: .../emit-c-smoke/emit-c-prelude-emit.stderr" and hid the compiler's error (the #1377 battery). run_capture already returns the captured text, so the report uses the result's `stderr`.
|
Battery (seed-driven, new seed) on the PR head 9766033 (main + #1377, with the C-backend module fix and the loud emit-C failure report): build ok, :fixpoint ok, :test ok (no reds — err_emit_c_dyn_trait_dispatch, err_emit_c_vec_get_disjoint, emit-c-smoke, cli-selfhost-edge-tests all green), :test-green ok, :last-green ok. |
…ace fn keeps its module-qualified identity beside a same-named fn (#1362) 1. The §18.2 prelude gate (Sema.decl_visible_from_current_gated) applied only when the target module was in the prelude closure — the prelude modules and the modules they name. std.re.defs sits one edge deeper (prelude -> std.regex -> std.re.defs), so its declarations skipped the gate and module_is_visible_from_current walked the synthetic prelude edge: `u128_mul_would_overflow(1, 2)`, `is_alnum(33)` and `c_int` compiled with no import. Every std target is gated now; a non-§18.2 name resolves from user code only over an explicit import path (module_visible_no_prelude). std_gated_import_note offers the prelude closure's modules first, else any std module declaring the name (displaced declarations included), so the error names the `use`. 2. On-demand interface declarations (Zcu.merge_interface_sections_on_demand) are merged after the tier merge, so #1350's displacement never saw them: a colliding interface fn shared the flat symbol of a user or std fn (D39 interface_yields), and the codegen audit checked the interface signature against the other function ("finalized source type or LLVM parameter disagrees with FnAbi"); with several helpers codegen failed ("declaration check_match has no finalized FnAbi signature"). A colliding interface fn of another module is displaced to `name$in$<module>` (displace_colliding_interface_fns); Sema's lazy interface demand answers to its short name (interface_decl_is_named); the link name keeps the bundle's (fn_abi_module_link_name). Sweep (stage2 check, before = #1364 stage2, after = this tree) over src/, lib/, rt/, tools/, test/, tests/, scripts/, examples/, build.w, build/, build/release_uat_fixtures/ (raylib via `with get c.raylib`) and the docs/blog_posts code blocks: no file newly fails. Behavior: 1134 run, no regressions. Two separate pre-existing bugs found: #1372, #1374. Fixtures: err_1362_bundle_internal_unimported, err_1362_std_helper_unimported, behav_1362_user_fns_named_like_bundle_interface_fns, behav_1362_bundle_interface_collision_audit (audit:all).
…se them, and a public std name keeps resolving (§18.2, #1362) Review of 06ede15 against §18.2 ("Every public declaration of the standard library is available by its unqualified name as the lowest-priority resolution tier"; "Engine packages are ordinary explicit dependencies and are never ambient; a public re-export from the standard library is deliberate promotion into the ambient vocabulary"): gating every std module turned std.string's is_alnum, which programs called unimported, into an error. The rule is now: - Engine corpora (a std module whose directory holds a `bundle.w` root: std.re, std.zl, std.tommyds, std.c_algorithms; record_engine_corpora, read from the interface registry or the source tree, so stage1 and a bundle build classify them too) are never ambient: user code reaches one only through its own `use` of a module of that corpus. module_visible_no_prelude enters an engine module only from the start module or from its own corpus, so `use std.zlib` does not expose std.zl.defs (no facade re-exports; the language has no `pub use`). - Non-engine std keeps the pre-#1362 rule: the D29 prelude gate on the prelude closure, nothing new. - std_fallback_bridge_path: a name that resolved only because an engine twin was reachable over the prelude edge (is_alnum beside std.re.defs') resolves to the unique public non-engine std declaration — the one §18.2's tier 5 names. No program that compiled becomes an error; the full tier 5 is #752 (D29 work item 3, after #751). Closing the leak exposed a context bug it had masked: a generic declaration's type node was resolved in the requesting module (type_layout_generic_struct_field_type -> resolve_generic_return_type_node resolved SortedVec[T]'s `*mut _SortedArray` against the user's imports; lldb: emit_unknown_type_error <- resolve_type_expr <- resolve_generic_return_type_node <- type_layout_generic_struct_field_type <- eager_type_caches_pass). A named type node now resolves in the module whose file holds it (resolve_type_expr_in_owner_module), as a generic fn body already does. Fixtures: err_1362_std_helper_unimported replaced by behav_1362_std_helper_resolves_unimported (compiles, binds std.string's); new err_1362_facade_import_no_engine_internals (`use std.zlib` + check_match). Sweep and behavior run: no file newly fails.
…ed sizeof names its type argument (#1362) The seed-driven battery of main + #1377 went red on four emit-C targets (err_emit_c_dyn_trait_dispatch, err_emit_c_vec_get_disjoint, emit-c-smoke, cli-selfhost-edge-tests build-options-emit-c). None of them reached the construct it tests: under --emit-c the prelude's std.regex compiles std.re in-unit, and emission stopped in std.re first: emit-c could not resolve the type argument 'pcre2_real_code_8' of sizeof in 'find_minlength' (resolved from module 'test/compile_errors/err_emit_c_dyn_trait_dispatch.w') (lldb on the stage2: CCodegen.fail <- emit_builtin_generic_call_term <- emit_builtin_call_term <- emit_term <- emit_fn_body.) The refusals themselves key on nothing #1377 renamed. CCodegen never pointed sema.current_module_path at the function it emits, so resolve_type_level_arg_expr_frozen judged visibility from the compilation root. Before #1377 the root reached std.re.defs over the prelude edge by accident; engine corpora are no longer ambient (§18.2). This is the #705 class the LLVM backend fixed in Codegen.enter_decl. - emit_fn_body sets sema.current_module_path to the function's declaring module (fn_symbol_source_path). - global_decl_tid resolves a global's declared type in its declaring module (resolve_decl_type_frozen). Otherwise an extern var of an engine type failed to resolve and fell to the silent i32 fallback (filed #1429). - The sizeof/alignof failure names the type argument, the function and the module it was resolved from. The old message named none, so the red could not be read without lldb. native-compile-error-tests (889 files), emit-c-smoke and cli-selfhost-edge-tests are green driven by the seed. emit-c-test is red on a pre-#1377 compiler too, for another reason (#1434).
…red stderr instead of dying in ToolFs run_emit_c_smoke_action and run_build_helper_programs_action reported a failed subprocess by reading back its stderr capture with `fs.read_text(<absolute capture path>)`. ToolFs accepts only project-relative paths (tool_path_require_project_relative), so the report itself exited with "ToolFs path escapes project root: .../emit-c-smoke/emit-c-prelude-emit.stderr" and hid the compiler's error (the #1377 battery). run_capture already returns the captured text, so the report uses the result's `stderr`.
9766033 to
69fd294
Compare
|
Stack #1466 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main 1c76062 + #1418 → #1419 → #1425 → #1428 → #1449 → #1377 → #1459 → #1460 → #1461 → #1462 (head cf36211, including the #1449/#1462 Codegen resolution and the fixed #1460): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Each branch holds exactly its tested commits on the layer below. Merge the whole stack: |
…d of being declared int (#1429) global_decl_tid answered `ty_i32` whenever it could not recover a global's type: an `extern var` whose declared type did not resolve, a `let` whose annotation did not resolve (it then took the initializer's type, which may differ from the annotation), and an unannotated `let` whose initializer Sema never typed. The emitted C then declared the global `int` — an extern of another C type read the wrong bytes, a `let` stored its value truncated (AGENTS.md No Silent Fallbacks). Until #1377 the root module's frozen resolution reached the extern branch for any global whose type the root cannot name; #1377 resolves in the declaring module, which removed that route but left the fallback. Now each case calls `fail` with the global's name and kind, the type's spelling and the module it was resolved from, like the sizeof failure since #1377, and returns 0, which both callers already skip. No program reaches these branches on this tree, so no fixture reaches the failure; the fix is that it can no longer be silent. Probed with --emit-c: extern vars of arrays, pointers to arrays, tuples, fn types, Option, Result and Vec, and unannotated lets of arrays, tuples, Option, str, float, bool, suffixed ints and shifts all resolve. Emitting the whole compiler (src/main.w) as C passes every global of every module through the new check: emit_global_var_defs runs before any body, and both the base stage1 and this one then stop in a body on the loud "HashMap traversal lowering is not implemented" limitation. The same probe showed CCodegen.global_init_text zero-initializing every global whose initializer is not a literal (`let SHIFTED = 1 << 3` emits `static int32_t ... = 0`): filed as #1484.
…d of being declared int (#1429) (#1524) global_decl_tid answered `ty_i32` whenever it could not recover a global's type: an `extern var` whose declared type did not resolve, a `let` whose annotation did not resolve (it then took the initializer's type, which may differ from the annotation), and an unannotated `let` whose initializer Sema never typed. The emitted C then declared the global `int` — an extern of another C type read the wrong bytes, a `let` stored its value truncated (AGENTS.md No Silent Fallbacks). Until #1377 the root module's frozen resolution reached the extern branch for any global whose type the root cannot name; #1377 resolves in the declaring module, which removed that route but left the fallback. Now each case calls `fail` with the global's name and kind, the type's spelling and the module it was resolved from, like the sizeof failure since #1377, and returns 0, which both callers already skip. No program reaches these branches on this tree, so no fixture reaches the failure; the fix is that it can no longer be silent. Probed with --emit-c: extern vars of arrays, pointers to arrays, tuples, fn types, Option, Result and Vec, and unannotated lets of arrays, tuples, Option, str, float, bool, suffixed ints and shifts all resolve. Emitting the whole compiler (src/main.w) as C passes every global of every module through the new check: emit_global_var_defs runs before any body, and both the base stage1 and this one then stop in a body on the loud "HashMap traversal lowering is not implemented" limitation. The same probe showed CCodegen.global_init_text zero-initializing every global whose initializer is not a literal (`let SHIFTED = 1 << 3` emits `static int32_t ... = 0`): filed as #1484. Co-authored-by: Eric Hartford <[email protected]>
Fixes #1362. Base: main (#1364 is merged). Commits: 1b87475 (first cut), 4df85ab (revision after review against §18.2), c9947a4 + 9766033 (emit-C battery reds, last section).
The spec (quoted exactly)
§18.1 Modules:
§18.2 Imports:
The rule this PR implements
useof one of its modules. A std module counts as engine when its directory holds abundle.wroot (Sema.record_engine_corpora). That is read from the interface registry, or from the source tree when the corpus compiles from source (stage1, bundle builds), so every stage classifies the same modules. Unimportedu128_mul_would_overflow,check_matchandc_intare errors, and the error names theuseto add.module_visible_no_preludeenters an engine module only from the importing module itself or from another module of the same corpus.use std.zlibtherefore does not bring in std.zl.defs. No std facade re-exports engine names, and the language has nopub use.with updatepinning migration a hard requirement that ships with the tier. Instead:std_fallback_bridge_path) covers a name that resolved only because an engine twin was reachable over the prelude edge (is_alnum,is_digit,to_lower… beside std.re.defs'). Such a name resolves to the unique public non-engine std declaration, which is the one tier 5 would pick.is_alnum(33)with no import compiles and binds std.string's, as before. No program that compiled before becomes an error.name$in$<module>(Zcu.displace_colliding_interface_fns). Sema's on-demand collection matches it by its short name, and its link name stays the bundle's. A user fn named like any bundle interface fn no longer breaksaudit:all.Closing the leak exposed a bug it had hidden: a generic declaration's type names were resolved in the module that asked for them. Proof from lldb on the new stage2, running
checkonSortedVec[i32], stopped on the new error:emit_unknown_type_error ← resolve_type_expr ← resolve_generic_return_type_node ← type_layout_generic_struct_field_type ← eager_type_caches_pass.SortedVec[T] { array: *mut _SortedArray }was resolved against the user's imports. A named type node now resolves in the module whose file holds it (resolve_type_expr_in_owner_module), the same way a generic fn body already does (check_generic_body).Root cause of the leak
src/Sema.w,decl_visible_from_current_gated:Only the prelude modules and the modules they import directly were gated.
std.re.defsis one step further (prelude →std.regex→std.re.defs), so no gate applied. The fallback visibility check (module_is_visible_from_current) then followed the prelude's own import edge and found it. The facade case (use std.zlib→std.zl.defs) went through the transitive walk inmodule_visible_no_prelude.Enumeration against the revised rule
Sweep:
with-stage2 checkon every file, with #1364's stage2 (a9b7fc3) as "before" and this branch's stage2 as "after"; every error line diffed. Scope:src/main.w,lib/,rt/,tools/,test/,tests/,scripts/,runtime/,examples/,build.w,build/,build/release_uat_fixtures/, 3,116 files in all. Also checked: the raylib UAT in awith init+with get c.raylibproject, and the 59 code blocks ofdocs/blog_posts/*.md. Then all 1,134test/behaviorprograms were run on the new stage2. Non-zero exits were rerun serially on both compilers.tests/cimport_scope/test_own_ci.w(legacy, run by no suite) fails before and after. Its error moves from "c_ulonglong is private to module c_user.w" to an enginec_uintgate error; the defect underneath is #1372. Nouseneeded adding anywhere.build/release_uat_fixtures/*.w(raylib included), 59 blog code blocksexpect-stdoutpasses all match. The 81 non-zero exits fail identically on the base compiler (expected panics, check-fail fixtures, no-mainfixtures).usetheir own migrated defs.Fixtures
The four marked "fails on base" fail on #1364's stage2 and pass here.
test/compile_errors/err_1362_bundle_internal_unimported.w:u128_mul_would_overflow(1, 2)with no import is an error withadd: use std.re.defs.u128_mul_would_overflow(fails on base).test/compile_errors/err_1362_facade_import_no_engine_internals.w:use std.zlibthencheck_match(...)is an error withadd: use std.zl.defs.check_match(fails on base).test/behavior/behav_1362_std_helper_resolves_unimported.w:is_alnumwith no import compiles and binds std.string's, next to a userfn is_digit(ch: u8). It passes on base too: it guards against this PR's own regression.test/behavior/behav_1362_user_fns_named_like_bundle_interface_fns.w: a user fn for every non-generic enginedefs.whelper, with regex, zlib and HashMap in use (fails on base with "declaration check_match has no finalized FnAbi signature").test/behavior/behav_1362_bundle_interface_collision_audit.w:audit:allreports violations=0 on the previous fixture. A second program uses SortedVec and hash_index, so all four corpora take part; it runs, and its audit shows no FnAbi or codegen violation (fails on base).The first cut's
err_1362_std_helper_unimportedis removed: it pinned the error that the revised rule withdraws.Evidence: iterate tier only.
with build :stage2is green andcheck src/main.wis ok. The full battery has not run, so this PR stays a draft.Open items
with runin one directory: link fails with undefined rt_*/with_* symbols (shared out/tmp/with_runtime/*.o rewritten mid-link) #1374 (concurrentwith runlink race). Result[str, E].unwrap_or returns a str with the payload's length and a bad data pointer (segfault / garbage) #1363 (Result[str].unwrap_or) also broke the sweep tool until I worked around it.Battery red on emit-C (main + #1377 + #1420), fixed in c9947a4 / 9766033
The branch is rebased on origin/main (04e4934; #1364 is merged, so the base is
main). The two #1362 commits are unchanged by the rebase (git range-diff:=).Four targets failed, all emit-C:
err_emit_c_dyn_trait_dispatch,err_emit_c_vec_get_disjoint,emit-c-smoke, andcli-selfhost-edge-tests(the build-options-emit-c case). None of them got as far as the construct it tests. Under--emit-cthe prelude's std.regex compiles std.re in-unit, and emission stopped inside std.re first. With the diagnostic from this change:CCodegen.fail ← emit_builtin_generic_call_term ← emit_builtin_call_term ← emit_term ← emit_fn_body. The LLVM-only refusals key on nothing Sema/Frontend: engine corpora never ambient (§18.2); bundle interface fns keep their module identity (#1362) #1377 renamed.sema.current_module_pathat the function it emits.resolve_type_level_arg_expr_frozentherefore judged visibility from the compilation root. Before Bundle interface fns leak past the §18.2 prelude gate, and a same-named user fn shares their flat signature (audit:all fails) #1362 the root reached std.re.defs over the prelude edge by accident. This is the Tool-mode compiles of compiler-library tools fail at codegen: unresolved field types (MirBuilder.cur_bb, CiMigrate structs) #705 class the LLVM backend already fixed inCodegen.enter_decl.emit_fn_bodysets the declaring module (fn_symbol_source_path).global_decl_tidresolves a global's declared type in its own module (resolve_decl_type_frozen); otherwise an engine-typed extern var reached the silenti32fallback, filed as CCodegen.global_decl_tid: an extern var whose type does not resolve is silently emitted as i32 #1429. The sizeof/alignof failure now names the type argument, the function and the module.run_emit_c_smoke_actionandrun_build_helper_programs_actionread the absolute stderr capture back through ToolFs, which accepts only project-relative paths, so the compiler's real error was lost. They now reportrun_capture'sstderr(9766033).Evidence, driven by the pinned seed (
WITH=$PWD/src/main src/main build :<target>)::native-compile-error-tests:emit-c-smoke:cli-selfhost-edge-testsThe behavior suite on the rebased stage2 has no new failures against the previous run. The re-sweep of examples, the UAT fixtures (raylib in a project) and the blog blocks shows no new errors.
Filed during this work:
global_decl_tidemits an unresolved extern var's type asi32, silently.:emit-c-test(not part of:test) is red on a pre-Sema/Frontend: engine corpora never ambient (§18.2); bundle interface fns keep their module identity (#1362) #1377 compiler too. The C backend refusesfor (k, v) in map.stage-embedded-objects-objectstays fresh when a .wo bundle is rebuilt, because the.sonly incbins paths. stage2 then embeds stale bundles, and the p7 harness prefers stage2.The full battery has not been re-run. This stays a draft until it is.