Skip to content
Merged
207 changes: 207 additions & 0 deletions crates/ripr/src/analysis/language/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,86 @@ fn apply_rust_macro_wrapped_assertion_limit(finding: &mut Finding, index: &RustI
.extend(rust_macro_assertion_limitation_detail_lines(&witness));
}

/// Name the bounded value-propagation limitation from #3215 without
/// pretending that syntax-first analysis proved the equality boundary.
///
/// This deliberately recognizes only a changed `let` binding whose value is
/// produced by `find`/`rfind` or `len_utf8`, normalized through `map_or`, and
/// whose same-owner body later compares that binding. Other helper, loop,
/// coercion, and data-flow shapes remain unchanged and fail closed as before.
fn apply_rust_value_propagation_limit(finding: &mut Finding, probe: &Probe, index: &RustIndex) {
if finding.class != ExposureClass::StaticUnknown
|| finding.static_limit_kind.is_some()
|| finding.related_tests.is_empty()
{
return;
}
let Some((binding, rhs)) = changed_let_binding(&probe.expression) else {
return;
};
if !rhs.contains("map_or")
|| !(rhs.contains(".find(") || rhs.contains(".rfind(") || rhs.contains(".len_utf8("))
{
return;
}
let Some(owner_id) = probe.owner.as_ref() else {
return;
};
let Some(owner) = index
.functions
.iter()
.find(|function| &function.id == owner_id)
else {
return;
};
let Some(predicate) = owner
.body
.lines()
.find(|line| line.contains("==") && contains_identifier_token(line, binding))
else {
return;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
};

finding.static_limit_kind = Some(StaticLimitKind::RustValuePropagationUnresolved);
finding
.stop_reasons
.push(StopReason::PropagationEvidenceUnknown);
finding.evidence.push(format!(
"limitation_last_established_edge: changed binding `{binding}` uses `{rhs}`"
));
finding.evidence.push(format!(
"limitation_first_unresolved_edge: `{binding}` value propagation into equality predicate `{}`",
predicate.trim()
));
finding
.evidence
.push("limitation_analyzer_route: analysis/rust-value-propagation".to_string());
finding.evidence.push(
"limitation_non_claim: named analyzer limitation only; ripr does not confirm coverage or prescribe a repair test"
.to_string(),
);
}

fn changed_let_binding(expression: &str) -> Option<(&str, &str)> {
let text = expression.trim().trim_end_matches(';').trim();
let rest = text.strip_prefix("let ")?;
let (lhs, rhs) = rest.split_once('=')?;
let binding = lhs.trim().strip_prefix("mut ").unwrap_or(lhs.trim());
if binding.is_empty()
|| !binding
.chars()
.all(|ch| ch.is_ascii_alphanumeric() || ch == '_')
{
return None;
}
Some((binding, rhs.trim()))
}

