Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benches/pons_bench.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ while [ "$#" -gt 0 ]; do
done

REPS=5
BIN="target/release/pons"
BIN="${CARGO_TARGET_DIR:-target}/release/pons"

echo "bench: building pons-cli (release)"
if ! cargo build --release --locked -p pons-cli; then
Expand Down
43 changes: 24 additions & 19 deletions crates/pons-rules/src/t1/read_before_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@ use tree_sitter::Node;

const LANGUAGES: &[Lang] = &[Lang::Python];

/// Rule 10: a read of a local that some path reaches before the name is
/// bound — Python raises `UnboundLocalError`. `WARN` uniformly in v0.1.0:
/// raising the every-path case to `ERROR` would need a must-analysis, which
/// ADR-0002 declines. Python has no default initialisation, so the rule has
/// no counter-condition. Opacity and scope are handled by the OPAQUE hatch and
/// the locals pre-pass; the analysis is also path-insensitive, so correlated
/// guards and loops over non-empty literals yield infeasible-path false
/// positives that ADR-0002 does not yet name (#47).
/// Rule 10: a local read may precede binding in the abstract CFG.
/// WARN denotes a dataflow finding, not a proven feasible Python execution.
/// Correlated guards, exceptional paths and opaque constructs limit precision.
/// The bounded pruning pass accepts plain names only, never attributes whose
/// descriptor evaluation may change between reads.
pub struct ReadBeforeInit;

impl ReadBeforeInit {
Expand Down Expand Up @@ -47,7 +44,8 @@ impl Rule for ReadBeforeInit {
}

/// Reports possible unbound local reads in analysable functions as `WARN`,
/// without counter-conditions. Opaque functions produce no findings.
/// with an explicit path-feasibility counter-condition. Opaque functions
/// produce no findings.
/// Offsets selected by the bounded correlated-guard pass are omitted.
fn check(&self, ctx: &RuleCtx) -> Vec<RawFinding> {
let mut findings = Vec::new();
Expand All @@ -73,10 +71,10 @@ impl Rule for ReadBeforeInit {
"local may be read before it is assigned",
format!(
"on at least one path through `{}`, `{name}` is read here before it \
is assigned — Python raises `UnboundLocalError`",
is assigned in the abstract CFG; path feasibility is not established",
cfg.name()
),
None,
Some("Correlated conditions, exceptional control flow or other model limitations may make this abstract path infeasible.".into()),
));
}
}
Expand All @@ -86,8 +84,11 @@ impl Rule for ReadBeforeInit {

/// Extract a textual base and polarity from an `is None` or `is not None`
/// suffix with exactly that spacing. The trimmed base may contain only ASCII
/// letters, digits, underscores and dots; calls are rejected. This is a
/// syntactic filter and does not establish that attribute access is pure.
/// letters, digits and underscores. Attribute access is rejected because a
/// Python descriptor may return a different value on every read.
/// Returns the base and `none` or `not-none` polarity, or `None` if the
/// suffix or non-empty base does not match. This is a textual filter, not
/// Python identifier validation. `text` must be the source for `cond`.
fn guard_key(cond: Node<'_>, text: &str) -> Option<(String, String)> {
let raw = &text[cond.byte_range()];
let (base, polarity) = if let Some(base) = raw.strip_suffix(" is not None") {
Expand All @@ -97,11 +98,7 @@ fn guard_key(cond: Node<'_>, text: &str) -> Option<(String, String)> {
(base, "none")
};
let base = base.trim();
if base.is_empty()
|| !base
.chars()
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '_' | '.'))
{
if base.is_empty() || !base.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {
return None;
}
Some((base.to_string(), polarity.to_string()))
Expand Down Expand Up @@ -300,7 +297,7 @@ mod tests {

#[test]
fn a_correlated_guard_read_is_pruned_but_a_mismatched_guard_is_not() {
let correlated = "def pack(self):\n if self.name is not None:\n name = 1\n if self.name is not None:\n MonsterAddName(name)\n";
let correlated = "def pack(value):\n if value is not None:\n name = 1\n if value is not None:\n MonsterAddName(name)\n";
assert!(
check(correlated).is_empty(),
"identical pure guard was not pruned"
Expand All @@ -314,6 +311,14 @@ mod tests {
);
}

#[test]
fn attribute_guards_are_not_assumed_pure_or_stable() {
let src = "def pack(self):\n if self.name is not None:\n name = 1\n if self.name is not None:\n return name\n";
let findings = check(src);
assert_eq!(findings.len(), 1, "a descriptor can change between reads");
assert!(findings[0].counter_condition().is_some());
}

#[test]
fn a_mutation_between_identical_guards_disables_pruning() {
let src = "def pack(self):\n if self.name is not None:\n name = 1\n self = other\n if self.name is not None:\n MonsterAddName(name)\n";
Expand Down
32 changes: 32 additions & 0 deletions docs/ASSURANCE-AUDIT-2026-11-04.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SPDX-FileCopyrightText: 2026 Jonathan D.A. Jewell (hyperpolymath)
// SPDX-License-Identifier: CC-BY-SA-4.0
= Assurance audit repair — 2026-11-04

Base `84f58f910de7020b79450f2c2643599fe7760f73` passed 250 Rust tests.
The expanded suite passes 251. Tests are not proofs of analysis soundness.

== Descriptor counterexample

The former negative `read-before-init/correlated_guard.py` repeats
`self.name is not None`. Python descriptors may return None on the first access
and a value on the second. With MonsterAddName bound to a harmless function,
executing that specimen raises UnboundLocalError before the call.

The exact original specimen is retained in `positive/attribute_guard.py`.
The corrected negative snapshots `self.name` into a local once. The optimisation
now refuses attribute guards, and finding evidence states that abstract CFG
paths may be infeasible. This does not close general path-sensitivity issue #47,
exception modelling or the other limits of the remaining plain-name pruning.

== Other evidence

Both scanners ran against cicd-suite and proven-tests-and-benches. Strict scans
were partial: Pons analysed 1 and 8 files respectively. Those repositories'
shell/configuration/Idris source is not certified by these runs. The shared suite
contains the reproducible bounded parser/report controls and detailed audit.

The benchmark harness now locates the binary under CARGO_TARGET_DIR when set.
Exploratory timings on modified worktrees are not accepted regression baselines;
source commit, dirty state, binary/toolchain and workload identity must accompany
any comparison. Mathematical source-to-model soundness and independent oracle
coverage remain open.
7 changes: 4 additions & 3 deletions fixtures/read-before-init/negative/correlated_guard.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# The same pure None guard bounds both the definition and the use.
# Snapshot the descriptor once; subsequent local identity tests are stable.
def pack(self):
if self.name is not None:
value = self.name
if value is not None:
name = 1
if self.name is not None:
if value is not None:
MonsterAddName(name)
6 changes: 6 additions & 0 deletions fixtures/read-before-init/positive/attribute_guard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# The same pure None guard bounds both the definition and the use.
def pack(self):
if self.name is not None:
name = 1
if self.name is not None:
MonsterAddName(name)
Loading