crates.sage_ir.inference.atomic_checking

Speculative checking changes commit atomically. A candidate or multi-part compatibility check stages its inference changes and obligations in an isolated child version. The whole operation either commits to its direct parent or is discarded; no equality, wake, or obligation from a rejected alternative reaches the requester. The version invariants are defined by Versioned egraph children are inference transactions.

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

Implementation

Implemented crates/sage-ir/src/check/infer/egraph.rs:242–247

sage_ir::check::infer::egraph · lib:sage_ir

#![allow(unused)]
fn main() {
    // {anchor}`crates.sage_ir.inference.atomic_checking`
    // {anchor}`crates.sage_ir.inference.transaction_isolation`
    pub fn collapse_into(&mut self, child: Version, parent: Version) -> CommitEffects {
        self.versions.assert_live(child);
        self.versions.assert_live(parent);
        assert_eq!(self.versions.parent(child), Some(parent));

}

See more source ↗

Implemented crates/sage-ir/src/check/infer/obligations.rs:148–153

sage_ir::check::infer::obligations · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.inference.atomic_checking`
pub struct StagedObligationBatch<'db> {
    pub(crate) environments: Vec<(CheckedParameterEnv<'db>, ObligationProvenance)>,
}

impl<'db> StagedObligationBatch<'db> {

}

See more source ↗

Implemented crates/sage-ir/src/check/infer/unify.rs:213–218

sage_ir::check::infer::unify · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.inference.atomic_checking`
fn try_probe<'db, T>(
    egraph: &mut VersionedEGraph<'db>,
    stash: &mut Stash,
    parent: Version,
    operation: impl FnOnce(&mut VersionedEGraph<'db>, &mut Stash, Version) -> Result<T, UnifyError<'db>>,

}

See more source ↗

Implemented crates/sage-ir/src/check/infer/version.rs:189–194

sage_ir::check::infer::version · lib:sage_ir

#![allow(unused)]
fn main() {
    // {anchor}`crates.sage_ir.inference.atomic_checking`
    // {anchor}`crates.sage_ir.inference.transaction_isolation`
    pub fn branch_from(&mut self, parent: Version) -> Version {
        self.assert_live(parent);
        let child = Version(self.nodes.len() as u32);
        self.nodes.push(VersionNode::child(parent));

}

See more source ↗

Implemented crates/sage-ir/src/check/infer_ctx.rs:1060–1065

sage_ir::check::infer_ctx · lib:sage_ir

#![allow(unused)]
fn main() {
    // {anchor}`crates.sage_ir.inference.atomic_checking`
    pub(crate) fn commit_branch(&self, version: Version) {
        let effects = {
            let mut stash = self.target_stash.borrow_mut();
            let mut egraph = self.egraph.borrow_mut();
            egraph.rebuild(version, &mut stash);

}

See more source ↗

Implemented crates/sage-ir/src/check/method.rs:311–316

sage_ir::check::method · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.inference.atomic_checking`
fn instantiate_external_inherent_signature<'db>(
    cx: &InferCtx<'_, 'db>,
    signature: &sage_stash::Stashed<crate::ty::Binder<'db, FnSig<'db>>>,
    receiver_ty: Ptr<Ty<'db>>,
    arguments: &[(Ptr<Ty<'db>>, RelativeSpan)],

}

See more source ↗

Implemented crates/sage-ir/src/check/solve/boundary.rs:43–48

sage_ir::check::solve::boundary · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.inference.atomic_checking`
// {anchor}`crates.sage_ir.solver.alternative_isolation`
pub fn instantiate_query<'db>(query: &Stashed<GoalQueryData<'db>>) -> QueryProofState<'db> {
    let (source, data) = query.open();
    let mut stash = Stash::new();
    let mut egraph = VersionedEGraph::new();

}

See more source ↗

Implemented crates/sage-ir/src/check/solve/prove.rs:1128–1133

sage_ir::check::solve::prove · lib:sage_ir

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_ir.inference.atomic_checking`
async fn prove_conjunction<'db>(
    db: &'db dyn crate::Db,
    whiteboard: &Whiteboard<'db>,
    state: &mut QueryProofState<'db>,
    parent: Version,

}

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::infer::unify::tests::batch_failure_is_atomic

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

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_ir.inference.atomic_checking)]
    fn batch_failure_is_atomic() {
        let mut egraph = VersionedEGraph::new();
        let mut stash = Stash::new();
        let variable = variable(&mut egraph, &mut stash, Version::ROOT, Universe::ROOT);
        let int = stash.alloc(Ty::Int(IntTy::I32));
        let boolean = stash.alloc(Ty::Bool);

        assert!(
            try_unify_batch(
                &mut egraph,
                &mut stash,
                Version::ROOT,
                &[(variable, int), (int, boolean)]
            )
            .is_err()
        );
        assert_eq!(egraph.find(Version::ROOT, variable), variable);
    }
}

Conditional source: #[cfg(test)]

See more source ↗

Implemented sage_ir::check::infer::unify::tests::concrete_and_nested_unification

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

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_ir.inference.atomic_checking)]
    fn concrete_and_nested_unification() {
        let mut egraph = VersionedEGraph::new();
        let mut stash = Stash::new();
        let variable = variable(&mut egraph, &mut stash, Version::ROOT, Universe::ROOT);
        let int = stash.alloc(Ty::Int(IntTy::I32));
        let left_elements = stash.alloc_slice(&[variable]);
        let left = stash.alloc(Ty::Tuple(left_elements));
        let right_elements = stash.alloc_slice(&[int]);
        let right = stash.alloc(Ty::Tuple(right_elements));

        try_unify(&mut egraph, &mut stash, Version::ROOT, left, right).unwrap();
        assert_eq!(egraph.find(Version::ROOT, variable), int);
        assert_eq!(
            egraph.find(Version::ROOT, left),
            egraph.find(Version::ROOT, right)
        );
    }
}

Conditional source: #[cfg(test)]

See more source ↗

Implemented sage_ir::check::infer::unify::tests::late_mismatch_rolls_back_earlier_equality

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

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_ir.inference.atomic_checking)]
    fn late_mismatch_rolls_back_earlier_equality() {
        let mut egraph = VersionedEGraph::new();
        let mut stash = Stash::new();
        let variable = variable(&mut egraph, &mut stash, Version::ROOT, Universe::ROOT);
        let int = stash.alloc(Ty::Int(IntTy::I32));
        let boolean = stash.alloc(Ty::Bool);
        let left_elements = stash.alloc_slice(&[variable, boolean]);
        let left = stash.alloc(Ty::Tuple(left_elements));
        let right_elements = stash.alloc_slice(&[int, int]);
        let right = stash.alloc(Ty::Tuple(right_elements));
        let revision = egraph.semantic_revision(Version::ROOT);

        assert!(matches!(
            try_unify(&mut egraph, &mut stash, Version::ROOT, left, right),
            Err(UnifyError::Mismatch { .. })
        ));
        assert_eq!(egraph.find(Version::ROOT, variable), variable);
        assert_eq!(egraph.semantic_revision(Version::ROOT), revision);
    }
}

Conditional source: #[cfg(test)]

See more source ↗

Implemented sage_ir::check::method::tests::external_method_mismatch_discards_partial_generic_bindings

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

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_ir.inference.atomic_checking)]
    #[sage::test(crates.sage_ir.checking.body.isolated_completion)]
    fn external_method_mismatch_discards_partial_generic_bindings() {
        let database = Database::new(SignatureTcx {
            ordinary_complete: true,
        });
        database.attach(|db| {
            let source_stash = Stash::new();
            let cx = InferCtx::new(db, &source_stash, None);
            let function =
                FnSymbol::Ext(SymExt::new(db, CrateNum(1), DefIndex(11), SymExtKind::Fn));
            let signature = function.sig(db).expect("synthetic external signature");

            let bool_ty = cx.alloc_ty(Ty::Bool);
            let char_ty = cx.alloc_ty(Ty::Char);
            let caller_var = cx.fresh_ty_var();
            let owner = StructSymbol::Ext(SymExt::new(
                db,
                CrateNum(1),
                DefIndex(10),
                SymExtKind::Struct,
            ));
            let owner_args = cx.stash_mut().alloc_slice(&[bool_ty]);
            let receiver_ty = cx.alloc_ty(Ty::Adt(owner.into(), owner_args));
            let span = RelativeSpan { start: 0, end: 0 };
            let root_revision = cx.root_semantic_revision();

            assert!(
                instantiate_external_inherent_signature(
                    &cx,
                    &signature,
                    receiver_ty,
                    &[(caller_var, span), (char_ty, span)],
                    span,
                )
                .is_err(),
                "the second argument must reject the selected signature"
            );
            assert_eq!(cx.get_bound(caller_var), Bound::None);
            assert_eq!(
                cx.root_semantic_revision(),
                root_revision,
                "the first argument's method-generic binding must roll back"
            );
        });
    }
}

Conditional source: #[cfg(test)]

See more source ↗

TODO sage_meta::todo::inference_atomic_checking

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

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_ir.inference.atomic_checking)]
    fn inference_atomic_checking() {
        // TODO: Complete the claim-specific verification matrix:
        // Unit tests reject a candidate after partial generic matching and observe the parent unchanged,
        // accept the same shape and observe exactly one staged obligation publication, and exercise
        // isolated sibling candidates without shared inference identities.
    }
}

See more source ↗

Review: Accepted · Codex /root/anchor_094.

Reviewed the full atomic_checking claim, all eight associated implementation entries and all five test entries, with the inference design and accepted transaction RFD captured. This is source inspection; no behavioral suites rerun and no source changes made.

The required boundary is all-or-discard inference and staged obligations for a speculative candidate or multipart check, with rejected equalities/wakes/obligations excluded from the requester. The RFD distinguishes exclusive short-lived probes committed to a direct parent from independent candidate proof contexts whose answers cross a canonical boundary. unify.rs try_probe creates a child, runs the entire operation there, rebuilds/collapses only on success and discards on failure; batch unification shares this transaction. egraph.rs collapse_into checks live direct-parent/exclusive-leaf conditions, transfers child maps, revisions and wake effects, reowns variables and removes the child; discard removes branch state. version.rs allocates fresh version nodes, tracks ancestry/liveness and provides the lifecycle restrictions supporting these operations.

infer_ctx.rs commit_branch rebuilds before collapse and publishes resulting wakes afterward. obligations.rs StagedObligationBatch owns unpublished environment/provenance entries; dropping a rejected batch has no registry publication. method.rs stages external inherent receiver and argument matching in a child, discards on mismatch, and commits before publishing the environment. solve/boundary.rs instantiate_query constructs a fresh stash/egraph with newly instantiated canonical inputs, separating proof contexts from requesters. solve/prove.rs prove_conjunction owns a child for the multipart conjunction, discards it on No and commits the resulting state only through its parent boundary on complete or residual outcomes. A residual or Maybe is not misreported here as a rejected No; the caller-facing candidate isolation still depends on the separate proof-context/canonical-result boundary.

The four ordinary tests provide specific evidence. concrete_and_nested_unification asserts a successful tuple relation binds the variable to i32 and merges tuple representatives. late_mismatch_rolls_back_earlier_equality first permits a variable/i32 relation, then fails bool/i32 in the same tuple; it asserts the variable remains its original root and the parent's semantic revision is unchanged. batch_failure_is_atomic similarly fails a later pair and checks the earlier variable binding did not escape. external_method_mismatch_discards_partial_generic_bindings uses the in-file SignatureTcx fixture with owner T, method E and arguments E then bool; passing a caller variable then char fails after partial matching, and assertions check Bound::None plus unchanged root revision. Helpers are visible in the associated files and perform real variable allocation/signature construction rather than opaque verification.

These assertions do not count wake publication or staged-obligation publication, nor do they establish all sibling-candidate identity isolation scenarios. The associated inference_atomic_checking TODO explicitly retains the remaining matrix: partial generic rejection with unchanged parent, corresponding acceptance with exactly one obligation publication, and isolated sibling candidates without shared inference identities. Its prerequisite is completing those targeted observations across the shared transaction callers, including rejection wake/obligation effects required by the claim. The TODO remains non-executable deferred evidence; the successful and failed equality tests are not a blanket proof of the entire speculative checker. All entries and requirements are accounted for, no concrete defect was identified in the inspected paths, and no additional 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