fn contains_identifier_token(text: &str, ident: &str) -> bool {
text.split(|ch: char| !ch.is_ascii_alphanumeric() && ch != '_')
.any(|token| token == ident)
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
struct RustMacroAssertionWitness {
test_name: String,
Expand Down Expand Up @@ -1414,6 +1494,7 @@ impl RustAdapter {
// the seam. This is an oracle limitation, not macro expansion
// or promotion.
apply_rust_macro_wrapped_assertion_limit(&mut finding, &index);
apply_rust_value_propagation_limit(&mut finding, &probe, &index);
// Fail closed on cross-language seams: when the probe owner
// carries an FFI/binding attribute, replace any Rust-gap
// static_limit_kind with the cross-language limitation so
Expand Down Expand Up @@ -1548,6 +1629,7 @@ impl RustAdapter {
// disclosure for repo-mode (same logic as diff-mode).
apply_rust_no_static_path_limit(&mut finding, &probe, &index);
apply_rust_macro_wrapped_assertion_limit(&mut finding, &index);
apply_rust_value_propagation_limit(&mut finding, &probe, &index);
// Fail closed on cross-language seams (#910).
if let Some(limit) = cross_language_limit_kind(&probe, &index, &finding.class) {
finding.static_limit_kind = Some(limit);
Expand Down Expand Up @@ -1701,6 +1783,131 @@ mod tests {
Ok(())
}

fn value_propagation_fixture(
name: &str,
changed_line_number: usize,
old_line: &str,
changed_line: &str,
expected_limit: bool,
) -> Result<(), String> {
let root = temp_root(name)?;
let cleanup_root = root.clone();
write(
&root.join("Cargo.toml"),
"[package]\nname='value-propagation'\nversion='0.1.0'\nedition='2024'\n",
)?;
let start_line = if changed_line_number == 2 {
changed_line
} else {
" let start = delim.chars().next().map_or(0, |ch| ch.len_utf8());"
};
let end_line = if changed_line_number == 3 {
changed_line
} else {
" let end = input.rfind(delim).map_or(0, |idx| idx);"
};
let source = format!(
"pub fn split(input: &str, delim: &str) -> usize {{\n{start_line}\n{end_line}\n if end == start {{ 1 }} else {{ 0 }}\n}}\n"
);
write(&root.join("src/lib.rs"), &source)?;
write(
&root.join("tests/split.rs"),
"#[test]\nfn empty_delimiter_splits_at_start() {\n assert_eq!(split(\"abc\", \"\"), 1);\n}\n#[test]\nfn nonempty_delimiter_splits() {\n assert_eq!(split(\"abc\", \"b\"), 0);\n}\n",
)?;
let diff_text = format!(
"diff --git a/src/lib.rs b/src/lib.rs\n--- a/src/lib.rs\n+++ b/src/lib.rs\n@@ -{changed_line_number},1 +{changed_line_number},1 @@\n-{old_line}\n+{changed_line}\n"
);
let changed_files = diff::parse_unified_diff(&diff_text);
let result = RustAdapter.analyze_diff(
&AnalysisOptions {
root,
base: None,
diff_file: None,
mode: AnalysisMode::Ready,
include_unchanged_tests: true,
resolve_tsconfig_paths: false,
perl_facts_path: None,
git_timeout: None,
},
&OraclePolicy::default(),
&changed_files,
)?;
let binding_name = changed_line
.trim()
.strip_prefix("let ")
.and_then(|rest| rest.split_whitespace().next())
.unwrap_or("end");
let finding = result
.findings
.iter()
.find(|finding| {
finding
.probe
.expression
.contains(&format!("let {binding_name}"))
})
.ok_or_else(|| format!("missing changed binding finding: {:?}", result.findings))?;
assert_eq!(
finding
.static_limit_kind
.as_ref()
.map(StaticLimitKind::as_str)
== Some("rust_value_propagation_unresolved"),
expected_limit,
"unexpected value-propagation finding: {finding:?}"
);
if expected_limit {
assert_eq!(finding.class, ExposureClass::StaticUnknown);
assert!(
finding
.evidence
.iter()
.any(|line| line.contains("limitation_first_unresolved_edge"))
);
assert!(
finding
.evidence
.iter()
.any(|line| line.contains("analysis/rust-value-propagation"))
);
}
fs::remove_dir_all(cleanup_root).map_err(|error| format!("remove fixture: {error}"))?;
Ok(())
}

#[test]
fn diff_analysis_names_rfind_value_propagation_limitation() -> Result<(), String> {
value_propagation_fixture(
"rfind-value-limit",
3,
" let end = input.rfind(delim).map_or(0, |idx| idx);",
" let end = input.rfind(delim).map_or(1, |idx| idx);",
true,
)
}

#[test]
fn diff_analysis_keeps_unbounded_value_shapes_fail_closed() -> Result<(), String> {
value_propagation_fixture(
"unbounded-value-limit",
3,
" let end = input.rfind(delim).map_or(0, |idx| idx);",
" let end = input.len();",
false,
)
}

#[test]
fn diff_analysis_names_len_utf8_value_propagation_limitation() -> Result<(), String> {
value_propagation_fixture(
"len-utf8-value-limit",
2,
" let start = delim.chars().next().map_or(0, |ch| ch.len_utf8());",
" let start = delim.chars().next().map_or(1, |ch| ch.len_utf8());",
true,
)
}

#[test]
fn diff_index_file_limit_defaults_when_unset() {
assert_eq!(
Expand Down
15 changes: 15 additions & 0 deletions crates/ripr/src/domain/language.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ pub enum StaticLimitKind {
/// oracle. The classification stays reachable-but-undiscriminated; this
/// label names the unresolved assertion macro, not a coverage claim.
RustMacroWrappedAssertionUnresolved,
/// A changed Rust let binding uses a bounded value-producing operation,
/// but the syntax-first analyzer cannot carry that value into the
/// same-owner equality predicate. Classification remains `static_unknown`;
/// this is a named limitation, not a coverage or repair claim.
RustValuePropagationUnresolved,
}

impl StaticLimitKind {
Expand Down Expand Up @@ -193,6 +198,7 @@ impl StaticLimitKind {
StaticLimitKind::RustMacroWrappedAssertionUnresolved => {
"rust_macro_wrapped_assertion_unresolved"
}
StaticLimitKind::RustValuePropagationUnresolved => "rust_value_propagation_unresolved",
}
}

Expand Down Expand Up @@ -269,6 +275,11 @@ impl StaticLimitKind {
so the assertion semantics are unresolved. This is a named limitation, not a \
coverage claim."
}
StaticLimitKind::RustValuePropagationUnresolved => {
"A changed Rust value binding uses a bounded string or character operation, but \
ripr cannot carry that value into the same-owner equality predicate. This is a \
named analyzer limitation, not a coverage or repair claim."
}
}
}
}
Expand Down Expand Up @@ -367,6 +378,10 @@ mod tests {
StaticLimitKind::RustIntegrationPublicApiPathUnresolved.as_str(),
"rust_integration_public_api_path_unresolved"
);
assert_eq!(
StaticLimitKind::RustValuePropagationUnresolved.as_str(),
"rust_value_propagation_unresolved"
);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
assert_eq!(
StaticLimitKind::RustMacroReachUnresolved.as_str(),
"rust_macro_reach_unresolved"
Expand Down
13 changes: 13 additions & 0 deletions crates/ripr/src/lsp/gap_artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,7 @@ fn known_static_limit_kind(kind: &str) -> bool {
StaticLimitKind::RustMacroReachUnresolved,
StaticLimitKind::RustMacroWrappedTestCallUnresolved,
StaticLimitKind::RustMacroWrappedAssertionUnresolved,
StaticLimitKind::RustValuePropagationUnresolved,
]
.iter()
.any(|known| known.as_str() == kind)
Expand Down Expand Up @@ -2782,6 +2783,18 @@ mod tests {
Ok(())
}

#[test]
fn validation_accepts_rust_value_propagation_static_limit_kind() -> Result<(), String> {
let mut artifact = preview_gap_ledger();
artifact["records"][0]["language"] = json!("rust");
artifact["records"][0]["language_status"] = json!("stable");
artifact["records"][0]["static_limit_kind"] = json!("rust_value_propagation_unresolved");

validate_gap_artifact(&artifact, &context(&[LanguageId::Rust]))
.map_err(|err| format!("{err:?}"))?;
Ok(())
}

#[test]
fn evidence_record_validates_text_static_limits_without_parsing_action_semantics()
-> Result<(), String> {
Expand Down
6 changes: 4 additions & 2 deletions docs/OUTPUT_SCHEMA.md
Original file line number Diff line number Diff line change
Expand Up @@ -1214,11 +1214,13 @@ JSON fields:
`rust_integration_public_api_path_unresolved`, or
`rust_macro_reach_unresolved`, or
`rust_macro_wrapped_test_call_unresolved`, or
`rust_macro_wrapped_assertion_unresolved`.
`rust_macro_wrapped_assertion_unresolved`, or
`rust_value_propagation_unresolved`.
- `static_limitation` is an additive optional per-finding object emitted only
when a finding with `static_limit_kind` also carries a complete structured
limitation detail. Current Rust transitive-reach, integration public-API path,
macro-reach, direct test macro-call, and macro-wrapped assertion limitations
macro-reach, direct test macro-call, macro-wrapped assertion, and
value-propagation limitations
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
populate it from the same evidence lines rendered in human output. Fields are
`kind`, `last_established_edge`, `first_unresolved_edge`, `analyzer_route`,
and `non_claim`. The object is absent for static limits that do not have all
Expand Down
2 changes: 2 additions & 0 deletions docs/STATIC_LIMITS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ rust_integration_public_api_path_unresolved
rust_macro_reach_unresolved
rust_macro_wrapped_test_call_unresolved
rust_macro_wrapped_assertion_unresolved
rust_value_propagation_unresolved
```

When `static_limit_kind` is absent but stable static-limit text is present,
Expand All @@ -59,6 +60,7 @@ action.
| `rust_macro_reach_unresolved` | A Rust test appears to call an entry point whose path toward the changed owner stops at a same-repo macro invocation RIPR does not expand. | Inspect the macro path manually or improve macro-aware reach. Do not treat the macro mention as evidence that the test observes the change. |
| `rust_macro_wrapped_test_call_unresolved` | A Rust test directly invokes a same-repo macro whose definition mentions the changed owner, but RIPR does not expand that macro. | Treat this as first-run evidence that RIPR saw the test-body macro call but could not cross it. It is not a clean result, reach claim, or repair packet. |
| `rust_macro_wrapped_assertion_unresolved` | A Rust test reaches the changed owner, but the visible assertion-like custom macro is not classified as an oracle. | Treat this as first-run evidence that RIPR saw a candidate assertion macro but could not confirm its discriminator. It is not a clean result, oracle claim, or repair packet. |
| `rust_value_propagation_unresolved` | A changed Rust `let` binding uses a bounded `find`/`rfind` or `len_utf8` operation normalized through `map_or`, but syntax-first analysis cannot carry that value into a same-owner equality predicate. | Treat this as a named `static_unknown` analyzer limitation. Do not add a duplicate discriminator test or infer coverage, repair readiness, or a runtime result. |

## What Static Limits Do Not Mean

Expand Down
1 change: 1 addition & 0 deletions docs/specs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ observable behavior.
| [RIPR-SPEC-0137](RIPR-SPEC-0137-lsp-protocol-tracing.md) | accepted | LSP protocol tracing: session-local `off`/`messages`/`verbose` trace state with a manually validated `$/setTrace` lifecycle and structurally redacted `$/logTrace` emission (method/direction/class; bounded numeric metadata at verbose) that never touches snapshot, input-identity, diagnostic, action, or status state (#2035) |
| [RIPR-SPEC-0138](RIPR-SPEC-0138-lsp-codelens-refresh.md) | accepted | LSP CodeLens refresh lifecycle: negotiated `workspace.codeLens.refreshSupport` with a deterministic semantic lens-view identity (wall-clock excluded) so one `workspace/codeLens/refresh` is sent per changed visible lens view and none for byte-identical re-commits (#2032) |
| [RIPR-SPEC-0139](RIPR-SPEC-0139-lsp-workspace-folder-set-authority.md) | accepted | LSP workspace-folder set authority: one stored canonical folder set with validate-before-mutate delta application, typed bounded rejections, an epoch-bound reconciliation confirmation step, and no epoch bump for byte-identical transitions (#2036) |
| [RIPR-SPEC-0150](RIPR-SPEC-0150-rust-value-propagation-limitation.md) | accepted | Rust bounded value-propagation limitation: name `find`/`rfind` or `len_utf8` plus `map_or` changed-let values that cannot reach a same-owner equality predicate; keep `static_unknown`, fail closed, and emit no repair route (#3215) |
| [RIPR-SPEC-0140](RIPR-SPEC-0140-check-artifact-reuse.md) | accepted | Check-artifact reuse: explicit `check --write-artifact` / `explain\|context --from` pair with a full-fidelity `CheckArtifactV1` envelope, atomic writes, a fail-closed identity gate (diff bytes, root, mode, languages, analysis options, versioned config identity, analyzer version), and byte-identical reused rendering (#2107) |
| [RIPR-SPEC-0141](RIPR-SPEC-0141-lsp-typed-component-degradation.md) | accepted | LSP typed component-outcome degradation model: bounded per-component outcomes on the snapshot, one shared run-status aggregation, deduplicated `window/logMessage` warnings with recovery routes, and no hidden-stderr degradation reporting (#1997) |
| [RIPR-SPEC-0142](RIPR-SPEC-0142-lsp-git-input-authority.md) | accepted | LSP Git input authority: one typed request-local `ResolvedGitInputs` resolution per accepted refresh shared by input identity, dedup, snapshot, and status, with episode-bounded reuse, explicit invalidation, and fail-closed unresolved/loader-default states (#2000) |
Expand Down
46 changes: 46 additions & 0 deletions docs/specs/RIPR-SPEC-0150-rust-value-propagation-limitation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# RIPR-SPEC-0150: Rust bounded value-propagation limitation

Status: accepted

Issue: #3215

## Contract

When a changed Rust `let` binding has a right-hand side containing `map_or`
and one of the bounded operation families `find`, `rfind`, or `len_utf8`, and
the same owner function later compares that binding in an equality predicate,
RIPR may emit:

```text
static_limit_kind: rust_value_propagation_unresolved
class: static_unknown
```

The finding must retain related tests when they are already discovered. It
must disclose the last established binding, the first unresolved edge into
the equality predicate, the analyzer route
`analysis/rust-value-propagation`, and a limitation-only non-claim.

## Required guards

- the changed line must parse as a simple `let` binding;
- the operation-family and `map_or` checks apply to the changed right-hand
side, not arbitrary owner text;
- the compared identifier must be a whole identifier in the same owner body;
- a missing owner or missing related tests produces no new limitation;
- unrelated helper, loop, dynamic, and non-equality shapes remain unchanged;
- classification is never promoted and no repair packet or verify command is
synthesized.

## Proof

The production-path Rust adapter fixture covers the `rfind`/`map_or` binding
feeding an equality predicate with two exact related tests. Negative controls
cover a non-family `len` binding and must not receive this limitation. The
stable enum wire string and LSP accepted-kind catalog are tested separately.

## Non-goals

This slice does not resolve value propagation, prove the equality boundary,
change probe-family inference, execute mutations, calculate rates, or create
repair/test instructions. Those are later bounded slices of #3215.
Loading
Loading