Repository navigation
D70 namespaced types reachable when shadowed (#1757); generator stages and g.pull() over view args (#1732, #1737); iterator adapters over any Iter[T] (#1746); generic free calls record view origins; generic instances resolve their template by identity - #1965
Conversation
|
The battery on c1fb5b5 was RED on 25 fixtures, all from this layer; fixed in bd713fd, 75d64eb, 2e81143 (tip 2e81143), each red→green with its original diagnostic:
|
|
Battery GREEN on 6a6d0d7 (seed-driven, |
…ows its short name (#1757) `shapes.Pt` beside a local `type Pt` was refused: types are not displaced (#1703), so the rewritten ident `Pt` resolved by the D29 tier rule to whatever `Pt` means here, and namespace_member failed loudly rather than bind the wrong type. The rewritten ident now carries the module's type identity (Ast.bind_namespace_ident stores the tid, namespace_type_member), and the sites that read an ident as a type — check_ident, the static receiver (static_receiver_named_type, static_receiver_type_is_known) — use it before any short-name lookup. A namespaced type annotation (`let c: shapes.Pt`, parsed NK_TYPE_ASSOC) was silently resolving to nothing and inferring from the initializer (`let c: shapes.Nope = …` compiled); it now resolves by identity in both the mutable resolver and its frozen twin, refusing a type the import does not provide and a private one. The pinned error fixture becomes behav_d70_namespaced_type_shadowed.w; err_d70_namespace_type_missing.w pins the annotation diagnostic.
…1732, #1737) Infrastructure (green): a type parameter bound binds what its parameterized bounds name — `[T, G: Gen[T]](g: G)` called with a generator infers T from G's element type as `g: impl Gen[T]` does (Parser keeps a bound's arguments beside the type-parameter list in Ast.type_bound_args, copied by astpool_clone_deep; Sema binds them after the arguments: bind_type_params_from_bounds, sharing bind_type_params_from_trait_args with the impl-trait path). #1737 (stages, behavior green; two error fixtures red): std.generators' stages hold the generator in a field (MapStage/FilterStage/TakeStage, generic over the generator type) instead of an escaping closure, which §12.2 forbids for an ephemeral capture; a stage over a view-holding generator is ephemeral by §5.2 propagation. record_call_view_origins no longer skips a by-value origin parameter of an ephemeral type, and an inner block's ephemeral-value tail is escape-checked like a tail view. Still red: err_gen_stage_view_mutated and err_gen_stage_escapes_block — compute_expr_view_origin_mask has no NK_STRUCT_LIT case (it handles NK_TUPLE at the sibling line), so `MapStage { g, f }` returned from map carries no parameter origin and `g` never gets escape_view; the stage binding therefore holds no deps and registers no borrow. #1732 (pull, red): g.pull() of an ephemeral generator is accepted; Sema ties the pulled iterator to the generator's origins at the call (gen_pull_view_nodes; expr_is_ephemeral_value/note_view_store honor it) — err_gen_pull_view_escapes and err_gen_pull_view_mutated pass. gen_pull is rewritten to hold the generator in PullCore[G] behind a PullHeader, reached by captureless closures specialized for G. Red: task.w:301/306 `let held = (*(arg as *mut PullCore[G])).source` is an implicit field move out of a raw-deref place (D32), and behav_1745: inside the specialized std body `PullCore[G]` resolves to the user's `PullCore` (generic-inst base looked up by short name). behav_gen_pull_zip/step cascade from those. err_gen_pull_view_args_unimplemented.w pinned the removed error and is retired; behav_gen_pull_view_args.w also needs its lockstep helper not to return collected views (a pre-existing limit, seen on the seed).
§13.2/§13.3: `.zip`, `.map`, `.filter`, `.filter_map`, `.take`, `.drop`,
`.take_while`, `.drop_while`, `.enumerate`, `.chain`, `.step_by`,
`.collect[Vec]`, `.fold`, `.count`, `.for_each`, `.any`, `.all`,
`.none`, `.find` and `.position` on a user type implementing Iter[T]
(std's Pulled[T] included) were "unknown method": the adapters existed
only as intrinsics on the built-in iterator types. They are now written
once in std over the trait — std.traits' `iter_<name>` free fns and
adapter types (Zipped, Mapped, Filtered, …; iter_collect lives in
std.collections, the core prelude being Vec-less) — and Sema resolves
`recv.<name>(args)` and `recv |> <name>(args)` on a type with a declared
`next()` and no method of that name to that fn with the receiver first
(check_user_iter_method, the g.pull() shape; receiver_arg_call_nodes).
The built-in types keep their intrinsic lowering untouched.
Two parser bugs it exposed: a positional struct literal looped forever on
a field it could not parse (`{ it, left: n }` — `it` is a keyword), now
reported once; and `impl Iter[(A, B)]` pushed the tuple's elements into
the impl's trait-argument run, so the trait saw the wrong T — arguments
are laid out after they parse.
Fixtures: behav_1746_user_iter_adapters, behav_1746_tuple_trait_argument,
err_positional_struct_literal_no_progress (each shown red on the seed).
…ge (#1737 stage2 red) record_call_view_origins, since 53ff577, treats a by-value origin parameter of an ephemeral type as an origin itself (its storage holds the views the result carries). For a `fn`/`mut fn` the origin parameter can be `self`, which is a borrowed place, not a value the call received: the call site pushed the receiver binding's own root as a dep of the result, so `self.finish_gen_loop(…, move child)` after `child = self.begin_gen_loop_closure(…)` read as mutating self under a live view of it (src/MirLower.w:8165, :8223; stage2 self-compile red). The in-place receiver (param 0 of a Read/Mut signature) now contributes only its deps — what self views — never its root; a Move receiver and every other by-value ephemeral argument keep the root. behav_mut_receiver_ephemeral_child_view pins the shape (red on the tip's stage1, green on the seed and after the fix); stage1 `check src/main.w` is ok again.
… its fields' origins (#1737) err_gen_stage_view_mutated and err_gen_stage_escapes_block emitted nothing. Two owners were missing, one per layer: 1. compute_expr_view_origin_mask had no NK_STRUCT_LIT case (NK_TUPLE at the sibling line has one), so `MapStage { g, f }` returned from a stage carried no parameter origin and the specialization's `g` never took escape_view. A struct literal's mask is now the union of its field initializers' (collect_expr_view_deps already walked them). 2. With that in place the specialized signature read `g eff=[escape_view]` (explain:effect), and the call still recorded no deps: the generic free-call path — check_generic_call via check_selected_generic_call_args, direct or pipeline — never called record_call_view_origins at all, while the generic method path (:25117) records through its concrete signature. That hole predates this branch: `fn first[T](v: &Vec[T]) -> &T` followed by `v.push` is accepted by the seed. record_call_view_origins now builds the call's arguments by parameter index and delegates to record_call_view_origins_args, which check_selected_generic_call_args calls with its own arg_nodes (a pipeline's lhs first; the arguments are not a contiguous AST run). The in-place-receiver rule of the previous commit moves with it. Fixtures: the two #1737 error fixtures go red→green; err_generic_call_result_views_arg pins the generic hole (red on the seed, green now); behav_gen_stages_view_args and behav_mut_receiver_ephemeral_child_view stay green; stage1 `check src/main.w` is ok.
…ent views what the Pulled views (#1732, #1745, #751) Three owners, one per fact: 1. lib/std/task.w:301/:306 — `let held = (*(arg as *mut PullCore[G])).source` was an implicit field move out of a raw-deref place (§2.2, D32). The closure now takes the cell out and vacates the field: `var cell = *(…)`, `let held = move cell.source`. 2. Inside std.task's specialized body, `PullCore[G]` resolved to the USER's `type PullCore` (behav_1745: "unknown field 'source' for type 'PullCore[…]'"). A TY_GENERIC_INST carries only its base SYMBOL, and every consumer that needed the template declaration — struct_field_type, setup_generic_inst_substitution, type_reflection_field_*, exhaustiveness, debug_fmt, CCodegen's struct test, MirLower's struct-literal field walk — went sym → type_decl_nodes, the flat map holding the newest declaration of that name in any module (the #751 gap collect_type_decl's comment names). Sema now records the template's tid per instance (generic_inst_templates: resolve_generic_type stores the visibility-resolved base it already computed; substitute_type carries it to the substituted instance), and generic_inst_template_tid / generic_inst_decl_node answer by that identity, falling back to the symbol only for an instance that recorded none (an intrinsic's result). struct_literal_decl_node handles a generic instance the same way, and MirLower's literal walk uses it instead of the flat map (the f3005a6 class: no name lookup after Sema). 3. behav_gen_pull_view_args: lockstep's `Some(y) => out.push((x, y))` failed "view `out` may originate from `y`" because `Pulled[&str].next()` returned a view with no origin — the element crosses the coroutine through a raw slot, so the body says nothing. The same helper over Vec iterators passes on the seed, so the gap was the Pulled, not the collected-views shape. note_pulled_next_view_origins (generic method path) ties the element of an ephemeral std Pulled to the receiver's origins, the twin of the `g.pull()` tie-in (gen_pull_view_nodes). behav_1745_user_type_named_like_std_private, behav_gen_pull_zip, behav_gen_pull_step, behav_gen_pull_view_args and the two err_gen_pull_view_* fixtures pass on stage1; stage1 `check src/main.w` is ok. Remaining #751 edge, not addressed here: two GENERIC declarations of one name share the instance cache key (base symbol + args).
…h is only for receivers without one (#1746) user_iter_adapter_fn (64af132) resolved `recv.<adapter>(…)` and `recv |> <adapter>(…)` to std.traits' iter_<name> for any receiver with a declared next() and no method of that name — which VecIter and the intrinsic adapter types also are (impl Iter[T] for VecIter[T] in std): `xs.iter() |> collect[Option[i32]]()` lost the intrinsic's `unsupported collect target` (err_collect_* red), and a VecIter's .filter/.map went through Filtered/Mapped (return type mismatch in behav_iter_pipeline_local, the contextual-join internal error at traits.w:377 in behav_1810_str_view_lookups). The dispatch now stands aside for every built-in iterator type (iterator_owner_symbol): their adapters stay the compiler's intrinsics, as the brief said they would. Green on stage1: err_collect_btree_unimplemented, err_collect_hashmap_non_pair, err_collect_string_bad_elem, err_collect_unknown_target, behav_1810_str_view_lookups, behav_iter_pipeline_local, spec_ss13_3_collect_targets, spec_ss13_3_collection_operations; behav_1746_user_iter_adapters stays green.
… only when its pointee type can carry a view (#1783) note_view_store (1ac4a26) asks expr_is_ephemeral_value whether the stored value can hold a view, so a pulled iterator marked ephemeral by Sema (gen_pull_view_nodes) is stored with its origins. That predicate's NK_UNARY branch recursed into the operand for every operator, so `*r` with `r: &i32` answered yes — the operand's reference, not the value's — and `seen[0] = *r` / `seen[count] = *v` recorded `n` / `v` as origins of `seen` (behav_1783_copy_read_store_is_owned, behav_trie:36 red). The check_unary deref path itself types the result as the pointee and type_holds_callable's comment already states the rule: a Copy read through a reference owns what it holds. UOP_DEREF now answers by the pointee type of its operand (an ident's binding type, else the recorded expression type): `*r` of a `&i32` is owned; `**rr`, `*r` of a `&Vec[&T]` stay ephemeral. (The unary node has no typed_expr_types entry — check_expr returns check_unary's result without recording it — so the operand's type is the one to read.) Green on stage1: behav_trie, behav_1783_copy_read_store_is_owned; err_generic_call_result_views_arg, err_gen_pull_view_escapes, err_gen_pull_view_mutated, err_gen_stage_view_mutated, err_gen_stage_escapes_block, behav_gen_pull_view_args and behav_gen_stages_view_args stay green.
…h their views: an in-place receiver stays an origin unless the body proves its result never points into self (#1737, §21.1 Rule 6) 345b276 made every in-place receiver (`fn`/`mut fn` self) contribute only its deps to a call's result, never its own place, so that `var c = Builder.mk(self.src); c` returned from a `mut fn` would not read as a view of self (the MirBuilder.begin_gen_loop_closure/finish_gen_loop shape; stage2 self-compile red). That dropped the receiver's storage as an origin for every method whose result does point into self: the compiler accepted `fn view() -> &i32: &self.n` followed by `drop(db)` (a plain dangling reference), `V { origin: self }` of an ephemeral receiver (err_view_of_ephemeral_receiver_outlives_it), and every facade child or borrowed text that `borrows param 0` from its resource (err_c_facade_*, err_sqlite_facade_*: 16 lost safety diagnostics). The signature carried one fact — param 0 is an origin — for two cases the seed told apart by over-approximating (every value receiver is an origin, `self.src` included) and 345b276 by under-approximating. Sema now owns the distinction (D65). Beside each signature's view-origin mask it records a THROUGH mask (sig_param_view_through): the origin parameters whose own storage the returned view provably never points into — the result views only what they view. The body computes it with compute_expr_storage_origin_mask, the storage subset of compute_expr_view_origin_mask: `self` held as a reference, `&self.n`, a non-Copy field place and a facade/interface declared origin are self's storage; `self.src` read out of a `&i32` field is what self views; a nested call contributes its callee's through verdict applied to its argument (arg_storage_origin_mask / arg_viewed_storage_origin_mask); a binding and a recorded expression carry the subset (BindingProvenance.view_storage_mask, expr_view_storage_origins), reset to the whole mask by every recorder and narrowed only where proven. Unproven is storage, so a missed shape errs toward the seed's verdict, and an overflowed (negative) mask proves nothing. record_call_view_origins_args pushes an in-place receiver's root unless the callee's through mask names param 0, and records the result's storage subset for the enclosing body. explain:effect prints the fact: `Builder.child` reads `escape_view: origins=[0] through=[0]`; `S.view` reads `origins=[0] through=[]`. Green on stage1: the 16 facade/sqlite/ephemeral-receiver fixtures above (each with its original diagnostic), behav_mut_receiver_ephemeral_child_view, and the generator/facade corpus (338 fixtures); the new stage1 checks src/main.w ok. A probe that the seed over-reports — `let s = b.src_ref()` with `fn src_ref() -> &i32: self.src` — is accepted, while `fn self_ref() -> &i32: &self.n` on the same receiver is refused.
…ger share one capture directory (exit 127 with nothing captured) behav_action_absolute_paths.w and behav_action_absolute_paths_comptime.w run the shared accepted_paths case under the same p7 label, "action_absolute_paths", and the test batch runs the two files at once. p7_run removes and recreates the label's capture directory before it spawns the compiler; the sibling's removal landed between this run's mkdir and its child's open of stdout.txt, so the child exited 127 before exec with nothing captured, and p7_assert_success reported `rc=127` over empty stdout and stderr. Reproduced outside the battery: the runner's sequence against a process removing the same directory in a loop produced 30 exit-127 children in 400 runs, none with the directory to itself. The label is per mode now, as the case directory already was, and p7_assert_success says what 127 means (the child never started: a capture file, the case directory or the compiler path was missing) instead of a bare rc.
…s record of the instance: sizeof[PullCore[G]] in gen_pull, and each Box.new[T] instance's own T (#1766) emit-c-smoke was red on test/emit_c/gen_pull.w: "emit-c could not resolve the type argument '<type:29>' of sizeof in 'gen_pull__sema__870:…:864=1047'". std.task's gen_pull[T, G: Gen[T]] allocates `sizeof[PullCore[G]]()`. The C backend resolves a sizeof type argument with Sema's frozen resolver (CCodegen.w emit_builtin_generic_call_term), and that resolver finds a type parameter only in the active generic substitution frame (SemaCheck.w resolve_type_level_arg_expr_frozen: lookup_generic_subst at the NK_IDENT branch); at codegen no frame is active, so `G` was 0, the NK_INDEX branch returned 0 for `PullCore[G]`, and the emitter failed. The LLVM backend binds the instance's type parameters from Sema's register_concrete_specialization record before every monomorphized body (set_mono_type_bindings); the C backend never did. The same gap miscompiled silently: a receiver instance's bare `T` resolved through a stale binding, so `Box.new` of an A then a B emitted `sizeof(B)` in BOTH instances, and the A was allocated one byte (observed in the emitted C of a two-type probe). Sema now exposes the fact it owns: push_specialization_subst(mono_sym) installs the recorded substitution of a concrete specialization as the generic substitution frame and pop_generic_subst removes it, with a phase bug if a frame is still active at a frozen consumer. CCodegen installs it around every named body and every closure body (under the closure's owning named function, through enclosing closures), and in collect_used_struct_types, which resolved the same type arguments from the root module with no frame and silently skipped what it could not see. The diagnostic spells an index-expression type argument (`PullCore[G]`, not `<type:29>`). test/emit_c/generic_sizeof_mono.w covers both shapes: `sizeof[PC[G]]` under a generic free function and `sizeof[T]` under PC.make[T], two instances each, plus Box.new of two types; the emission failed before the fix, and the LLVM backend prints the same sizes.
Fixes #1757, #1732, #1737, #1746. Six commits.
shapes.Ptbeside a localPt) #1757: namespace idents carry the module's type identity; namespaced annotations resolve by identity and refuse missing/private types.[T, G: Gen[T]](parser kept bound args; Sema binds them after arguments).compute_expr_view_origin_maskgained the NK_STRUCT_LIT case.g.pull()over view args;Pulled[&T].next()views the receiver's origins; lib/std/task.w D32 spelling.iter_<name>fns over anyimpl Iter[T]; Sema resolvesrecv.name(args)on a type withnext(). Two parser bugs fixed (positional struct-literal infinite loop;impl Iter[(A, B)]).Pre-existing holes fixed on the way (each with a failing-first fixture red on the seed): generic FREE calls never called record_call_view_origins (only generic methods did) —
fn first[T](v: &Vec[T]) -> &T+v.pushwas accepted; a TY_GENERIC_INST resolved its template via the symbol-keyedtype_decl_nodes(newest same-named decl wins, the #751 gap) — nowgeneric_inst_templatesrecords the template tid per instance. In-place receivers contribute their deps, never their root, to call view origins (the stage2 self-compile red).Noted, not fixed: two generic declarations sharing one name still share the instance cache key (remaining #751 edge). The generic-call origin recording is new behavior for every generic free call; self-check and gate are green, the battery is the real test. 54/54 gen/pull/D70 fixtures, drop-audit 254/0, gate green on 30f89aa. Battery with the next batch.