crates.sage_ir.checking.body.elaboration

A completed body is an elaborated semantic tree. Successful output contains final types and semantic identities and materializes all type-directed operations used by the source. Method syntax, unresolved names, inference variables, pending obligations, and adjustment recipes do not survive in CheckedBody; Completed bodies are elaborated typed trees owns the cross-cutting representation decision.

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

Implementation

Implemented crates/sage-ir/src/check/expr.rs:20–25

sage_ir::check::expr · lib:sage_ir

#![allow(unused)]
fn main() {
    // {anchor}`crates.sage_ir.checking.body.elaboration`
    // {anchor}`crates.sage_ir.checking.body.interface_dependencies`
    // {anchor}`crates.sage_ir.checking.body.isolated_completion`
    // {anchor}`crates.sage_ir.checking.body.expected_types`
    // {anchor}`crates.sage_ir.checking.body.operator_calls`
    pub(crate) async fn check_with(

}

See more source ↗

Implemented crates/sage-ir/src/check/finalize.rs:22–27

sage_ir::check::finalize · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.checking.body.elaboration`
// {anchor}`crates.sage_stash.storage.handle_ownership`
// {anchor}`crates.sage_stash.storage.immutable_entries`
pub(super) fn finalize_typed_body<'db>(
    source: &Stash,
    egraph: &VersionedEGraph<'db>,

}

See more source ↗

Implemented crates/sage-ir/src/check/infer_ctx.rs:2312–2317

sage_ir::check::infer_ctx · lib:sage_ir

#![allow(unused)]
fn main() {
    // {anchor}`crates.sage_ir.checking.body.elaboration`
    // {anchor}`crates.sage_ir.types.body.no_inference`
    // {anchor}`crates.sage_ir.inference.body_local_quiescence`
    // {anchor}`crates.sage_ir.inference.completed_body_boundary`
    pub fn finish(self, root: Ptr<TyExpr<'db>>, span: RelativeSpan) -> CheckedBody<'db> {
        assert!(

}

See more source ↗

Tests and review

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

Implemented sage_ir::check::finalize::tests::body_finalization_resolves_types_into_a_fresh_stash

crates/sage-ir/src/check/finalize.rs · lib:sage_ir

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_ir.inference.body_local_quiescence)]
    #[sage::test(crates.sage_ir.checking.owned_products)]
    #[sage::test(crates.sage_ir.checking.body.elaboration)]
    fn body_finalization_resolves_types_into_a_fresh_stash() {
        let mut source = Stash::new();
        let mut egraph = VersionedEGraph::new();
        let variable = egraph.alloc_var(Version::ROOT, Universe::ROOT);
        let inference_ty = source.alloc(Ty::InferVar(variable));
        let resolved_ty = source.alloc(Ty::Int(IntTy::I32));
        try_unify(
            &mut egraph,
            &mut source,
            Version::ROOT,
            inference_ty,
            resolved_ty,
        )
        .unwrap();
        let tuple_elements = source.alloc_slice(&[inference_ty]);
        let tuple_ty = source.alloc(Ty::Tuple(tuple_elements));

        let span = RelativeSpan { start: 0, end: 0 };
        let root = source.alloc(TyExpr {
            data: TyExprData::Missing,
            ty: tuple_ty,
            span,
        });
        let body = finalize_typed_body(&source, &egraph, root, &[], &[], span);

        assert_eq!(source[inference_ty], Ty::InferVar(InferVarIndex(0)));
        let (target, body_root) = body.open_deref();
        let Ty::Tuple(elements) = target[target[body_root.root].ty] else {
            panic!("completed expression should retain its tuple type")
        };
        let [element] = target[elements] else {
            panic!("completed tuple should have one element")
        };
        assert_eq!(target[element], Ty::Int(IntTy::I32));
    }
}

Conditional source: #[cfg(test)]

See more source ↗

TODO sage_meta::todo::checking_body_elaboration

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

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_ir.checking.body.elaboration)]
    fn checking_body_elaboration() {
        // TODO: Complete the claim-specific verification matrix:
        // Structural Typed-IR snapshots cover paths, fields, calls, generic substitutions, borrows,
        // dereferences, coercions, and recovery; completion checks reject every unresolved or live
        // internal form; and selected slices match the independent rustc oracle by exact text.
    }
}

See more source ↗

Implemented sage_test_harness::indexing_reports_unsupported_until_call_elaboration_exists

crates/sage-test-harness/tests/body_elaboration_review.rs · test:body_elaboration_review

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_ir.checking.body.elaboration)]
fn indexing_reports_unsupported_until_call_elaboration_exists() {
    with_test_crate("fn f(x: &[i32]) -> i32 { x[0usize] }", |db, root| {
        let checked = local_function_named(db, root, "f").body(db);
        // Successful indexing elaboration requires materialized Index/IndexMut calls.
        assert!(
            checked.diagnostics.iter().any(|diagnostic| diagnostic.message
                == "indexing elaboration is not supported yet"),
            "unsupported indexing must not masquerade as successful elaboration: {:?}",
            checked.diagnostics
        );
    });
}
}

See more source ↗

Review: Accepted · Codex /root/anchor_094 independent final reviewer.

Independently reviewed the complete body.elaboration claim, all three associated implementation files, and all three test entries. Captured the checking design, architectural-foundations RFD, Typed IR representation, and the in-memory test setup/lookup helpers. This review is source inspection; behavioral suites were centrally run and were not rerun here. No Rust files were authored or changed in this review.

The normative requirement is a successful completed semantic tree with final types and identities and explicit type-directed operations, without source method syntax, unresolved names, inference variables, pending obligations or adjustment recipes. The RFD confirms this is a successful-output requirement and permits structured control flow above MIR. expr.rs checks source forms into typed nodes: its method branch consumes a resolved target and signature, materializes receiver adjustment and argument coercion, submits the parameter environment where needed and emits ResolvedCall; failures produce diagnosed error types. Field and path checking similarly operate through resolution rather than preserving an unchecked source lookup. This is implementation progress, not an assertion that every language operation has complete coverage.

infer_ctx.rs finish guards completion against pending obligations, non-root live inference branches, active tasks, unpublished wakes and unfilled expression slots. It transfers only the finalized body and diagnostics into CheckedBody. finalize.rs follows root egraph representatives recursively when copying types, rejects escaped InferVar, resolves expression slots and copies expression/type graphs into a fresh target stash. It also copies call targets and their type arguments. These mechanisms establish the intended boundary; the completed representation still contains source-shaped variants, and the finalizer is not itself a blanket validator rejecting every possible such variant. The associated TODO explicitly retains the full completion-rejection matrix, so this report does not upgrade those incomplete checks into full implementation proof.

The ordinary body_finalization_resolves_types_into_a_fresh_stash test unifies an inference variable with i32, places it inside a tuple expression type, finalizes, asserts the original source still contains InferVar(0), and asserts the completed tuple element is i32. It meaningfully verifies recursive resolved output without mutating the source, but uses a Missing expression and does not demonstrate method/operator/coercion lowering or all forbidden-form rejection.

The second ordinary test indexing_reports_unsupported_until_call_elaboration_exists runs the actual body query for x[0usize] on &[i32] and requires the exact diagnostic indexing elaboration is not supported yet. The captured harness creates a database, parses the supplied root source, and selects the named local function, so the assertion reaches real checking rather than a mock. expr.rs matches that contract: it checks both operands, records this error and assigns Ty::Error while retaining an Index recovery node. This prevents unmaterialized Index/IndexMut behavior from masquerading as successful elaboration; it is not evidence that indexing calls have been implemented.

The checking_body_elaboration TODO explicitly defers the complete verification matrix: structural Typed-IR snapshots for paths, fields, calls, generic substitutions, borrows, dereferences, coercions and recovery; rejection checks for all unresolved/live internal forms; and exact independent rustc oracle comparisons for selected slices. Its prerequisite is completing and associating those claim-specific checks and the corresponding supported lowering. I preserve this deferral for the full successful-output requirement, including semantic identity and materialization of all type-directed operations. The two ordinary tests prove their narrow finalization and diagnosed-indexing scenarios only. No claim weakening, fabricated execution result, or blanket assertion of full elaboration completeness is made. All current evidence entries are accounted for and no additional concrete edits are requested.

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