Repository navigation
Conversation
added 4 commits
October 27, 2026 17:46
#2520) Root causes, each observed: Ast.inherit_trait_impl_receivers took the first NK_TRAIT_DECL matching the impl's trait sym, so a user's `trait One` impl inherited std One's absent receiver ("undefined variable self"); method_decl_base_symbol minted `Owner.method` for trait impls, so two traits giving one type the same method collided in the MIR body map ("body index map mismatch") and in fn_decl_nodes ("already defined"); trait_lookup's flat last-wins map fed every impl check, so the newest same-named trait answered for all of them. - Traits register (module, name) candidates like named types; trait_idx_for_impl resolves the trait an impl names from the impl's own module, and the impl checks read it. Ast receiver inheritance prefers the trait declared in the impl's own file. - A trait impl method's symbol is Owner.Trait.method (the trait's $m$ identity segment when the trait name is declared in more than one file, computed AST-only beside colliding type names). - Methods register under (owner, trait, method) beside the bare slot; a second trait contesting a bare name records an ambiguity chain (inherent still wins). Generic methods register the same rows. - Dispatch: when a name is contested, the bound of the receiver's type parameter names the trait (bound_trait_idx_for_method, read by lookup_method_fn/sig and lookup_generic_method_fn); a bare call no bound settles is the §11.4 ambiguity error naming both candidates. Evidence: behav_2520_user_trait_shadows_std prints 3 (was two errors); behav_2520_two_traits_dispatch_by_bound prints "2 1" (was the body-map ICE); behav_2520_two_traits_instance_bound prints "11 12"; err_2520_ambiguous_bare_trait_method gets the §11.4 error. 66 neighboring trait/dyn/impl behavior tests pass on stage1; audit:trait-tables violations=0; ceremony census diff ok. Dyn trait-object dispatch still resolves traits by bare name (find_dyn_trait_method_info) — pre-existing, outside this fix.
mir_emit_multi_index_method_call composed `Owner.multi_index` text to find the callee — a second derivation of a fact Sema owns (D65). Since trait impl methods carry their trait in the symbol (`Matrix.MultiIndex.multi_index`), the composed name no longer exists and every multi-index over a trait impl failed with "missing concrete method `Matrix.multi_index`" (spec_ss11_7_multi_index_and_dispatch on stage1; green on the installed compiler). The lowering now asks Sema's method registry by the receiver's owner key (method_owner_symbol_for_type + lookup_method_fn, the CodegenTraits pattern); text composition remains only where Sema has no row.
…xt (#2520) drop_owner_for_fn_symbol split the fn symbol at its first dot and compared the rest to "drop"; a Drop impl's symbol is now `Owner.Drop.drop`, so current_drop_type_sym stayed 0 inside drop bodies and the §2.4 conditional-field-move check fell through to the generic implicit-move error (err_conditional_drop_field_move). Owner and method now come from method_owner_keys/method_name_syms — the registration facts (D65) — with the text split kept only for unregistered symbols. err_1819_op_route's expected diagnostic names the trait-qualified callee `P.Add.add`.
…2520) Battery fallout of Owner.Trait.method symbols: two consumers still composed the callee from the raw AST spelling. dispatcher_bodies (SemaCheck.w) pushed dyn impl bodies by ast.get_data0(method_node) — Owner.method — so get_sig missed and a dyn call wrote no globals (the err_1827_*_dyn family lost its diagnostic). declare_async_function (CodegenDispatch.w) did the same, so an async trait method had no finalized FnAbi signature (spec_ss11_5, spec_ss14_3). Both now take fn_decl_semantic_symbol[_at], as declare_function_at_inner already did. err_1819_iter_route's expectation names the callee as the diagnostic now correctly spells it: Count.Iter.next.
ehartford
marked this pull request as ready for review
October 28, 2026 00:35
ehartford
added a commit
that referenced
this pull request
Oct 29, 2026
…ame, through dyn too (#2520) (#2795) Reopened on review of #2764: with a program's `trait Unit1: fn one() -> Self` on f64, `f64.one()` was "ambiguous trait method 'one' … candidates: f64.One.one, f64.Unit1.one" though the program never imported std's One, and `dyn One` over a program's own `trait One` resolved std's: "trait 'One' is not object-safe", then, past Sema, "cannot lower dyn trait method 'one' because its return type mentions Self". §18.2 ranks a module's own declarations above imports and imports above the prelude; the trait resolvers took the first visible candidate or the last registered one. - Sema.trait_by_precedence is the one precedence walk: the current module's trait, then another program module's, then std's. lookup_trait_visible is it under visibility; a contested bare method (selected_trait_idx_for_method) takes the receiver's bound, else the one non-std candidate; §11.4's ambiguity stays for candidates of equal rank. - dyn: the object-safety check reads the visible trait's declaration (trait_decl_nodes per trait index), and TY_TRAIT_OBJ records the trait Sema resolved (index + 1 in d1). Codegen keys its trait tables (trait_map, vtables, impl lookups) by Sema's trait identity symbol (trait_identity_symbol: the name unless it collides across files, as impl method symbols are minted), read from the dyn type, the impl (trait_idx_for_impl) or the written `dyn Name` (trait_identity_symbol_ named_at); none re-derives the trait from a bare name. Tests: behav_2520_user_trait_outranks_prelude (2 1) and behav_2520_dyn_user_trait_named_like_std (7) fail on the installed compiler and pass on stage1, with the #2764 suite and 187 trait, dyn, vtable, impl and Box tests. The ambiguity chain (register_method_slot) recorded only the first two candidates for an (owner, method): with std's One, a program's Unit1 and Unit2 on f64, it held One and Unit1, so the precedence rule saw one program candidate and `f64.one()` silently took Unit1's (lldb: selected_trait_idx_ for_method returned Unit1's index). Every later candidate now joins the chain's end. err_2520_two_program_traits_and_std_ambiguous printed `1` on the stage1 without it; the installed compiler reports it only because any two candidates were ambiguous there. A written `dyn Name` names its trait with lookup_trait_named: the visible trait by precedence, else the one registered under the name, as the prelude's Error, which a program reaches with no import, is (spec_ss10_8_error_trait: "unknown method 'source' for dyn trait 'Error'" when the dyn path asked for the import-visible trait alone; lldb: trait_by_precedence returned -1 in the body's context). One answer in every context, so a signature's `&dyn Error` and a body's are one type. 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.
Stack created with GitHub Stacks CLI • Give Feedback 💬