Build semantic lineage analysis #26

Merged
JayKobe6k merged 8 commits from issue-11-lineage-analysis into main 2026-09-04 21:30:56 +00:00
Owner

Summary

  • build ClariTree-owned fixed-point reaching-definition and producer-to-consumer lineage analysis over owned IR
  • model branch, loop, call, return, variadic, alias, field, array, global, and external effects with typed certainty
  • persist explicit revision-owned value nodes and six endpoint-typed relationship tables in LadybugDB schema version 3 with pre-commit round-trip validation

Tests

  • nix develop --command cargo fmt --all -- --check
  • nix develop --command cargo lint
  • nix develop --command cargo test --all-targets --all-features
  • nix develop --command cargo doc --no-deps --all-features
  • nix develop --command cargo check --target x86_64-pc-windows-gnu --all-features

Closes #11

## Summary - build ClariTree-owned fixed-point reaching-definition and producer-to-consumer lineage analysis over owned IR - model branch, loop, call, return, variadic, alias, field, array, global, and external effects with typed certainty - persist explicit revision-owned value nodes and six endpoint-typed relationship tables in LadybugDB schema version 3 with pre-commit round-trip validation ## Tests - `nix develop --command cargo fmt --all -- --check` - `nix develop --command cargo lint` - `nix develop --command cargo test --all-targets --all-features` - `nix develop --command cargo doc --no-deps --all-features` - `nix develop --command cargo check --target x86_64-pc-windows-gnu --all-features` Closes #11
Build semantic lineage analysis
All checks were successful
Validate / Formatting, linting, and tests (pull_request) Successful in 1m56s
Validate / Formatting, linting, and tests (push) Successful in 14m10s
98f537a16a
JayKobe6k left a comment

Found four actionable lineage-analysis defects.

