crates.sage_ir.symbols.associated_identity

A trait or impl function, type, or constant has its own stable symbol tied to its associated owner. Repeated requests and movement among siblings preserve that owner and the associated item identity.

Read in specification context · design/crates/sage_ir/symbols.sage

Implementation

Implemented crates/sage-ir/src/local_syms/associated.rs:24–29

sage_ir::local_syms::associated · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.symbols.associated_identity`
pub(crate) struct LocalAssociatedItemKey<'db> {
    pub kind: LocalAssociatedItemKind,
    pub name: Name<'db>,
    pub occurrence: u32,
}

}

See more source ↗

Implemented crates/sage-ir/src/local_syms/consts.rs:11–16

sage_ir::local_syms::consts · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.symbols.associated_identity`
// {anchor}`crates.sage_ir.symbols.local_identity`
pub struct LocalConstSym<'db> {
    pub name: Name<'db>,
    pub scope: ScopeSymbol<'db>,
    pub owner: Option<LocalAssociatedOwner<'db>>,

}

See more source ↗

Implemented crates/sage-ir/src/local_syms/fns.rs:88–93

sage_ir::local_syms::fns · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.symbols.associated_identity`
// {anchor}`crates.sage_ir.modules.parse.detail_firewall`
// {anchor}`crates.sage_ir.types.spans.offset_reuse`
pub struct LocalFnSym<'db> {
    pub name: Name<'db>,
    pub scope: ScopeSymbol<'db>,

}

See more source ↗

Implemented crates/sage-ir/src/local_syms/type_aliases.rs:11–16

sage_ir::local_syms::type_aliases · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.symbols.associated_identity`
// {anchor}`crates.sage_ir.symbols.local_identity`
pub struct LocalTypeAliasSym<'db> {
    pub name: Name<'db>,
    pub scope: ScopeSymbol<'db>,
    pub owner: Option<LocalAssociatedOwner<'db>>,

}

See more source ↗

Tests and review

Indexed tests and the implementation-completeness and test-adequacy review; no test run is implied.

Implemented sage_test_harness::trait_system_tests::moving_associated_items_preserves_symbol_query_keys

