crates.sage_test_harness.compile_tests.starting_expressions

A ty observation includes every source expression whose span starts on its target line in the same file. An expression may extend across subsequent lines; its start alone determines inclusion. Expressions starting on earlier or later lines are omitted, even if they contain or intersect the target line. Multiple sibling expressions starting on one line are all included. Each selected source expression appears once, with its logical filename, expression kind and readable source description, and completed type. The snapshot omits line numbers, columns, and ranges. Blocks follow the same start-line rule; a function-body block starting earlier is not included merely because it contains the target line.

All type markers contribute to the same snapshot. Files are ordered by logical path, then marked target lines by source order. Within each target line, output follows source-tree postorder: children before parents, with siblings in source order. Repeated markers targeting the same line do not duplicate observations. Distinct source expressions remain distinct entries even if their rendered text is identical. Source nesting distinguishes expressions with equal spans. Generated elaboration nodes do not add duplicate observations, except that meaningful coercion wrappers are reported after their wrapped expression. Each wrapper belongs to the selected source expression and exposes its resulting type, preserving child-before-parent order through a chain of coercions. A target line with no expression starting on it, or lacking a reliable source-to-semantic correspondence, fails explicitly. V1 observes expressions; binding declarations and other semantic entities require future selectors.

For example, an inline marker targets the code on its own line. The observations expectation contains the complete ordered observation:

use expect_test::expect;
use indoc::indoc;