Found four actionable lineage-analysis defects.
@ -633,0 +640,4 @@
}
fn source_range_is_valid(start: &ValueSourcePoint, end: &ValueSourcePoint) -> bool {
start.path() == end.path() && start.byte_offset() <= end.byte_offset()
Author
Owner

[P1] This requires a spelling range's endpoints to share one file, but libclang can emit a macro operation whose spelling starts in the defining header and ends at the expansion site. A valid return ADD_ONE(input); probe therefore makes analyze fail with InvalidDefinitionAnchor, aborting the entire index. Please preserve this mixed spelling/expansion provenance or normalize the operation anchor before validation, and cover a header-defined expression macro.

[P1] This requires a spelling range's endpoints to share one file, but libclang can emit a macro operation whose spelling starts in the defining header and ends at the expansion site. A valid `return ADD_ONE(input);` probe therefore makes `analyze` fail with `InvalidDefinitionAnchor`, aborting the entire index. Please preserve this mixed spelling/expansion provenance or normalize the operation anchor before validation, and cover a header-defined expression macro.
@ -0,0 +858,4 @@
AnalysisCertainty::Possible,
),
)));
self.bind_known_alias_effects(
Author
Owner

[P1] Known-call effect binding here covers only parameter-rooted alias writes, so direct writes to globals never enter the caller's call_effects. In set_shared(); return shared;, the pre-call initializer remains the sole certain producer and the callee assignment is disconnected. Please summarize and project callee writes to canonical global storage as well as pointer-parameter effects.

[P1] Known-call effect binding here covers only parameter-rooted alias writes, so direct writes to globals never enter the caller's `call_effects`. In `set_shared(); return shared;`, the pre-call initializer remains the sole certain producer and the callee assignment is disconnected. Please summarize and project callee writes to canonical global storage as well as pointer-parameter effects.
@ -0,0 +1145,4 @@
.iter()
.filter(|value_use| {
value_use.operation == call.operation
&& matches!(value_use.role, ValueUseRole::Argument(_))
Author
Owner

[P2] This filter excludes the indirect callee's Operand use even though that value selects the code producing the result. For return function(value);, the result derives only from value, so lineage from the function-pointer definition stops before the call result. Please include the indirect callee use as a Possible(IndirectCall) result derivation while keeping alias-effect creation restricted to arguments.

[P2] This filter excludes the indirect callee's `Operand` use even though that value selects the code producing the result. For `return function(value);`, the result derives only from `value`, so lineage from the function-pointer definition stops before the call result. Please include the indirect callee use as a `Possible(IndirectCall)` result derivation while keeping alias-effect creation restricted to arguments.
@ -0,0 +1393,4 @@
fn callable_seeds(&self, unit_index: usize, callable: CallableId) -> ReachingState {
let mut state = ReachingState::new();
for definition in self.definition_info[unit_index]
Author
Owner

[P1] Seeding only definition_info[unit_index] keeps file-scope storage separated by translation-unit-local SymbolId. With extern int shared in one unit and int shared = 7 in another, the caller's read is reached only by a synthetic external definition, while the real initializer is disconnected. Please reconcile external-storage globals by canonical SymbolKey across units and seed each caller from the project-wide definition.

[P1] Seeding only `definition_info[unit_index]` keeps file-scope storage separated by translation-unit-local `SymbolId`. With `extern int shared` in one unit and `int shared = 7` in another, the caller's read is reached only by a synthetic external definition, while the real initializer is disconnected. Please reconcile external-storage globals by canonical `SymbolKey` across units and seed each caller from the project-wide definition.
Propagate project-wide lineage effects
All checks were successful
Validate / Formatting, linting, and tests (pull_request) Successful in 2m54s
Validate / Formatting, linting, and tests (push) Successful in 3m5s
7b64cb0750
Author
Owner

Review comment #1077: Fixed in 80e3b58. Occurrence validation now orders offsets only when endpoint paths match, while preserving distinct spelling/expansion endpoint paths for mixed-file macro locations. Regression: header_defined_expression_macro_preserves_mixed_source_anchors; full all-target/all-feature tests, lint, rustdoc, and Windows target check passed.

Review comment #1077: Fixed in 80e3b58. Occurrence validation now orders offsets only when endpoint paths match, while preserving distinct spelling/expansion endpoint paths for mixed-file macro locations. Regression: `header_defined_expression_macro_preserves_mixed_source_anchors`; full all-target/all-feature tests, lint, rustdoc, and Windows target check passed.
Author
Owner

Review comment #1081: Fixed in 7b64cb0. Direct and transitive known-callee global writes are summarized and projected into caller state before subsequent reads. Regression: transitive_known_calls_project_global_writes_to_the_caller; full validation passed.

Review comment #1081: Fixed in 7b64cb0. Direct and transitive known-callee global writes are summarized and projected into caller state before subsequent reads. Regression: `transitive_known_calls_project_global_writes_to_the_caller`; full validation passed.
Author
Owner

Review comment #1079: Fixed in 7b64cb0. Project analysis now reconciles externally linked globals by typed SymbolKey, allowing initializers and uses in different translation units to share reaching-definition state. Regression: external_global_initialization_reaches_reads_in_another_translation_unit; full validation passed.

Review comment #1079: Fixed in 7b64cb0. Project analysis now reconciles externally linked globals by typed `SymbolKey`, allowing initializers and uses in different translation units to share reaching-definition state. Regression: `external_global_initialization_reaches_reads_in_another_translation_unit`; full validation passed.
Author
Owner

Review comment #1082: Fixed in 7b64cb0. Indirect-call result definitions now depend on the evaluated callee operand as well as arguments, without introducing unsupported alias effects. Regression: indirect_callee_values_derive_call_results_without_alias_effects; full validation passed.

Review comment #1082: Fixed in 7b64cb0. Indirect-call result definitions now depend on the evaluated callee operand as well as arguments, without introducing unsupported alias effects. Regression: `indirect_callee_values_derive_call_results_without_alias_effects`; full validation passed.
Preserve certainty for repeated global effects
Some checks failed
Validate / Formatting, linting, and tests (pull_request) Successful in 2m45s
Validate / Formatting, linting, and tests (push) Failing after 17m30s
992a10a8f5
Author
Owner

Review comment #1079: Follow-up hardening is pushed in 1d05096, 4596fa2, and 979eba6: canonical global effects now traverse intermediate translation units without declarations, unknown/indirect calls include project-visible external symbols, and internal-linkage resolution remains confined to the owning compilation context. Added direct-static, three-TU known/unknown-call, and repeated-compilation regressions. Full required validation passed.

Review comment #1079: Follow-up hardening is pushed in 1d05096, 4596fa2, and 979eba6: canonical global effects now traverse intermediate translation units without declarations, unknown/indirect calls include project-visible external symbols, and internal-linkage resolution remains confined to the owning compilation context. Added direct-static, three-TU known/unknown-call, and repeated-compilation regressions. Full required validation passed.
Author
Owner

Review comment #1081: Follow-up hardening is pushed in 1d05096, 4596fa2, 979eba6, and 992a10a: call summaries now preserve CFG-aware certainty, ternary control flow, nested/direct effect order, reachability, and certainty when the same definition is repeated. Regressions cover conditional/loop/ternary writes, nested overwrites, unreachable writes, recursion, and repeated calls. All PR checks passed, and a temporary resolved #26+#27 integration tree passed 188 tests plus lint, rustdoc, Windows cross-check, and diff checks.

Review comment #1081: Follow-up hardening is pushed in 1d05096, 4596fa2, 979eba6, and 992a10a: call summaries now preserve CFG-aware certainty, ternary control flow, nested/direct effect order, reachability, and certainty when the same definition is repeated. Regressions cover conditional/loop/ternary writes, nested overwrites, unreachable writes, recursion, and repeated calls. All PR checks passed, and a temporary resolved #26+#27 integration tree passed 188 tests plus lint, rustdoc, Windows cross-check, and diff checks.
JayKobe6k changed target branch from issue-10-durable-value-handles to main 2026-09-04 21:30:40 +00:00
Sign in to join this conversation.
No description provided.