crates/sage-test-harness/src/lib.rs · lib:sage_test_harness

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_ir.symbols.local_identity)]
    #[sage::test(crates.sage_ir.symbols.associated_identity)]
    #[sage::test(crates.sage_ir.types.spans.relative_composition)]
    fn moving_associated_items_preserves_symbol_query_keys() {
        use sage_ir::local_syms::LocalAssociatedOwner;
        use sage_ir::symbol::{ConstSymbol, TypeAliasSymbol};
        use sage_ir::ty::TraitItemDef;
        use salsa::Setter as _;

        fn force_target_observer(db: &dyn Db, source_file: SourceFile) {
            let (_, root) = setup_root_module(db, source_file);
            let (owner, items) = root
                .expanded_module_items(db)
                .iter()
                .find_map(|symbol| match symbol.data(db) {
                    SymbolData::TraitSymbol(TraitSymbol::Local(owner)) => {
                        Some((LocalAssociatedOwner::Trait(owner), owner.items(db)))
                    }
                    SymbolData::ImplSymbol(sage_ir::symbol::ImplSymbol::Local(owner)) => {
                        Some((LocalAssociatedOwner::Impl(owner), owner.items(db)))
                    }
                    _ => None,
                })
                .expect("expected a trait or impl owner");
            let (stash, binder) = items.open();
            let symbol = stash[binder.value]
                .iter()
                .find_map(|item| {
                    let symbol = match *item {
                        TraitItemDef::Function(FnSymbol::Local(symbol)) => {
                            assert_eq!(symbol.owner(db), Some(owner));
                            Symbol::from(FnSymbol::Local(symbol))
                        }
                        TraitItemDef::Type(TypeAliasSymbol::Local(symbol)) => {
                            assert_eq!(symbol.owner(db), Some(owner));
                            Symbol::from(TypeAliasSymbol::Local(symbol))
                        }
                        TraitItemDef::Const(ConstSymbol::Local(symbol)) => {
                            assert_eq!(symbol.owner(db), Some(owner));
                            Symbol::from(ConstSymbol::Local(symbol))
                        }
                        _ => panic!("expected local associated items"),
                    };
                    let name = symbol.name(db)?.0.text(db);
                    name.eq_ignore_ascii_case("target").then_some(symbol)
                })
                .expect("expected a target associated item");
            observe_symbol_identity(db, ObservedSymbol::new(db, symbol));
        }

        let cases = [
            (
                "trait function",
                "trait HasItems { fn earlier(); fn target(&self) -> bool { true } }",
                "trait HasItems { fn earlier(); fn added(); fn target(&self) -> bool { true } }",
            ),
            (
                "trait type",
                "trait HasItems { type Earlier; type Target; }",
                "trait HasItems { type Earlier; type Added; type Target; }",
            ),
            (
                "trait const",
                "trait HasItems { const EARLIER: bool; const TARGET: bool; }",
                "trait HasItems { const EARLIER: bool; const ADDED: bool; const TARGET: bool; }",
            ),
            (
                "impl function",
                "struct HasItems; impl HasItems { fn earlier() {} fn target(&self) -> bool { true } }",
                "struct HasItems; impl HasItems { fn earlier() {} fn added() {} fn target(&self) -> bool { true } }",
            ),
            (
                "impl type",
                "struct HasItems; impl HasItems { type Earlier = bool; type Target = bool; }",
                "struct HasItems; impl HasItems { type Earlier = bool; type Added = bool; type Target = bool; }",
            ),
            (
                "impl const",
                "struct HasItems; impl HasItems { const EARLIER: bool = true; const TARGET: bool = true; }",
                "struct HasItems; impl HasItems { const EARLIER: bool = true; const ADDED: bool = true; const TARGET: bool = true; }",
            ),
            (
                "trait function reorder",
                "trait HasItems { fn earlier(); fn target(&self) -> bool { true } }",
                "trait HasItems { fn target(&self) -> bool { true } fn earlier(); }",
            ),
            (
                "trait type reorder",
                "trait HasItems { type Earlier; type Target; }",
                "trait HasItems { type Target; type Earlier; }",
            ),
            (
                "trait const reorder",
                "trait HasItems { const EARLIER: bool; const TARGET: bool; }",
                "trait HasItems { const TARGET: bool; const EARLIER: bool; }",
            ),
            (
                "impl function reorder",
                "struct HasItems; impl HasItems { fn earlier() {} fn target(&self) -> bool { true } }",
                "struct HasItems; impl HasItems { fn target(&self) -> bool { true } fn earlier() {} }",
            ),
            (
                "impl type reorder",
                "struct HasItems; impl HasItems { type Earlier = bool; type Target = bool; }",
                "struct HasItems; impl HasItems { type Target = bool; type Earlier = bool; }",
            ),
            (
                "impl const reorder",
                "struct HasItems; impl HasItems { const EARLIER: bool = true; const TARGET: bool = true; }",
                "struct HasItems; impl HasItems { const TARGET: bool = true; const EARLIER: bool = true; }",
            ),
        ];

        for (label, before, after) in cases {
            let mut database = Database::default();
            let source_file = database.add_source_file("lib.rs".to_owned(), before.to_owned());
            database.attach(|db| force_target_observer(db, source_file));
            database.take_query_log();

            source_file.set_text(&mut database).to(after.to_owned());
            database.attach(|db| force_target_observer(db, source_file));
            let edit_trace = database.take_query_log();
            assert!(
                !edit_trace.contains("observe_symbol_identity"),
                "moving an unchanged associated {label} reminted it:\n{edit_trace}"
            );

            source_file.set_text(&mut database).to(before.to_owned());
            database.attach(|db| force_target_observer(db, source_file));
            let reverse_trace = database.take_query_log();
            assert!(
                !reverse_trace.contains("observe_symbol_identity"),
                "reversing the associated {label} edit reminted it:\n{reverse_trace}"
            );
        }
    }
}

Conditional source: #[cfg(test)]

See more source ↗

Implemented sage_test_harness::trait_system_tests::trait_items_have_stable_symbols_and_owner_identity