#[test]
fn tuple_types() {
    compile_test! {
        source: indoc! {r#"
            fn example() -> (u16, (bool, u8)) {
                (1u16, (true, 2u8)) //# ty
            }
        "#},
        observations: expect![[r#"
            src/lib.rs: literal `1u16`
              type: u16
            src/lib.rs: literal `true`
              type: bool
            src/lib.rs: literal `2u8`
              type: u8
            src/lib.rs: tuple `(true, 2u8)`
              type: (bool, u8)
            src/lib.rs: tuple `(1u16, (true, 2u8))`
              type: (u16, (bool, u8))
        "#]],
        diagnostics: expect![""],
    }
}

The first tuple element precedes the second element’s subtree. Within that subtree, both literals precede their tuple. The function-body block starts on the preceding line, so it is omitted. The function declaration itself is not an expression.

A multi-line call demonstrates that enclosing expressions starting on earlier lines are omitted:

use expect_test::expect;
use indoc::indoc;

#[test]
fn call_argument_types() {
    compile_test! {
        source: indoc! {r#"
            fn inner(value: u16) -> u32 { value as u32 }
            fn outer(first: u32, second: u16) -> u64 { first as u64 + second as u64 }

            fn example() -> u64 {
                outer(
                    inner(22u16), //# ty
                    33u16,
                )
            }
        "#},
        observations: expect![[r#"
            src/lib.rs: path `inner`
              type: fn(u16) -> u32
            src/lib.rs: literal `22u16`
              type: u16
            src/lib.rs: call `inner(22u16)`
              type: u32
        "#]],
        diagnostics: expect![""],
    }
}

The callee path outer, the outer(...) call, and the function-body block start on earlier lines, so they are omitted. The literal 33u16 starts on a later line and is also omitted. Moving the marker to the line immediately after outer( would instead observe the path outer followed by the complete outer(...) call, even though that call ends several lines later. These expectation literals illustrate the filename-only output. Moving an expression to another line without changing observation order does not itself change its type snapshot. Expression descriptions use the single-line rendering rules below. Type representations describe the completed types currently exposed by Sage; the runner does not manufacture distinctions absent from its typed IR.

Read in specification context · design/crates/sage_test_harness/compile-tests.md

Implementation

Implemented crates/sage-test-harness/src/compile/observe.rs:368–373

sage_test_harness::compile::observe · lib:sage_test_harness

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_test_harness.compile_tests.starting_expressions`
// {anchor}`crates.sage_test_harness.compile_tests.completed_types`<<
fn walk_expr<'db>(
    db: &'db dyn Db,
    stash: &Stash,
    expression: Ptr<TyExpr<'db>>,

}

See more source ↗

Implemented crates/sage-test-harness/src/compile/source.rs:5–10

sage_test_harness::compile::source · lib:sage_test_harness

#![allow(unused)]
fn main() {
// {anchor}`crates.sage_test_harness.compile_tests.starting_expressions`
use sage_ir::cst::expr::{ExprCst, ExprCstKind as C, StmtCstKind};
use sage_ir::span::RelativeSpan;
use sage_stash::Stash;

pub(super) struct SourceExpression {

}

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::compile::tests::expectations_and_source_selections_must_agree

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

#![allow(unused)]
fn main() {
#[test]
    #[sage::test(crates.sage_test_harness.compile_tests.annotation_validation)]
    #[sage::test(crates.sage_test_harness.compile_tests.completed_types)]
    #[sage::test(crates.sage_test_harness.compile_tests.starting_expressions)]
    fn expectations_and_source_selections_must_agree() {
        let mut test = CompileTest::default();
        test.source("fn f() { 22; } //# ty");
        assert!(
            test.prepare()
                .unwrap_err()
                .contains("observations expectation")
        );
        let mut test = CompileTest::default();
        test.source("fn f() {}");
        test.observations(expect![""]);
        assert!(
            test.prepare()
                .unwrap_err()
                .contains("observations expectation")
        );
        let mut test = CompileTest::default();
        test.source("fn f() {\n}\n//# ty");
        test.observations(expect![""]);
        assert!(test.prepare().unwrap_err().contains("no expression"));
    }
}

Conditional source: #[cfg(test)]

See more source ↗

Implemented sage_test_harness::files_lines_and_identical_siblings_keep_source_order

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_test_harness.compile_tests.starting_expressions)]
fn files_lines_and_identical_siblings_keep_source_order() {
    compile_test! {
        files: {
            "src/z.rs": "fn z() -> u8 {\n 3 //# ty\n}",
            "src/lib.rs": "mod z; mod a;",
            "src/a.rs": "fn a() -> (u8, (bool, u8)) {\n (1, (true, 1)) //# ty\n //# ty\n}\nfn b() -> u8 {\n 2 //# ty\n}",
        },
        observations: expect![[r#"
            src/a.rs: literal `1`
              type: u8
            src/a.rs: literal `true`
              type: bool
            src/a.rs: literal `1`
              type: u8
            src/a.rs: tuple `(true, 1)`
              type: (bool, u8)
            src/a.rs: tuple `(1, (true, 1))`
              type: (u8, (bool, u8))
            src/a.rs: literal `2`
              type: u8
            src/z.rs: literal `3`
              type: u8
        "#]],
    }
}
}

See more source ↗

Implemented sage_test_harness::function_declaration_is_not_an_expression

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_test_harness.compile_tests.starting_expressions)]
#[should_panic(expected = "no expression with a completed type starts on this line")]
fn function_declaration_is_not_an_expression() {
    compile_test! {
        source: "fn f() //# ty\n{ }",
        observations: expect![""],
    }
}
}

See more source ↗

Implemented sage_test_harness::call_argument_types

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_test_harness.compile_tests.invocation)]
#[sage::test(crates.sage_test_harness.compile_tests.starting_expressions)]
#[sage::test(crates.sage_test_harness.compile_tests.completed_types)]
fn call_argument_types() {
    compile_test! {
        source: indoc! {r#"
            fn inner(value: u16) -> u32 { value as u32 }
            fn outer(first: u32, second: u16) -> u64 { first as u64 + second as u64 }
            fn example() -> u64 {
                outer(
                    inner(22u16), //# ty
                    33u16,
                )
            }
        "#},
        observations: expect![[r#"
            src/lib.rs: path `inner`
              type: fn(u16) -> u32
            src/lib.rs: literal `22u16`
              type: u16
            src/lib.rs: call `inner(22u16)`
              type: u32
        "#]],
        diagnostics: expect![""],
    }
}
}

See more source ↗

Implemented sage_test_harness::coercion_wrapper_follows_its_source_expression

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_test_harness.compile_tests.completed_types)]
#[sage::test(crates.sage_test_harness.compile_tests.starting_expressions)]
fn coercion_wrapper_follows_its_source_expression() {
    compile_test! {
        source: indoc! {r#"
            fn example() -> u16 {
                return 22; //# ty
            }
        "#},
        observations: expect![[r#"
            src/lib.rs: literal `22`
              type: u16
            src/lib.rs: return `return 22`
              type: !
            src/lib.rs: coercion `return 22`
              type: u16
        "#]],
    }
}
}

See more source ↗

Implemented sage_test_harness::implicit_dereferences_do_not_duplicate_source_observations

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_test_harness.compile_tests.starting_expressions)]
fn implicit_dereferences_do_not_duplicate_source_observations() {
    compile_test! {
        source: indoc! {r#"
            struct Pair { value: u16 }
            fn read(pair: &Pair) -> u16 {
                pair.value //# ty
            }
        "#},
        observations: expect![[r#"
            src/lib.rs: path `pair`
              type: &Pair
            src/lib.rs: field `pair.value`
              type: u16
        "#]],
    }
}
}

See more source ↗

Implemented sage_test_harness::tuples_and_multiline_descriptions

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_test_harness.compile_tests.starting_expressions)]
#[sage::test(crates.sage_test_harness.compile_tests.rendering)]
fn tuples_and_multiline_descriptions() {
    compile_test! {
        source: indoc! {r#"
            fn example() -> (u16, bool) {
                (22, true) //# ty
                //# ty
            }
            fn multiline() -> (u16, bool) {
                ( //# ty
                    22,
                    true,
                )
            }
        "#},
        observations: expect![[r#"
            src/lib.rs: literal `22`
              type: u16
            src/lib.rs: literal `true`
              type: bool
            src/lib.rs: tuple `(22, true)`
              type: (u16, bool)
            src/lib.rs: tuple `( 22, true, )`
              type: (u16, bool)
        "#]],
    }
}
}

See more source ↗

Implemented sage_test_harness::unicode_and_indentation_do_not_change_line_type_selection

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

#![allow(unused)]
fn main() {
#[test]
#[sage::test(crates.sage_test_harness.compile_tests.coordinates)]
#[sage::test(crates.sage_test_harness.compile_tests.starting_expressions)]
fn unicode_and_indentation_do_not_change_line_type_selection() {
    compile_test! {
        source: "    fn café() -> bool { true } //# ty",
        observations: expect![[r#"
            src/lib.rs: literal `true`
              type: bool
            src/lib.rs: block `{ true }`
              type: bool
        "#]],
    }
}
}

See more source ↗

Review: Accepted · Codex anchor_023 fresh CI review.

Fresh review performed from the current start output, not the previous verdict. The current inventory contains two ordinary implementation entries, observe.rs and source.rs, and eight ordinary tests; no TODO/N/A entries or deferral prerequisites are present. Additional captured dependencies are the compile runner, marker parser, FrozenType conversion/completeness/rendering, and expression span construction.

The claim requires exact file/start-line selection, inclusion of multiline expressions and siblings, exclusion of earlier/later starts and containing blocks, one row per source expression, readable filename/kind/source/completed-type output without coordinates, one ordered snapshot across markers, file/line/postorder sorting, marker deduplication without text deduplication, source nesting and generated-node control, coercion wrapper ordering/types, explicit failure for empty or unreliable correspondence, and expression-only selection. The examples additionally require the nested tuple order, the inner-call-only selection, and line-independent snapshot coordinates.

Implementation: source::walk is exhaustive over ExprCstKind and visits children before pushing a source row; statement traversal visits initializer expressions but not binding declarations or function declarations. observe::walk_symbol obtains checked bodies, walks the typed expression tree, enumerates source expressions, and chooses a unique same-span candidate, preferring the source kind. Generated semantic rows therefore cannot independently produce observations. A missing/ambiguous match produces an invalid row, and collect rejects invalid or incomplete rows explicitly before formatting. The no-expression branch rejects an empty target selection. walk_expr resolves spans to the logical file and counts newlines before the start. collect requires equal file and start line; it does not test intersection. Hence multiline starts remain selected and containing blocks starting earlier remain excluded.

Ordering: BTreeSet<(file,line)> sorts targets and deduplicates repeated markers. Source traversal retains sibling order and nesting. Stable sorting by file, end, and reverse start produces child-before-parent order, retaining traversal order for equal keys. Individual rows are never deduplicated by rendered text. Semantic coercions are traversed after their children, excluded from the base-candidate choice, and appended after their matching source expression; same-span wrapper chains preserve their typed postorder. Other generated nodes, such as implicit dereferences, are not appended. The parsed-source span constructor uses syntax-node byte ranges and allocates one node per expression; valid enclosing syntax has its own delimiters/operators, while equal-span generated wrappers are handled separately. There is no demonstrated reachable same-kind/equal-span source ambiguity requiring a synthetic injection test. Missing-child/unresolved representations are rejected by the correspondence guards, whose handling was source-inspected rather than claimed as an executed ambiguous-CST case.

Output: collect formats only logical filename, kind, compact source, and FrozenType. compact uses Rust syntax leaves, removes annotation comments, normalizes inter-token whitespace, and escapes multiline/literal text. FrozenType reads completed typed IR and recursively checks missing components; expected strings cannot change semantic types because CompileTest prepares first and compares afterward. Omitting coordinates explains why moving expressions without changing order does not itself change the snapshot.

Complete test accounting: call_argument_types contains the documented multiline call scenario and exactly asserts inner path/literal/call with completed types, excluding the outer call/body and later literal. tuples_and_multiline_descriptions asserts sibling-before-parent order, repeated marker collapse, the selected multiline tuple but not its later-line literals, and compact source text. files_lines_and_identical_siblings_keep_source_order deliberately reverses fixture/module input order and asserts sorted logical paths, ordered marked lines, nested tuple postorder, duplicate-marker collapse, and retention of two identical literal entries. implicit_dereferences_do_not_duplicate_source_observations asserts exactly the source path and field despite generated dereference elaboration. coercion_wrapper_follows_its_source_expression asserts literal, return of never type, then the same-source coercion with resulting u16 type. unicode_and_indentation_do_not_change_line_type_selection asserts literal followed by a same-line body block, without function declaration or coordinates. function_declaration_is_not_an_expression requires the specific no-expression failure on a declaration line whose body starts later. expectations_and_source_selections_must_agree asserts expectation/marker consistency and the empty selection on a closing brace rather than selecting an earlier-starting body. These are explicit scenario/expected-output assertions, not opaque verification helpers. The correspondence-error guards and general chain ordering were additionally inspected structurally; the tests exercise real source selection failures and the supported equal-span coercion case, not synthetic internal-state injection.

Assessment: current implementation and tests adequately establish the complete claim and its qualifications. No production or test edits are requested. This refresh executed review start/read/record tooling only; no behavior tests or build were rerun by this reviewer. The coordinator centrally runs the relevant suites. Prior test runs 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