crates.sage_ir.symbols.kind_wrappers

Symbol supports heterogeneous membership and resolution results. Operations whose meaning requires a definition kind accept the corresponding kind-specific wrapper; conversion into Symbol preserves identity, checked recovery accepts the right kind, and recovery of a wrong kind fails.

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

Implementation

Implemented crates/sage-ir/src/symbol/mod.rs:330–335

sage_ir::symbol · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.symbols.kind_wrappers`
define_kind_symbols! {
    #[sage::item(crate::symbols::Symbol)]
    pub struct Symbol<'db> { data: SymbolDataPriv<'db> }
    pub enum SymbolData<'db> { .. }


}

See more source ↗

Tests and review

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

Implemented sage_ir::external_use_roundtrip_preserves_kind_and_identity

crates/sage-ir/tests/kind_wrappers.rs · test:kind_wrappers

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.symbols.kind_wrappers)]
fn external_use_roundtrip_preserves_kind_and_identity() {
    let db = Database::default();
    let external = SymExt::new(&db, CrateNum(1), DefIndex(2), SymExtKind::Use);
    let wrapper = UseSymbol::Ext(external);
    let symbol: Symbol<'_> = wrapper.into();

    assert_eq!(symbol, Symbol::from(external));
    let SymbolData::UseSymbol(recovered) = symbol.data(&db) else {
        panic!("external use must recover as a use wrapper");
    };
    assert_eq!(recovered, wrapper);
    assert_eq!(symbol.module(&db), None);
    assert_eq!(symbol.trait_symbol(&db), None);
}
}

See more source ↗

TODO sage_meta::todo::symbols_kind_wrappers

crates/sage-meta/tests/representation_spec.rs · test:representation_spec

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_ir.symbols.kind_wrappers)]
    fn symbols_kind_wrappers() {
        // TODO: Complete compile-time/API conversion and local/external dispatch coverage
        // for every supported symbol kind.
    }
}

See more source ↗

Review: Accepted · Codex ci_kind_wrappers subagent.

Reviewed the complete kind_wrappers claim, its single ordinary implementation association in symbol/mod.rs, both associated tests, and captured model/database setup context. Requirements are heterogeneous Symbol membership/results, kind-specific operation receivers, identity-preserving erasure, correct-kind recovery, and rejection of incorrect-kind recovery. The macro creates one private local discriminant per represented kind plus an external interned handle, and public SymbolData variants for kind-aware matching. From implementations move the exact local or external handle into Symbol without allocating a new definition; data() reconstructs the corresponding wrapper using the local discriminant or external kind. Module and enum item interfaces return heterogeneous Symbol slices, while FnSymbol::sig, TraitSymbol::sig/items, EnumSymbol::variants and ModSymbol::expanded_module_items have kind-specific receivers. Their semantic producer algorithms are outside this conversion claim. module(), trait_symbol(), and external_adt() discriminate recovered variants and reject represented mismatches with None. Local-only intrinsic and macro-invocation kinds remain local payload variants. Raw unsupported external kinds reaching the existing todo branch are not represented kind wrappers; this review does not certify support for them or arbitrary forged external wrapper payloads.

The review discovered and reproduced an actual represented-kind error: UseSymbol declared Ext(SymExtKind::Mod), so an external use could not recover via SymbolData. Added the anchor-associated external_use_roundtrip_preserves_kind_and_identity regression and ran cargo test -p sage-ir --test kind_wrappers external_use_roundtrip_preserves_kind_and_identity before the fix: 0 passed, 1 failed, with panic at symbol/mod.rs:331 'not yet implemented: NDM: add all variants here'. The intended result is the same UseSymbol wrapper and rejection as module/trait. Corrected only the UseSymbol external discriminant to SymExtKind::Use, formatted with cargo fmt, and reran the same command: 1 passed, 0 failed. The ordinary regression visibly asserts Symbol identity equals conversion of the original external handle, exact UseSymbol recovery, equality of the recovered wrapper, and None for both wrong-kind module and trait recovery. It would catch the original missing dispatch and accidental conflation with modules.

The second associated entry sage_meta::todo::symbols_kind_wrappers remains explicitly deferred. Its empty body is not behavioral evidence. Its stated prerequisite is complete compile-time/API conversion and local/external dispatch coverage for every supported symbol kind; that requires a per-kind fixture and conversion/rejection matrix and compile-time interface checks. The focused external-use regression does not discharge that broader work, including the local-kind and other external-kind matrices or uniform semantic dispatcher coverage. This is a justified retained test TODO, not a claim that complete test adequacy has been achieved. Existing abstract modeled interfaces likewise are not executable dispatcher tests. No TODO is upgraded or removed. Source inspection supports the current represented-kind conversion mechanism after the minimal fix; test coverage remains honestly partial under its explicit TODO. Fresh start after changes captured the complete current evidence. The focused regression and formatting were executed by this reviewer; broader workspace tests/build and mandatory independent quality reviews are coordinated by root, and no results for them are claimed here.

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