crates/sage-test-harness/src/lib.rs · lib:sage_test_harness

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_ir.symbols.associated_identity)]
    #[sage::test(crates.sage_ir.types.binder.owner_parameters)]
    fn trait_items_have_stable_symbols_and_owner_identity() {
        use sage_ir::local_syms::LocalAssociatedOwner;
        use sage_ir::local_syms::associated::local_associated_items;
        use sage_ir::symbol::{ConstSymbol, FnSymbol, TypeAliasSymbol};
        use sage_ir::ty::{SolverEligibility, TraitItemDef};

        with_test_crate(
            "trait HasItems { fn method(&self); fn make(); type Output; const VALUE: u32; }",
            |db, root| {
                let [symbol] = root.expanded_module_items(db) else {
                    panic!("expected one trait")
                };
                let SymbolData::TraitSymbol(TraitSymbol::Local(local_trait)) = symbol.data(db)
                else {
                    panic!("expected a local trait")
                };
                let items = local_trait.items(db);
                let (stash, binder) = items.open();
                let [
                    TraitItemDef::Function(FnSymbol::Local(function)),
                    TraitItemDef::Function(FnSymbol::Local(associated_function)),
                    TraitItemDef::Type(TypeAliasSymbol::Local(alias)),
                    TraitItemDef::Const(ConstSymbol::Local(constant)),
                ] = &stash[binder.value]
                else {
                    panic!("expected function, type, and const items")
                };
                let owner = Some(LocalAssociatedOwner::Trait(local_trait));
                assert_eq!(function.owner(db), owner);
                assert_eq!(alias.owner(db), owner);
                assert_eq!(constant.owner(db), owner);
                assert_eq!(stash[binder.generics].len(), 1);

                let semantic_symbols: Vec<Symbol<'_>> = stash[binder.value]
                    .iter()
                    .map(|item| match *item {
                        TraitItemDef::Function(symbol) => symbol.into(),
                        TraitItemDef::Type(symbol) => symbol.into(),
                        TraitItemDef::Const(symbol) => symbol.into(),
                    })
                    .collect();
                let membership_symbols: Vec<Symbol<'_>> =
                    local_associated_items(db, owner.unwrap())
                        .iter()
                        .copied()
                        .map(Into::into)
                        .collect();
                assert_eq!(membership_symbols, semantic_symbols);

                let method_signature = function.sig(db);
                let (method_stash, method) = method_signature.open();
                assert!(method.value.receiver.is_some());
                assert_eq!(method_stash[method.generics], stash[binder.generics]);

                let associated_signature = associated_function.sig(db);
                let associated = associated_signature.root();
                assert!(associated.value.receiver.is_none());
                assert_eq!(
                    associated.value.method_candidate_eligibility,
                    SolverEligibility::Unsupported
                );
            },
        );
    }
}

Conditional source: #[cfg(test)]

See more source ↗

Review: Accepted · Codex /root/anchor_080.

Fresh review of the current associated_identity claim, all four ordinary implementation entries, and both ordinary associated tests. No TODO or N/A entries exist. The requirements are separate stable function/type/constant symbols for both trait and impl owners, ownership attachment, repeatable retrieval, and preservation of identity and owner when siblings move.

associated.rs supplies LocalAssociatedItemKey(kind, name, occurrence). Both lower_items and membership enumeration compute the same keys and invoke the per-owner tracked local_trait_associated_item/local_impl_associated_item queries. keyed_source_item matches kind/name and occurrence rather than a global sibling position. Consequently adding another named sibling and moving a named item among siblings retain the minting query key. Each of lower_item's three branches creates the corresponding concrete symbol and passes Some(owner). The three other associated implementation files define LocalFnSym, LocalConstSym, and LocalTypeAliasSym with name, scope, and owner as identity fields; CST and span are tracked mutable detail. The complete files, beyond the association previews, were inspected. No relevant behavior is missing from those associations.

The complete trait_items_have_stable_symbols_and_owner_identity test destructures method, associated function, type and constant symbols, explicitly checks method/type/constant ownership, and compares membership enumeration against semantic enumeration for the complete collection. This gives a second retrieval path with actual symbol equality assertions. Its binder/signature assertions are additional evidence for other claims, not a replacement for identity assertions. The complete moving_associated_items_preserves_symbol_query_keys test covers all six combinations of trait/impl with function/type/constant. For each it adds a preceding sibling and separately tests reorder; both edits are reversed. Its helper checks ownership on the visited symbols and retrieves the target by name. The test asserts that a symbol-keyed observer never reruns after either forward or reverse changes. The captured ObservedSymbol helper interns the symbol itself and its tracked observer has no body/detail dependencies. The captured Database logging records WillExecute, drains between observations, and is installed by the default database constructor. Reminting the target would create a new observer key and fail the visible assertions. Fixture setup and persistent source-file handling were captured as dependencies.

Together these tests exercise repeated retrieval, all three concrete kinds and both owners, ownership checks and stable identity under insertion, removal by reversing insertion, and sibling reorder. Source inspection also confirms kind/name occurrence distinguishes same-named entries rather than collapsing them; the explicit movement scenarios use distinct named declarations. All current ordinary evidence is substantive and no deferral is being silently approved. No suspected behavioral violation was identified. No Rust edits were needed. This refresh is source inspection only: I ran review start/read/record commands, not behavior tests; current test execution is delegated centrally to root by the captured instructions, and earlier test results are not asserted as current execution evidence.

Browse crates anchors

139 anchors

Specification anchors and declared coverage
AnchorImplementationTests
crates (139)114 Implemented37 TODO2 N/A74 Implemented107 TODO
crates.sage_inspector (15)13 Implemented1 TODO2 N/A3 Implemented15 TODO
crates.sage_inspector.inspection (15)13 Implemented1 TODO2 N/A3 Implemented15 TODO
balanced_tracesImplementedTODO
canonical_ownershipImplementedImplementedTODO
derive_reflectionImplementedImplementedTODO
detail_free_indexImplementedTODO
deterministic_traceImplementedTODO
durable_navigationN/ATODO
generic_browserN/ATODO
owned_reflectionImplementedImplementedTODO
product_availabilityImplementedTODO
revision_and_demandImplementedTODO
semantic_phase_boundaryImplementedTODO
source_evidenceImplementedTODO
typed_serviceImplementedTODO
unknown_workImplementedTODOTODO
workspace_actorImplementedTODO
crates.sage_ir (90)67 Implemented34 TODO40 Implemented88 TODO
crates.sage_ir.checking (12)12 Implemented3 TODO5 Implemented12 TODO
crates.sage_ir.checking.body (5)5 Implemented2 TODO3 Implemented5 TODO
elaborationImplementedImplementedTODO
expected_typesImplementedTODOTODO
interface_dependenciesImplementedImplementedTODO
isolated_completionImplementedImplementedTODO
operator_callsImplementedTODOTODO
identity_mintingImplementedTODO
owned_productsImplementedImplementedTODO
crates.sage_ir.checking.signature (4)4 Implemented1 TODO1 Implemented4 TODO
body_independenceImplementedTODO
narrow_detailImplementedTODOTODO
owner_binderImplementedImplementedTODO
storageImplementedTODO
symbol_keyed_interfacesImplementedTODO
crates.sage_ir.crate (9)9 TODO9 TODO
explicit_restrictionsTODOTODO
identity_before_detailTODOTODO
incremental_evidenceTODOTODO
narrow_demandsTODOTODO
reexecution_and_invalidationTODOTODO
represented_completenessTODOTODO
restrictions_and_gapsTODOTODO
semantic_query_boundariesTODOTODO
terminal_incompletenessTODOTODO
crates.sage_ir.inference (8)8 Implemented6 Implemented8 TODO
atomic_checkingImplementedImplementedTODO
body_local_quiescenceImplementedImplementedTODO
canonical_boundaryImplementedImplementedTODO
completed_body_boundaryImplementedTODO
numeric_domainsImplementedImplementedTODO
subtyping_and_coercionImplementedImplementedTODO
terminal_obligationsImplementedTODO
transaction_isolationImplementedImplementedTODO
crates.sage_ir.metadata (4)4 Implemented1 TODO4 TODO
explicit_incompletenessImplementedTODO
keyed_reuseImplementedTODOTODO
product_boundariesImplementedTODO
provider_authorityImplementedTODO
crates.sage_ir.modules (8)7 Implemented1 TODO4 Implemented8 TODO
crates.sage_ir.modules.expand (4)4 Implemented2 Implemented4 TODO
completenessImplementedImplementedTODO
dependenciesImplementedTODO
direct_membersImplementedTODO
recursion_and_fixpointImplementedImplementedTODO
crates.sage_ir.modules.parse (4)3 Implemented1 TODO2 Implemented4 TODO
dependenciesImplementedTODO
detail_firewallImplementedImplementedTODO
recovery_completenessTODOTODO
syntax_identitiesImplementedImplementedTODO
crates.sage_ir.resolution (5)5 Implemented1 TODO3 Implemented4 TODO
crates.sage_ir.resolution.lookup (5)5 Implemented1 TODO3 Implemented4 TODO
completenessImplementedTODOImplementedTODO
dependenciesImplementedTODO
expansion_import_ambiguityImplementedImplemented
identity_onlyImplementedTODO
precedenceImplementedImplementedTODO
crates.sage_ir.solver (9)7 Implemented7 TODO5 Implemented9 TODO
alternative_isolationImplementedTODOImplementedTODO
bounded_completenessImplementedTODOTODO
candidate_completenessImplementedTODO
canonical_cyclesTODOTODO
canonical_outputsImplementedImplementedTODO
local_index_firewallTODOTODO
normalization_demandImplementedTODOImplementedTODO
schedule_independenceImplementedTODOImplementedTODO
shared_final_resultImplementedTODOImplementedTODO
crates.sage_ir.symbols (8)8 Implemented4 Implemented7 TODO
associated_identityImplementedImplemented
associated_interfacesImplementedTODO
body_interfacesImplementedImplementedTODO
definition_identityImplementedTODO
external_fact_queriesImplementedTODO
external_identityImplementedTODO
kind_wrappersImplementedImplementedTODO
local_identityImplementedImplementedTODO
crates.sage_ir.types (27)16 Implemented12 TODO13 Implemented27 TODO
crates.sage_ir.types.aliases (2)1 Implemented1 TODO1 Implemented2 TODO
identityImplementedImplementedTODO
revelationTODOTODO
crates.sage_ir.types.binder (1)1 Implemented1 TODO1 Implemented1 TODO
owner_parametersImplementedTODOImplementedTODO
crates.sage_ir.types.body (13)4 Implemented9 TODO3 Implemented13 TODO
awaitTODOTODO
closuresTODOTODO
conditional_patternsTODOTODO
coroutinesTODOTODO
diagnosed_recoveryImplementedImplementedTODO
elaboratedTODOImplementedTODO
for_iterationTODOTODO
indexingTODOTODO
macro_expansionTODOTODO
no_inferenceImplementedImplementedTODO
resolved_referencesImplementedTODO
try_residualTODOTODO
typed_provenanceImplementedTODO
crates.sage_ir.types.calls (2)1 Implemented1 TODO1 Implemented2 TODO
dispatch_familiesTODOTODO
selected_semanticsImplementedImplementedTODO
crates.sage_ir.types.lifetimes (2)2 Implemented2 Implemented2 TODO
dummyImplementedImplementedTODO
unchecked_borrowsImplementedImplementedTODO
crates.sage_ir.types.operators (2)2 Implemented1 Implemented2 TODO
lazy_control_flowImplementedTODO
trait_callsImplementedImplementedTODO
scoped_identitiesImplementedTODO
crates.sage_ir.types.spans (4)4 Implemented4 Implemented4 TODO
generated_identityImplementedImplementedTODO
item_originImplementedImplementedTODO
offset_reuseImplementedImplementedTODO
relative_compositionImplementedImplementedTODO
crates.sage_oracle_harness (4)4 Implemented2 TODO1 Implemented4 TODO
crates.sage_oracle_harness.crate (4)4 Implemented2 TODO1 Implemented4 TODO
deterministic_emissionImplementedTODO
exact_comparisonImplementedTODOImplementedTODO
fixed_projectionImplementedTODO
independent_coverageImplementedTODOTODO
crates.sage_stash (5)5 Implemented5 Implemented
crates.sage_stash.storage (5)5 Implemented5 Implemented
handle_ownershipImplementedImplemented
immutable_entriesImplementedImplemented
query_valueImplementedImplemented
rooted_equalityImplementedImplemented
typed_interningImplementedImplemented
crates.sage_test_harness (25)25 Implemented25 Implemented
crates.sage_test_harness.compile_tests (25)25 Implemented25 Implemented
annotation_validationImplementedImplemented
blessing_gateImplementedImplemented
callsite_updatesImplementedImplemented
checking_scopeImplementedImplemented
compiler_conditionsImplementedImplemented
completed_typesImplementedImplemented
coordinatesImplementedImplemented
dependenciesImplementedImplemented
diagnostic_countsImplementedImplemented
diagnostic_locationsImplementedImplemented
editionImplementedImplemented
fixturesImplementedImplemented
grouped_observationsImplementedImplemented
invocationImplementedImplemented
production_executionImplementedImplemented
project_isolationImplementedImplemented
query_captureImplementedImplemented
query_projectionImplementedImplemented
renderingImplementedImplemented
resolved_symbolsImplementedImplemented
review_visibilityImplementedImplemented
rustc_executionImplementedImplemented
rustc_lintsImplementedImplemented
starting_expressionsImplementedImplemented
target_lineImplementedImplemented