blob: cfe1958c558e46fb5d28516ddd2b284ce8af36a8 [file]
# Copyright 2026 The Fuchsia Authors
#
# Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0
# <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT
# license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option.
# This file may not be copied, modified, or distributed except according to
# those terms.
"""Guard-mutation CI check for Anneal's MIR semantics, auditor, and capture.
Why this check exists
---------------------
Positive verification proofs and positive canary suites cannot catch an
accidental deletion or weakening of an undefined-behavior (UB) guard or policy
rejection branch. If a refactor drops division-by-zero checking, removes an
alignment check, disables a MIR capture refusal, or loosens an import
restriction, every positive proof still succeeds while unsound programs
silently become provable.
This script closes that blind spot by performing single-guard mutation testing
in temporary directories (never modifying the repository working tree):
1. Against the unmodified TCB sources, every negative refutation theorem in
`ci/fixtures/guard_mutation/` must compile with zero errors, every negative
header or boundary fixture must be rejected by `TrustedBoundary.lean` with
a policy error (`exit 1`, `"category": "policy"`), and every negative
`anneal-rustc-capture` witness or unit test must reject as expected.
2. For each cataloged guard, the runner disables only that guard inside a fresh
`tempfile.TemporaryDirectory()` copy, confirms that the mutated TCB module
and positive sanity checks still compile/pass cleanly (preventing syntax or
type errors from masquerading as mutant kills), and verifies that the
guard's targeted negative refutation fails with a proof/type error on the
target theorem (or flips from reject to accept in `TrustedBoundary.lean` /
`anneal-rustc-capture`, or breaks its targeted negative unit test).
3. The check exits `0` only if 100% of executed guards are killed.
What this check guarantees — and what it does NOT guarantee
-----------------------------------------------------------
- **Guarantees:** Every guard listed in `MIR_SEMANTICS_GUARDS`,
`AUDIT_HEADER_GUARDS`, `AUDIT_BOUNDARY_GUARDS`, and `EXTRACT_GUARDS` is
exercised by a targeted negative refutation, auditor/capture witness, or unit
test whose outcome changes when that single guard is weakened. Most entries
verify sole UB or admission gates; `EXTRACT_GUARDS` entries marked
`allow_downstream_fallback=True` (`extract_reject_cleanup_block`,
`extract_reject_uninstantiated_generic_fn`, and
`extract_eval_required_consts`) pin diagnostic precedence ahead of downstream
refusals, and `MIR_SEMANTICS_GUARDS` also includes lockstep fault-kind
classification, Profile-v1 alignment, and function-level defense-in-depth
guards labeled in their descriptions.
- **Does NOT guarantee:** Coverage of unmodeled Rust semantics, guards added to
`Trusted/MirSemantics/`, `TrustedBoundary.lean`, or
`trusted/rustc-capture/src/` without a catalog entry, or automatic GitHub
Actions execution of `EXTRACT_GUARDS` until `--suite extract_guards` is wired
into a `rustc-dev` CI job (invoking `--suite all` without a `rustc-dev`
toolchain auto-skips `extract_guards`, while
`run_anneal_check.sh guard-mutation` passes `--lean-only` explicitly; both
record `extract_guards` in `skipped_suites`).
How to add a new guard
----------------------
Whenever a new UB check lands in `trusted/lean/Trusted/MirSemantics/`, a new
policy guard lands in `trusted/audit/TrustedBoundary.lean`, or a new admission
guard lands in `trusted/rustc-capture/src/`:
1. Add a minimal negative refutation theorem `refute_<guard_id>` in the
corresponding `ci/fixtures/guard_mutation/*Refutations.lean` file (or a
negative fixture/unit test for `AUDIT_HEADER_GUARDS`,
`AUDIT_BOUNDARY_GUARDS`, or `EXTRACT_GUARDS`).
2. Add a matching `MirSemanticsGuard`, `AuditHeaderGuard`,
`AuditBoundaryGuard`, or `ExtractGuard` entry below whose `anchor` matches
the guard expression uniquely and whose `replacement` weakens only that
guard while keeping the mutated source well-typed.
3. For Lean or auditor guards, run
`python3 -I -B ci/check_guard_mutation.py --lean <path-to-lean>`; for
`ExtractGuard` entries, run `python3 -I -B` on
`ci/check_guard_mutation.py --suite extract_guards --rustc <pinned-rustc>`
(since `--suite all` skips `extract_guards` when `rustc-dev` is absent) and
confirm a 100% kill rate.
"""
from __future__ import annotations
import argparse
from concurrent.futures import ThreadPoolExecutor, as_completed
from dataclasses import asdict, dataclass
import json
import os
from pathlib import Path
import re
import shutil
import subprocess
import sys
import tempfile
import time
import tomllib
# Base trusted Lean modules compiled once into the shared baseline `.olean`
# directory. No cataloged mutant modifies these files, so every mutant reuses
# their precompiled `.olean` artifacts via left-to-right `LEAN_PATH`.
BASE_TRUSTED_MODULES: tuple[str, ...] = (
"Trusted",
"Trusted/MirAst/Types",
"Trusted/MirAst/Places",
"Trusted/MirAst/Rvalues",
"Trusted/MirAst/Statements",
"Trusted/MirAst/Terminators",
"Trusted/MirAst/Body",
"Trusted/MirAst",
"Trusted/MirModel",
)
# Guard-bearing semantics modules in strict topological import order. When a
# guard mutates one of these modules, only that module and the modules
# reachable from it in `SEMANTICS_DOWNSTREAM` need to be recompiled for that
# mutant.
SEMANTICS_MODULES: tuple[str, ...] = (
"Trusted/MirSemantics/Ops",
"Trusted/MirSemantics/Enum",
"Trusted/MirSemantics/Layout",
"Trusted/MirSemantics/Memory",
"Trusted/MirSemantics/Bytes",
"Trusted/MirSemantics/CoreContracts",
"Trusted/MirSemantics/AllocContracts",
"Trusted/MirSemantics/State",
"Trusted/MirSemantics/Step",
"Trusted/MirSemantics/Boundary",
"Trusted/MirSemantics/Contract",
)
# `Trusted/MirSemantics/*.lean` modules intentionally omitted from mutation
# coverage because they contain concrete canary programs/claims rather than
# guard branches (`CanaryFixtures.lean` is checked directly by Pass 1
# `Trusted.MirSemantics` canary proofs and Pass 2 `Trusted.Correspondence`).
NON_GUARD_SEMANTICS_MODULES: tuple[str, ...] = (
"Trusted/MirSemantics/CanaryFixtures",
)
# Per-module rebuild closure (inclusive, in topological order) recompiled for
# each mutable semantics module. `Layout` and `Memory` intentionally prune
# `State`/`Step`/`Boundary`/`Contract`, and `Ops`..`Boundary` prune `Contract`
# because their dedicated sanity and refutation fixtures import at most
# `Boundary` / `Bytes` / `Memory`; `validate_catalog_invariants` enforces that
# no fixture or sanity module used by a guard transitively imports a downstream
# semantics module omitted from its rebuild list.
SEMANTICS_DOWNSTREAM: dict[str, tuple[str, ...]] = {
"Trusted/MirSemantics/Ops": (
"Trusted/MirSemantics/Ops",
"Trusted/MirSemantics/Enum",
"Trusted/MirSemantics/Layout",
"Trusted/MirSemantics/Memory",
"Trusted/MirSemantics/Bytes",
"Trusted/MirSemantics/CoreContracts",
"Trusted/MirSemantics/AllocContracts",
"Trusted/MirSemantics/State",
"Trusted/MirSemantics/Step",
"Trusted/MirSemantics/Boundary",
),
"Trusted/MirSemantics/Enum": (
"Trusted/MirSemantics/Enum",
"Trusted/MirSemantics/Layout",
"Trusted/MirSemantics/Memory",
"Trusted/MirSemantics/Bytes",
"Trusted/MirSemantics/CoreContracts",
"Trusted/MirSemantics/AllocContracts",
"Trusted/MirSemantics/State",
"Trusted/MirSemantics/Step",
"Trusted/MirSemantics/Boundary",
),
"Trusted/MirSemantics/Layout": (
"Trusted/MirSemantics/Layout",
"Trusted/MirSemantics/Memory",
"Trusted/MirSemantics/Bytes",
),
"Trusted/MirSemantics/Memory": (
"Trusted/MirSemantics/Memory",
),
"Trusted/MirSemantics/Bytes": (
"Trusted/MirSemantics/Bytes",
"Trusted/MirSemantics/CoreContracts",
"Trusted/MirSemantics/AllocContracts",
"Trusted/MirSemantics/State",
"Trusted/MirSemantics/Step",
"Trusted/MirSemantics/Boundary",
),
"Trusted/MirSemantics/CoreContracts": (
"Trusted/MirSemantics/CoreContracts",
"Trusted/MirSemantics/AllocContracts",
"Trusted/MirSemantics/Step",
"Trusted/MirSemantics/Boundary",
),
"Trusted/MirSemantics/State": (
"Trusted/MirSemantics/State",
"Trusted/MirSemantics/Step",
"Trusted/MirSemantics/Boundary",
),
"Trusted/MirSemantics/AllocContracts": (
"Trusted/MirSemantics/AllocContracts",
"Trusted/MirSemantics/Step",
"Trusted/MirSemantics/Boundary",
),
"Trusted/MirSemantics/Step": (
"Trusted/MirSemantics/Step",
"Trusted/MirSemantics/Boundary",
),
"Trusted/MirSemantics/Boundary": (
"Trusted/MirSemantics/Boundary",
),
"Trusted/MirSemantics/Contract": (
"Trusted/MirSemantics/Contract",
),
}
# Fixture helper modules compiled once against the baseline and rebuilt per
# mutant only when needed by that mutant's fixture.
FIXTURE_HELPERS_END_TO_END: tuple[str, ...] = (
"GuardRefuteBase",
"GuardRefuteWf",
)
FIXTURE_HELPERS_BOUNDARY: tuple[str, ...] = (
"GuardRefuteBase",
)
# Error substrings that indicate a compiler crash, parse error, missing import,
# or resource exhaustion rather than a genuine proof refutation failure. Any
# mutant whose fixture fails with one of these is classified as an error rather
# than a kill so broken fixtures or crashes can never masquerade as kills.
NON_KILL_ERROR_MARKERS: tuple[str, ...] = (
"unknown identifier",
"unknown constant",
"unknown module",
"expected token",
"unexpected token",
"maximum recursion depth",
"deterministic timeout",
"heartbeat_limit_exceeded",
"recursion_depth_exceeded",
"PANIC",
"internal exception",
"invalid import",
)
# Diagnostic substrings produced by Lean 4 when a refutation theorem fails to
# type-check because the mutated semantics no longer rejects the UB program.
EXPECTED_PROOF_FAILURE_MARKERS: tuple[str, ...] = (
"Type mismatch",
"type mismatch",
"has type",
"rfl",
"unsolved goals",
"Function expected",
"Application type mismatch",
"failed to synthesize",
"invalid field",
"is not a valid",
)
@dataclass(frozen=True)
class MirSemanticsGuard:
"""Single-guard mutation entry targeting `Trusted/MirSemantics/`."""
guard_id: str
target_file: str
target_module: str
description: str
anchor: str
replacement: str
fixture_module: str
theorem_name: str
sanity_module: str = "PositiveSanity"
needs_wf_helper: bool = True
@dataclass(frozen=True)
class AuditHeaderGuard:
"""Single-guard mutation entry targeting `TrustedBoundary.lean` or `SpecPreflight.lean` headers."""
guard_id: str
target_file: str
description: str
anchor: str
replacement: str
negative_source: str
@dataclass(frozen=True)
class AuditBoundaryGuard:
"""Single-guard mutation entry for spec-preflight or target-audit."""
guard_id: str
target_file: str
mode: str # "spec-preflight" | "target-audit"
description: str
anchor: str
replacement: str
fixture_id: str
@dataclass(frozen=True)
class ExtractGuard:
"""Single-guard mutation entry targeting `trusted/rustc-capture/src/`."""
guard_id: str
target_file: str
mode: str # "capture" | "unit"
description: str
anchor: str
replacement: str
negative_source: str = ""
capture_scope: str = "select" # "select" | "crate" | "instantiate"
select_root: str = "selected"
instantiate_json: str = ""
expected_baseline_status: str = "unsupported"
expected_baseline_diagnostic: str = ""
expected_fallback_diagnostic: str = ""
allow_downstream_fallback: bool = False
allow_unstable_features: tuple[str, ...] = ()
stdlib_crate: str = ""
panic_strategy: str = ""
# `--exclude-trait` paths for `capture` mode. Such guards use
# `EXCLUDE_TRAIT_POSITIVE_SANITY_SOURCE` as their positive sanity input.
exclude_traits: tuple[str, ...] = ()
unit_test_name: str = ""
sanity_unit_test: str = (
"extract::tests::use_retag_is_admitted_only_for_retag_noop_types"
)
@dataclass(frozen=True)
class GuardResult:
"""Outcome of executing one guard-mutation check."""
suite: str
guard_id: str
target_file: str
status: str # KILLED | SURVIVED | ERROR
duration_sec: float
detail: str
MIR_SEMANTICS_GUARDS: tuple[MirSemanticsGuard, ...] = (
MirSemanticsGuard(
guard_id="bytes_adt_single_index",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="an untagged payload enum holds the variant its layout names",
anchor=" | .single => .ok (some l.tagValidStart)",
replacement=" | .single => .ok (some 0)",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_single_index",
),
MirSemanticsGuard(
guard_id="layout_adt_single_other_uninhabited",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="an untagged payload enum's other variants are uninhabited",
anchor=" (!adtSingleOtherVariantV2 l i || fieldsHaveNeverV2 fs) &&",
replacement=" true &&",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_adt_single_other_uninhabited",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_adt_single_head_index",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="an untagged payload enum names one of its variants",
anchor=" Nat.blt l.tagValidStart n && Nat.beq l.tagValidStart l.tagValidEnd",
replacement=" true",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_adt_single_head_index",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_never_no_value",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="decoding `!` yields no value",
anchor=" | .never => .ok none",
replacement=" | .never => .ok (some .unit)",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_never_no_value",
),
MirSemanticsGuard(
guard_id="core_try_branch_result_err_breaks",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Result::branch` maps `Err(e)` to `Break(Err(e))`",
anchor=(
" .ok (.adtVal 1 (.tuple [.adtVal 1 (.tuple [e])]), m)"
),
replacement=(
" .ok (.adtVal 0 (.tuple [e]), m)"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_result",
),
MirSemanticsGuard(
guard_id="core_try_branch_result_src_shape",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Result::branch` checks the source `Result` shape",
anchor=(
" if !adtResultShapeV2 ok err vs ||\n"
" !adtControlFlowV2 ok (adtResultResidualV2 err) dstTy then"
),
replacement=(
" if false ||\n"
" !adtControlFlowV2 ok (adtResultResidualV2 err) dstTy then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_result",
),
MirSemanticsGuard(
guard_id="core_try_branch_result_dst",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Result::branch` checks the destination `ControlFlow`",
anchor=(
" !adtControlFlowV2 ok (adtResultResidualV2 err) dstTy then"
),
replacement=(
" false then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_result",
),
MirSemanticsGuard(
guard_id="core_adt_result_shape_ok",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="a `Result` shape compares the `Ok` field type",
anchor=(
" | [.struct_ _ [o], .struct_ _ [e]] => MirTy.beq o ok && MirTy.beq e err"
),
replacement=(
" | [.struct_ _ [_], .struct_ _ [e]] => MirTy.beq e err"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_result",
),
MirSemanticsGuard(
guard_id="core_adt_result_shape_err",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="a `Result` shape compares the `Err` field type",
anchor=(
" | [.struct_ _ [o], .struct_ _ [e]] => MirTy.beq o ok && MirTy.beq e err"
),
replacement=(
" | [.struct_ _ [o], .struct_ _ [_]] => MirTy.beq o ok"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_result",
),
MirSemanticsGuard(
guard_id="core_adt_control_flow_continue",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="a `ControlFlow` shape compares the `Continue` type",
anchor=(
" MirTy.beq c cont && isResidual b"
),
replacement=(
" isResidual b"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_result",
),
MirSemanticsGuard(
guard_id="core_adt_control_flow_break",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="a `ControlFlow` shape checks the `Break` residual",
anchor=(
" MirTy.beq c cont && isResidual b"
),
replacement=(
" MirTy.beq c cont"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_result",
),
MirSemanticsGuard(
guard_id="core_try_branch_option_none_breaks",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Option::branch` maps `None` to `Break(None)`",
anchor=(
" | none => .ok (.adtVal 1 (.tuple [.adtVal 0 (.tuple [])]), m)"
),
replacement=(
" | none => .ok (.adtVal 0 (.tuple []), m)"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_option",
),
MirSemanticsGuard(
guard_id="core_try_branch_option_inner",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Option::branch` checks the source `Option` type",
anchor=(
" if !MirTy.beq inner inInner ||\n"
" !adtControlFlowV2 inner adtOptionResidualV2 dstTy then"
),
replacement=(
" if false ||\n"
" !adtControlFlowV2 inner adtOptionResidualV2 dstTy then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_option",
),
MirSemanticsGuard(
guard_id="core_try_branch_option_dst",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Option::branch` checks the destination `ControlFlow`",
anchor=(
" if !MirTy.beq inner inInner ||\n"
" !adtControlFlowV2 inner adtOptionResidualV2 dstTy then"
),
replacement=(
" if !MirTy.beq inner inInner ||\n"
" false then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_option",
),
MirSemanticsGuard(
guard_id="core_try_branch_option_adt_some_continues",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="payload-enum `Option::branch` maps `Some(v)` to `Continue(v)`",
anchor=(
" | 1, .tuple [v] =>\n"
" if !tryPayloadValidV2 m inner v then\n"
" .error .undefined\n"
" else\n"
" .ok (.adtVal 0 (.tuple [v]), m)"
),
replacement=(
" | 1, .tuple [v] =>\n"
" if !tryPayloadValidV2 m inner v then\n"
" .error .undefined\n"
" else\n"
" .ok (.adtVal 1 (.tuple [v]), m)"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_option",
),
MirSemanticsGuard(
guard_id="core_try_branch_option_adt_shape",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="payload-enum `Option::branch` checks the source shape",
anchor=(
" if !adtOptionShapeV2 inner vs ||\n"
" !adtControlFlowV2 inner adtOptionResidualV2 dstTy then"
),
replacement=(
" if false ||\n"
" !adtControlFlowV2 inner adtOptionResidualV2 dstTy then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_option",
),
MirSemanticsGuard(
guard_id="core_try_branch_option_adt_dst",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="payload-enum `Option::branch` checks the destination",
anchor=(
" if !adtOptionShapeV2 inner vs ||\n"
" !adtControlFlowV2 inner adtOptionResidualV2 dstTy then"
),
replacement=(
" if !adtOptionShapeV2 inner vs ||\n"
" false then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_option",
),
MirSemanticsGuard(
guard_id="core_adt_option_residual",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Option<Infallible>` residual holds `!` in `Some`",
anchor=(
" | .adtEnum _ vs => adtOptionShapeV2 .never vs"
),
replacement=(
" | .adtEnum _ _ => true"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_branch_option",
),
MirSemanticsGuard(
guard_id="core_from_residual_result_identity",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Result::from_residual` requires the identity `From`",
anchor=(
" if !adtResultResidualV2 err resTy then"
),
replacement=(
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_from_residual_result",
),
MirSemanticsGuard(
guard_id="core_from_residual_result_dst",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Result::from_residual` checks the destination `Result`",
anchor=(
" if !adtResultShapeV2 ok err vs then\n"
" .error .unsupported"
),
replacement=(
" if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_core_from_residual_result",
),
MirSemanticsGuard(
guard_id="core_try_payload_refs_valid",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`tryPayloadValidV2` validates payload references/handles in memory",
anchor=" refsValidInMem m ty v && spansPairwiseDisjoint (valueAccessSpans m ty v)",
replacement=" spansPairwiseDisjoint (valueAccessSpans m ty v)",
fixture_module="StepRefutations",
theorem_name="refute_core_try_payload_valid",
),
MirSemanticsGuard(
guard_id="core_try_payload_spans_disjoint",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`tryPayloadValidV2` checks pairwise disjointness of payload access spans",
anchor=" refsValidInMem m ty v && spansPairwiseDisjoint (valueAccessSpans m ty v)",
replacement=" refsValidInMem m ty v",
fixture_module="StepRefutations",
theorem_name="refute_core_try_payload_valid",
),
MirSemanticsGuard(
guard_id="core_try_branch_result_ok_valid",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Result::branch` validates `Ok` payload at call boundary",
anchor=(
" | 0, .tuple [v] =>\n"
" if !tryPayloadValidV2 m ok v then"
),
replacement=(
" | 0, .tuple [v] =>\n"
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_payload_valid",
),
MirSemanticsGuard(
guard_id="core_try_branch_result_err_valid",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Result::branch` validates `Err` payload at call boundary",
anchor=(
" | 1, .tuple [e] =>\n"
" if !tryPayloadValidV2 m err e then"
),
replacement=(
" | 1, .tuple [e] =>\n"
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_payload_valid",
),
MirSemanticsGuard(
guard_id="core_try_branch_option_valid",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Option::branch` validates `.option` `Some` payload at call boundary",
anchor=(
" | some v =>\n"
" if !tryPayloadValidV2 m inner v then"
),
replacement=(
" | some v =>\n"
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_payload_valid",
),
MirSemanticsGuard(
guard_id="core_try_branch_option_adt_valid",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Option::branch` validates payload-enum `Some` payload at call boundary",
anchor=(
" | 1, .tuple [v] =>\n"
" if !tryPayloadValidV2 m inner v then"
),
replacement=(
" | 1, .tuple [v] =>\n"
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_try_payload_valid",
),
MirSemanticsGuard(
guard_id="core_from_residual_result_valid",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Result::from_residual` validates `Err` payload at call boundary",
anchor=" else if !tryPayloadValidV2 m err e then",
replacement=" else if false then",
fixture_module="StepRefutations",
theorem_name="refute_core_try_payload_valid",
),
MirSemanticsGuard(
guard_id="core_from_residual_option_residual",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Option::from_residual` checks the residual type",
anchor=(
" if !adtOptionResidualV2 resTy then"
),
replacement=(
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_from_residual_option",
),
MirSemanticsGuard(
guard_id="core_from_residual_option_dst",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Option::from_residual` checks the destination `Option`",
anchor=(
" if MirTy.beq dInner inner then .ok (.optionVal none, m)"
),
replacement=(
" if true then .ok (.optionVal none, m)"
),
fixture_module="StepRefutations",
theorem_name="refute_core_from_residual_option",
),
MirSemanticsGuard(
guard_id="core_from_residual_option_adt_dst",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="`Option::from_residual` checks a payload-enum destination",
anchor=(
" if adtOptionShapeV2 inner vs then .ok (.adtVal 0 (.tuple []), m)"
),
replacement=(
" if true then .ok (.adtVal 0 (.tuple []), m)"
),
fixture_module="StepRefutations",
theorem_name="refute_core_from_residual_option",
),
MirSemanticsGuard(
guard_id="bytes_refs_valid_ref_enum",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refsValidInMem validates a payload enum's reference fields "
"through the active variant"
),
anchor=" | some (.struct_ _ fs) => refsValidInMemList m fs pvs",
replacement=" | some (.struct_ _ _) => true",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_refs_valid_ref_enum",
),
MirSemanticsGuard(
guard_id="bytes_refs_valid_ref_enum_shape",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refsValidInMem refuses a payload enum payload that is not a "
"tuple of the variant's fields"
),
anchor=(
" | _ => false\n"
" | _ => false\n"
" else"
),
replacement=(
" | _ => false\n"
" | _ => true\n"
" else"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_refs_valid_ref_enum_shape",
),
MirSemanticsGuard(
guard_id="bytes_ref_alloc_ids_ref_enum",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refAllocIds sees a reference inside a payload enum",
anchor=" | some t => refAllocIds t p",
replacement=" | some _ => []",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_ref_alloc_ids_ref_enum",
),
MirSemanticsGuard(
guard_id="bytes_ptr_or_ref_alloc_ids_ref_enum",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="ptrOrRefAllocIds sees a reference inside a payload enum",
anchor=" | some t => ptrOrRefAllocIds t p",
replacement=" | some _ => []",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_ptr_or_ref_alloc_ids_ref_enum",
),
MirSemanticsGuard(
guard_id="bytes_ref_access_spans_ref_enum",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refAccessSpans sees a reference inside a payload enum",
anchor=" | some t => refAccessSpans t p",
replacement=" | some _ => []",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_ref_access_spans_ref_enum",
),
MirSemanticsGuard(
guard_id="enum_v2_ref_enum_fields",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"a payload enum with reference fields has only shared references "
"and heap-free owned data as fields"
),
anchor=" | ty => isOwnedDataTyV2 ty && !tyHasHeapHandleV2 ty",
replacement=" | _ => true",
fixture_module="BytesRefutations",
theorem_name="refute_enum_v2_ref_enum_fields",
),
MirSemanticsGuard(
guard_id="enum_v2_nested_ref_outer_shared",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="a two-level reference local has a shared outer reference",
anchor=" | .ref .shared (.ref _ pt) => isNestedRefInnerPointeeV2 pt",
replacement=" | .ref _ (.ref _ pt) => isNestedRefInnerPointeeV2 pt",
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_nested_ref_outer_shared",
),
MirSemanticsGuard(
guard_id="enum_v2_nested_ref_arm_pointee",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"a two-level reference local, `&&T` or `& &mut T`, has an admitted "
"inner pointee"
),
anchor=" | .ref .shared (.ref _ pt) => isNestedRefInnerPointeeV2 pt",
replacement=" | .ref .shared (.ref _ pt) => true",
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_nested_ref_arm_pointee",
),
MirSemanticsGuard(
guard_id="enum_v2_nested_ref_inner_pointee",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"a two-level reference local's inner pointee is sized and not a "
"reference or raw pointer"
),
anchor=" | .slice _ | .ref _ _ | .rawPtr _ _ => false",
replacement=" | .slice _ | .ref _ _ | .rawPtr _ _ => true",
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_nested_ref_inner_pointee",
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_nested_inner",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refValidInMem checks the inner reference of a `&&T`",
anchor=" ptrValidInMemV2 m (Mutability.beq innerMut .mut) innerPt innerP",
replacement=" (Except.ok () : Except FaultKind Unit)",
fixture_module="StepRefutations",
theorem_name="refute_bytes_v2_ref_valid_nested_inner",
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_nested_shared_only",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refValidInMem admits a `&&T` only as a shared reference",
anchor=(
" if !Mutability.beq reqMut .shared ||\n"
" !isNestedRefInnerPointeeV2 innerPt then"
),
replacement=(
" if false ||\n"
" !isNestedRefInnerPointeeV2 innerPt then"
),
fixture_module="StepRefutations",
theorem_name="refute_bytes_v2_ref_valid_nested_shared_only",
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_nested_inner_mut_alloc",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refValidInMem requires the inner `&mut T` of a `& &mut T` to point "
"into a mutable allocation"
),
anchor=(
" else if isMut && Nat.blt 0 lay.size &&\n"
" !Mutability.beq a.mutability .mut then\n"
" .error .undefined"
),
replacement=(
" else if false then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_bytes_v2_ref_valid_nested_inner_mut_alloc",
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_nested_inner_mut_checked",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refValidInMem applies the mutable-allocation check to an inner "
"`&mut T`"
),
anchor=" ptrValidInMemV2 m (Mutability.beq innerMut .mut) innerPt innerP",
replacement=" ptrValidInMemV2 m false innerPt innerP",
fixture_module="StepRefutations",
theorem_name="refute_bytes_v2_ref_valid_nested_inner_mut_checked",
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_nested_inner_mut_heap",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refValidInMem requires the inner `&mut T` of a `& &mut T` to own "
"mutable heap buffers"
),
anchor=" | .ok (some decVal) => ownedValidInMem m isMut pointee decVal",
replacement=" | .ok (some decVal) => ownedValidInMem m false pointee decVal",
fixture_module="StepRefutations",
theorem_name="refute_bytes_v2_ref_valid_nested_inner_mut_heap",
),
MirSemanticsGuard(
guard_id="bytes_array_owned_each_elem",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"ownedValidInMem/recOwnedWalkV2 checks every element of an array of owned data"
),
anchor=(
" recAllValsV2\n"
" (fun vis' v => recOwnedWalkV2 m isMut heapRec self vis' elem v)\n"
" vis vs"
),
replacement=(
" recAllValsV2\n"
" (fun vis' v => recOwnedWalkV2 m isMut heapRec self vis' elem v)\n"
" vis (match vs with | v :: _ => [v] | [] => [])"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_array_owned_each_elem",
),
MirSemanticsGuard(
guard_id="bytes_array_owned_len",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"ownedValidInMem/recOwnedWalkV2 requires an array of owned data to have its length"
),
anchor=(
" if !Nat.beq vs.length n then\n"
" .error .undefined\n"
" else\n"
" recAllValsV2"
),
replacement=(
" if false then\n"
" .error .undefined\n"
" else\n"
" recAllValsV2"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_array_owned_len",
),
MirSemanticsGuard(
guard_id="bytes_refs_valid_array",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refsValidInMem checks an array of owned data as owned data"
),
anchor=(
" match ownedValidInMem m true (.array elem n) v with"
),
replacement=(
" match (Except.ok () : Except FaultKind Unit) with"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_refs_valid_array",
),
MirSemanticsGuard(
guard_id="bytes_array_owned_shape",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"ownedValidInMem/recOwnedWalkV2 rejects a non-array value at an array type"
),
anchor=(
" | _, .option _, _ | _, .array _ _, _ | _, .adtEnum _ _, _ =>\n"
" .error .undefined"
),
replacement=(
" | _, .option _, _ | _, .adtEnum _ _, _ =>\n"
" .error .undefined"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_array_owned_shape",
),
# ------------------------------------------------------------------
# Trusted/MirSemantics/Ops.lean (17 UB, overflow, cast & op guards)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="ops_shift_unchecked_overflow",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="Unchecked shift amount < 0 or >= bitWidth faults UB",
anchor=" if overflow && op.isUnchecked then\n .error .undefined",
replacement=" if false then\n .error .undefined",
fixture_module="OpsRefutations",
theorem_name="refute_ops_shift_unchecked_overflow",
),
MirSemanticsGuard(
guard_id="ops_div_rem_by_zero",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="Integer division and remainder by zero fault UB",
anchor=" if isDivOrRem && r == 0 then\n .error .undefined",
replacement=" if false then\n .error .undefined",
fixture_module="OpsRefutations",
theorem_name="refute_ops_div_rem_by_zero",
),
MirSemanticsGuard(
guard_id="ops_signed_div_rem_min_neg1",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="Signed INT_MIN / -1 and INT_MIN % -1 fault UB",
anchor=(
" else if s && isDivOrRem && (l == signedMinInt w && r == Neg.neg 1) then\n"
" .error .undefined"
),
replacement=" else if false then\n .error .undefined",
fixture_module="OpsRefutations",
theorem_name="refute_ops_signed_div_rem_min_neg1",
),
MirSemanticsGuard(
guard_id="ops_arith_unchecked_overflow",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="Unchecked integer add/sub/mul overflow faults UB",
anchor=(
" if (hostOverflow || lossy) && op.isUnchecked then\n"
" .error .undefined"
),
replacement=" if false then\n .error .undefined",
fixture_module="OpsRefutations",
theorem_name="refute_ops_arith_unchecked_overflow",
),
MirSemanticsGuard(
guard_id="ops_scalar_wf_width_check",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="ScalarVal.wf enforces bits fit within width",
anchor=(
"noncomputable def wf (v : ScalarVal) : Bool :=\n"
" truncateBits v.width v.bits == v.bits"
),
replacement="noncomputable def wf (_v : ScalarVal) : Bool :=\n true",
fixture_module="OpsRefutations",
theorem_name="refute_ops_scalar_wf_width_check",
),
MirSemanticsGuard(
guard_id="ops_arith_host_overflow_signed",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="128-bit signed hostOverflow detects i128 unchecked overflow",
anchor=(
" if s then\n"
" decide (result < Neg.neg (HPow.hPow (2 : Int) 127)) ||\n"
" decide (result ≥ HPow.hPow (2 : Int) 127)"
),
replacement=" if s then\n false",
fixture_module="OpsRefutations",
theorem_name="refute_ops_arith_host_overflow_signed",
),
MirSemanticsGuard(
guard_id="ops_arith_host_overflow_unsigned",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="128-bit unsigned hostOverflow detects u128 unchecked overflow",
anchor=(
" else\n"
" decide (result < 0) || decide (result ≥ HPow.hPow (2 : Int) 128)"
),
replacement=" else\n false",
fixture_module="OpsRefutations",
theorem_name="refute_ops_arith_host_overflow_unsigned",
),
MirSemanticsGuard(
guard_id="ops_arith_with_overflow_flag",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="WithOverflow arithmetic returns accurate overflow boolean",
anchor=(
" else if op.isOverflowing then\n"
" .ok (.tuple [.scalar val, .bool (hostOverflow || lossy)])"
),
replacement=(
" else if op.isOverflowing then\n"
" .ok (.tuple [.scalar val, .bool false])"
),
fixture_module="OpsRefutations",
theorem_name="refute_ops_arith_with_overflow_flag",
),
MirSemanticsGuard(
guard_id="ops_binop_scalar_type_mismatch",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="Non-shift scalar BinOp rejects mismatched width/signedness",
anchor=(
" else if !(IntWidth.beq l.width r.width && (l.signed == r.signed)) then\n"
" .error .unsupported"
),
replacement=" else if false then\n .error .unsupported",
fixture_module="OpsRefutations",
theorem_name="refute_ops_binop_scalar_type_mismatch",
),
MirSemanticsGuard(
guard_id="ops_binop_scalar_unsupported_op",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="Scalar evalBinOp rejects unsupported operators like offset",
anchor=(
" | .addWithOverflow | .subWithOverflow | .mulWithOverflow =>\n"
" evalArithOp op w s lInt rInt\n"
" | _ => .error .unsupported"
),
replacement=(
" | .addWithOverflow | .subWithOverflow | .mulWithOverflow =>\n"
" evalArithOp op w s lInt rInt\n"
" | _ => .ok (.scalar l)"
),
fixture_module="OpsRefutations",
theorem_name="refute_ops_binop_scalar_unsupported_op",
),
MirSemanticsGuard(
guard_id="ops_binop_bool_unsupported_op",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="Bool evalBinOp rejects unsupported operators like add",
anchor=(
" | .bitXor => .ok (.bool (bne l r))\n"
" | _ => .error .unsupported"
),
replacement=(
" | .bitXor => .ok (.bool (bne l r))\n"
" | _ => .ok (.bool l)"
),
fixture_module="OpsRefutations",
theorem_name="refute_ops_binop_bool_unsupported_op",
),
MirSemanticsGuard(
guard_id="ops_binop_char_unsupported_op",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="Char evalBinOp rejects non-comparison operators like add",
anchor=(
" | .cmp => .ok (.ordering (cmpOrderingOfInt lInt rInt))\n"
" | _ => .error .unsupported"
),
replacement=(
" | .cmp => .ok (.ordering (cmpOrderingOfInt lInt rInt))\n"
" | _ => .ok (.bool false)"
),
fixture_module="OpsRefutations",
theorem_name="refute_ops_binop_char_unsupported_op",
),
MirSemanticsGuard(
guard_id="ops_binop_mixed_operand_types",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="evalBinOp catch-all rejects mixed operand types (u32, bool)",
anchor=(
" | _ => .error .unsupported\n"
" | _, _ => .error .unsupported\n\n"
"/-- The `u128` intermediate"
),
replacement=(
" | _ => .error .unsupported\n"
" | _, _ => .ok (.bool false)\n\n"
"/-- The `u128` intermediate"
),
fixture_module="OpsRefutations",
theorem_name="refute_ops_binop_mixed_operand_types",
),
MirSemanticsGuard(
guard_id="ops_cast_int_to_char_above_u8",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="evalIntToIntCast to char rejects values > 255",
anchor=(
" | .char =>\n"
" if Nat.ble bits 255 then\n"
" .ok (.char (Char.ofNat bits))\n"
" else\n"
" .error .unsupported"
),
replacement=(
" | .char =>\n"
" if true then\n"
" .ok (.char (Char.ofNat bits))\n"
" else\n"
" .error .unsupported"
),
fixture_module="OpsRefutations",
theorem_name="refute_ops_cast_int_to_char_above_u8",
),
MirSemanticsGuard(
guard_id="ops_cast_unsupported_target",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="evalIntToIntCast rejects non-int non-char target types",
anchor=(
" else\n"
" .error .unsupported\n"
" | _ => .error .unsupported"
),
replacement=(
" else\n"
" .error .unsupported\n"
" | _ => .ok (.bool false)"
),
fixture_module="OpsRefutations",
theorem_name="refute_ops_cast_unsupported_target",
),
MirSemanticsGuard(
guard_id="ops_unop_neg_unsigned",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="UnOp.neg rejects unsigned integer scalars",
anchor=(
" | .neg, .scalar sv =>\n"
" let integer := decodeScalar sv\n"
" if sv.signed then"
),
replacement=(
" | .neg, .scalar sv =>\n"
" let integer := decodeScalar sv\n"
" if true then"
),
fixture_module="OpsRefutations",
theorem_name="refute_ops_unop_neg_unsigned",
),
MirSemanticsGuard(
guard_id="ops_unop_unsupported_combo",
target_file="trusted/lean/Trusted/MirSemantics/Ops.lean",
target_module="Trusted/MirSemantics/Ops",
description="evalUnOp rejects unsupported op/value combinations",
anchor=(
" else\n"
" .error .unsupported\n"
" | _, _ => .error .unsupported"
),
replacement=(
" else\n"
" .error .unsupported\n"
" | _, _ => .ok (.bool false)"
),
fixture_module="OpsRefutations",
theorem_name="refute_ops_unop_unsupported_combo",
),
# ------------------------------------------------------------------
# Trusted/MirSemantics/Enum.lean (17 enum/validity/identity guards;
# +1 Profile v2 overflow-pair pointee guard below = 18 total)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="enum_char_above_unicode_max",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="char scalar value > 0x10FFFF faults UB",
anchor=(
"noncomputable def isUnicodeScalar (n : Nat) : Bool :=\n"
" Nat.ble n 0x10ffff && !(Nat.ble 0xd800 n && Nat.ble n 0xdfff)"
),
replacement=(
"noncomputable def isUnicodeScalar (n : Nat) : Bool :=\n"
" !(Nat.ble 0xd800 n && Nat.ble n 0xdfff)"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_char_above_unicode_max",
),
MirSemanticsGuard(
guard_id="enum_char_surrogate_gap",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="char surrogate code point in [0xD800, 0xDFFF] faults UB",
anchor=(
"noncomputable def isUnicodeScalar (n : Nat) : Bool :=\n"
" Nat.ble n 0x10ffff && !(Nat.ble 0xd800 n && Nat.ble n 0xdfff)"
),
replacement=(
"noncomputable def isUnicodeScalar (n : Nat) : Bool :=\n"
" Nat.ble n 0x10ffff"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_char_surrogate_gap",
),
MirSemanticsGuard(
guard_id="enum_identity_empty_rejected",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="identityKey? rejects empty body identity",
anchor=(
"noncomputable def identityKey? (identity : String) : Option IdentityKey :=\n"
" match identity.toByteArray.data.toList with\n"
" | [] => none\n"
" | bs => some ⟨byteListTag 1 0 bs, bs⟩"
),
replacement=(
"noncomputable def identityKey? (identity : String) : Option IdentityKey :=\n"
" match identity.toByteArray.data.toList with\n"
" | [] => some ⟨0, []⟩\n"
" | bs => some ⟨byteListTag 1 0 bs, bs⟩"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_identity_empty_rejected",
),
MirSemanticsGuard(
guard_id="enum_identity_duplicate_rejected",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="identityRbInsertAux rejects duplicate body identities",
anchor=" | .eq => none\n | .gt =>",
replacement=" | .eq => some (.node c l x xv r)\n | .gt =>",
fixture_module="EnumRefutations",
theorem_name="refute_enum_identity_duplicate_rejected",
),
MirSemanticsGuard(
guard_id="enum_admitted_nonempty",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="enumAdmitted rejects 0-variant enums",
anchor=(
"noncomputable def enumAdmitted (ety : EnumTy) : Bool :=\n"
" !ety.discriminants.isEmpty &&"
),
replacement=(
"noncomputable def enumAdmitted (ety : EnumTy) : Bool :=\n"
" true &&"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_admitted_nonempty",
),
MirSemanticsGuard(
guard_id="enum_admitted_variant_count_bound",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="enumAdmitted enforces variant count < 2^32",
anchor=" Nat.blt ety.discriminants.length (Nat.pow 2 32) &&",
replacement=" true &&",
fixture_module="EnumRefutations",
theorem_name="refute_enum_admitted_variant_count_bound",
),
MirSemanticsGuard(
guard_id="enum_admitted_discr_fits_width",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="enumAdmitted requires every discriminant fits discrWidth",
anchor=(
" ety.discriminants.all\n"
" (fun d => Nat.blt d (Nat.pow 2 ety.discrWidth.bitWidth)) &&"
),
replacement=" true &&",
fixture_module="EnumRefutations",
theorem_name="refute_enum_admitted_discr_fits_width",
),
MirSemanticsGuard(
guard_id="enum_admitted_discr_distinct",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="enumAdmitted requires pairwise-distinct discriminants",
anchor=" natListPairwiseNe ety.discriminants &&",
replacement=" true &&",
fixture_module="EnumRefutations",
theorem_name="refute_enum_admitted_discr_distinct",
),
MirSemanticsGuard(
guard_id="enum_admitted_zst_single_variant",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="enumAdmitted requires .zeroSized enum to have 1 variant",
anchor=" | .zeroSized => Nat.beq ety.discriminants.length 1",
replacement=" | .zeroSized => true",
fixture_module="EnumRefutations",
theorem_name="refute_enum_admitted_zst_single_variant",
),
MirSemanticsGuard(
guard_id="enum_admitted_scalar_tag_lossless",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="enumAdmitted requires scalar tag roundtrip to be lossless",
anchor=(
" | .scalar tagW tagS =>\n"
" ety.discriminants.all (fun d =>\n"
" let dBits := BitVec.ofNat 128 d\n"
" tagBitsToDiscrBits tagW tagS ety.discrWidth\n"
" (truncateBits tagW dBits) == dBits)"
),
replacement=" | .scalar _ _ => true",
fixture_module="EnumRefutations",
theorem_name="refute_enum_admitted_scalar_tag_lossless",
),
MirSemanticsGuard(
guard_id="enum_ordering_invalid_tag_none",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="orderingOfTagBits returns none for tags outside {-1,0,1}",
anchor=(
" else if Nat.beq bits 1 then\n"
" some .greater\n"
" else\n"
" none"
),
replacement=(
" else if Nat.beq bits 1 then\n"
" some .greater\n"
" else\n"
" some .equal"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_ordering_invalid_tag_none",
),
MirSemanticsGuard(
guard_id="enum_val_ty_enum_variant_in_bounds",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="Val.ty? requires enumVal variant index < discriminants.length",
anchor=" if enumAdmitted ety && Nat.blt v ety.discriminants.length then",
replacement=" if enumAdmitted ety && true then",
fixture_module="EnumRefutations",
theorem_name="refute_enum_val_ty_enum_variant_in_bounds",
),
MirSemanticsGuard(
guard_id="enum_val_ty_overflow_pair_wf",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="Val.ty? enforces sv.wf on overflow-pair tuple scalars",
anchor=(
" | .tuple [.scalar sv, .bool _] =>\n"
" if sv.wf then some (.tuple [.int sv.width sv.signed, .bool]) else none"
),
replacement=(
" | .tuple [.scalar sv, .bool _] =>\n"
" some (.tuple [.int sv.width sv.signed, .bool])"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_val_ty_overflow_pair_wf",
),
MirSemanticsGuard(
guard_id="enum_check_args_length_mismatch",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="checkArgsMatch rejects argument-count mismatches",
anchor=(
" | v :: vs, ty :: tys => checkVal v ty && checkArgsMatch vs tys\n"
" | _, _ => false"
),
replacement=(
" | v :: vs, ty :: tys => checkVal v ty && checkArgsMatch vs tys\n"
" | _, _ => true"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_check_args_length_mismatch",
),
MirSemanticsGuard(
guard_id="enum_supported_ty_reject_non_overflow_tuple",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isSupportedScalarOrUnitTy rejects non-overflow-pair tuples",
anchor=(
" | .enum ety => enumAdmitted ety\n"
" | .tuple fs => isOverflowPairTy (.tuple fs)"
),
replacement=(
" | .enum ety => enumAdmitted ety\n"
" | .tuple _ => true"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_supported_ty_reject_non_overflow_tuple",
),
MirSemanticsGuard(
guard_id="enum_supported_ty_reject_ref_ptr",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isSupportedScalarOrUnitTy rejects ref/rawPtr/unsupported",
anchor=(
" | .enum ety => enumAdmitted ety\n"
" | .tuple fs => isOverflowPairTy (.tuple fs)\n"
" | _ => false"
),
replacement=(
" | .enum ety => enumAdmitted ety\n"
" | .tuple fs => isOverflowPairTy (.tuple fs)\n"
" | _ => true"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_supported_ty_reject_ref_ptr",
),
MirSemanticsGuard(
guard_id="enum_live_uninit_scalar_enum_uninit",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="liveUninitSlot starts scalar-tagged enums uninitialized",
anchor=(
" | .enum ety =>\n"
" if isZstEnumTy ety then .immediate (some (.enumVal ety 0))\n"
" else .immediate none"
),
replacement=(
" | .enum ety =>\n"
" .immediate (some (.enumVal ety 0))"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_live_uninit_scalar_enum_uninit",
),
# ------------------------------------------------------------------
# ------------------------------------------------------------------
# Trusted/MirSemantics/Layout.lean (8 alignment & admission guards)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="layout_unadmitted_enum_none",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="layoutOfTy returns none for unadmitted fieldless enums",
anchor=(
" | .enum ety =>\n"
" if !enumAdmitted ety then\n"
" none"
),
replacement=(
" | .enum ety =>\n"
" if false then\n"
" none"
),
fixture_module="LayoutRefutations",
theorem_name="refute_layout_unadmitted_enum_none",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_unsupported_ty_none",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="layoutOfTy returns none for unsupported types",
anchor=(
" | .tuple [.int w _, .bool] => some (overflowPairLayout w)\n"
" | _ => none"
),
replacement=(
" | .tuple [.int w _, .bool] => some (overflowPairLayout w)\n"
" | _ => some ⟨0, 0⟩"
),
fixture_module="LayoutRefutations",
theorem_name="refute_layout_unsupported_ty_none",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_int_i16_align",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="intLayout 2-byte alignment for i16/u16 (function-level; unobs. in v1)",
anchor=" | .i16 => ⟨2, 1⟩",
replacement=" | .i16 => ⟨2, 0⟩",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_int_i16_align",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_int_i32_align",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="intLayout 4-byte alignment for i32/u32 (function-level; unobs. in v1)",
anchor=" | .i32 => ⟨4, 2⟩",
replacement=" | .i32 => ⟨4, 0⟩",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_int_i32_align",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_int_i64_isize_align",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="intLayout 8-byte alignment for i64/isize (function-level; unobs. in v1)",
anchor=" | .i64 | .isize => ⟨8, 3⟩",
replacement=" | .i64 | .isize => ⟨8, 0⟩",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_int_i64_isize_align",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_int_i128_align",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="intLayout 16-byte alignment for i128/u128 (function-level; unobs. in v1)",
anchor=" | .i128 => ⟨16, 4⟩",
replacement=" | .i128 => ⟨16, 0⟩",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_int_i128_align",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_char_align",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="layoutOfTy 4-byte alignment for char (function-level; unobs. in v1)",
anchor=" | .char => some ⟨4, 2⟩",
replacement=" | .char => some ⟨4, 0⟩",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_char_align",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_overflow_pair_align",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="overflowPairLayout ABI alignment (function-level; unobs. in v1)",
anchor=(
"noncomputable def overflowPairLayout (w : IntWidth) : LayoutData :=\n"
" ⟨2 * (intLayout w).size, (intLayout w).alignLog2⟩"
),
replacement=(
"noncomputable def overflowPairLayout (w : IntWidth) : LayoutData :=\n"
" ⟨2 * (intLayout w).size, 0⟩"
),
fixture_module="LayoutRefutations",
theorem_name="refute_layout_overflow_pair_align",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
# ------------------------------------------------------------------
# Trusted/MirSemantics/Bytes.lean (28 validity, width, codec & UTF-8 guards)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="bytes_invalid_bool_value",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="bool scalar outside {0, 1} faults UB",
anchor=(
" else if v == 1 then\n"
" .ok (.bool true)\n"
" else\n"
" .error .undefined"
),
replacement=(
" else if v == 1 then\n"
" .ok (.bool true)\n"
" else\n"
" .ok (.bool true)"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_invalid_bool_value",
),
MirSemanticsGuard(
guard_id="bytes_invalid_char_surrogate",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="evalConstLit char rejects non-Unicode scalar values as UB",
anchor=(
" else if isUnicodeScalar bits.toNat then\n"
" .ok (.char (Char.ofNat bits.toNat))\n"
" else\n"
" .error .undefined"
),
replacement=(
" else if true then\n"
" .ok (.char (Char.ofNat bits.toNat))\n"
" else\n"
" .error .undefined"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_invalid_char_surrogate",
),
MirSemanticsGuard(
guard_id="bytes_invalid_ordering_tag",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="Ordering tag outside {-1_i8, 0, 1} faults UB",
anchor=(
" match orderingOfTagBits bits.toNat with\n"
" | some ord => .ok (.ordering ord)\n"
" | none => .error .undefined"
),
replacement=(
" match orderingOfTagBits bits.toNat with\n"
" | some ord => .ok (.ordering ord)\n"
" | none => .ok (.ordering .equal)"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_invalid_ordering_tag",
),
MirSemanticsGuard(
guard_id="bytes_invalid_enum_tag",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="Fieldless enum tag not matching any discriminant faults UB",
anchor=(
" match findDiscrVariant? discrBits ety.discriminants with\n"
" | some v => .ok (.enumVal ety v)\n"
" | none => .error .undefined"
),
replacement=(
" match findDiscrVariant? discrBits ety.discriminants with\n"
" | some v => .ok (.enumVal ety v)\n"
" | none => .ok (.enumVal ety 0)"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_invalid_enum_tag",
),
MirSemanticsGuard(
guard_id="bytes_uninit_memory_read",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="initBytes? rejects uninitialized bytes rather than zeroing",
anchor=(
"noncomputable def initBytes? : List AllocByte → Option (List UInt8)\n"
" | [] => some []\n"
" | .uninit :: _ => none"
),
replacement=(
"noncomputable def initBytes? : List AllocByte → Option (List UInt8)\n"
" | [] => some []\n"
" | .uninit :: rest =>\n"
" match initBytes? rest with\n"
" | some bs => some (0 :: bs)\n"
" | none => none"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_uninit_memory_read",
),
MirSemanticsGuard(
guard_id="bytes_const_int_width_overflow",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="evalConstLit int rejects scalar bits exceeding width",
anchor=(
" | .int w s, .scalar bits =>\n"
" if truncateBits w bits != bits then\n"
" .error .unsupported"
),
replacement=(
" | .int w s, .scalar bits =>\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_const_int_width_overflow",
),
MirSemanticsGuard(
guard_id="bytes_const_bool_width_overflow",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="evalConstLit bool rejects scalar bits exceeding 1 byte",
anchor=(
" | .bool, .scalar bits =>\n"
" if truncateBits .i8 bits != bits then\n"
" .error .unsupported"
),
replacement=(
" | .bool, .scalar bits =>\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_const_bool_width_overflow",
),
MirSemanticsGuard(
guard_id="bytes_const_char_width_overflow",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="evalConstLit char >32-bit lockstep-classifies as .unsupported",
anchor=(
" | .char, .scalar bits =>\n"
" if truncateBits .i32 bits != bits then\n"
" .error .unsupported"
),
replacement=(
" | .char, .scalar bits =>\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_const_char_width_overflow",
),
MirSemanticsGuard(
guard_id="bytes_const_ordering_width_overflow",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="evalConstLit ordering >8-bit lockstep-classifies as .unsupported",
anchor=(
" | .ordering, .scalar bits =>\n"
" if truncateBits .i8 bits != bits then\n"
" .error .unsupported"
),
replacement=(
" | .ordering, .scalar bits =>\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_const_ordering_width_overflow",
),
MirSemanticsGuard(
guard_id="bytes_const_zst_enum_requires_zst",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="evalConstLit enum zeroSized requires isZstEnumTy",
anchor=(
" | .enum ety, .zeroSized =>\n"
" if isZstEnumTy ety then .ok (.enumVal ety 0) else .error .unsupported"
),
replacement=(
" | .enum ety, .zeroSized =>\n"
" .ok (.enumVal ety 0)"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_const_zst_enum_requires_zst",
),
MirSemanticsGuard(
guard_id="bytes_const_scalar_lit_on_zst_enum",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="evalConstLit rejects ConstLit.scalar on .zeroSized enum",
anchor=(
" match ety.tagRepr with\n"
" | .zeroSized => .error .unsupported"
),
replacement=(
" match ety.tagRepr with\n"
" | .zeroSized => .ok (.enumVal ety 0)"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_const_scalar_lit_on_zst_enum",
),
MirSemanticsGuard(
guard_id="bytes_const_scalar_enum_width_overflow",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="evalConstLit scalar enum rejects tag bits exceeding tagW",
anchor=" if !enumAdmitted ety || truncateBits tagW bits != bits then",
replacement=" if !enumAdmitted ety || false then",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_const_scalar_enum_width_overflow",
),
MirSemanticsGuard(
guard_id="bytes_const_mismatched_lit_kind",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="evalConstLit rejects mismatched type/literal combinations",
anchor=(
" | none => .error .undefined\n"
" | _, _ => .error .unsupported"
),
replacement=(
" | none => .error .undefined\n"
" | _, _ => .ok .unit"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_const_mismatched_lit_kind",
),
MirSemanticsGuard(
guard_id="bytes_encode_val_checks_type",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="encodeVal rejects invalid values (function-level defense-in-depth)",
anchor=(
"noncomputable def encodeVal (endian : TargetEndian) (ty : MirTy) (v : Val) :\n"
" Except FaultKind (List AllocByte) :=\n"
" if !checkVal v ty then\n"
" .error .unsupported"
),
replacement=(
"noncomputable def encodeVal (endian : TargetEndian) (ty : MirTy) (v : Val) :\n"
" Except FaultKind (List AllocByte) :=\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_encode_val_checks_type",
),
MirSemanticsGuard(
guard_id="bytes_encode_overflow_pair_padding_uninit",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="encodeVal writes uninit padding bytes for overflow pairs",
anchor=" List.replicate (w.byteSize - 1) AllocByte.uninit)",
replacement=" List.replicate (w.byteSize - 1) (AllocByte.init 0 none))",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_encode_overflow_pair_padding_uninit",
),
MirSemanticsGuard(
guard_id="bytes_decode_never_returns_uninit",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="decodeVal returns .ok none for uninhabited .never",
anchor=" | .never => .ok none",
replacement=" | .never => .ok (some .unit)",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_decode_never_returns_uninit",
),
MirSemanticsGuard(
guard_id="bytes_decode_length_mismatch",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="decodeVal checks byte length (function-level defense-in-depth)",
anchor=(
" if !Nat.beq bytes.length layout.size then\n"
" .error .unsupported"
),
replacement=(
" if false then\n"
" .error .unsupported"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_decode_length_mismatch",
),
MirSemanticsGuard(
guard_id="bytes_decode_overflow_pair_length_mismatch",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="decodeVal checks overflow-pair size (function-level defense-in-depth)",
anchor=(
" if !Nat.beq bytes.length (overflowPairLayout w).size then\n"
" .error .unsupported"
),
replacement=(
" if false then\n"
" .error .unsupported"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_decode_overflow_pair_length_mismatch",
),
MirSemanticsGuard(
guard_id="bytes_decode_overflow_pair_uninit_bool",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="decodeVal returns .ok none when overflow-pair bytes are uninit",
anchor=(
" | .ok boolVal => .ok (some (.tuple [intVal, boolVal]))\n"
" | _, _ => .ok none"
),
replacement=(
" | .ok boolVal => .ok (some (.tuple [intVal, boolVal]))\n"
" | _, _ => .ok (some (.tuple [.scalar ⟨w, s, BitVec.ofNat 128 0⟩, .bool false]))"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_decode_overflow_pair_uninit_bool",
),
MirSemanticsGuard(
guard_id="bytes_utf8_two_byte_lead_min",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"validUtf8Go rejects the overlong two-byte leads 0xC0 and 0xC1"
),
anchor=(
" else if Nat.ble 0xC2 n && Nat.ble n 0xDF then validUtf8Go 1 0x80 0xBF rest"
),
replacement=(
" else if Nat.ble 0xC0 n && Nat.ble n 0xDF then validUtf8Go 1 0x80 0xBF rest"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_utf8_two_byte_lead_min",
),
MirSemanticsGuard(
guard_id="bytes_utf8_e0_overlong",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"validUtf8Go narrows the second byte after 0xE0 to 0xA0..=0xBF"
),
anchor=(
" else if Nat.beq n 0xE0 then validUtf8Go 2 0xA0 0xBF rest"
),
replacement=(
" else if Nat.beq n 0xE0 then validUtf8Go 2 0x80 0xBF rest"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_utf8_e0_overlong",
),
MirSemanticsGuard(
guard_id="bytes_utf8_ed_surrogate",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"validUtf8Go narrows the second byte after 0xED to 0x80..=0x9F"
),
anchor=(
" else if Nat.beq n 0xED then validUtf8Go 2 0x80 0x9F rest"
),
replacement=(
" else if Nat.beq n 0xED then validUtf8Go 2 0x80 0xBF rest"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_utf8_ed_surrogate",
),
MirSemanticsGuard(
guard_id="bytes_utf8_f0_overlong",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"validUtf8Go narrows the second byte after 0xF0 to 0x90..=0xBF"
),
anchor=(
" else if Nat.beq n 0xF0 then validUtf8Go 3 0x90 0xBF rest"
),
replacement=(
" else if Nat.beq n 0xF0 then validUtf8Go 3 0x80 0xBF rest"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_utf8_f0_overlong",
),
MirSemanticsGuard(
guard_id="bytes_utf8_f4_max",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"validUtf8Go narrows the second byte after 0xF4 to 0x80..=0x8F"
),
anchor=(
" else if Nat.beq n 0xF4 then validUtf8Go 3 0x80 0x8F rest"
),
replacement=(
" else if Nat.beq n 0xF4 then validUtf8Go 3 0x80 0xBF rest"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_utf8_f4_max",
),
MirSemanticsGuard(
guard_id="bytes_utf8_invalid_lead",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"validUtf8Go rejects lone continuation bytes and leads 0xF5..=0xFF"
),
anchor=(
" else if Nat.beq n 0xF4 then validUtf8Go 3 0x80 0x8F rest\n"
" else false"
),
replacement=(
" else if Nat.beq n 0xF4 then validUtf8Go 3 0x80 0x8F rest\n"
" else true"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_utf8_invalid_lead",
),
MirSemanticsGuard(
guard_id="bytes_utf8_truncated",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"validUtf8Go rejects input that ends inside a multi-byte sequence"
),
anchor=(
" | _ + 1, _, _, [] => false"
),
replacement=(
" | _ + 1, _, _, [] => true"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_utf8_truncated",
),
MirSemanticsGuard(
guard_id="bytes_utf8_continuation_hi",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"validUtf8Go bounds continuation bytes above by 0xBF"
),
anchor=(
" Nat.ble lo b.toNat && Nat.ble b.toNat hi && validUtf8Go k 0x80 0xBF rest"
),
replacement=(
" Nat.ble lo b.toNat && validUtf8Go k 0x80 0xBF rest"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_utf8_continuation_hi",
),
MirSemanticsGuard(
guard_id="bytes_utf8_continuation_lo",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"validUtf8Go bounds continuation bytes below by 0x80"
),
anchor=(
" Nat.ble lo b.toNat && Nat.ble b.toNat hi && validUtf8Go k 0x80 0xBF rest"
),
replacement=(
" Nat.ble b.toNat hi && validUtf8Go k 0x80 0xBF rest"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_utf8_continuation_lo",
),
# ------------------------------------------------------------------
# Trusted/MirSemantics/Memory.lean (29 allocation/bounds/align/mut/
# provenance guards; 6 additional Profile v2 memory guards follow = 35)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="mem_dealloc_nonzero_offset",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="deallocateStack rejects non-zero pointer offset as UB",
anchor=(
"noncomputable def deallocateStack (m : MemoryState) (place : MemPlace) :\n"
" Except FaultKind MemoryState :=\n"
" if !Nat.beq place.offset 0 then\n"
" .error .undefined"
),
replacement=(
"noncomputable def deallocateStack (m : MemoryState) (place : MemPlace) :\n"
" Except FaultKind MemoryState :=\n"
" if false then\n"
" .error .undefined"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_dealloc_nonzero_offset",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_dealloc_missing_alloc",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="deallocateStack rejects missing allocation id as UB",
anchor=(
" match findAllocation place.allocId m.allocations with\n"
" | none => .error .undefined\n"
" | some a =>\n"
" if !a.live then\n"
" .error .undefined"
),
replacement=(
" match findAllocation place.allocId m.allocations with\n"
" | none => .ok m\n"
" | some a =>\n"
" if !a.live then\n"
" .error .undefined"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_dealloc_missing_alloc",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_dealloc_use_after_free",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="deallocateStack rejects double-free on dead allocation as UB",
anchor=(
" if !a.live then\n"
" .error .undefined\n"
" else\n"
" match a.mutability with\n"
" | .shared => .error .undefined"
),
replacement=(
" if false then\n"
" .error .undefined\n"
" else\n"
" match a.mutability with\n"
" | .shared => .error .undefined"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_dealloc_use_after_free",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_dealloc_immutable",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="deallocateStack rejects immutable (.shared) allocation as UB",
anchor=(
" match a.mutability with\n"
" | .shared => .error .undefined\n"
" | .mut =>\n"
" .ok { m with\n"
" allocations :=\n"
" replaceAllocation { a with live := false } m.allocations }"
),
replacement=(
" match a.mutability with\n"
" | .shared => .ok m\n"
" | .mut =>\n"
" .ok { m with\n"
" allocations :=\n"
" replaceAllocation { a with live := false } m.allocations }"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_dealloc_immutable",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_read_missing_alloc",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="readBytes rejects missing allocation id as UB",
anchor=(
" match findAllocation place.allocId m.allocations with\n"
" | none => .error .undefined\n"
" | some a =>\n"
" if Nat.beq size 0 then"
),
replacement=(
" match findAllocation place.allocId m.allocations with\n"
" | none => .ok []\n"
" | some a =>\n"
" if Nat.beq size 0 then"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_read_missing_alloc",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_read_use_after_free",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="readBytes rejects reading from deallocated allocation as UB",
anchor=(
" else if !a.live || !isInBounds a place.offset size ||\n"
" !isAligned a place.offset alignLog2 then\n"
" .error .undefined\n"
" else\n"
" .ok ((a.bytes.drop place.offset).take size)"
),
replacement=(
" else if false || !isInBounds a place.offset size ||\n"
" !isAligned a place.offset alignLog2 then\n"
" .error .undefined\n"
" else\n"
" .ok ((a.bytes.drop place.offset).take size)"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_read_use_after_free",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_read_out_of_bounds",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="readBytes rejects out-of-bounds read as UB",
anchor=(
" else if !a.live || !isInBounds a place.offset size ||\n"
" !isAligned a place.offset alignLog2 then\n"
" .error .undefined\n"
" else\n"
" .ok ((a.bytes.drop place.offset).take size)"
),
replacement=(
" else if !a.live || false ||\n"
" !isAligned a place.offset alignLog2 then\n"
" .error .undefined\n"
" else\n"
" .ok ((a.bytes.drop place.offset).take size)"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_read_out_of_bounds",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_read_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="readBytes rejects misaligned access as UB",
anchor=(
" else if !a.live || !isInBounds a place.offset size ||\n"
" !isAligned a place.offset alignLog2 then\n"
" .error .undefined\n"
" else\n"
" .ok ((a.bytes.drop place.offset).take size)"
),
replacement=(
" else if !a.live || !isInBounds a place.offset size ||\n"
" false then\n"
" .error .undefined\n"
" else\n"
" .ok ((a.bytes.drop place.offset).take size)"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_read_misaligned",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_read_zst_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="readBytes rejects misaligned zero-size read as UB",
anchor=(
" if Nat.beq size 0 then\n"
" if !isAligned a place.offset alignLog2 then\n"
" .error .undefined\n"
" else\n"
" .ok []"
),
replacement=(
" if Nat.beq size 0 then\n"
" if false then\n"
" .error .undefined\n"
" else\n"
" .ok []"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_read_zst_misaligned",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_write_missing_alloc",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="writeBytes rejects missing allocation id as UB",
anchor=(
" match findAllocation place.allocId m.allocations with\n"
" | none => .error .undefined\n"
" | some a =>\n"
" if Nat.beq bytes.length 0 then"
),
replacement=(
" match findAllocation place.allocId m.allocations with\n"
" | none => .ok m\n"
" | some a =>\n"
" if Nat.beq bytes.length 0 then"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_write_missing_alloc",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_write_use_after_free",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="writeBytes rejects writing to deallocated allocation as UB",
anchor=(
" else if !a.live || !isInBounds a place.offset bytes.length ||\n"
" !isAligned a place.offset alignLog2 then"
),
replacement=(
" else if false || !isInBounds a place.offset bytes.length ||\n"
" !isAligned a place.offset alignLog2 then"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_write_use_after_free",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_write_out_of_bounds",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="writeBytes rejects out-of-bounds write as UB",
anchor=(
" else if !a.live || !isInBounds a place.offset bytes.length ||\n"
" !isAligned a place.offset alignLog2 then"
),
replacement=(
" else if !a.live || false ||\n"
" !isAligned a place.offset alignLog2 then"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_write_out_of_bounds",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_write_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="writeBytes rejects misaligned write as UB",
anchor=(
" else if !a.live || !isInBounds a place.offset bytes.length ||\n"
" !isAligned a place.offset alignLog2 then"
),
replacement=(
" else if !a.live || !isInBounds a place.offset bytes.length ||\n"
" false then"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_write_misaligned",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_write_readonly",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="writeBytes rejects writing to .shared allocation as UB",
anchor=(
" match a.mutability with\n"
" | .shared => .error .undefined\n"
" | .mut =>\n"
" let bytes' :="
),
replacement=(
" match a.mutability with\n"
" | .shared => .ok m\n"
" | .mut =>\n"
" let bytes' :="
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_write_readonly",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_write_zst_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="writeBytes rejects misaligned empty write as UB",
anchor=(
" if Nat.beq bytes.length 0 then\n"
" if !isAligned a place.offset alignLog2 then\n"
" .error .undefined\n"
" else\n"
" .ok m"
),
replacement=(
" if Nat.beq bytes.length 0 then\n"
" if false then\n"
" .error .undefined\n"
" else\n"
" .ok m"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_write_zst_misaligned",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_read_zst_alloc_align",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"readBytes rejects zero-size read above the "
"allocation alignment as UB"
),
anchor=(
" if Nat.beq size 0 then\n"
" if !isAligned a place.offset alignLog2 then\n"
" .error .undefined\n"
" else\n"
" .ok []"
),
replacement=(
" if Nat.beq size 0 then\n"
" if false then\n"
" .error .undefined\n"
" else\n"
" .ok []"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_read_zst_alloc_align",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_read_zst_dead_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"readBytes rejects misaligned zero-size read "
"of a dead allocation as UB"
),
anchor=(
" if Nat.beq size 0 then\n"
" if !isAligned a place.offset alignLog2 then\n"
" .error .undefined\n"
" else\n"
" .ok []"
),
replacement=(
" if Nat.beq size 0 then\n"
" if false then\n"
" .error .undefined\n"
" else\n"
" .ok []"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_read_zst_dead_misaligned",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_uninit_zst_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="writeUninit rejects misaligned zero-size write as UB",
anchor=(
" if Nat.beq bytes.length 0 then\n"
" if !isAligned a place.offset alignLog2 then\n"
" .error .undefined\n"
" else\n"
" .ok m"
),
replacement=(
" if Nat.beq bytes.length 0 then\n"
" if false then\n"
" .error .undefined\n"
" else\n"
" .ok m"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_uninit_zst_misaligned",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_zst_missing_alloc",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"readBytes rejects zero-size read of a "
"missing allocation id as UB"
),
anchor=(
" match findAllocation place.allocId m.allocations with\n"
" | none => .error .undefined\n"
" | some a =>\n"
" if Nat.beq size 0 then"
),
replacement=(
" match findAllocation place.allocId m.allocations with\n"
" | none => .ok []\n"
" | some a =>\n"
" if Nat.beq size 0 then"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_zst_missing_alloc",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_align_alloc_align_check",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="isAligned requires allocation alignment >= access alignment",
anchor=(
"noncomputable def isAligned (a : Allocation) (offset alignLog2 : Nat) : Bool :=\n"
" Nat.ble alignLog2 a.alignLog2 &&\n"
" Nat.beq (Nat.mod offset (Nat.pow 2 alignLog2)) 0"
),
replacement=(
"noncomputable def isAligned (a : Allocation) (offset alignLog2 : Nat) : Bool :=\n"
" true &&\n"
" Nat.beq (Nat.mod offset (Nat.pow 2 alignLog2)) 0"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_align_alloc_align_check",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_align_offset_mod_check",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="isAligned requires offset % 2^alignLog2 == 0",
anchor=(
"noncomputable def isAligned (a : Allocation) (offset alignLog2 : Nat) : Bool :=\n"
" Nat.ble alignLog2 a.alignLog2 &&\n"
" Nat.beq (Nat.mod offset (Nat.pow 2 alignLog2)) 0"
),
replacement=(
"noncomputable def isAligned (a : Allocation) (offset alignLog2 : Nat) : Bool :=\n"
" Nat.ble alignLog2 a.alignLog2 &&\n"
" true"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_align_offset_mod_check",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_reserve_alloc_id_monotonic",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="reserveAllocId increments nextAllocId so ids never alias",
anchor=" ({ m with nextAllocId := m.nextAllocId + 1 }, m.nextAllocId)",
replacement=" ({ m with nextAllocId := m.nextAllocId }, m.nextAllocId)",
fixture_module="MemoryRefutations",
theorem_name="refute_mem_reserve_alloc_id_monotonic",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_alloc_initializes_uninit",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="allocateStack fills fresh allocations with .uninit bytes",
anchor=" bytes := List.replicate layout.size .uninit",
replacement=" bytes := List.replicate layout.size (.init 0 none)",
fixture_module="MemoryRefutations",
theorem_name="refute_mem_alloc_initializes_uninit",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_dealloc_marks_dead",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="deallocateStack sets live := false on the freed allocation",
anchor=" replaceAllocation { a with live := false } m.allocations }",
replacement=" replaceAllocation a m.allocations }",
fixture_module="MemoryRefutations",
theorem_name="refute_mem_dealloc_marks_dead",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_in_bounds_includes_size",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="isInBounds checks offset + size <= bytes.length",
anchor=(
"noncomputable def isInBounds (a : Allocation) (offset size : Nat) : Bool :=\n"
" Nat.ble (offset + size) a.bytes.length"
),
replacement=(
"noncomputable def isInBounds (a : Allocation) (offset _size : Nat) : Bool :=\n"
" Nat.ble offset a.bytes.length"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_in_bounds_includes_size",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_write_uninit_marks_uninit",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="writeUninit writes .uninit bytes rather than zero bytes",
anchor=" writeBytes m place alignLog2 (List.replicate size .uninit)",
replacement=" writeBytes m place alignLog2 (List.replicate size (.init 0 none))",
fixture_module="MemoryRefutations",
theorem_name="refute_mem_write_uninit_marks_uninit",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
# ------------------------------------------------------------------
# Trusted/MirSemantics/State.lean (13 entry & storage-liveness guards,
# 9 singleBodyStaticAdmitted guards, & 5 sysroot/call/init guards = 27)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="state_init_pointer_width_64",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initState rejects non-64-bit pointerWidthBits",
anchor=" if !Nat.beq p.pointerWidthBits 64 || !Nat.beq p.mirProfileVersion 1 then",
replacement=" if false || !Nat.beq p.mirProfileVersion 1 then",
fixture_module="StateRefutations",
theorem_name="refute_state_init_pointer_width_64",
),
MirSemanticsGuard(
guard_id="state_init_mir_profile_v1",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initState rejects non-v1 mirProfileVersion",
anchor=" if !Nat.beq p.pointerWidthBits 64 || !Nat.beq p.mirProfileVersion 1 then",
replacement=" if !Nat.beq p.pointerWidthBits 64 || false then",
fixture_module="StateRefutations",
theorem_name="refute_state_init_mir_profile_v1",
),
MirSemanticsGuard(
guard_id="state_init_empty_caller_mem",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initState rejects non-empty callerMem",
anchor=" else if !q.callerMem.allocations.isEmpty then\n .error .unsupported",
replacement=" else if false then\n .error .unsupported",
fixture_module="StateRefutations",
theorem_name="refute_state_init_empty_caller_mem",
),
MirSemanticsGuard(
guard_id="state_init_nonempty_blocks",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initState rejects empty basicBlocks list",
anchor=(
" | some body =>\n"
" if body.isExternal || body.basicBlocks.isEmpty then\n"
" .error .unsupported\n"
" else if !Nat.blt body.argumentCount body.locals.length then\n"
" .error .unsupported\n"
" else if !storageAnnotationsInBounds body then\n"
" .error .unsupported\n"
" else if !discriminantTypesValid body then\n"
" .error .unsupported\n"
" else if !castTypesValid body then\n"
" .error .unsupported\n"
" else if !assertConditionTypesValid body then\n"
" .error .unsupported\n"
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
replacement=(
" | some body =>\n"
" if body.isExternal || false then\n"
" .error .unsupported\n"
" else if !Nat.blt body.argumentCount body.locals.length then\n"
" .error .unsupported\n"
" else if !storageAnnotationsInBounds body then\n"
" .error .unsupported\n"
" else if !discriminantTypesValid body then\n"
" .error .unsupported\n"
" else if !castTypesValid body then\n"
" .error .unsupported\n"
" else if !assertConditionTypesValid body then\n"
" .error .unsupported\n"
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
fixture_module="StateRefutations",
theorem_name="refute_state_init_nonempty_blocks",
),
MirSemanticsGuard(
guard_id="state_init_arg_count_lt_locals",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initState requires argumentCount < locals.length",
anchor=(
" | some body =>\n"
" if body.isExternal || body.basicBlocks.isEmpty then\n"
" .error .unsupported\n"
" else if !Nat.blt body.argumentCount body.locals.length then\n"
" .error .unsupported\n"
" else if !storageAnnotationsInBounds body then\n"
" .error .unsupported\n"
" else if !discriminantTypesValid body then\n"
" .error .unsupported\n"
" else if !castTypesValid body then\n"
" .error .unsupported\n"
" else if !assertConditionTypesValid body then\n"
" .error .unsupported\n"
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
replacement=(
" | some body =>\n"
" if body.isExternal || body.basicBlocks.isEmpty then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .unsupported\n"
" else if !storageAnnotationsInBounds body then\n"
" .error .unsupported\n"
" else if !discriminantTypesValid body then\n"
" .error .unsupported\n"
" else if !castTypesValid body then\n"
" .error .unsupported\n"
" else if !assertConditionTypesValid body then\n"
" .error .unsupported\n"
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
fixture_module="StateRefutations",
theorem_name="refute_state_init_arg_count_lt_locals",
),
MirSemanticsGuard(
guard_id="state_init_storage_annotations_in_bounds",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initState enforces storageAnnotationsInBounds",
anchor=(
" | some body =>\n"
" if body.isExternal || body.basicBlocks.isEmpty then\n"
" .error .unsupported\n"
" else if !Nat.blt body.argumentCount body.locals.length then\n"
" .error .unsupported\n"
" else if !storageAnnotationsInBounds body then\n"
" .error .unsupported\n"
" else if !discriminantTypesValid body then\n"
" .error .unsupported\n"
" else if !castTypesValid body then\n"
" .error .unsupported\n"
" else if !assertConditionTypesValid body then\n"
" .error .unsupported\n"
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
replacement=(
" | some body =>\n"
" if body.isExternal || body.basicBlocks.isEmpty then\n"
" .error .unsupported\n"
" else if !Nat.blt body.argumentCount body.locals.length then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .unsupported\n"
" else if !discriminantTypesValid body then\n"
" .error .unsupported\n"
" else if !castTypesValid body then\n"
" .error .unsupported\n"
" else if !assertConditionTypesValid body then\n"
" .error .unsupported\n"
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
fixture_module="StateRefutations",
theorem_name="refute_state_init_storage_annotations_in_bounds",
),
MirSemanticsGuard(
guard_id="state_storage_oob_marker_check",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="storageAnnotationsInBounds checks StorageLive/Dead < numLocals",
anchor=" | .storageLive id | .storageDead id => Nat.blt id numLocals",
replacement=" | .storageLive _ | .storageDead _ => true",
fixture_module="StateRefutations",
theorem_name="refute_state_storage_oob_marker_check",
),
MirSemanticsGuard(
guard_id="state_init_discriminant_types_valid",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initState enforces discriminantTypesValid",
anchor=(
" | some body =>\n"
" if body.isExternal || body.basicBlocks.isEmpty then\n"
" .error .unsupported\n"
" else if !Nat.blt body.argumentCount body.locals.length then\n"
" .error .unsupported\n"
" else if !storageAnnotationsInBounds body then\n"
" .error .unsupported\n"
" else if !discriminantTypesValid body then\n"
" .error .unsupported\n"
" else if !castTypesValid body then\n"
" .error .unsupported\n"
" else if !assertConditionTypesValid body then\n"
" .error .unsupported\n"
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
replacement=(
" | some body =>\n"
" if body.isExternal || body.basicBlocks.isEmpty then\n"
" .error .unsupported\n"
" else if !Nat.blt body.argumentCount body.locals.length then\n"
" .error .unsupported\n"
" else if !storageAnnotationsInBounds body then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .unsupported\n"
" else if !castTypesValid body then\n"
" .error .unsupported\n"
" else if !assertConditionTypesValid body then\n"
" .error .unsupported\n"
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
fixture_module="StateRefutations",
theorem_name="refute_state_init_discriminant_types_valid",
),
MirSemanticsGuard(
guard_id="state_discr_ordering_type_check",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="discriminantTypesValid enforces i8 destination for Ordering",
anchor=(
" | .ordering =>\n"
" match getElem? body.locals dst.localId with\n"
" | some dstTy => MirTy.beq dstTy (.int .i8 true)"
),
replacement=(
" | .ordering =>\n"
" match getElem? body.locals dst.localId with\n"
" | some _ => true"
),
fixture_module="StateRefutations",
theorem_name="refute_state_discr_ordering_type_check",
),
MirSemanticsGuard(
guard_id="state_init_cast_types_valid",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initState enforces castTypesValid",
anchor=(
" | some body =>\n"
" if body.isExternal || body.basicBlocks.isEmpty then\n"
" .error .unsupported\n"
" else if !Nat.blt body.argumentCount body.locals.length then\n"
" .error .unsupported\n"
" else if !storageAnnotationsInBounds body then\n"
" .error .unsupported\n"
" else if !discriminantTypesValid body then\n"
" .error .unsupported\n"
" else if !castTypesValid body then\n"
" .error .unsupported\n"
" else if !assertConditionTypesValid body then\n"
" .error .unsupported\n"
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
replacement=(
" | some body =>\n"
" if body.isExternal || body.basicBlocks.isEmpty then\n"
" .error .unsupported\n"
" else if !Nat.blt body.argumentCount body.locals.length then\n"
" .error .unsupported\n"
" else if !storageAnnotationsInBounds body then\n"
" .error .unsupported\n"
" else if !discriminantTypesValid body then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .unsupported\n"
" else if !assertConditionTypesValid body then\n"
" .error .unsupported\n"
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
fixture_module="StateRefutations",
theorem_name="refute_state_init_cast_types_valid",
),
MirSemanticsGuard(
guard_id="state_init_supported_local_types",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initState requires all local types to be supported",
anchor=(
" else if !body.locals.all isSupportedScalarOrUnitTy then\n"
" .error .unsupported"
),
replacement=" else if false then\n .error .unsupported",
fixture_module="StateRefutations",
theorem_name="refute_state_init_supported_local_types",
),
MirSemanticsGuard(
guard_id="state_init_args_match_param_tys",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initState enforces checkArgsMatch on query arguments",
anchor=(
" if !checkArgsMatch q.args paramTys then\n"
" .error .unsupported"
),
replacement=" if false then\n .error .unsupported",
fixture_module="StateRefutations",
theorem_name="refute_state_init_args_match_param_tys",
),
MirSemanticsGuard(
guard_id="state_init_annotated_local_starts_dead",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initLocalsLoop initializes storage-annotated locals as .dead",
anchor=" else if hasStorageAnnotation body idx then\n .dead",
replacement=" else if false then\n .dead",
fixture_module="StateRefutations",
theorem_name="refute_state_init_annotated_local_starts_dead",
),
# ------------------------------------------------------------------
# Trusted/MirSemantics/Step.lean (44 v1 UB, move-deinit, frame & admission
# guards, 3 non-root call/return guards, & 17 Profile v2 guards = 64)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="step_copy_dead_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Operand.copy of a .dead local faults UB",
anchor=(
" | .copy place =>\n"
" match getElem? bodyLocals place.localId,\n"
" getElem? locals place.localId with\n"
" | some _, some .dead => .error .undefined"
),
replacement=(
" | .copy place =>\n"
" match getElem? bodyLocals place.localId,\n"
" getElem? locals place.localId with\n"
" | some ty, some .dead => .ok (ty, some .unit, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_copy_dead_local",
),
MirSemanticsGuard(
guard_id="step_move_dead_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Operand.move of a .dead local faults UB",
anchor=(
" | .move place =>\n"
" match getElem? bodyLocals place.localId,\n"
" getElem? locals place.localId with\n"
" | some _, some .dead => .error .undefined"
),
replacement=(
" | .move place =>\n"
" match getElem? bodyLocals place.localId,\n"
" getElem? locals place.localId with\n"
" | some ty, some .dead => .ok (ty, some .unit, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_move_dead_local",
),
MirSemanticsGuard(
guard_id="step_move_deinit_immediate",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Operand.move deinitializes immediate non-ZST locals",
anchor=(
" match setElem? locals place.localId (liveUninitSlot ty) with\n"
" | some locals' => .ok (ty, optVal, locals', mem)"
),
replacement=(
" match some locals with\n"
" | some locals' => .ok (ty, optVal, locals', mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_move_deinit_immediate",
),
MirSemanticsGuard(
guard_id="step_move_deinit_indirect",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Operand.move deinitializes indirect non-ZST locals in memory",
anchor=(
" match deinitIndirect mem ty mplace with\n"
" | .ok mem' => .ok (ty, optVal, locals, mem')"
),
replacement=(
" match (Except.ok mem : Except FaultKind MemoryState) with\n"
" | .ok mem' => .ok (ty, optVal, locals, mem')"
),
fixture_module="StepRefutations",
theorem_name="refute_step_move_deinit_indirect",
),
MirSemanticsGuard(
guard_id="step_prim_uninit_read",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalPrimitiveOperand rejects uninitialized local as UB",
anchor=(
" match optVal with\n"
" | some v => .ok (v, locals', mem')\n"
" | none => .error .undefined"
),
replacement=(
" match optVal with\n"
" | some v => .ok (v, locals', mem')\n"
" | none => .ok (.bool false, locals', mem')"
),
fixture_module="StepRefutations",
theorem_name="refute_step_prim_uninit_read",
),
MirSemanticsGuard(
guard_id="step_discriminant_uninit_enum",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalDiscriminantOfVal rejects uninitialized scalar enum as UB",
anchor=" | .scalar _ _, none => .error .undefined",
replacement=(
" | .scalar _ _, none =>\n"
" .ok (.scalar ⟨ety.discrWidth, ety.discrSigned, BitVec.ofNat 128 0⟩, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_discriminant_uninit_enum",
),
MirSemanticsGuard(
guard_id="step_discriminant_uninit_ordering",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalOrderingDiscriminantOfVal rejects uninitialized Ordering as UB",
anchor=(
" match optVal with\n"
" | none => .error .undefined\n"
" | some (.ordering ord) =>"
),
replacement=(
" match optVal with\n"
" | none => .ok (.scalar ⟨.i8, true, BitVec.ofNat 128 0⟩, locals, mem)\n"
" | some (.ordering ord) =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_discriminant_uninit_ordering",
),
MirSemanticsGuard(
guard_id="step_use_uninit_read",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalue .use rejects uninitialized source local as UB",
anchor=(
" match optVal with\n"
" | some v => .ok (v, locals₁, mem₁)\n"
" | none => .error .undefined"
),
replacement=(
" match optVal with\n"
" | some v => .ok (v, locals₁, mem₁)\n"
" | none => .ok (.bool false, locals₁, mem₁)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_use_uninit_read",
),
MirSemanticsGuard(
guard_id="step_cast_uninit_read",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalue (.cast .intToInt) rejects uninitialized source as UB",
anchor=(
" match optVal with\n"
" | none => .error .undefined\n"
" | some v =>\n"
" match evalIntToIntCast v castTy with"
),
replacement=(
" match optVal with\n"
" | none =>\n"
" match evalIntToIntCast (.bool false) castTy with\n"
" | .error k => .error k\n"
" | .ok res => .ok (res, locals₁, mem₁)\n"
" | some v =>\n"
" match evalIntToIntCast v castTy with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_cast_uninit_read",
),
MirSemanticsGuard(
guard_id="step_discriminant_dead_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalue .discriminant rejects .dead local as UB",
anchor=(
" | .discriminant place =>\n"
" match getElem? bodyLocals place.localId,\n"
" getElem? locals place.localId with\n"
" | some _, some .dead => .error .undefined"
),
replacement=(
" | .discriminant place =>\n"
" match getElem? bodyLocals place.localId,\n"
" getElem? locals place.localId with\n"
" | some _, some .dead =>\n"
" .ok (.scalar ⟨.i8, true, BitVec.ofNat 128 0⟩, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_discriminant_dead_local",
),
MirSemanticsGuard(
guard_id="step_write_dead_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="writePlace rejects writing to a .dead destination local as UB",
anchor=(
" match getElem? locals dstLocalId with\n"
" | none => .error .unsupported\n"
" | some .dead => .error .undefined"
),
replacement=(
" match getElem? locals dstLocalId with\n"
" | none => .error .unsupported\n"
" | some .dead =>\n"
" match setElem? locals dstLocalId (.immediate (some val)) with\n"
" | some locals' => .ok (locals', mem)\n"
" | none => .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_write_dead_local",
),
MirSemanticsGuard(
guard_id="step_return_uninit_or_dead",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="TerminatorKind.return_ rejects uninitialized or dead _0 as UB",
anchor=" | some (.immediate none) | some .dead => .fault .undefined",
replacement=(
" | some (.immediate none) | some .dead =>\n"
" .done (.returned ⟨.unit, callerMem⟩)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_return_uninit_or_dead",
),
MirSemanticsGuard(
guard_id="step_return_indirect_uninit",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="TerminatorKind.return_ rejects uninitialized indirect _0 as UB",
anchor=(
" match loadIndirect mem retTy mplace with\n"
" | .ok (some retVal) => .done (.returned ⟨retVal, callerMem⟩)\n"
" | .ok none => .fault .undefined"
),
replacement=(
" match loadIndirect mem retTy mplace with\n"
" | .ok (some retVal) => .done (.returned ⟨retVal, callerMem⟩)\n"
" | .ok none => .done (.returned ⟨.unit, callerMem⟩)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_return_indirect_uninit",
),
MirSemanticsGuard(
guard_id="step_unreachable_terminator",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="TerminatorKind.unreachable faults UB",
anchor=" | .unreachable =>\n .fault .undefined",
replacement=" | .unreachable =>\n .done (.returned ⟨.unit, callerMem⟩)",
fixture_module="StepRefutations",
theorem_name="refute_step_unreachable_terminator",
),
MirSemanticsGuard(
guard_id="step_force_alloc_dead_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="forceAllocation rejects .dead local as UB",
anchor=(
" match getElem? body.locals localId, getElem? frame.locals localId with\n"
" | some _, some .dead => .error .undefined"
),
replacement=(
" match getElem? body.locals localId, getElem? frame.locals localId with\n"
" | some _, some .dead => .ok (s, ⟨0, 0⟩)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_force_alloc_dead_local",
),
MirSemanticsGuard(
guard_id="step_nonroot_return_uninit_or_dead",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalNonRootReturn rejects uninitialized or dead callee _0 as UB",
anchor=(
" | some (.immediate (some retVal)) => .ok retVal\n"
" | some (.immediate none) | some .dead => .error .undefined"
),
replacement=(
" | some (.immediate (some retVal)) => .ok retVal\n"
" | some (.immediate none) | some .dead =>\n"
" .ok (.scalar ⟨.i32, false, BitVec.ofNat 128 0⟩)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_nonroot_return_uninit_or_dead",
),
MirSemanticsGuard(
guard_id="step_nonroot_return_none_target",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalNonRootReturn faults UB when callee returns to target = none",
anchor=(
" match callee.retTarget? with\n"
" | none => .fault .undefined\n"
" | some tgt =>"
),
replacement=(
" match callee.retTarget? with\n"
" | none => .done (.returned ⟨.unit, ⟨[]⟩⟩)\n"
" | some tgt =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_nonroot_return_none_target",
),
MirSemanticsGuard(
guard_id="step_nonroot_return_indirect_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalNonRootReturn fails closed on .indirect callee locals",
anchor=" if bb.cleanup || localsHaveIndirect callee.locals then",
replacement=" if bb.cleanup then",
fixture_module="StepRefutations",
theorem_name="refute_step_nonroot_return_indirect_local",
),
# ------------------------------------------------------------------
# Trusted/MirSemantics/State.lean (3 sysroot UB + 2 call/init guards)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="state_sysroot_unchecked_add_ub",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="sysrootNumBinOp maps .uncheckedAdd to .addUnchecked (not wrapping .add)",
anchor=(
"noncomputable def sysrootNumBinOp : SysrootNumKind → BinOp\n"
" | .uncheckedAdd => .addUnchecked"
),
replacement=(
"noncomputable def sysrootNumBinOp : SysrootNumKind → BinOp\n"
" | .uncheckedAdd => .add"
),
fixture_module="StepRefutations",
theorem_name="refute_state_sysroot_unchecked_add_ub",
),
MirSemanticsGuard(
guard_id="state_sysroot_unchecked_sub_ub",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="sysrootNumBinOp maps .uncheckedSub to .subUnchecked (not wrapping .sub)",
anchor=" | .uncheckedSub => .subUnchecked",
replacement=" | .uncheckedSub => .sub",
fixture_module="StepRefutations",
theorem_name="refute_state_sysroot_unchecked_sub_ub",
),
MirSemanticsGuard(
guard_id="state_sysroot_unchecked_mul_ub",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="sysrootNumBinOp maps .uncheckedMul to .mulUnchecked (not wrapping .mul)",
anchor=" | .uncheckedMul => .mulUnchecked",
replacement=" | .uncheckedMul => .mul",
fixture_module="StepRefutations",
theorem_name="refute_state_sysroot_unchecked_mul_ub",
),
MirSemanticsGuard(
guard_id="state_calls_admitted_unsafe_callee",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="callsAdmitted rejects intra-crate .call targets that are unsafe fns",
anchor=(
" | some calleeBody =>\n"
" !calleeBody.isExternal &&\n"
" !calleeBody.isUnsafe &&\n"
" callTargetAdmitted body bb calleeBody args dst target unwind"
),
replacement=(
" | some calleeBody =>\n"
" !calleeBody.isExternal &&\n"
" callTargetAdmitted body bb calleeBody args dst target unwind"
),
fixture_module="StepRefutations",
theorem_name="refute_state_calls_admitted_unsafe_callee",
),
MirSemanticsGuard(
guard_id="state_v2_init_uses_entry_memory_for_args",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description=(
"initStateV2 uses entryMemoryForArgsV2 so callee stack allocations "
"cannot reuse dangling raw-pointer argument AllocIds"
),
anchor=" let entryMem := entryMemoryForArgsV2 q.callerMem paramTys q.args",
replacement=" let entryMem := entryMemoryWithCaller q.callerMem",
fixture_module="StepRefutations",
theorem_name="refute_state_v2_init_uses_entry_memory_for_args",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_copy_imm_reject_projection",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Operand.copy on immediate local rejects projections",
anchor=(
" | some ty, some (.immediate optVal) =>\n"
" if !place.projection.isEmpty then\n"
" .error .unsupported\n"
" else\n"
" .ok (ty, optVal, locals, mem)"
),
replacement=(
" | some ty, some (.immediate optVal) =>\n"
" if false then\n"
" .error .unsupported\n"
" else\n"
" .ok (ty, optVal, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_copy_imm_reject_projection",
),
MirSemanticsGuard(
guard_id="step_copy_indirect_reject_projection",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Operand.copy on indirect local rejects projections",
anchor=(
" | some ty, some (.indirect mplace) =>\n"
" if !place.projection.isEmpty then\n"
" .error .unsupported\n"
" else if !tyOk ty then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirect mem ty mplace with\n"
" | .ok optVal => .ok (ty, optVal, locals, mem)"
),
replacement=(
" | some ty, some (.indirect mplace) =>\n"
" if false then\n"
" .error .unsupported\n"
" else if !tyOk ty then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirect mem ty mplace with\n"
" | .ok optVal => .ok (ty, optVal, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_copy_indirect_reject_projection",
),
MirSemanticsGuard(
guard_id="step_copy_indirect_tyok_before_load",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Operand.copy on indirect local checks tyOk before memory read",
anchor=(
" else if !tyOk ty then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirect mem ty mplace with\n"
" | .ok optVal => .ok (ty, optVal, locals, mem)"
),
replacement=(
" else if false then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirect mem ty mplace with\n"
" | .ok optVal => .ok (ty, optVal, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_copy_indirect_tyok_before_load",
),
MirSemanticsGuard(
guard_id="step_move_imm_reject_projection",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Operand.move on immediate local rejects projections",
anchor=(
" | some ty, some (.immediate optVal) =>\n"
" if !place.projection.isEmpty then\n"
" .error .unsupported\n"
" else\n"
" match setElem? locals place.localId (liveUninitSlot ty) with"
),
replacement=(
" | some ty, some (.immediate optVal) =>\n"
" if false then\n"
" .error .unsupported\n"
" else\n"
" match setElem? locals place.localId (liveUninitSlot ty) with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_move_imm_reject_projection",
),
MirSemanticsGuard(
guard_id="step_move_indirect_reject_projection",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Operand.move on indirect local rejects projections",
anchor=(
" | some ty, some (.indirect mplace) =>\n"
" if !place.projection.isEmpty then\n"
" .error .unsupported\n"
" else if !tyOk ty then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirect mem ty mplace with\n"
" | .error k => .error k\n"
" | .ok optVal =>\n"
" match deinitIndirect mem ty mplace with"
),
replacement=(
" | some ty, some (.indirect mplace) =>\n"
" if false then\n"
" .error .unsupported\n"
" else if !tyOk ty then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirect mem ty mplace with\n"
" | .error k => .error k\n"
" | .ok optVal =>\n"
" match deinitIndirect mem ty mplace with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_move_indirect_reject_projection",
),
MirSemanticsGuard(
guard_id="step_move_indirect_tyok_before_load",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Operand.move on indirect local checks tyOk before memory read",
anchor=(
" else if !tyOk ty then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirect mem ty mplace with\n"
" | .error k => .error k\n"
" | .ok optVal =>\n"
" match deinitIndirect mem ty mplace with"
),
replacement=(
" else if false then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirect mem ty mplace with\n"
" | .error k => .error k\n"
" | .ok optVal =>\n"
" match deinitIndirect mem ty mplace with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_move_indirect_tyok_before_load",
),
MirSemanticsGuard(
guard_id="step_prim_operand_requires_primitive_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalPrimitiveOperand rejects non-primitive-readable types",
anchor=(
" | .ok (ty, optVal, locals', mem') =>\n"
" if !isPrimitiveReadableTy ty then\n"
" .error .unsupported"
),
replacement=(
" | .ok (ty, optVal, locals', mem') =>\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_prim_operand_requires_primitive_ty",
),
MirSemanticsGuard(
guard_id="step_use_type_mismatch",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalue .use lockstep-classifies srcTy != dstTy before uninit",
anchor=" if !(MirTy.beq srcTy dstTy) then\n .error .unsupported",
replacement=" if false then\n .error .unsupported",
fixture_module="StepRefutations",
theorem_name="refute_step_use_type_mismatch",
),
MirSemanticsGuard(
guard_id="step_cast_requires_intlike_src",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalue (.cast .intToInt) lockstep-classifies non-int-like srcTy",
anchor=" if !isIntLikeTy srcTy then\n .error .unsupported",
replacement=" if false then\n .error .unsupported",
fixture_module="StepRefutations",
theorem_name="refute_step_cast_requires_intlike_src",
),
MirSemanticsGuard(
guard_id="step_discriminant_imm_reject_projection",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalue .discriminant rejects projected immediate place",
anchor=(
" | some srcTy, some (.immediate optVal) =>\n"
" if !place.projection.isEmpty then\n"
" .error .unsupported"
),
replacement=(
" | some srcTy, some (.immediate optVal) =>\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_discriminant_imm_reject_projection",
),
MirSemanticsGuard(
guard_id="step_discriminant_indirect_reject_projection",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalue .discriminant rejects projected indirect place",
anchor=(
" | some srcTy, some (.indirect mplace) =>\n"
" if !place.projection.isEmpty then\n"
" .error .unsupported"
),
replacement=(
" | some srcTy, some (.indirect mplace) =>\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_discriminant_indirect_reject_projection",
),
MirSemanticsGuard(
guard_id="step_write_place_check_val",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="writePlace enforces checkVal val dstTy",
anchor=(
"noncomputable def writePlace (locals : List LocalSlot) (mem : MemoryState)\n"
" (dstLocalId : LocalId) (dstTy : MirTy) (val : Val) :\n"
" Except FaultKind (List LocalSlot × MemoryState) :=\n"
" if !checkVal val dstTy then\n"
" .error .unsupported"
),
replacement=(
"noncomputable def writePlace (locals : List LocalSlot) (mem : MemoryState)\n"
" (dstLocalId : LocalId) (dstTy : MirTy) (val : Val) :\n"
" Except FaultKind (List LocalSlot × MemoryState) :=\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_write_place_check_val",
),
MirSemanticsGuard(
guard_id="step_deallocate_local_indirect",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="deallocateLocal frees indirect stack allocation on StorageDead",
anchor=" | .indirect mplace => deallocateStack mem mplace",
replacement=" | .indirect _ => .ok mem",
fixture_module="StepRefutations",
theorem_name="refute_step_deallocate_local_indirect",
),
MirSemanticsGuard(
guard_id="step_storage_live_reinits_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="StorageLive resets already-live local to liveUninitSlot",
anchor=" match setElem? frame.locals localId (liveUninitSlot localTy) with",
replacement=" match some frame.locals with",
fixture_module="StepRefutations",
theorem_name="refute_step_storage_live_reinits_local",
),
MirSemanticsGuard(
guard_id="step_storage_dead_return_place",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="StorageDead 0 rejects deallocating return place _0",
anchor=(
" callerMem\n"
" mem := mem'\n"
" }\n"
" | .storageDead localId =>\n"
" if Nat.beq localId 0 then\n"
" .fault .unsupported"
),
replacement=(
" callerMem\n"
" mem := mem'\n"
" }\n"
" | .storageDead localId =>\n"
" if false then\n"
" .fault .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_storage_dead_return_place",
),
MirSemanticsGuard(
guard_id="step_assign_reject_dst_projection",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalStatement .assign rejects non-empty destination projection",
anchor=(
" | .assign dst rvalue =>\n"
" if !dst.projection.isEmpty then\n"
" .fault .unsupported"
),
replacement=(
" | .assign dst rvalue =>\n"
" if false then\n"
" .fault .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_assign_reject_dst_projection",
),
MirSemanticsGuard(
guard_id="step_statement_unsupported_faults",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="StatementKind.unsupported fails closed with .fault .unsupported",
anchor=(
" callerMem\n"
" mem := memAfterWrite\n"
" }\n"
" | .placeMention _ | .unsupported => .fault .unsupported"
),
replacement=(
" callerMem\n"
" mem := memAfterWrite\n"
" }\n"
" | .placeMention _ | .unsupported =>\n"
" .step { frames := [{ frame with stmtIdx := frame.stmtIdx + 1 }], "
"callerMem, mem }"
),
fixture_module="StepRefutations",
theorem_name="refute_step_statement_unsupported_faults",
),
MirSemanticsGuard(
guard_id="step_switch_int_case_overflow",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalSwitchBranches rejects case bits overflowing width w",
anchor=" if truncateBits w caseBits != caseBits then\n .error .unsupported",
replacement=" if false then\n .error .unsupported",
fixture_module="StepRefutations",
theorem_name="refute_step_switch_int_case_overflow",
),
MirSemanticsGuard(
guard_id="step_switch_bool_invalid_case",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalBoolSwitchBranches propagates invalid bool case faults",
anchor=(
" | .ok (.bool true) =>\n"
" if discr then .ok target else evalBoolSwitchBranches discr otherwise rest\n"
" | .error k =>\n"
" .error k"
),
replacement=(
" | .ok (.bool true) =>\n"
" if discr then .ok target else evalBoolSwitchBranches discr otherwise rest\n"
" | .error _ =>\n"
" evalBoolSwitchBranches discr otherwise rest"
),
fixture_module="StepRefutations",
theorem_name="refute_step_switch_bool_invalid_case",
),
MirSemanticsGuard(
guard_id="step_switch_char_invalid_case",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalCharSwitchBranches propagates invalid char case faults",
anchor=(
" else\n"
" evalCharSwitchBranches discr otherwise rest\n"
" | .error k =>\n"
" .error k"
),
replacement=(
" else\n"
" evalCharSwitchBranches discr otherwise rest\n"
" | .error _ =>\n"
" evalCharSwitchBranches discr otherwise rest"
),
fixture_module="StepRefutations",
theorem_name="refute_step_switch_char_invalid_case",
),
MirSemanticsGuard(
guard_id="step_return_in_cleanup_block",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="TerminatorKind.return_ rejects cleanup unwind blocks",
anchor=(
" | .return_ =>\n"
" if bb.cleanup then\n"
" .fault .unsupported\n"
" else\n"
" match getElem? frame.locals 0 with"
),
replacement=(
" | .return_ =>\n"
" if false then\n"
" .fault .unsupported\n"
" else\n"
" match getElem? frame.locals 0 with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_return_in_cleanup_block",
),
MirSemanticsGuard(
guard_id="step_switch_overflow_pair_nonempty_branches",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="switchInt on overflow pair rejects non-empty branch lists",
anchor=(
" -- (which compares nothing) jumps to `otherwise`.\n"
" match targets.branches with\n"
" | [] => .ok targets.otherwise\n"
" | _ :: _ => .error .unsupported"
),
replacement=(
" -- (which compares nothing) jumps to `otherwise`.\n"
" match targets.branches with\n"
" | [] => .ok targets.otherwise\n"
" | _ :: _ => .ok targets.otherwise"
),
fixture_module="StepRefutations",
theorem_name="refute_step_switch_overflow_pair_nonempty_branches",
),
MirSemanticsGuard(
guard_id="step_unsupported_terminators_fault",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Unmodeled terminators "
"(unwindResume/call/coreCall/sysrootCall/callNe/callVia/drop/unsupported) fault"
),
anchor=(
" | .unwindResume | .call _ _ _ _ _ | .coreCall _ _ _ _ _\n"
" | .sysrootCall _ _ _ _ _ | .callNe _ _ _ _ _ | .callVia _ _ _ _ _ _\n"
" | .drop _ _ _ | .unsupported =>\n"
" .fault .unsupported"
),
replacement=(
" | .unwindResume | .call _ _ _ _ _ | .coreCall _ _ _ _ _\n"
" | .sysrootCall _ _ _ _ _ | .callNe _ _ _ _ _ | .callVia _ _ _ _ _ _\n"
" | .drop _ _ _ | .unsupported =>\n"
" .done (.returned ⟨.unit, callerMem⟩)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_unsupported_terminators_fault",
),
MirSemanticsGuard(
guard_id="step_oob_block_idx_faults",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalStep faults .unsupported on out-of-bounds blockIdx",
anchor=(
" match getElem? body.basicBlocks frame.blockIdx with\n"
" | none => .fault .unsupported\n"
" | some bb =>\n"
" match getElem? bb.statements frame.stmtIdx with\n"
" | some stmt =>\n"
" attachCallers callers\n"
" (evalStatement body frame s.mem s.callerMem stmt)"
),
replacement=(
" match getElem? body.basicBlocks frame.blockIdx with\n"
" | none => .done (.returned ⟨.unit, s.callerMem⟩)\n"
" | some bb =>\n"
" match getElem? bb.statements frame.stmtIdx with\n"
" | some stmt =>\n"
" attachCallers callers\n"
" (evalStatement body frame s.mem s.callerMem stmt)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_oob_block_idx_faults",
),
MirSemanticsGuard(
guard_id="step_operand_copy_oob_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalOperandToSlot .copy rejects out-of-bounds localId",
anchor=(
" | .error k => .error k\n"
" | _, _ => .error .unsupported\n"
" | .move place =>"
),
replacement=(
" | .error k => .error k\n"
" | _, _ => .ok (.unit, some .unit, locals, mem)\n"
" | .move place =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_operand_copy_oob_local",
),
MirSemanticsGuard(
guard_id="step_operand_move_oob_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalOperandToSlot .move rejects out-of-bounds localId",
anchor=(
" | .error k => .error k\n"
" | _, _ => .error .unsupported\n"
" | .constant c =>"
),
replacement=(
" | .error k => .error k\n"
" | _, _ => .ok (.unit, some .unit, locals, mem)\n"
" | .constant c =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_operand_move_oob_local",
),
MirSemanticsGuard(
guard_id="step_discriminant_non_enum_src",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalue .discriminant rejects non-enum immediate source",
anchor=(
" | .ordering => evalOrderingDiscriminantOfVal optVal locals mem\n"
" | _ => .error .unsupported\n"
" | some srcTy, some (.indirect mplace) =>"
),
replacement=(
" | .ordering => evalOrderingDiscriminantOfVal optVal locals mem\n"
" | _ => .ok (.scalar ⟨.i8, false, BitVec.ofNat 128 0⟩, locals, mem)\n"
" | some srcTy, some (.indirect mplace) =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_discriminant_non_enum_src",
),
MirSemanticsGuard(
guard_id="step_rvalue_catchall_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalue catch-all rejects ref/addressOf/unsupported rvalues",
anchor=(
" | _ => .error .unsupported\n\n"
"/-- Write `val` into"
),
replacement=(
" | _ => .ok (.unit, locals, mem)\n\n"
"/-- Write `val` into"
),
fixture_module="StepRefutations",
theorem_name="refute_step_rvalue_catchall_unsupported",
),
MirSemanticsGuard(
guard_id="step_assign_oob_dst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalStatement .assign rejects out-of-bounds dst.localId",
anchor=(
" match getElem? body.locals dst.localId with\n"
" | none => .fault .unsupported\n"
" | some dstTy =>\n"
" match evalRvalue body.locals frame.locals mem dstTy rvalue with"
),
replacement=(
" match getElem? body.locals dst.localId with\n"
" | none =>\n"
" .step { frames := [{ frame with stmtIdx := frame.stmtIdx + 1 }], "
"callerMem, mem }\n"
" | some dstTy =>\n"
" match evalRvalue body.locals frame.locals mem dstTy rvalue with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_assign_oob_dst",
),
# ------------------------------------------------------------------
# Trusted/MirSemantics/Boundary.lean (12 v1 judgment & admission guards
# & 4 Profile v2 guards = 16 total; 9 singleBodyStaticAdmitted guards are
# under State.lean above)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="boundary_wellformed_forbids_faults",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="WellFormed forbids reachable faults",
anchor=" (∀ k : FaultKind, ¬ ReachesResult p q (.fault k))",
replacement=" True",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_wellformed_forbids_faults",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_safe_fn_ignores_safety_pre",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="BodyVerified ignores safetyPre for safe functions",
anchor=" (body.isUnsafe = true → safetyPre args) →",
replacement=" safetyPre args →",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_safe_fn_ignores_safety_pre",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_body_static_admitted",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="BodyVerified requires BodyStaticAdmitted unconditionally",
anchor=" BodyStaticAdmitted p body = true ∧",
replacement=" True ∧",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_body_static_admitted",
needs_wf_helper=False,
),
# ------------------------------------------------------------------
# Profile v2 memory, step, type-admission, and boundary guards (131 guards)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="mem_v2_ptr_add_null_nonzero",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="ptrAddInMem rejects nonzero offset on provenance-free (null) pointer as UB",
anchor=(
" | none =>\n"
" if Nat.beq delta 0 then\n"
" .ok p\n"
" else\n"
" .error .undefined"
),
replacement=(
" | none =>\n"
" if true then\n"
" .ok p\n"
" else\n"
" .error .undefined"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_ptr_add_null_nonzero",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_ptr_add_oob",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="ptrAddInMem rejects offset past end of allocation as UB",
anchor=(
" | some a =>\n"
" if !a.live || !Nat.ble (p.offsetBytes.toNat + delta) a.bytes.length then\n"
" .error .undefined"
),
replacement=(
" | some a =>\n"
" if !a.live || false then\n"
" .error .undefined"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_ptr_add_oob",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_null",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"sliceRefRawCheck and sliceFromRawPartsCheck reject null pointer "
"even for zero-length slices as UB"
),
anchor=(
" | none =>\n"
" if Nat.beq p.offsetBytes.toNat 0 || Nat.blt 0 totalBytes then\n"
" .error .undefined"
),
replacement=(
" | none =>\n"
" if false || Nat.blt 0 totalBytes then\n"
" .error .undefined"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_slice_null",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_readonly",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"sliceRefRawCheck and sliceFromRawPartsCheck reject non-empty "
"mutable slice over .shared allocation as UB"
),
anchor=(
" else if isMut && Nat.blt 0 totalBytes &&\n"
" !Mutability.beq a.mutability .mut then\n"
" .error .undefined"
),
replacement=(
" else if false then\n"
" .error .undefined"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_slice_readonly",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_readonly_zero_len",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"sliceRefRawCheck and sliceFromRawPartsCheck accept zero-byte "
"mutable slice over .shared .rodata allocation"
),
anchor=(
" else if isMut && Nat.blt 0 totalBytes &&\n"
" !Mutability.beq a.mutability .mut then\n"
" .error .undefined"
),
replacement=(
" else if isMut && true &&\n"
" !Mutability.beq a.mutability .mut then\n"
" .error .undefined"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_slice_readonly_zero_len",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_uninit",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="sliceFromRawPartsCheck rejects uninitialized bytes in slice span as UB",
anchor=(
" | .ok (some a) =>\n"
" if !isSliceAllInit ((a.bytes.drop p.offsetBytes.toNat).take totalBytes) then\n"
" .error .undefined\n"
" else\n"
" .ok (.slicePtr p len)"
),
replacement=(
" | .ok (some _) =>\n"
" if false then\n"
" .error .undefined\n"
" else\n"
" .ok (.slicePtr p len)"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_slice_uninit",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_get_unchecked_oob",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="sliceGetUncheckedCheck rejects endOff > len out-of-bounds subslice as UB",
anchor=(
" (len startOff endOff : Nat) (elemSize : Nat := 1) : Except FaultKind Val :=\n"
" if !Nat.ble startOff endOff || !Nat.ble endOff len then\n"
" .error .undefined"
),
replacement=(
" (len startOff endOff : Nat) (elemSize : Nat := 1) : Except FaultKind Val :=\n"
" if !Nat.ble startOff endOff || false then\n"
" .error .undefined"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_slice_get_unchecked_oob",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_entry_byte_prov_fresh",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"entryMemoryWithCaller advances nextAllocId past provenance AllocIds "
"stored inside caller allocation bytes"
),
anchor=(
"noncomputable def entryMemoryWithCaller (cm : CallerMemory) : MemoryState :=\n"
" { nextAllocId := Nat.max entryMemory.nextAllocId (maxAllocAndProvId cm.allocations + 1)"
),
replacement=(
"noncomputable def entryMemoryWithCaller (cm : CallerMemory) : MemoryState :=\n"
" { nextAllocId := Nat.max entryMemory.nextAllocId (maxAllocId cm.allocations + 1)"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_entry_byte_prov_fresh",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_entry_raw_ptr_arg_fresh",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"entryMemoryForArgsV2 advances nextAllocId past provenance AllocIds "
"carried in raw-pointer parameters"
),
anchor=(
" let base := entryMemoryWithCaller cm\n"
" if !tyListHasRawPtrV2 paramTys then\n"
" base"
),
replacement=(
" let base := entryMemoryWithCaller cm\n"
" if true then\n"
" base"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_entry_raw_ptr_arg_fresh",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_entry_option_raw_ptr_ty",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"tyHasRawPtrV2 recurses through Option so Option<*const T> "
"parameters advance the entry nextAllocId"
),
anchor=(
" | .option e | .rangeTo e | .rangeFrom e | .range e => "
"tyHasRawPtrV2 e\n"
),
replacement=(
" | .option _ => false\n"
" | .rangeTo e | .rangeFrom e | .range e => tyHasRawPtrV2 e\n"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_entry_option_raw_ptr_ty",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_entry_option_raw_ptr_val",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"maxValPtrAllocId counts provenance AllocIds inside Some payloads"
),
anchor=" | .optionVal (some v) => maxValPtrAllocId v\n",
replacement=" | .optionVal (some _) => 0\n",
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_entry_option_raw_ptr_val",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_get_unchecked_elem_size",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="sliceGetUncheckedCheck scales startOff by elemSize in ptrAddInMem",
anchor=" match ptrAddInMem m elemSize p startOff with",
replacement=" match ptrAddInMem m 1 p startOff with",
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_slice_get_unchecked_elem_size",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_write_readonly",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"resolvePlaceDestV2 rejects dereference store through a .shared "
"raw pointer as UB"
),
anchor=(
" if isUnsizedTy pt || !MirTy.beq pt dstTy then\n"
" .error .unsupported\n"
" else if !Mutability.beq ptrMut .mut then\n"
" .error .undefined"
),
replacement=(
" if isUnsizedTy pt || !MirTy.beq pt dstTy then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_write_readonly",
),
MirSemanticsGuard(
guard_id="step_v2_return_dangling_stack_ref",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalTerminatorV2 .return_ rejects returning a reference to a callee stack local as UB",
anchor=(
" else if !refsStayInCallerMem callerMem retTy retVal ||\n"
" !refsValidInMem mem retTy retVal ||\n"
" !spansPairwiseDisjoint (valueAccessSpans mem retTy retVal) then\n"
" .fault .undefined"
),
replacement=(
" else if false ||\n"
" !refsValidInMem mem retTy retVal ||\n"
" !spansPairwiseDisjoint (valueAccessSpans mem retTy retVal) then\n"
" .fault .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_return_dangling_stack_ref",
),
MirSemanticsGuard(
guard_id="step_v2_offset_dst_type",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 .offset rejects a destination type that differs "
"from the pointer operand type"
),
anchor=(
" if isUnsizedTy pt || !MirTy.beq dstTy lhsTy then\n"
" .error .unsupported"
),
replacement=(
" if isUnsizedTy pt then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_offset_dst_type",
),
MirSemanticsGuard(
guard_id="step_v2_get_unchecked_range_to_in_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp validates the get_unchecked(..end) input slice "
"at its own mutability"
),
anchor=(
" match refValidInMem m inMut (.slice (.int w s)) (.slicePtr p len) with\n"
" | .error k => .error k\n"
" | .ok () =>\n"
" sliceGetUncheckedCheck m p len.toNat 0 endOff.toNat w.byteSize"
),
replacement=(
" match refValidInMem m outMut (.slice (.int w s)) (.slicePtr p len) with\n"
" | .error k => .error k\n"
" | .ok () =>\n"
" sliceGetUncheckedCheck m p len.toNat 0 endOff.toNat w.byteSize"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_get_unchecked_range_to_in_mut",
),
MirSemanticsGuard(
guard_id="step_v2_get_unchecked_range_from_in_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp validates the get_unchecked(start..) input slice "
"at its own mutability"
),
anchor=(
" match refValidInMem m inMut (.slice (.int w s)) (.slicePtr p len) with\n"
" | .error k => .error k\n"
" | .ok () =>\n"
" sliceGetUncheckedCheck m p len.toNat startOff.toNat len.toNat\n"
" w.byteSize"
),
replacement=(
" match refValidInMem m outMut (.slice (.int w s)) (.slicePtr p len) with\n"
" | .error k => .error k\n"
" | .ok () =>\n"
" sliceGetUncheckedCheck m p len.toNat startOff.toNat len.toNat\n"
" w.byteSize"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_get_unchecked_range_from_in_mut",
),
MirSemanticsGuard(
guard_id="step_v2_get_unchecked_range_in_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp validates the get_unchecked(start..end) input slice "
"at its own mutability"
),
anchor=(
" match refValidInMem m inMut (.slice (.int w s)) (.slicePtr p len) with\n"
" | .error k => .error k\n"
" | .ok () =>\n"
" sliceGetUncheckedCheck m p len.toNat startOff.toNat endOff.toNat\n"
" w.byteSize"
),
replacement=(
" match refValidInMem m outMut (.slice (.int w s)) (.slicePtr p len) with\n"
" | .error k => .error k\n"
" | .ok () =>\n"
" sliceGetUncheckedCheck m p len.toNat startOff.toNat endOff.toNat\n"
" w.byteSize"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_get_unchecked_range_in_mut",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_get_unchecked_range_from_elem_stride",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp scales get_unchecked(start..) pointer offset by "
"the slice element byte size"
),
anchor=(
" sliceGetUncheckedCheck m p len.toNat startOff.toNat len.toNat\n"
" w.byteSize"
),
replacement=(
" sliceGetUncheckedCheck m p len.toNat startOff.toNat len.toNat\n"
" 1"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_get_unchecked_range_from_elem_stride",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_get_unchecked_range_elem_stride",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp scales get_unchecked(start..end) pointer offset by "
"the slice element byte size"
),
anchor=(
" sliceGetUncheckedCheck m p len.toNat startOff.toNat endOff.toNat\n"
" w.byteSize"
),
replacement=(
" sliceGetUncheckedCheck m p len.toNat startOff.toNat endOff.toNat\n"
" 1"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_get_unchecked_range_elem_stride",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_mem_size_of_unsupported_local_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp .memSizeOf enforces isSupportedV2LocalTy rather "
"than evaluating layoutOfTyV2 on unsupported local types"
),
anchor=(
" | .memSizeOf ty, [] =>\n"
" if !MirTy.beq dstTy (.int .isize false) || isUnsizedTy ty ||\n"
" !isSupportedV2LocalTy ty then"
),
replacement=(
" | .memSizeOf ty, [] =>\n"
" if !MirTy.beq dstTy (.int .isize false) || isUnsizedTy ty ||\n"
" false then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_mem_size_of_unsupported_local_ty",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_mem_size_of_isize_max",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp .memSizeOf rejects layouts of isize::MAX + 1 bytes "
"or more instead of truncating them"
),
anchor=(
" if !Nat.blt lay.size isizeMaxBytes then\n"
" .error .unsupported"
),
replacement=(
" if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_mem_size_of_isize_max",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_int_from_le_bytes_array_len",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp .intFromLeBytes requires the byte array length to "
"equal w.byteSize"
),
anchor=(
" | .intFromLeBytes w s, [(.array (.int .i8 false) len, .array vs)] =>\n"
" if !Nat.beq len w.byteSize || !Nat.beq vs.length w.byteSize ||\n"
" !MirTy.beq dstTy (.int w s) then"
),
replacement=(
" | .intFromLeBytes w s, [(.array (.int .i8 false) len, .array vs)] =>\n"
" if false ||\n"
" !MirTy.beq dstTy (.int w s) then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_int_from_le_bytes_array_len",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_get_unchecked_index_in_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp validates the get_unchecked(idx) input slice at "
"its own mutability"
),
anchor=(
" match refValidInMem m inMut (.slice elem) (.slicePtr p len) with\n"
" | .error k => .error k\n"
" | .ok () =>\n"
" let idx := (truncateBits .isize idxSv.bits).toNat"
),
replacement=(
" match refValidInMem m outMut (.slice elem) (.slicePtr p len) with\n"
" | .error k => .error k\n"
" | .ok () =>\n"
" let idx := (truncateBits .isize idxSv.bits).toNat"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_get_unchecked_index_in_mut",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_get_unchecked_index_oob",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp .sliceGetUncheckedIndex rejects idx >= len as "
".undefined"
),
anchor=(
" let idx := (truncateBits .isize idxSv.bits).toNat\n"
" if !Nat.blt idx len.toNat then\n"
" .error .undefined"
),
replacement=(
" let idx := (truncateBits .isize idxSv.bits).toNat\n"
" if false then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_get_unchecked_index_oob",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_get_unchecked_index_elem_stride",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp .sliceGetUncheckedIndex advances the element "
"pointer by lay.size"
),
anchor=(
" match ptrAddInMem m lay.size p idx with\n"
" | .error k => .error k\n"
" | .ok p' => .ok (.ptr p')"
),
replacement=(
" match ptrAddInMem m 1 p idx with\n"
" | .error k => .error k\n"
" | .ok p' => .ok (.ptr p')"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_get_unchecked_index_elem_stride",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_slice_subslice_in_mut",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execSliceSubsliceOutcome validates the input slice reference at its "
"own "
"mutability"
),
anchor=(
" match refValidInMem m inMut (.slice elem) (.slicePtr p len) with\n"
" | .error k => .fault k\n"
" | .ok () =>\n"
" if !Nat.ble startOff endOff || !Nat.ble endOff len.toNat then"
),
replacement=(
" match refValidInMem m reqMut (.slice elem) (.slicePtr p len) with\n"
" | .error k => .fault k\n"
" | .ok () =>\n"
" if !Nat.ble startOff endOff || !Nat.ble endOff len.toNat then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_slice_subslice_in_mut",
),
MirSemanticsGuard(
guard_id="core_contracts_slice_split_at_in_mut",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execSliceSplitAtOutcome validates the input slice reference at "
"its own mutability"
),
anchor=(
" match refValidInMem m inMut (.slice elem) (.slicePtr p len) with\n"
" | .error k => .fault k\n"
" | .ok () =>\n"
" if !Nat.ble mid len.toNat then"
),
replacement=(
" match refValidInMem m reqMut (.slice elem) (.slicePtr p len) with\n"
" | .error k => .fault k\n"
" | .ok () =>\n"
" if !Nat.ble mid len.toNat then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_slice_split_at_in_mut",
),
MirSemanticsGuard(
guard_id="core_contracts_i128_host_overflow",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"truncateScalarWithHostOverflow detects 128-bit mathematical "
"overflow via intHostOverflow before BitVec 128 carrier truncation"
),
anchor=(
" match truncateScalar w s value with\n"
" | .error k => .error k\n"
" | .ok (sv, truncOvf) => .ok (sv, intHostOverflow s value || truncOvf)"
),
replacement=(
" match truncateScalar w s value with\n"
" | .error k => .error k\n"
" | .ok (sv, truncOvf) => .ok (sv, truncOvf)"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_i128_host_overflow",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="enum_v2_overflow_pair_pointee",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isSupportedV2DataTy rejects overflow pairs as pointees or array elements",
anchor=(
" noncomputable def isSupportedV2DataTy : MirTy → Bool\n"
" | .array elem _ => isSupportedV2DataTy elem\n"
" | .struct_ _ fs => isSupportedV2DataTyList fs\n"
" | ty => !isOverflowPairTy ty && isSupportedScalarOrUnitTy ty"
),
replacement=(
" noncomputable def isSupportedV2DataTy : MirTy → Bool\n"
" | .array elem _ => isSupportedV2DataTy elem\n"
" | .struct_ _ fs => isSupportedV2DataTyList fs\n"
" | ty => true && isSupportedScalarOrUnitTy ty"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_overflow_pair_pointee",
),
MirSemanticsGuard(
guard_id="enum_v2_sized_no_ref_tuple_pointee",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"isSizedNoRefV2Ty and isSupportedV2LocalTy reject pointers to "
"tuples and overflow pairs"
),
anchor=(
" | .tuple _ | .array _ _ | .vec _ | .box _ | .ref _ _ | .rawPtr _ _ | .slice _\n"
),
replacement=(
" | .tuple _ => true\n"
" | .array _ _ | .vec _ | .box _ | .ref _ _ | .rawPtr _ _ | .slice _\n"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_overflow_pair_pointee",
),
MirSemanticsGuard(
guard_id="step_v2_ptr_cast_const_to_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalPtrToPtrCastV2 rejects a *const T to *mut T cast, which "
"could write to an immutable binding"
),
anchor=" if isConstRawPtrTy srcTy && Mutability.beq castMut .mut then",
replacement=" if false && Mutability.beq castMut .mut then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_ptr_cast_const_to_mut",
),
MirSemanticsGuard(
guard_id="step_v2_assign_resolves_destination_first",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalStatementV2 resolves an assignment's destination before "
"evaluating its rvalue"
),
anchor=" match writePlaceDestV2 locals1 mem1 dest dstTy val with",
replacement=(
" match writePlaceV2 body.locals locals1 mem1 dst dstTy val with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_resolves_destination_first",
),
MirSemanticsGuard(
guard_id="step_v2_raw_borrow_mut_through_const",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalAddressOfRvalueV2 rejects &raw mut *p through a *const T "
"pointer as UB"
),
anchor=(
" if Mutability.beq srcMut .shared && Mutability.beq reqMut .mut then\n"
" .error .undefined\n"
" else if !MirTy.beq dstTy (.rawPtr reqMut pt) then"
),
replacement=(
" if false && Mutability.beq reqMut .mut then\n"
" .error .undefined\n"
" else if !MirTy.beq dstTy (.rawPtr reqMut pt) then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_raw_borrow_mut_through_const",
),
MirSemanticsGuard(
guard_id="step_v2_partial_tuple_move_moved_field",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="readPlaceV2 rejects moving an already moved tuple field as UB",
anchor=(
" | none => .error .unsupported\n"
" | some _, some none => .error .undefined"
),
replacement=(
" | none => .error .unsupported\n"
" | some elemTy, some none => .ok (elemTy, some .unit, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_partial_tuple_move_moved_field",
),
MirSemanticsGuard(
guard_id="step_v2_partial_tuple_copy_moved_field",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="readPlaceV2 rejects copying an already moved tuple field as UB",
anchor=(
" else .ok (elemTy, some elemVal, locals, mem)\n"
" | some _, some none => .error .undefined"
),
replacement=(
" else .ok (elemTy, some elemVal, locals, mem)\n"
" | some elemTy, some none =>\n"
" .ok (elemTy, some .unit, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_partial_tuple_copy_moved_field",
),
MirSemanticsGuard(
guard_id="step_v2_partial_tuple_whole_read",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="readPlaceV2 rejects reading a partially moved tuple as a whole as UB",
anchor=(
" | .dead => .error .undefined\n"
" | .partialTuple _ => .error .undefined\n"
" | .immediate optVal =>"
),
replacement=(
" | .dead => .error .undefined\n"
" | .partialTuple _ => .ok (baseTy, some .unit, locals, mem)\n"
" | .immediate optVal =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_partial_tuple_whole_read",
),
MirSemanticsGuard(
guard_id="step_v2_assert_failure_faults",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 .assert faults instead of continuing when an "
"overflow check fails"
),
anchor=(
" if b == expected then\n"
" jumpToBlock { frame with locals := locals1 } mem1 callerMem target\n"
" else\n"
" evalAssertFailure msg panicStrategy unwind\n"
" (extractCallerMemory callerMem mem1) hasLocalPanicHandler"
),
replacement=(
" if true then\n"
" jumpToBlock { frame with locals := locals1 } mem1 callerMem target\n"
" else\n"
" evalAssertFailure msg panicStrategy unwind\n"
" (extractCallerMemory callerMem mem1) hasLocalPanicHandler"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assert_failure_faults",
),
MirSemanticsGuard(
guard_id="step_v2_constant_index_min_len",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="constantIndexOffset rejects arrays shorter than minLen as UB",
anchor=(
"noncomputable def constantIndexOffset (len off minLen : Nat)\n"
" (fromEnd : Bool) : Except FaultKind Nat :=\n"
" if !Nat.ble minLen len then\n"
" .error .undefined"
),
replacement=(
"noncomputable def constantIndexOffset (len off minLen : Nat)\n"
" (fromEnd : Bool) : Except FaultKind Nat :=\n"
" if false then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_constant_index_min_len",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_constant_index_oob",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="constantIndexOffset rejects out-of-bounds offset >= len as UB",
anchor=(
" else\n"
" if !Nat.blt off len then\n"
" .error .undefined"
),
replacement=(
" else\n"
" if false then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_constant_index_oob",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_read_deref_proj_raw_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="readDerefProjectedV2 enforces base-pointer alignment for raw sub-place reads",
anchor=(
" if !isAligned a pv.offsetBytes.toNat ptLay.alignLog2 ||\n"
" (isRef && (!a.live || !isInBounds a pv.offsetBytes.toNat ptLay.size)) ||"
),
replacement=(
" if false ||\n"
" (isRef && (!a.live || !isInBounds a pv.offsetBytes.toNat ptLay.size)) ||"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_deref_proj_raw_misaligned",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_read_deref_proj_no_prov_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readDerefProjectedV2 enforces base-pointer alignment for "
"provenance-free zero-size projected reads"
),
anchor=(
" let badBaseAlign :=\n"
" !Nat.beq (Nat.mod pv.offsetBytes.toNat (Nat.pow 2 ptLay.alignLog2)) 0\n"
" let badRefBase :="
),
replacement=(
" let badBaseAlign :=\n"
" false\n"
" let badRefBase :="
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_deref_proj_no_prov_misaligned",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_read_deref_proj_no_prov_nonzero_zst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readDerefProjectedV2 rejects non-zero projection offsets on "
"provenance-free raw pointers even for zero-sized leaf fields"
),
anchor=" let badProjOffset := Nat.blt 0 subOff",
replacement=" let badProjOffset := false",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_deref_proj_no_prov_nonzero_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_read_deref_proj_dangling_nonzero_zst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readDerefProjectedV2 rejects non-zero projection offsets on "
"dangling raw pointers even for zero-sized leaf fields"
),
anchor=" if (Nat.blt 0 subOff && !a.live) ||",
replacement=" if false ||",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_deref_proj_dangling_nonzero_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_read_deref_proj_oob_nonzero_zst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readDerefProjectedV2 rejects out-of-bounds non-zero projection "
"offsets on raw pointers even for zero-sized leaf fields"
),
anchor=(
" (Nat.blt 0 subOff &&\n"
" !isInBounds a pv.offsetBytes.toNat (subOff + leafLay.size)) then"
),
replacement=" false then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_deref_proj_oob_nonzero_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_read_deref_proj_downcast_dangling_nonzero_zst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readDerefProjectedV2 downcast arm rejects non-zero projection "
"offsets on dangling raw pointers even for zero-sized leaf fields"
),
anchor=" if (Nat.blt pv.offsetBytes.toNat off && !a.live) ||",
replacement=" if false ||",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_deref_proj_downcast_dangling_nonzero_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_read_deref_proj_downcast_oob_nonzero_zst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readDerefProjectedV2 downcast arm rejects out-of-bounds non-zero "
"projection offsets on raw pointers even for zero-sized leaf fields"
),
anchor=(
" (Nat.blt pv.offsetBytes.toNat off &&\n"
" !isInBounds a off leafLay.size) then"
),
replacement=" false then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_deref_proj_downcast_oob_nonzero_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_unsize_shared_to_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="CastKind.unsize rejects coercing & [T; N] to &mut [T] as UB",
anchor=(
" | .ref srcMut (.array srcElem len), .ref dstMut (.slice dstElem), .ptr p =>\n"
" if !MirTy.beq srcElem dstElem || !Nat.blt len (Nat.pow 2 64) then\n"
" .error .unsupported\n"
" else if Mutability.beq srcMut .shared &&\n"
" Mutability.beq dstMut .mut then\n"
" .error .undefined"
),
replacement=(
" | .ref srcMut (.array srcElem len), .ref dstMut (.slice dstElem), .ptr p =>\n"
" if !MirTy.beq srcElem dstElem || !Nat.blt len (Nat.pow 2 64) then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_unsize_shared_to_mut",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_unsize_src_mut_valid",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"CastKind.unsize validates source &mut [T; N] at srcMut before "
"reborrowing as &[T]"
),
anchor=(
" match refValidInMem mem1 srcMut (.array srcElem len) (.ptr p) with"
),
replacement=(
" match refValidInMem mem1 dstMut (.array srcElem len) (.ptr p) with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_unsize_src_mut_valid",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_unsize_raw_shared_to_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="CastKind.unsize rejects coercing *const [T; N] to *mut [T] as UB",
anchor=(
" | .rawPtr srcMut (.array srcElem len),\n"
" .rawPtr dstMut (.slice dstElem), .ptr p =>\n"
" if !MirTy.beq srcElem dstElem || !Nat.blt len (Nat.pow 2 64) then\n"
" .error .unsupported\n"
" else if Mutability.beq srcMut .shared &&\n"
" Mutability.beq dstMut .mut then\n"
" .error .undefined"
),
replacement=(
" | .rawPtr srcMut (.array srcElem len),\n"
" .rawPtr dstMut (.slice dstElem), .ptr p =>\n"
" if !MirTy.beq srcElem dstElem || !Nat.blt len (Nat.pow 2 64) then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_unsize_raw_shared_to_mut",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_resolve_deref_proj_propagates_ub",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"resolvePlaceDestV2 propagates projectMemoryLayoutV2 .error .undefined "
"faults on dereferenced projected stores"
),
anchor=(
" match layoutOfTyV2 pt, projectMemoryLayoutV2 pt rest with\n"
" | none, _ => .error .unsupported\n"
" | _, .error k => .error k"
),
replacement=(
" match layoutOfTyV2 pt, projectMemoryLayoutV2 pt rest with\n"
" | none, _ => .error .unsupported\n"
" | _, .error _ => .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_resolve_deref_proj_propagates_ub",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_read_indirect_proj_propagates_error",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readPlaceV2 propagates projection errors on indirect "
"locals instead of falling back to a whole-local load"
),
anchor=(
" -- whole `Option` first (`projectMemoryPlaceV2`).\n"
" match projectMemoryPlaceV2 mem mplace.allocId mplace.offset baseTy\n"
" [] projs with\n"
" | .error k => .error k"
),
replacement=(
" -- whole `Option` first (`projectMemoryPlaceV2`).\n"
" match projectMemoryPlaceV2 mem mplace.allocId mplace.offset baseTy\n"
" [] projs with\n"
" | .error _ => .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_indirect_proj_propagates_error",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_resolve_local_proj_validates_first",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"resolvePlaceDestV2 validates projected immediate-local "
"destinations before rvalue evaluation"
),
anchor=(
" | some baseTy, some (.immediate _) =>\n"
" match validatePlaceProjV2 baseTy projs with\n"
" | .error k => .error k"
),
replacement=(
" | some baseTy, some (.immediate _) =>\n"
" match validatePlaceProjV2 baseTy projs with\n"
" | .error _ => .ok (.localProj dst.localId baseTy projs)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_resolve_local_proj_validates_first",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_rodata_bytes_data_ty_only",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalOperandToSlotV2 restricts ConstLit.rodataBytes to "
"isSupportedV2DataTy or heap-free payload-enum variants and "
"fails closed on references"
),
anchor=(
" | .rodataBytes bytes =>\n"
" let allocBytes := bytes.map rodataByteToAllocByte\n"
" if !isSupportedV2DataTy c.ty &&\n"
" !rodataAdtVariantDataOkV2 c.ty allocBytes then\n"
" .error .unsupported"
),
replacement=(
" | .rodataBytes bytes =>\n"
" let allocBytes := bytes.map rodataByteToAllocByte\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rodata_bytes_data_ty_only",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_zero_sized_adt_enum",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalOperandToSlotV2 decodes zero-sized .adtEnum ConstLit.zeroSized constants"
),
anchor=(
" | .adtEnum l vs =>\n"
" -- A zero-sized payload enum constant (`ConstValue::ZeroSized`) has no\n"
" -- bytes; `decodeValV2` checks `layoutOfTyV2` (rejecting any non-ZST\n"
" -- field) and decodes its single variant from the empty byte list.\n"
" match decodeValV2 profileV2TargetEndian (.adtEnum l vs) [] with"
),
replacement=(
" | .adtEnum l vs =>\n"
" match (Except.error .unsupported : Except FaultKind (Option Val)) with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_enum_consts",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_rodata_adt_active_variant_data_only",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"rodataAdtVariantDataOkV2 requires the active payload-enum "
"variant to be heap-free owned data (rejecting heap handles)"
),
anchor=(
" match adtDecodeVariantV2 profileV2TargetEndian l bytes with\n"
" | .ok (some i) =>\n"
" match getElem? vs i with\n"
" | some vTy => isOwnedDataTyV2 vTy && !tyHasHeapHandleV2 vTy\n"
" | none => false"
),
replacement=(
" match adtDecodeVariantV2 profileV2TargetEndian l bytes with\n"
" | .ok (some i) =>\n"
" match getElem? vs i with\n"
" | some _ => true\n"
" | none => false"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rodata_adt_active_variant_data_only",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_rodata_ref_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRodataRefConstV2 rejects mutable &mut T reference over .rodata as unsupported",
anchor=(
" | .ref reqMut pt, none =>\n"
" if isUnsizedTy pt || !rodataPointeeOkV2 pt allocBytes offsetBytes then\n"
" .error .unsupported\n"
" else if Mutability.beq reqMut .mut then\n"
" .error .unsupported"
),
replacement=(
" | .ref reqMut pt, none =>\n"
" if isUnsizedTy pt || !rodataPointeeOkV2 pt allocBytes offsetBytes then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rodata_ref_mut",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_rodata_ref_pointee_ok",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRodataRefConstV2 requires sized &T rodata pointees to pass "
"rodataPointeeOkV2"
),
anchor=(
" | .ref reqMut pt, none =>\n"
" if isUnsizedTy pt || !rodataPointeeOkV2 pt allocBytes offsetBytes then\n"
" .error .unsupported"
),
replacement=(
" | .ref reqMut pt, none =>\n"
" if isUnsizedTy pt then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rodata_ref_pointee_ok",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_rodata_slice_ref_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRodataRefConstV2 rejects mutable &mut [T] slice reference over .rodata as unsupported",
anchor=(
" | .ref reqMut (.slice elem), some len =>\n"
" if !Nat.blt len (Nat.pow 2 64) then\n"
" .error .unsupported\n"
" else if Mutability.beq reqMut .mut then\n"
" .error .unsupported"
),
replacement=(
" | .ref reqMut (.slice elem), some len =>\n"
" if !Nat.blt len (Nat.pow 2 64) then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rodata_slice_ref_mut",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_rodata_raw_ptr_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRodataRefConstV2 rejects mutable *mut T raw pointer over .rodata as unsupported",
anchor=(
" | .rawPtr reqMut pt, none =>\n"
" if isUnsizedTy pt || !isSupportedV2DataTy pt then\n"
" .error .unsupported\n"
" else if Mutability.beq reqMut .mut then\n"
" .error .unsupported"
),
replacement=(
" | .rawPtr reqMut pt, none =>\n"
" if isUnsizedTy pt || !isSupportedV2DataTy pt then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rodata_raw_ptr_mut",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_rodata_raw_ptr_data_ty_only",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRodataRefConstV2 restricts sized *const T raw pointers over "
".rodata to isSupportedV2DataTy"
),
anchor=(
" | .rawPtr reqMut pt, none =>\n"
" if isUnsizedTy pt || !isSupportedV2DataTy pt then\n"
" .error .unsupported"
),
replacement=(
" | .rawPtr reqMut pt, none =>\n"
" if isUnsizedTy pt then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rodata_raw_ptr_data_ty_only",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_rodata_raw_slice_mut",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRodataRefConstV2 rejects mutable *mut [T] raw slice over .rodata as unsupported",
anchor=(
" | .rawPtr reqMut (.slice _), some len =>\n"
" if !Nat.blt len (Nat.pow 2 64) then\n"
" .error .unsupported\n"
" else if Mutability.beq reqMut .mut then\n"
" .error .unsupported"
),
replacement=(
" | .rawPtr reqMut (.slice _), some len =>\n"
" if !Nat.blt len (Nat.pow 2 64) then\n"
" .error .unsupported\n"
" else if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rodata_raw_slice_mut",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_array_eq_dangling_ref",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="CoreCallOp.arrayEq validates reference operands via refValidInMem",
anchor=(
" match refValidInMem m m1 (.array elem len) (.ptr p1),\n"
" refValidInMem m m2 (.array elem len) (.ptr p2) with\n"
" | .error k, _ => .error k"
),
replacement=(
" match (Except.ok () : Except FaultKind Unit),\n"
" refValidInMem m m2 (.array elem len) (.ptr p2) with\n"
" | .error k, _ => .error k"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_array_eq_dangling_ref",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_core_call_partial_eq_ne_routed",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="execCoreCallWithMemOutcome routes CoreCallOp.partialEqNe to execCoreCallOp",
anchor=(
" | .usizeUncheckedSub | .intToLeBytes _ _ | .intFromLeBytes _ _ | .memSizeOf _\n"
" | .arrayEq _ _\n"
" | .partialEqNe _ =>\n"
" match execCoreCallOp m op args dstTy with\n"
" | .ok v => .ok v m\n"
" | .error k => .fault k\n"
" | .sliceIndexRange _ _"
),
replacement=(
" | .usizeUncheckedSub | .intToLeBytes _ _ | .intFromLeBytes _ _ | .memSizeOf _\n"
" | .arrayEq _ _ =>\n"
" match execCoreCallOp m op args dstTy with\n"
" | .ok v => .ok v m\n"
" | .error k => .fault k\n"
" | .partialEqNe _ | .sliceIndexRange _ _"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_call_partial_eq_ne_routed",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_borrow_deref_projection_ub",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"placeAddrV2 propagates projectMemoryLayoutV2/projectMemoryPlaceV2 "
"faults below a deref (projected deref borrows)"
),
anchor=(
" match projectMemoryPlaceV2 mem aid p.offsetBytes.toNat pt [] rest with\n"
" | .error k' => .error k'"
),
replacement=(
" match projectMemoryPlaceV2 mem aid p.offsetBytes.toNat pt [] rest with\n"
" | .error _ => .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_borrow_deref_projection_ub",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_return_rodata_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalTerminatorV2 .return_ faults .unsupported when returning a callee .rodata ref or raw pointer",
anchor=(
" if hasEscapingRodataPtr callerMem mem retTy retVal then\n"
" .fault .unsupported"
),
replacement=(
" if false then\n"
" .fault .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_return_rodata_unsupported",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_ptr_or_ref_alloc_ids_option",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"ptrOrRefAllocIds recurses into a Some payload, so returning an "
"Option of a pointer into callee .rodata faults .unsupported"
),
anchor=(
" | .option inner, .optionVal (some innerV) => "
"ptrOrRefAllocIds inner innerV"
),
replacement=" | .option _, .optionVal (some _) => []",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_return_rodata_option_ptr",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_slice_uninhabited_elem",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refValidInMem rejects positive-length slices of uninhabited ZST "
"or nested uninhabited element types as UB"
),
anchor=(
" if Nat.blt 0 len.toNat && !isInhabitedV2Ty elem then\n"
" .error .undefined"
),
replacement=(
" if Nat.blt 0 len.toNat && false then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_bytes_v2_slice_uninhabited_elem",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assert_abort_extract_caller_mem",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalTerminatorV2 .assert abort preserves pre-abort caller memory mutations",
anchor=(
" else\n"
" evalAssertFailure msg panicStrategy unwind\n"
" (extractCallerMemory callerMem mem1) hasLocalPanicHandler"
),
replacement=(
" else\n"
" evalAssertFailure msg panicStrategy unwind callerMem hasLocalPanicHandler"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assert_abort_extract_caller_mem",
),
MirSemanticsGuard(
guard_id="step_assert_optional_overflow_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalAssertFailure keeps optional overflow assertions as "
".fault .unsupported without overflowChecks"
),
anchor=" if !overflowChecks || hasLocalPanicHandler then",
replacement=" if hasLocalPanicHandler then",
fixture_module="StepRefutations",
theorem_name="refute_step_assert_optional_overflow_unsupported",
),
MirSemanticsGuard(
guard_id="step_assert_checked_overflow_local_handler_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalAssertFailure keeps checked overflow assertions as "
".fault .unsupported under a crate-local #[panic_handler]"
),
anchor=" if !overflowChecks || hasLocalPanicHandler then",
replacement=" if !overflowChecks then",
fixture_module="StepRefutations",
theorem_name=(
"refute_step_assert_checked_overflow_local_handler_unsupported"
),
),
MirSemanticsGuard(
guard_id="step_assert_local_panic_handler_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalAssertFailure keeps failing safe assertions as .fault .unsupported "
"when the crate defines a crate-local #[panic_handler]"
),
anchor=(
" if hasLocalPanicHandler then\n"
" .fault .unsupported\n"
" else"
),
replacement=(
" if false then\n"
" .fault .unsupported\n"
" else"
),
fixture_module="StepRefutations",
theorem_name="refute_step_assert_local_panic_handler_unsupported",
),
MirSemanticsGuard(
guard_id="step_assert_ptr_deref_undefined",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalAssertFailure maps .misalignedPtrDeref and .nullPtrDeref "
"to .fault .undefined even under --panic abort"
),
anchor=(
" | .misalignedPtrDeref | .nullPtrDeref => .fault .undefined\n"
" | .boundsCheck | .overflow .div | .overflow .rem\n"
" | .divByZero | .remByZero =>"
),
replacement=(
" | .misalignedPtrDeref | .nullPtrDeref => .fault .unsupported\n"
" | .boundsCheck | .overflow .div | .overflow .rem\n"
" | .divByZero | .remByZero =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_assert_ptr_deref_undefined",
),
MirSemanticsGuard(
guard_id="step_assert_v1_failure_faults",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminator .assert routes failing conditions (b != expected) "
"through evalAssertFailure rather than jumping to target"
),
anchor=(
" | .bool b =>\n"
" if b == expected then\n"
" jumpToBlock { frame with locals := locals1 } mem1 callerMem target\n"
" else\n"
" evalAssertFailure msg panicStrategy unwind callerMem\n"
" hasLocalPanicHandler"
),
replacement=(
" | .bool b =>\n"
" if true then\n"
" jumpToBlock { frame with locals := locals1 } mem1 callerMem target\n"
" else\n"
" evalAssertFailure msg panicStrategy unwind callerMem\n"
" hasLocalPanicHandler"
),
fixture_module="StepRefutations",
theorem_name="refute_step_assert_v1_failure_faults",
),
MirSemanticsGuard(
guard_id="step_assert_v1_non_bool_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminator .assert refuses non-bool condition operands "
"with .fault .unsupported"
),
anchor=(
" else\n"
" evalAssertFailure msg panicStrategy unwind callerMem\n"
" hasLocalPanicHandler\n"
" | _ => .fault .unsupported"
),
replacement=(
" else\n"
" evalAssertFailure msg panicStrategy unwind callerMem\n"
" hasLocalPanicHandler\n"
" | _ =>\n"
" jumpToBlock { frame with locals := locals1 } mem1 callerMem target"
),
fixture_module="StepRefutations",
theorem_name="refute_step_assert_v1_non_bool_unsupported",
),
MirSemanticsGuard(
guard_id="step_v2_assert_non_bool_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 .assert refuses non-bool condition operands "
"with .fault .unsupported"
),
anchor=(
" else\n"
" evalAssertFailure msg panicStrategy unwind\n"
" (extractCallerMemory callerMem mem1) hasLocalPanicHandler\n"
" overflowChecks\n"
" | _ => .fault .unsupported"
),
replacement=(
" else\n"
" evalAssertFailure msg panicStrategy unwind\n"
" (extractCallerMemory callerMem mem1) hasLocalPanicHandler\n"
" overflowChecks\n"
" | _ =>\n"
" jumpToBlock { frame with locals := locals1 } mem1 callerMem target"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assert_non_bool_unsupported",
),
MirSemanticsGuard(
guard_id="step_v2_assign_use_overlap_ub",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"checkAssignCopyHazardV2 rejects overlapping non-zero-sized "
"BackendRepr::Memory or padded Assign Use copies as UB"
),
anchor=(
" | .use (.copy src) | .use (.move src)\n"
" | .useRetag (.copy src) | .useRetag (.move src) =>\n"
" if !isMemoryCopyReprTyV2 dstTy then\n"
" .ok ()"
),
replacement=(
" | .use (.copy src) | .use (.move src)\n"
" | .useRetag (.copy src) | .useRetag (.move src) =>\n"
" if true then\n"
" .ok ()"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_use_overlap_ub",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_aggregate_clobber_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"checkAggregateCopyHazardLoopV2 fails closed with .unsupported when "
"an earlier Aggregate field write overlaps a later operand"
),
anchor=(
" if clobberedByEarlier then\n"
" .error .unsupported"
),
replacement=(
" if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_aggregate_clobber_unsupported",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_aggregate_range_clobber_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"checkAssignCopyHazardV2 routes Range aggregates through the "
"in-order field-write hazard loop"
),
anchor=(
" | .aggregateRange elemTy startOp endOp =>\n"
" match copyReprOfTyV2 dstTy with"
),
replacement=(
" | .aggregateRange elemTy startOp endOp =>\n"
" match (CopyReprV2.zst 0 : CopyReprV2) with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_aggregate_range_clobber_unsupported",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_range_field_span",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"normalizeImmProjPathV2 resolves Range field projections on "
"immediate locals"
),
anchor=(
" if !Nat.blt idx 2 || !MirTy.beq (.int .isize false) fTy then none"
),
replacement=(
" if true then none"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_range_field_span",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_option_payload_span",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"normalizeImmProjPathV2 resolves Option payload projections on "
"immediate locals"
),
anchor=(
" | .option inner, .downcast 1 :: .field 0 fTy :: rest =>\n"
" if !MirTy.beq inner fTy then none"
),
replacement=(
" | .option inner, .downcast 1 :: .field 0 fTy :: rest =>\n"
" if true then none"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_option_payload_span",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_adt_enum_payload_span",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"normalizeImmProjPathV2 resolves payload enum and recursive enum "
"downcasts on immediate locals"
),
anchor=(
" | ty, .downcast vi :: rest =>\n"
" let isField := match rest with | .field _ _ :: _ => true | _ => false\n"
" if !isField then none\n"
" else\n"
" match adtVariantPayloadV2 ty vi with\n"
" | some pTy => (normalizeImmProjPathV2 pTy rest).map (fun _ => [])\n"
" | none => none"
),
replacement=(
" | _, .downcast _ :: _ => none"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_adt_enum_payload_span",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_adt_enum_self_overlap_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"checkAssignCopyHazardV2 fails closed on .aggregateAdtEnum with "
"same-enum operand overlap"
),
anchor=(
" if fields.any (fun op =>\n"
" match operandCopySpanV2 bodyLocals locals mem op with\n"
" | some opSpan => copySpansOverlapV2 baseSpan opSpan\n"
" | none => false) then\n"
" .error .unsupported\n"
" else"
),
replacement=(
" if false then\n"
" .error .unsupported\n"
" else"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_adt_enum_self_overlap_unsupported",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_aggregate_unresolved_operand_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"checkAggregateCopyHazardLoopV2 fails closed on a non-constant "
"operand whose source span is unresolved"
),
anchor=(
" else if unresolved &&\n"
" (!writtenSpans.isEmpty || isMemoryCopyReprTyV2 fieldTy) then"
),
replacement=(
" else if false &&\n"
" (!writtenSpans.isEmpty || isMemoryCopyReprTyV2 fieldTy) then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_aggregate_unresolved_operand_unsupported",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_aggregate_deref_ptr_clobber_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"checkAggregateCopyHazardLoopV2 fails closed with .unsupported when "
"an earlier Aggregate field write overlaps the pointer local read by "
"a later .deref operand"
),
anchor=(
" else if ptrClobberedByEarlier then\n"
" .error .unsupported"
),
replacement=(
" else if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_aggregate_deref_ptr_clobber_unsupported",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_aggregate_field_overlap_ub",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"checkAggregateCopyHazardLoopV2 rejects overlapping "
"BackendRepr::Memory Aggregate field writes as UB"
),
anchor=(
" if selfOverlap && isMemoryCopyReprTyV2 fieldTy then\n"
" .error .undefined"
),
replacement=(
" if false then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_aggregate_field_overlap_ub",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_repeat_overlap_ub",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"checkAssignCopyHazardV2 rejects overlapping BackendRepr::Memory "
"Rvalue.repeat_ initial element copies as UB"
),
anchor=(
" | .repeat_ op elemTy count =>\n"
" if Nat.beq count 0 || !isMemoryCopyReprTyV2 elemTy then\n"
" .ok ()"
),
replacement=(
" | .repeat_ op elemTy count =>\n"
" if true then\n"
" .ok ()"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_repeat_overlap_ub",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_core_panic_local_handler_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCorePanicAbort keeps diverging core::panicking calls as "
".fault .unsupported when the crate defines a crate-local #[panic_handler]"
),
anchor=(
" if hasLocalPanicHandler then\n"
" .fault .unsupported\n"
" else"
),
replacement=(
" if false then\n"
" .fault .unsupported\n"
" else"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_panic_local_handler_unsupported",
),
MirSemanticsGuard(
guard_id="step_v2_core_panic_unwind_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCorePanicAbort keeps diverging core::panicking calls as "
".fault .unsupported under --panic unwind"
),
anchor=(
" match panicStrategy, unwind with\n"
" | .abort, .continue_ | .abort, .unreachable | .abort, .terminate =>\n"
" .done (.aborted callerMem)\n"
" | _, _ => .fault .unsupported"
),
replacement=(
" match panicStrategy, unwind with\n"
" | .abort, .continue_ | .abort, .unreachable | .abort, .terminate\n"
" | .unwind, .continue_ =>\n"
" .done (.aborted callerMem)\n"
" | _, _ => .fault .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_panic_unwind_unsupported",
),
MirSemanticsGuard(
guard_id="step_v2_core_panic_abort_extract_caller_mem",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 .coreCall .panicAbort preserves pre-abort caller "
"memory mutations"
),
anchor=(
" match validatePanicAbortArgs mem1 typedArgs with\n"
" | .error k => .fault k\n"
" | .ok () =>\n"
" evalCorePanicAbort panicStrategy unwind\n"
" (extractCallerMemory callerMem mem1) hasLocalPanicHandler"
),
replacement=(
" match validatePanicAbortArgs mem1 typedArgs with\n"
" | .error k => .fault k\n"
" | .ok () =>\n"
" evalCorePanicAbort panicStrategy unwind callerMem hasLocalPanicHandler"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_panic_abort_extract_caller_mem",
),
MirSemanticsGuard(
guard_id="step_v2_core_panic_abort_ref_valid",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"validatePanicAbortArgs re-validates refValidInMem on local &str "
"operands passed to CoreCallOp.panicAbort"
),
anchor=(
" | [(.ref .shared .str, .slicePtr p len)] =>\n"
" if !IntWidth.beq p.width .isize then\n"
" .error .unsupported\n"
" else\n"
" match refValidInMem m .shared .str (.slicePtr p len) with"
),
replacement=(
" | [(.ref .shared .str, .slicePtr p len)] =>\n"
" if !IntWidth.beq p.width .isize then\n"
" .error .unsupported\n"
" else\n"
" match Except.ok () with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_panic_abort_ref_valid",
),
MirSemanticsGuard(
guard_id="step_v2_core_panic_abort_non_utf8_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"validatePanicAbortArgs rejects non-UTF-8 &str operands passed to "
"CoreCallOp.panicAbort as .error .unsupported"
),
anchor=(
" if !strSliceUtf8InMem m p len then\n"
" .error .unsupported\n"
" else\n"
" .ok ()"
),
replacement=(
" if false then\n"
" .error .unsupported\n"
" else\n"
" .ok ()"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_panic_abort_non_utf8_unsupported",
),
MirSemanticsGuard(
guard_id="step_v2_ptr_metadata_str_dst_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 UnOp.ptrMetadata on &str requires usize destination "
"type"
),
anchor=(
" | .ref .shared .str, .slicePtr p len =>\n"
" if !MirTy.beq dstTy (.int .isize false) then\n"
" .error .unsupported"
),
replacement=(
" | .ref .shared .str, .slicePtr p len =>\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_ptr_metadata_str_dst_ty",
),
MirSemanticsGuard(
guard_id="step_v2_ptr_metadata_str_ref_valid",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 UnOp.ptrMetadata on &str validates refValidInMem on "
"the source string slice"
),
anchor=(
" match refValidInMem mem1 .shared .str (.slicePtr p len) with\n"
" | .error k => .error k\n"
" | .ok () =>"
),
replacement=(
" match Except.ok () with\n"
" | .error k => .error k\n"
" | .ok () =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_ptr_metadata_str_ref_valid",
),
MirSemanticsGuard(
guard_id="step_v2_core_panic_abort_eval_args",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 .coreCall .panicAbort evaluates its &str "
"argument before aborting so uninitialized local or rodata "
"operands fault .undefined"
),
anchor=(
" match evalArgOperandsV2 body.locals frame.locals mem args with\n"
" | .error k => .fault k\n"
" | .ok (typedArgs, _, mem1) =>"
),
replacement=(
" match evalArgOperandsV2 body.locals frame.locals mem args with\n"
" | .error _ =>\n"
" evalCorePanicAbort panicStrategy unwind\n"
" (extractCallerMemory callerMem mem) hasLocalPanicHandler\n"
" | .ok (typedArgs, _, mem1) =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_panic_abort_eval_args",
),
MirSemanticsGuard(
guard_id="step_v2_core_panic_abort_dead_dst_unsupported",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 .coreCall .panicAbort rejects dead ! destination "
"locals as .fault .unsupported before aborting"
),
anchor=(
" | some .never, some (.immediate _)\n"
" | some .never, some (.indirect _) =>"
),
replacement=(
" | some .never, some (.immediate _)\n"
" | some .never, some (.indirect _)\n"
" | some .never, some .dead =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_panic_abort_dead_dst_unsupported",
),
MirSemanticsGuard(
guard_id="enum_v2_overflow_pair_vec_elem",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isSupportedV2LocalTy rejects Vec of overflow pairs",
anchor=(
" | .vec elem => isOwnedDataTyV2 elem"
),
replacement=(
" | .vec elem => true"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_overflow_pair_vec_elem",
),
MirSemanticsGuard(
guard_id="enum_v2_overflow_pair_box_pointee",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isSupportedV2LocalTy rejects Box of an overflow pair",
anchor=(
" | .box pt => isOwnedDataTyV2 pt"
),
replacement=(
" | .box pt => true"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_overflow_pair_box_pointee",
),
MirSemanticsGuard(
guard_id="enum_v2_overflow_pair_slice_elem",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isSupportedV2LocalTy rejects reference slices of overflow pairs",
anchor=(
" | .ref _ (.slice elem) => isSizedNoRefV2Ty elem || isOwnedDataTyV2 elem"
),
replacement=(
" | .ref _ (.slice elem) => true"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_overflow_pair_slice_elem",
),
MirSemanticsGuard(
guard_id="enum_v2_overflow_pair_raw_slice_elem",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isSupportedV2LocalTy rejects raw-pointer slices of overflow pairs",
anchor=(
" | .rawPtr _ (.slice elem) => isSizedNoRefV2Ty elem"
),
replacement=(
" | .rawPtr _ (.slice elem) => true"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_overflow_pair_slice_elem",
),
MirSemanticsGuard(
guard_id="enum_v2_owned_struct_fields",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isOwnedDataTyV2 requires every struct field to be owned data",
anchor=(
" | .struct_ _ fs => isOwnedDataTyListV2 fs"
),
replacement=(
" | .struct_ _ fs => true"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_owned_struct_fields",
),
MirSemanticsGuard(
guard_id="enum_v2_owned_option_handle_only",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"isOwnedDataTyV2 admits Option only of a Vec or Box handle or of "
"plain sized data"
),
anchor=(
" | .option inner =>\n"
" isHeapHandleTyV2 inner && isOwnedDataTyV2 inner ||\n"
" isSizedNoRefV2Ty (.option inner)"
),
replacement=(
" | .option inner =>\n"
" isOwnedDataTyV2 inner"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_owned_option_handle_only",
),
MirSemanticsGuard(
guard_id="enum_v2_raw_ptr_owned_pointee_refused",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isSupportedV2LocalTy refuses raw pointers to owned handle data",
anchor=(
" | .rawPtr _ pt => isSupportedV2PointeeTy pt"
),
replacement=(
" | .rawPtr _ pt => isSupportedV2PointeeTy pt || isOwnedDataTyV2 pt"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_raw_ptr_owned_pointee_refused",
),
MirSemanticsGuard(
guard_id="bytes_owned_vec_elems_validated",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="recEnterBufV2 validates the buffers owned by Vec elements",
anchor=(
" | .ok vs => recAllValsV2 (fun vs' v => heapRec vs' elem v) vis' vs"
),
replacement=(
" | .ok _ => .ok vis'"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_owned_vec_elems_validated",
),
MirSemanticsGuard(
guard_id="bytes_owned_struct_fields_validated",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="recOwnedWalkV2 validates the buffers owned by struct fields",
anchor=(
" | vis, .struct_ _ fs, .tuple vs =>\n"
" recOwnedWalkListV2 m isMut heapRec self vis fs vs"
),
replacement=(
" | vis, .struct_ _ _, .tuple _ => .ok vis"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_owned_struct_fields_validated",
),
MirSemanticsGuard(
guard_id="bytes_owned_option_some_validated",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="recOwnedWalkV2 validates the handle inside Some",
anchor=(
" | vis, .option inner, .optionVal (some v) =>\n"
" recOwnedWalkV2 m isMut heapRec self vis inner v"
),
replacement=(
" | vis, .option _, .optionVal (some _) => .ok vis"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_owned_option_some_validated",
),
MirSemanticsGuard(
guard_id="bytes_ref_pointee_owned_validated",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refValidInMem validates buffers owned by a reference pointee",
anchor=(
" ownedValidInMem m (Mutability.beq reqMut .mut) pointee decVal"
),
replacement=(
" .ok ()"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_ref_pointee_owned_validated",
),
MirSemanticsGuard(
guard_id="bytes_slice_owned_elems_validated",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refValidInMem validates buffers owned by slice elements",
anchor=(
" match recAllValsV2\n"
" (fun vis v =>\n"
" recOwnedValidAtV2 m isMut\n"
" (m.allocations.length + 2) vis elem v)\n"
" [] vs with\n"
" | .ok _ => .ok ()\n"
" | .error k => .error k"
),
replacement=(
" .ok ()"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_slice_owned_elems_validated",
),
MirSemanticsGuard(
guard_id="bytes_option_box_null_some_refused",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="encodeValV2 refuses Some of a null Box (it would encode as None)",
anchor=(
" if p.allocId.isNone && Nat.beq p.offsetBytes.toNat 0 then\n"
" .error .unsupported"
),
replacement=(
" if false then\n"
" .error .unsupported"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_option_box_null_some_refused",
),
MirSemanticsGuard(
guard_id="bytes_option_box_null_decode_refused",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"decodeValV2 refuses a null Box under Some (mixed-provenance zero "
"bytes), which encodeValV2 would refuse to re-encode"
),
anchor=(
" if p.allocId.isNone && Nat.beq p.offsetBytes.toNat 0 then\n"
" .ok none"
),
replacement=(
" if false then\n"
" .ok none"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_option_box_null_decode_refused",
),
MirSemanticsGuard(
guard_id="bytes_option_vec_niche_cap_refused",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="encodeValV2 refuses Vec and Option<Vec<T>>::Some with capacity >= 2^63",
anchor=(
" | .vec _, .vec p cap len =>\n"
" if !Nat.blt cap.toNat isizeMaxBytes then"
),
replacement=(
" | .vec _, .vec p cap len =>\n"
" if false then"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_option_vec_niche_cap_refused",
),
MirSemanticsGuard(
guard_id="bytes_vec_decode_high_bit_cap",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="decodeVecHandleV2 rejects Vec capacity words >= 2^63 (UsizeNoHighBit)",
anchor=(
" let capNat := decodeUInt endian cRaw\n"
" if !Nat.blt capNat isizeMaxBytes then\n"
" none"
),
replacement=(
" let capNat := decodeUInt endian cRaw\n"
" if false then\n"
" none"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_vec_decode_high_bit_cap",
),
MirSemanticsGuard(
guard_id="bytes_option_vec_none_niche_u64_max",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"Option<Vec<T>>::None encodes and decodes rustc's u64::MAX "
"(2^64 - 1) niche value (vecNoneNicheV2)"
),
anchor="noncomputable def vecNoneNicheV2 : Nat := Nat.pow 2 64 - 1",
replacement="noncomputable def vecNoneNicheV2 : Nat := Nat.pow 2 63",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_option_vec_none_niche_u64_max",
),
MirSemanticsGuard(
guard_id="bytes_heap_buf_zst_len_unbounded",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"heapBufValidInMem skips len <= cap for ZSTs (lay.size = 0) so "
"ValidEntryArgsV2 admits valid Rust Vec<ZST> with len >= 2^63"
),
anchor=(
" if !Nat.beq lay.size 0 && !Nat.ble len.toNat cap.toNat then\n"
" .error .undefined"
),
replacement=(
" if !Nat.ble len.toNat cap.toNat then\n"
" .error .undefined"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_heap_buf_zst_len_unbounded",
),
MirSemanticsGuard(
guard_id="bytes_vec_cap_offset",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="A Vec handle's capacity word is at rustc's offset 0",
anchor=(
'noncomputable def vecCapOffsetV2 : Nat := 0'
),
replacement=(
'noncomputable def vecCapOffsetV2 : Nat := 8'
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_vec_word_order",
),
MirSemanticsGuard(
guard_id="bytes_vec_ptr_offset",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="A Vec handle's pointer word is at rustc's offset 8",
anchor=(
'noncomputable def vecPtrOffsetV2 : Nat := 8'
),
replacement=(
'noncomputable def vecPtrOffsetV2 : Nat := 0'
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_vec_word_order",
),
MirSemanticsGuard(
guard_id="bytes_vec_len_offset",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="A Vec handle's length word is at rustc's offset 16",
anchor=(
'noncomputable def vecLenOffsetV2 : Nat := 16'
),
replacement=(
'noncomputable def vecLenOffsetV2 : Nat := 8'
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_vec_word_order",
),
MirSemanticsGuard(
guard_id="bytes_vec_encode_order",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="encodeVecHandleV2 writes the capacity word first",
anchor=(
' (encodeUInt endian 8 cap.toNat).map (fun b => AllocByte.init b none) ++\n (encodeUInt endian 8 p.offsetBytes.toNat).map\n (fun b => AllocByte.init b p.allocId) ++'
),
replacement=(
' (encodeUInt endian 8 p.offsetBytes.toNat).map\n (fun b => AllocByte.init b p.allocId) ++\n (encodeUInt endian 8 cap.toNat).map (fun b => AllocByte.init b none) ++'
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_vec_word_order",
),
MirSemanticsGuard(
guard_id="bytes_adt_untagged_check",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="adtFinishEncodeV2 requires the encoded bytes to read back as the encoded variant",
anchor=" | .ok (some w) => if Nat.beq w v then .ok bytes else .error .unsupported\n | _ => .error .unsupported",
replacement=" | _ => .ok bytes",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_untagged_check",
),
MirSemanticsGuard(
guard_id="bytes_adt_direct_unknown_tag",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="adtDecodeVariantV2 maps a direct tag only to a variant with that discriminant",
anchor=" .ok (findDiscrVariant?\n (tagBitsToDiscrBits l.tagWidth l.tagSigned l.discrWidth\n (BitVec.ofNat 128 tag))\n l.discriminants)",
replacement=" .ok (some (Nat.mod tag l.discriminants.length))",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_direct_unknown_tag",
),
MirSemanticsGuard(
guard_id="bytes_adt_niche_valid_range",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="adtDecodeVariantV2 requires a non-niche tag to be in the tag's valid range",
anchor=" else if inRange then .ok (some u)\n else .ok none",
replacement=" else .ok (some u)",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_niche_valid_range",
),
MirSemanticsGuard(
guard_id="bytes_adt_niche_untagged_index",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="adtDecodeVariantV2 rejects the niche value of the untagged variant",
anchor=" if Nat.beq (first + adtNicheRelV2 tagMod start tag) u then .ok none",
replacement=" if false then .ok none",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_niche_untagged_index",
),
MirSemanticsGuard(
guard_id="bytes_adt_niche_rel_wrap",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="adtNicheRelV2 wraps the niche-relative index at the tag width",
anchor=" if Nat.ble start tag then tag - start else tag + tagMod - start",
replacement=" if Nat.ble start tag then tag - start else tag + tagMod - start + 1",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_niche_rel_wrap",
),
MirSemanticsGuard(
guard_id="bytes_adt_tag_provenance",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="adtDecodeVariantV2 accepts a tag with provenance only for a pointer niche {0}",
anchor=(
" if IntWidth.beq l.tagWidth .isize && Nat.beq start 0 &&\n"
" Nat.beq first last then\n"
" .ok (some u)\n"
" else .error .unsupported\n"
" | _, _ => .error .unsupported"
),
replacement=" .ok (some u)\n | _, _ => .ok (some 0)",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_tag_provenance",
),
MirSemanticsGuard(
guard_id="layout_v2_option_int_field",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="layoutOfArrayV2 gives an Option<int> field its Option layout",
anchor=(
" | .option (.int w s) =>\n"
" match layoutOfTy (.int w s) with"
),
replacement=(
" | .option (.int w s) =>\n"
" match (none : Option LayoutData) with"
),
fixture_module="LayoutRefutations",
theorem_name="refute_layout_v2_option_plain_field",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_v2_option_bool_field",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="layoutOfArrayV2 gives Option<bool> and Option<()> fields a layout",
anchor=" | .option .bool | .option .unit => some ⟨1, 0⟩\n | .option (.int w s) =>",
replacement=" | .option .bool | .option .unit => none\n | .option (.int w s) =>",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_v2_option_plain_field",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_adt_tag_overlap",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="adtVariantWfV2 keeps a tagged variant's fields off the tag",
anchor=" (!adtVariantTaggedV2 l i ||\n natSpanDisjointWith (adtTagSpanV2 l) spans)",
replacement=" true",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_adt_tag_overlap",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_adt_direct_roundtrip",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="adtEnumHeadWfV2 requires direct discriminants to round-trip through the tag",
anchor=" tagFits && ds.all (fun d =>\n let dBits := BitVec.ofNat 128 d\n tagBitsToDiscrBits l.tagWidth l.tagSigned l.discrWidth\n (truncateBits l.tagWidth dBits) == dBits)",
replacement=" tagFits",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_adt_direct_roundtrip",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_adt_niche_discriminants",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="adtEnumHeadWfV2 requires a niche enum's discriminants to be its variant indices",
anchor=" natListBeq ds (natRangeFrom 0 n)",
replacement=" true",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_adt_niche_discriminants",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_adt_tag_in_bounds",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="adtEnumHeadWfV2 requires the tag to lie inside the enum",
anchor=" Nat.ble (l.tagOffset + l.tagWidth.byteSize) l.size &&",
replacement=" true &&",
fixture_module="LayoutRefutations",
theorem_name="refute_layout_adt_tag_in_bounds",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="enum_adt_check_val",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="checkValV2 checks an adtVal against its variant's payload",
anchor=" | .adtVal i p, .adtEnum _ vs => checkValV2Nth p i vs",
replacement=" | .adtVal _ _, .adtEnum _ _ => true",
fixture_module="BytesRefutations",
theorem_name="refute_enum_adt_check_val",
),
MirSemanticsGuard(
guard_id="enum_adt_owned_data",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isOwnedDataTyV2 admits a payload enum only when every variant is owned data",
anchor=" | .adtEnum _ vs => isOwnedDataTyListV2 vs",
replacement=" | .adtEnum _ _ => true",
fixture_module="BytesRefutations",
theorem_name="refute_enum_adt_owned_data",
),
MirSemanticsGuard(
guard_id="enum_adt_inhabited",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isInhabitedV2Ty admits a payload enum only when some variant is inhabited",
anchor=" | .adtEnum _ vs => isInhabitedV2TyAny vs\n",
replacement=" | .adtEnum _ _ => true\n",
fixture_module="BytesRefutations",
theorem_name="refute_enum_adt_inhabited",
),
MirSemanticsGuard(
guard_id="state_adt_has_ref",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="tyHasRefV2 looks into payload enum variants",
anchor=" | .struct_ _ fs | .adtEnum _ fs => tyListHasRefV2 fs\n",
replacement=(
" | .struct_ _ fs => tyListHasRefV2 fs\n"
" | .adtEnum _ _ => false\n"
),
fixture_module="BytesRefutations",
theorem_name="refute_state_adt_ref_and_drop",
),
MirSemanticsGuard(
guard_id="mem_v2_adt_raw_ptr_ty",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="tyHasRawPtrV2 looks into payload enum variants",
anchor=" | .struct_ _ fs | .adtEnum _ fs => tyListHasRawPtrV2 fs\n",
replacement=(
" | .struct_ _ fs => tyListHasRawPtrV2 fs\n"
" | .adtEnum _ _ => false\n"
),
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_adt_raw_ptr_ty",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_entry_adt_raw_ptr_val",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"maxValPtrAllocId counts provenance AllocIds inside payload enum "
"variants"
),
anchor=" | .adtVal _ payload => maxValPtrAllocId payload\n",
replacement=" | .adtVal _ _ => 0\n",
fixture_module="MemoryRefutations",
theorem_name="refute_mem_v2_entry_adt_raw_ptr_val",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_adt_needs_drop",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="tyNeedsDropV2 gives a payload enum the drop glue of its variants",
anchor=" | .adtEnum _ vs => tyNeedsDropV2List vs",
replacement=" | .adtEnum _ _ => false",
fixture_module="BytesRefutations",
theorem_name="refute_state_adt_ref_and_drop",
),
MirSemanticsGuard(
guard_id="bytes_adt_owned_valid",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="recOwnedWalkV2 validates and alias-checks a payload enum's active variant",
anchor=" | vis, .adtEnum _ vs, .adtVal i p =>\n recOwnedWalkNthV2 m isMut heapRec self vis p i vs",
replacement=" | vis, .adtEnum _ _, .adtVal _ _ => .ok vis",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_owned_valid",
),
MirSemanticsGuard(
guard_id="enum_adt_nested_heap_handle",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="tyHasNestedHeapHandleV2 recurses into .adtEnum variants",
anchor=(
" | .tuple fs | .struct_ _ fs | .adtEnum _ fs =>\n"
" tyListHasNestedHeapHandleV2 fs"
),
replacement=(
" | .tuple fs | .struct_ _ fs =>\n"
" tyListHasNestedHeapHandleV2 fs"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_adt_nested_heap_handle",
),
MirSemanticsGuard(
guard_id="bytes_adt_nested_owned_spans",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="nestedOwnedWalkSpansV2 walks .adtEnum variants to collect depth>=2 heap spans",
anchor=" | .adtEnum _ vs, .adtVal i p =>\n nestedOwnedWalkSpansNthV2 m heapRec inHeap self p i vs",
replacement=" | .adtEnum _ _, _ => []",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_nested_owned_spans",
),
MirSemanticsGuard(
guard_id="bytes_adt_rec_handle_spans",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="ownedHandleWalkAccessSpans walks .adtEnum variants inside .recAdt binders",
anchor=" | .adtEnum _ vs, .adtVal i p =>\n ownedHandleWalkAccessSpansNth self p i vs",
replacement=" | .adtEnum _ _, _ => []",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_rec_handle_spans",
),
MirSemanticsGuard(
guard_id="bytes_adt_refs_valid",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refsValidInMem validates a payload enum as owned data",
anchor=(
" else\n"
" match ownedValidInMem m true (.adtEnum l vs) v with\n"
" | .ok () => true\n"
" | .error _ => false"
),
replacement=" else\n true",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_adt_owned_valid",
),
MirSemanticsGuard(
guard_id="step_v2_adt_downcast_variant",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="projectValFieldV2 faults on the field of a variant the value does not hold",
anchor=" if !Nat.beq vi w then\n .error .undefined",
replacement=" if false then\n .error .undefined",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_downcast_variant",
),
MirSemanticsGuard(
guard_id="step_v2_adt_mem_downcast_variant",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="projectMemoryPlaceV2 faults on the field of a variant the enum does not hold",
anchor=" if !Nat.beq w vi then\n .error .undefined",
replacement=" if false then\n .error .undefined",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_mem_downcast_variant",
),
MirSemanticsGuard(
guard_id="step_v2_adt_discriminant_uninit",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalAdtDiscriminantOfVal faults on an uninitialized enum",
anchor=" | none => .error .undefined\n | some (.adtVal i _) =>",
replacement=" | none =>\n .ok (.scalar ⟨l.discrWidth, l.discrSigned, 0⟩, locals, mem)\n | some (.adtVal i _) =>",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_discriminant",
),
MirSemanticsGuard(
guard_id="step_v2_adt_discriminant_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalAdtDiscriminantOfVal requires the enum's discriminant type as destination",
anchor=" if !MirTy.beq dstTy (.int l.discrWidth l.discrSigned) then",
replacement=" if false then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_discriminant",
),
MirSemanticsGuard(
guard_id="step_v2_adt_discriminant_deref",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalueV2 reads the discriminant of a projected payload enum",
anchor=(
" | .adtEnum l _ | .recAdt _ (.adtEnum l _) =>\n"
" evalAdtDiscriminantOfVal l dstTy optVal locals1 mem1"
),
replacement=(
" | .adtEnum l _ | .recAdt _ (.adtEnum l _) =>\n"
" evalAdtDiscriminantOfVal l dstTy (some (.adtVal 0 .unit)) locals1 mem1"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_discriminant_deref",
),
MirSemanticsGuard(
guard_id="step_v2_adt_aggregate_fields",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="an enum variant aggregate checks its operands against the variant's fields",
anchor=" if !typedArgsMatchV2 typedVals fieldTys ||\n !checkValV2List vals fieldTys then",
replacement=" if false then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_aggregate",
),
MirSemanticsGuard(
guard_id="step_v2_adt_aggregate_dst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="an enum variant aggregate requires the enum as destination type",
anchor=" if !MirTy.beq dstTy enumTy then",
replacement=" if false then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_aggregate",
),
MirSemanticsGuard(
guard_id="step_v2_fieldless_enum_aggregate_fields",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="a fieldless enum variant aggregate takes no operands",
anchor=(
" if !fields.isEmpty || !MirTy.beq dstTy enumTy || !enumAdmitted ety ||\n"
" !Nat.blt vi ety.discriminants.length then"
),
replacement=(
" if false || !MirTy.beq dstTy enumTy || !enumAdmitted ety ||\n"
" !Nat.blt vi ety.discriminants.length then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_fieldless_enum_aggregate",
),
MirSemanticsGuard(
guard_id="step_v2_fieldless_enum_aggregate_dst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="a fieldless enum variant aggregate requires the enum as destination type",
anchor=(
" if !fields.isEmpty || !MirTy.beq dstTy enumTy || !enumAdmitted ety ||\n"
" !Nat.blt vi ety.discriminants.length then"
),
replacement=(
" if !fields.isEmpty || false || !enumAdmitted ety ||\n"
" !Nat.blt vi ety.discriminants.length then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_fieldless_enum_aggregate",
),
MirSemanticsGuard(
guard_id="step_v2_fieldless_enum_aggregate_admitted",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="a fieldless enum variant aggregate requires an admitted enum",
anchor=(
" if !fields.isEmpty || !MirTy.beq dstTy enumTy || !enumAdmitted ety ||\n"
" !Nat.blt vi ety.discriminants.length then"
),
replacement=(
" if !fields.isEmpty || !MirTy.beq dstTy enumTy || false ||\n"
" !Nat.blt vi ety.discriminants.length then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_fieldless_enum_aggregate",
),
MirSemanticsGuard(
guard_id="step_v2_fieldless_enum_aggregate_variant",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="a fieldless enum variant aggregate requires an in-range variant",
anchor=(
" if !fields.isEmpty || !MirTy.beq dstTy enumTy || !enumAdmitted ety ||\n"
" !Nat.blt vi ety.discriminants.length then"
),
replacement=(
" if !fields.isEmpty || !MirTy.beq dstTy enumTy || !enumAdmitted ety ||\n"
" false then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_fieldless_enum_aggregate",
),
MirSemanticsGuard(
guard_id="step_v2_adt_mut_downcast_ref",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRefRvalueV2 refuses &mut through a payload enum downcast that "
"could change the variant"
),
anchor=(
" if Mutability.beq reqMut .mut &&\n"
" projsDowncastMutUnsafeV2 baseTy projs' then\n"
" .error .unsupported\n"
" else\n"
" match placeAddrV2 bodyLocals locals mem true place.localId projs' with"
),
replacement=(
" if false then\n"
" .error .unsupported\n"
" else\n"
" match placeAddrV2 bodyLocals locals mem true place.localId projs' with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_mut_downcast_ref",
),
MirSemanticsGuard(
guard_id="step_v2_adt_mut_downcast_raw",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalAddressOfRvalueV2 refuses &raw mut through a payload enum downcast",
anchor=(
" if Mutability.beq reqMut .mut &&\n"
" projsDowncastNonOptionV2 baseTy projs' then\n"
" .error .unsupported\n"
" else\n"
" match placeAddrV2 bodyLocals locals mem false place.localId projs' with"
),
replacement=(
" if false then\n"
" .error .unsupported\n"
" else\n"
" match placeAddrV2 bodyLocals locals mem false place.localId projs' with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_mut_downcast",
),
MirSemanticsGuard(
guard_id="step_v2_adt_mut_downcast_kind",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="projsDowncastNonOptionV2 flags a downcast of a non-Option type",
anchor=" | .option _ => projsDowncastNonOptionV2 ty rest\n | _ => true",
replacement=" | .option _ => projsDowncastNonOptionV2 ty rest\n | _ => false",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_mut_downcast",
),
MirSemanticsGuard(
guard_id="step_v2_ref_mut_downcast_direct_only",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"a &mut through a downcast is admitted only for a .direct enum"
),
anchor=(
" | .direct, some off, some ty' =>"
),
replacement=(
" | _, some off, some ty' =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_ref_mut_downcast",
),
MirSemanticsGuard(
guard_id="step_v2_ref_mut_downcast_off_tag",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"a &mut through a downcast is admitted only for a field outside the tag"
),
anchor=(
" | some lay => natSpanDisjointWith (off, lay.size) [adtTagSpanV2 l]"
),
replacement=(
" | some lay => true"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_ref_mut_downcast",
),
MirSemanticsGuard(
guard_id="step_v2_ref_mut_downcast_field_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"a &mut through a downcast checks the field at its recorded type"
),
anchor=(
" if !MirTy.beq ty' fTy then\n"
" false"
),
replacement=(
" if false then\n"
" false"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_ref_mut_downcast",
),
MirSemanticsGuard(
guard_id="step_v2_ref_mut_downcast_kind",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"a &mut through a bare non-Option downcast is flagged"
),
anchor=(
" | .option _ => projsDowncastMutUnsafeV2 ty rest\n"
" | _ => true"
),
replacement=(
" | .option _ => projsDowncastMutUnsafeV2 ty rest\n"
" | _ => false"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_ref_mut_downcast",
),
MirSemanticsGuard(
guard_id="step_v2_ref_mut_downcast_nested",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"a &mut through a downcast checks the downcasts inside the field"
),
anchor=(
" !adtDirectFieldOffTagV2 ty vi fi fTy || projsDowncastMutUnsafeV2 fTy rest"
),
replacement=(
" !adtDirectFieldOffTagV2 ty vi fi fTy"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_ref_mut_downcast",
),
MirSemanticsGuard(
guard_id="enum_rec_adt_head_enum_id",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"recAdtHeadOkV2 requires a recursive payload enum's layout id to be "
"its binder id"
),
anchor=" | .adtEnum l _ => Nat.beq l.id id",
replacement=" | .adtEnum _ _ => true",
fixture_module="StepRefutations",
theorem_name="refute_enum_rec_adt_head_enum_id",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="enum_adt_variants_rec_unfold",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"adtVariantsV2 gives a recursive payload enum the variants of its "
"unfolding, whose back edges are the closed binder"
),
anchor=" match unfoldRecV2 id defn with\n | .adtEnum _ vs => some vs",
replacement=" match defn with\n | .adtEnum _ vs => some vs",
fixture_module="StepRefutations",
theorem_name="refute_enum_adt_variants_rec_unfold",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_adt_rec_downcast",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"projectValFieldV2 downcasts a recursive payload enum through its "
"unfolding"
),
anchor=" match adtVariantsV2 ty with",
replacement=" match (match ty with | .adtEnum _ vs => some vs | _ => none) with",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_rec_downcast",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_adt_rec_mem_downcast",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"projectMemoryPlaceV2 downcasts a recursive payload enum in memory "
"through its unfolding"
),
anchor=" match adtVariantPayloadV2 eTy vi with",
replacement=(
" match (match eTy with | .adtEnum _ vs => getElem? vs vi | _ => none) with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_rec_downcast",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_adt_rec_discriminant",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="discriminant(x) of an immediate recursive payload enum local",
anchor=(
" | .adtEnum l _ | .recAdt _ (.adtEnum l _) =>\n"
" evalAdtDiscriminantOfVal l dstTy optVal locals mem"
),
replacement=(
" | .adtEnum l _ =>\n"
" evalAdtDiscriminantOfVal l dstTy optVal locals mem"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_rec_discriminant",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_adt_rec_discriminant_deref",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="discriminant(*r) of a recursive payload enum behind a reference",
anchor=(
" | .adtEnum l _ | .recAdt _ (.adtEnum l _) =>\n"
" evalAdtDiscriminantOfVal l dstTy optVal locals1 mem1"
),
replacement=(
" | .adtEnum l _ =>\n"
" evalAdtDiscriminantOfVal l dstTy optVal locals1 mem1"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_rec_discriminant",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_adt_rec_discriminant_indirect",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="discriminant(x) of an in-memory recursive payload enum local",
anchor=(
" | .adtEnum l _ | .recAdt _ (.adtEnum l _) =>\n"
" match loadIndirectV2 mem srcTy mplace with"
),
replacement=(
" | .adtEnum l _ =>\n"
" match loadIndirectV2 mem srcTy mplace with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_rec_discriminant",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_adt_rec_aggregate",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="aggregateAdtEnum builds a variant of a recursive payload enum",
anchor=" match adtVariantsV2 enumTy, layoutOfTyV2 enumTy with",
replacement=(
" match (match enumTy with | .adtEnum _ vs => some vs | _ => none),\n"
" layoutOfTyV2 enumTy with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_rec_aggregate",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_adt_move_downcast_no_heap",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readPlaceV2 refuses immediate payload-enum downcast moves when the "
"enum owns a heap handle (drop-elaboration discriminant check)"
),
anchor=(
" | .adtEnum _ vs, [.downcast vidx, .field 0 _], .immediate _ =>\n"
" if tyHasHeapHandleV2 baseTy then false"
),
replacement=(
" | .adtEnum _ vs, [.downcast vidx, .field 0 _], .immediate _ =>\n"
" if false then false"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_move_downcast_guards",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_adt_move_downcast_single_field_only",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readPlaceV2 refuses immediate payload-enum downcast moves on "
"multi-field variants whose sibling fields would be wiped"
),
anchor=(
" match getElem? vs vidx with\n"
" | some (.struct_ _ [_]) => true\n"
" | _ => false"
),
replacement=(
" match getElem? vs vidx with\n"
" | some (.struct_ _ _) => true\n"
" | _ => false"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_adt_move_downcast_guards",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="enum_rec_keys_plain_adt_enum",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"recAdtKeysV2 records a plain payload enum's layout id, so "
"recTysCoherentV2 rejects one reusing a binder id"
),
anchor=(
" | .adtEnum l vs =>\n"
" let r := recAdtKeysListV2 vs\n"
" (r.1, l.id :: r.2)"
),
replacement=(
" | .adtEnum l vs =>\n"
" let r := recAdtKeysListV2 vs\n"
" (r.1, r.2)"
),
fixture_module="StepRefutations",
theorem_name="refute_enum_rec_keys_plain_adt_enum",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_place_mention_reads_place",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalStatementV2 evaluates a projected PlaceMention as a read "
"instead of skipping it"
),
anchor=" match readPlaceV2 body.locals frame.locals mem false place with",
replacement=(
" match (Except.ok (MirTy.unit, none, frame.locals, mem) :\n"
" Except FaultKind (MirTy × Option Val × List LocalSlot × MemoryState)) with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_place_mention_dangling",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_place_mention_zst_deref",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalStatementV2 conservatively refuses a PlaceMention of a "
"zero-sized leaf behind a deref"
),
anchor=" if placeMentionZstDerefV2 place ty then",
replacement=" if false then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_place_mention_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_place_mention_zst_only",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"placeMentionZstDerefV2 refuses only a zero-sized leaf, so a valid "
"mention through a deref leaves the state unchanged"
),
anchor=" | some lay => Nat.beq lay.size 0",
replacement=" | some _ => true",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_place_mention_valid",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_adt_option_shape",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="adtOptionShapeV2 requires the Option<inner> variant shape",
anchor=" | [.struct_ _ [], .struct_ _ [t]] => MirTy.beq t inner",
replacement=" | [.struct_ _ [], .struct_ _ [_]] => true",
fixture_module="StepRefutations",
theorem_name="refute_core_adt_option_shape",
),
MirSemanticsGuard(
guard_id="step_v2_move_option_downcast_indirect",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readPlaceV2 refuses to move out of (x as Some).0 when the Option "
"local lives in memory (.indirect)"
),
anchor=" | .option _, [.downcast 1, .field 0 _], .immediate _ => true",
replacement=" | .option _, [.downcast 1, .field 0 _], _ => true",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_option_downcast_indirect",
),
MirSemanticsGuard(
guard_id="bytes_heap_buf_elems_decoded",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="heapBufValidInMem decodes every non-integer element's fields",
anchor=" sliceElemsValidV2 elem lay.size len.toNat initSlice",
replacement=" Except.ok ()",
fixture_module="BytesRefutations",
theorem_name="refute_bytes_heap_buf_elems_decoded",
),
MirSemanticsGuard(
guard_id="alloc_vec_grow_zst_pin",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="vecGrowCap pins a ZST capacity below isize::MAX (UsizeNoHighBit)",
anchor=(
" if Nat.blt minCap isizeMaxBytes then some (isizeMaxBytes - 1) else none"
),
replacement=" some minCap",
fixture_module="StepRefutations",
theorem_name="refute_alloc_vec_grow_zst_pin",
),
MirSemanticsGuard(
guard_id="alloc_vec_with_capacity_zero_bytes_cap",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="Vec::with_capacity stores capacity 0 when it allocates no bytes",
anchor=" .ok (.vec (danglingAligned lay.alignLog2) 0 0) m",
replacement=" .ok (.vec (danglingAligned lay.alignLog2) cap 0) m",
fixture_module="StepRefutations",
theorem_name="refute_alloc_vec_with_capacity_zero_bytes_cap",
),
MirSemanticsGuard(
guard_id="alloc_resize_data_only",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="evalVecResizeOutcome admits only data elements",
anchor=(
" if !isSupportedV2DataTy elem || !checkValV2 value elem then"
),
replacement=(
" if !checkValV2 value elem then"
),
fixture_module="StepRefutations",
theorem_name="refute_alloc_resize_data_only",
),
MirSemanticsGuard(
guard_id="alloc_extend_from_slice_data_only",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="evalVecExtendFromSliceOutcome admits only data elements",
anchor=(
" if !isSupportedV2DataTy elem then\n"
" .fault .unsupported\n"
" else\n"
" match readVecFromRef m true elem selfPtr,"
),
replacement=(
" if false then\n"
" .fault .unsupported\n"
" else\n"
" match readVecFromRef m true elem selfPtr,"
),
fixture_module="StepRefutations",
theorem_name="refute_alloc_extend_from_slice_data_only",
),
MirSemanticsGuard(
guard_id="alloc_box_clone_data_only",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="evalBoxClone admits only data pointees",
anchor=(
" if isUnsizedTy pt || !isSupportedV2DataTy pt then"
),
replacement=(
" if isUnsizedTy pt then"
),
fixture_module="StepRefutations",
theorem_name="refute_alloc_box_clone_data_only",
),
MirSemanticsGuard(
guard_id="alloc_box_clone_slice_data_only",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="evalBoxClone admits only data slice elements",
anchor=(
" if !isSupportedV2DataTy elem then\n"
" .error .unsupported\n"
" else\n"
" match layoutOfTyV2 elem with"
),
replacement=(
" if false then\n"
" .error .unsupported\n"
" else\n"
" match layoutOfTyV2 elem with"
),
fixture_module="StepRefutations",
theorem_name="refute_alloc_box_clone_slice_data_only",
),
MirSemanticsGuard(
guard_id="state_v2_vec_counts_as_ref",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="tyHasRefV2 counts a Vec as a reference for the no-mix rule",
anchor=(
" | .vec _ => true\n"
),
replacement=(
" | .vec elem => tyHasRefV2 elem\n"
),
fixture_module="StepRefutations",
theorem_name="refute_state_v2_vec_counts_as_ref",
),
MirSemanticsGuard(
guard_id="layout_v2_struct_overlap",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="layoutOfArrayV2 rejects struct layouts with overlapping fields",
anchor=(
" Nat.beq (Nat.mod l.size (Nat.pow 2 l.alignLog2)) 0 &&\n"
" natSpansPairwiseDisjoint spans then"
),
replacement=(
" Nat.beq (Nat.mod l.size (Nat.pow 2 l.alignLog2)) 0 &&\n"
" true then"
),
fixture_module="LayoutRefutations",
theorem_name="refute_layout_v2_struct_overlap",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_v2_struct_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="structFieldSpansV2 rejects misaligned struct field offsets",
anchor=(
" if Nat.ble (off + lay.size) size && Nat.ble lay.alignLog2 alignLog2 &&\n"
" Nat.beq (Nat.mod off (Nat.pow 2 lay.alignLog2)) 0 then"
),
replacement=(
" if Nat.ble (off + lay.size) size && Nat.ble lay.alignLog2 alignLog2 &&\n"
" true then"
),
fixture_module="LayoutRefutations",
theorem_name="refute_layout_v2_struct_misaligned",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_v2_struct_align_max",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="layoutOfArrayV2 rejects struct layouts with alignLog2 > 29 (Align::MAX)",
anchor=(
" if Nat.blt l.size structSizeBound &&\n"
" Nat.ble l.alignLog2 29 &&\n"
" Nat.beq (Nat.mod l.size (Nat.pow 2 l.alignLog2)) 0 &&"
),
replacement=(
" if Nat.blt l.size structSizeBound &&\n"
" true &&\n"
" Nat.beq (Nat.mod l.size (Nat.pow 2 l.alignLog2)) 0 &&"
),
fixture_module="LayoutRefutations",
theorem_name="refute_layout_v2_struct_align_max",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_adt_align_max",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description="adtEnumHeadWfV2 rejects payload enum layouts with alignLog2 > 29 (Align::MAX)",
anchor=(
" Nat.blt l.size structSizeBound &&\n"
" Nat.ble l.alignLog2 29 &&\n"
" Nat.beq (Nat.mod l.size (Nat.pow 2 l.alignLog2)) 0 &&"
),
replacement=(
" Nat.blt l.size structSizeBound &&\n"
" true &&\n"
" Nat.beq (Nat.mod l.size (Nat.pow 2 l.alignLog2)) 0 &&"
),
fixture_module="LayoutRefutations",
theorem_name="refute_layout_adt_align_max",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_index_dead_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="ProjectionElem.index through a dead usize local faults UB",
anchor=" | some (.int .isize false), some .dead => .error .undefined",
replacement=" | some (.int .isize false), some .dead => .ok 0",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_index_dead_local",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_index_uninit_local",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="ProjectionElem.index through an uninitialized usize local faults UB",
anchor=" | some (.int .isize false), some (.immediate none) => .error .undefined",
replacement=" | some (.int .isize false), some (.immediate none) => .ok 0",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_index_uninit_local",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_return_to_caller_dangling",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalReturnToCallerV2 rejects returning a reference into the popped "
"callee frame as UB"
),
anchor=(
" if !refsValidInMem mem1 retTy retVal ||\n"
" !spansPairwiseDisjoint (valueAccessSpans mem1 retTy retVal) then\n"
" .fault .undefined"
),
replacement=(
" if false ||\n"
" !spansPairwiseDisjoint (valueAccessSpans mem1 retTy retVal) then\n"
" .fault .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_return_to_caller_dangling",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_arg_invalid_ref",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalCallV2 rejects invalid reference arguments as UB",
anchor=(
" else if !refsValidInMemList mem1 paramTys argVals ||\n"
" !spansPairwiseDisjoint\n"
" (valueAccessSpansList mem1 paramTys argVals) then\n"
" .fault .undefined"
),
replacement=(
" else if false ||\n"
" !spansPairwiseDisjoint\n"
" (valueAccessSpansList mem1 paramTys argVals) then\n"
" .fault .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_arg_invalid_ref",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_dead_destination",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallV2 faults UB on a dead call destination before pushing "
"the callee frame"
),
anchor=(
" | some .dead => .fault .undefined\n"
" | some _ =>\n"
" let argVals := argValues typedArgs"
),
replacement=(
" | some _ =>\n"
" let argVals := argValues typedArgs"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_dead_destination",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_unsafe_callee",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"bodyCallAdmittedV2 refuses intra-crate calls to unsafe callees"
),
anchor=(
"noncomputable def bodyCallAdmittedV2 (callee : Body) : Bool :=\n"
" !callee.isExternal &&\n"
" !callee.isUnsafe &&"
),
replacement=(
"noncomputable def bodyCallAdmittedV2 (callee : Body) : Bool :=\n"
" !callee.isExternal &&\n"
" true &&"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_unsafe_callee",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_moves_disjoint",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallV2 refuses calls whose move arguments and destination "
"are not definitely disjoint"
),
anchor=" if !moveDefinitelyDisjoint args dst then",
replacement=" if false then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_moves_disjoint",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_arg_move_indirect",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallV2 refuses to move an in-memory local into a call, which "
"upstream passes in place and protects"
),
anchor=(
" | .move place => localIsIndirectV2 locals place.localId\n"
),
replacement=" | .move place => false\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_arg_move_indirect",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_arg_copy_indirect",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallV2 refuses to copy an in-memory local into a call that "
"also moves an argument"
),
anchor=(
" | .copy place => hasMove && localIsIndirectV2 locals "
"place.localId\n"
),
replacement=" | .copy place => false\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_arg_copy_indirect",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_dst_indirect",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallV2 refuses a call whose destination lives in memory, "
"which upstream protects"
),
anchor=(
" if !moveDefinitelyDisjoint args dst then\n"
" .fault .unsupported\n"
" else if callInPlaceArgsV2 frame.locals args then\n"
" .fault .unsupported\n"
" else if localIsIndirectV2 frame.locals dst.localId then\n"
),
replacement=(
" if !moveDefinitelyDisjoint args dst then\n"
" .fault .unsupported\n"
" else if callInPlaceArgsV2 frame.locals args then\n"
" .fault .unsupported\n"
" else if false then\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_dst_indirect",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_wellformed_forbids_faults",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="WellFormedV2 forbids reachable faults",
anchor=" (∀ k : FaultKind, ¬ ReachesResultV2 p q (.fault k))",
replacement=" True",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_wellformed_forbids_faults",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_safe_fn_ignores_safety_pre",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="BodyVerifiedV2 ignores safetyPre for safe functions",
anchor=" (body.isUnsafe = true → safetyPre q) →",
replacement=" safetyPre q →",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_safe_fn_ignores_safety_pre",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_body_static_admitted",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="BodyVerifiedV2 requires BodyStaticAdmittedV2 unconditionally",
anchor=(
" BodyStaticAdmittedV2 p body = true ∧\n"
" ∀ q : Query,\n"
" ValidEntryArgsV2 body q →\n"
" (body.isUnsafe = true → safetyPre q) →"
),
replacement=(
" True ∧\n"
" ∀ q : Query,\n"
" ValidEntryArgsV2 body q →\n"
" (body.isUnsafe = true → safetyPre q) →"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_body_static_admitted",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_rejects_mixed_refs_and_raw_ptrs",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="BodyStaticAdmittedV2 rejects bodies mixing refs and raw pointers",
anchor=(
" assertConditionTypesValid body &&\n"
" !bodyMixesRefsAndRawPtrsV2 body &&"
),
replacement=(
" assertConditionTypesValid body &&\n"
" true &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_rejects_mixed_refs_and_raw_ptrs",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_effect_mask_allow_abort_default",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="EffectMaskV2 defaults allowAbort to false",
anchor=(
"structure EffectMaskV2 where\n"
" allowAbort : Bool := false"
),
replacement=(
"structure EffectMaskV2 where\n"
" allowAbort : Bool := true"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_effect_mask_allow_abort_default",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_safe_contract_allow_abort_default",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="SafeContractV2 defaults effects.allowAbort to false",
anchor=(
" behaviorPre : Query → Prop := fun _ => True\n"
" effects : EffectMaskV2 := { allowAbort := false }"
),
replacement=(
" behaviorPre : Query → Prop := fun _ => True\n"
" effects : EffectMaskV2 := { allowAbort := true }"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_safe_contract_allow_abort_default",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_safe_contract_post_abort_default",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="SafeContractV2 defaults postAbort to False",
anchor=(
" postReturn : Query → Out → Prop := fun _ _ => True\n"
" postAbort : Query → CallerMemory → Prop := fun _ _ => False"
),
replacement=(
" postReturn : Query → Out → Prop := fun _ _ => True\n"
" postAbort : Query → CallerMemory → Prop := fun _ _ => True"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_safe_contract_post_abort_default",
needs_wf_helper=False,
),
# ------------------------------------------------------------------
# Additional Profile v2 silent-saturation, aliasing, negative-offset,
# slice/thin-ref validity, and provenance-free deref guards (69 guards)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="mem_v2_slice_get_unchecked_inverted",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"sliceGetUncheckedCheck rejects inverted range startOff > endOff "
"as UB rather than saturating subtraction"
),
anchor=(
" (len startOff endOff : Nat) (elemSize : Nat := 1) : Except FaultKind Val :=\n"
" if !Nat.ble startOff endOff || !Nat.ble endOff len then\n"
" .error .undefined"
),
replacement=(
" (len startOff endOff : Nat) (elemSize : Nat := 1) : Except FaultKind Val :=\n"
" if false || !Nat.ble endOff len then\n"
" .error .undefined"
),
fixture_module="ProfileV2MemoryRefutations",
theorem_name="refute_mem_v2_slice_get_unchecked_inverted",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_ptr_add_dead_alloc",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description="ptrAddInMem rejects offset on a deallocated allocation as UB",
anchor=(
" | some a =>\n"
" if !a.live || !Nat.ble (p.offsetBytes.toNat + delta) a.bytes.length then\n"
" .error .undefined"
),
replacement=(
" | some a =>\n"
" if false || !Nat.ble (p.offsetBytes.toNat + delta) a.bytes.length then\n"
" .error .undefined"
),
fixture_module="ProfileV2MemoryRefutations",
theorem_name="refute_mem_v2_ptr_add_dead_alloc",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_no_prov_nonempty",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"sliceFromRawPartsCheck rejects non-empty slice backed by a "
"provenance-free pointer as UB"
),
anchor=(
" | none =>\n"
" if Nat.beq p.offsetBytes.toNat 0 || Nat.blt 0 totalBytes then\n"
" .error .undefined"
),
replacement=(
" | none =>\n"
" if Nat.beq p.offsetBytes.toNat 0 || false then\n"
" .error .undefined"
),
fixture_module="ProfileV2MemoryRefutations",
theorem_name="refute_mem_v2_slice_no_prov_nonempty",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_no_prov_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"sliceFromRawPartsCheck rejects misaligned zero-length slice "
"backed by a provenance-free pointer as UB"
),
anchor=(
" else if !Nat.beq\n"
" (Nat.mod p.offsetBytes.toNat (Nat.pow 2 elemAlignLog2)) 0 then\n"
" .error .undefined\n"
" else\n"
" .ok none"
),
replacement=(
" else if false then\n"
" .error .undefined\n"
" else\n"
" .ok none"
),
fixture_module="ProfileV2MemoryRefutations",
theorem_name="refute_mem_v2_slice_no_prov_misaligned",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_dead_alloc",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"sliceFromRawPartsCheck rejects a slice into a deallocated "
"allocation as UB"
),
anchor=(
" if !a.live || !isInBounds a p.offsetBytes.toNat totalBytes ||\n"
" !isAligned a p.offsetBytes.toNat elemAlignLog2 then\n"
" .error .undefined"
),
replacement=(
" if false || !isInBounds a p.offsetBytes.toNat totalBytes ||\n"
" !isAligned a p.offsetBytes.toNat elemAlignLog2 then\n"
" .error .undefined"
),
fixture_module="ProfileV2MemoryRefutations",
theorem_name="refute_mem_v2_slice_dead_alloc",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_oob",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"sliceFromRawPartsCheck rejects out-of-bounds slice length as UB "
"instead of allowing List.take truncation"
),
anchor=(
" if !a.live || !isInBounds a p.offsetBytes.toNat totalBytes ||\n"
" !isAligned a p.offsetBytes.toNat elemAlignLog2 then\n"
" .error .undefined"
),
replacement=(
" if !a.live || false ||\n"
" !isAligned a p.offsetBytes.toNat elemAlignLog2 then\n"
" .error .undefined"
),
fixture_module="ProfileV2MemoryRefutations",
theorem_name="refute_mem_v2_slice_oob",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="mem_v2_slice_misaligned",
target_file="trusted/lean/Trusted/MirSemantics/Memory.lean",
target_module="Trusted/MirSemantics/Memory",
description=(
"sliceFromRawPartsCheck rejects misaligned provenance-bearing "
"slice as UB"
),
anchor=(
" if !a.live || !isInBounds a p.offsetBytes.toNat totalBytes ||\n"
" !isAligned a p.offsetBytes.toNat elemAlignLog2 then\n"
" .error .undefined"
),
replacement=(
" if !a.live || !isInBounds a p.offsetBytes.toNat totalBytes ||\n"
" false then\n"
" .error .undefined"
),
fixture_module="ProfileV2MemoryRefutations",
theorem_name="refute_mem_v2_slice_misaligned",
sanity_module="MemorySanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_span_disjoint_overlap",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="spanDisjoint rejects overlapping mutable byte spans",
anchor=(
" if !(m1 || m2) || Nat.beq n1 0 || Nat.beq n2 0 || !Nat.beq id1 id2 then\n"
" true\n"
" else\n"
" Nat.ble (s1 + n1) s2 || Nat.ble (s2 + n2) s1"
),
replacement=(
" if !(m1 || m2) || Nat.beq n1 0 || Nat.beq n2 0 || !Nat.beq id1 id2 then\n"
" true\n"
" else\n"
" true"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_bytes_v2_span_disjoint_overlap",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_span_disjoint_mut_vs_shared",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="spanDisjoint rejects &mut overlapping & (not only &mut vs &mut)",
anchor=(
" if !(m1 || m2) || Nat.beq n1 0 || Nat.beq n2 0 || !Nat.beq id1 id2 then\n"
" true\n"
" else\n"
" Nat.ble (s1 + n1) s2 || Nat.ble (s2 + n2) s1"
),
replacement=(
" if !(m1 && m2) || Nat.beq n1 0 || Nat.beq n2 0 || !Nat.beq id1 id2 then\n"
" true\n"
" else\n"
" Nat.ble (s1 + n1) s2 || Nat.ble (s2 + n2) s1"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_bytes_v2_span_disjoint_mut_vs_shared",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_null_zst",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refValidInMem rejects null thin reference even for ZST pointee",
anchor=(
" | none =>\n"
" if Nat.beq p.offsetBytes.toNat 0 || Nat.blt 0 lay.size then\n"
" .error .undefined"
),
replacement=(
" | none =>\n"
" if false || Nat.blt 0 lay.size then\n"
" .error .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_bytes_v2_ref_valid_null_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_readonly_mut",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refValidInMem rejects non-zero-sized thin &mut T into a .shared "
"allocation as UB"
),
anchor=(
" else if Mutability.beq reqMut .mut && Nat.blt 0 lay.size &&\n"
" !Mutability.beq a.mutability .mut then\n"
" .error .undefined"
),
replacement=(
" else if false then\n"
" .error .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_bytes_v2_ref_valid_readonly_mut",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_readonly_zst",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refValidInMem accepts zero-sized thin &mut T into a .shared "
".rodata allocation"
),
anchor=(
" else if Mutability.beq reqMut .mut && Nat.blt 0 lay.size &&\n"
" !Mutability.beq a.mutability .mut then\n"
" .error .undefined"
),
replacement=(
" else if Mutability.beq reqMut .mut && true &&\n"
" !Mutability.beq a.mutability .mut then\n"
" .error .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_bytes_v2_ref_valid_readonly_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_uninit_pointee",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refValidInMem rejects thin reference to uninitialized pointee as UB",
anchor=(
" | .ok none => .error .undefined\n"
" | .error k => .error k\n"
" | _, _ => .error .unsupported"
),
replacement=(
" | .ok none => .ok ()\n"
" | .error k => .error k\n"
" | _, _ => .error .unsupported"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_bytes_v2_ref_valid_uninit_pointee",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_array_elem_layout",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"encodeValV2 refuses arrays whose element type has no layoutOfTyV2"
),
anchor=(
" if !(layoutOfTyV2 elem).isSome || !Nat.beq vs.length len then\n"
),
replacement=" if !Nat.beq vs.length len then\n",
fixture_module="ProfileV2Refutations",
theorem_name="refute_bytes_v2_array_elem_layout",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="state_v2_init_invalid_entry_ref",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initStateV2 rejects invalid entry reference arguments as UB",
anchor=(
" if !refsValidInMemList entryMem paramTys q.args ||\n"
" !spansPairwiseDisjoint\n"
" (valueAccessSpansList entryMem paramTys q.args) then\n"
" .error .undefined"
),
replacement=(
" if false ||\n"
" !spansPairwiseDisjoint\n"
" (valueAccessSpansList entryMem paramTys q.args) then\n"
" .error .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_state_v2_init_invalid_entry_ref",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="state_v2_init_aliased_entry_refs",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="initStateV2 rejects overlapping mutable entry references as UB",
anchor=(
" if !refsValidInMemList entryMem paramTys q.args ||\n"
" !spansPairwiseDisjoint\n"
" (valueAccessSpansList entryMem paramTys q.args) then\n"
" .error .undefined"
),
replacement=(
" if !refsValidInMemList entryMem paramTys q.args ||\n"
" false then\n"
" .error .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_state_v2_init_aliased_entry_refs",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_usize_unchecked_sub_underflow",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"execCoreCallOp .usizeUncheckedSub rejects rhs > lhs as UB rather "
"than saturating Nat subtraction to 0"
),
anchor=(
" else if !Nat.ble rSv.bits.toNat lSv.bits.toNat then\n"
" .error .undefined"
),
replacement=(
" else if false then\n"
" .error .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_step_v2_usize_unchecked_sub_underflow",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_ptr_offset_neg_underflow",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalPtrOffsetV2 rejects negative offset before byte 0 as UB "
"rather than saturating Nat subtraction to 0"
),
anchor=(
" if !a.live || !Nat.ble p.offsetBytes.toNat a.bytes.length ||\n"
" !Nat.ble delta p.offsetBytes.toNat then\n"
" .error .undefined"
),
replacement=(
" if !a.live || !Nat.ble p.offsetBytes.toNat a.bytes.length ||\n"
" false then\n"
" .error .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_step_v2_ptr_offset_neg_underflow",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_ptr_offset_neg_start_oob",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalPtrOffsetV2 rejects negative offset starting past end of "
"allocation as UB"
),
anchor=(
" if !a.live || !Nat.ble p.offsetBytes.toNat a.bytes.length ||\n"
" !Nat.ble delta p.offsetBytes.toNat then\n"
" .error .undefined"
),
replacement=(
" if !a.live || false ||\n"
" !Nat.ble delta p.offsetBytes.toNat then\n"
" .error .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_step_v2_ptr_offset_neg_start_oob",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_ptr_offset_neg_null",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalPtrOffsetV2 rejects negative offset on provenance-free pointer as UB",
anchor=(
" match p.allocId with\n"
" | none => .error .undefined\n"
" | some aid =>"
),
replacement=(
" match p.allocId with\n"
" | none => .ok (.ptr p)\n"
" | some aid =>"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_step_v2_ptr_offset_neg_null",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_ptr_offset_neg_dead_alloc",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalPtrOffsetV2 rejects negative offset on dead allocation as UB",
anchor=(
" if !a.live || !Nat.ble p.offsetBytes.toNat a.bytes.length ||\n"
" !Nat.ble delta p.offsetBytes.toNat then\n"
" .error .undefined"
),
replacement=(
" if false || !Nat.ble p.offsetBytes.toNat a.bytes.length ||\n"
" !Nat.ble delta p.offsetBytes.toNat then\n"
" .error .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_step_v2_ptr_offset_neg_dead_alloc",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_return_aliased_mut_refs",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 .return_ rejects returning overlapping mutable "
"reference spans as UB"
),
anchor=(
" else if !refsStayInCallerMem callerMem retTy retVal ||\n"
" !refsValidInMem mem retTy retVal ||\n"
" !spansPairwiseDisjoint (valueAccessSpans mem retTy retVal) then\n"
" .fault .undefined"
),
replacement=(
" else if !refsStayInCallerMem callerMem retTy retVal ||\n"
" !refsValidInMem mem retTy retVal ||\n"
" false then\n"
" .fault .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_step_v2_return_aliased_mut_refs",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_return_invalid_ref",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 .return_ rejects returning a reference to an "
"invalid pointee in caller memory as UB"
),
anchor=(
" else if !refsStayInCallerMem callerMem retTy retVal ||\n"
" !refsValidInMem mem retTy retVal ||\n"
" !spansPairwiseDisjoint (valueAccessSpans mem retTy retVal) then\n"
" .fault .undefined"
),
replacement=(
" else if !refsStayInCallerMem callerMem retTy retVal ||\n"
" false ||\n"
" !spansPairwiseDisjoint (valueAccessSpans mem retTy retVal) then\n"
" .fault .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_step_v2_return_invalid_ref",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_use_retag_invalid_ref",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalueV2 .useRetag rejects invalid reference operands as UB",
anchor=(
" if !refsValidInMem mem1 srcTy v then\n"
" .error .undefined"
),
replacement=(
" if false then\n"
" .error .undefined"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_step_v2_use_retag_invalid_ref",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_read_no_prov_non_zst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readPlaceV2 rejects dereference read of non-ZST through a "
"provenance-free pointer as UB"
),
anchor=(
" | none =>\n"
" if Nat.beq pv.offsetBytes.toNat 0 || Nat.blt 0 lay.size ||\n"
" !Nat.beq (Nat.mod pv.offsetBytes.toNat (Nat.pow 2 lay.alignLog2)) 0 then\n"
" .error .undefined\n"
" else\n"
" match decodeValV2 profileV2TargetEndian pt [] with"
),
replacement=(
" | none =>\n"
" if Nat.beq pv.offsetBytes.toNat 0 || false ||\n"
" !Nat.beq (Nat.mod pv.offsetBytes.toNat (Nat.pow 2 lay.alignLog2)) 0 then\n"
" .error .undefined\n"
" else\n"
" match decodeValV2 profileV2TargetEndian pt [] with"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_step_v2_read_no_prov_non_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_write_no_prov_non_zst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"writePlaceDestV2 rejects dereference store of non-ZST through a "
"provenance-free pointer as UB"
),
anchor=(
" | none =>\n"
" if Nat.beq pv.offsetBytes.toNat 0 || Nat.blt 0 lay.size ||\n"
" !Nat.beq (Nat.mod pv.offsetBytes.toNat (Nat.pow 2 lay.alignLog2)) 0 then\n"
" .error .undefined\n"
" else\n"
" match encodeValV2 profileV2TargetEndian pt val with"
),
replacement=(
" | none =>\n"
" if Nat.beq pv.offsetBytes.toNat 0 || false ||\n"
" !Nat.beq (Nat.mod pv.offsetBytes.toNat (Nat.pow 2 lay.alignLog2)) 0 then\n"
" .error .undefined\n"
" else\n"
" match encodeValV2 profileV2TargetEndian pt val with"
),
fixture_module="ProfileV2Refutations",
theorem_name="refute_step_v2_write_no_prov_non_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_forbids_arg_or_ret",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="isFakePtrMetadataLocalV2 rejects return place _0 and caller parameters",
anchor=(
"noncomputable def isFakePtrMetadataLocalV2 (body : Body)\n"
" (lid : LocalId) : Bool :=\n"
" Nat.blt body.argumentCount lid &&"
),
replacement=(
"noncomputable def isFakePtrMetadataLocalV2 (body : Body)\n"
" (lid : LocalId) : Bool :=\n"
" true &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_forbids_arg_or_ret",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_requires_fake_assign",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="isFakePtrMetadataLocalV2 requires at least one .fakeAddressOf assignment",
anchor=(
" body.basicBlocks.any (fun bb =>\n"
" bb.statements.any (stmtAssignsFakeAddressOfToV2 lid)) &&"
),
replacement=" true &&",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_requires_fake_assign",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_forbids_non_metadata_use",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description=(
"stmtRespectsFakePtrMetadataLocalV2 rejects non-PtrMetadata reads "
"or dereferences of fake metadata locals"
),
anchor=(
" else if rvalueMentionsLocalV2 lid rv then\n"
" match rv with"
),
replacement=(
" else if false then\n"
" match rv with"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_forbids_non_metadata_use",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_forbids_self_assign",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description=(
"fakeAddressOfTypesMatchV2 rejects self-referential "
".fakeAddressOf (*_lid) assignments"
),
anchor=(
"noncomputable def fakeAddressOfTypesMatchV2 (locals : List MirTy)\n"
" (dstId : LocalId) (src : Place) : Bool :=\n"
" !Nat.beq src.localId dstId &&"
),
replacement=(
"noncomputable def fakeAddressOfTypesMatchV2 (locals : List MirTy)\n"
" (dstId : LocalId) (src : Place) : Bool :=\n"
" true &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_forbids_self_assign",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_forbids_overflow_pair",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description=(
"fakeAddressOfTypesMatchV2 rejects overflow-pair pointee types"
),
anchor=" !isOverflowPairTy pt && MirTy.beq dstTy (.rawPtr .shared pt)",
replacement=" true && MirTy.beq dstTy (.rawPtr .shared pt)",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_forbids_overflow_pair",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_requires_matching_pointee",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description=(
"fakeAddressOfTypesMatchV2 requires destination *const T pointee "
"to match base pointee"
),
anchor=" !isOverflowPairTy pt && MirTy.beq dstTy (.rawPtr .shared pt)",
replacement=" !isOverflowPairTy pt && true",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_requires_matching_pointee",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_forbids_projected_dst",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description=(
"stmtRespectsFakePtrMetadataLocalV2 rejects projected assignments "
"through a fake-metadata local"
),
anchor=(
" if placeMentionsLocalV2 lid dst then\n"
" dst.projection.isEmpty &&\n"
" match rv with"
),
replacement=(
" if placeMentionsLocalV2 lid dst then\n"
" true &&\n"
" match rv with"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_forbids_projected_dst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_forbids_projected_ptr_meta_operand",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description=(
"stmtRespectsFakePtrMetadataLocalV2 requires .ptrMetadata operands "
"on fake-metadata locals to have empty projections"
),
anchor=" | .copy p | .move p => Nat.beq p.localId lid && p.projection.isEmpty",
replacement=" | .copy p | .move p => Nat.beq p.localId lid && true",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_forbids_projected_ptr_meta_operand",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_forbids_terminator_use",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description=(
"isFakePtrMetadataLocalV2 rejects fake-metadata locals mentioned "
"by any terminator (e.g. coreCall args or dst)"
),
anchor=(
" bb.statements.all\n"
" (stmtRespectsFakePtrMetadataLocalV2 body.locals lid) &&\n"
" !terminatorMentionsLocalV2 lid bb.terminator)"
),
replacement=(
" bb.statements.all\n"
" (stmtRespectsFakePtrMetadataLocalV2 body.locals lid) &&\n"
" true)"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_forbids_terminator_use",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_adt_enum_operand",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description=(
"rvalueMentionsLocalV2 sees a fake metadata local read by a "
"payload enum aggregate operand"
),
anchor=(
" | .aggregateTuple ops | .aggregateArray _ ops | .aggregateStruct _ ops\n"
" | .aggregateAdtEnum _ _ ops =>\n"
" operandListMentionsLocalV2 lid ops\n"
" | .unsupported => false"
),
replacement=(
" | .aggregateTuple ops | .aggregateArray _ ops | .aggregateStruct _ ops =>\n"
" operandListMentionsLocalV2 lid ops\n"
" | .aggregateAdtEnum _ _ _ | .unsupported => false"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_adt_enum_operand",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_fake_ptr_metadata_forbids_place_mention",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description=(
"stmtRespectsFakePtrMetadataLocalV2 rejects a PlaceMention of a "
"fake metadata local"
),
anchor=" | .placeMention p => !placeMentionsLocalV2 lid p\n",
replacement=" | .placeMention _ => true\n",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_fake_ptr_metadata_forbids_place_mention",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_body_fake_address_of_valid",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description=(
"BodyStaticAdmittedV2 requires bodyFakeAddressOfValidV2 even on "
"raw-pointer-only bodies"
),
anchor=(
" !bodyMixesRefsAndRawPtrsV2 body &&\n"
" bodyFakeAddressOfValidV2 body &&"
),
replacement=(
" !bodyMixesRefsAndRawPtrsV2 body &&\n"
" true &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_body_fake_address_of_valid",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_fake_address_of_ref_validity",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalFakeAddressOfRvalueV2 enforces refValidInMem on reference "
"base locals"
),
anchor=(
" match readSlot with\n"
" | .error k => .error k\n"
" | .ok none => .error .undefined\n"
" | .ok (some v) =>\n"
" match refValidInMem mem srcMut pt v with\n"
" | .error k => .error k\n"
" | .ok () => .ok (v, locals, mem)"
),
replacement=(
" match readSlot with\n"
" | .error k => .error k\n"
" | .ok none => .error .undefined\n"
" | .ok (some v) => .ok (v, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_fake_address_of_ref_validity",
),
MirSemanticsGuard(
guard_id="core_contracts_option_unwrap_refs_valid",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execCoreContractOpOutcome .optionUnwrap validates unwrapped "
"Option<&T> "
"reference payloads via refsValidInMem"
),
anchor=(
" | some v =>\n"
" if !refsValidInMem m inner v then\n"
" .fault .undefined\n"
" else\n"
" .ok v m"
),
replacement=(
" | some v =>\n"
" if false then\n"
" .fault .undefined\n"
" else\n"
" .ok v m"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_option_unwrap_refs_valid",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_mem_replace_readonly_zst",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execMemReplace accepts a zero-sized pointee in a .shared .rodata "
"allocation (Nat.blt 0 lay.size)"
),
anchor=(
" if !a.live || (Nat.blt 0 lay.size &&\n"
" !Mutability.beq a.mutability .mut) then\n"
" .error .undefined"
),
replacement=(
" if !a.live || (true &&\n"
" !Mutability.beq a.mutability .mut) then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_mem_replace_readonly_zst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_option_discriminant_dst_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 .discriminant on projected Option checks dstTy is "
"isize"
),
anchor=(
" | .option _ =>\n"
" if !MirTy.beq dstTy (.int .isize true) then\n"
" .error .unsupported\n"
" else\n"
" evalOptionDiscriminantOfVal optVal locals1 mem1"
),
replacement=(
" | .option _ =>\n"
" if false then\n"
" .error .unsupported\n"
" else\n"
" evalOptionDiscriminantOfVal optVal locals1 mem1"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_option_discriminant_dst_ty",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_next_power_of_two_overflow_trap",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execNextPowerOfTwo traps via corePanicTrap when self exceeds "
"2^(BITS - 1)"
),
anchor=(
" if Nat.blt (Nat.pow 2 (w.bitWidth - 1)) bits then\n"
" .error corePanicTrap"
),
replacement=(
" if false then\n"
" .error corePanicTrap"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_next_power_of_two_overflow_trap",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_next_multiple_of_div_zero_trap",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="execNextMultipleOf traps via corePanicTrap when rhs is 0",
anchor=(
" if Nat.beq r 0 then\n"
" .error corePanicTrap"
),
replacement=(
" if false then\n"
" .error corePanicTrap"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_next_multiple_of_div_zero_trap",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_next_multiple_of_overflow_trap",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execNextMultipleOf traps via corePanicTrap when the rounded "
"result overflows w.bitWidth"
),
anchor=(
" if Nat.ble (Nat.pow 2 w.bitWidth) res then\n"
" .error corePanicTrap"
),
replacement=(
" if false then\n"
" .error corePanicTrap"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_next_multiple_of_overflow_trap",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_next_power_of_two_unsigned_only",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execCoreContractOpOutcome rejects signed operands on .numNextPowerOfTwo "
"as .unsupported"
),
anchor=(
" | .numNextPowerOfTwo w s, [(.int lw ls, .scalar lSv)] =>\n"
" if s || ls || !IntWidth.beq w lw || !MirTy.beq dstTy (.int w false) then"
),
replacement=(
" | .numNextPowerOfTwo w s, [(.int lw ls, .scalar lSv)] =>\n"
" if false || !IntWidth.beq w lw || !MirTy.beq dstTy (.int w false) then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_next_power_of_two_unsigned_only",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_next_multiple_of_unsigned_only",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execCoreContractOpOutcome rejects signed operands on .numNextMultipleOf "
"as .unsupported"
),
anchor=(
" | .numNextMultipleOf w s,\n"
" [(.int lw ls, .scalar lSv), (.int rw rs, .scalar rSv)] =>\n"
" if s || ls || rs || !IntWidth.beq w lw || !IntWidth.beq w rw ||"
),
replacement=(
" | .numNextMultipleOf w s,\n"
" [(.int lw ls, .scalar lSv), (.int rw rs, .scalar rSv)] =>\n"
" if false || !IntWidth.beq w lw || !IntWidth.beq w rw ||"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_next_multiple_of_unsigned_only",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_cmp_min_tie_break",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="Ord::min returns self (lSv) when both operands decode equal",
anchor=" else if decide (decodeScalar lSv ≤ decodeScalar rSv) then",
replacement=" else if decide (decodeScalar lSv < decodeScalar rSv) then",
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_cmp_min_tie_break",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_cmp_max_tie_break",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="Ord::max returns other (rSv) when both operands decode equal",
anchor=" else if decide (decodeScalar rSv < decodeScalar lSv) then",
replacement=" else if decide (decodeScalar rSv ≤ decodeScalar lSv) then",
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_cmp_max_tie_break",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_div_ceil_div_zero_trap",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="execCoreContractOpOutcome .numDivCeil traps via corePanicTrap when rhs = 0",
anchor=(
" if Nat.beq r 0 then\n"
" .error corePanicTrap\n"
" else\n"
" let d := Nat.div l r"
),
replacement=(
" if false then\n"
" .error corePanicTrap\n"
" else\n"
" let d := Nat.div l r"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_div_ceil_div_zero_trap",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_div_ceil_unsigned_only",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execCoreContractOpOutcome rejects signed operands on .numDivCeil as "
".unsupported"
),
anchor=(
" | .numDivCeil w s,\n"
" [(.int lw ls, .scalar lSv), (.int rw rs, .scalar rSv)] =>\n"
" if s || ls || rs || !IntWidth.beq w lw || !IntWidth.beq w rw ||"
),
replacement=(
" | .numDivCeil w s,\n"
" [(.int lw ls, .scalar lSv), (.int rw rs, .scalar rSv)] =>\n"
" if false || !IntWidth.beq w lw || !IntWidth.beq w rw ||"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_div_ceil_unsigned_only",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_checked_shl_oob_none",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execCoreContractOpOutcome .numCheckedShl returns None when rhs >= BITS"
),
anchor=(
" let amt := (truncateBits .i32 rSv.bits).toNat\n"
" if !Nat.blt amt w.bitWidth then\n"
" .ok (.optionVal none, m)"
),
replacement=(
" let amt := (truncateBits .i32 rSv.bits).toNat\n"
" if false then\n"
" .ok (.optionVal none, m)"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_checked_shl_oob_none",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_leading_zeros_bit_test",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"leadingZerosFrom stops at the most-significant set bit for u32 "
"and u64 leading_zeros"
),
anchor=" if Nat.beq (Nat.land (Nat.shiftRight bits n) 1) 1 then 0",
replacement=" if false then 0",
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_leading_zeros_u32_u64",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_leading_zeros_width",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"numLeadingZeros scans w.bitWidth bits (64 for u64 vs 32 for u32)"
),
anchor=" let count := leadingZerosFrom bits w.bitWidth",
replacement=" let count := leadingZerosFrom bits 32",
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_leading_zeros_u32_u64",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_count_ones_bit_count",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="countOnesFrom accumulates each set bit across w.bitWidth",
anchor=" | n + 1 => Nat.land bits 1 + countOnesFrom (Nat.shiftRight bits 1) n",
replacement=" | n + 1 => countOnesFrom (Nat.shiftRight bits 1) n",
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_count_ones",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_trailing_zeros_bit_test",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="trailingZerosFrom stops at the least-significant set bit",
anchor=" if Nat.beq (Nat.land bits 1) 1 then 0",
replacement=" if false then 0",
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_trailing_zeros",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_is_multiple_of_zero_rhs",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"numIsMultipleOf returns (self == 0) when rhs = 0 instead of "
"returning false unconditionally"
),
anchor=" if Nat.beq r 0 then .ok (.bool (Nat.beq l 0), m)",
replacement=" if Nat.beq r 0 then .ok (.bool false, m)",
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_is_multiple_of_zero_rhs",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_is_multiple_of_unsigned_only",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execCoreContractOpOutcome .numIsMultipleOf rejects signed integers as "
".unsupported"
),
anchor=(
" | .numIsMultipleOf w s,\n"
" [(.int lw ls, .scalar lSv), (.int rw rs, .scalar rSv)] =>\n"
" if s || ls || rs || !IntWidth.beq w lw || !IntWidth.beq w rw ||"
),
replacement=(
" | .numIsMultipleOf w s,\n"
" [(.int lw ls, .scalar lSv), (.int rw rs, .scalar rSv)] =>\n"
" if false || !IntWidth.beq w lw || !IntWidth.beq w rw ||"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_is_multiple_of_unsigned_only",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_split_at_mut_bounds_panic",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execSliceSplitAtOutcome returns .panicked when mid > len instead of "
"constructing out-of-bounds subslices"
),
anchor=(
" if !Nat.ble mid len.toNat then\n"
" .panicked"
),
replacement=(
" if false then\n"
" .panicked"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_split_at_mut_bounds_panic",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_split_at_mut_no_shared_upgrade",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execSliceSplitAtOutcome rejects upgrading a shared &[T] input "
"slice into (&mut [T], &mut [T])"
),
anchor=(
" else if Mutability.beq inMut .shared && Mutability.beq reqMut .mut then\n"
" .fault .undefined\n"
" else\n"
" match refValidInMem m inMut (.slice elem) (.slicePtr p len) with\n"
" | .error k => .fault k\n"
" | .ok () =>\n"
" if !Nat.ble mid len.toNat then"
),
replacement=(
" else if false then\n"
" .fault .undefined\n"
" else\n"
" match refValidInMem m inMut (.slice elem) (.slicePtr p len) with\n"
" | .error k => .fault k\n"
" | .ok () =>\n"
" if !Nat.ble mid len.toNat then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_split_at_mut_no_shared_upgrade",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_split_at_mut_suffix_offset_disjoint",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execSliceSplitAtOutcome advances the suffix pointer by mid "
"elements so the prefix and suffix &mut spans are disjoint"
),
anchor=" match ptrAddInMem m lay.size p mid with",
replacement=" match ptrAddInMem m lay.size p 0 with",
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_split_at_mut_suffix_offset_disjoint",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_split_at_mut_suffix_len_union",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execSliceSplitAtOutcome sets suffix length to len - mid so the "
"union of prefix and suffix equals the input span"
),
anchor=" let suffixVal := Val.slicePtr p' (UInt64.ofNat (len.toNat - mid))",
replacement=" let suffixVal := Val.slicePtr p' len",
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_split_at_mut_suffix_len_union",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_core_call_dead_destination",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 returning .coreCall faults .undefined on a dead "
"destination local before dispatching contract panics"
),
anchor=(
" match getElem? locals1 dst.localId with\n"
" | none => .fault .unsupported\n"
" | some .dead => .fault .undefined\n"
" | some _ =>"
),
replacement=(
" match getElem? locals1 dst.localId with\n"
" | none => .fault .unsupported\n"
" | some _ =>"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_call_dead_destination",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_array_subslice_len_u64_bound",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execArraySubsliceOutcome rejects array lengths >= 2^64 before "
"converting len to UInt64"
),
anchor=(
"noncomputable def execArraySubsliceOutcome (m : MemoryState)\n"
" (reqMut inMut : Mutability) (elem : MirTy) (len : Nat) (p : PtrVal)\n"
" (startOff endOff : Nat) : CoreCallOutcome :=\n"
" if !Nat.blt len (Nat.pow 2 64) then"
),
replacement=(
"noncomputable def execArraySubsliceOutcome (m : MemoryState)\n"
" (reqMut inMut : Mutability) (elem : MirTy) (len : Nat) (p : PtrVal)\n"
" (startOff endOff : Nat) : CoreCallOutcome :=\n"
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_array_subslice_len_u64_bound",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_subslice_oob_panics",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execSliceSubsliceOutcome reports an out-of-bounds range as a panic, "
"not a fault"
),
anchor=(
" if !Nat.ble startOff endOff || !Nat.ble endOff len.toNat then\n"
" .panicked"
),
replacement=(
" if !Nat.ble startOff endOff || !Nat.ble endOff len.toNat then\n"
" .fault .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_subslice_oob_panics",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_split_at_oob_panics",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execSliceSplitAtOutcome reports mid > len as a panic, not a fault"
),
anchor=(
" if !Nat.ble mid len.toNat then\n"
" .panicked"
),
replacement=(
" if !Nat.ble mid len.toNat then\n"
" .fault .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_split_at_oob_panics",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_contracts_option_unwrap_none_panics",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"execCoreContractOpOutcome reports Option::unwrap on None as a panic, "
"not a fault"
),
anchor=(
" | none => .panicked"
),
replacement=(
" | none => .fault .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_option_unwrap_none_panics",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_core_call_panic_dispatch",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 routes a returning core call panic through "
"evalCorePanicAbort, so it stays .unsupported under --panic unwind"
),
anchor=(
" | .panicked =>\n"
" evalCorePanicAbort panicStrategy unwind\n"
" (extractCallerMemory callerMem mem1) hasLocalPanicHandler"
),
replacement=(
" | .panicked =>\n"
" .done (.aborted (extractCallerMemory callerMem mem1))"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_call_panic_dispatch",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_core_call_panic_caller_mem",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 reports post-call caller memory when a returning "
"core call panic aborts"
),
anchor=(
" | .panicked =>\n"
" evalCorePanicAbort panicStrategy unwind\n"
" (extractCallerMemory callerMem mem1) hasLocalPanicHandler"
),
replacement=(
" | .panicked =>\n"
" evalCorePanicAbort panicStrategy unwind\n"
" callerMem hasLocalPanicHandler"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_core_call_panic_caller_mem",
needs_wf_helper=False,
),
# ------------------------------------------------------------------
# Profile v2 heap allocation (`Vec`/`Box`), unit aggregate, sysroot call,
# and core call guards (34 guards)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="alloc_vec_valid_unsupported_elem",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"vecValidInMem refuses an element type that is not owned data "
"(isOwnedDataTyV2) with .unsupported"
),
anchor=(
" if !isOwnedDataTyV2 v.elem then\n"
" .error .unsupported\n"
" else if !Nat.blt v.cap.toNat isizeMaxBytes then\n"
" .error .undefined\n"
" else\n"
" ownedHeapBufValidInMem m isMut v.elem v.ptr v.cap v.len"
),
replacement=(
" if false then\n"
" .error .unsupported\n"
" else if !Nat.blt v.cap.toNat isizeMaxBytes then\n"
" .error .undefined\n"
" else\n"
" ownedHeapBufValidInMem m isMut v.elem v.ptr v.cap v.len"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_vec_valid_unsupported_elem",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_vec_valid_zst_cap_high_bit",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"vecValidInMem enforces cap < 2^63 (RawVecInner.cap UsizeNoHighBit) "
"even for ZST elements"
),
anchor=(
" else if !Nat.blt v.cap.toNat isizeMaxBytes then\n"
" .error .undefined\n"
" else\n"
" ownedHeapBufValidInMem m isMut v.elem v.ptr v.cap v.len"
),
replacement=(
" else if false then\n"
" .error .undefined\n"
" else\n"
" ownedHeapBufValidInMem m isMut v.elem v.ptr v.cap v.len"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_vec_valid_zst_cap_high_bit",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_ensure_vec_cap_zst_unbounded",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"ensureVecCapacityOutcome allows ZST Vec growth up to 2^64 - 1 without "
"mutating self.cap (matching RawVecInner::capacity(0) = usize::MAX)"
),
anchor=(
" else if Nat.beq lay.size 0 then\n"
" -- Upstream `RawVecInner::capacity(0)` is `usize::MAX`: ZST buffers never\n"
" -- allocate or mutate `self.cap`, overflowing only at `2^64`.\n"
" if !Nat.blt minCap (Nat.pow 2 64) then"
),
replacement=(
" else if false then\n"
" if !Nat.blt minCap (Nat.pow 2 64) then"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_ensure_vec_cap_zst_unbounded",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_box_valid_unsupported_slice_elem",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"boxValidInMem refuses Box<[T]> whose element type is not owned "
"data (isOwnedDataTyV2) with .unsupported"
),
anchor=(
" | .slice elem =>\n"
" if !isOwnedDataTyV2 elem then\n"
" .error .unsupported\n"
" else\n"
" boxPointeeValidInMem m isMut b.pointee b.ptr b.len"
),
replacement=(
" | .slice elem =>\n"
" if false then\n"
" .error .unsupported\n"
" else\n"
" boxPointeeValidInMem m isMut b.pointee b.ptr b.len"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_box_valid_unsupported_slice_elem",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_vec_grow_cap_doubled_overflow",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"vecGrowCap fails when the amortized doubled capacity exceeds "
"isize::MAX bytes (isizeMaxBytes)"
),
anchor=(
" if Nat.blt (doubled * elemSize) isizeMaxBytes &&\n"
" Nat.blt doubled u64Bound then\n"
" some doubled"
),
replacement=(
" if true &&\n"
" Nat.blt doubled u64Bound then\n"
" some doubled"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_vec_grow_cap_doubled_overflow",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_vec_with_capacity_overflow",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"evalVecWithCapacityOutcome panics (capacity overflow) when "
"capacity * size exceeds isize::MAX"
),
anchor=(
" let totalBytes := cap.toNat * lay.size\n"
" if !Nat.blt totalBytes isizeMaxBytes then\n"
" .panicked"
),
replacement=(
" let totalBytes := cap.toNat * lay.size\n"
" if false then\n"
" .panicked"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_vec_with_capacity_overflow",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_vec_index_oob",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"evalVecIndexOutcome panics (bounds check) when idx >= len, even "
"inside the capacity"
),
anchor=(
" if !Nat.blt idx.toNat v.len.toNat then\n"
" .panicked"
),
replacement=(
" if false then\n"
" .panicked"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_vec_index_oob",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_vec_with_capacity_overflow_panics",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"evalVecWithCapacityOutcome reports a capacity overflow as a panic, "
"which aborts under --panic abort, not a fault"
),
anchor=(
" if !Nat.blt totalBytes isizeMaxBytes then\n"
" .panicked"
),
replacement=(
" if !Nat.blt totalBytes isizeMaxBytes then\n"
" .fault .unsupported"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_vec_with_capacity_overflow_panics",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_vec_index_oob_panics",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"evalVecIndexOutcome reports an out-of-bounds index as a panic, not "
"a fault"
),
anchor=(
" if !Nat.blt idx.toNat v.len.toNat then\n"
" .panicked"
),
replacement=(
" if !Nat.blt idx.toNat v.len.toNat then\n"
" .fault .unsupported"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_vec_index_oob_panics",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_vec_grow_capacity_overflow_panics",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"ensureVecCapacityOutcome reports a failed vecGrowCap as a panic "
"(none), not a fault"
),
anchor=(
" match vecGrowCap lay.size v.cap.toNat minCap with\n"
" | none => none"
),
replacement=(
" match vecGrowCap lay.size v.cap.toNat minCap with\n"
" | none => some (.error .unsupported)"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_vec_grow_capacity_overflow_panics",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_vec_reserve_len_overflow_panics",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"evalVecReserveOutcome reports an overflowing len + additional as a "
"panic, not a fault"
),
anchor=(
" if !Nat.blt minCap (Nat.pow 2 64) then\n"
" .panicked"
),
replacement=(
" if !Nat.blt minCap (Nat.pow 2 64) then\n"
" .fault .unsupported"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_vec_reserve_len_overflow_panics",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_vec_extend_len_overflow_panics",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"evalVecExtendFromSliceOutcome reports an overflowing len + srcLen "
"as a panic, not a fault"
),
anchor=(
" if !Nat.blt newLen (Nat.pow 2 64) then\n"
" .panicked"
),
replacement=(
" if !Nat.blt newLen (Nat.pow 2 64) then\n"
" .fault .unsupported"
),
fixture_module="AllocRefutations",
theorem_name="refute_alloc_vec_extend_len_overflow_panics",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_retire_heap_buffer",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"retireHeapBuffer kills a reallocated buffer, so pointers into "
"it lose provenance (stale reads fault)"
),
anchor=(
" | some aid => deallocateStack m ⟨aid, p.offsetBytes.toNat⟩"
),
replacement=" | some _ => .ok m",
fixture_module="AllocRefutations",
theorem_name="refute_alloc_retire_heap_buffer",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_zero_cap_ptr_null",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"zeroCapPtrValidInMem rejects a null provenance-free pointer for "
"an empty heap buffer"
),
anchor=(
" let align := Nat.pow 2 alignLog2\n"
" if Nat.beq p.offsetBytes.toNat 0 ||\n"
" !Nat.beq (Nat.mod p.offsetBytes.toNat align) 0 then"
),
replacement=(
" let align := Nat.pow 2 alignLog2\n"
" if false ||\n"
" !Nat.beq (Nat.mod p.offsetBytes.toNat align) 0 then"
),
fixture_module="AllocRefutations",
theorem_name="refute_bytes_zero_cap_ptr_null",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_heap_buf_len_gt_cap",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="heapBufValidInMem rejects len > cap as UB for non-ZSTs",
anchor=(
" if !Nat.beq lay.size 0 && !Nat.ble len.toNat cap.toNat then\n"
" .error .undefined\n"
" else\n"
" let capBytes := cap.toNat * lay.size"
),
replacement=(
" if false then\n"
" .error .undefined\n"
" else\n"
" let capBytes := cap.toNat * lay.size"
),
fixture_module="AllocRefutations",
theorem_name="refute_bytes_heap_buf_len_gt_cap",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_heap_buf_dead_alloc",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"heapBufValidInMem rejects a buffer in a dead (live = false) "
"allocation as UB"
),
anchor=(
" if !a.live || "
"!isInBounds a p.offsetBytes.toNat capBytes ||\n"
),
replacement=(
" if false || "
"!isInBounds a p.offsetBytes.toNat capBytes ||\n"
),
fixture_module="AllocRefutations",
theorem_name="refute_bytes_heap_buf_dead_alloc",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_heap_buf_cap_oob",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"heapBufValidInMem rejects cap * size bytes past the end of the "
"allocation as UB"
),
anchor=(
" if !a.live || "
"!isInBounds a p.offsetBytes.toNat capBytes ||\n"
),
replacement=" if !a.live || false ||\n",
fixture_module="AllocRefutations",
theorem_name="refute_bytes_heap_buf_cap_oob",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_heap_buf_uninit",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"heapBufValidInMem rejects uninitialized bytes in the len "
"prefix as UB"
),
anchor=(
" if isIntMirTy elem then\n"
" if !isSliceAllInit initSlice then\n"
" .error .undefined"
),
replacement=(
" if isIntMirTy elem then\n"
" if false then\n"
" .error .undefined"
),
fixture_module="AllocRefutations",
theorem_name="refute_bytes_heap_buf_uninit",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_owned_heap_buf_size",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"ownedHeapBufValidInMem requires the allocation size to be "
"exactly cap * size bytes"
),
anchor=(
" !Nat.beq a.bytes.length "
"(cap.toNat * lay.size) ||\n"
),
replacement=" false ||\n",
fixture_module="AllocRefutations",
theorem_name="refute_bytes_owned_heap_buf_size",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_box_pointee_slice_owned",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"boxPointeeValidInMem requires a Box<[T]> to own its whole "
"allocation (ownedHeapBufValidInMem)"
),
anchor=(
" | .slice elem, some len => "
"ownedHeapBufValidInMem m isMut elem p len len"
),
replacement=(
" | .slice elem, some len => "
"heapBufValidInMem m isMut elem p len len"
),
fixture_module="AllocRefutations",
theorem_name="refute_bytes_box_pointee_slice_owned",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_box_as_ref_validity",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCastKindV2 .boxAsRef checks refValidInMem of the "
"dereferenced Box pointer"
),
anchor=(
" match refValidInMem mem .shared pt ptrVal with\n"
" | .error k => .error k\n"
" | .ok () => .ok ptrVal"
),
replacement=(
" match refValidInMem mem .shared pt ptrVal with\n"
" | .error _ => .ok ptrVal\n"
" | .ok () => .ok ptrVal"
),
fixture_module="AllocRefutations",
theorem_name="refute_step_box_as_ref_validity",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_box_as_ref_pointee_mismatch",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCastKindV2 .boxAsRef refuses a cast to a reference with a "
"different pointee type"
),
anchor=(
" | .box pt, .boxPtr p optLen, .ref .shared castPt =>\n"
" if !MirTy.beq pt castPt then\n"
" .error .unsupported"
),
replacement=(
" | .box pt, .boxPtr p optLen, .ref .shared castPt =>\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="AllocRefutations",
theorem_name="refute_step_box_as_ref_pointee_mismatch",
sanity_module="AllocSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_aggregate_unit_empty_fields",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 .aggregateTuple into .unit rejects non-empty field lists"
),
anchor=(
" | .aggregateTuple fields =>\n"
" match dstTy with\n"
" | .unit =>\n"
" if fields.isEmpty then"
),
replacement=(
" | .aggregateTuple fields =>\n"
" match dstTy with\n"
" | .unit =>\n"
" if true then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_aggregate_unit_empty_fields",
),
MirSemanticsGuard(
guard_id="step_v2_sysroot_call_target_admitted",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalTerminatorV2 .sysrootCall enforces callTargetAdmitted "
"(rejecting cleanup unwinds and move/dst aliasing)"
),
anchor=(
" | .sysrootCall op args dst (some target) unwind =>\n"
" if !callTargetAdmitted body bb (sysrootNumBody op) args dst\n"
" (some target) unwind then"
),
replacement=(
" | .sysrootCall op args dst (some target) unwind =>\n"
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_sysroot_call_target_admitted",
),
MirSemanticsGuard(
guard_id="enum_v2_option_nested_ref_rejected",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description="isOptionPayloadSupportedV2 rejects nested &&T payloads",
anchor=" | .ref _ (.ref _ _) => false",
replacement=" | .ref _ (.ref _ _) => true",
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_option_nested_ref_rejected",
),
MirSemanticsGuard(
guard_id="boundary_v2_rejects_nested_ref_signature",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="BodyStaticAdmittedV2 rejects bodies with &&int in signatures",
anchor=(
" bodyFakeAddressOfValidV2 body &&\n"
" !bodyHasNestedRefSignatureV2 body &&"
),
replacement=(
" bodyFakeAddressOfValidV2 body &&\n"
" true &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_rejects_nested_ref_signature",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_shared_int_ref_mut_only_shared",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refValidInMem admits &(&int) only at .shared mutability",
anchor=(
" | .ref .shared (.int w s), .ptr p =>\n"
" if !Mutability.beq reqMut .shared then"
),
replacement=(
" | .ref .shared (.int w s), .ptr p =>\n"
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_bytes_v2_ref_valid_shared_int_ref_mut_only_shared",
),
MirSemanticsGuard(
guard_id="bytes_v2_ref_valid_nested_inner_ref",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description="refValidInMem validates the inner &int behind a &&int",
anchor=(
" | .ok (some (.ptr innerP)) =>\n"
" sharedIntRefValidInMem m w s innerP"
),
replacement=(
" | .ok (some (.ptr _)) =>\n"
" .ok ()"
),
fixture_module="StepRefutations",
theorem_name="refute_bytes_v2_ref_valid_nested_inner_ref",
),
MirSemanticsGuard(
guard_id="step_v2_read_place_deref_nested_ref_valid",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="readPlaceV2 re-validates a loaded inner &int on deref",
anchor=(
" | .ref _ _, some v =>\n"
" if !refsValidInMem mem pt v then\n"
" .error .undefined"
),
replacement=(
" | .ref _ _, some v =>\n"
" if false then\n"
" .error .undefined"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_place_deref_nested_ref_valid",
),
MirSemanticsGuard(
guard_id="step_v2_aggregate_ordering_tag_valid",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="evalRvalueV2 .aggregateOrdering rejects invalid tags",
anchor=(
" | .aggregateOrdering tagBits =>\n"
" if !MirTy.beq dstTy .ordering then\n"
" .error .unsupported\n"
" else\n"
" match orderingOfTagBits tagBits with\n"
" | some ord => .ok (.ordering ord, locals, mem)\n"
" | none => .error .unsupported"
),
replacement=(
" | .aggregateOrdering tagBits =>\n"
" if !MirTy.beq dstTy .ordering then\n"
" .error .unsupported\n"
" else\n"
" match orderingOfTagBits tagBits with\n"
" | some ord => .ok (.ordering ord, locals, mem)\n"
" | none => .ok (.ordering .equal, locals, mem)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_aggregate_ordering_tag_valid",
),
MirSemanticsGuard(
guard_id="core_contracts_default_val_dst_type",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="CoreCallOp.defaultVal checks destination type matches op type",
anchor=(
" | .defaultVal (.int w s), [] =>\n"
" if !MirTy.beq dstTy (.int w s) then\n"
" .error .unsupported"
),
replacement=(
" | .defaultVal (.int w s), [] =>\n"
" if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_default_val_dst_type",
),
MirSemanticsGuard(
guard_id="core_contracts_ref_int_partial_eq_second_arg",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="CoreCallOp.refIntPartialEq validates and reads the second &&int arg",
anchor=(
" match loadRefIntV2 m w s p1, loadRefIntV2 m w s p2 with\n"
" | .error k, _ => .error k\n"
" | _, .error k => .error k"
),
replacement=(
" match loadRefIntV2 m w s p1, loadRefIntV2 m w s p1 with\n"
" | .error k, _ => .error k\n"
" | _, .error k => .error k"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_ref_int_partial_eq_second_arg",
),
MirSemanticsGuard(
guard_id="core_contracts_unit_partial_eq_validates_refs",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description="CoreCallOp.unitPartialEq validates both &() references",
anchor=(
" match refValidInMem m m1 .unit (.ptr p1),\n"
" refValidInMem m m2 .unit (.ptr p2) with"
),
replacement=(
" match (.ok () : Except FaultKind Unit),\n"
" refValidInMem m m2 .unit (.ptr p2) with"
),
fixture_module="StepRefutations",
theorem_name="refute_core_contracts_unit_partial_eq_validates_refs",
),
MirSemanticsGuard(
guard_id="step_v2_call_nested_ref_signature",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"bodyCallAdmittedV2 refuses intra-crate calls to callees with "
"&&int in their signature"
),
anchor=(
" bodyFakeAddressOfValidV2 callee &&\n"
" !bodyHasNestedRefSignatureV2 callee"
),
replacement=(
" bodyFakeAddressOfValidV2 callee &&\n"
" true"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_nested_ref_signature",
needs_wf_helper=False,
),
# ------------------------------------------------------------------
# Profile v2 drop glue (76 guards)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="alloc_v2_drop_vec_retire",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropVecV2 frees a Vec buffer with nonzero element size and capacity"
),
anchor=(
" if Nat.beq lay.size 0 || Nat.beq cap.toNat 0 then\n"
" .ok m1"
),
replacement=(
" if true then\n"
" .ok m1"
),
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_drop_vec_retire",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_v2_drop_box_retire",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropBoxV2 frees a non-zero-sized Box allocation"
),
anchor=(
" if Nat.beq (count * lay.size) 0 then\n"
" .ok m1"
),
replacement=(
" if true then\n"
" .ok m1"
),
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_drop_box_retire",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_v2_drop_vec_valid",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropVecV2 validates the Vec handle before freeing its buffer"
),
anchor=" match vecValidInMem m true ⟨elem, ptr, cap, len⟩, layoutOfTyV2 elem with",
replacement=" match (Except.ok () : Except FaultKind Unit), layoutOfTyV2 elem with",
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_drop_vec_valid",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_v2_drop_box_valid",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropBoxV2 validates the Box handle before freeing its allocation"
),
anchor=" match boxValidInMem m true ⟨pointee, ptr, optLen⟩, layoutOfTyV2 elemTy with",
replacement=" match (Except.ok () : Except FaultKind Unit), layoutOfTyV2 elemTy with",
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_drop_box_valid",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_v2_drop_fields",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropGlueFieldsV2 drops every remaining field in order"
),
anchor=" | .ok m1 => dropGlueFieldsV2 m1 ts vs",
replacement=" | .ok m1 => .ok m1",
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_drop_fields",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_v2_drop_array_elems",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropGlueV2 drops every element of an array with drop glue"
),
anchor=" dropValsV2 (fun m' v' => dropGlueV2 m' elem v') m vs",
replacement=" dropValsV2 (fun m' _ => .ok m') m vs",
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_drop_array_elems",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_v2_drop_shape_mismatch_refused",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropGlueV2 refuses a value whose shape does not match a type "
"with drop glue"
),
anchor=" | ty, _ => if tyNeedsDropV2 ty then .error .unsupported else .ok m",
replacement=" | ty, _ => if tyNeedsDropV2 ty && false then .error .unsupported else .ok m",
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_drop_shape_mismatch_refused",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_v2_drop_option_some",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropGlueV2 drops the payload of a Some Option"
),
anchor=" | .option inner, .optionVal (some v) => dropGlueV2 m inner v",
replacement=" | .option inner, .optionVal (some v) => .ok m",
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_drop_option_some",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_v2_drop_owned_struct",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropGlueV2 drops the fields of a struct owning heap buffers"
),
anchor=" | .struct_ _ ts, .tuple vs => dropGlueFieldsV2 m ts vs",
replacement=" | .struct_ _ ts, .tuple vs => .ok m",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_owned_struct_frees_buffers",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_adt_drop_active_variant",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropGlueV2 drops the fields of a payload enum's active variant"
),
anchor=" | .adtEnum _ vs, .adtVal i p => dropGlueNthV2 m vs i p",
replacement=" | .adtEnum _ vs, .adtVal i p => .ok m",
fixture_module="StepRefutations",
theorem_name="refute_alloc_adt_drop_active_variant",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_adt_drop_nth_variant",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"dropGlueNthV2 runs the glue of the active variant's payload, not "
"the first variant's"
),
anchor=" | _ :: ts, i + 1, v => dropGlueNthV2 m ts i v",
replacement=" | t :: _, i + 1, v => dropGlueV2 m t v",
fixture_module="StepRefutations",
theorem_name="refute_alloc_adt_drop_nth_variant",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_runs_glue_immediate",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop of an immediate local with drop glue runs dropGlueV2"
),
anchor=(
" if !tyNeedsDropV2 ty then\n"
" .ok mem\n"
" else\n"
" match optVal with"
),
replacement=(
" if true then\n"
" .ok mem\n"
" else\n"
" match optVal with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_runs_glue_immediate",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deinit_immediate",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop deinitializes an immediate local"
),
anchor=" match setElem? frame.locals place.localId (liveUninitSlot ty) with",
replacement=" match setElem? frame.locals place.localId (.immediate optVal) with",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deinit_immediate",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_uninit_immediate",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop of an uninitialized immediate local with drop glue faults"
),
anchor=(
" | none => .error .unsupported\n"
" | some v => dropGlueV2 mem ty v"
),
replacement=(
" | none => .ok mem\n"
" | some v => dropGlueV2 mem ty v"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_uninit_immediate",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_runs_glue_indirect",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop of an in-memory local with drop glue runs dropGlueV2"
),
anchor=(
" if !tyNeedsDropV2 ty then\n"
" .ok mem\n"
" else\n"
" match loadIndirectV2 mem ty mplace with"
),
replacement=(
" if true then\n"
" .ok mem\n"
" else\n"
" match loadIndirectV2 mem ty mplace with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_runs_glue_indirect",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deinit_indirect",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop deinitializes an in-memory local"
),
anchor=" match deinitIndirectV2 mem1 ty mplace with",
replacement=" match (Except.ok mem1 : Except FaultKind MemoryState) with",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deinit_indirect",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_uninit_indirect",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop of an uninitialized in-memory local with drop glue faults"
),
anchor=(
" | .ok none => .error .unsupported\n"
" | .ok (some v) => dropGlueV2 mem ty v"
),
replacement=(
" | .ok none => .ok mem\n"
" | .ok (some v) => dropGlueV2 mem ty v"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_uninit_indirect",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deref_runs_glue",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop through a mutable reference runs dropGlueV2"
),
anchor=" match dropGlueV2 mem pt v with",
replacement=" match (Except.ok mem : Except FaultKind MemoryState) with",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deref_runs_glue",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deref_deinit",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop through a mutable reference deinitializes the pointee"
),
anchor=(
" match deinitIndirectV2 mem1 pt\n"
" ⟨aid, selfPtr.offsetBytes.toNat⟩ with"
),
replacement=(
" match deinitIndirectV2 mem1 .unit\n"
" ⟨aid, selfPtr.offsetBytes.toNat⟩ with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deref_deinit",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deref_non_handle",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop through a reference to a pointee without drop glue faults"
),
anchor=(
" else if !tyNeedsDropV2 leafTy then\n"
" .error .unsupported"
),
replacement=(
" else if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deref_non_handle",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deref_dead",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop through a dead reference local faults with .undefined"
),
anchor=(
" | .dead | .partialTuple _ => .error .undefined\n"
" | .immediate optVal => .ok optVal\n"
" | .indirect mplace => loadIndirectV2 mem (.ref .mut pt) mplace"
),
replacement=(
" | .dead | .partialTuple _ => .error .unsupported\n"
" | .immediate optVal => .ok optVal\n"
" | .indirect mplace => loadIndirectV2 mem (.ref .mut pt) mplace"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deref_dead",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deref_box",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop through a mutable reference to a Box runs its drop glue"
),
anchor=" | .ok b => .ok (.boxPtr b.ptr b.len)",
replacement=" | .ok _ => .error .unsupported",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deref_box",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="enum_v2_rec_self_inline",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"recTyWfV2 rejects a recursive occurrence outside a Box or Vec pointee"
),
anchor=(
" | .recSelf _ => false\n"
" | .box (.recSelf j) | .vec (.recSelf j) =>"
),
replacement=(
" | .recSelf _ => true\n"
" | .box (.recSelf j) | .vec (.recSelf j) =>"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_rec_self_inline",
),
MirSemanticsGuard(
guard_id="enum_v2_rec_self_scope",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"recTyWfV2 requires a back edge to name the innermost binder"
),
anchor=(
" | .box (.recSelf j) | .vec (.recSelf j) => recScopeIs scope j"
),
replacement=(
" | .box (.recSelf j) | .vec (.recSelf j) => true"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_rec_self_scope",
),
MirSemanticsGuard(
guard_id="enum_v2_rec_adt_no_rebind",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"recTyWfV2 rejects a binder that rebinds an enclosing id"
),
anchor=(
" !recScopeIs scope j && recAdtHeadOkV2 j defn && recTyWfV2 (some j) defn"
),
replacement=(
" true && recAdtHeadOkV2 j defn && recTyWfV2 (some j) defn"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_rec_adt_no_rebind",
),
MirSemanticsGuard(
guard_id="enum_v2_rec_adt_head",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"recTyWfV2 requires a binder to define the struct with its layout id"
),
anchor=(
" !recScopeIs scope j && recAdtHeadOkV2 j defn && recTyWfV2 (some j) defn"
),
replacement=(
" !recScopeIs scope j && true && recTyWfV2 (some j) defn"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_rec_adt_head",
),
MirSemanticsGuard(
guard_id="enum_v2_rec_coherent_defs",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"recTysCoherentV2 requires binders with one id to share a definition"
),
anchor=(
" keys.1.all (fun b => !Nat.beq a.1 b.1 || MirTy.beq a.2 b.2) &&"
),
replacement=(
" keys.1.all (fun _ => true) &&"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_rec_coherent_defs",
),
MirSemanticsGuard(
guard_id="enum_v2_rec_coherent_struct_id",
target_file="trusted/lean/Trusted/MirSemantics/Enum.lean",
target_module="Trusted/MirSemantics/Enum",
description=(
"recTysCoherentV2 rejects a plain struct reusing a binder layout id"
),
anchor=(
" keys.2.all (fun i => !Nat.beq a.1 i))"
),
replacement=(
" keys.2.all (fun _ => true))"
),
fixture_module="EnumRefutations",
theorem_name="refute_enum_v2_rec_coherent_struct_id",
),
MirSemanticsGuard(
guard_id="layout_v2_rec_self_none",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description=(
"layoutOfTyV2 gives an inline recursive occurrence no layout"
),
anchor=(
" | .recSelf _ => none\n"
" | _ => layoutOfPtrOrRangeV2 ty"
),
replacement=(
" | .recSelf _ => some ⟨8, 3⟩\n"
" | _ => layoutOfPtrOrRangeV2 ty"
),
fixture_module="LayoutRefutations",
theorem_name="refute_layout_v2_rec_self_none",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="layout_v2_rec_self_field_none",
target_file="trusted/lean/Trusted/MirSemantics/Layout.lean",
target_module="Trusted/MirSemantics/Layout",
description=(
"layoutOfArrayV2 gives an inline recursive field no layout"
),
anchor=(
" | .recAdt _ defn => layoutOfArrayV2 defn\n"
" | .recSelf _ => none\n"
" | .adtEnum l vs =>"
),
replacement=(
" | .recAdt _ defn => layoutOfArrayV2 defn\n"
" | .recSelf _ => some ⟨8, 3⟩\n"
" | .adtEnum l vs =>"
),
fixture_module="LayoutRefutations",
theorem_name="refute_layout_v2_rec_self_field_none",
sanity_module="LayoutSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_rec_self_decode",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"decodeValV2 faults on an inline recursive occurrence"
),
anchor=(
" | .recSelf _, _ => .error .unsupported\n"
" -- A payload enum reads its variant"
),
replacement=(
" | .recSelf _, _ => .ok (some .unit)\n"
" -- A payload enum reads its variant"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_rec_self_decode",
),
MirSemanticsGuard(
guard_id="alloc_v2_rec_needs_drop",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description=(
"tyNeedsDropV2 gives recursive types drop glue, so the glue of their "
"heap elements runs"
),
anchor=" | .recAdt _ _ | .recSelf _ => true",
replacement=" | .recAdt _ _ | .recSelf _ => false",
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_rec_needs_drop",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_rec_drop_arm",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="dropGlueV2 runs the fuelled glue of a recursive value",
anchor=(
" | .recAdt j defn, v =>\n"
" dropGlueFuelV2 (m.allocations.length + 2) m (.recAdt j defn) v"
),
replacement=(
" | .recAdt j defn, v =>\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_rec_needs_drop",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_rec_drop_self",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="dropGlueRecV2 binds back edges to the innermost recursive binder",
anchor=" | .recAdt j defn, v => dropGlueRecV2 heapRec (some (j, defn)) m defn v",
replacement=" | .recAdt j defn, v => dropGlueRecV2 heapRec none m defn v",
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_rec_needs_drop",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_rec_drop_box_pointee",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="dropGlueRecV2 drops a recursive Box's pointee before freeing it",
anchor=" | some pt => dropBoxV2 (fun m' v' => heapRec m' pt v') m pt ptr optLen",
replacement=" | some pt => dropBoxV2 (fun m' _ => .ok m') m pt ptr optLen",
fixture_module="StepRefutations",
theorem_name="refute_alloc_v2_rec_needs_drop",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_rec_drop_vec_elems",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="dropGlueRecV2 drops each element of a recursive Vec's buffer",
anchor=" | some e => dropVecV2 (fun m' v' => heapRec m' e v') m e ptr cap len",
replacement=" | some e => dropVecV2 (fun m' _ => .ok m') m e ptr cap len",
fixture_module="StepRefutations",
theorem_name="refute_alloc_rec_drop_vec_elems",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="alloc_rec_drop_fuel",
target_file="trusted/lean/Trusted/MirSemantics/AllocContracts.lean",
target_module="Trusted/MirSemantics/AllocContracts",
description="dropGlueFuelV2 faults when out of fuel instead of skipping glue",
anchor=" | 0, _, _, _ => .error .unsupported\n | fuel + 1, m, ty, v =>",
replacement=" | 0, m, _, _ => .ok m\n | fuel + 1, m, ty, v =>",
fixture_module="StepRefutations",
theorem_name="refute_alloc_rec_drop_fuel",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_rec_owned_valid",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"recOwnedWalkV2 unfolds .recAdt binders during owned-data validation"
),
anchor=(
" | vis, .recAdt j defn, v =>\n"
" recOwnedWalkV2 m isMut heapRec (some (j, defn)) vis defn v"
),
replacement=(
" | vis, .recAdt _ _, _ => .ok vis"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_rec_owned_valid",
),
MirSemanticsGuard(
guard_id="bytes_v2_rec_walk_revisit",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"recOwnedValidV2 faults on a heap buffer entered twice"
),
anchor=(
" if allocIdListContains aid vis then none else some (aid :: vis)"
),
replacement=(
" if false then none else some (aid :: vis)"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_rec_walk_revisit",
),
MirSemanticsGuard(
guard_id="bytes_v2_rec_walk_fuel",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"recOwnedValidAtV2 fails closed when its heap fuel runs out"
),
anchor=(
" | 0 => fun _ _ _ => .error .unsupported\n"
" | fuel + 1 => recOwnedWalkV2 m isMut (recOwnedValidAtV2 m isMut fuel) none"
),
replacement=(
" | 0 => fun vis _ _ => .ok vis\n"
" | fuel + 1 => recOwnedWalkV2 m isMut (recOwnedValidAtV2 m isMut fuel) none"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_rec_walk_fuel",
),
MirSemanticsGuard(
guard_id="bytes_v2_rec_resolve_nested",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"recResolveV2 closes every back edge, including one under nested "
"handles"
),
anchor=(
" | some (i, d) => substRecSelfV2 i (.recAdt i d) t"
),
replacement=(
" | some (_, _) => t"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_rec_resolve_nested",
),
MirSemanticsGuard(
guard_id="bytes_v2_rec_refs_valid",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refsValidInMem checks a by-value recursive struct's owned data"
),
anchor=(
" | .recAdt id defn, v =>\n"
" match ownedValidInMem m true (.recAdt id defn) v with"
),
replacement=(
" | .recAdt _ _, _ =>\n"
" match (Except.ok () : Except FaultKind Unit) with"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_rec_refs_valid",
),
MirSemanticsGuard(
guard_id="bytes_v2_rec_walk_inline_self",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"recOwnedWalkV2 fails closed on an inline recursive occurrence"
),
anchor=(
" | _, .recSelf _, _ => .error .unsupported"
),
replacement=(
" | vis, .recSelf _, _ => .ok vis"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_rec_walk_inline_self",
),
MirSemanticsGuard(
guard_id="step_v2_rec_proj_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"stepProjectedTyV2 checks recursive struct field types"
),
anchor=(
" match unfoldRecV2 id defn with\n"
" | .struct_ _ fs =>\n"
" match getElem? fs idx with\n"
" | some t => if MirTy.beq t fTy then stepProjectedTyV2 t rest else none"
),
replacement=(
" match unfoldRecV2 id defn with\n"
" | .struct_ _ fs =>\n"
" match getElem? fs idx with\n"
" | some t => if MirTy.beq t fTy || true then stepProjectedTyV2 t rest else none"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rec_proj_ty",
),
MirSemanticsGuard(
guard_id="step_v2_rec_aggregate",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 builds a recursive struct aggregate from its unfolding"
),
anchor=(
" | .recAdt id defn =>\n"
" match unfoldRecV2 id defn with\n"
" | .struct_ _ fieldTys =>\n"
" if !MirTy.beq dstTy structTy then"
),
replacement=(
" | .recAdt id defn =>\n"
" match MirTy.unsupported with\n"
" | .struct_ _ fieldTys =>\n"
" if !MirTy.beq dstTy structTy then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rec_aggregate",
),
MirSemanticsGuard(
guard_id="step_v2_rec_aggregate_field_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 checks recursive struct aggregate operands against the unfolded fields"
),
anchor=(
" if !typedArgsMatchV2 typedVals fieldTys ||\n"
" !checkValV2List vs fieldTys then"
),
replacement=(
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rec_aggregate_field_ty",
),
MirSemanticsGuard(
guard_id="step_v2_rec_aggregate_dst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 requires a recursive struct aggregate's destination type"
),
anchor=(
" | .struct_ _ fieldTys =>\n"
" if !MirTy.beq dstTy structTy then"
),
replacement=(
" | .struct_ _ fieldTys =>\n"
" if false then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rec_aggregate_dst",
),
MirSemanticsGuard(
guard_id="step_v2_rec_mem_proj_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"projectMemoryLayoutV2 checks recursive struct field types"
),
anchor=(
" match unfoldRecV2 id defn with\n"
" | .struct_ l fs =>\n"
" match getElem? fs idx, getElem? l.fieldOffsets idx with\n"
" | some elemTy, some off =>\n"
" if !MirTy.beq elemTy fTy then"
),
replacement=(
" match unfoldRecV2 id defn with\n"
" | .struct_ l fs =>\n"
" match getElem? fs idx, getElem? l.fieldOffsets idx with\n"
" | some elemTy, some off =>\n"
" if !MirTy.beq elemTy fTy && false then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rec_mem_proj_ty",
),
MirSemanticsGuard(
guard_id="step_v2_downcast_none_undefined",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"projectMemoryPlaceV2 faults on the payload of an in-memory None"
),
anchor=(
" | .ok (some (.optionVal none)) | .ok none => .error .undefined"
),
replacement=(
" | .ok (some (.optionVal none)) | .ok none =>\n"
" projectMemoryPlaceV2 mem aid (base + off + someOff) inner [] rest"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_downcast_none_undefined",
),
MirSemanticsGuard(
guard_id="step_v2_downcast_niche_offset",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"optionSomeOffsetV2 puts a niche Option payload at offset 0"
),
anchor=(
" | .ref _ _ | .box _ => some 0"
),
replacement=(
" | .ref _ _ | .box _ => some 8"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_downcast_niche_offset",
),
MirSemanticsGuard(
guard_id="step_v2_downcast_tag_offset",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"optionSomeOffsetV2 puts a direct-tag Option payload after the tag"
),
anchor=(
" | some lay => some (Nat.pow 2 lay.alignLog2)"
),
replacement=(
" | some lay => some 0"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_downcast_tag_offset",
),
MirSemanticsGuard(
guard_id="step_v2_downcast_bool_unit",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"optionSomeOffsetV2 refuses Option<bool> and Option<()>"
),
anchor=(
" | .bool | .unit => none\n"
" | _ =>\n"
" if !isOptionPayloadSupportedV2 inner then"
),
replacement=(
" | _ =>\n"
" if !isOptionPayloadSupportedV2 inner then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_downcast_bool_unit",
),
MirSemanticsGuard(
guard_id="step_v2_downcast_vec_zst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"optionSomeOffsetV2 refuses the payload of Option<Vec<ZST>>"
),
anchor=(
" | some lay => if Nat.beq lay.size 0 then none else some 0"
),
replacement=(
" | some lay => some 0"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_downcast_vec_zst",
),
MirSemanticsGuard(
guard_id="step_v2_discriminant_deref_option",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 reads the discriminant of a projected Option"
),
anchor=(
" | .option _ =>\n"
" if !MirTy.beq dstTy (.int .isize true) then\n"
" .error .unsupported\n"
" else\n"
" evalOptionDiscriminantOfVal optVal locals1 mem1"
),
replacement=(
" | .option _ =>\n"
" if true then\n"
" .error .unsupported\n"
" else\n"
" evalOptionDiscriminantOfVal optVal locals1 mem1"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_discriminant_deref_option",
),
MirSemanticsGuard(
guard_id="step_v2_discriminant_local_option_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 requires an isize destination for an unprojected "
"immediate Option discriminant"
),
anchor=(
" | .option _ =>\n"
" if !MirTy.beq dstTy (.int .isize true) then\n"
" .error .unsupported\n"
" else\n"
" evalOptionDiscriminantOfVal optVal locals mem"
),
replacement=(
" | .option _ =>\n"
" if false then\n"
" .error .unsupported\n"
" else\n"
" evalOptionDiscriminantOfVal optVal locals mem"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_discriminant_local_option_ty",
),
MirSemanticsGuard(
guard_id="step_v2_discriminant_indirect_option_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalRvalueV2 requires an isize destination for an unprojected "
"in-memory Option discriminant"
),
anchor=(
" | .option _ =>\n"
" if !MirTy.beq dstTy (.int .isize true) then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirectV2 mem srcTy mplace with"
),
replacement=(
" | .option _ =>\n"
" if false then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirectV2 mem srcTy mplace with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_discriminant_indirect_option_ty",
),
MirSemanticsGuard(
guard_id="step_v2_downcast_field_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"projectMemoryPlaceV2 checks the downcast field type"
),
anchor=(
" if !MirTy.beq inner fTy then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirectV2 mem (.option inner) ⟨aid, base + off⟩ with"
),
replacement=(
" if false then\n"
" .error .unsupported\n"
" else\n"
" match loadIndirectV2 mem (.option inner) ⟨aid, base + off⟩ with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_downcast_field_ty",
),
MirSemanticsGuard(
guard_id="step_v2_read_indirect_field_downcast",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readPlaceV2 reads an Option payload below a field of an "
"indirect local"
),
anchor=(
" -- whole `Option` first (`projectMemoryPlaceV2`).\n"
" match projectMemoryPlaceV2 mem mplace.allocId mplace.offset baseTy\n"
" [] projs with"
),
replacement=(
" -- whole `Option` first (`projectMemoryPlaceV2`).\n"
" match projectMemoryPlaceV2 mem mplace.allocId mplace.offset baseTy\n"
" projs [] with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_indirect_downcast",
),
MirSemanticsGuard(
guard_id="step_v2_read_indirect_downcast",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readPlaceV2 reads an Option payload of an indirect local"
),
anchor=(
" .ok (fty, some fv, locals, mem)\n"
" | .indirect mplace =>\n"
" match projectMemoryPlaceV2 mem mplace.allocId mplace.offset baseTy\n"
" [] projs with"
),
replacement=(
" .ok (fty, some fv, locals, mem)\n"
" | .indirect mplace =>\n"
" match projectMemoryPlaceV2 mem mplace.allocId mplace.offset baseTy\n"
" projs [] with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_read_indirect_downcast",
),
MirSemanticsGuard(
guard_id="step_v2_downcast_ref_place",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"placeAddrV2 resolves a post-deref Option downcast in memory"
),
anchor=(
" match projectMemoryPlaceV2 mem aid p.offsetBytes.toNat pt [] rest with"
),
replacement=(
" match (Except.error k : Except FaultKind (MirTy × Nat)) with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_downcast_ref_place",
),
MirSemanticsGuard(
guard_id="step_v2_downcast_read_place",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"readDerefProjectedV2 resolves a post-deref Option downcast in memory"
),
anchor=(
" match projectMemoryPlaceV2 mem aid pv.offsetBytes.toNat pt [] rest with"
),
replacement=(
" match (Except.error k : Except FaultKind (MirTy × Nat)) with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_downcast_read_place",
),
MirSemanticsGuard(
guard_id="step_v2_downcast_promoted_place",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"placeAddrV2 resolves an Option downcast of an in-memory local"
),
anchor=(
" match projectMemoryPlaceV2 mem1 mplace.allocId mplace.offset localTy []\n"
" projs with"
),
replacement=(
" match (Except.error .unsupported : Except FaultKind (MirTy × Nat)) with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_downcast_promoted_place",
),
MirSemanticsGuard(
guard_id="step_v2_rec_imm_proj_ty",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"projectOneElemV2 checks recursive struct field types"
),
anchor=(
" match unfoldRecV2 id defn, v with\n"
" | .struct_ _ fs, .tuple vs =>\n"
" match getElem? fs idx, getElem? vs idx with\n"
" | some elemTy, some elemVal =>\n"
" if !MirTy.beq elemTy fTy then"
),
replacement=(
" match unfoldRecV2 id defn, v with\n"
" | .struct_ _ fs, .tuple vs =>\n"
" match getElem? fs idx, getElem? vs idx with\n"
" | some elemTy, some elemVal =>\n"
" if !MirTy.beq elemTy fTy && false then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rec_imm_proj_ty",
),
MirSemanticsGuard(
guard_id="step_v2_call_rec_wf",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"bodyCallAdmittedV2 rejects callees with ill-formed recursive types"
),
anchor=(
" !bodyHasNestedRefSignatureV2 callee &&\n"
" callee.locals.all (recTyWfV2 none)"
),
replacement=(
" !bodyHasNestedRefSignatureV2 callee &&\n"
" true"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_rec_wf",
),
MirSemanticsGuard(
guard_id="boundary_v2_rec_tys_admitted",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description=(
"BodyStaticAdmittedV2 rejects incoherent recursive struct types"
),
anchor=(
" bodyFakeAddressOfValidV2 body &&\n"
" !bodyHasNestedRefSignatureV2 body &&\n"
" body.locals.all isSupportedV2LocalTy &&\n"
" programRecTysAdmittedV2 p"
),
replacement=(
" bodyFakeAddressOfValidV2 body &&\n"
" !bodyHasNestedRefSignatureV2 body &&\n"
" body.locals.all isSupportedV2LocalTy &&\n"
" true"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_rec_tys_admitted",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_satisfies_post_requires_wf",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="SatisfiesPost requires WellFormed p q",
anchor=" WellFormed p q ∧ ∀ out : TerminalOut, Behavior p q out → post out",
replacement=" True ∧ ∀ out : TerminalOut, Behavior p q out → post out",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_satisfies_post_requires_wf",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_satisfies_post_enforces_post",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="SatisfiesPost enforces post on every terminal output",
anchor=" WellFormed p q ∧ ∀ out : TerminalOut, Behavior p q out → post out",
replacement=" WellFormed p q ∧ True",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_satisfies_post_enforces_post",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_static_admitted_pointer_width",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="singleBodyStaticAdmitted enforces 64-bit pointerWidthBits",
anchor=(
"noncomputable def singleBodyStaticAdmitted (p : Program) (body : Body) : Bool :=\n"
" Nat.beq p.pointerWidthBits 64 &&"
),
replacement=(
"noncomputable def singleBodyStaticAdmitted (p : Program) (body : Body) : Bool :=\n"
" true &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_static_admitted_pointer_width",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_static_admitted_profile_v1",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="singleBodyStaticAdmitted enforces mirProfileVersion = 1",
anchor=" Nat.beq p.mirProfileVersion 1 &&",
replacement=" true &&",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_static_admitted_profile_v1",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_static_admitted_nonempty_identity",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="singleBodyStaticAdmitted requires non-empty body.identity",
anchor=(
" Nat.beq p.mirProfileVersion 1 &&\n"
" !stringIsEmpty body.identity &&"
),
replacement=(
" Nat.beq p.mirProfileVersion 1 &&\n"
" true &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_static_admitted_nonempty_identity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_static_admitted_nonempty_blocks",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="singleBodyStaticAdmitted requires non-empty basicBlocks",
anchor=(
" Nat.beq p.mirProfileVersion 1 &&\n"
" !stringIsEmpty body.identity &&\n"
" !body.isExternal &&\n"
" !body.basicBlocks.isEmpty &&"
),
replacement=(
" Nat.beq p.mirProfileVersion 1 &&\n"
" !stringIsEmpty body.identity &&\n"
" !body.isExternal &&\n"
" true &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_static_admitted_nonempty_blocks",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_static_admitted_arg_count_bound",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="singleBodyStaticAdmitted requires argumentCount < locals.length",
anchor=(
" Nat.beq p.mirProfileVersion 1 &&\n"
" !stringIsEmpty body.identity &&\n"
" !body.isExternal &&\n"
" !body.basicBlocks.isEmpty &&\n"
" Nat.blt body.argumentCount body.locals.length &&"
),
replacement=(
" Nat.beq p.mirProfileVersion 1 &&\n"
" !stringIsEmpty body.identity &&\n"
" !body.isExternal &&\n"
" !body.basicBlocks.isEmpty &&\n"
" true &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_static_admitted_arg_count_bound",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="single_body_v1_rejects_external_stub",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="singleBodyStaticAdmitted rejects isExternal = true bodies",
anchor=(
" Nat.beq p.mirProfileVersion 1 &&\n"
" !stringIsEmpty body.identity &&\n"
" !body.isExternal &&\n"
" !body.basicBlocks.isEmpty &&"
),
replacement=(
" Nat.beq p.mirProfileVersion 1 &&\n"
" !stringIsEmpty body.identity &&\n"
" true &&\n"
" !body.basicBlocks.isEmpty &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_single_body_v1_rejects_external_stub",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_v2_rejects_external_stub",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="BodyStaticAdmittedV2 rejects isExternal = true bodies",
anchor=(
" Nat.beq p.mirProfileVersion 2 &&\n"
" !stringIsEmpty body.identity &&\n"
" !(body.isExternal || body.basicBlocks.isEmpty) &&"
),
replacement=(
" Nat.beq p.mirProfileVersion 2 &&\n"
" !stringIsEmpty body.identity &&\n"
" !body.basicBlocks.isEmpty &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_v2_rejects_external_stub",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="stub_boundary_v2_rejects_nonempty_blocks",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="StubBodyStaticAdmittedV2 requires empty basicBlocks",
anchor=(
" body.isExternal &&\n"
" body.basicBlocks.isEmpty &&\n"
" Nat.beq body.locals.length (body.argumentCount + 1) &&"
),
replacement=(
" body.isExternal &&\n"
" true &&\n"
" Nat.beq body.locals.length (body.argumentCount + 1) &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_stub_boundary_v2_rejects_nonempty_blocks",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="stub_boundary_v2_rejects_extra_locals",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="StubBodyStaticAdmittedV2 requires signature-only locals",
anchor=(
" body.isExternal &&\n"
" body.basicBlocks.isEmpty &&\n"
" Nat.beq body.locals.length (body.argumentCount + 1) &&"
),
replacement=(
" body.isExternal &&\n"
" body.basicBlocks.isEmpty &&\n"
" true &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_stub_boundary_v2_rejects_extra_locals",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_static_admitted_storage_bounds",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="singleBodyStaticAdmitted enforces storageAnnotationsInBounds",
anchor=(
" storageAnnotationsInBounds body &&\n"
" discriminantTypesValid body &&\n"
" castTypesValid body &&\n"
" assertConditionTypesValid body &&\n"
" body.locals.all isSupportedScalarOrUnitTy &&"
),
replacement=(
" true &&\n"
" discriminantTypesValid body &&\n"
" castTypesValid body &&\n"
" assertConditionTypesValid body &&\n"
" body.locals.all isSupportedScalarOrUnitTy &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_static_admitted_storage_bounds",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_static_admitted_discr_types",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="singleBodyStaticAdmitted enforces discriminantTypesValid",
anchor=(
" discriminantTypesValid body &&\n"
" castTypesValid body &&\n"
" assertConditionTypesValid body &&\n"
" body.locals.all isSupportedScalarOrUnitTy &&"
),
replacement=(
" true &&\n"
" castTypesValid body &&\n"
" assertConditionTypesValid body &&\n"
" body.locals.all isSupportedScalarOrUnitTy &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_static_admitted_discr_types",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_static_admitted_cast_types",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="singleBodyStaticAdmitted enforces castTypesValid",
anchor=(
" castTypesValid body &&\n"
" assertConditionTypesValid body &&\n"
" body.locals.all isSupportedScalarOrUnitTy &&"
),
replacement=(
" true &&\n"
" assertConditionTypesValid body &&\n"
" body.locals.all isSupportedScalarOrUnitTy &&"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_static_admitted_cast_types",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_static_admitted_local_types",
target_file="trusted/lean/Trusted/MirSemantics/State.lean",
target_module="Trusted/MirSemantics/State",
description="singleBodyStaticAdmitted enforces supported local types",
anchor=(
" body.locals.all isSupportedScalarOrUnitTy &&\n"
" callsAdmitted p body"
),
replacement=(
" true &&\n"
" callsAdmitted p body"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_static_admitted_local_types",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_body_verified_binds_body",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="BodyVerified binds body to p.bodies[defId]",
anchor=(
"noncomputable def BodyVerified (p : Program) (defId : DefId) (body : Body)\n"
" (safetyPre : List Val → Prop) : Prop :=\n"
" getElem? p.bodies defId = some body ∧"
),
replacement=(
"noncomputable def BodyVerified (p : Program) (defId : DefId) (body : Body)\n"
" (safetyPre : List Val → Prop) : Prop :=\n"
" True ∧"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_body_verified_binds_body",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_program_verified_entry_in_bounds",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="ProgramVerified enforces entryDefId < bodies.length",
anchor=(
" Nat.beq p.mirProfileVersion 1 = true ∧\n"
" !p.bodies.isEmpty = true ∧\n"
" Nat.blt p.entryDefId p.bodies.length = true ∧"
),
replacement=(
" Nat.beq p.mirProfileVersion 1 = true ∧\n"
" !p.bodies.isEmpty = true ∧\n"
" True ∧"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_program_verified_entry_in_bounds",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_program_verified_unique_identities",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="ProgramVerified enforces bodiesHaveUniqueIdentities",
anchor=(
" Nat.beq p.mirProfileVersion 1 = true ∧\n"
" !p.bodies.isEmpty = true ∧\n"
" Nat.blt p.entryDefId p.bodies.length = true ∧\n"
" bodiesHaveUniqueIdentities p.bodies = true ∧"
),
replacement=(
" Nat.beq p.mirProfileVersion 1 = true ∧\n"
" !p.bodies.isEmpty = true ∧\n"
" Nat.blt p.entryDefId p.bodies.length = true ∧\n"
" True ∧"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_program_verified_unique_identities",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_program_verified_checks_all_bodies",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="ProgramVerified requires BodyVerified on every body",
anchor=(
" (∀ (defId : DefId) (body : Body),\n"
" getElem? p.bodies defId = some body →\n"
" BodyVerified p defId body (specs.safety body.identity)) ∧"
),
replacement=" True ∧",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_program_verified_checks_all_bodies",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_program_verified_checks_property",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="ProgramVerified enforces specs.property p",
anchor=(
" BodyVerified p defId body (specs.safety body.identity)) ∧\n"
" specs.property p"
),
replacement=(
" BodyVerified p defId body (specs.safety body.identity)) ∧\n"
" True"
),
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_program_verified_checks_property",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_crate_theorem_requires_crate_scope",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="CrateTheorem enforces c.program.scope = .crate",
anchor=" c.program.scope = .crate ∧ ProgramVerified c.program c.specs",
replacement=" True ∧ ProgramVerified c.program c.specs",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_crate_theorem_requires_crate_scope",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="boundary_unit_theorem_requires_unit_scope",
target_file="trusted/lean/Trusted/MirSemantics/Boundary.lean",
target_module="Trusted/MirSemantics/Boundary",
description="UnitTheorem enforces c.program.scope = .unit",
anchor=" c.program.scope = .unit ∧ ProgramVerified c.program c.specs",
replacement=" True ∧ ProgramVerified c.program c.specs",
fixture_module="BoundaryRefutations",
theorem_name="refute_boundary_unit_theorem_requires_unit_scope",
needs_wf_helper=False,
),
# ------------------------------------------------------------------
# Trusted/MirSemantics/Contract.lean (23 contract & RB-index guards)
# ------------------------------------------------------------------
MirSemanticsGuard(
guard_id="contract_effective_safety_pre_unsafe_gate",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="effectiveSafetyPre ignores safetyPre on safe functions",
anchor=(
"noncomputable def FnContract.effectiveSafetyPre (c : FnContract)\n"
" (isUnsafe : Bool) (q : Query) : Prop :=\n"
" isUnsafe = true → c.safetyPre q"
),
replacement=(
"noncomputable def FnContract.effectiveSafetyPre (c : FnContract)\n"
" (isUnsafe : Bool) (q : Query) : Prop :=\n"
" c.safetyPre q"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_effective_safety_pre_unsafe_gate",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_effective_behavior_pre_safety",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="effectiveBehaviorPre includes effectiveSafetyPre",
anchor=(
"noncomputable def FnContract.effectiveBehaviorPre (c : FnContract)\n"
" (isUnsafe : Bool) (q : Query) : Prop :=\n"
" c.effectiveSafetyPre isUnsafe q ∧ c.behaviorPre q"
),
replacement=(
"noncomputable def FnContract.effectiveBehaviorPre (c : FnContract)\n"
" (isUnsafe : Bool) (q : Query) : Prop :=\n"
" True ∧ c.behaviorPre q"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_effective_behavior_pre_safety",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_effective_behavior_pre_behavior",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="effectiveBehaviorPre includes behaviorPre",
anchor=(
"noncomputable def FnContract.effectiveBehaviorPre (c : FnContract)\n"
" (isUnsafe : Bool) (q : Query) : Prop :=\n"
" c.effectiveSafetyPre isUnsafe q ∧ c.behaviorPre q"
),
replacement=(
"noncomputable def FnContract.effectiveBehaviorPre (c : FnContract)\n"
" (isUnsafe : Bool) (q : Query) : Prop :=\n"
" c.effectiveSafetyPre isUnsafe q ∧ True"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_effective_behavior_pre_behavior",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_safety_arg_pre_checks_pre",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="FnContract.safetyArgPre enforces c.safetyPre",
anchor=(
"noncomputable def FnContract.safetyArgPre (c : FnContract) : List Val → Prop :=\n"
" fun args => c.safetyPre { args := args }"
),
replacement=(
"noncomputable def FnContract.safetyArgPre (c : FnContract) : List Val → Prop :=\n"
" fun _ => True"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_safety_arg_pre_checks_pre",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_body_satisfied_binds_body",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="BodyContractSatisfied binds body to p.bodies[defId]",
anchor=(
"noncomputable def BodyContractSatisfied (p : Program) (defId : DefId)\n"
" (body : Body) (c : FnContract) : Prop :=\n"
" getElem? p.bodies defId = some body ∧"
),
replacement=(
"noncomputable def BodyContractSatisfied (p : Program) (defId : DefId)\n"
" (body : Body) (c : FnContract) : Prop :=\n"
" True ∧"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_body_satisfied_binds_body",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_body_satisfied_static_admitted",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="BodyContractSatisfied requires BodyStaticAdmitted unconditionally",
anchor=(
" getElem? p.bodies defId = some body ∧\n"
" BodyStaticAdmitted p body = true ∧"
),
replacement=(
" getElem? p.bodies defId = some body ∧\n"
" True ∧"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_body_satisfied_static_admitted",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_body_satisfied_enforces_safety_wf",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="BodyContractSatisfied requires WellFormed under effectiveSafetyPre",
anchor=" (c.effectiveSafetyPre body.isUnsafe q → WellFormed ep q) ∧",
replacement=" (c.effectiveSafetyPre body.isUnsafe q → True) ∧",
fixture_module="ContractRefutations",
theorem_name="refute_contract_body_satisfied_enforces_safety_wf",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_body_satisfied_post_return",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="BodyContractSatisfied enforces postReturn on normal return",
anchor=" | .returned retOut => c.postReturn q retOut",
replacement=" | .returned _ => True",
fixture_module="ContractRefutations",
theorem_name="refute_contract_body_satisfied_post_return",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_body_satisfied_forbids_abort",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="BodyContractSatisfied forbids .aborted outcomes",
anchor=" | .aborted _ => False) ∧",
replacement=" | .aborted _ => True) ∧",
fixture_module="ContractRefutations",
theorem_name="refute_contract_body_satisfied_forbids_abort",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_body_satisfied_terminates",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="BodyContractSatisfied forbids Diverges when terminates = true",
anchor=" (c.effects.terminates = true → ¬ Diverges ep q))",
replacement=" (c.effects.terminates = true → True))",
fixture_module="ContractRefutations",
theorem_name="refute_contract_body_satisfied_terminates",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_sig_matches_is_unsafe",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="bodyMatchesContractSignature checks body.isUnsafe == sig.isUnsafe",
anchor=" (body.isUnsafe == sig.isUnsafe) &&",
replacement=" true &&",
fixture_module="ContractRefutations",
theorem_name="refute_contract_sig_matches_is_unsafe",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_sig_matches_arg_count",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="bodyMatchesContractSignature checks argumentCount == sig.params.length",
anchor=" Nat.beq body.argumentCount sig.params.length &&",
replacement=" true &&",
fixture_module="ContractRefutations",
theorem_name="refute_contract_sig_matches_arg_count",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_sig_matches_params",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="bodyMatchesContractSignature checks parameter MirTy list equality",
anchor=" MirTy.beqList ((body.locals.drop 1).take body.argumentCount) sig.params &&",
replacement=" true &&",
fixture_module="ContractRefutations",
theorem_name="refute_contract_sig_matches_params",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_sig_matches_ret",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="bodyMatchesContractSignature checks return local MirTy equality",
anchor=(
" match body.locals with\n"
" | retTy :: _ => MirTy.beq retTy sig.ret\n"
" | [] => false"
),
replacement=(
" match body.locals with\n"
" | _ :: _ => true\n"
" | [] => false"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_sig_matches_ret",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_sig_rejects_empty_locals",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="bodyMatchesContractSignature rejects empty body.locals",
anchor=(
" match body.locals with\n"
" | retTy :: _ => MirTy.beq retTy sig.ret\n"
" | [] => false"
),
replacement=(
" match body.locals with\n"
" | retTy :: _ => MirTy.beq retTy sig.ret\n"
" | [] => true"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_sig_rejects_empty_locals",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_entry_matches_identity",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="bodySatisfiesContractEntry requires body.identity == e.identity",
anchor=" stringBeq body.identity e.identity = true ∧",
replacement=" True ∧",
fixture_module="ContractRefutations",
theorem_name="refute_contract_entry_matches_identity",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_entry_checks_signature",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="bodySatisfiesContractEntry checks e.signature when present",
anchor=(
" (match e.signature with\n"
" | none => True\n"
" | some sig => bodyMatchesContractSignature body sig = true) ∧"
),
replacement=" True ∧",
fixture_module="ContractRefutations",
theorem_name="refute_contract_entry_checks_signature",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_entry_require_inhabited",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="bodySatisfiesContractEntry requires ContractPreInhabited when requireInhabited = true",
anchor=" (e.requireInhabited = true → ContractPreInhabited body e.contract)",
replacement=" True",
fixture_module="ContractRefutations",
theorem_name="refute_contract_entry_require_inhabited",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_entries_satisfied_head",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="ContractEntriesSatisfied checks the head ContractEntry",
anchor=(
" | e :: rest =>\n"
" bodySatisfiesContractEntry p e ∧ ContractEntriesSatisfied p rest"
),
replacement=(
" | _ :: rest =>\n"
" True ∧ ContractEntriesSatisfied p rest"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_entries_satisfied_head",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_entries_satisfied_tail",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="ContractEntriesSatisfied recurses over remaining entries",
anchor=(
" | e :: rest =>\n"
" bodySatisfiesContractEntry p e ∧ ContractEntriesSatisfied p rest"
),
replacement=(
" | e :: _ =>\n"
" bodySatisfiesContractEntry p e ∧ True"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_entries_satisfied_tail",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_specs_rejects_bad_identities",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="ContractSpecs fails closed on empty or duplicate identities",
anchor=(
" property := fun p =>\n"
" (false = true) ∧ ContractEntriesSatisfied p entries }"
),
replacement=(
" property := fun p =>\n"
" (true = true) ∧ ContractEntriesSatisfied p entries }"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_specs_rejects_bad_identities",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_specs_safety_dispatch",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="ContractSpecs.safety enforces the matched entry's safetyArgPre",
anchor=(
" match contractEntryRbLookup tree id with\n"
" | some e => e.contract.safetyArgPre args\n"
" | none => True"
),
replacement=(
" match contractEntryRbLookup tree id with\n"
" | some _ => True\n"
" | none => True"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_specs_safety_dispatch",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="contract_specs_checks_entries",
target_file="trusted/lean/Trusted/MirSemantics/Contract.lean",
target_module="Trusted/MirSemantics/Contract",
description="ContractSpecs.property enforces ContractEntriesSatisfied",
anchor=(
" property := fun p =>\n"
" (true = true) ∧ ContractEntriesSatisfied p entries }"
),
replacement=(
" property := fun _ =>\n"
" (true = true) ∧ True }"
),
fixture_module="ContractRefutations",
theorem_name="refute_contract_specs_checks_entries",
sanity_module="ContractSanity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_rec_enter_owns_bytes",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"recEnterBufV2 only records visited AllocIds when cap * size > 0"
),
anchor=(
" | some lay => !Nat.beq (cap.toNat * lay.size) 0"
),
replacement=(
" | some _ => true"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_rec_enter_owns_bytes",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_owned_nested_alias",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"ownedValidInMem enforces allocation-ID disjointness across nested handles"
),
anchor=(
"noncomputable def ownedValidInMem (m : MemoryState) (isMut : Bool)\n"
" (ty : MirTy) (v : Val) : Except FaultKind Unit :=\n"
" recOwnedValidV2 m isMut ty v"
),
replacement=(
"noncomputable def ownedValidInMem (_m : MemoryState) (_isMut : Bool)\n"
" (_ty : MirTy) (_v : Val) : Except FaultKind Unit :=\n"
" .ok ()"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_owned_nested_alias",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_owned_array_alias",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"recOwnedWalkV2 threads visited AllocIds across array elements"
),
anchor=(
" recAllValsV2\n"
" (fun vis' v => recOwnedWalkV2 m isMut heapRec self vis' elem v)\n"
" vis vs"
),
replacement=(
" .ok vis"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_owned_array_alias",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_slice_owned_alias",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"refValidInMem threads visited AllocIds across owned-handle slice elements"
),
anchor=(
" recOwnedValidAtV2 m isMut\n"
" (m.allocations.length + 2) vis elem v"
),
replacement=(
" recOwnedValidAtV2 m isMut\n"
" (m.allocations.length + 2) [] elem v"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_slice_owned_alias",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_rec_handle_spans",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"ownedHandleAccessSpans unfolds .recAdt to emit top-level handle spans"
),
anchor=(
" | .recAdt j defn, v => ownedHandleRecAccessSpans j defn defn v"
),
replacement=(
" | .recAdt _ _, _ => []"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_rec_handle_spans",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_nested_owned_spans",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"valueAccessSpans includes strictly nested owned heap-buffer spans in m"
),
anchor=(
" if !tyHasNestedHeapHandleV2 ty then\n"
" refAccessSpans ty v\n"
" else\n"
" nestedOwnedAccessSpans m ty v ++ refAccessSpans ty v"
),
replacement=(
" refAccessSpans ty v"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_nested_owned_spans",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="bytes_v2_owned_zst_vec_cap_high_bit",
target_file="trusted/lean/Trusted/MirSemantics/Bytes.lean",
target_module="Trusted/MirSemantics/Bytes",
description=(
"recOwnedWalkV2 enforces Vec cap < 2^63 (RawVecInner.cap "
"UsizeNoHighBit) even for ZST elements"
),
anchor=(
" | some e' =>\n"
" -- Upstream `RawVecInner.cap : UsizeNoHighBit` requires `cap < 2^63`\n"
" -- even for zero-sized elements (`lay.size = 0`).\n"
" if !Nat.blt cap.toNat isizeMaxBytes then\n"
" .error .undefined"
),
replacement=(
" | some e' =>\n"
" if false then\n"
" .error .undefined"
),
fixture_module="BytesRefutations",
theorem_name="refute_bytes_v2_owned_zst_vec_cap_high_bit",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_rec_update_proj",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"updateValAtProjV2 unfolds .recAdt on immediate recursive struct field writes"
),
anchor=(
" | .recAdt id defn, .tuple vs, .field idx fTy :: rest, newVal =>\n"
" match unfoldRecV2 id defn with\n"
" | .struct_ _ fs =>\n"
" match getElem? fs idx, getElem? vs idx with\n"
" | some elemTy, some oldElem =>\n"
" if !MirTy.beq elemTy fTy then\n"
" .error .unsupported\n"
" else\n"
" match updateValAtProjV2 elemTy oldElem rest newVal with\n"
" | .error k => .error k\n"
" | .ok elem' =>\n"
" match setElem? vs idx elem' with\n"
" | some vs' => .ok (.tuple vs')\n"
" | none => .error .unsupported\n"
" | _, _ => .error .unsupported\n"
" | _ => .error .unsupported"
),
replacement=(
" | .recAdt _ _, .tuple _, .field _ _ :: _, _ => .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rec_update_proj",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_rec_norm_imm_proj_overlap",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"normalizeImmProjPathV2 unfolds .recAdt for copy-hazard overlap checks"
),
anchor=(
" | .recAdt id defn, .field idx fTy :: rest =>\n"
" match unfoldRecV2 id defn with\n"
" | .struct_ _ fs =>\n"
" match getElem? fs idx with\n"
" | some elemTy =>\n"
" if !MirTy.beq elemTy fTy then none\n"
" else (normalizeImmProjPathV2 elemTy rest).map (.field idx :: ·)\n"
" | none => none\n"
" | _ => none"
),
replacement=(
" | .recAdt _ _, .field _ _ :: _ => none"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_rec_norm_imm_proj_overlap",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_assign_hazard_option_some",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"checkAssignCopyHazardV2 rejects self-overlapping Option Some payload copies"
),
anchor=(
" | some someSpan =>\n"
" if copySpansOverlapV2 someSpan opSpan then\n"
" .error .undefined\n"
" else\n"
" .ok ()"
),
replacement=(
" | some _ => .ok ()"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_assign_hazard_option_some",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_src_span_slice_ptr",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"srcPlaceCopySpanV2 resolves runtime-indexed .slicePtr elements"
),
anchor=(
" | some (.slicePtr p len) =>\n"
" match pt with\n"
" | .slice elem =>\n"
" match resolveIndexProjsV2 bodyLocals locals mem rest with\n"
" | .error _ => none\n"
" | .ok rest' =>\n"
" match sliceElemAddrV2 mem elem p len.toNat rest' with\n"
" | .ok (leafTy, aid, off) =>\n"
" (layoutOfTyV2 leafTy).map (fun lay =>\n"
" .memRange aid off lay.size)\n"
" | .error _ => none\n"
" | _ => none"
),
replacement=" | some (.slicePtr _ _) => none",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_src_span_slice_ptr",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_agg_index_clobber",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"checkAggregateCopyHazardLoopV2 fails closed with .unsupported when "
"an earlier Aggregate field write overlaps a runtime .index local "
"read by a later operand"
),
anchor=(
" else if indexClobberedByEarlier then\n"
" .error .unsupported"
),
replacement=(
" else if false then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_agg_index_clobber",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_src_span_deref_index",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"srcPlaceCopySpanV2 resolves runtime .index projections below sized .deref"
),
anchor=(
" else\n"
" match resolveIndexProjsV2 bodyLocals locals mem rest with\n"
" | .error _ => none\n"
" | .ok rest' =>\n"
" match projectMemoryLayoutV2 pt rest' with"
),
replacement=(
" else\n"
" match (Except.ok rest : Except FaultKind (List ProjectionElem)) with\n"
" | .error _ => none\n"
" | .ok rest' =>\n"
" match projectMemoryLayoutV2 pt rest' with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_src_span_deref_index",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_src_span_deref_downcast",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"srcPlaceCopySpanV2 resolves downcast projections below sized .deref"
),
anchor=(
" | .error _ =>\n"
" match projectMemoryPlaceV2 mem aid pv.offsetBytes.toNat pt\n"
" [] rest' with\n"
" | .ok (leafTy, off) =>\n"
" (layoutOfTyV2 leafTy).map (fun lay =>\n"
" .memRange aid off lay.size)\n"
" | .error _ => none"
),
replacement=" | .error _ => none",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_src_span_deref_downcast",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_src_span_local_index",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"srcPlaceCopySpanV2 resolves runtime .index projections on non-deref locals"
),
anchor=(
" | projs =>\n"
" match resolveIndexProjsV2 bodyLocals locals mem projs with\n"
" | .error _ => none\n"
" | .ok projs' =>\n"
" match slot with"
),
replacement=(
" | projs =>\n"
" match (Except.ok projs : Except FaultKind (List ProjectionElem)) with\n"
" | .error _ => none\n"
" | .ok projs' =>\n"
" match slot with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_src_span_local_index",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_via_in_place_args",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallViaV2 refuses calls whose arguments trigger unmodeled "
"in-place passing (callInPlaceArgsV2)"
),
anchor=(
" if !(moveDefinitelyDisjoint args dst) then\n"
" .fault .unsupported\n"
" else if callInPlaceArgsV2 frame.locals args then\n"
),
replacement=(
" if !(moveDefinitelyDisjoint args dst) then\n"
" .fault .unsupported\n"
" else if false then\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_via_in_place_args",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_via_indirect_dst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallViaV2 refuses a call whose destination lives in memory "
"(localIsIndirectV2)"
),
anchor=(
" if !(moveDefinitelyDisjoint args dst) then\n"
" .fault .unsupported\n"
" else if callInPlaceArgsV2 frame.locals args then\n"
" .fault .unsupported\n"
" else if localIsIndirectV2 frame.locals dst.localId then\n"
),
replacement=(
" if !(moveDefinitelyDisjoint args dst) then\n"
" .fault .unsupported\n"
" else if callInPlaceArgsV2 frame.locals args then\n"
" .fault .unsupported\n"
" else if false then\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_via_indirect_dst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_via_ref_eq_negates",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalReturnToCallerV2 negates the callee's result for a "
"CallVia.refPartialEq true (ne) call"
),
anchor=(
" | .callVia (.refPartialEq negate) _ _ _ _ _, "
".bool b =>\n"
" .ok (.bool (if negate then !b else b))"
),
replacement=(
" | .callVia (.refPartialEq negate) _ _ _ _ _, "
".bool b =>\n"
" .ok (.bool b)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_via_ref_eq_negates",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_via_ref_eq_bool_sig",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallViaV2 refuses a CallVia.refPartialEq call whose callee "
"or destination is not bool"
),
anchor=(
" if !MirTy.beq retTy .bool || "
"!MirTy.beq dstTy .bool ||\n"
" !Nat.beq args.length 2 then"
),
replacement=(
" if false ||\n"
" !Nat.beq args.length 2 then"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_via_ref_eq_bool_sig",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_via_outer_ref_validity",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallViaV2 validates the whole &&A arguments of the "
"forwarding call as UB before dereferencing them"
),
anchor=(
" if !refsValidInMemList mem1 outerTys "
"outerVals ||\n"
" !spansPairwiseDisjoint\n"
" (refAccessSpansList outerTys outerVals)"
" then\n"
" .fault .undefined\n"
" else\n"
" match derefSharedRefArgsV2 mem1 outerArgs"
" with"
),
replacement=(
" if false ||\n"
" !spansPairwiseDisjoint\n"
" (refAccessSpansList outerTys outerVals)"
" then\n"
" .fault .undefined\n"
" else\n"
" match derefSharedRefArgsV2 mem1 outerArgs"
" with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_via_outer_ref_validity",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_via_deref_inner_arg",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"derefSharedRefArgsV2 passes the loaded inner &A (*a) to the "
"callee, not the outer &&A"
),
anchor=(
" | .ok vs => .ok ((.ref .shared pt, inner) :: vs)"
),
replacement=(
" | .ok vs => .ok ((.ref .shared pt, .ptr p) :: vs)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_via_deref_inner_arg",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_via_box_clone_writes_dst",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallViaV2 holds the newly allocated Box in dst while the "
"CallVia.boxClone callee runs"
),
anchor=(
" match writePlaceV2 body.locals "
"locals1 mem2 dst\n"
" (.box pointee) "
"(.boxPtr newPtr none) with"
),
replacement=(
" match (Except.ok (locals1, mem2) :\n"
" Except FaultKind\n"
" (List LocalSlot × MemoryState))"
" with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_via_box_clone_writes_dst",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_via_box_clone_ret_sig",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallViaV2 refuses a CallVia.boxClone call whose callee does "
"not return the pointee type"
),
anchor=(
" if !MirTy.beq retTy pointee || "
"!MirTy.beq dstTy (.box pointee) ||"
),
replacement=(
" if false || !MirTy.beq dstTy (.box pointee) ||"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_via_box_clone_ret_sig",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_via_box_clone_arg_pointee",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallViaV2 refuses a CallVia.boxClone argument &Box<T> whose "
"T is not the pointee type"
),
anchor=" if !MirTy.beq pt pointee then",
replacement=" if false then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_via_box_clone_arg_pointee",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_call_via_box_clone_zst_dangling",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"evalCallViaV2 gives a zero-sized CallVia.boxClone a dangling "
"box pointer instead of allocating"
),
anchor=(
" if Nat.beq lay.size 0 then\n"
" "
"(mem1, danglingAligned lay.alignLog2)"
),
replacement=(
" if false then\n"
" "
"(mem1, danglingAligned lay.alignLog2)"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_call_via_box_clone_zst_dangling",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_box_clone_store_checks_ret",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"storeBoxCloneResultV2 refuses a returned value that is not a "
"valid pointee"
),
anchor=(
" !dst.projection.isEmpty || "
"!checkValV2 retVal pointee then"
),
replacement=" !dst.projection.isEmpty || false then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_box_clone_store_checks_ret",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_box_clone_store_writes_result",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"storeBoxCloneResultV2 writes the callee's result into the "
"cloned Box's buffer"
),
anchor=(
" if Nat.beq lay.size 0 then\n"
" .ok mem\n"
" else\n"
" match p.allocId,"
),
replacement=(
" if true then\n"
" .ok mem\n"
" else\n"
" match p.allocId,"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_box_clone_store_writes_result",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deref_field_runs_glue",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop of a field through a mutable reference runs dropGlueV2"
),
anchor=" match dropGlueV2 mem leafTy v with",
replacement=" match (Except.ok mem : Except FaultKind MemoryState) with",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deref_field_runs_glue",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deref_field_deinit",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop of a field through a mutable reference deinitializes it"
),
anchor=" | .ok mem1 => deinitIndirectV2 mem1 leafTy leaf",
replacement=" | .ok mem1 => .ok mem1",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deref_field_deinit",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deref_field_bounds",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop through a mutable reference requires the whole pointee in bounds"
),
anchor=(
" if !a.live || !Mutability.beq a.mutability .mut ||\n"
" !isInBounds a pv.offsetBytes.toNat ptLay.size ||\n"
" !isAligned a pv.offsetBytes.toNat ptLay.alignLog2 then\n"
" .error .undefined\n"
" else\n"
" let leaf : MemPlace"
),
replacement=(
" if !a.live || !Mutability.beq a.mutability .mut ||\n"
" false ||\n"
" !isAligned a pv.offsetBytes.toNat ptLay.alignLog2 then\n"
" .error .undefined\n"
" else\n"
" let leaf : MemPlace"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deref_field_bounds",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deref_generic_pointee",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop through a reference to a non-handle pointee uses dropDerefPlaceV2"
),
anchor=" if !isDropHandleRefV2 body.locals place.localId then",
replacement=" if false then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deref_generic_pointee",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_deref_index_resolves",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop through a mutable reference resolves index locals first"
),
anchor=(
" | .ok resolved =>\n"
" match dropDerefPlaceV2 mem pt pv resolved with"
),
replacement=(
" | .ok resolved =>\n"
" match dropDerefPlaceV2 mem pt pv rest with"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_deref_index_resolves",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_tuple_field_runs_glue",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop of a tuple field runs dropGlueV2"
),
anchor=" match dropGlueV2 mem1 fTy v with",
replacement=" match (Except.ok mem1 : Except FaultKind MemoryState) with",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_tuple_field_runs_glue",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_tuple_field_moves",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop of a tuple field moves it out of the tuple"
),
anchor=" match readPlaceV2 bodyLocals locals mem true place with",
replacement=" match readPlaceV2 bodyLocals locals mem false place with",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_tuple_field_moves",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_tuple_field_no_glue",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Drop of a tuple field without drop glue faults"
),
anchor=" if !isSupportedV2LocalTy fTy || !tyNeedsDropV2 fTy then",
replacement=" if !isSupportedV2LocalTy fTy then",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_tuple_field_no_glue",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_local_place",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Drop of a field and element place of a local runs in memory",
anchor=" | _ :: _ => dropLocalPlaceV2 bodyLocals locals mem place\n",
replacement=" | _ :: _ => .error .unsupported\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_local_place",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_local_field",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Drop of a field of a struct local runs in memory",
anchor=" | _, _ => dropLocalPlaceV2 bodyLocals locals mem place\n",
replacement=" | _, _ => .error .unsupported\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_local_field",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_local_keeps_promotion",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Drop of a local's field keeps the local in its stack allocation",
anchor=(
" ⟨some mp.allocId, 0, .isize⟩ resolved with\n"
" | .ok mem2 => .ok (locals1, mem2)\n"
),
replacement=(
" ⟨some mp.allocId, 0, .isize⟩ resolved with\n"
" | .ok mem2 => .ok (locals, mem2)\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_local_keeps_promotion",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_local_index_resolves",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Drop of an element of a local resolves index locals first",
anchor=(
" match dropDerefPlaceV2 mem1 lt\n"
" ⟨some mp.allocId, 0, .isize⟩ resolved with\n"
),
replacement=(
" match dropDerefPlaceV2 mem1 lt\n"
" ⟨some mp.allocId, 0, .isize⟩\n"
" place.projection with\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_local_place",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_local_field",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A move out of a field of a struct local runs in memory",
anchor=(
" | _, _ => .error .unsupported\n"
" | _, _ => moveLocalPlaceV2 bodyLocals locals mem place\n"
),
replacement=(
" | _, _ => .error .unsupported\n"
" | _, _ => .error .unsupported\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_local_field",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_local_nested",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A move out of a nested field of a local runs in memory",
anchor=(
" moveTuplePathV2 locals mem fs ts idx fTy rest\n"
" | _, _ => moveLocalPlaceV2 bodyLocals locals mem place\n"
),
replacement=(
" moveTuplePathV2 locals mem fs ts idx fTy rest\n"
" | _, _ => .error .unsupported\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_local_nested",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_local_deinit",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A move out of a field of a local deinitializes the field",
anchor=(
" match deinitIndirectV2 mem1 leafTy leaf with\n"
" | .error k => .error k\n"
" | .ok mem2 => .ok (leafTy, some v, locals1, mem2)\n"
),
replacement=" .ok (leafTy, some v, locals1, mem1)\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_local_deinit",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_local_keeps_promotion",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A move out of a field of a local keeps the local in memory",
anchor=" | .ok mem2 => .ok (leafTy, some v, locals1, mem2)\n",
replacement=" | .ok mem2 => .ok (leafTy, some v, locals, mem2)\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_local_field",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_hazard_rec_struct_path",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Copy-hazard paths follow a recursive struct's unfolding",
anchor=(
" -- as for `projectMemoryLayoutV2`.\n"
" | .recAdt id defn, .field idx fTy :: rest =>\n"
" match unfoldRecV2 id defn with\n"
),
replacement=(
" -- as for `projectMemoryLayoutV2`.\n"
" | .recAdt id defn, .field idx fTy :: rest =>\n"
" match (MirTy.unit : MirTy) with\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_hazard_rec_struct_path",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_local_downcast_keeps_bytes",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A move out of a variant field of a local leaves its bytes",
anchor=" if projsHaveDowncastV2 place.projection then\n",
replacement=" if false then\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_local_downcast_keeps_bytes",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_local_downcast_only",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Only a move through a variant leaves the moved field's bytes",
anchor=" if projsHaveDowncastV2 place.projection then\n",
replacement=" if true then\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_local_deinit",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_local_downcast",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Drop of a variant field of a local runs its glue in place",
anchor=" if projsHaveDowncastV2 resolved then\n",
replacement=" if false then\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_local_downcast",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_tuple_dispatch",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A nested move out of a tuple local is projected from its value",
anchor=" moveTuplePathV2 locals mem fs ts idx fTy rest\n",
replacement=" moveLocalPlaceV2 bodyLocals locals mem place\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_tuple_dispatch",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_tuple_downcast_keeps",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A nested tuple move through a variant leaves the tuple in place",
anchor=(
" | .ok (leafTy, leafVal) =>\n"
" .ok (leafTy, some leafVal, locals, mem)\n"
),
replacement=(
" | .ok (leafTy, leafVal) =>\n"
" .ok (leafTy, some leafVal, [], mem)\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_tuple_downcast_keeps",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_tuple_requires_downcast",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A nested tuple move without a variant downcast fails closed",
anchor=" else if !projsHaveDowncastV2 rest then\n",
replacement=" else if false then\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_tuple_requires_downcast",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_tuple_field_or_downcast",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A nested tuple move admits only field and variant projections",
anchor=" if !projsFieldOrDowncastV2 rest then\n",
replacement=" if false then\n",
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_tuple_field_or_downcast",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_tuple_field_type",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A nested tuple move checks the type of the tuple field",
anchor=(
" if !MirTy.beq elemTy fTy then\n"
" .error .unsupported\n"
" else\n"
" match projectValFieldV2 elemTy elemVal rest with\n"
),
replacement=(
" if false then\n"
" .error .unsupported\n"
" else\n"
" match projectValFieldV2 elemTy elemVal rest with\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_tuple_field_type",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_move_option_heap_keeps_discriminant",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description=(
"Moving out of an immediate heap-owning Option local leaves its "
"discriminant intact for drop elaboration"
),
anchor=(
" if isMove then\n"
" if tyHasHeapHandleV2 baseTy then\n"
" .ok (fty, some fv, locals, mem)\n"
),
replacement=(
" if isMove then\n"
" if false then\n"
" .ok (fty, some fv, locals, mem)\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_move_option_heap_keeps_discriminant",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_drop_tuple_path",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="A drop of a field chain of a tuple local moves it out first",
anchor=(
" | .field _ _ :: _ =>\n"
" match getElem? bodyLocals place.localId, getElem? locals place.localId with\n"
),
replacement=(
" | [.field _ _] =>\n"
" match getElem? bodyLocals place.localId, getElem? locals place.localId with\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_drop_tuple_path",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="step_v2_hazard_indirect_variant_path",
target_file="trusted/lean/Trusted/MirSemantics/Step.lean",
target_module="Trusted/MirSemantics/Step",
description="Copy-hazard spans follow a variant field of an in-memory local",
anchor=(
" -- (`moveLocalPlaceV2`), reading the enum at the downcast.\n"
" if projsHaveDowncastV2 projs' then\n"
),
replacement=(
" -- (`moveLocalPlaceV2`), reading the enum at the downcast.\n"
" if false then\n"
),
fixture_module="StepRefutations",
theorem_name="refute_step_v2_hazard_indirect_variant_path",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_scalar_clone_prim_only",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"`CoreCallOp.scalarClone` restricts `ty` to primitive Copy scalars"
),
anchor=(
" if !isPrim || !MirTy.beq ty pt || !MirTy.beq dstTy ty then\n"
" .error .unsupported"
),
replacement=(
" if false || !MirTy.beq ty pt || !MirTy.beq dstTy ty then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_core_scalar_clone_prim_only",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_scalar_clone_ty_match",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"`CoreCallOp.scalarClone` checks receiver pointee and destination"
" match `ty`"
),
anchor=(
" if !isPrim || !MirTy.beq ty pt || !MirTy.beq dstTy ty then\n"
" .error .unsupported"
),
replacement=(
" if !isPrim then\n"
" .error .unsupported"
),
fixture_module="StepRefutations",
theorem_name="refute_core_scalar_clone_ty_match",
needs_wf_helper=False,
),
MirSemanticsGuard(
guard_id="core_scalar_clone_invalid_bytes",
target_file="trusted/lean/Trusted/MirSemantics/CoreContracts.lean",
target_module="Trusted/MirSemantics/CoreContracts",
description=(
"`CoreCallOp.scalarClone` faults `.undefined` when"
" `loadIndirectV2` returns `none`"
),
anchor=(
" match loadIndirectV2 m ty ⟨aid, p.offsetBytes.toNat⟩ with\n"
" | .error k => .error k\n"
" | .ok (some v) => .ok (v, m)\n"
" | .ok none => .error .undefined"
),
replacement=(
" match loadIndirectV2 m ty ⟨aid, p.offsetBytes.toNat⟩ with\n"
" | .error k => .error k\n"
" | .ok (some v) => .ok (v, m)\n"
" | .ok none => .ok (.bool false, m)"
),
fixture_module="StepRefutations",
theorem_name="refute_core_scalar_clone_invalid_bytes",
needs_wf_helper=False,
),
)
AUDIT_HEADER_GUARDS: tuple[AuditHeaderGuard, ...] = (
AuditHeaderGuard(
guard_id="audit_header_reject_lean_import",
target_file="trusted/audit/TrustedBoundary.lean",
description="isForbiddenPureImport rejects `import Lean` in target headers",
anchor=(
" let r := m.getRoot\n"
" r == `Lean || r == `Lake ||"
),
replacement=(
" let r := m.getRoot\n"
" false || r == `Lake ||"
),
negative_source="import Lean\n",
),
AuditHeaderGuard(
guard_id="audit_header_reject_lake_import",
target_file="trusted/audit/TrustedBoundary.lean",
description="isForbiddenPureImport rejects `import Lake` in target headers",
anchor=(
" let r := m.getRoot\n"
" r == `Lean || r == `Lake ||"
),
replacement=(
" let r := m.getRoot\n"
" r == `Lean || false ||"
),
negative_source="import Lake\n",
),
AuditHeaderGuard(
guard_id="audit_header_reject_init_system_import",
target_file="trusted/audit/TrustedBoundary.lean",
description="isForbiddenPureImport rejects `import Init.System.IO` in target headers",
anchor=" m == `Init.System || (`Init.System).isPrefixOf m ||",
replacement=" false ||",
negative_source="import Init.System.IO\n",
),
AuditHeaderGuard(
guard_id="audit_header_reject_std_uv_import",
target_file="trusted/audit/TrustedBoundary.lean",
description="isForbiddenPureImport rejects `import Std.Internal.UV` in target headers",
anchor=" m == `Std.Internal.UV || (`Std.Internal.UV).isPrefixOf m",
replacement=" false",
negative_source="import Std.Internal.UV\n",
),
AuditHeaderGuard(
guard_id="audit_header_reject_std_async_import",
target_file="trusted/audit/TrustedBoundary.lean",
description="isForbiddenPureImport rejects `import Std.Async.DNS` in target headers",
anchor=" m == `Std.Async || (`Std.Async).isPrefixOf m ||",
replacement=" false ||",
negative_source="import Std.Async.DNS\n",
),
AuditHeaderGuard(
guard_id="audit_header_reject_init_meta_import",
target_file="trusted/audit/TrustedBoundary.lean",
description="isForbiddenPureImport rejects `import Init.Meta.Defs` in target headers",
anchor=" m == `Init.Meta || (`Init.Meta).isPrefixOf m ||",
replacement=" false ||",
negative_source="import Init.Meta.Defs\n",
),
AuditHeaderGuard(
guard_id="spec_preflight_reject_lean_import",
target_file="trusted/audit/SpecPreflight.lean",
description="SpecPreflight isForbiddenPureImport rejects `import Lean` in target headers",
anchor=(
" let r := m.getRoot\n"
" r == `Lean || r == `Lake ||"
),
replacement=(
" let r := m.getRoot\n"
" false || r == `Lake ||"
),
negative_source="import Lean\n",
),
AuditHeaderGuard(
guard_id="spec_preflight_reject_lake_import",
target_file="trusted/audit/SpecPreflight.lean",
description="SpecPreflight isForbiddenPureImport rejects `import Lake` in target headers",
anchor=(
" let r := m.getRoot\n"
" r == `Lean || r == `Lake ||"
),
replacement=(
" let r := m.getRoot\n"
" r == `Lean || false ||"
),
negative_source="import Lake\n",
),
AuditHeaderGuard(
guard_id="spec_preflight_reject_init_system_import",
target_file="trusted/audit/SpecPreflight.lean",
description="SpecPreflight isForbiddenPureImport rejects `import Init.System.IO` in target headers",
anchor=" m == `Init.System || (`Init.System).isPrefixOf m ||",
replacement=" false ||",
negative_source="import Init.System.IO\n",
),
AuditHeaderGuard(
guard_id="spec_preflight_reject_std_uv_import",
target_file="trusted/audit/SpecPreflight.lean",
description="SpecPreflight isForbiddenPureImport rejects `import Std.Internal.UV` in target headers",
anchor=" m == `Std.Internal.UV || (`Std.Internal.UV).isPrefixOf m",
replacement=" false",
negative_source="import Std.Internal.UV\n",
),
AuditHeaderGuard(
guard_id="spec_preflight_reject_std_async_import",
target_file="trusted/audit/SpecPreflight.lean",
description="SpecPreflight isForbiddenPureImport rejects `import Std.Async.DNS` in target headers",
anchor=" m == `Std.Async || (`Std.Async).isPrefixOf m ||",
replacement=" false ||",
negative_source="import Std.Async.DNS\n",
),
AuditHeaderGuard(
guard_id="spec_preflight_reject_init_meta_import",
target_file="trusted/audit/SpecPreflight.lean",
description="SpecPreflight isForbiddenPureImport rejects `import Init.Meta.Defs` in target headers",
anchor=" m == `Init.Meta || (`Init.Meta).isPrefixOf m ||",
replacement=" false ||",
negative_source="import Init.Meta.Defs\n",
),
)
VALID_SPEC_BOUNDARY_FIXTURE_IDS: frozenset[str] = frozenset(
{
"spec_auto_implicit",
"spec_bang_ident",
"spec_dbg_trace",
"spec_uv_open",
"spec_default_or_ofNonempty",
"spec_value_of",
"spec_uv_open_only",
"spec_uv_open_renaming",
"spec_uv_export",
"spec_reserved_expected_ns",
"spec_reserved_tb_ns",
"spec_transitive_std_async",
"spec_export_reserved_alias",
"spec_open_renaming_reserved_alias",
}
)
VALID_TARGET_BOUNDARY_FIXTURE_IDS: frozenset[str] = frozenset(
{
"target_expected_true",
"target_bad_theorem_type",
"target_proof_sorry",
"target_impl_by",
"target_spec_transitive_dbg",
"target_dup_library",
"target_unsafe_rec_type_mismatch",
"target_foundation_propext_hijack",
"target_transitive_std_async",
"target_reserved_captured_in_spec",
"target_reserved_proof_in_spec",
"target_reserved_anneal_in_proof",
"target_anneal_helper_unknown_parent",
"target_reserved_tb_in_spec",
"target_spec_alias_opaque",
"target_spec_alias_extern",
"target_spec_alias_impl_by",
"target_spec_alias_unsafe",
"target_spec_alias_partial",
"target_spec_alias_axiom",
"target_spec_autoparam_ref",
"target_spec_alias_forbidden",
"target_cap_alias_trusted_root",
"target_cap_alias_reserved_root",
"target_cap_alias_anneal_root",
"target_companion_extra_const",
"target_companion_imports_mismatch",
"target_companion_const_mismatch",
"target_root_prefixed_alias",
"target_spec_bad_alias_name",
"target_alias_role_edge",
"target_source_root_trusted_const",
"target_proof_root_trusted_const",
"target_nested_private_reserved_const",
"target_sealed_admission",
}
)
VALID_AUDIT_BOUNDARY_FIXTURE_IDS: frozenset[str] = frozenset(
{
"audit_non_auto_syntax",
"audit_obf_auto_syntax",
"audit_bad_tactic_auto_syntax",
"audit_preresolved_auto_syntax",
"audit_private_preresolved_auto_syntax",
"audit_private_mod_preresolved_auto_syntax",
"audit_multi_root_preresolved_auto_syntax",
"audit_lean_root_const",
"audit_disallowed_autoparam_tactic",
"audit_export_trusted_alias",
"audit_export_reserved_alias",
"audit_export_forbidden_alias",
"audit_export_role_edge",
"audit_export_meta_target",
"audit_export_opaque_target",
"audit_export_unsafe_target",
"audit_root_trusted_const",
"audit_target_decl_root",
"audit_panic_const",
"audit_panic_preresolved_auto_syntax",
"audit_export_panic_alias",
"audit_ptr_const",
}
)
AUDIT_BOUNDARY_GUARDS: tuple[AuditBoundaryGuard, ...] = (
AuditBoundaryGuard(
guard_id="spec_preflight_reject_auto_implicit",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="validateSpecSetOption rejects `set_option autoImplicit true`",
anchor=' else\n fail s!"unsupported option {optName} in specification"',
replacement=" else\n pure ()",
fixture_id="spec_auto_implicit",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_bang_ident",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="inspectSpecSyntax rejects bang helpers like `List.head!`",
anchor="if hasForbiddenSpecIdentComponent cand || hasBangComponent cand then",
replacement="if hasForbiddenSpecIdentComponent cand then",
fixture_id="spec_bang_ident",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_dbg_trace",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description=(
"inspectSpecSyntax rejects `dbgTrace` identifier references"
),
anchor=(
"if forbiddenSpecIdentifiers.contains cand then\n"
' fail s!"disallowed identifier {val} in specification"'
),
replacement=(
"if false then\n"
' fail s!"disallowed identifier {val} in specification"'
),
fixture_id="spec_dbg_trace",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_uv_open",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description=(
"rejectForbiddenSpecNamespace blocks `open Std.Internal.UV`"
),
anchor=(
"def rejectForbiddenSpecNamespace (how : String) (ns : Name) : "
"IO Unit := do\n"
" if isForbiddenPureNamespace ns (banLeanRoot := true) then"
),
replacement=(
"def rejectForbiddenSpecNamespace (how : String) (ns : Name) : "
"IO Unit := do\n"
" if false then"
),
fixture_id="spec_uv_open",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_expected_mismatch",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"targetAudit enforces Expected isDefEq canonical root"
),
anchor=(
' requireKernelEquality "compiled Expected comparison"\n'
' "compiled Expected body differs from the canonical root"\n'
" (Kernel.isDefEq checkedEnv {} expectedBody canonical)"
),
replacement=" pure ()",
fixture_id="target_expected_true",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_theorem_type",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"targetAudit enforces proof theorem type isDefEq canonical root"
),
anchor=(
' requireKernelEquality "target theorem type comparison"\n'
' "target theorem type differs from Expected"\n'
" (Kernel.isDefEq checkedEnv {} theoremInfo.type canonical)"
),
replacement=" pure ()",
fixture_id="target_bad_theorem_type",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_proof_sorry",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"runTargetClosurePhase blocks sorryAx in Proof without allowSorry"
),
anchor=(
"if !inPhase1 && allowSorryInProof &&\n"
" role == .source .proof && "
"!phase1Closure.contains n then"
),
replacement=(
"if !inPhase1 &&\n"
" role == .source .proof && "
"!phase1Closure.contains n then"
),
fixture_id="target_proof_sorry",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_compiler_override",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"targetAudit rejects @[implemented_by] on logical dependencies"
),
anchor=(
"if sourceOverrides.implementedBy.contains n ||\n"
" sourceOverrides.externDecls.contains n then"
),
replacement="if sourceOverrides.externDecls.contains n then",
fixture_id="target_impl_by",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_transitive_spec_dbg",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"targetAudit enforces transitive spec ban over Model helpers"
),
anchor=(
"if isForbiddenSpecTransitiveConst n then\n"
' fail s!"specification transitively references disallowed '
'constant {n}"'
),
replacement=(
"if false then\n"
' fail s!"specification transitively references disallowed '
'constant {n}"'
),
fixture_id="target_spec_transitive_dbg",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_dup_library",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"verifyModuleHeaderInventory rejects intra-module duplicates"
),
anchor=(
" if modSeen.contains ci.name then\n"
' fail s!"duplicate {dupLabel} {ci.name}"'
),
replacement=(
" if false then\n"
' fail s!"duplicate {dupLabel} {ci.name}"'
),
fixture_id="target_dup_library",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_unsafe_rec_type_mismatch",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"pairedSpecUnsafeRecParent? checks _unsafe_rec type and "
"levelParams"
),
anchor=(
"def sameUnsafeRecHeader (unsafeCi parentCi : ConstantInfo) : "
"Bool :=\n"
" unsafeCi.type == parentCi.type &&\n"
" unsafeCi.levelParams == parentCi.levelParams"
),
replacement=(
"def sameUnsafeRecHeader (unsafeCi parentCi : ConstantInfo) : "
"Bool :=\n"
" true"
),
fixture_id="target_unsafe_rec_type_mismatch",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_foundation_propext_hijack",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"targetAudit foundation loop rejects subsumed propext theorem"
),
anchor=(
" if !sameConstantShape stored ci then\n"
" unless sameRealizedThmHeader stored ci do\n"
' fail s!"stored target declaration differs '
'{ci.name}"\n'
" pendingSourceAlternates :=\n"
" pendingSourceAlternates.push (none, stored, ci)"
),
replacement=" let _ := (stored, ci)",
fixture_id="target_foundation_propext_hijack",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_default_or_ofNonempty",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="forbiddenSpecTermKinds rejects `default_or_ofNonempty% unsafe`",
anchor=(
" `Lean.Parser.Term.throwNamedErrorAtMacro,\n"
" `Lean.Parser.Term.defaultOrOfNonempty,"
),
replacement=" `Lean.Parser.Term.throwNamedErrorAtMacro,",
fixture_id="spec_default_or_ofNonempty",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_value_of",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="forbiddenSpecTermKinds rejects `value_of%`",
anchor=(
" `Lean.Parser.Term.defaultOrOfNonempty,\n"
" `Lean.Parser.Term.valueOf,"
),
replacement=" `Lean.Parser.Term.defaultOrOfNonempty,",
fixture_id="spec_value_of",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_open_only_uv",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="validateSpecOpenDecl openOnly checks dotted `Std.Internal (UV.Loop.alive)`",
anchor=(
" for itemId in itemIds do\n"
' checkSpecQualifiedItem "open" ns itemId\n'
" ods := OpenDecl.explicit itemId (ns ++ itemId) :: ods"
),
replacement=(
" for itemId in itemIds do\n"
" ods := OpenDecl.explicit itemId (ns ++ itemId) :: ods"
),
fixture_id="spec_uv_open_only",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_open_renaming_uv",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="validateSpecOpenDecl openRenaming checks `UV.Loop.alive -> uvAlive`",
anchor=(
" for (fromId, toId) in pairs do\n"
' checkSpecQualifiedItem "open" ns fromId\n'
" if parserEnv.isNamespace ns then\n"
" ods := OpenDecl.explicit toId (ns ++ fromId) :: ods\n"
" added := true\n"
" if !added then\n"
" let stripped := nsId.replacePrefix rootNamespace .anonymous\n"
" if pairs.isEmpty then\n"
' rejectForbiddenSpecNamespace "open" stripped\n'
" for (fromId, toId) in pairs do\n"
' checkSpecQualifiedItem "open" stripped fromId\n'
" ods := OpenDecl.explicit toId (stripped ++ fromId) :: ods"
),
replacement=(
" for (fromId, toId) in pairs do\n"
" if parserEnv.isNamespace ns then\n"
" ods := OpenDecl.explicit toId (ns ++ fromId) :: ods\n"
" added := true\n"
" if !added then\n"
" let stripped := nsId.replacePrefix rootNamespace .anonymous\n"
" if pairs.isEmpty then\n"
' rejectForbiddenSpecNamespace "open" stripped\n'
" for (fromId, toId) in pairs do\n"
" ods := OpenDecl.explicit toId (stripped ++ fromId) :: ods"
),
fixture_id="spec_uv_open_renaming",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_export_uv",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="validateSpecExport checks `export Std.Internal (UV.Loop.alive)`",
anchor=(
" for itemId in itemIds do\n"
' checkSpecQualifiedItem "export" ns itemId'
),
replacement=" for _ in itemIds do\n pure ()",
fixture_id="spec_uv_export",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_reserved_expected_ns",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="forbiddenSpecDeclRootNamespaces reserves `Expected` and `Captured`",
anchor=" `Trusted, `Anneal, `Proof, `Expected, `Captured,",
replacement=" `Trusted, `Anneal, `Proof, `Captured,",
fixture_id="spec_reserved_expected_ns",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_reserved_tb_ns",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="forbiddenSpecDeclRootNamespaces reserves `SpecPreflight` and `TrustedBoundary`",
anchor=" `SpecPreflight, `TrustedBoundary, `Init, `Std,",
replacement=" `Init, `Std,",
fixture_id="spec_reserved_tb_ns",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_transitive_std_async",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="preflightSpecs rejects transitive `Std.Async.*` library admission",
anchor=(
" for lib in libraries do\n"
" if isForbiddenTransitiveLibrary lib then\n"
' fail s!"disallowed transitive sysroot import {lib} in specification"'
),
replacement=" for _ in libraries do\n pure ()",
fixture_id="spec_transitive_std_async",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_transitive_std_async",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit rejects transitive `Std.Async.*` library admission",
anchor=(
" for lib in libraries do\n"
" if isForbiddenTransitiveLibrary lib then\n"
' fail s!"disallowed transitive sysroot import {lib} in target"'
),
replacement=" for _ in libraries do\n pure ()",
fixture_id="target_transitive_std_async",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_reserved_captured_in_spec",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="isReservedTargetRootForbidden rejects `Captured.*` outside capture role",
anchor=(
" if userRoot == `Captured then\n"
" targetRole != .capture &&\n"
" !isRealizedOrCompilerHelper env allMatchers isCaptureConst ci\n"
" allowUnimportedProofSparse"
),
replacement=" if userRoot == `Captured then\n false",
fixture_id="target_reserved_captured_in_spec",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_reserved_proof_in_spec",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"isReservedTargetRootForbidden rejects `Proof.*` outside authored "
"proof role"
),
anchor=(
" else if userRoot == `Proof then\n"
" targetRole != .proof || isAnnealModuleName modName"
),
replacement=" else if userRoot == `Proof then\n false",
fixture_id="target_reserved_proof_in_spec",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_reserved_anneal_in_authored",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"isReservedTargetRootForbidden rejects `Anneal.*` outside bundled "
"theory modules, including unreferenced homonyms in authored proofs"
),
anchor=(
" else if userRoot == `Anneal then\n"
" -- `Anneal.*` belongs to bundled theory (`TargetRole::Proof` modules"
),
replacement=(
" else if userRoot == `Anneal then\n"
" false &&\n"
" -- `Anneal.*` belongs to bundled theory (`TargetRole::Proof` modules"
),
fixture_id="target_reserved_anneal_in_proof",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_anneal_helper_unknown_parent",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"isBundledTheoryHelper exempts helper-shaped `Anneal.*` theorems "
"only when their parent is an imported public bundled theory "
"declaration"
),
anchor=(
" | .thmInfo _, .str parent suffix =>\n"
" (isBundledDef parent && isBundledTheoryDefHelperSuffix suffix) ||\n"
" (isBundledCongrParent parent && isBundledTheoryCongrHelperSuffix suffix)"
),
replacement=(
" | .thmInfo _, .str parent suffix =>\n"
" ((parent == parent) && isBundledTheoryDefHelperSuffix suffix) ||\n"
" ((parent == parent) && isBundledTheoryCongrHelperSuffix suffix)"
),
fixture_id="target_anneal_helper_unknown_parent",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_reserved_tb_in_spec",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="reservedKernelRoots blocks `SpecPreflight` and `TrustedBoundary` in compiled target oleans",
anchor=(
" `Nonempty, `Ordering, `Rat, `Except, `EStateM, `StateM,\n"
" `Expected, `Captured, `Proof, `IncorrectnessCheck, "
"`IncorrectnessExpected,\n"
" `SpecPreflight, `TrustedBoundary]"
),
replacement=(
" `Nonempty, `Ordering, `Rat, `Except, `EStateM, `StateM,\n"
" `Expected, `Captured, `Proof, `IncorrectnessCheck, "
"`IncorrectnessExpected]"
),
fixture_id="target_reserved_tb_in_spec",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_spec_alias_opaque",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit aliasExtension scan rejects exported `opaque` alias in Spec",
anchor=(
" if targetCi matches .opaqueInfo _ &&\n"
" !(targetOriginRole == .foundation &&\n"
" allowedSystemPlatformDecls.contains targetName) then"
),
replacement=" if false then",
fixture_id="target_spec_alias_opaque",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_spec_alias_extern",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit aliasExtension scan rejects exported `@[extern]` alias in Spec",
anchor=(
" if targetOv.externDecls.contains targetName ||\n"
" targetOv.implementedBy.contains targetName then"
),
replacement=(
" if false ||\n"
" targetOv.implementedBy.contains targetName then"
),
fixture_id="target_spec_alias_extern",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_spec_alias_impl_by",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit aliasExtension scan rejects exported `@[implemented_by]` alias in Spec",
anchor=(
" if targetOv.externDecls.contains targetName ||\n"
" targetOv.implementedBy.contains targetName then"
),
replacement=(
" if targetOv.externDecls.contains targetName ||\n"
" false then"
),
fixture_id="target_spec_alias_impl_by",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_spec_alias_unsafe",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit aliasExtension scan rejects exported `unsafe` declaration",
anchor=" if targetCi.isUnsafe then",
replacement=" if false then",
fixture_id="target_spec_alias_unsafe",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_spec_alias_partial",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit aliasExtension scan rejects exported `partial` declaration in Spec",
anchor=" if targetCi.isPartial then",
replacement=" if false then",
fixture_id="target_spec_alias_partial",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_spec_alias_axiom",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit aliasExtension scan rejects exported unapproved axiom in Spec",
anchor=(
" if targetCi matches .axiomInfo _ &&\n"
" !axiomPolicy.contains\n"
" (targetName.toString, targetOrig.toString) then"
),
replacement=" if false then",
fixture_id="target_spec_alias_axiom",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_spec_autoparam_ref",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit Phase 1 rejects direct `autoParam` references in Spec",
anchor=(
" if isLeanSyntaxConst dep || isPanicSpecConst dep || "
"isAutoParamConst dep then"
),
replacement=(
" if isLeanSyntaxConst dep || isPanicSpecConst dep then"
),
fixture_id="target_spec_autoparam_ref",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_spec_alias_forbidden",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit aliasExtension scan rejects exported panic/disallowed alias in Spec",
anchor=(
" if isForbiddenSpecTransitiveConst targetName ||\n"
" isLeanSyntaxConst targetName ||\n"
" isPanicSpecConst targetName ||\n"
" isAutoParamConst targetName then"
),
replacement=(
" if isForbiddenSpecTransitiveConst targetName ||\n"
" isLeanSyntaxConst targetName ||\n"
" false ||\n"
" isAutoParamConst targetName then"
),
fixture_id="target_spec_alias_forbidden",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_cap_alias_trusted_root",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit aliasExtension scan rejects `Trusted`-root alias outside Model",
anchor=(
" if targetRole != TargetRole.model && aliasRoot == `Trusted then\n"
' fail (s!"non-model target module {m.module} cannot export " ++\n'
' s!"alias {aliasName} in Trusted namespace")'
),
replacement=(
" if false then\n"
' fail (s!"non-model target module {m.module} cannot export " ++\n'
' s!"alias {aliasName} in Trusted namespace")'
),
fixture_id="target_cap_alias_trusted_root",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_cap_alias_reserved_root",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit aliasExtension scan rejects reserved-root alias outside owning role",
anchor=(
" if badAliasReserved then\n"
' fail (s!"target module {m.module} cannot export alias " ++\n'
' s!"{aliasName} in reserved kernel namespace {aliasRoot}")'
),
replacement=(
" if false then\n"
' fail (s!"target module {m.module} cannot export alias " ++\n'
' s!"{aliasName} in reserved kernel namespace {aliasRoot}")'
),
fixture_id="target_cap_alias_reserved_root",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_cap_alias_anneal_root",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"targetAudit aliasExtension scan rejects `Anneal`-root alias "
"outside bundled theory modules"
),
anchor=(
" else if aliasRoot == `Anneal then\n"
" targetRole != TargetRole.proof || !isAnnealModuleName m.module"
),
replacement=(
" else if aliasRoot == `Anneal then\n"
" false"
),
fixture_id="target_cap_alias_anneal_root",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_non_auto_syntax",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAutoParamAndMeta rejects non-`_auto_<N>` `Lean.Syntax` constants",
anchor=(
" unless isAutoParamAuxName ci.name do\n"
' fail s!"disallowed Lean.Syntax declaration {ci.name} in {m.module}"'
),
replacement=" let _ := ci.name",
fixture_id="audit_non_auto_syntax",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_non_literal_auto_syntax",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAutoParamAndMeta rejects obfuscated non-literal `_auto_<N>` bodies",
anchor=(
" let some stx := decodePureAutoSyntax? val\n"
' | fail (s!"disallowed non-literal autoParam tactic {ci.name} in " ++\n'
' s!"{m.module}")\n'
" inspectSyntax allowedTheorySyntaxKinds stx (requirePrelude := false)\n"
" (currNs := effMod) (openDecls := []) (checkPureRefs := true)\n"
" inspectDecodedAutoPreresolved stx"
),
replacement=" let _ := (val, effMod)",
fixture_id="audit_obf_auto_syntax",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_bad_tactic_auto_syntax",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAutoParamAndMeta runs inspectSyntax on decoded `_auto_<N>` tactics",
anchor=(
" inspectSyntax allowedTheorySyntaxKinds stx (requirePrelude := false)\n"
" (currNs := effMod) (openDecls := []) (checkPureRefs := true)\n"
" inspectDecodedAutoPreresolved stx"
),
replacement=" let _ := (stx, effMod)",
fixture_id="audit_bad_tactic_auto_syntax",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_preresolved_auto_syntax",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAutoParamAndMeta runs inspectDecodedAutoPreresolved on `_auto_<N>` tactics",
anchor=" inspectDecodedAutoPreresolved stx",
replacement=" pure ()",
fixture_id="audit_preresolved_auto_syntax",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_private_preresolved_auto_syntax",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="inspectDecodedAutoPreresolved normalizes private-mangled names before namespace checks",
anchor=" let u := stripRootAndPrivatePrefixes c0",
replacement=" let u := stripLeadingRootPrefix c0",
fixture_id="audit_private_preresolved_auto_syntax",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_private_mod_preresolved_auto_syntax",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="inspectDecodedAutoPreresolved rejects private-mangled names from forbidden modules",
anchor=" if hasEmbeddedRootOrScope || privModForbidden ||",
replacement=" if hasEmbeddedRootOrScope ||",
fixture_id="audit_private_mod_preresolved_auto_syntax",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_multi_root_preresolved_auto_syntax",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="inspectDecodedAutoPreresolved strips arbitrary leading `_root_` prefixes and rejects embedded `_root_`",
anchor=(
" let c0 := stripLeadingRootPrefix cand\n"
" let hasEmbeddedRootOrScope :=\n"
" c0.isAnonymous || c0.hasMacroScopes ||\n"
" c0.components.any (· == rootNamespace)"
),
replacement=(
" let c0 := cand.replacePrefix rootNamespace .anonymous\n"
" let hasEmbeddedRootOrScope := c0.isAnonymous || c0.hasMacroScopes"
),
fixture_id="audit_multi_root_preresolved_auto_syntax",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_lean_root_const",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="isForbiddenRepoMetaConst rejects root `Lean.*` constants via banLeanRoot := true",
anchor=(
" u == `Init.Meta || (`Init.Meta).isPrefixOf u ||\n"
" isForbiddenPureNamespace u (banLeanRoot := true)"
),
replacement=(
" u == `Init.Meta || (`Init.Meta).isPrefixOf u ||\n"
" isForbiddenPureNamespace u (banLeanRoot := false)"
),
fixture_id="audit_lean_root_const",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_disallowed_autoparam_tactic",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="checkRepoExprAutoAndMeta rejects autoParam applications referencing unvalidated tactics",
anchor=(
" unless validatedAutos.contains tacName ||\n"
" (isAutoParamAuxName tacName && isFoundationAuto tacName) do"
),
replacement=" if false then",
fixture_id="audit_disallowed_autoparam_tactic",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_export_reserved_alias",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="validateSpecExport rejects `export` creating aliases in reserved/forbidden namespaces",
anchor=(
" for itemId in itemIds do\n"
' validateSpecAliasTarget "export" (currNs ++ itemId)'
),
replacement=" let _ := (currNs, itemIds)",
fixture_id="spec_export_reserved_alias",
),
AuditBoundaryGuard(
guard_id="spec_preflight_reject_open_renaming_reserved_alias",
target_file="trusted/audit/TrustedBoundary.lean",
mode="spec-preflight",
description="validateSpecOpenDecl openRenaming rejects reserved/forbidden `toId` aliases",
anchor=' validateSpecAliasTarget "open renaming" toId',
replacement=" let _ := toId",
fixture_id="spec_open_renaming_reserved_alias",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_trusted_alias",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAliases rejects `Trusted.*` aliases exported by non-Trusted modules",
anchor=(
" if !isTrusted && aliasRoot == `Trusted then\n"
' fail (s!"non-Trusted module {m} cannot export alias {aliasName} " ++\n'
' "in Trusted namespace")'
),
replacement=" if false then\n pure ()",
fixture_id="audit_export_trusted_alias",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_reserved_alias",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAliases rejects reserved-kernel-root aliases",
anchor=(
" if kernelAcceleratedNames.contains aliasUser ||\n"
" reservedKernelRoots.contains aliasRoot ||\n"
" reservedRepoTargetDeclRoots.contains aliasRoot then\n"
' fail (s!"repository module {m} cannot export alias {aliasName} " ++\n'
' s!"in reserved kernel namespace {aliasRoot}")'
),
replacement=" if false then\n pure ()",
fixture_id="audit_export_reserved_alias",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_forbidden_alias",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAliases rejects forbidden pure identifier/namespace aliases",
anchor=(
" if forbiddenPureIdentifiers.contains aliasUser ||\n"
" isForbiddenRepoPanicRef aliasUser ||\n"
" aliasUser == `autoParam || aliasUser == `optParam ||\n"
" isForbiddenPureNamespace aliasUser (banLeanRoot := true) then\n"
' fail s!"disallowed export alias {aliasName} in {m}"'
),
replacement=" if false then\n pure ()",
fixture_id="audit_export_forbidden_alias",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_target_decl_root",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description=(
"validateRepoConstant rejects target specification/refutation "
"root declarations in repository modules"
),
anchor=(
" if kernelAcceleratedNames.contains userName ||\n"
" reservedRepoTargetDeclRoots.contains userRoot ||"
),
replacement=(
" if kernelAcceleratedNames.contains userName ||\n"
" false ||"
),
fixture_id="audit_target_decl_root",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_panic_const",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description=(
"isForbiddenRepoMetaConst rejects runtime panic references in "
"compiled repository declarations"
),
anchor=(
" forbiddenPureIdentifiers.contains u || "
"isForbiddenRepoPanicRef u ||"
),
replacement=" forbiddenPureIdentifiers.contains u || false ||",
fixture_id="audit_panic_const",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_panic_preresolved_auto",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description=(
"inspectDecodedAutoPreresolved rejects runtime panic and bang "
"preresolutions in `_auto_<N>` tactics"
),
anchor=(
" forbiddenPureIdentifiers.contains u ||\n"
" isForbiddenRepoPanicRef u ||"
),
replacement=(
" forbiddenPureIdentifiers.contains u ||\n"
" false ||"
),
fixture_id="audit_panic_preresolved_auto_syntax",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_panic_alias",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description=(
"validateRepoAliases rejects runtime panic and bang export aliases "
"in repository modules"
),
anchor=(
" if forbiddenPureIdentifiers.contains aliasUser ||\n"
" isForbiddenRepoPanicRef aliasUser ||"
),
replacement=(
" if forbiddenPureIdentifiers.contains aliasUser ||\n"
" false ||"
),
fixture_id="audit_export_panic_alias",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_ptr_const",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description=(
"forbiddenPureIdentifiers blocks Init.Util pointer-identity "
"primitives in compiled repository declarations"
),
anchor=" `withPtrAddr, `withPtrEq, `withPtrEqDecEq,",
replacement=" `withPtrAddr, `withPtrEqDecEq,",
fixture_id="audit_ptr_const",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_alias_role_edge",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAliases enforces role-edge authority on exported targets",
anchor=(
" if let some msg :=\n"
" edgeViolation? aliasName modRole targetName targetOrig targetRole then\n"
" fail msg"
),
replacement=" let _ := (modRole, targetOrig, targetRole)",
fixture_id="audit_export_role_edge",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_alias_meta_target",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAliases rejects forbidden metaprogramming/effectful targets",
anchor=(
" if isForbiddenRepoMetaConst env targetName then\n"
' fail s!"disallowed export target {targetName} in {m}"'
),
replacement=" if false then\n pure ()",
fixture_id="audit_export_meta_target",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_alias_opaque_target",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAliases rejects `opaque` export targets outside Trusted",
anchor=(
" if !isTrusted && (targetCi matches .opaqueInfo _) then\n"
' fail (s!"opaque export target {targetName} in {m} is not allowed " ++\n'
' "outside Trusted")'
),
replacement=" if false then\n pure ()",
fixture_id="audit_export_opaque_target",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_alias_unsafe_target",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoAliases rejects unsafe/partial/unapproved-axiom export targets",
anchor=(
" if targetCi.isUnsafe || targetCi.isPartial ||\n"
" (targetCi.isAxiom && !approvedAxiom) then\n"
' fail (s!"disallowed unsafe/partial/axiom export target {targetName} " ++\n'
' s!"in {m}")'
),
replacement=" let _ := approvedAxiom",
fixture_id="audit_export_unsafe_target",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_companion_extra_const",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="validateCompanionOleanParts rejects companion `.olean` constants absent from `.olean.private`",
anchor=(
" unless privConsts.contains ci.name do\n"
' fail (s!"{ctxPrefix}companion constant {ci.name} missing from " ++\n'
' s!"private inventory of {m}")'
),
replacement=" if false then\n pure ()",
fixture_id="target_companion_extra_const",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_companion_imports_mismatch",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="validateCompanionOleanParts rejects companion `.olean` parts whose imports differ from `.olean.private`",
anchor=(
" unless partData.imports == privData.imports do\n"
' fail s!"mismatched {ctxPrefix}companion imports in {m}"'
),
replacement=" let _ := privData.imports",
fixture_id="target_companion_imports_mismatch",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_companion_const_mismatch",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="validateCompanionOleanParts rejects companion `.olean` constants inconsistent with `.olean.private`",
anchor=(
" if let some privCi := privConsts.get? ci.name then\n"
" unless isValidCompanionConstant privData.isModule privCi ci do\n"
' fail (s!"mismatched {ctxPrefix}companion constant {ci.name} " ++\n'
' s!"in {m}")'
),
replacement=" let _ := privData.isModule",
fixture_id="target_companion_const_mismatch",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_root_prefixed_alias",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit normalizes `_root_`-prefixed alias keys before root checks",
anchor=(
" let aliasUser := stripRootAndPrivatePrefixes aliasName\n"
" if aliasUser.hasMacroScopes ||\n"
" hasMalformedRootOrPrivate aliasUser then\n"
' fail s!"invalid export alias {aliasName} in {m.module}"'
),
replacement=" let aliasUser := privateToUserName aliasName",
fixture_id="target_root_prefixed_alias",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_spec_bad_alias_name",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit rejects specification export aliases violating isForbiddenSpecAliasUser",
anchor=(
" if targetRole == TargetRole.specification &&\n"
" isForbiddenSpecAliasUser aliasUser then\n"
' fail (s!"specification module {m.module} cannot export alias " ++\n'
' s!"{aliasName}")'
),
replacement=" if false then\n pure ()",
fixture_id="target_spec_bad_alias_name",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_alias_role_edge",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit enforces role-edge authority on exported target aliases",
anchor=(
" if let some msg := TargetOrigin.edgeViolation? aliasName\n"
" (.source targetRole) targetName targetOriginRole then\n"
" fail msg"
),
replacement=" let _ := targetOriginRole",
fixture_id="target_alias_role_edge",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_source_root_trusted_const",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit source loop normalizes `_root_`/`_private` prefixes before `Trusted` root check",
anchor=(
" let sourceUser := stripRootAndPrivatePrefixes ci.name\n"
" if hasMalformedRootOrPrivate sourceUser then\n"
' fail s!"invalid target constant identifier {ci.name} in {m.module}"\n'
" let userRoot := sourceUser.getRoot"
),
replacement=" let userRoot := (privateToUserName ci.name).getRoot",
fixture_id="target_source_root_trusted_const",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_proof_root_trusted_const",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="targetAudit proof-export loop normalizes `_root_`/`_private` prefixes before `Trusted` root check",
anchor=(
" let proofUser := stripRootAndPrivatePrefixes ci.name\n"
" if hasMalformedRootOrPrivate proofUser then\n"
' fail s!"invalid target constant identifier {ci.name} in {pm.moduleName}"\n'
" let userRoot := proofUser.getRoot"
),
replacement=" let userRoot := (privateToUserName ci.name).getRoot",
fixture_id="target_proof_root_trusted_const",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_nested_private_reserved_const",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description="isReservedTargetRootForbidden strips interleaved `_private`/`_root_` prefixes to a fixpoint",
anchor=" let userRoot := (stripRootAndPrivatePrefixes ci.name).getRoot",
replacement=(
" let userRoot :=\n"
" (stripLeadingRootPrefix (privateToUserName (stripLeadingRootPrefix ci.name))).getRoot"
),
fixture_id="target_nested_private_reserved_const",
),
AuditBoundaryGuard(
guard_id="target_audit_reject_sealed_admission",
target_file="trusted/audit/TrustedBoundary.lean",
mode="target-audit",
description=(
"targetAuditObligation fails closed on sealed module admission "
"before sealed-prefix verification is enabled"
),
anchor=(
" if admission == .sealed then\n"
' fail s!"sealed module admission is not supported for {m}"'
),
replacement=' if false then\n fail ""',
fixture_id="target_sealed_admission",
),
AuditBoundaryGuard(
guard_id="audit_repo_reject_root_trusted_const",
target_file="trusted/audit/TrustedBoundary.lean",
mode="audit",
description="validateRepoConstant normalizes `_root_`/`_private` prefixes before `Trusted`/reserved root checks",
anchor=(
" let userName := stripRootAndPrivatePrefixes ci.name\n"
" if hasMalformedRootOrPrivate userName then\n"
' fail s!"invalid constant identifier {ci.name} in {m}"'
),
replacement=" let userName := privateToUserName ci.name",
fixture_id="audit_root_trusted_const",
),
)
# Direct crate dependencies of `trusted/rustc-capture/Cargo.toml` needed to
# compile isolated single-guard mutants directly with `rustc` against the
# baseline Cargo `deps/` directory.
EXTRACT_DIRECT_DEPS: tuple[str, ...] = (
"clap",
"serde",
"serde_json",
"sha2",
"tempfile",
)
EXTRACT_POSITIVE_SANITY_SOURCE: str = (
"pub fn selected(x: u64) -> u64 {\n"
" x + 1\n"
"}\n"
)
# Positive sanity input for `--exclude-trait` guards: a crate with an
# excluded derived `Debug` impl that must still capture.
EXCLUDE_TRAIT_POSITIVE_SANITY_SOURCE: str = (
"#[derive(Debug)]\n"
"pub enum E { A }\n"
"pub fn zero() -> u64 { 0 }\n"
)
EXCLUDE_TRAIT_POSITIVE_SANITY_TRAITS: tuple[str, ...] = ("core::fmt::Debug",)
# Defense-in-depth `--exclude-trait` checks in `trusted/rustc-capture/src/`
# that sit behind an active upstream guard, so mutating only the secondary
# site cannot flip a valid fixture without first disabling the primary guard.
# They have no `EXTRACT_GUARDS` entry.
EXCLUDE_TRAIT_DEFENSE_IN_DEPTH_EXEMPTIONS: dict[str, str] = {
"capture_exclude_trait_callee_queue": (
"capture.rs collect() callee-queue exclusion check is "
"defense-in-depth behind check_body_disjoint(), which inspects "
"every Call terminator before extract_body populates callees."
),
"capture_exclude_trait_mentioned_items": (
"capture.rs check_mentioned_items() (including its None fail-closed"
" branch) is an independent rustc MentionedItems cross-check run "
"after Runtime(PostCleanup) extraction, behind "
"check_body_disjoint()."
),
"capture_exclude_trait_unsize_vtable": (
"capture.rs check_unsize_cast() vtable_entries loop is "
"defense-in-depth behind check_trait_or_supertraits(), which "
"already rejects any dyn principal whose trait or supertrait is "
"excluded."
),
"capture_exclude_trait_default_method_select": (
"capture.rs codegen_select_candidate() check for inherited default "
"methods (e.g. Error::source) is defense-in-depth behind the "
"non-local FnDef predicates_of() elaboration guard (every trait "
"method carries Self: Trait); it remains to emit the more specific "
"local-impl error."
),
"capture_exclude_trait_drop_ty": (
"capture.rs check_drop_ty() is defense-in-depth because "
"core::ops::Drop is outside the closed --exclude-trait allowlist; "
"it guards against future allowlist expansion or drop glue reaching"
" excluded items."
),
"capture_exclude_trait_const_alloc": (
"capture.rs check_const_alloc() GlobalAlloc provenance recursion is"
" defense-in-depth behind CTFE MIR and promoted_mir "
"check_body_disjoint() walks."
),
"capture_exclude_trait_diag_item_krate_kind": (
"capture.rs resolve_excluded_traits() krate/DefKind::Trait pin is "
"defense-in-depth against a tampered sysroot core mapping "
"diagnostic items to non-traits or local defs; unreachable under "
"the authenticated pinned rustc sysroot."
),
}
CAPTURE_REC_STRUCT_DEFENSE_IN_DEPTH_EXEMPTIONS: dict[str, str] = {
"capture_rec_tys_checked": (
"ir.rs check_rec_tys() (Ty::rec_ty_wf and the binder coherence check) "
"is defense-in-depth behind extract.rs ty_in()/handle_pointee_ty(), "
"which emit only closed, guarded, coherent RecAdt terms, and in front "
"of the Lean admission predicate programRecTysAdmittedV2 (guards "
"enum_v2_rec_* and boundary_v2_rec_tys_admitted); ir.rs unit tests "
"exercise each refusal."
),
"capture_rec_struct_reentry": (
"extract.rs ty_in() refusal of re-entering a struct still being "
"translated (other than through handle_pointee_ty's direct Box/Vec "
"back edge) has no well-defined mutant: weakening it recurses without "
"bound. typed_capture profile_v2_refuses_recursive_structs_without_"
"overflow covers it."
),
"capture_rec_drop_glue_back_edge": (
"extract.rs check_drop_glue_tree() stops at a self-recursive type's "
"back edge (`visiting`); removing that cutoff has no well-defined "
"mutant (the walk recurses without bound). The Lean fuelled glue is "
"guarded by alloc_rec_drop_*."
),
}
# Documentation-only catalog of defense-in-depth capture checks in
# `trusted/rustc-capture/src/` that no Rust source can reach, so they have no
# `EXTRACT_GUARDS` entry.
CAPTURE_DEFENSE_IN_DEPTH_EXEMPTIONS: dict[str, str] = {
"capture_nested_mut_ref_copy_site": (
"extract.rs check_nested_mut_ref_copies() refusals of a copy of `*g` "
"(g: `& &mut T`) other than `_k = copy (*g)` into a fresh non-argument "
"local defined once, and of a move of or write to `*g`, are "
"defense-in-depth: the Derefer pass emits every such copy in that "
"form, and the borrow checker forbids moving or writing through "
"`& &mut T` (E0507, E0594), so no Rust source reaches them."
),
}
EXTRACT_GUARDS: tuple[ExtractGuard, ...] = (
# ------------------------------------------------------------------
# UB-preservation & compiler profile guards (capture.rs)
# ------------------------------------------------------------------
ExtractGuard(
guard_id="extract_shard_call_ne_terminator_edges",
target_file="trusted/rustc-capture/src/shard.rs",
mode="unit",
description=(
"maybe_shard_manifest adds Call/CallNe terminator edges to the "
"shard call graph"
),
anchor=" out.insert(callee_body.identity().to_owned());",
replacement=" let _ = callee_body;",
unit_test_name=(
"shard::tests::sharding_follows_call_ne_edges_missing_from_callees"
),
),
ExtractGuard(
guard_id="extract_profile_require_mir_preserve_ub",
target_file="trusted/rustc-capture/src/capture.rs",
mode="unit",
description="validate_profile_options requires -Zmir-preserve-ub",
anchor=(
" if !opts.unstable_opts.mir_preserve_ub {\n"
' return Err("-Zmir-preserve-ub must be enabled during capture".into());\n'
" }"
),
replacement=(
" if false {\n"
' return Err("-Zmir-preserve-ub must be enabled during capture".into());\n'
" }"
),
unit_test_name=(
"capture::tests::"
"compiler_options_gate_requires_mir_preserve_ub_and_matching_crate_type_and_panic"
),
),
ExtractGuard(
guard_id="extract_profile_require_mir_opt_level_zero",
target_file="trusted/rustc-capture/src/capture.rs",
mode="unit",
description="validate_profile_options requires -Zmir-opt-level=0",
anchor=" if opts.unstable_opts.mir_opt_level != Some(0) {",
replacement=" if false {",
unit_test_name=(
"capture::tests::"
"compiler_options_gate_enforces_opt_level_debug_assertions_and_overflow_checks"
),
),
ExtractGuard(
guard_id="extract_profile_require_overflow_checks_no",
target_file="trusted/rustc-capture/src/capture.rs",
mode="unit",
description=(
"validate_profile_options enforces -Coverflow-checks matching "
"expected_overflow_checks"
),
anchor=" if opts.cg.overflow_checks != Some(expected_overflow_checks) {",
replacement=" if false {",
unit_test_name=(
"capture::tests::"
"compiler_options_gate_enforces_opt_level_debug_assertions_and_overflow_checks"
),
),
ExtractGuard(
guard_id="extract_profile_require_debug_assertions_no",
target_file="trusted/rustc-capture/src/capture.rs",
mode="unit",
description="validate_profile_options requires -Cdebug-assertions=no",
anchor=(
" if opts.debug_assertions {\n"
' return Err("-Cdebug-assertions=no is required during capture".into());\n'
" }"
),
replacement=(
" if false {\n"
' return Err("-Cdebug-assertions=no is required during capture".into());\n'
" }"
),
unit_test_name=(
"capture::tests::"
"compiler_options_gate_enforces_opt_level_debug_assertions_and_overflow_checks"
),
),
ExtractGuard(
guard_id="extract_profile_require_64bit_pointers",
target_file="trusted/rustc-capture/src/capture.rs",
mode="unit",
description="checked_target_profile requires 64-bit pointer width",
anchor=(
" match endian {\n"
' Endian::Little if pointer_bits == 64 => Ok((pointer_bits, "little")),\n'
" Endian::Little | Endian::Big => {\n"
' Err(Failure::unsupported('
'"only 64-bit little-endian targets are modeled"))\n'
" }\n"
" }"
),
replacement=(
" match endian {\n"
' Endian::Little => Ok((pointer_bits, "little")),\n'
" Endian::Big => {\n"
' Err(Failure::unsupported('
'"only 64-bit little-endian targets are modeled"))\n'
" }\n"
" }"
),
unit_test_name=(
"capture::tests::target_profile_gate_requires_64_bit_little_endian"
),
),
ExtractGuard(
guard_id="extract_profile_require_little_endian",
target_file="trusted/rustc-capture/src/capture.rs",
mode="unit",
description="checked_target_profile requires little-endian target",
anchor=(
" match endian {\n"
' Endian::Little if pointer_bits == 64 => Ok((pointer_bits, "little")),\n'
" Endian::Little | Endian::Big => {\n"
' Err(Failure::unsupported('
'"only 64-bit little-endian targets are modeled"))\n'
" }\n"
" }"
),
replacement=(
" match endian {\n"
' Endian::Little | Endian::Big if pointer_bits == 64 => '
'Ok((pointer_bits, "little")),\n'
" Endian::Little | Endian::Big => {\n"
' Err(Failure::unsupported('
'"only 64-bit little-endian targets are modeled"))\n'
" }\n"
" }"
),
unit_test_name=(
"capture::tests::target_profile_gate_requires_64_bit_little_endian"
),
),
# ------------------------------------------------------------------
# Alignment, layout & codegen attribute guards (extract.rs)
# ------------------------------------------------------------------
ExtractGuard(
guard_id="extract_reject_fn_alignment",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="codegen_attrs rejects #[rustc_align] function alignment",
anchor=(
" if let Some(align) = alignment {\n"
' return Err(format!("function alignment {align:?} is unsupported"));\n'
" }"
),
replacement=" let _ = alignment;",
negative_source=(
"#![feature(fn_align)]\n"
"#[rustc_align(64)]\n"
"pub fn selected(x: u64) -> u64 { x }\n"
),
allow_unstable_features=("fn_align",),
expected_baseline_diagnostic="function alignment",
),
ExtractGuard(
guard_id="extract_reject_target_feature",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="codegen_attrs rejects #[target_feature] entry obligations",
anchor=(
" if !is_stub && (!target_features.is_empty() || *safe_target_features) {\n"
' return Err("target-feature entry obligations are unsupported".into());\n'
" }"
),
replacement=" let _ = (target_features, safe_target_features);",
negative_source=(
'#[cfg(not(target_arch = "x86_64"))]\n'
'compile_error!(\n'
' "extract_reject_target_feature fixture requires x86_64"\n'
');\n'
'#[cfg_attr(target_arch = "x86_64", '
'target_feature(enable = "avx2"))]\n'
"pub fn selected(x: u64) -> u64 { x }\n"
),
expected_baseline_diagnostic="target-feature entry obligations are unsupported",
),
ExtractGuard(
guard_id="extract_reject_linkage_attr",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="codegen_attrs rejects #[linkage] attributes",
anchor=(
" if let Some(linkage) = linkage.or(*import_linkage) {\n"
" return Err(format!(\n"
' "linkage attribute {linkage:?} is unsupported: '
'calls need not execute the captured body"\n'
" ));\n"
" }"
),
replacement=" let _ = (linkage, import_linkage);",
negative_source=(
"#![feature(linkage)]\n"
'#[linkage = "weak"]\n'
"pub fn selected(x: u64) -> u64 { x }\n"
),
allow_unstable_features=("linkage",),
expected_baseline_diagnostic="linkage attribute",
),
ExtractGuard(
guard_id="extract_reject_export_name",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="codegen_attrs rejects #[unsafe(export_name)] symbols",
anchor=(
" if let Some(name) = symbol_name {\n"
" return Err(format!(\n"
' "exported symbol name `{name}` is unsupported: '
'symbol obligations are unmodeled"\n'
" ));\n"
" }"
),
replacement=" let _ = symbol_name;",
negative_source=(
'#[unsafe(export_name = "anneal_custom_sym")]\n'
"pub fn selected(x: u64) -> u64 { x }\n"
),
expected_baseline_diagnostic="exported symbol name",
),
ExtractGuard(
guard_id="extract_reject_link_section",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="codegen_attrs rejects #[unsafe(link_section)] attributes",
anchor=(
" if let Some(section) = link_section {\n"
" return Err(format!(\n"
' "link section `{section}` is unsupported: '
'section obligations are unmodeled"\n'
" ));\n"
" }"
),
replacement=" let _ = link_section;",
negative_source=(
'#[unsafe(link_section = ".text.anneal_mut")]\n'
"pub fn selected(x: u64) -> u64 { x }\n"
),
expected_baseline_diagnostic="link section",
),
ExtractGuard(
guard_id="extract_reject_no_mangle_flag",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="codegen_attrs rejects unmodeled flags such as NO_MANGLE",
anchor=(
" let unmodeled = flags.difference(allowed_flags);\n"
" if !unmodeled.is_empty() {\n"
" return Err(format!(\n"
' "codegen attribute flags {unmodeled:?} are unsupported"\n'
" ));\n"
" }"
),
replacement=" let _ = (flags, allowed_flags);",
negative_source=(
"#[unsafe(no_mangle)]\n"
"pub fn selected(x: u64) -> u64 { x }\n"
),
expected_baseline_diagnostic="codegen attribute flags",
),
ExtractGuard(
guard_id="extract_reject_force_inline",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="codegen_attrs rejects #[rustc_force_inline]",
anchor=(
" InlineAttr::Force { .. } => {\n"
' return Err("forced inlining is unsupported".into());\n'
" }"
),
replacement=" InlineAttr::Force { .. } => {}",
negative_source=(
"#![feature(no_core, lang_items, rustc_attrs)]\n"
"#![allow(internal_features)]\n"
"#![no_core]\n"
'#[lang = "pointee_sized"] pub trait PointeeSized {}\n'
'#[lang = "meta_sized"] pub trait MetaSized: PointeeSized {}\n'
'#[lang = "sized"] pub trait Sized: MetaSized {}\n'
'#[lang = "copy"] pub trait Copy {}\n'
"impl Copy for u64 {}\n"
"#[rustc_force_inline]\n"
"pub fn selected(x: u64) -> u64 { x }\n"
),
stdlib_crate="core",
expected_baseline_diagnostic="forced inlining is unsupported",
),
ExtractGuard(
guard_id="extract_reject_sanitizer_override",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="codegen_attrs rejects #[sanitize(...)] overrides",
anchor=(
" if *sanitizers != SanitizerFnAttrs::default() {\n"
' return Err(format!("sanitizer settings {sanitizers:?} are unsupported"));\n'
" }"
),
replacement=" let _ = sanitizers;",
negative_source=(
"#![feature(sanitize)]\n"
'#[sanitize(address = "off")]\n'
"pub fn selected(x: u64) -> u64 { x }\n"
),
allow_unstable_features=("sanitize",),
expected_baseline_diagnostic="sanitizer settings",
),
ExtractGuard(
guard_id="extract_reject_patchable_function_entry",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="codegen_attrs rejects #[patchable_function_entry] nops",
anchor=(
" if patchable_function_entry.is_some() {\n"
' return Err("patchable function entries are unsupported".into());\n'
" }"
),
replacement=" let _ = patchable_function_entry;",
negative_source=(
"#![feature(patchable_function_entry)]\n"
"#[patchable_function_entry(prefix_nops = 1, entry_nops = 1)]\n"
"pub fn selected(x: u64) -> u64 { x }\n"
),
allow_unstable_features=("patchable_function_entry",),
expected_baseline_diagnostic="patchable function entries are unsupported",
),
# ------------------------------------------------------------------
# Type, enum & discriminant guards (extract.rs, ir.rs, capture.rs)
# ------------------------------------------------------------------
ExtractGuard(
guard_id="extract_ir_reject_overflow_pair_pointee",
target_file="trusted/rustc-capture/src/ir.rs",
mode="capture",
description=(
"ir::is_supported_v2_data rejects overflow pairs"
),
anchor=(
" pub fn is_supported_v2_data(&self) -> bool {\n"
" match self {\n"
" Self::Array { elem, .. } => elem.is_supported_v2_data(),\n"
" Self::Struct(sty) => sty.fields().iter().all(Self::is_supported_v2_data),\n"
" Self::OverflowPair(_) => false,"
),
replacement=(
" pub fn is_supported_v2_data(&self) -> bool {\n"
" match self {\n"
" Self::Array { elem, .. } => elem.is_supported_v2_data(),\n"
" Self::Struct(sty) => sty.fields().iter().all(Self::is_supported_v2_data),\n"
" Self::OverflowPair(_) => true,"
),
negative_source="pub fn selected(_p: &(u8, bool)) -> u64 { 0 }\n",
expected_baseline_diagnostic="outside the Profile v2 type fragment",
),
ExtractGuard(
guard_id="extract_reject_enum_id_collision",
target_file="trusted/rustc-capture/src/capture.rs",
mode="capture",
description="check_admitted_enum_collisions rejects duplicate local enum keys",
anchor=(
" if defs.len() > 1 {\n"
" return Err(Failure::unsupported(format!(\n"
' "{kind} identity collision: {} and {} share id {id}",\n'
" tcx.def_path_str(defs[0]),\n"
" tcx.def_path_str(defs[1]),\n"
" )));\n"
" }"
),
replacement=" let _ = (tcx, defs);",
negative_source=(
"pub fn outer() {\n"
" {\n"
" pub enum E { A, B }\n"
" pub fn selected(x: E) -> u8 {\n"
" match x { E::A => 0, E::B => 1 }\n"
" }\n"
" }\n"
" { enum E { C, D } }\n"
"}\n"
),
select_root="outer::selected",
expected_baseline_diagnostic="enum identity collision",
),
ExtractGuard(
guard_id="extract_ir_reject_invalid_enum_const_tag",
target_file="trusted/rustc-capture/src/ir.rs",
mode="unit",
description="ir::validate_constant rejects enum tag not matching any variant",
anchor=(
" if !ety.discriminants.contains(&discr) {\n"
" return Err(format!(\n"
' "enum tag constant {bits:#x} '
'does not match any declared variant"\n'
" ));\n"
" }"
),
replacement=" let _ = discr;",
unit_test_name=(
"extract::tests::"
"body_constructor_rejects_storage_dead_return_place_and_invalid_constants"
),
),
ExtractGuard(
guard_id="extract_ir_reject_enum_tag_width_overflow",
target_file="trusted/rustc-capture/src/ir.rs",
mode="unit",
description="ir::validate_constant rejects enum tag exceeding tag width",
anchor=(
" if *bits > tag.width.mask() {\n"
" return Err(format!(\n"
' "enum tag constant {bits:#x} '
'exceeds {}-bit tag width",\n'
" tag.width.bits()\n"
" ));\n"
" }"
),
replacement=" let _ = tag.width.mask();",
unit_test_name=(
"extract::tests::"
"body_constructor_rejects_storage_dead_return_place_and_invalid_constants"
),
),
# ------------------------------------------------------------------
# PlaceMention & retag guards (extract.rs, ir.rs)
# ------------------------------------------------------------------
ExtractGuard(
guard_id="extract_ir_reject_place_mention_unsized",
target_file="trusted/rustc-capture/src/ir.rs",
mode="unit",
description="ir::admit_place_mention rejects unsized PlaceMention locals",
anchor=(
"fn admit_place_mention(is_sized: bool) -> Result<(), String> {\n"
" if !is_sized {\n"
' return Err("PlaceMention on unsized locals is unsupported".into());\n'
" }\n"
" Ok(())\n"
"}"
),
replacement=(
"fn admit_place_mention(_is_sized: bool) -> Result<(), String> {\n"
" Ok(())\n"
"}"
),
unit_test_name=(
"ir::tests::place_mention_guard_checks_local_bounds_and_sizedness"
),
),
ExtractGuard(
guard_id="extract_ir_reject_effective_retag",
target_file="trusted/rustc-capture/src/ir.rs",
mode="unit",
description="ir::admit_retag rejects erasing WithRetag::Yes on non-noop types",
anchor=(
"fn admit_retag(retag_noop: bool, with_retag: bool) -> Result<(), String> {\n"
" if with_retag && !retag_noop {\n"
' return Err("retagging Use rvalues on reference-bearing types '
'are unsupported".into());\n'
" }\n"
" Ok(())\n"
"}"
),
replacement=(
"fn admit_retag(_retag_noop: bool, _with_retag: bool) -> Result<(), String> {\n"
" Ok(())\n"
"}"
),
unit_test_name=(
"ir::tests::retag_guard_refuses_erasing_an_effective_retag"
),
),
# ------------------------------------------------------------------
# Rodata indirect-constant allocation guards (extract.rs)
# ------------------------------------------------------------------
ExtractGuard(
guard_id="extract_rodata_reject_big_endian",
target_file="trusted/rustc-capture/src/extract.rs",
mode="unit",
description="read_rodata_scalar_from_alloc rejects non-little-endian layouts",
anchor=(
" width: u32,\n"
") -> Result<u128> {\n"
" if cx.data_layout().endian != Endian::Little {\n"
' return Err("non-little-endian global allocation constants '
'are unsupported".into());\n'
" }"
),
replacement=(
" width: u32,\n"
") -> Result<u128> {\n"
" let _ = cx.data_layout().endian;"
),
unit_test_name=(
"extract::tests::"
"rodata_global_alloc_reader_enforces_immutability_init_bounds_endian_and_no_provenance"
),
),
ExtractGuard(
guard_id="extract_rodata_reject_mutable_alloc",
target_file="trusted/rustc-capture/src/extract.rs",
mode="unit",
description="read_rodata_scalar_from_alloc rejects mutable allocations",
anchor=(
" if alloc.mutability != Mutability::Not {\n"
' return Err("mutable global allocations are unsupported '
'in constants".into());\n'
" }\n"
" let byte_len = u64::from(width / 8);"
),
replacement=(
" let _ = alloc.mutability;\n"
" let byte_len = u64::from(width / 8);"
),
unit_test_name=(
"extract::tests::"
"rodata_global_alloc_reader_enforces_immutability_init_bounds_endian_and_no_provenance"
),
),
ExtractGuard(
guard_id="extract_rodata_reject_oob_range",
target_file="trusted/rustc-capture/src/extract.rs",
mode="unit",
description="read_rodata_scalar_from_alloc rejects out-of-bounds ranges",
anchor=(
" if end > alloc.size().bytes() {\n"
" return Err(format!(\n"
' "global allocation constant range [{}..{end}) '
'exceeds allocation size {}",\n'
" offset.bytes(),\n"
" alloc.size().bytes()\n"
" ));\n"
" }"
),
replacement=" let _ = end;",
unit_test_name=(
"extract::tests::"
"rodata_global_alloc_reader_enforces_immutability_init_bounds_endian_and_no_provenance"
),
),
ExtractGuard(
guard_id="extract_rodata_reject_provenance",
target_file="trusted/rustc-capture/src/extract.rs",
mode="unit",
description="read_rodata_scalar_from_alloc rejects provenance-bearing ranges",
anchor=(
" if !alloc.provenance().range_empty(range, cx) {\n"
' return Err("provenance-bearing global allocation constants '
'are unsupported".into());\n'
" }\n"
" let scalar = alloc"
),
replacement=(
" let _ = alloc.provenance().range_empty(range, cx);\n"
" let scalar = alloc"
),
unit_test_name=(
"extract::tests::"
"rodata_global_alloc_reader_enforces_immutability_init_bounds_endian_and_no_provenance"
),
),
# ------------------------------------------------------------------
# Unwind / cleanup-block guard (extract.rs)
# ------------------------------------------------------------------
ExtractGuard(
guard_id="extract_reject_cleanup_block",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="body_inner cleanup-block refusal (diagnostic-precedence pin)",
anchor=(
" if let Some((id, _)) = body\n"
" .basic_blocks\n"
" .iter_enumerated()\n"
" .find(|(_, block)| block.is_cleanup)\n"
" {\n"
' return Err(format!("cleanup block {id:?} is unsupported"));\n'
" }"
),
replacement=" let _ = &body.basic_blocks;",
negative_source=(
"pub struct Guard;\n"
"impl Drop for Guard {\n"
" fn drop(&mut self) {}\n"
"}\n"
"pub fn callee() {}\n"
"pub fn selected() {\n"
" let _guard = Guard;\n"
" callee();\n"
"}\n"
),
expected_baseline_diagnostic="cleanup block bb",
expected_fallback_diagnostic="structs with a Drop impl are unsupported: Guard",
allow_downstream_fallback=True,
),
# ------------------------------------------------------------------
# Statement, call-source, terminator, operator & cast guards (extract.rs)
# ------------------------------------------------------------------
ExtractGuard(
guard_id="extract_reject_statement_intrinsic_assume",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="statement() default-deny refuses StatementKind::Intrinsic(Assume)",
anchor=' other => return Err(format!("unsupported statement: {other:?}")),',
replacement=(
" mir::StatementKind::Intrinsic(_) => ir::Statement::Nop,\n"
' other => return Err(format!("unsupported statement: {other:?}")),'
),
negative_source=(
"#![feature(no_core, lang_items, intrinsics)]\n"
"#![allow(internal_features)]\n"
"#![no_core]\n"
'#[lang = "pointee_sized"] pub trait PointeeSized {}\n'
'#[lang = "meta_sized"] pub trait MetaSized: PointeeSized {}\n'
'#[lang = "sized"] pub trait Sized: MetaSized {}\n'
'#[lang = "copy"] pub trait Copy {}\n'
"impl Copy for bool {}\n"
"#[rustc_intrinsic]\n"
"pub unsafe fn assume(b: bool);\n"
"pub unsafe fn selected(b: bool) -> u8 {\n"
" unsafe { assume(b) };\n"
" 0\n"
"}\n"
),
stdlib_crate="core",
expected_baseline_diagnostic="unsupported statement",
),
ExtractGuard(
guard_id="extract_reject_call_source_use",
target_file="trusted/rustc-capture/src/extract.rs",
mode="unit",
description="check_call_source rejects CallSource::Use terminators",
anchor=(
" mir::CallSource::Use => Err(\n"
' "CallSource::Use call terminators are unsupported: post-capture \\\n'
" optimize_use_clone may rewrite Clone::clone to a bitwise copy \\\n"
' for Copy types, diverging from captured MIR"\n'
" .into(),\n"
" ),"
),
replacement=" mir::CallSource::Use => Ok(()),",
unit_test_name=(
"extract::tests::"
"call_source_use_fails_closed_while_other_call_sources_pass_guard"
),
),
ExtractGuard(
guard_id="extract_reject_returning_call",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description=(
"terminator() validates returning Call terminators instead of "
"short-circuiting them to Unsupported"
),
anchor=(
" let Some(target_bb) = target else {\n"
" if admit_core_panicking_abort(tcx)"
),
replacement=(
" let Some(target_bb) = target.as_ref().filter(|_| false) else {\n"
" if admit_core_panicking_abort(tcx)"
),
negative_source=(
"fn helper<T>(x: T) -> T { x }\n"
"pub fn selected(x: u32) -> u32 { helper(x) }\n"
),
expected_baseline_diagnostic="calls to generic or monomorphized functions",
),
ExtractGuard(
guard_id="extract_reject_terminator_inline_asm",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="terminator() default-deny refuses TerminatorKind::InlineAsm",
anchor=' other => return Err(format!("unsupported terminator: {other:?}")),',
replacement=(
" mir::TerminatorKind::InlineAsm { targets, .. } => "
"RawTerminator::Resolved(ir::Terminator::Goto {\n"
" block: targets[0].as_u32(),\n"
" }),\n"
' other => return Err(format!("unsupported terminator: {other:?}")),'
),
negative_source=(
"pub unsafe fn selected() {\n"
' unsafe { core::arch::asm!("nop", options(nomem, nostack)) };\n'
"}\n"
),
expected_baseline_diagnostic="unsupported terminator",
),
ExtractGuard(
guard_id="extract_reject_unchecked_binop",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="bin_op() rejects unchecked shift operators (ShlUnchecked)",
anchor=' other => return Err(format!("unsupported binary operator: {other:?}")),',
replacement=(
" mir::BinOp::ShlUnchecked => ir::BinOp::Shl,\n"
' other => return Err(format!("unsupported binary operator: {other:?}")),'
),
negative_source=(
"#![feature(no_core, lang_items, intrinsics)]\n"
"#![allow(internal_features)]\n"
"#![no_core]\n"
'#[lang = "pointee_sized"] pub trait PointeeSized {}\n'
'#[lang = "meta_sized"] pub trait MetaSized: PointeeSized {}\n'
'#[lang = "sized"] pub trait Sized: MetaSized {}\n'
'#[lang = "copy"] pub trait Copy {}\n'
"impl Copy for u32 {}\n"
"#[rustc_intrinsic]\n"
"pub unsafe fn unchecked_shl<T: Copy, U: Copy>(x: T, y: U) -> T;\n"
"pub unsafe fn selected(a: u32, b: u32) -> u32 {\n"
" unsafe { unchecked_shl(a, b) }\n"
"}\n"
),
stdlib_crate="core",
expected_baseline_diagnostic="unsupported binary operator: ShlUnchecked",
),
ExtractGuard(
guard_id="extract_reject_transmute_cast",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="cast_kind() rejects CastKind::Transmute",
anchor=(
" | mir::CastKind::Transmute\n"
' | mir::CastKind::Subtype => Err(format!("unsupported cast kind: {kind:?}")),'
),
replacement=(
' | mir::CastKind::Subtype => Err(format!("unsupported cast kind: {kind:?}")),\n'
" mir::CastKind::Transmute => Ok(ir::CastKind::IntToInt),"
),
negative_source=(
"pub fn selected(x: u32) -> i32 {\n"
" unsafe { core::mem::transmute(x) }\n"
"}\n"
),
expected_baseline_diagnostic="unsupported cast kind: Transmute",
),
ExtractGuard(
guard_id="extract_reject_expose_provenance_cast",
target_file="trusted/rustc-capture/src/extract.rs",
mode="unit",
description="cast_kind() rejects CastKind::PointerExposeProvenance",
anchor=(
" mir::CastKind::PointerExposeProvenance\n"
" | mir::CastKind::PointerCoercion(..)"
),
replacement=(
" mir::CastKind::PointerExposeProvenance => "
"Ok(ir::CastKind::IntToInt),\n"
" mir::CastKind::PointerCoercion(..)"
),
unit_test_name=(
"extract::tests::"
"operator_and_cast_extractors_admit_modeled_variants_and_refuse_others"
),
),
# ------------------------------------------------------------------
# Intrinsic fallback, ABI, generics & required-const guards (extract.rs)
# ------------------------------------------------------------------
ExtractGuard(
guard_id="extract_reject_intrinsic_fallback",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="body_inner rejects #[rustc_intrinsic] fallback bodies",
anchor=(
" if let Some(intrinsic) = tcx.intrinsic(def) {\n"
" return Err(format!(\n"
' "intrinsic `{}` is unsupported: '
'calls need not execute its fallback body",\n'
" intrinsic.name\n"
" ));\n"
" }"
),
replacement=" let _ = tcx.intrinsic(def);",
negative_source=(
"#![feature(no_core, lang_items, intrinsics)]\n"
"#![allow(internal_features)]\n"
"#![no_core]\n"
'#[lang = "pointee_sized"] pub trait PointeeSized {}\n'
'#[lang = "meta_sized"] pub trait MetaSized: PointeeSized {}\n'
'#[lang = "sized"] pub trait Sized: MetaSized {}\n'
"#[rustc_intrinsic]\n"
"pub unsafe fn unreachable() -> ! {\n"
" loop {}\n"
"}\n"
),
stdlib_crate="core",
select_root="unreachable",
expected_baseline_diagnostic="intrinsic `unreachable` is unsupported",
),
ExtractGuard(
guard_id="extract_reject_uninstantiated_generic_fn",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description=(
"body_inner type-generic refusal (diagnostic-precedence pin ahead "
"of predicates_of PointeeSized check)"
),
anchor=(
" if !matches!(param.kind, ty::GenericParamDefKind::Lifetime) {\n"
" return Err(\n"
' "generic functions require quantified instantiation obligations".into(),\n'
" );\n"
" }"
),
replacement=" let _ = &param.kind;",
negative_source="pub fn selected<T: ?Sized>(x: u64) -> u64 { x }\n",
expected_baseline_diagnostic="generic functions require quantified",
expected_fallback_diagnostic=(
"functions with generic or lifetime bounds are unsupported"
),
allow_downstream_fallback=True,
),
ExtractGuard(
guard_id="extract_reject_non_rust_abi",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="body_inner rejects non-Rust ABI functions (extern \"C\")",
anchor=(
" if signature.abi() != ExternAbi::Rust || signature.c_variadic() {\n"
' return Err("only non-variadic Rust ABI functions are admitted".into());\n'
" }"
),
replacement=(
" if signature.c_variadic() {\n"
' return Err("only non-variadic Rust ABI functions are admitted".into());\n'
" }"
),
negative_source='pub extern "C" fn selected(x: u64) -> u64 { x }\n',
expected_baseline_diagnostic="only non-variadic Rust ABI functions are admitted",
),
ExtractGuard(
guard_id="extract_eval_required_consts",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description="body_inner evaluates required_consts (diagnostic-precedence pin)",
anchor=" eval_required_consts(tcx, typing_env, body)?;",
replacement=" let _ = (tcx, typing_env, body);",
negative_source=(
"pub fn pme<T>() -> usize {\n"
" if false {\n"
" let _ = const { assert!(core::mem::size_of::<T>() > 0); 0f32 };\n"
" }\n"
" 2\n"
"}\n"
),
capture_scope="instantiate",
instantiate_json='{"path":"pme","args":["()"]}',
expected_baseline_status="compiler_failed",
expected_baseline_diagnostic="E0080",
expected_fallback_diagnostic="unsupported type:",
allow_downstream_fallback=True,
),
# ------------------------------------------------------------------
# Monomorphization & crate-level admission guards (mono.rs, capture.rs)
# ------------------------------------------------------------------
ExtractGuard(
guard_id="extract_mono_verify_predicates_and_wf",
target_file="trusted/rustc-capture/src/mono.rs",
mode="capture",
description="mono::instantiate_body enforces trait and WF predicates",
anchor=' verify_predicates_and_wf(tcx, typing_env, target_def, args, "target")?;',
replacement=(
" let _ = verify_predicates_and_wf("
'tcx, typing_env, target_def, args, "target");'
),
negative_source="pub fn f<T: ?Sized>() -> u64 { 0 }\n",
capture_scope="instantiate",
instantiate_json='{"path":"f","args":["[[u8]]"]}',
expected_baseline_diagnostic="trait or well-formedness predicates unsatisfied",
),
ExtractGuard(
guard_id="extract_reject_cfg_attr_rustc_private",
target_file="trusted/rustc-capture/src/capture.rs",
mode="capture",
description="validate_crate_root_meta recurses into #![cfg_attr] items",
anchor=(
" if last_ident == Some(sym::cfg_attr)\n"
" && let Some(items) = meta.meta_item_list()\n"
" {\n"
" for item in items.iter().skip(1) {\n"
" if let MetaItemInner::MetaItem(nested) = item {\n"
" validate_crate_root_meta(nested, expected, false)?;\n"
" }\n"
" }\n"
" }"
),
replacement=" let _ = (last_ident, meta);",
negative_source=(
"#![cfg_attr(any(), feature(rustc_private))]\n"
"pub fn selected(x: u64) -> u64 { x }\n"
),
expected_baseline_diagnostic="#![feature(rustc_private)]",
),
ExtractGuard(
guard_id="extract_reject_rustc_private_feature",
target_file="trusted/rustc-capture/src/capture.rs",
mode="capture",
description=(
"validate_crate_root_meta rejects feature(rustc_private) even "
"behind inactive cfg_attr"
),
anchor=(
" if item.has_name(sym::rustc_private) {\n"
' return Err("#![feature(rustc_private)] is '
'unsupported during capture".into());\n'
" }"
),
replacement=" let _ = item;",
negative_source=(
"#![cfg_attr(any(), feature(rustc_private))]\n"
"pub fn selected(x: u64) -> u64 { x }\n"
),
expected_baseline_diagnostic="#![feature(rustc_private)]",
),
ExtractGuard(
guard_id="extract_crate_reject_unsafe_trait",
target_file="trusted/rustc-capture/src/capture.rs",
mode="capture",
description="admit_safe_trait rejects unsafe trait declarations in crate scope",
anchor=(
" if *safety != hir::Safety::Safe {\n"
' return Err("whole-crate obligation is unsupported: '
'Trait (unsafe trait)".into());\n'
" }"
),
replacement=" let _ = safety;",
negative_source=(
"pub unsafe trait Bad { fn f(); }\n"
"pub fn ok() -> u8 { 0 }\n"
),
capture_scope="crate",
expected_baseline_diagnostic="Trait (unsafe trait)",
),
ExtractGuard(
guard_id="extract_crate_reject_unsafe_impl",
target_file="trusted/rustc-capture/src/capture.rs",
mode="capture",
description="admit_safe_impl rejects user unsafe impl blocks in crate scope",
anchor=(
" if !is_builtin_trivial_clone {\n"
" return Err(\n"
' "whole-crate obligation is unsupported: '
'Impl { of_trait: true } (unsafe impl)"\n'
" .into(),\n"
" );\n"
" }"
),
replacement=" let _ = is_builtin_trivial_clone;",
negative_source=(
"pub enum E { A }\n"
"unsafe impl Send for E {}\n"
"pub fn ok() -> u8 { 0 }\n"
),
capture_scope="crate",
expected_baseline_diagnostic="Impl { of_trait: true } (unsafe impl)",
),
ExtractGuard(
guard_id="extract_crate_reject_unsafe_const",
target_file="trusted/rustc-capture/src/capture.rs",
mode="capture",
description="admit_const_item rejects unsafe blocks in const items",
anchor=" check_const_hir_safety(tcx, def, false, &context)?;",
replacement=" let _ = check_const_hir_safety(tcx, def, false, &context);",
negative_source=(
"pub const X: u8 = unsafe { 1 };\n"
"pub fn ok() -> u8 { X }\n"
),
capture_scope="crate",
expected_baseline_diagnostic="unsafe blocks are unsupported in constants",
),
ExtractGuard(
guard_id='capture_exclude_trait_allowlist',
target_file='trusted/rustc-capture/src/ir.rs',
mode="capture",
description='ExcludedTrait::parse_canonical refuses traits outside the closed allowlist (e.g. core::ops::Drop)',
anchor=' _ => Err(format!(\n "trait `{raw}` is not in the closed --exclude-trait allowlist \\\n (allowed: core::error::Error, core::fmt::Debug, core::fmt::Display)"\n )),',
replacement=' _ => Ok(Self::Debug),',
negative_source='pub fn zero() -> u64 { 0 }\n',
capture_scope='crate',
exclude_traits=('core::ops::Drop',),
expected_baseline_diagnostic='not in the closed --exclude-trait allowlist',
),
ExtractGuard(
guard_id='capture_exclude_trait_select_scope',
target_file='trusted/rustc-capture/src/lib.rs',
mode="capture",
description='Args::resolved_scope refuses --exclude-trait when combined with --select or --instantiate',
anchor=' if !self.exclude_trait.is_empty() {\n return Err(Failure::unsupported(\n "--exclude-trait is valid only with --scope crate; \\\n cannot be combined with --select or --instantiate",\n ));\n }',
replacement=' if false && !self.exclude_trait.is_empty() {\n return Err(Failure::unsupported(\n "--exclude-trait is valid only with --scope crate; \\\n cannot be combined with --select or --instantiate",\n ));\n }',
negative_source='pub fn selected() -> u64 { 0 }\n',
capture_scope='select',
exclude_traits=('core::fmt::Debug',),
expected_baseline_diagnostic='--exclude-trait is valid only with --scope crate',
),
ExtractGuard(
guard_id='capture_exclude_trait_reachability',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='ExclusionIndex::check_body_disjoint refuses verified bodies or constants referencing excluded trait impl items',
anchor=" fn check_body_disjoint<'tcx>(\n &self,\n tcx: TyCtxt<'tcx>,\n typing_env: TypingEnv<'tcx>,\n body: &mir::Body<'tcx>,\n ) -> extract::Result<()> {\n if self.excluded_traits.is_empty() {\n return Ok(());\n }",
replacement=" fn check_body_disjoint<'tcx>(\n &self,\n tcx: TyCtxt<'tcx>,\n typing_env: TypingEnv<'tcx>,\n body: &mir::Body<'tcx>,\n ) -> extract::Result<()> {\n if true || self.excluded_traits.is_empty() {\n return Ok(());\n }",
negative_source='#[derive(Debug)]\npub enum E { A }\npub const C: u64 = { let _ = <E as core::fmt::Debug>::fmt; 42 };\npub fn zero() -> u64 { C }\n',
capture_scope='crate',
exclude_traits=('core::fmt::Debug',),
expected_baseline_diagnostic='references excluded item',
),
ExtractGuard(
guard_id='capture_exclude_trait_nested_def',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='find_excluded_ancestor keeps unexcludable nested items (e.g. #[no_mangle] fns) out of the exclusion set',
anchor=' if is_unexcludable_nested_def(tcx, id, tcx.def_kind(id)) {\n return None;\n }',
replacement=' if false && is_unexcludable_nested_def(tcx, id, tcx.def_kind(id)) {\n return None;\n }',
negative_source='pub enum S { A }\nimpl core::fmt::Display for S {\n fn fmt(&self, f: &mut core::fmt::Formatter<\'_>) -> core::fmt::Result {\n #[unsafe(no_mangle)]\n pub fn smuggled() -> u64 { 0 }\n f.write_str("s")\n }\n}\npub fn zero() -> u64 { 0 }\n',
capture_scope='crate',
exclude_traits=('core::fmt::Display',),
expected_baseline_diagnostic='NO_MANGLE',
),
ExtractGuard(
guard_id='capture_exclude_trait_nested_impl_descendant',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='find_excluded_ancestor short-circuits on unexcludable ancestor impls so their descendant methods stay in the required census',
anchor=' if is_unexcludable_nested_def(tcx, id, tcx.def_kind(id)) {\n return None;\n }',
replacement=' if id == def && is_unexcludable_nested_def(tcx, id, tcx.def_kind(id)) {\n return None;\n }',
negative_source='pub enum S { A }\npub enum K { B }\nimpl core::fmt::Display for S {\n fn fmt(&self, f: &mut core::fmt::Formatter<\'_>) -> core::fmt::Result {\n impl K {\n pub fn evil() -> f64 { 1.0 }\n }\n f.write_str("s")\n }\n}\npub fn zero() -> u64 { 0 }\n',
capture_scope='crate',
exclude_traits=('core::fmt::Display',),
expected_baseline_diagnostic='unsupported type: f64',
),
ExtractGuard(
guard_id='capture_exclude_trait_impl_header',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='build_exclusion_index requires excluded trait impls to pass admit_safe_impl (refusing negative/unsafe/default/const impls)',
anchor=' if let Some(&tr) = excluded_traits.get(&trait_did)\n && admit_safe_impl(tcx, def, true).is_ok()\n {\n excluded_impls.insert(def, tr);\n }',
replacement=' if let Some(&tr) = excluded_traits.get(&trait_did)\n && (true || admit_safe_impl(tcx, def, true).is_ok())\n {\n excluded_impls.insert(def, tr);\n }',
negative_source='#![feature(negative_impls)]\npub enum S { A }\nimpl !core::fmt::Display for S {}\npub fn zero() -> u64 { 0 }\n',
capture_scope='crate',
allow_unstable_features=('negative_impls',),
exclude_traits=('core::fmt::Display',),
expected_baseline_diagnostic='negative polarity',
),
ExtractGuard(
guard_id='capture_exclude_trait_supertrait_dyn',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='check_trait_or_supertraits elaborates supertraits so dyn subtraits of excluded traits fail closed',
anchor=' for super_ref in rustc_trait_selection::traits::supertraits(\n tcx,\n ty::Binder::dummy(ty::TraitRef::identity(tcx, principal_did)),\n ) {',
replacement=' for super_ref in rustc_trait_selection::traits::supertraits(\n tcx,\n ty::Binder::dummy(ty::TraitRef::identity(tcx, principal_did)),\n ).take(0) {',
negative_source='#[derive(Debug)]\npub enum E { A }\npub trait SubDebug: core::fmt::Debug {}\nimpl SubDebug for E {}\npub const C: u64 = { let _: Option<&dyn SubDebug> = None; 42 };\npub fn zero() -> u64 { C }\n',
capture_scope='crate',
exclude_traits=('core::fmt::Debug',),
expected_baseline_diagnostic='whose supertrait',
),
ExtractGuard(
guard_id='capture_exclude_trait_nonlocal_predicates',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='check_fn_ty elaborates instantiated predicates_of for non-local FnDefs to reject external callees with excluded-trait bounds',
anchor=' if !def_id.is_local() {\n self.check_nonlocal_predicates(tcx, def_id, args, context)?;',
replacement=' if false && !def_id.is_local() {\n self.check_nonlocal_predicates(tcx, def_id, args, context)?;',
negative_source='#[derive(Debug)]\npub enum E { A }\npub const C: u64 = { let _ = core::fmt::DebugSet::entries::<E, Option<E>>; 42 };\npub fn zero() -> u64 { C }\n',
capture_scope='crate',
exclude_traits=('core::fmt::Debug',),
expected_baseline_diagnostic='trait bound',
),
ExtractGuard(
guard_id='capture_exclude_trait_resolved_instance_predicates',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='check_fn_ty elaborates predicates_of for the non-local item a trait method resolves to, so blanket impls bounded on excluded traits fail closed',
anchor=' if let ty::InstanceKind::Item(item_did) = instance.def\n && item_did != def_id',
replacement=' if false && let ty::InstanceKind::Item(item_did) = instance.def\n && item_did != def_id',
negative_source='pub enum E { A }\nimpl core::fmt::Display for E {\n fn fmt(&self, f: &mut core::fmt::Formatter<\'_>) -> core::fmt::Result {\n f.write_str("e")\n }\n}\npub const C: u64 = { let _ = <E as std::string::ToString>::to_string; 42 };\npub fn zero() -> u64 { C }\n',
capture_scope='crate',
exclude_traits=('core::fmt::Display',),
expected_baseline_diagnostic='trait bound',
),
ExtractGuard(
guard_id='capture_exclude_trait_user_unsafe_block',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='is_unexcludable_nested_def keeps items whose bodies contain user-written unsafe blocks out of the exclusion set',
anchor=' if matches!(b.rules, hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::UserProvided)) {',
replacement=' if false && matches!(b.rules, hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::UserProvided)) {',
negative_source='pub enum S { A }\nimpl core::fmt::Debug for S {\n fn fmt(&self, f: &mut core::fmt::Formatter<\'_>) -> core::fmt::Result {\n let _ = unsafe { core::mem::transmute::<u8, i8>(1) };\n f.write_str("s")\n }\n}\npub fn zero() -> u64 { 0 }\n',
capture_scope='crate',
exclude_traits=('core::fmt::Debug',),
expected_baseline_diagnostic='std::fmt::Error',
),
ExtractGuard(
guard_id='capture_exclude_trait_inline_asm',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='is_unexcludable_nested_def keeps items whose bodies contain inline assembly (including naked_asm!) out of the exclusion set',
anchor=' if matches!(ex.kind, hir::ExprKind::InlineAsm(_)) {',
replacement=' if false && matches!(ex.kind, hir::ExprKind::InlineAsm(_)) {',
negative_source='pub enum S { A }\nimpl core::fmt::Display for S {\n fn fmt(&self, f: &mut core::fmt::Formatter<\'_>) -> core::fmt::Result {\n #[unsafe(naked)]\n extern "C" fn tramp() { core::arch::naked_asm!("ret") }\n f.write_str("s")\n }\n}\npub fn zero() -> u64 { 0 }\n',
capture_scope='crate',
exclude_traits=('core::fmt::Display',),
expected_baseline_diagnostic='only non-variadic Rust ABI functions are admitted',
),
ExtractGuard(
guard_id='capture_exclude_trait_unsafe_fn',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='is_unexcludable_nested_def keeps unsafe fns, which need no unsafe block for unsafe operations, out of the exclusion set',
anchor=' || tcx.fn_sig(def).instantiate_identity().skip_binder().safety().is_unsafe()\n',
replacement=' || false\n',
negative_source='pub enum S { A }\nimpl core::fmt::Display for S {\n fn fmt(&self, f: &mut core::fmt::Formatter<\'_>) -> core::fmt::Result {\n #[allow(dead_code)]\n unsafe fn poke() -> f64 { 1.0 }\n f.write_str("s")\n }\n}\npub fn zero() -> u64 { 0 }\n',
capture_scope='crate',
exclude_traits=('core::fmt::Display',),
expected_baseline_diagnostic='unsupported type: f64',
),
ExtractGuard(
guard_id='capture_exclude_trait_promoted_mir',
target_file='trusted/rustc-capture/src/capture.rs',
mode="capture",
description='check_mir_const inspects tcx.promoted_mir(uv.def)[promoted] so promoted constants referencing excluded items fail closed',
anchor=' if let Some(promoted) = uv.promoted\n && seen_promoted.insert((uv.def, promoted))\n {',
replacement=' if false && let Some(promoted) = uv.promoted\n && seen_promoted.insert((uv.def, promoted))\n {',
negative_source="#[derive(Debug)]\npub enum E { A }\npub const C: u64 = {\n let _r: &'static fn(&E, &mut core::fmt::Formatter<'_>) -> core::fmt::Result =\n &(<E as core::fmt::Debug>::fmt\n as fn(&E, &mut core::fmt::Formatter<'_>) -> core::fmt::Result);\n 42\n};\npub fn zero() -> u64 { C }\n",
capture_scope='crate',
exclude_traits=('core::fmt::Debug',),
expected_baseline_diagnostic='promoted',
),
ExtractGuard(
guard_id="capture_rec_mutual_refused",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description=(
"handle_pointee_ty refuses a Box/Vec back edge to a struct other "
"than the innermost one being translated (mutual recursion)"
),
anchor=" if pos + 1 != visiting.len() {",
replacement=" if false && pos + 1 != visiting.len() {",
negative_source=(
"pub struct A { pub b: Option<Box<B>>, pub v: u8 }\n"
"pub struct B { pub a: Option<Box<A>>, pub v: u8 }\n"
"pub fn selected(a: &A) -> u8 { a.v }\n"
),
expected_baseline_diagnostic="mutually recursive struct types are unsupported",
),
ExtractGuard(
guard_id="capture_adt_mut_downcast_refused",
target_file="trusted/rustc-capture/src/ir.rs",
mode="capture",
description=(
"Body::try_new refuses a mutable borrow or write through a payload "
"enum downcast, which could store bytes at a niche enum's tag"
),
anchor=(
" if require_mut_deref\n"
" || role == \"assignment\"\n"
" || (role == \"ref_mut\" && !direct_ref_mut)\n"
" {"
),
replacement=" if false {",
negative_source=(
"pub enum N { A(bool, u8), B }\n"
"pub fn selected(n: &mut N) { if let N::A(_, x) = n { *x = 1; } }\n"
),
expected_baseline_diagnostic="mutable borrow through a downcast",
),
ExtractGuard(
guard_id="capture_adt_mut_downcast_direct_only",
target_file="trusted/rustc-capture/src/ir.rs",
mode="capture",
description=(
"Body::try_new admits a mutable borrow through a payload enum "
"downcast only for a Direct enum, whose fields lie outside the tag"
),
anchor=" && matches!(aty.layout.encoding, AdtTagEncoding::Direct);",
replacement=" && true;",
negative_source=(
"pub enum N { A(bool, u8), B }\n"
"pub fn selected(n: &mut N) { if let N::A(_, x) = n { *x = 1; } }\n"
),
expected_baseline_diagnostic="mutable borrow through a downcast",
),
ExtractGuard(
guard_id="capture_place_mention_checks_place",
target_file="trusted/rustc-capture/src/ir.rs",
mode="capture",
description=(
"Body::try_new checks a projected PlaceMention's place as a read "
"operand, refusing an unsized deref"
),
anchor=(
" check_place(\n"
" &local_tys,\n"
" place,\n"
" \"operand\",\n"
" false,\n"
" false,\n"
" promoted_locals.contains(&place.local),\n"
" )?;\n"
" }\n"
" Statement::Nop => {}"
),
replacement=(
" let _ = place;\n"
" }\n"
" Statement::Nop => {}"
),
negative_source="pub fn selected(s: &[u8]) -> usize { let _ = *s; 0 }\n",
expected_baseline_diagnostic="unsized deref of",
),
ExtractGuard(
guard_id="extract_reject_indirect_option_downcast_move",
target_file="trusted/rustc-capture/src/ir.rs",
mode="capture",
description=(
"Body::try_new refuses Operand::MovePlace on (x as Some).0 when x "
"has its address taken in the body (promoted to .indirect)"
),
anchor=" }) && !promoted_locals.contains(&place.local) =>",
replacement=" }) && true =>",
negative_source=(
"pub fn selected(o: Option<Box<u8>>) -> Option<Box<u8>> {\n"
" let r = &o;\n"
" let _ = matches!(r, Some(_));\n"
" match o {\n"
" Some(b) => Some(b),\n"
" None => None,\n"
" }\n"
"}\n"
),
expected_baseline_diagnostic="projected move operands",
),
ExtractGuard(
guard_id="extract_option_handle_niche_start",
target_file="trusted/rustc-capture/src/ir.rs",
mode="unit",
description=(
"check_niche_option_handle_layout enforces niche_start == 0 for "
"Option<Box<..>> and niche_start == VEC_NONE_NICHE (u64::MAX) for "
"Option<Vec<T>>"
),
anchor=(
" if !niche_ok {\n"
" return Err(format!(\n"
' "Option<{kind:?}> niche_start ({niche_start:#x}) disagrees with modeled niche range"'
),
replacement=(
" if false {\n"
" return Err(format!(\n"
' "Option<{kind:?}> niche_start ({niche_start:#x}) disagrees with modeled niche range"'
),
unit_test_name=(
"ir::tests::niche_option_handle_layout_check_enforces_tag_niche_and_payload_offset"
),
),
ExtractGuard(
guard_id="extract_option_handle_some_payload_offset",
target_file="trusted/rustc-capture/src/ir.rs",
mode="unit",
description=(
"check_niche_option_handle_layout requires Some payload offset 0 "
"matching Trusted.MirSemantics.optionSomeOffsetV2"
),
anchor=(
" if some_payload_offset != Some(0) {\n"
" return Err(format!(\n"
' "Option<{kind:?}> Some payload offset ({some_payload_offset:?}) \\'
),
replacement=(
" if false {\n"
" return Err(format!(\n"
' "Option<{kind:?}> Some payload offset ({some_payload_offset:?}) \\'
),
unit_test_name=(
"ir::tests::niche_option_handle_layout_check_enforces_tag_niche_and_payload_offset"
),
),
# ------------------------------------------------------------------
# Ambient CTFE and built-in source-location macro guards
# ------------------------------------------------------------------
ExtractGuard(
guard_id="capture_reject_ambient_location_macros",
target_file="trusted/rustc-capture/src/capture.rs",
mode="capture",
description=(
"check_no_ambient_builtin_macros rejects file!/line!/column!/"
"module_path!"
),
anchor=(
" if let Some(name) = builtin\n"
" && matches!(name, sym::file | sym::line | sym::column "
"| sym::module_path)\n"
" {"
),
replacement=(
" if let Some(name) = builtin\n"
" && false\n"
" {"
),
negative_source=(
"const F: usize = file!().len();\n"
"pub fn selected(x: usize) -> usize { x.wrapping_add(F) }\n"
),
expected_baseline_diagnostic="macro is unsupported during capture",
),
ExtractGuard(
guard_id="ctfe_finalize_reject_violations",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"ctfe::check_current_violations fails closed whenever any CTFE "
"violation is recorded"
),
anchor=" if !violations.is_empty() {",
replacement=" if false && !violations.is_empty() {",
negative_source=(
"const N: usize = core::panic::Location::caller().file().len();\n"
"pub fn selected(x: usize) -> usize { x.wrapping_add(N) }\n"
),
expected_baseline_diagnostic="core::panic::Location",
),
ExtractGuard(
guard_id="ctfe_reject_forbidden_intrinsics",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"is_forbidden_ctfe_intrinsic rejects TypeId/type_name/"
"caller_location/vtable/heap CTFE intrinsics"
),
anchor=(
"fn is_forbidden_ctfe_intrinsic(name: Symbol) -> bool {\n"
" matches!("
),
replacement=(
"fn is_forbidden_ctfe_intrinsic(name: Symbol) -> bool {\n"
" false && matches!("
),
negative_source=(
"#[allow(dead_code)]\n"
"fn generic_only<T: 'static>() -> core::any::TypeId {\n"
" const { core::any::TypeId::of::<T>() }\n"
"}\n"
"pub fn selected(x: u32) -> u32 { x }\n"
),
expected_baseline_diagnostic="type_id",
),
ExtractGuard(
guard_id="ctfe_reject_non_core_track_caller",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"check_def_identity rejects non-core #[track_caller] functions "
"reached in CTFE"
),
anchor=(
" if !is_exempt_core_tracked_helper(tcx, target) "
"&& def_requires_caller_location(tcx, target) {"
),
replacement=(
" if false && !is_exempt_core_tracked_helper(tcx, target) "
"&& def_requires_caller_location(tcx, target) {"
),
negative_source=(
"#[track_caller]\n"
"const fn tracked(v: usize) -> usize { v }\n"
"const N: usize = tracked(7);\n"
"pub fn selected(x: usize) -> usize { x.wrapping_add(N) }\n"
),
expected_baseline_diagnostic="#[track_caller]",
),
ExtractGuard(
guard_id="ctfe_reject_panic_location_type",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"scan_ty rejects core::panic::Location ADT types appearing in CTFE"
),
anchor=(
" ty::Adt(adt, _) if is_panic_location_item(tcx, adt.did()) => {\n"
" summary.violations.push(CtfeViolation::ambient(format!("
),
replacement=(
" ty::Adt(adt, _) if false && is_panic_location_item(tcx, adt.did()) => {\n"
" summary.violations.push(CtfeViolation::ambient(format!("
),
negative_source=(
"const SZ: usize = core::mem::size_of::<core::panic::Location<'static>>();\n"
"pub fn selected(x: usize) -> usize { x.wrapping_add(SZ) }\n"
),
expected_baseline_diagnostic="core::panic::Location",
),
ExtractGuard(
guard_id="ctfe_reject_static_ref_global_alloc",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"scan_alloc_ids rejects GlobalAlloc::Static references inside CTFE "
"constants"
),
anchor=(
" GlobalAlloc::Static(did) => {\n"
" if !allow_static_refs {"
),
replacement=(
" GlobalAlloc::Static(did) => {\n"
" if false && !allow_static_refs {"
),
negative_source=(
"const C: usize = {\n"
" static S: u8 = 7;\n"
" let _p: &u8 = &S;\n"
" 1\n"
"};\n"
"pub fn selected(x: usize) -> usize { x.wrapping_add(C) }\n"
),
expected_baseline_diagnostic="static",
),
ExtractGuard(
guard_id="ctfe_reject_vtable_global_alloc",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"scan_alloc_ids rejects GlobalAlloc::VTable allocations inside "
"constants"
),
anchor=(
" GlobalAlloc::VTable(..) => {\n"
" summary.violations.push(CtfeViolation::ambient(format!(\n"
' "vtable global allocations in `{owner_path}` are unsupported in constants",\n'
" )));\n"
" }"
),
replacement=(
" GlobalAlloc::VTable(..) => {\n"
" let _ = owner_path;\n"
" }"
),
negative_source=(
"#[allow(dead_code)]\n"
"const V: &dyn core::fmt::Debug = &0u8;\n"
"pub fn selected(x: usize) -> usize { x }\n"
),
expected_baseline_diagnostic="vtable",
),
ExtractGuard(
guard_id="ctfe_has_ctfe_mir_external_inline_const",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"has_ctfe_mir treats external InlineConst bodies (e.g. "
"core::any::TypeId::of::{constant#0}) as having mir_for_ctfe"
),
anchor=(
" DefKind::Const { is_type_const: false } "
"| DefKind::AnonConst | DefKind::InlineConst => {"
),
replacement=(
" DefKind::Const { is_type_const: false } "
"| DefKind::AnonConst => {"
),
negative_source=(
"#[allow(dead_code)]\n"
"struct Generic<T>(T);\n"
"#[allow(dead_code)]\n"
"impl<T: 'static> Generic<T> {\n"
" const ID: core::any::TypeId = core::any::TypeId::of::<T>();\n"
"}\n"
"pub fn selected(x: u32) -> u32 { x }\n"
),
expected_baseline_diagnostic="type_id",
),
ExtractGuard(
guard_id="ctfe_local_const_closure",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"audit_after_analysis seeds crate-local AnonConst/Const/AssocConst/"
"InlineConst roots to catch unmonomorphized generic CTFE"
),
anchor=(
" let need_seed = stdlib_crate.is_none() "
"&& with_state(|s| !s.local_consts_seeded);"
),
replacement=" let need_seed = false;",
negative_source=(
"#[allow(dead_code)]\n"
"fn generic_only<T: 'static>() -> &'static core::any::TypeId {\n"
" &const { core::any::TypeId::of::<T>() }\n"
"}\n"
"pub fn selected(x: u32) -> u32 { x }\n"
),
expected_baseline_diagnostic="type_id",
),
ExtractGuard(
guard_id="ctfe_promoted_mir_scan",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"audit_after_analysis seeds crate-local promoted_mir bodies to "
"catch unmonomorphized generic promoted constants"
),
anchor=(
" for p in tcx.promoted_mir(did).indices() {\n"
" target_roots.push(BodyKey::new(did, Some(p.as_u32())));\n"
" }"
),
replacement=" let _ = (did, target_roots);",
negative_source=(
"#[track_caller]\n"
"const fn tracked() -> u32 { 1 }\n"
"#[allow(dead_code)]\n"
"fn generic_only<T>() -> &'static fn() -> u32 {\n"
" &(tracked as fn() -> u32)\n"
"}\n"
"pub fn selected(x: u32) -> u32 { x }\n"
),
expected_baseline_diagnostic="#[track_caller]",
),
ExtractGuard(
guard_id="ctfe_bfs_transitive_callees",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"collect_bfs_violations traverses transitive CTFE callees so "
"helper const fn bodies with ambient intrinsics fail closed"
),
anchor=(
" for &callee in &summary.callees {\n"
" if !visited.contains(&callee) {\n"
" queue.push_back(callee);\n"
" }\n"
" }"
),
replacement=" let _ = &summary.callees;",
negative_source=(
"const fn helper() -> bool {\n"
" let _ = core::any::TypeId::of::<u8>();\n"
" true\n"
"}\n"
"#[allow(dead_code)]\n"
"fn generic_only<T>() { const { let _ = helper(); } }\n"
"pub fn selected(x: u32) -> u32 { x }\n"
),
expected_baseline_diagnostic="type_id",
),
ExtractGuard(
guard_id="ctfe_static_root_ambient_audit",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"check_current_violations audits static_roots for ambient CTFE "
"channels such as #[track_caller]"
),
anchor=(
" collect_bfs_violations("
"s, s.static_roots.iter().copied(), true, false, &mut found);"
),
replacement=" let _ = &s.static_roots;",
negative_source=(
"#[track_caller]\n"
"const fn tracked() -> usize { 1 }\n"
"static S: usize = tracked();\n"
"pub fn selected(x: u32) -> u32 { x }\n"
),
expected_baseline_diagnostic="#[track_caller]",
),
ExtractGuard(
guard_id="ctfe_reject_core_guaranteed_cmp_normal_crate",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"violation_matches refuses ptr_guaranteed_cmp (CoreGuaranteedCmp) "
"on normal crates"
),
anchor=(
" ViolationKind::CoreGuaranteedCmp => !allow_core_guaranteed_cmp,"
),
replacement=" ViolationKind::CoreGuaranteedCmp => false,",
negative_source=(
"const B: bool = core::ptr::null::<u8>().is_null();\n"
"pub fn selected(x: u32) -> u32 { if B { x } else { 0 } }\n"
),
expected_baseline_diagnostic="ptr_guaranteed_cmp",
),
ExtractGuard(
guard_id="ctfe_reject_core_guaranteed_cmp_stdlib_core",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"check_current_violations refuses dynamically loaded "
"ptr_guaranteed_cmp constants (including pre-folded match "
"patterns) under --stdlib-crate=core"
),
anchor=(
" for key in &s.dynamic_ctfe_bodies {\n"
" if let Some(summary) = s.body_summaries.get(key) {\n"
" for v in &summary.violations {\n"
" if violation_matches(v.kind, summary.is_static_initializer, false) {\n"
" found.insert(v.message.clone());\n"
" }\n"
" }\n"
" }\n"
" }"
),
replacement=" let _ = &s.dynamic_ctfe_bodies;",
negative_source=(
"#![feature(no_core, lang_items, intrinsics, auto_traits)]\n"
"#![allow(internal_features)]\n"
"#![no_core]\n"
'#[lang = "pointee_sized"] pub trait PointeeSized {}\n'
'#[lang = "meta_sized"] pub trait MetaSized: PointeeSized {}\n'
'#[lang = "sized"] pub trait Sized: MetaSized {}\n'
'#[lang = "copy"] pub trait Copy {}\n'
"impl Copy for u8 {}\n"
'#[lang = "freeze"] pub unsafe auto trait Freeze {}\n'
'#[lang = "eq"] pub trait PartialEq<Rhs: ?Sized = Self> {}\n'
"impl PartialEq for u8 {}\n"
'#[lang = "structural_peq"] pub trait StructuralPartialEq {}\n'
"impl StructuralPartialEq for u8 {}\n"
"#[rustc_intrinsic]\n"
"pub const fn ptr_guaranteed_cmp<T>(ptr: *const T, other: *const T) -> u8;\n"
"const C: u8 = ptr_guaranteed_cmp(0 as *const u8, 0 as *const u8);\n"
"pub fn selected(x: u8) -> u8 { match x { C => 1, _ => 0 } }\n"
),
stdlib_crate="core",
expected_baseline_diagnostic="ptr_guaranteed_cmp",
),
ExtractGuard(
guard_id="ctfe_static_ref_initializer_only_stdlib_core",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"summarize_mir_body restricts the StaticRef exemption strictly to "
"DefKind::Static initializer bodies so callable const_trait_impl "
"bodies memoized under static INIT cannot leak static reads into "
"const C under --stdlib-crate=core"
),
anchor=(
" let mut summary = "
"CtfeBodySummary { is_static_initializer, ..CtfeBodySummary::default() };"
),
replacement=(
" let mut summary = "
"CtfeBodySummary { is_static_initializer: true, ..CtfeBodySummary::default() };"
),
negative_source=(
"#![feature(no_core, lang_items, auto_traits, const_trait_impl)]\n"
"#![allow(internal_features)]\n"
"#![no_core]\n"
'#[lang = "pointee_sized"] pub trait PointeeSized {}\n'
'#[lang = "meta_sized"] pub trait MetaSized: PointeeSized {}\n'
'#[lang = "sized"] pub trait Sized: MetaSized {}\n'
'#[lang = "copy"] pub trait Copy {}\n'
"impl Copy for u8 {}\n"
'#[lang = "freeze"] pub unsafe auto trait Freeze {}\n'
'#[lang = "sync"] pub unsafe trait Sync {}\n'
"unsafe impl Sync for u8 {}\n"
'#[lang = "eq"] pub trait PartialEq<Rhs: ?Sized = Self> {}\n'
"impl PartialEq for u8 {}\n"
'#[lang = "structural_peq"] pub trait StructuralPartialEq {}\n'
"impl StructuralPartialEq for u8 {}\n"
"static S: u8 = 7;\n"
"pub const trait Read { fn read() -> u8; }\n"
"pub struct Reader;\n"
"impl const Read for Reader { fn read() -> u8 { S } }\n"
"const fn via_trait<T: [const] Read>() -> u8 { T::read() }\n"
"#[allow(dead_code)]\n"
"static INIT: u8 = via_trait::<Reader>();\n"
"const C: u8 = via_trait::<Reader>();\n"
"pub fn selected(x: u8) -> u8 { match x { C => 1, _ => 0 } }\n"
),
stdlib_crate="core",
expected_baseline_diagnostic="static",
),
ExtractGuard(
guard_id="ctfe_diverging_call_args_location",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"check_diverging_call_no_location refuses Location::caller, "
"caller_location, and non-exempt #[track_caller] FnDef references "
"on diverging runtime calls"
),
anchor=(
" check_diverging_fndef(tcx, typing_env, owner_def, did, fn_args)?;"
),
replacement=(
" let _ = (tcx, typing_env, owner_def, did, fn_args);"
),
negative_source=(
"fn diverge_sink<F>(_f: F) -> ! { loop {} }\n"
"pub fn selected(x: u32) -> u32 {\n"
" if x == u32::MAX { diverge_sink(core::panic::Location::caller); }\n"
" x\n"
"}\n"
),
expected_baseline_diagnostic="core::panic::Location",
),
ExtractGuard(
guard_id="ctfe_diverging_call_callee_track_caller",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="capture",
description=(
"check_diverging_call_no_location inspects the diverging callee "
"operand (not only args) to refuse non-exempt #[track_caller] callees"
),
anchor=(
" for op in core::iter::once(func).chain(args.iter().map(|spanned| &spanned.node)) {"
),
replacement=(
" let _ = func;\n"
" for op in args.iter().map(|spanned| &spanned.node) {"
),
negative_source=(
"#[track_caller]\n"
"fn diverge_tracked() -> ! { loop {} }\n"
"pub fn selected(x: u32) -> u32 {\n"
" if x == u32::MAX { diverge_tracked(); }\n"
" x\n"
"}\n"
),
expected_baseline_diagnostic="#[track_caller]",
),
ExtractGuard(
guard_id="ctfe_eval_mir_const_non_value_ty_const",
target_file="trusted/rustc-capture/src/ctfe.rs",
mode="unit",
description=(
"eval_mir_const_audited rejects non-value Const::Ty variants "
"(ConstKind::Expr / Placeholder) before Const::eval"
),
anchor=(
" mir::Const::Ty(_, ct) if matches!(ct.kind(), ty::ConstKind::Value(_)) => constant"
),
replacement=(
" mir::Const::Ty(_, _) => constant"
),
unit_test_name=(
"ctfe::tests::eval_mir_const_audited_rejects_const_kind_expr_and_placeholder"
),
),
ExtractGuard(
guard_id="extract_stub_reject_c_abi",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
capture_scope="crate",
description=(
"extract_stub_body rejects non-Rust ABI (including extern \"C\") "
"until Trusted.MirAst.Body records per-body ABIs"
),
anchor=(
" if signature.c_variadic() || signature.abi() != ExternAbi::Rust {"
),
replacement=(
" if signature.c_variadic()\n"
" || !matches!(signature.abi(), ExternAbi::Rust | ExternAbi::C { unwind: false })\n"
" {"
),
negative_source=(
"#![feature(register_tool)]\n"
"#![register_tool(anneal)]\n"
"unsafe extern \"C\" {\n"
" #[anneal::assume_stub(reason = \"external C fn\")]\n"
" pub fn c_helper(x: u32) -> u32;\n"
"}\n"
"pub fn portable(x: u32) -> u32 { x }\n"
),
allow_unstable_features=("register_tool",),
expected_baseline_diagnostic="Rust ABI",
),
ExtractGuard(
guard_id="capture_dead_local_unmentioned",
target_file="trusted/rustc-capture/src/ir.rs",
mode="capture",
description=(
"dead_local_ty erases only a local that nothing mentions, so a "
"local mentioned by storage markers or debuginfo keeps its type"
),
anchor=" if idx <= arg_count || mentioned {",
replacement=" if idx <= arg_count {",
negative_source="pub fn selected() -> u8 { let _x: f64; 0 }\n",
expected_baseline_diagnostic="unsupported type: f64",
),
ExtractGuard(
guard_id="capture_ref_forwarded_eq_track_caller",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description=(
"a reference comparison forwards only to a crate-local method "
"without #[track_caller], like an intra-crate call"
),
anchor=(
" if tcx.codegen_fn_attrs(resolved).flags.contains("
"CodegenFnAttrFlags::TRACK_CALLER) {\n"
' return Err(format!("{context}: forwarded call is '
'#[track_caller]"));'
),
replacement=(
" if false {\n"
' return Err(format!("{context}: forwarded call is '
'#[track_caller]"));'
),
negative_source=(
"pub struct A(pub u8);\n"
"impl PartialEq for A {\n"
" #[track_caller]\n"
" fn eq(&self, o: &Self) -> bool { self.0 == o.0 }\n"
"}\n"
"pub fn selected(a: &A, b: &A) -> bool { a == b }\n"
),
expected_baseline_diagnostic="forwarded call is #[track_caller]",
),
ExtractGuard(
guard_id="capture_local_box_clone_track_caller",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description=(
"Box<T>::clone calls T::clone only when it is a crate-local method "
"without #[track_caller], like an intra-crate call"
),
anchor=(
" if tcx.codegen_fn_attrs(resolved).flags.contains("
"CodegenFnAttrFlags::TRACK_CALLER) {\n"
' return Err(format!("{context}: `{pointee:?}::clone` is '
'#[track_caller]"));'
),
replacement=(
" if false {\n"
' return Err(format!("{context}: `{pointee:?}::clone` is '
'#[track_caller]"));'
),
negative_source=(
"pub struct W(pub u32);\n"
"impl Clone for W {\n"
" #[track_caller]\n"
" fn clone(&self) -> W { W(self.0) }\n"
"}\n"
"pub fn selected(b: &Box<W>) -> Box<W> { b.clone() }\n"
),
panic_strategy="abort",
expected_baseline_diagnostic="`W::clone` is #[track_caller]",
),
ExtractGuard(
guard_id="capture_nested_mut_ref_copy_read_only",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description=(
"a `&mut T` copied out of a `& &mut T` may only be reborrowed "
"shared or read, so no write can go through it"
),
anchor=(
" _ => false,\n"
" };\n"
" if !allowed && self.error.is_none() {"
),
replacement=(
" _ => true,\n"
" };\n"
" if !allowed && self.error.is_none() {"
),
negative_source="pub fn selected(m: &mut u8) -> u8 { let x = &m; let _ = **x; 0 }\n",
expected_baseline_diagnostic="copied out of a `& &mut T` may only be reborrowed",
),
ExtractGuard(
guard_id="capture_nested_mut_ref_fence_enforced",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description=(
"check_nested_mut_ref_copies refuses every use of a `&mut T` copied "
"out of a `& &mut T` outside its allowlist; disabling the refusal "
"would also let a write through the copy pass, which the borrow "
"checker keeps out of Rust source, so a refused read kills it"
),
anchor=" if !allowed && self.error.is_none() {",
replacement=" if false && self.error.is_none() {",
negative_source=(
"#[derive(Clone, Copy)]\n"
"pub struct S { pub a: u64, pub b: u64 }\n"
"pub fn selected(m: &mut S) -> u64 { let x = &m; let v: S = **x; v.a }\n"
),
expected_baseline_diagnostic="copied out of a `& &mut T` may only be reborrowed",
),
ExtractGuard(
guard_id="capture_nested_mut_ref_scalar_copy",
target_file="trusted/rustc-capture/src/extract.rs",
mode="capture",
description=(
"a `&mut T` copied out of a `& &mut T` is read whole only when T "
"is a bool, char, or integer"
),
anchor=" || self.scalar_copies.contains(&place.local))",
replacement=" || true)",
negative_source=(
"#[derive(Clone, Copy)]\n"
"pub struct S { pub a: u64, pub b: u64 }\n"
"pub fn selected(m: &mut S) -> u64 { let x = &m; let v: S = **x; v.a }\n"
),
expected_baseline_diagnostic="copied out of a `& &mut T` may only be reborrowed",
),
)
def apply_single_guard_mutation(
source_text: str,
anchor: str,
replacement: str,
*,
guard_id: str,
) -> str:
"""Replace `anchor` with `replacement`, requiring exactly one occurrence.
Requiring a unique match ensures that refactoring a guarded expression in
the TCB fails loudly rather than silently skipping the mutation or editing
the wrong branch.
"""
occurrences = source_text.count(anchor)
if occurrences != 1:
raise ValueError(
f"guard {guard_id!r}: expected anchor to match exactly once, "
f"found {occurrences} occurrences"
)
if anchor == replacement:
raise ValueError(
f"guard {guard_id!r}: replacement must differ from anchor"
)
return source_text.replace(anchor, replacement, 1)
def find_theorem_line_span(
fixture_text: str,
theorem_name: str,
) -> tuple[int, int]:
"""Return the inclusive 1-based `(start, end)` line span of `theorem_name`.
Used to confirm that a Lean proof failure on a mutated semantics actually
originated inside the guard's dedicated refutation theorem rather than in
an unrelated declaration or file header.
"""
lines = fixture_text.splitlines()
decl_re = re.compile(
r"^(?:theorem|lemma|def|noncomputable\s+def|example|instance|"
r"abbrev|structure|inductive|class|opaque|end)\b|^@\["
)
target_re = re.compile(rf"^theorem\s+{re.escape(theorem_name)}\b")
start: int | None = None
for idx, line in enumerate(lines, start=1):
if start is None:
if target_re.match(line):
start = idx
elif decl_re.match(line):
return (start, idx - 1)
if start is None:
raise ValueError(
f"theorem {theorem_name!r} not found in fixture source"
)
return (start, len(lines))
def classify_refutation_failure(
returncode: int,
combined_output: str,
fixture_filename: str,
theorem_span: tuple[int, int],
) -> tuple[str, str]:
"""Classify Lean output on a mutated refutation fixture.
Returns `(status, detail)` where `status` is:
- `SURVIVED`: Lean accepted (`rc == 0`) the negative refutation even after
the guard was disabled.
- `KILLED`: Lean rejected (`rc == 1`) with a genuine proof/type failure
localized inside the target theorem's line span and with no crash/parse
markers.
- `ERROR`: Unexpected exit status, crash/parse/timeout marker, or error
outside the target theorem span (never counted as a kill).
"""
if returncode == 0:
return ("SURVIVED", "refutation theorem still compiled on mutant")
if returncode != 1:
return (
"ERROR",
f"unexpected Lean exit code {returncode} (expected 1 on proof failure)",
)
for marker in NON_KILL_ERROR_MARKERS:
if marker in combined_output:
return (
"ERROR",
f"non-proof failure marker {marker!r} in Lean output",
)
if not any(m in combined_output for m in EXPECTED_PROOF_FAILURE_MARKERS):
return (
"ERROR",
"Lean failed without a recognized proof/type mismatch diagnostic",
)
# Extract `<path>:<line>:<col>: error:` diagnostics belonging to the
# fixture file and confirm at least one lies inside `theorem_span`.
diag_re = re.compile(
rf"{re.escape(fixture_filename)}:(\d+):\d+:\s*error:",
re.MULTILINE,
)
error_lines = [int(m.group(1)) for m in diag_re.finditer(combined_output)]
start, end = theorem_span
matching = [ln for ln in error_lines if start <= ln <= end]
if not matching:
return (
"ERROR",
f"no error diagnostic in target theorem lines {start}-{end} "
f"(saw error lines: {error_lines})",
)
return (
"KILLED",
f"proof failed inside target theorem at line(s) {matching}",
)
def _lean_subprocess_env(
lean_path: list[Path] | None = None,
) -> dict[str, str]:
"""Build a cleared allowlisted environment for child `lean` processes."""
env: dict[str, str] = {}
for key in ("HOME", "TMPDIR", "LANG", "LC_ALL"):
if key in os.environ:
env[key] = os.environ[key]
env["PATH"] = os.environ.get("PATH", "/usr/bin:/bin")
if lean_path is not None:
env["LEAN_PATH"] = os.pathsep.join(str(p) for p in lean_path)
return env
def _run_lean(
lean_bin: Path,
args: list[str],
*,
lean_path: list[Path],
timeout_sec: int,
) -> subprocess.CompletedProcess[str]:
return subprocess.run(
[str(lean_bin), *args],
env=_lean_subprocess_env(lean_path),
capture_output=True,
text=True,
timeout=timeout_sec,
)
def _compile_module(
lean_bin: Path,
root_dir: Path,
module: str,
out_dir: Path,
*,
lean_path: list[Path],
timeout_sec: int,
) -> subprocess.CompletedProcess[str]:
src = root_dir / f"{module}.lean"
olean = out_dir / f"{module}.olean"
olean.parent.mkdir(parents=True, exist_ok=True)
return _run_lean(
lean_bin,
["-R", str(root_dir), "-o", str(olean), str(src)],
lean_path=lean_path,
timeout_sec=timeout_sec,
)
def _query_lean_sysroot(lean_bin: Path, timeout_sec: int) -> str:
res = subprocess.run(
[str(lean_bin), "--print-prefix"],
env=_lean_subprocess_env(),
capture_output=True,
text=True,
timeout=timeout_sec,
check=True,
)
return res.stdout.strip()
def _run_tb_request(
lean_bin: Path,
tb_olean_dir: Path,
req_payload: dict[str, object],
work_dir: Path,
*,
tag: str,
module_name: str = "TrustedBoundary",
timeout_sec: int,
) -> tuple[int, dict[str, object] | None, str]:
"""Invoke precompiled audit module (`TrustedBoundary` or `SpecPreflight`)."""
req_path = work_dir / f"req_{tag}.json"
res_path = work_dir / f"res_{tag}.json"
runner_path = work_dir / f"run_{module_name}.lean"
req_path.write_text(json.dumps(req_payload), encoding="utf-8")
if not runner_path.exists():
runner_path.write_text(f"import {module_name}\n", encoding="utf-8")
proc = _run_lean(
lean_bin,
["--run", str(runner_path), str(req_path), str(res_path)],
lean_path=[tb_olean_dir],
timeout_sec=timeout_sec,
)
parsed: dict[str, object] | None = None
if res_path.is_file():
try:
parsed = json.loads(res_path.read_text(encoding="utf-8"))
except json.JSONDecodeError:
parsed = None
return proc.returncode, parsed, (proc.stdout + "\n" + proc.stderr).strip()
def _run_audit_headers(
lean_bin: Path,
tb_olean_dir: Path,
sysroot: str,
source_text: str,
work_dir: Path,
*,
module_name: str = "TrustedBoundary",
timeout_sec: int,
) -> tuple[int, dict[str, object] | None, str]:
"""Invoke precompiled `TrustedBoundary` or `SpecPreflight` in `"headers"` mode."""
target_src = work_dir / "Target.lean"
target_src.write_text(source_text, encoding="utf-8")
return _run_tb_request(
lean_bin,
tb_olean_dir,
{
"mode": "headers",
"sysroot": sysroot,
"sources": [["Target", str(target_src)]],
},
work_dir,
tag="headers",
module_name=module_name,
timeout_sec=timeout_sec,
)
def _load_foundation_artifacts(
anneal_root: Path,
sysroot: str,
) -> tuple[list[str], dict[str, list[list[str]]]]:
"""Load foundation module names and sysroot artifact paths from lock."""
lock = json.loads(
(anneal_root / "trusted/lean/foundation-lock.json").read_text(
encoding="utf-8"
)
)
lean_lib = Path(sysroot) / "lib/lean"
foundation_mods = sorted(lock["modules"].keys())
artifacts: dict[str, list[list[str]]] = {}
for mod in foundation_mods:
parts = lock["modules"][mod]["parts"]
rel = mod.replace(".", "/")
olean_parts = [
str(lean_lib / f"{rel}.{ext}")
for ext in ("olean", "olean.server", "olean.private")
if parts.get(ext) is not None
]
artifacts[mod] = [olean_parts, []]
return foundation_mods, artifacts
def _build_boundary_fixtures(
*,
anneal_root: Path,
lean_bin: Path,
tb_olean_dir: Path,
sysroot: str,
fixtures_root: Path,
timeout_sec: int,
) -> tuple[
dict[str, dict[str, object]],
dict[str, dict[str, object]],
dict[str, dict[str, object]],
]:
"""Compile minimal baseline and negative boundary fixtures once."""
foundation_mods, foundation_arts = _load_foundation_artifacts(
anneal_root, sysroot
)
rc, parsed, out = _run_tb_request(
lean_bin,
tb_olean_dir,
{
"mode": "resolve-imports",
"sysroot": sysroot,
"modules": foundation_mods,
},
fixtures_root,
tag="resolve_found",
timeout_sec=timeout_sec,
)
if rc != 0 or not isinstance(parsed, dict) or parsed.get("ok") is not True:
raise RuntimeError(
f"resolve-imports failed for foundation: rc={rc} out={out}"
)
found_graph = dict(parsed["result"]["graph"]) # type: ignore[index]
# Pre-Preflight requests
spec_srcs: dict[str, str] = {
"spec_sanity": (
"prelude\nimport Model\n"
"def Spec.specs (p : Nat) : Prop := p = p\n"
),
"spec_auto_implicit": (
"prelude\nimport Model\n"
"set_option autoImplicit true in\n"
"def Spec.bad (x : y_auto) : Nat := 0\n"
),
"spec_bang_ident": (
"prelude\nimport Model\n"
"def Spec.bad (xs : List Nat) : Nat := xs.head!\n"
),
"spec_dbg_trace": (
"prelude\nimport Model\n"
'def Spec.bad : Nat := dbgTrace "leak" fun _ => 1\n'
),
"spec_uv_open": (
"prelude\nimport Model\ndef Spec.specs (p : Nat) : Prop := p = p\n"
"open Std.Internal.UV\n"
),
"spec_default_or_ofNonempty": (
"prelude\nimport Model\n"
"def Spec.specs (p : Nat) : Prop := (default_or_ofNonempty% unsafe : Nat) = p\n"
),
"spec_value_of": (
"prelude\nimport Model\n"
"def Spec.helper : Nat := 0\n"
"def Spec.specs (p : Nat) : Prop := value_of% Spec.helper = p\n"
),
"spec_uv_open_only": (
"prelude\nimport Model\n"
"open Std.Internal (UV.Loop.alive)\n"
"def Spec.specs (p : Nat) : Prop := p = p\n"
),
"spec_uv_open_renaming": (
"prelude\nimport Model\n"
"open Std.Internal renaming UV.Loop.alive -> uvAlive\n"
"def Spec.specs (p : Nat) : Prop := p = p\n"
),
"spec_uv_export": (
"prelude\nimport Model\n"
"export Std.Internal (UV.Loop.alive)\n"
"def Spec.specs (p : Nat) : Prop := p = p\n"
),
"spec_reserved_expected_ns": (
"prelude\nimport Model\n"
"namespace Expected\ndef bad : Nat := 0\nend Expected\n"
"def Spec.specs (p : Nat) : Prop := p = p\n"
),
"spec_reserved_tb_ns": (
"prelude\nimport Model\n"
"namespace TrustedBoundary\ndef bad : Nat := 0\nend TrustedBoundary\n"
"def Spec.specs (p : Nat) : Prop := p = p\n"
),
"spec_export_reserved_alias": (
"prelude\nimport Model\n"
"namespace Safe.Expected\ndef claim : Prop := True\nend Safe.Expected\n"
"export Safe (Expected.claim)\n"
"def Spec.specs (p : Nat) : Prop := p = p\n"
),
"spec_open_renaming_reserved_alias": (
"prelude\nimport Model\n"
"namespace Safe\ndef fakePred : Prop := True\nend Safe\n"
"open Safe renaming fakePred -> Expected.claim\n"
"def Spec.specs (p : Nat) : Prop := p = p\n"
),
}
spec_reqs: dict[str, dict[str, object]] = {}
for name, src in spec_srcs.items():
p = fixtures_root / f"{name}.lean"
p.write_text(src, encoding="utf-8")
spec_reqs[name] = {
"mode": "spec-preflight",
"sysroot": sysroot,
"foundation": foundation_mods,
"libraries": [],
"artifacts": list(foundation_arts.items()),
"graph": found_graph,
"sources": [["Spec", str(p)]],
}
# Build minimal Init.Core-only `.olean` target fixtures for target-audit.
src_dir = fixtures_root / "src"
olean_dir = fixtures_root / "olean"
src_dir.mkdir()
olean_dir.mkdir()
def compile_target_mod(
mod: str,
code: str,
bucket: str,
*,
deps_olean_dirs: list[Path] | None = None,
) -> tuple[Path, Path]:
rel = mod.replace(".", "/")
mod_src_root = src_dir / bucket
mod_olean_root = olean_dir / bucket
s_path = mod_src_root / f"{rel}.lean"
o_path = mod_olean_root / f"{rel}.olean"
s_path.parent.mkdir(parents=True, exist_ok=True)
o_path.parent.mkdir(parents=True, exist_ok=True)
s_path.write_text(code, encoding="utf-8")
c_res = _compile_module(
lean_bin,
mod_src_root,
rel,
mod_olean_root,
lean_path=[*(deps_olean_dirs or []), mod_olean_root],
timeout_sec=timeout_sec,
)
if c_res.returncode != 0:
raise RuntimeError(
f"failed to compile {bucket}/{mod}: "
f"{c_res.stdout}\n{c_res.stderr}"
)
return o_path, mod_olean_root
model_body = (
"namespace Trusted.MirSemantics\n"
"structure Crate where\n"
" program : Nat\n"
" specs : Nat → Prop\n"
"def UnitTheorem (c : Crate) : Prop :=\n"
" c.program = 7 ∧ c.specs c.program\n"
"end Trusted.MirSemantics\n"
)
model_src = "prelude\nimport Init.Core\n" + model_body
model_dbg_src = (
"prelude\nimport Init.Core\nimport Init.Util\n"
+ model_body
+ 'def Model.dbgLeak (n : Nat) : Nat := dbgTrace "leak" fun _ => n\n'
)
model_olean, base_odir = compile_target_mod("Model", model_src, "base")
cap_olean, _ = compile_target_mod(
"Captured",
"prelude\nimport Model\ndef Captured.program : Nat := 7\n",
"base",
)
spec_ok_src = (
"prelude\nimport Model\ndef Spec.specs (p : Nat) : Prop := p = 7\n"
)
spec_olean, _ = compile_target_mod("Spec", spec_ok_src, "base")
exp_ok_src = (
"prelude\nimport Model\nimport Captured\nimport Spec\n"
"def Expected.claim : Prop :=\n"
" Trusted.MirSemantics.UnitTheorem\n"
" (Trusted.MirSemantics.Crate.mk Captured.program Spec.specs)\n"
)
exp_olean, _ = compile_target_mod("Expected", exp_ok_src, "base")
proof_ok_olean, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Proof.verify : Expected.claim := And.intro rfl rfl\n",
"base",
)
core_edge = [{"module": "Init.Core", "isExported": True, "importAll": False, "isMeta": False}]
model_edge = [{"module": "Model", "isExported": True, "importAll": False, "isMeta": False}]
cap_edge = [{"module": "Captured", "isExported": True, "importAll": False, "isMeta": False}]
spec_edge = [{"module": "Spec", "isExported": True, "importAll": False, "isMeta": False}]
exp_edge = [{"module": "Expected", "isExported": True, "importAll": False, "isMeta": False}]
base_graph = dict(found_graph)
base_graph.update(
{
"Model": core_edge,
"Captured": model_edge,
"Spec": model_edge,
"Expected": model_edge + cap_edge + spec_edge,
"Proof": exp_edge,
}
)
def make_ta_case(
case_id: str,
*,
mod_oleans: dict[str, Path],
proof_o: Path,
allow_sorry: bool = False,
graph_override: dict[str, object] | None = None,
libraries: list[str] | None = None,
arts_override: dict[str, list[list[str]]] | None = None,
is_module_mods: set[str] | None = None,
) -> dict[str, object]:
case_dir = fixtures_root / f"case_{case_id}"
case_dir.mkdir()
arts_all = dict(foundation_arts)
for m, p in mod_oleans.items():
arts_all[m] = [[str(p)], []]
if arts_override:
arts_all.update(arts_override)
export_arts = dict(arts_all)
export_arts["Proof"] = [[str(proof_o)], []]
is_mod = is_module_mods or set()
modules_meta = [
{"module": "Model", "role": "model", "isModule": "Model" in is_mod},
{"module": "Captured", "role": "capture", "isModule": "Captured" in is_mod},
{"module": "Spec", "role": "specification", "isModule": "Spec" in is_mod},
{"module": "Expected", "role": "expected", "isModule": "Expected" in is_mod},
{"module": "Proof", "role": "proof", "isModule": "Proof" in is_mod},
]
target_meta: dict[str, object] = {
"modules": modules_meta,
"theoremName": "Proof.verify",
"theoremModule": "Proof",
"expectedDeclaration": "Expected.claim",
"expectedModule": "Expected",
"canonicalRoot": "Trusted.MirSemantics.UnitTheorem",
"subjectDeclaration": "Captured.program",
"specificationDeclaration": "Spec.specs",
"allowSorryInProof": allow_sorry,
}
use_graph = graph_override if graph_override is not None else base_graph
use_libs = libraries if libraries is not None else []
export_req = {
"mode": "target-export",
"sysroot": sysroot,
"foundation": foundation_mods,
"libraries": use_libs,
"target": target_meta,
"artifacts": list(export_arts.items()),
"graph": use_graph,
}
e_rc, e_parsed, e_out = _run_tb_request(
lean_bin,
tb_olean_dir,
export_req,
case_dir,
tag="export",
timeout_sec=timeout_sec,
)
if e_rc != 0 or not isinstance(e_parsed, dict) or e_parsed.get("ok") is not True:
raise RuntimeError(
f"target-export failed for {case_id}: rc={e_rc} out={e_out}"
)
export_path = case_dir / "proof_export.json"
export_path.write_text(
json.dumps(e_parsed["result"]), encoding="utf-8"
)
return {
"mode": "target-audit",
"sysroot": sysroot,
"foundation": foundation_mods,
"libraries": use_libs,
"target": target_meta,
"artifacts": list(arts_all.items()),
"graph": use_graph,
"proofExportPath": str(export_path),
"axioms": [
["Classical.choice", "Init.Prelude"],
["Quot.sound", "Init.Prelude"],
["propext", "Init.Core"],
],
}
target_reqs: dict[str, dict[str, object]] = {
"target_sanity": make_ta_case(
"sanity",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
),
}
# Case: target_sealed_admission (module requests `"admission": "sealed"`)
sealed_req = json.loads(json.dumps(target_reqs["target_sanity"]))
sealed_req["target"]["modules"][0]["admission"] = "sealed"
target_reqs["target_sealed_admission"] = sealed_req
# Case: target_expected_true (`Expected.claim := True` while Proof proves
# canonical claim)
exp_true_o, exp_true_dir = compile_target_mod(
"Expected",
"prelude\nimport Model\nimport Captured\nimport Spec\n"
"def Expected.claim : Prop := True\n",
"expected_true",
deps_olean_dirs=[base_odir],
)
proof_true_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Proof.verify : Trusted.MirSemantics.UnitTheorem\n"
" (Trusted.MirSemantics.Crate.mk Captured.program Spec.specs) :=\n"
" And.intro rfl rfl\n",
"expected_true",
deps_olean_dirs=[exp_true_dir, base_odir],
)
target_reqs["target_expected_true"] = make_ta_case(
"expected_true",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_true_o,
},
proof_o=proof_true_o,
)
# Case: target_bad_theorem_type (theorem Proof.verify takes `(h : False)`)
proof_bad_ty_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Proof.verify (h : False) : Expected.claim := False.elim h\n",
"bad_theorem_type",
deps_olean_dirs=[base_odir],
)
target_reqs["target_bad_theorem_type"] = make_ta_case(
"bad_theorem_type",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_bad_ty_o,
)
# Case: target_proof_sorry (uses `sorry` with `allowSorryInProof = false`)
proof_sorry_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Proof.verify : Expected.claim := And.intro rfl sorry\n",
"proof_sorry",
deps_olean_dirs=[base_odir],
)
target_reqs["target_proof_sorry"] = make_ta_case(
"proof_sorry",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_sorry_o,
allow_sorry=False,
)
# Case: target_impl_by (`@[implemented_by]` inside Proof on logical helper)
proof_impl_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"unsafe def Proof.nativeH : Nat := 1\n"
"@[implemented_by Proof.nativeH] def Proof.logH : Nat := 0\n"
"theorem Proof.verify : Expected.claim :=\n"
" (fun _ : Proof.logH = 0 => And.intro rfl rfl) rfl\n",
"impl_by",
deps_olean_dirs=[base_odir],
)
target_reqs["target_impl_by"] = make_ta_case(
"impl_by",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_impl_o,
)
# Case: target_spec_transitive_dbg (Spec calls `Model.dbgLeak`)
model_dbg_o, dbg_odir = compile_target_mod(
"Model", model_dbg_src, "spec_transitive_dbg"
)
cap_dbg_o, _ = compile_target_mod(
"Captured",
"prelude\nimport Model\ndef Captured.program : Nat := 7\n",
"spec_transitive_dbg",
deps_olean_dirs=[dbg_odir],
)
spec_dbg_o, _ = compile_target_mod(
"Spec",
"prelude\nimport Model\n"
"def Spec.specs (p : Nat) : Prop := p = 7 ∧ Model.dbgLeak p = p\n",
"spec_transitive_dbg",
deps_olean_dirs=[dbg_odir],
)
exp_dbg_o, _ = compile_target_mod(
"Expected",
exp_ok_src,
"spec_transitive_dbg",
deps_olean_dirs=[dbg_odir],
)
proof_dbg_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Proof.verify : Expected.claim :=\n"
" And.intro rfl (And.intro rfl rfl)\n",
"spec_transitive_dbg",
deps_olean_dirs=[dbg_odir],
)
dbg_graph = dict(base_graph)
dbg_graph["Model"] = core_edge + [
{"module": "Init.Util", "isExported": True, "importAll": False, "isMeta": False}
]
target_reqs["target_spec_transitive_dbg"] = make_ta_case(
"spec_transitive_dbg",
mod_oleans={
"Model": model_dbg_o,
"Captured": cap_dbg_o,
"Spec": spec_dbg_o,
"Expected": exp_dbg_o,
},
proof_o=proof_dbg_o,
graph_override=dbg_graph,
)
def run_lean_forge(tag: str, script_body: str) -> None:
script_path = fixtures_root / f"forge_{tag}.lean"
script_path.write_text(script_body, encoding="utf-8")
res = subprocess.run(
[
str(lean_bin),
"-j1",
"-M2048",
"-s16384",
"--run",
str(script_path),
],
env=_lean_subprocess_env([]),
capture_output=True,
text=True,
timeout=timeout_sec,
)
if res.returncode != 0:
raise RuntimeError(
f"failed forging fixture {tag}: {res.stdout + res.stderr}"
)
# Case: target_dup_library (intra-module duplicate in .library)
dup_lib_o = fixtures_root / "DupLib.olean"
run_lean_forge(
"dup_library",
"import Lean.Environment\n"
"open Lean in\n"
"def main : IO Unit := do\n"
" let ci : ConstantInfo := .thmInfo {\n"
" name := `DupLib.t, levelParams := [], type := .const `True [],\n"
" value := .const `True.intro [], all := [`DupLib.t] }\n"
" let md : ModuleData := {\n"
" isModule := false, imports := #[{ module := `Init.Core }],\n"
" constNames := #[`DupLib.t, `DupLib.t], constants := #[ci, ci],\n"
" extraConstNames := #[], entries := #[] }\n"
f" saveModuleData (System.FilePath.mk {json.dumps(str(dup_lib_o))}) `DupLib md\n",
)
dup_graph = dict(base_graph)
dup_graph["DupLib"] = core_edge
target_reqs["target_dup_library"] = make_ta_case(
"dup_library",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_olean,
"DupLib": dup_lib_o,
},
proof_o=proof_ok_olean,
graph_override=dup_graph,
libraries=["DupLib"],
)
# Case: target_companion_extra_const (3-part `Spec` with `Spec.ghost` only
# in part 0)
comp_p0 = fixtures_root / "SpecComp.olean"
comp_p1 = fixtures_root / "SpecComp.olean.server"
comp_p2 = fixtures_root / "SpecComp.olean.private"
run_lean_forge(
"companion_extra_const",
"import Lean.Environment\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" let (baseData, _) ← readModuleData (System.FilePath.mk {json.dumps(str(spec_olean))})\n"
" let ghost : ConstantInfo := .defnInfo {\n"
" name := `Spec.ghost, levelParams := [], type := .const `Nat [],\n"
" value := .lit (.natVal 0), hints := .abbrev, safety := .safe,\n"
" all := [`Spec.ghost] }\n"
" let d2 := { baseData with isModule := true }\n"
" let d1 := d2\n"
" let cn := d2.constNames.push `Spec.ghost\n"
" let cs := d2.constants.push ghost\n"
" let d0 := { d2 with constNames := cn, constants := cs }\n"
" saveModuleDataParts `Spec #[\n"
f" (System.FilePath.mk {json.dumps(str(comp_p0))}, d0),\n"
f" (System.FilePath.mk {json.dumps(str(comp_p1))}, d1),\n"
f" (System.FilePath.mk {json.dumps(str(comp_p2))}, d2)]\n",
)
target_reqs["target_companion_extra_const"] = make_ta_case(
"companion_extra_const",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": comp_p0,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
arts_override={"Spec": [[str(comp_p0), str(comp_p1), str(comp_p2)], []]},
is_module_mods={"Spec"},
)
# Case: target_companion_imports_mismatch (3-part `Spec` with empty imports
# in part 0)
comp_imp_p0 = fixtures_root / "SpecCompImp.olean"
comp_imp_p1 = fixtures_root / "SpecCompImp.olean.server"
comp_imp_p2 = fixtures_root / "SpecCompImp.olean.private"
run_lean_forge(
"companion_imports_mismatch",
"import Lean.Environment\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" let (baseData, _) ← readModuleData (System.FilePath.mk {json.dumps(str(spec_olean))})\n"
" let d2 := { baseData with isModule := true }\n"
" let d1 := d2\n"
" let d0 := { d2 with imports := #[] }\n"
" saveModuleDataParts `Spec #[\n"
f" (System.FilePath.mk {json.dumps(str(comp_imp_p0))}, d0),\n"
f" (System.FilePath.mk {json.dumps(str(comp_imp_p1))}, d1),\n"
f" (System.FilePath.mk {json.dumps(str(comp_imp_p2))}, d2)]\n",
)
target_reqs["target_companion_imports_mismatch"] = make_ta_case(
"companion_imports_mismatch",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": comp_imp_p0,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
arts_override={
"Spec": [[str(comp_imp_p0), str(comp_imp_p1), str(comp_imp_p2)], []]
},
is_module_mods={"Spec"},
)
# Case: target_companion_const_mismatch (3-part `Spec` with altered
# `Spec.specs` body in part 0)
comp_body_p0 = fixtures_root / "SpecCompBody.olean"
comp_body_p1 = fixtures_root / "SpecCompBody.olean.server"
comp_body_p2 = fixtures_root / "SpecCompBody.olean.private"
run_lean_forge(
"companion_const_mismatch",
"import Lean.Environment\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" let (baseData, _) ← readModuleData (System.FilePath.mk {json.dumps(str(spec_olean))})\n"
" let d2 := { baseData with isModule := true }\n"
" let d1 := d2\n"
" let cs := d2.constants.map fun ci =>\n"
" if ci.name == `Spec.specs then\n"
" match ci with\n"
" | .defnInfo dv =>\n"
" .defnInfo { dv with value := .lam `p (.const `Nat []) (.const `True []) .default }\n"
" | other => other\n"
" else ci\n"
" let d0 := { d2 with constants := cs }\n"
" saveModuleDataParts `Spec #[\n"
f" (System.FilePath.mk {json.dumps(str(comp_body_p0))}, d0),\n"
f" (System.FilePath.mk {json.dumps(str(comp_body_p1))}, d1),\n"
f" (System.FilePath.mk {json.dumps(str(comp_body_p2))}, d2)]\n",
)
target_reqs["target_companion_const_mismatch"] = make_ta_case(
"companion_const_mismatch",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": comp_body_p0,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
arts_override={
"Spec": [
[str(comp_body_p0), str(comp_body_p1), str(comp_body_p2)],
[],
]
},
is_module_mods={"Spec"},
)
# Case: target_unsafe_rec_type_mismatch (`Spec.foo._unsafe_rec` : Bool)
bad_rec_spec_o = fixtures_root / "SpecBadUnsafeRec.olean"
shutil.copy2(spec_olean, bad_rec_spec_o)
run_lean_forge(
"unsafe_rec_type_mismatch",
"import Lean.Environment\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" let p := System.FilePath.mk {json.dumps(str(bad_rec_spec_o))}\n"
" let (data, _) ← readModuleData p\n"
" let parentCi : ConstantInfo := .defnInfo {\n"
" name := `Spec.foo, levelParams := [], type := .const `Nat [],\n"
" value := .lit (.natVal 0), hints := .abbrev, safety := .safe,\n"
" all := [`Spec.foo] }\n"
" let badRecCi : ConstantInfo := .defnInfo {\n"
" name := `Spec.foo._unsafe_rec, levelParams := [],\n"
" type := .const `Bool [], value := .const `Bool.true [],\n"
" hints := .abbrev, safety := .partial,\n"
" all := [`Spec.foo._unsafe_rec] }\n"
" let newNames := data.constNames ++ #[`Spec.foo, `Spec.foo._unsafe_rec]\n"
" let newConsts := data.constants ++ #[parentCi, badRecCi]\n"
" saveModuleData p `Spec\n"
" { data with constNames := newNames, constants := newConsts }\n",
)
target_reqs["target_unsafe_rec_type_mismatch"] = make_ta_case(
"unsafe_rec_type_mismatch",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": bad_rec_spec_o,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
)
# Case: target_foundation_propext_hijack (`Model` subsumes `propext`)
bad_propext_model_o = fixtures_root / "ModelPropextHijack.olean"
shutil.copy2(model_olean, bad_propext_model_o)
run_lean_forge(
"foundation_propext_hijack",
"import Lean.Environment\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" initSearchPath (System.FilePath.mk {json.dumps(str(sysroot))})\n"
" let env ← importModules #[{ module := `Init.Core }] {}\n"
" (trustLevel := 0) (plugins := #[]) (loadExts := false)\n"
" (level := .private)\n"
" let some px := env.checked.get.find? `propext\n"
' | throw (IO.userError "missing propext")\n'
f" let p := System.FilePath.mk {json.dumps(str(bad_propext_model_o))}\n"
" let (data, _) ← readModuleData p\n"
" let body := Expr.const `True []\n"
" let fakeThm : ConstantInfo := .thmInfo {\n"
" name := `propext, levelParams := px.levelParams,\n"
" type := px.type, value := body, all := [`propext] }\n"
" let newNames := data.constNames.push `propext\n"
" let newConsts := data.constants.push fakeThm\n"
" saveModuleData p `Model\n"
" { data with constNames := newNames, constants := newConsts }\n",
)
target_reqs["target_foundation_propext_hijack"] = make_ta_case(
"foundation_propext_hijack",
mod_oleans={
"Model": bad_propext_model_o,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
)
# Case: spec_transitive_std_async & target_transitive_std_async
# (`Std.Async.Fake` library).
async_fake_o, async_fake_odir = compile_target_mod(
"Std.Async.Fake",
"prelude\nimport Init.Core\ndef Std.Async.Fake.x : Nat := 0\n",
"async_fake",
)
async_edge = [{"module": "Std.Async.Fake", "isExported": True, "importAll": False, "isMeta": False}]
spec_async_graph = dict(found_graph)
spec_async_graph["Std.Async.Fake"] = core_edge
spec_async_arts = dict(foundation_arts)
spec_async_arts["Std.Async.Fake"] = [[str(async_fake_o)], []]
spec_reqs["spec_transitive_std_async"] = {
"mode": "spec-preflight",
"sysroot": sysroot,
"foundation": foundation_mods,
"libraries": ["Std.Async.Fake"],
"artifacts": list(spec_async_arts.items()),
"graph": spec_async_graph,
"sources": [["Spec", str(fixtures_root / "spec_sanity.lean")]],
}
safe_wrap_o, safe_wrap_odir = compile_target_mod(
"SafeWrap",
"prelude\nimport Init.Core\nimport Std.Async.Fake\n"
"def SafeWrap.y : Nat := 0\n",
"ta_async_wrap",
deps_olean_dirs=[async_fake_odir],
)
safe_wrap_edge = [{"module": "SafeWrap", "isExported": True, "importAll": False, "isMeta": False}]
spec_ta_async_o, _ = compile_target_mod(
"Spec",
"prelude\nimport Model\nimport SafeWrap\n"
"def Spec.specs (p : Nat) : Prop := p = 7\n",
"ta_async",
deps_olean_dirs=[base_odir, safe_wrap_odir, async_fake_odir],
)
exp_ta_async_o, exp_ta_async_dir = compile_target_mod(
"Expected",
exp_ok_src,
"ta_async",
deps_olean_dirs=[base_odir, spec_ta_async_o.parent, safe_wrap_odir, async_fake_odir],
)
proof_ta_async_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Proof.verify : Expected.claim := And.intro rfl rfl\n",
"ta_async",
deps_olean_dirs=[
exp_ta_async_dir,
base_odir,
spec_ta_async_o.parent,
safe_wrap_odir,
async_fake_odir,
],
)
ta_async_graph = dict(base_graph)
ta_async_graph["Std.Async.Fake"] = core_edge
ta_async_graph["SafeWrap"] = core_edge + async_edge
ta_async_graph["Spec"] = model_edge + safe_wrap_edge
target_reqs["target_transitive_std_async"] = make_ta_case(
"transitive_std_async",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_ta_async_o,
"Expected": exp_ta_async_o,
"SafeWrap": safe_wrap_o,
"Std.Async.Fake": async_fake_o,
},
proof_o=proof_ta_async_o,
graph_override=ta_async_graph,
libraries=["SafeWrap", "Std.Async.Fake"],
)
# Case: target_reserved_captured_in_spec (`Spec` declares
# `Captured.badDecl`).
spec_cap_o, _ = compile_target_mod(
"Spec",
"prelude\nimport Model\n"
"def Captured.badDecl : Nat := 0\n"
"def Spec.specs (p : Nat) : Prop := p = 7\n",
"reserved_captured_in_spec",
deps_olean_dirs=[base_odir],
)
target_reqs["target_reserved_captured_in_spec"] = make_ta_case(
"reserved_captured_in_spec",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_cap_o,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
)
# Case: target_reserved_proof_in_spec (`Spec` declares `Proof.badDecl`).
spec_proof_o, _ = compile_target_mod(
"Spec",
"prelude\nimport Model\n"
"def Proof.badDecl : Nat := 0\n"
"def Spec.specs (p : Nat) : Prop := p = 7\n",
"reserved_proof_in_spec",
deps_olean_dirs=[base_odir],
)
target_reqs["target_reserved_proof_in_spec"] = make_ta_case(
"reserved_proof_in_spec",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_proof_o,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
)
# Case: target_reserved_anneal_in_proof (authored `Proof` declares an
# unreferenced homonym of a bundled `Anneal.*` theorem whose module it does
# not import).
proof_anneal_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Anneal.InitLemmas.bool_and_left : True := True.intro\n"
"theorem Proof.verify : Expected.claim := And.intro rfl rfl\n",
"reserved_anneal_in_proof",
deps_olean_dirs=[base_odir],
)
target_reqs["target_reserved_anneal_in_proof"] = make_ta_case(
"reserved_anneal_in_proof",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_anneal_o,
)
# Case: target_anneal_helper_unknown_parent (authored `Proof` declares an
# equation-lemma-shaped `Anneal.*` theorem whose parent is not a bundled
# theory definition).
proof_anneal_helper_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Anneal.Missing.f.eq_1 : True := True.intro\n"
"theorem Proof.verify : Expected.claim := And.intro rfl rfl\n",
"anneal_helper_unknown_parent",
deps_olean_dirs=[base_odir],
)
target_reqs["target_anneal_helper_unknown_parent"] = make_ta_case(
"anneal_helper_unknown_parent",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_anneal_helper_o,
)
# Case: target_reserved_tb_in_spec (`Spec` declares
# `TrustedBoundary.badDecl`).
spec_tb_o, _ = compile_target_mod(
"Spec",
"prelude\nimport Model\n"
"def TrustedBoundary.badDecl : Nat := 0\n"
"def Spec.specs (p : Nat) : Prop := p = 7\n",
"reserved_tb_in_spec",
deps_olean_dirs=[base_odir],
)
target_reqs["target_reserved_tb_in_spec"] = make_ta_case(
"reserved_tb_in_spec",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_tb_o,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
)
# Case: target_spec_alias_opaque (`Spec` exports `Model.extOpq` via
# `aliasExtension`).
model_opq_o, model_opq_odir = compile_target_mod(
"Model",
model_src + "namespace Model\nopaque extOpq : Nat\nend Model\n",
"spec_alias_opaque",
)
cap_opq_o, _ = compile_target_mod(
"Captured",
"prelude\nimport Model\ndef Captured.program : Nat := 7\n",
"spec_alias_opaque",
deps_olean_dirs=[model_opq_odir],
)
spec_opq_o, _ = compile_target_mod(
"Spec",
"prelude\nimport Model\nexport Model (extOpq)\ndef Spec.specs (p : Nat) : Prop := p = 7\n",
"spec_alias_opaque",
deps_olean_dirs=[model_opq_odir],
)
exp_opq_o, _ = compile_target_mod(
"Expected",
exp_ok_src,
"spec_alias_opaque",
deps_olean_dirs=[model_opq_odir],
)
proof_opq_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\ntheorem Proof.verify : Expected.claim := And.intro rfl rfl\n",
"spec_alias_opaque",
deps_olean_dirs=[model_opq_odir],
)
target_reqs["target_spec_alias_opaque"] = make_ta_case(
"spec_alias_opaque",
mod_oleans={
"Model": model_opq_o,
"Captured": cap_opq_o,
"Spec": spec_opq_o,
"Expected": exp_opq_o,
},
proof_o=proof_opq_o,
)
# Cases for remaining `targetAudit` `aliasExtension` branches (`extern`,
# `implemented_by`, forbidden target, `Trusted`-root, reserved-root).
ov_lib_o, ov_lib_odir = compile_target_mod(
"Std.TestOverrideLib",
"prelude\nimport Init.Core\n"
"namespace Std.TestOverrideLib\n"
'@[extern "anneal_test_ext"] def extFn : Nat := 0\n'
"def implTarget : Nat := 1\n"
"@[implemented_by implTarget] def implFn : Nat := 0\n"
"unsafe def unsafeFn : Nat := 0\n"
"partial def partialFn (n : Nat) : Nat := partialFn n\n"
"axiom unapprovedAx : Prop\n"
"def autoHelper (_h : 0 = 0 := by rfl) : Nat := 0\n"
"def bangHelper! : Nat := 0\n"
"def optParam : Nat := 0\n"
"def okDef : Nat := 0\n"
"end Std.TestOverrideLib\n",
"alias_ov_lib",
)
ov_lib_edge = [
{
"module": "Std.TestOverrideLib",
"isExported": True,
"importAll": False,
"isMeta": False,
}
]
spec_ov_graph = dict(base_graph)
spec_ov_graph["Std.TestOverrideLib"] = core_edge
spec_ov_graph["Spec"] = model_edge + ov_lib_edge
for alias_case, spec_export_line in [
("target_spec_alias_extern", "export Std.TestOverrideLib (extFn)\n"),
("target_spec_alias_impl_by", "export Std.TestOverrideLib (implFn)\n"),
("target_spec_alias_unsafe", "export Std.TestOverrideLib (unsafeFn)\n"),
(
"target_spec_alias_axiom",
"export Std.TestOverrideLib (unapprovedAx)\n",
),
(
"target_spec_autoparam_ref",
"def Spec.useAuto := @Std.TestOverrideLib.autoHelper\n",
),
(
"target_spec_bad_alias_name",
"export Std.TestOverrideLib (optParam)\n",
),
]:
spec_al_o, spec_al_odir = compile_target_mod(
"Spec",
"prelude\nimport Model\nimport Std.TestOverrideLib\n"
+ spec_export_line
+ "def Spec.specs (p : Nat) : Prop := p = 7\n",
alias_case,
deps_olean_dirs=[base_odir, ov_lib_odir],
)
exp_al_o, exp_al_odir = compile_target_mod(
"Expected",
exp_ok_src,
alias_case,
deps_olean_dirs=[base_odir, spec_al_odir, ov_lib_odir],
)
proof_al_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Proof.verify : Expected.claim := And.intro rfl rfl\n",
alias_case,
deps_olean_dirs=[exp_al_odir, base_odir, spec_al_odir, ov_lib_odir],
)
target_reqs[alias_case] = make_ta_case(
alias_case,
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_al_o,
"Expected": exp_al_o,
"Std.TestOverrideLib": ov_lib_o,
},
proof_o=proof_al_o,
graph_override=spec_ov_graph,
libraries=["Std.TestOverrideLib"],
)
# Inject clean `MySpec.*` alias names targeting `partialFn._unsafe_rec` and
# `bangHelper!` so `isForbiddenSpecAliasUser` does not mask the dedicated
# `isPartialDecl` and `isForbiddenSpecTransitiveConst` target guards.
spec_ov_clean_o, spec_ov_clean_odir = compile_target_mod(
"Spec",
"prelude\nimport Model\nimport Std.TestOverrideLib\n"
"def Spec.specs (p : Nat) : Prop := p = 7\n",
"target_spec_ov_clean",
deps_olean_dirs=[base_odir, ov_lib_odir],
)
exp_ov_clean_o, exp_ov_clean_odir = compile_target_mod(
"Expected",
exp_ok_src,
"target_spec_ov_clean",
deps_olean_dirs=[base_odir, spec_ov_clean_odir, ov_lib_odir],
)
proof_ov_clean_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Proof.verify : Expected.claim := And.intro rfl rfl\n",
"target_spec_ov_clean",
deps_olean_dirs=[
exp_ov_clean_odir,
base_odir,
spec_ov_clean_odir,
ov_lib_odir,
],
)
for alias_case, alias_pair in [
(
"target_spec_alias_partial",
"(`MySpec.cleanPartial, `Std.TestOverrideLib.partialFn._unsafe_rec)",
),
(
"target_spec_alias_forbidden",
"(`MySpec.cleanForbidden, `Std.TestOverrideLib.bangHelper!)",
),
]:
forged_spec_o = fixtures_root / f"{alias_case}.Spec.olean"
shutil.copy2(spec_ov_clean_o, forged_spec_o)
run_lean_forge(
alias_case,
"import Lean\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" let p := System.FilePath.mk {json.dumps(str(forged_spec_o))}\n"
" let (data, _) ← readModuleData p\n"
" let e : Array EnvExtensionEntry := unsafe unsafeCast\n"
f" (#[{alias_pair}] : Array (Name × Name))\n"
" let ents := data.entries.push (Lean.aliasExtension.name, e)\n"
" saveModuleData p `Spec { data with entries := ents }\n",
)
target_reqs[alias_case] = make_ta_case(
alias_case,
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": forged_spec_o,
"Expected": exp_ov_clean_o,
"Std.TestOverrideLib": ov_lib_o,
},
proof_o=proof_ov_clean_o,
graph_override=spec_ov_graph,
libraries=["Std.TestOverrideLib"],
)
# Put `Trusted`-root and reserved-root alias exports in `Captured` so
# `.specification`'s `forbiddenSpecDeclRootNamespaces` check does not mask
# the dedicated `aliasRoot == Trusted` / `badAliasReserved` guards.
cap_ov_graph = dict(base_graph)
cap_ov_graph["Std.TestOverrideLib"] = core_edge
cap_ov_graph["Captured"] = model_edge + ov_lib_edge
for alias_case, cap_export_block in [
(
"target_cap_alias_trusted_root",
"namespace Trusted\nexport Std.TestOverrideLib (okDef)\n"
"end Trusted\n",
),
(
"target_cap_alias_reserved_root",
"namespace Expected\nexport Std.TestOverrideLib (okDef)\n"
"end Expected\n",
),
(
"target_cap_alias_anneal_root",
"namespace Anneal\nexport Std.TestOverrideLib (okDef)\n"
"end Anneal\n",
),
]:
cap_al_o, cap_al_odir = compile_target_mod(
"Captured",
"prelude\nimport Model\nimport Std.TestOverrideLib\n"
+ cap_export_block
+ "def Captured.program : Nat := 7\n",
alias_case,
deps_olean_dirs=[base_odir, ov_lib_odir],
)
exp_al_o, exp_al_odir = compile_target_mod(
"Expected",
exp_ok_src,
alias_case,
deps_olean_dirs=[base_odir, cap_al_odir, ov_lib_odir],
)
proof_al_o, _ = compile_target_mod(
"Proof",
"prelude\nimport Expected\n"
"theorem Proof.verify : Expected.claim := And.intro rfl rfl\n",
alias_case,
deps_olean_dirs=[exp_al_odir, base_odir, cap_al_odir, ov_lib_odir],
)
target_reqs[alias_case] = make_ta_case(
alias_case,
mod_oleans={
"Model": model_olean,
"Captured": cap_al_o,
"Spec": spec_olean,
"Expected": exp_al_o,
"Std.TestOverrideLib": ov_lib_o,
},
proof_o=proof_al_o,
graph_override=cap_ov_graph,
libraries=["Std.TestOverrideLib"],
)
# Case: target_root_prefixed_alias (`Captured` with `_root_.Trusted.spoof`
# in `aliasExtension`)
cap_root_alias_o = fixtures_root / "CapturedRootAlias.olean"
shutil.copy2(cap_olean, cap_root_alias_o)
run_lean_forge(
"target_root_prefixed_alias",
"import Lean\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" let p := System.FilePath.mk {json.dumps(str(cap_root_alias_o))}\n"
" let (data, _) ← readModuleData p\n"
" let e : Array EnvExtensionEntry := unsafe unsafeCast\n"
" (#[(`_root_.Trusted.spoof, `Nat.zero)] : Array (Name × Name))\n"
" let ents := data.entries.push (Lean.aliasExtension.name, e)\n"
" saveModuleData p `Captured { data with entries := ents }\n",
)
target_reqs["target_root_prefixed_alias"] = make_ta_case(
"root_prefixed_alias",
mod_oleans={
"Model": model_olean,
"Captured": cap_root_alias_o,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
)
# Case: target_alias_role_edge (`Spec` with `aliasExtension` referencing
# `Captured.program`)
spec_role_edge_o = fixtures_root / "SpecAliasRoleEdge.olean"
shutil.copy2(spec_olean, spec_role_edge_o)
run_lean_forge(
"target_alias_role_edge",
"import Lean\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" let p := System.FilePath.mk {json.dumps(str(spec_role_edge_o))}\n"
" let (data, _) ← readModuleData p\n"
" let e : Array EnvExtensionEntry := unsafe unsafeCast\n"
" (#[(`MySpec.capRef, `Captured.program)] : Array (Name × Name))\n"
" let ents := data.entries.push (Lean.aliasExtension.name, e)\n"
" saveModuleData p `Spec { data with entries := ents }\n",
)
target_reqs["target_alias_role_edge"] = make_ta_case(
"alias_role_edge",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_role_edge_o,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
)
# Pass-1 `"audit"` fixtures (`audit_sanity` + compiled `.olean`
# `autoParam`/Syntax/alias negative cases).
trusted_audit_o, trusted_audit_odir = compile_target_mod(
"Trusted",
"prelude\nimport Init.Core\ndef Trusted.ok : Prop := True\n"
"opaque Trusted.opq : Nat := 0\n",
"audit_base",
)
theory_good_o, _ = compile_target_mod(
"Anneal.Good",
"prelude\nimport Init.Core\nimport Trusted\n"
"def Anneal.Good.ok (_h : 0 = 0 := by rfl) : Nat := 0\n",
"audit_base",
deps_olean_dirs=[trusted_audit_odir],
)
trusted_edge = [{"module": "Trusted", "isExported": True, "importAll": False, "isMeta": False}]
def make_audit_case(
theory_mod: str,
theory_o: Path,
*,
trusted_o: Path | None = None,
extra_edges: list[dict[str, object]] | None = None,
) -> dict[str, object]:
arts_a = dict(foundation_arts)
arts_a["Trusted"] = [[str(trusted_o or trusted_audit_o)], []]
arts_a[theory_mod] = [[str(theory_o)], []]
g_a = dict(found_graph)
g_a["Trusted"] = core_edge
g_a[theory_mod] = (extra_edges or core_edge) + trusted_edge
return {
"mode": "audit",
"sysroot": sysroot,
"foundation": foundation_mods,
"trusted": ["Trusted"],
"theory": [theory_mod],
"moduleTiers": [["Trusted", "vetted"]],
"requireMirWp": False,
"artifacts": list(arts_a.items()),
"graph": g_a,
"axioms": [
["Classical.choice", "Init.Prelude"],
["Quot.sound", "Init.Prelude"],
["propext", "Init.Core"],
],
}
bad_non_auto_o, _ = compile_target_mod(
"Anneal.BadNonAuto",
'prelude\nimport Init.Core\nimport Trusted\ndef Anneal.BadNonAuto.s : Lean.Syntax := Lean.mkAtom "x"\n',
"audit_bad_non_auto",
deps_olean_dirs=[trusted_audit_odir],
)
bad_obf_auto_o, _ = compile_target_mod(
"Anneal.BadObfAuto",
"prelude\nimport Init.Core\nimport Trusted\n"
'def Anneal.BadObfAuto.f._auto_1 : Lean.Syntax := let a := Lean.mkAtom "x"; a\n'
"def Anneal.BadObfAuto.f (_h : autoParam (0 = 0) Anneal.BadObfAuto.f._auto_1) : Nat := 0\n",
"audit_bad_obf_auto",
deps_olean_dirs=[trusted_audit_odir],
)
bad_lit_auto_o, _ = compile_target_mod(
"Anneal.BadLitAuto",
"prelude\nimport Init.Core\nimport Trusted\n"
"def Anneal.BadLitAuto.f (_h : 0 = 0 := by set_option maxHeartbeats 1 in exact rfl) : Nat := 0\n",
"audit_bad_lit_auto",
deps_olean_dirs=[trusted_audit_odir],
)
bad_pre_auto_o, _ = compile_target_mod(
"Anneal.BadPreAuto",
"prelude\nimport Init.Core\nimport Trusted\n"
"def Anneal.BadPreAuto.f._auto_1 : Lean.Syntax :=\n"
' Lean.Syntax.ident Lean.SourceInfo.none (String.toRawSubstring "x")\n'
' (Lean.Name.mkStr1 "x")\n'
' (List.cons (Lean.Syntax.Preresolved.decl (Lean.Name.mkStr2 "IO" "println") List.nil) List.nil)\n'
"def Anneal.BadPreAuto.f (_h : autoParam (0 = 0) Anneal.BadPreAuto.f._auto_1) : Nat := 0\n",
"audit_bad_pre_auto",
deps_olean_dirs=[trusted_audit_odir],
)
bad_priv_pre_auto_o, _ = compile_target_mod(
"Anneal.BadPrivPreAuto",
"prelude\nimport Init.Core\nimport Trusted\n"
"def Anneal.BadPrivPreAuto.f._auto_1 : Lean.Syntax :=\n"
' Lean.Syntax.ident Lean.SourceInfo.none (String.toRawSubstring "x")\n'
' (Lean.Name.mkStr1 "x")\n'
' (List.cons (Lean.Syntax.Preresolved.decl (Lean.Name.str (Lean.Name.str (Lean.Name.num (Lean.Name.mkStr3 "_private" "Init" "Core") 0) "IO") "println") List.nil) List.nil)\n'
"def Anneal.BadPrivPreAuto.f (_h : autoParam (0 = 0) Anneal.BadPrivPreAuto.f._auto_1) : Nat := 0\n",
"audit_bad_priv_pre_auto",
deps_olean_dirs=[trusted_audit_odir],
)
bad_priv_mod_pre_auto_o, _ = compile_target_mod(
"Anneal.BadPrivModPreAuto",
"prelude\nimport Init.Core\nimport Trusted\n"
"def Anneal.BadPrivModPreAuto.f._auto_1 : Lean.Syntax :=\n"
' Lean.Syntax.ident Lean.SourceInfo.none (String.toRawSubstring "x")\n'
' (Lean.Name.mkStr1 "x")\n'
' (List.cons (Lean.Syntax.Preresolved.decl (Lean.Name.str (Lean.Name.num (Lean.Name.mkStr4 "_private" "Init" "System" "IO") 0) "secret") List.nil) List.nil)\n'
"def Anneal.BadPrivModPreAuto.f (_h : autoParam (0 = 0) Anneal.BadPrivModPreAuto.f._auto_1) : Nat := 0\n",
"audit_bad_priv_mod_pre_auto",
deps_olean_dirs=[trusted_audit_odir],
)
bad_multi_root_pre_auto_o, _ = compile_target_mod(
"Anneal.BadMultiRootPreAuto",
"prelude\nimport Init.Core\nimport Trusted\n"
"def Anneal.BadMultiRootPreAuto.f._auto_1 : Lean.Syntax :=\n"
' Lean.Syntax.ident Lean.SourceInfo.none (String.toRawSubstring "x")\n'
' (Lean.Name.mkStr1 "x")\n'
' (List.cons (Lean.Syntax.Preresolved.decl (Lean.Name.str (Lean.Name.num (Lean.Name.mkStr6 "_root_" "_root_" "_private" "Init" "System" "IO") 0) "secret") List.nil) List.nil)\n'
"def Anneal.BadMultiRootPreAuto.f (_h : autoParam (0 = 0) Anneal.BadMultiRootPreAuto.f._auto_1) : Nat := 0\n",
"audit_bad_multi_root_pre_auto",
deps_olean_dirs=[trusted_audit_odir],
)
bad_export_trusted_o, _ = compile_target_mod(
"Anneal.BadExportTrusted",
"prelude\nimport Init.Core\nimport Trusted\n"
"namespace Anneal.Foo.Trusted\ndef fake : Nat := 0\nend Anneal.Foo.Trusted\n"
"export Anneal.Foo (Trusted.fake)\n",
"audit_bad_export_trusted",
deps_olean_dirs=[trusted_audit_odir],
)
bad_export_reserved_o, _ = compile_target_mod(
"Anneal.BadExportReserved",
"prelude\nimport Init.Core\nimport Trusted\n"
"namespace Anneal.Foo.Expected\ndef claim : Prop := True\n"
"end Anneal.Foo.Expected\n"
"export Anneal.Foo (Expected.claim)\n",
"audit_bad_export_reserved",
deps_olean_dirs=[trusted_audit_odir],
)
bad_export_forbidden_o, _ = compile_target_mod(
"Anneal.BadExportForbidden",
"prelude\nimport Init.Core\nimport Trusted\n"
"namespace Anneal.Foo\ndef optParam : Nat := 0\nend Anneal.Foo\n"
"export Anneal.Foo (optParam)\n",
"audit_bad_export_forbidden",
deps_olean_dirs=[trusted_audit_odir],
)
bad_export_meta_o, _ = compile_target_mod(
"Anneal.BadExportMeta",
"prelude\nimport Init.Core\nimport Trusted\n"
"namespace Anneal.BadExportMeta\nexport Lean (ParserDescr)\n"
"end Anneal.BadExportMeta\n",
"audit_bad_export_meta",
deps_olean_dirs=[trusted_audit_odir],
)
bad_export_opaque_o, _ = compile_target_mod(
"Anneal.BadExportOpaque",
"prelude\nimport Init.Core\nimport Trusted\n"
"namespace Anneal.BadExportOpaque\nexport Trusted (opq)\n"
"end Anneal.BadExportOpaque\n",
"audit_bad_export_opaque",
deps_olean_dirs=[trusted_audit_odir],
)
trusted_role_edge_o = fixtures_root / "TrustedRoleEdge.olean"
shutil.copy2(trusted_audit_o, trusted_role_edge_o)
run_lean_forge(
"audit_export_role_edge",
"import Lean\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" let p := System.FilePath.mk {json.dumps(str(trusted_role_edge_o))}\n"
" let (data, _) ← readModuleData p\n"
" let e : Array EnvExtensionEntry := unsafe unsafeCast\n"
" (#[(`Trusted.badEdge, `Anneal.Good.ok)] : Array (Name × Name))\n"
" let ents := data.entries.push (Lean.aliasExtension.name, e)\n"
" saveModuleData p `Trusted { data with entries := ents }\n",
)
trusted_unsafe_alias_o = fixtures_root / "TrustedUnsafeAlias.olean"
shutil.copy2(trusted_audit_o, trusted_unsafe_alias_o)
run_lean_forge(
"audit_export_unsafe_target",
"import Lean\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" let p := System.FilePath.mk {json.dumps(str(trusted_unsafe_alias_o))}\n"
" let (data, _) ← readModuleData p\n"
" let e : Array EnvExtensionEntry := unsafe unsafeCast\n"
" (#[(`Trusted.badUnsafe, `unsafeCast)] : Array (Name × Name))\n"
" let ents := data.entries.push (Lean.aliasExtension.name, e)\n"
" saveModuleData p `Trusted { data with entries := ents }\n",
)
bad_lean_root_o, _ = compile_target_mod(
"Anneal.BadLeanRoot",
"prelude\nimport Init.Core\nimport Trusted\n"
"def Anneal.BadLeanRoot.pd : Type := Lean.ParserDescr\n",
"audit_bad_lean_root",
deps_olean_dirs=[trusted_audit_odir],
)
bad_auto_tac_o, _ = compile_target_mod(
"Anneal.BadAutoTac",
"prelude\nimport Init.Core\nimport Trusted\n"
"def Anneal.BadAutoTac.f (_h : autoParam (0 = 0) Lean.Syntax.missing) : Nat := 0\n",
"audit_bad_auto_tac",
deps_olean_dirs=[trusted_audit_odir],
)
cap_source_root_trusted_o = fixtures_root / "CapturedSourceRootTrusted.olean"
proof_root_trusted_o = fixtures_root / "ProofRootTrusted.olean"
proof_nested_reserved_o = fixtures_root / "ProofNestedReserved.olean"
theory_root_trusted_o = fixtures_root / "AnnealRootTrusted.olean"
shutil.copy2(cap_olean, cap_source_root_trusted_o)
shutil.copy2(proof_ok_olean, proof_root_trusted_o)
shutil.copy2(proof_ok_olean, proof_nested_reserved_o)
shutil.copy2(theory_good_o, theory_root_trusted_o)
run_lean_forge(
"root_and_nested_private_consts",
"import Lean\n"
"open Lean\n"
"def pushFakeDef (p : System.FilePath) (mod n : Name) : IO Unit := do\n"
" let (data, _) ← readModuleData p\n"
" let ci : ConstantInfo := .defnInfo {\n"
" name := n, levelParams := [], type := .const `Nat [],\n"
" value := .const `Nat.zero [], hints := .opaque, safety := .safe,\n"
" all := [n] }\n"
" saveModuleData p mod {\n"
" data with\n"
" constNames := data.constNames.push n,\n"
" constants := data.constants.push ci }\n"
"def main : IO Unit := do\n"
f" pushFakeDef (System.FilePath.mk {json.dumps(str(cap_source_root_trusted_o))})\n"
" `Captured `_root_.Trusted.spoof\n"
" let rootPrivTrusted :=\n"
' Name.str (Name.str (Name.num (Name.str (Name.str `_root_ "_private") "Proof") 0) "Trusted") "spoof"\n'
f" pushFakeDef (System.FilePath.mk {json.dumps(str(proof_root_trusted_o))})\n"
" `Proof rootPrivTrusted\n"
" let nestedPrivExpected :=\n"
' Name.str (Name.str (Name.num (Name.str (Name.str (Name.str (Name.num (Name.str `_private "Proof") 0) "_root_") "_private") "Proof") 0) "Expected") "spoof"\n'
f" pushFakeDef (System.FilePath.mk {json.dumps(str(proof_nested_reserved_o))})\n"
" `Proof nestedPrivExpected\n"
f" pushFakeDef (System.FilePath.mk {json.dumps(str(theory_root_trusted_o))})\n"
" `Anneal.Good `_root_.Trusted.spoof\n",
)
target_reqs["target_source_root_trusted_const"] = make_ta_case(
"source_root_trusted_const",
mod_oleans={
"Model": model_olean,
"Captured": cap_source_root_trusted_o,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_ok_olean,
)
target_reqs["target_proof_root_trusted_const"] = make_ta_case(
"proof_root_trusted_const",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_root_trusted_o,
)
target_reqs["target_nested_private_reserved_const"] = make_ta_case(
"nested_private_reserved_const",
mod_oleans={
"Model": model_olean,
"Captured": cap_olean,
"Spec": spec_olean,
"Expected": exp_olean,
},
proof_o=proof_nested_reserved_o,
)
bad_target_decl_root_o, _ = compile_target_mod(
"Anneal.BadTargetDeclRoot",
"prelude\nimport Init.Core\nimport Trusted\n"
"def Spec.spoof : Prop := True\n",
"audit_bad_target_decl_root",
deps_olean_dirs=[trusted_audit_odir],
)
bad_panic_const_o, _ = compile_target_mod(
"Anneal.BadPanicConst",
"prelude\nimport Init.Core\nimport Trusted\n"
'def Anneal.BadPanicConst.x : Nat := panicCore "bad"\n',
"audit_bad_panic_const",
deps_olean_dirs=[trusted_audit_odir],
)
bad_panic_pre_auto_o, _ = compile_target_mod(
"Anneal.BadPanicPreAuto",
"prelude\nimport Init.Core\nimport Trusted\n"
"def Anneal.BadPanicPreAuto.f._auto_1 : Lean.Syntax :=\n"
' Lean.Syntax.ident Lean.SourceInfo.none (String.toRawSubstring "x")\n'
' (Lean.Name.mkStr1 "x")\n'
' (List.cons (Lean.Syntax.Preresolved.decl (Lean.Name.mkStr1 "panicCore") List.nil) List.nil)\n'
"def Anneal.BadPanicPreAuto.f (_h : autoParam (0 = 0) Anneal.BadPanicPreAuto.f._auto_1) : Nat := 0\n",
"audit_bad_panic_pre_auto",
deps_olean_dirs=[trusted_audit_odir],
)
theory_panic_alias_o = fixtures_root / "AnnealPanicAlias.olean"
shutil.copy2(theory_good_o, theory_panic_alias_o)
run_lean_forge(
"audit_export_panic_alias",
"import Lean\n"
"open Lean in\n"
"def main : IO Unit := do\n"
f" let p := System.FilePath.mk {json.dumps(str(theory_panic_alias_o))}\n"
" let (data, _) ← readModuleData p\n"
" let e : Array EnvExtensionEntry := unsafe unsafeCast\n"
" (#[(`panicCore, `Anneal.Good.ok)] : Array (Name × Name))\n"
" let ents := data.entries.push (Lean.aliasExtension.name, e)\n"
" saveModuleData p `Anneal.Good { data with entries := ents }\n",
)
bad_ptr_const_o, _ = compile_target_mod(
"Anneal.BadPtrConst",
"prelude\nimport Init.Util\nimport Trusted\n"
"def Anneal.BadPtrConst.x (a : Unit) : Bool :=\n"
" withPtrEq a a (fun _ => true) (fun _ => rfl)\n",
"audit_bad_ptr_const",
deps_olean_dirs=[trusted_audit_odir],
)
util_edge = [
{
"module": "Init.Util",
"isExported": True,
"importAll": False,
"isMeta": False,
}
]
audit_reqs: dict[str, dict[str, object]] = {
"audit_sanity": make_audit_case("Anneal.Good", theory_good_o),
"audit_non_auto_syntax": make_audit_case("Anneal.BadNonAuto", bad_non_auto_o),
"audit_obf_auto_syntax": make_audit_case("Anneal.BadObfAuto", bad_obf_auto_o),
"audit_bad_tactic_auto_syntax": make_audit_case("Anneal.BadLitAuto", bad_lit_auto_o),
"audit_preresolved_auto_syntax": make_audit_case("Anneal.BadPreAuto", bad_pre_auto_o),
"audit_private_preresolved_auto_syntax": make_audit_case("Anneal.BadPrivPreAuto", bad_priv_pre_auto_o),
"audit_private_mod_preresolved_auto_syntax": make_audit_case("Anneal.BadPrivModPreAuto", bad_priv_mod_pre_auto_o),
"audit_multi_root_preresolved_auto_syntax": make_audit_case("Anneal.BadMultiRootPreAuto", bad_multi_root_pre_auto_o),
"audit_lean_root_const": make_audit_case("Anneal.BadLeanRoot", bad_lean_root_o),
"audit_disallowed_autoparam_tactic": make_audit_case("Anneal.BadAutoTac", bad_auto_tac_o),
"audit_export_trusted_alias": make_audit_case("Anneal.BadExportTrusted", bad_export_trusted_o),
"audit_export_reserved_alias": make_audit_case("Anneal.BadExportReserved", bad_export_reserved_o),
"audit_export_forbidden_alias": make_audit_case("Anneal.BadExportForbidden", bad_export_forbidden_o),
"audit_export_role_edge": make_audit_case("Anneal.Good", theory_good_o, trusted_o=trusted_role_edge_o),
"audit_export_meta_target": make_audit_case("Anneal.BadExportMeta", bad_export_meta_o),
"audit_export_opaque_target": make_audit_case("Anneal.BadExportOpaque", bad_export_opaque_o),
"audit_export_unsafe_target": make_audit_case("Anneal.Good", theory_good_o, trusted_o=trusted_unsafe_alias_o),
"audit_root_trusted_const": make_audit_case("Anneal.Good", theory_root_trusted_o),
"audit_target_decl_root": make_audit_case(
"Anneal.BadTargetDeclRoot", bad_target_decl_root_o
),
"audit_panic_const": make_audit_case(
"Anneal.BadPanicConst", bad_panic_const_o
),
"audit_panic_preresolved_auto_syntax": make_audit_case(
"Anneal.BadPanicPreAuto", bad_panic_pre_auto_o
),
"audit_export_panic_alias": make_audit_case(
"Anneal.Good", theory_panic_alias_o
),
"audit_ptr_const": make_audit_case(
"Anneal.BadPtrConst", bad_ptr_const_o, extra_edges=util_edge
),
}
built_spec_ids = set(spec_reqs.keys()) - {"spec_sanity"}
if built_spec_ids != VALID_SPEC_BOUNDARY_FIXTURE_IDS:
raise RuntimeError(
"spec boundary fixture keys drifted from static allowlist: "
f"{sorted(built_spec_ids)} != {sorted(VALID_SPEC_BOUNDARY_FIXTURE_IDS)}"
)
built_target_ids = set(target_reqs.keys()) - {"target_sanity"}
if built_target_ids != VALID_TARGET_BOUNDARY_FIXTURE_IDS:
raise RuntimeError(
"target boundary fixture keys drifted from static allowlist: "
f"{sorted(built_target_ids)} != {sorted(VALID_TARGET_BOUNDARY_FIXTURE_IDS)}"
)
built_audit_ids = set(audit_reqs.keys()) - {"audit_sanity"}
if built_audit_ids != VALID_AUDIT_BOUNDARY_FIXTURE_IDS:
raise RuntimeError(
"audit boundary fixture keys drifted from static allowlist: "
f"{sorted(built_audit_ids)} != {sorted(VALID_AUDIT_BOUNDARY_FIXTURE_IDS)}"
)
return spec_reqs, target_reqs, audit_reqs
def _check_one_mir_guard(
guard: MirSemanticsGuard,
*,
anneal_root: Path,
lean_bin: Path,
base_olean_dir: Path,
fixtures_dir: Path,
timeout_sec: int,
) -> GuardResult:
t0 = time.monotonic()
trusted_lean_dir = anneal_root / "trusted/lean"
src_path = anneal_root / guard.target_file
original_text = src_path.read_text(encoding="utf-8")
try:
mutated_text = apply_single_guard_mutation(
original_text,
guard.anchor,
guard.replacement,
guard_id=guard.guard_id,
)
except ValueError as exc:
return GuardResult(
suite="mir_semantics",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=str(exc),
)
fixture_path = fixtures_dir / f"{guard.fixture_module}.lean"
fixture_text = fixture_path.read_text(encoding="utf-8")
theorem_span = find_theorem_line_span(fixture_text, guard.theorem_name)
with tempfile.TemporaryDirectory(
prefix=f"anneal-gmut-{guard.guard_id}-"
) as tmp:
tmp_path = Path(tmp)
mut_src_root = tmp_path / "trusted_lean"
mut_olean_dir = tmp_path / "olean"
mut_olean_dir.mkdir()
# Copy only the mutated source file into a minimal `trusted_lean`
# overlay; unchanged downstream `.lean` sources are compiled directly
# from `trusted_lean_dir` while reading mutated `.olean`s from
# `mut_olean_dir` first via `LEAN_PATH`.
rel_target = Path(f"{guard.target_module}.lean")
mut_target_path = mut_src_root / rel_target
mut_target_path.parent.mkdir(parents=True, exist_ok=True)
mut_target_path.write_text(mutated_text, encoding="utf-8")
# Seed `mut_olean_dir` with hardlinks (falling back to copies across
# filesystems) to every unmodified module artifact (`.olean*` and
# `.ir*`) in `base_olean_dir`. Lean 4 resolves a root namespace
# (`Trusted.*`) from the first `LEAN_PATH` entry containing that root
# directory, and non-`module` fixtures importing `module` dependencies
# also load `.ir` files alongside `.olean*`.
downstream = SEMANTICS_DOWNSTREAM[guard.target_module]
rebuilt_mods = set(downstream) | {
guard.sanity_module,
guard.fixture_module,
}
if guard.sanity_module == "PositiveSanity":
rebuilt_mods |= set(
FIXTURE_HELPERS_END_TO_END
if guard.needs_wf_helper
else FIXTURE_HELPERS_BOUNDARY
)
for src_art in base_olean_dir.rglob("*"):
if not src_art.is_file():
continue
rel = src_art.relative_to(base_olean_dir)
rel_str = rel.as_posix()
rel_mod = None
for ext in (
".olean",
".olean.server",
".olean.private",
".ir",
".ir.sig",
):
if rel_str.endswith(ext):
rel_mod = rel_str[: -len(ext)]
break
if rel_mod is None or rel_mod in rebuilt_mods:
continue
dst_art = mut_olean_dir / rel
dst_art.parent.mkdir(parents=True, exist_ok=True)
try:
os.link(src_art, dst_art)
except OSError:
shutil.copy2(src_art, dst_art)
lean_path = [mut_olean_dir]
for idx, mod in enumerate(downstream):
root_for_mod = mut_src_root if idx == 0 else trusted_lean_dir
res = _compile_module(
lean_bin,
root_for_mod,
mod,
mut_olean_dir,
lean_path=lean_path,
timeout_sec=timeout_sec,
)
if res.returncode != 0:
return GuardResult(
suite="mir_semantics",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=(
f"mutated semantics module {mod} failed to compile "
f"(rc={res.returncode}): {(res.stdout + res.stderr).strip()[:300]}"
),
)
# Rebuild the fixture helper(s) needed by this guard against the
# mutated semantics `.olean`s, and confirm positive sanity still passes.
if guard.sanity_module == "PositiveSanity":
helpers = (
FIXTURE_HELPERS_END_TO_END
if guard.needs_wf_helper
else FIXTURE_HELPERS_BOUNDARY
)
for helper in helpers:
h_res = _compile_module(
lean_bin,
fixtures_dir,
helper,
mut_olean_dir,
lean_path=lean_path,
timeout_sec=timeout_sec,
)
if h_res.returncode != 0:
return GuardResult(
suite="mir_semantics",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=(
f"fixture helper {helper} failed to compile on mutant: "
f"{(h_res.stdout + h_res.stderr).strip()[:300]}"
),
)
sanity_res = _compile_module(
lean_bin,
fixtures_dir,
guard.sanity_module,
mut_olean_dir,
lean_path=lean_path,
timeout_sec=timeout_sec,
)
if sanity_res.returncode != 0:
return GuardResult(
suite="mir_semantics",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=(
f"positive sanity {guard.sanity_module} broke on mutant "
f"(rc={sanity_res.returncode}): "
f"{(sanity_res.stdout + sanity_res.stderr).strip()[:300]}"
),
)
# Compile the guard's negative refutation module. It MUST fail with a
# proof/type error inside `guard.theorem_name`.
refute_res = _compile_module(
lean_bin,
fixtures_dir,
guard.fixture_module,
mut_olean_dir,
lean_path=lean_path,
timeout_sec=timeout_sec,
)
combined = (refute_res.stdout + "\n" + refute_res.stderr).strip()
status, detail = classify_refutation_failure(
refute_res.returncode,
combined,
f"{guard.fixture_module}.lean",
theorem_span,
)
return GuardResult(
suite="mir_semantics",
guard_id=guard.guard_id,
target_file=guard.target_file,
status=status,
duration_sec=time.monotonic() - t0,
detail=detail,
)
def _compile_mutated_tb(
lean_bin: Path,
mutated_text: str,
tmp_path: Path,
*,
module_name: str = "TrustedBoundary",
timeout_sec: int,
) -> tuple[Path | None, str]:
"""Compile mutated `TrustedBoundary.lean` or `SpecPreflight.lean`."""
mut_src_dir = tmp_path / "src"
mut_src_dir.mkdir()
src_name = f"{module_name}.lean"
(mut_src_dir / src_name).write_text(mutated_text, encoding="utf-8")
mut_olean_dir = tmp_path / "olean"
mut_olean_dir.mkdir()
comp = _compile_module(
lean_bin,
mut_src_dir,
module_name,
mut_olean_dir,
lean_path=[],
timeout_sec=timeout_sec,
)
if comp.returncode != 0:
return None, (
f"mutated {src_name} failed to compile: "
f"{(comp.stdout + comp.stderr).strip()[:300]}"
)
return mut_olean_dir, ""
def _check_one_audit_guard(
guard: AuditHeaderGuard,
*,
anneal_root: Path,
lean_bin: Path,
sysroot: str,
timeout_sec: int,
) -> GuardResult:
t0 = time.monotonic()
tb_path = anneal_root / guard.target_file
mod_name = Path(guard.target_file).stem
original_text = tb_path.read_text(encoding="utf-8")
try:
mutated_text = apply_single_guard_mutation(
original_text,
guard.anchor,
guard.replacement,
guard_id=guard.guard_id,
)
except ValueError as exc:
return GuardResult(
suite="audit_headers",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=str(exc),
)
with tempfile.TemporaryDirectory(
prefix=f"anneal-gmut-{guard.guard_id}-"
) as tmp:
tmp_path = Path(tmp)
mut_olean_dir, comp_err = _compile_mutated_tb(
lean_bin,
mutated_text,
tmp_path,
module_name=mod_name,
timeout_sec=timeout_sec,
)
if mut_olean_dir is None:
return GuardResult(
suite="audit_headers",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=comp_err,
)
rc, parsed, out = _run_audit_headers(
lean_bin,
mut_olean_dir,
sysroot,
guard.negative_source,
tmp_path,
module_name=mod_name,
timeout_sec=timeout_sec,
)
if rc == 0 and isinstance(parsed, dict) and parsed.get("ok") is True:
return GuardResult(
suite="audit_headers",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="KILLED",
duration_sec=time.monotonic() - t0,
detail="negative header fixture flipped from policy reject to accept",
)
if (
rc == 1
and isinstance(parsed, dict)
and parsed.get("ok") is False
and parsed.get("category") == "policy"
):
return GuardResult(
suite="audit_headers",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="SURVIVED",
duration_sec=time.monotonic() - t0,
detail=f"mutant still rejected header: {parsed.get('message')!r}",
)
return GuardResult(
suite="audit_headers",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=f"unexpected auditor result rc={rc} parsed={parsed!r} out={out[:200]}",
)
def _check_one_boundary_guard(
guard: AuditBoundaryGuard,
*,
anneal_root: Path,
lean_bin: Path,
sanity_req: dict[str, object],
negative_req: dict[str, object],
timeout_sec: int,
) -> GuardResult:
t0 = time.monotonic()
tb_path = anneal_root / guard.target_file
original_text = tb_path.read_text(encoding="utf-8")
try:
mutated_text = apply_single_guard_mutation(
original_text,
guard.anchor,
guard.replacement,
guard_id=guard.guard_id,
)
except ValueError as exc:
return GuardResult(
suite="audit_boundary",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=str(exc),
)
with tempfile.TemporaryDirectory(
prefix=f"anneal-gmut-{guard.guard_id}-"
) as tmp:
tmp_path = Path(tmp)
mut_olean_dir, comp_err = _compile_mutated_tb(
lean_bin, mutated_text, tmp_path, timeout_sec=timeout_sec
)
if mut_olean_dir is None:
return GuardResult(
suite="audit_boundary",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=comp_err,
)
s_rc, s_parsed, s_out = _run_tb_request(
lean_bin,
mut_olean_dir,
sanity_req,
tmp_path,
tag="sanity",
timeout_sec=timeout_sec,
)
if s_rc != 0 or not isinstance(s_parsed, dict) or s_parsed.get("ok") is not True:
return GuardResult(
suite="audit_boundary",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=(
f"positive {guard.mode} sanity broke on mutant: "
f"rc={s_rc} parsed={s_parsed!r} out={s_out[:200]}"
),
)
rc, parsed, out = _run_tb_request(
lean_bin,
mut_olean_dir,
negative_req,
tmp_path,
tag="neg",
timeout_sec=timeout_sec,
)
if rc == 0 and isinstance(parsed, dict) and parsed.get("ok") is True:
return GuardResult(
suite="audit_boundary",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="KILLED",
duration_sec=time.monotonic() - t0,
detail=(
f"negative {guard.mode} fixture ({guard.fixture_id}) "
"flipped from policy reject to accept"
),
)
if (
rc == 1
and isinstance(parsed, dict)
and parsed.get("ok") is False
and parsed.get("category") == "policy"
):
return GuardResult(
suite="audit_boundary",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="SURVIVED",
duration_sec=time.monotonic() - t0,
detail=(
f"mutant still rejected {guard.mode} fixture: "
f"{parsed.get('message')!r}"
),
)
return GuardResult(
suite="audit_boundary",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=f"unexpected boundary result rc={rc} parsed={parsed!r} out={out[:200]}",
)
FORBIDDEN_LOADER_ENV_VARS: tuple[str, ...] = (
"LD_PRELOAD",
"LD_AUDIT",
"LD_DYNAMIC_WEAK",
"LD_USE_LOAD_BIAS",
"DYLD_INSERT_LIBRARIES",
"DYLD_FORCE_FLAT_NAMESPACE",
)
def _read_pinned_compiler_commit(anneal_root: Path) -> str:
"""Read `COMPILER_COMMIT` from `trusted/rustc-capture/src/ir.rs`."""
ir_path = anneal_root / "trusted/rustc-capture/src/ir.rs"
text = ir_path.read_text(encoding="utf-8")
m = re.search(r'pub const COMPILER_COMMIT: &str = "([0-9a-f]+)";', text)
if m is None:
raise RuntimeError(f"COMPILER_COMMIT not found in {ir_path}")
return m.group(1)
def _extract_subprocess_env(
rustc_bin: Path,
sysroot: str,
ice_dir: Path,
host_triple: str | None = None,
cargo_cwd: Path | None = None,
) -> dict[str, str]:
"""Build a sanitized environment for `rustc-capture` compile/run steps."""
env = dict(os.environ)
for var in FORBIDDEN_LOADER_ENV_VARS:
env.pop(var, None)
for key in list(env):
if (
key
in (
"RUSTFLAGS",
"CARGO_BUILD_RUSTFLAGS",
"CARGO_BUILD_RUSTC_WRAPPER",
"CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER",
)
or (
key.startswith("CARGO_TARGET_")
and key.endswith(("_RUSTFLAGS", "_LINKER"))
)
or (key.startswith("CARGO_PROFILE_") and key.endswith("_PANIC"))
):
env.pop(key, None)
sysroot_lib = str(Path(sysroot) / "lib")
# Cargo checks `CARGO_ENCODED_RUSTFLAGS` first with mutual exclusion over
# `RUSTFLAGS`, `target.*.rustflags`, and `build.rustflags`: pin the
# toolchain `<sysroot>/lib` native search path and `-Wl,-rpath` so baseline
# Cargo builds link and execute consistently with mutated direct-`rustc`
# builds on Linux, Nix/omnibus, and macOS while still blocking caller
# rustflags and target linker overrides (`CARGO_TARGET_*_LINKER` applies
# only to Cargo builds, not direct `rustc`). Clear `RUSTC_WRAPPER` and
# `RUSTC_WORKSPACE_WRAPPER` to empty string too so relative wrappers and
# Cargo config-level wrappers cannot fail after `cwd` changes or inject
# extra options missing from direct `rustc` mutant compiles. Force
# `profile.dev.panic = "unwind"` (the `test` profile inherits `dev` in
# `CARGO_PROFILE_*_PANIC=abort` overrides cannot produce abort `.rlib`s
# incompatible with direct `rustc -C panic=unwind` mutants.
env["CARGO_ENCODED_RUSTFLAGS"] = (
f"-Lnative={sysroot_lib}\x1f-Clink-arg=-Wl,-rpath,{sysroot_lib}"
)
env["CARGO_PROFILE_DEV_PANIC"] = "unwind"
env["RUSTC_WRAPPER"] = ""
env["RUSTC_WORKSPACE_WRAPPER"] = ""
if host_triple is not None and env.get("CARGO_BUILD_TARGET") not in (
None,
"",
host_triple,
):
env.pop("CARGO_BUILD_TARGET", None)
env["RUSTC"] = str(rustc_bin)
env["CARGO_PKG_VERSION"] = "0.1.0"
env["CARGO_NET_OFFLINE"] = "true"
env["RUSTC_ICE"] = str(ice_dir)
for lib_var in ("LD_LIBRARY_PATH", "DYLD_LIBRARY_PATH"):
existing_lib = env.get(lib_var, "")
env[lib_var] = (
f"{sysroot_lib}{os.pathsep}{existing_lib}"
if existing_lib
else sysroot_lib
)
if cargo_cwd is not None:
resolved_cwd = cargo_cwd.resolve()
for home_var in ("CARGO_HOME", "HOME"):
raw_val = env.get(home_var, "")
if raw_val and not Path(raw_val).is_absolute():
env[home_var] = str(
Path(os.path.normpath(resolved_cwd / raw_val))
)
return env
ALLOWED_CARGO_HOME_CONFIG_SECTIONS: frozenset[str] = frozenset({
"source",
})
ALLOWED_CARGO_SOURCE_KEYS: frozenset[str] = frozenset({
"replace-with",
"directory",
})
def _validate_cargo_home_config(parsed: dict[str, object], cand: Path) -> None:
"""Permit only offline directory-vendored `[source]` entries in config."""
disallowed = sorted(
k for k in parsed if k not in ALLOWED_CARGO_HOME_CONFIG_SECTIONS
)
if disallowed:
raise RuntimeError(
"refusing extract_guards execution with ambient Cargo home "
f"config sections {disallowed} in {cand}"
)
sources = parsed.get("source")
if sources is None:
return
if not isinstance(sources, dict):
raise RuntimeError(
"refusing extract_guards execution with invalid Cargo home "
f"config [source] section in {cand}"
)
for src_name, entry in sources.items():
if not isinstance(entry, dict):
raise RuntimeError(
"refusing extract_guards execution with invalid Cargo home "
f"config [source.{src_name}] entry in {cand}"
)
bad_keys = sorted(k for k in entry if k not in ALLOWED_CARGO_SOURCE_KEYS)
if bad_keys:
raise RuntimeError(
"refusing extract_guards execution with non-vendoring Cargo "
f"home config keys {bad_keys} under [source.{src_name}] in "
f"{cand}"
)
has_dir = "directory" in entry
has_repl = "replace-with" in entry
if has_dir == has_repl:
raise RuntimeError(
"refusing extract_guards execution with invalid Cargo home "
f"config [source.{src_name}] (must specify exactly one of "
f"directory or replace-with) in {cand}"
)
if has_dir:
dir_val = entry["directory"]
if not isinstance(dir_val, str) or not dir_val.strip():
raise RuntimeError(
"refusing extract_guards execution with empty Cargo home "
f"config [source.{src_name}].directory in {cand}"
)
else:
repl_val = entry["replace-with"]
if not isinstance(repl_val, str) or repl_val not in sources:
raise RuntimeError(
"refusing extract_guards execution with unknown Cargo "
f"home config [source.{src_name}].replace-with="
f"{repl_val!r} in {cand}"
)
for src_name in sources:
seen: set[str] = set()
cur = src_name
while "replace-with" in sources[cur]:
if cur in seen:
raise RuntimeError(
"refusing extract_guards execution with cyclic Cargo "
f"home config [source] replace-with in {cand}"
)
seen.add(cur)
cur = sources[cur]["replace-with"]
def _resolve_cargo_home_dir(base_dir: Path | None = None) -> Path | None:
"""Resolve Cargo's `CARGO_HOME` relative to `base_dir` if non-absolute."""
anchor = (
Path(os.path.abspath(base_dir)) if base_dir is not None else Path.cwd()
)
cargo_home_env = os.environ.get("CARGO_HOME", "")
if cargo_home_env:
raw_ch = Path(cargo_home_env)
return (
raw_ch
if raw_ch.is_absolute()
else Path(os.path.normpath(anchor / raw_ch))
)
home_env = os.environ.get("HOME", "")
if home_env:
raw_home = Path(home_env)
base_home = (
raw_home
if raw_home.is_absolute()
else Path(os.path.normpath(anchor / raw_home))
)
return base_home / ".cargo"
return Path.home() / ".cargo"
def _collect_cargo_home_roots(bases: list[Path]) -> list[Path]:
"""Collect logical and resolved `CARGO_HOME` candidates for `bases`."""
ch_roots: list[Path] = []
for base in bases:
cargo_home = _resolve_cargo_home_dir(base)
if cargo_home is None:
continue
cand_root = Path(os.path.normpath(cargo_home))
if cand_root not in ch_roots:
ch_roots.append(cand_root)
if cand_root.exists() or cand_root.is_symlink():
try:
resolved_ch = cand_root.resolve()
except OSError:
resolved_ch = None
if resolved_ch is not None and resolved_ch not in ch_roots:
ch_roots.append(resolved_ch)
return ch_roots
def _assert_no_ambient_toolchain_configs(
directory: Path,
*,
check_root_dot_cargo: bool = False,
check_cargo_home: bool = False,
) -> None:
"""Fail closed if ancestors or `CARGO_HOME` hold Cargo/rustup overrides."""
bases: list[Path] = []
for base in (Path(os.path.abspath(directory)), directory.resolve()):
if base not in bases:
bases.append(base)
roots: list[Path] = []
for base in bases:
for ancestor in (base, *base.parents):
if ancestor not in roots:
roots.append(ancestor)
local_forbidden: set[Path] = set()
if check_root_dot_cargo:
for base in bases:
for local in (base, base.parent):
local_forbidden.add(local)
dot_cargo = local / ".cargo"
if dot_cargo.exists() or dot_cargo.is_symlink():
raise RuntimeError(
"refusing extract_guards execution with forbidden root "
f"Cargo config directory: {dot_cargo}"
)
ch_roots = _collect_cargo_home_roots(bases) if check_cargo_home else []
ch_root_set = set(ch_roots)
for ancestor in roots:
dot_cargo = ancestor / ".cargo"
defer_dot_cargo = False
if check_cargo_home and ancestor not in local_forbidden:
dot_cargo_norm = Path(os.path.normpath(dot_cargo))
if dot_cargo_norm in ch_root_set:
defer_dot_cargo = True
elif dot_cargo.exists() or dot_cargo.is_symlink():
try:
if dot_cargo.resolve() in ch_root_set:
defer_dot_cargo = True
except OSError:
pass
if not defer_dot_cargo and dot_cargo.is_symlink():
raise RuntimeError(
"refusing extract_guards execution with symlinked ambient "
f".cargo override: {dot_cargo}"
)
cargo_rels: tuple[tuple[str, ...], ...] = (
()
if defer_dot_cargo
else ((".cargo", "config"), (".cargo", "config.toml"))
)
for rel in (*cargo_rels, ("rust-toolchain",), ("rust-toolchain.toml",)):
cand = ancestor.joinpath(*rel)
if cand.exists() or cand.is_symlink():
raise RuntimeError(
"refusing extract_guards execution with ambient toolchain "
f"or Cargo config override: {cand}"
)
if not check_cargo_home:
return
for ch_dir in ch_roots:
for cfg_name in ("config", "config.toml"):
cand = ch_dir / cfg_name
if not cand.exists() and not cand.is_symlink():
continue
if cand.is_symlink() or not cand.is_file():
raise RuntimeError(
"refusing extract_guards execution with non-regular or "
f"symlinked Cargo home config: {cand}"
)
try:
parsed = tomllib.loads(cand.read_text(encoding="utf-8"))
except (OSError, UnicodeDecodeError, tomllib.TOMLDecodeError) as exc:
raise RuntimeError(
"refusing extract_guards execution with unreadable or "
f"invalid Cargo home config {cand}: {exc}"
) from exc
_validate_cargo_home_config(parsed, cand)
def _resolve_executable_token(raw: str | Path) -> Path | None:
"""Resolve an explicit path or a bare command name strictly via `PATH`."""
raw_str = str(raw)
if not raw_str:
return None
if os.sep in raw_str or (os.altsep and os.altsep in raw_str):
cand = Path(raw_str)
if cand.is_file() and os.access(cand, os.X_OK):
return Path(os.path.abspath(cand))
return None
found = shutil.which(raw_str)
if found:
cand = Path(found)
if cand.is_file() and os.access(cand, os.X_OK):
return Path(os.path.abspath(cand))
return None
def _is_rustup_proxy(exe: Path) -> bool:
"""Return True when `exe` resolves to a `rustup` proxy shim."""
try:
real_stem = Path(os.path.realpath(exe)).stem.lower()
except OSError:
return False
return real_stem == "rustup"
def _sanitized_probe_env() -> dict[str, str]:
"""Return `os.environ` stripped of dynamic-loader injection variables."""
return {
k: v
for k, v in os.environ.items()
if k not in FORBIDDEN_LOADER_ENV_VARS
}
def _query_rustc_info(
rustc_bin: Path,
timeout_sec: int,
cwd: Path | None = None,
) -> tuple[str, str, str] | None:
"""Run `rustc -vV` and `--print sysroot`, returning `(commit, host, abs_sr)`."""
run_cwd = str(cwd) if cwd is not None else None
probe_env = _sanitized_probe_env()
try:
ver = subprocess.run(
[str(rustc_bin), "--version", "--verbose"],
capture_output=True,
text=True,
env=probe_env,
cwd=run_cwd,
timeout=timeout_sec,
)
except (OSError, subprocess.TimeoutExpired):
return None
if ver.returncode != 0:
return None
commit_hash = ""
host_triple = ""
for line in ver.stdout.splitlines():
if line.startswith("commit-hash:"):
commit_hash = line.split(":", 1)[1].strip()
elif line.startswith("host:"):
host_triple = line.split(":", 1)[1].strip()
if not commit_hash or not host_triple:
return None
try:
sr = subprocess.run(
[str(rustc_bin), "--print", "sysroot"],
capture_output=True,
text=True,
env=probe_env,
cwd=run_cwd,
timeout=timeout_sec,
)
except (OSError, subprocess.TimeoutExpired):
return None
if sr.returncode != 0:
return None
raw_sysroot = sr.stdout.strip()
if not raw_sysroot:
return None
base_cwd = run_cwd if run_cwd is not None else os.getcwd()
resolved_sysroot = os.path.abspath(os.path.join(base_cwd, raw_sysroot))
return commit_hash, host_triple, resolved_sysroot
def _run_cargo_version(
cargo_bin: Path,
timeout_sec: int,
*,
cwd: Path | None = None,
) -> str | None:
"""Return `cargo_bin --version` stdout when runnable, else `None`."""
try:
proc = subprocess.run(
[str(cargo_bin), "--version"],
capture_output=True,
text=True,
env=_sanitized_probe_env(),
cwd=str(cwd) if cwd is not None else None,
timeout=timeout_sec,
)
except (OSError, subprocess.TimeoutExpired):
return None
if proc.returncode != 0:
return None
return proc.stdout.strip()
def _cargo_usable_in_cwd(
cargo_bin: Path,
probe_cwd: Path,
timeout_sec: int,
*,
build_cwd: Path | None = None,
) -> bool:
"""Check that `cargo_bin` is not a cwd-sensitive `rustup` or shim proxy."""
if _is_rustup_proxy(cargo_bin):
return False
ver_caller = _run_cargo_version(cargo_bin, timeout_sec)
ver_tmp = _run_cargo_version(cargo_bin, timeout_sec, cwd=probe_cwd)
if ver_caller is None or ver_tmp is None or ver_caller != ver_tmp:
return False
if build_cwd is not None:
ver_build = _run_cargo_version(cargo_bin, timeout_sec, cwd=build_cwd)
if ver_build is None or ver_build != ver_caller:
return False
return True
def _validate_explicit_cargo_env() -> Path | None:
"""Resolve an explicit `CARGO` override or fail closed on invalid paths."""
env_cargo = os.environ.get("CARGO")
if env_cargo is None:
return None
if not env_cargo:
raise RuntimeError(
"CARGO is empty; set CARGO to a runnable cargo binary or unset CARGO"
)
explicit_cargo = _resolve_executable_token(env_cargo)
if explicit_cargo is None or not os.access(explicit_cargo, os.X_OK):
raise RuntimeError(
f"CARGO={env_cargo!r} does not point to a runnable cargo binary; "
"pass a valid cargo or unset CARGO"
)
return explicit_cargo
def _is_runnable_cargo(cargo_bin: Path, timeout_sec: int) -> bool:
"""Return True when `cargo_bin` is executable and runs `--version`."""
return (
cargo_bin.is_file()
and os.access(cargo_bin, os.X_OK)
and not _is_rustup_proxy(cargo_bin)
and _run_cargo_version(cargo_bin, timeout_sec) is not None
)
def _resolve_cargo_for_rustc(
rustc_bin: Path,
sysroot: Path,
probe_cwd: Path,
timeout_sec: int,
*,
build_cwd: Path | None = None,
) -> Path | None:
"""Select a concrete `cargo` binary paired with `rustc_bin` / `sysroot`."""
exe_name = "cargo.exe" if os.name == "nt" else "cargo"
sysroot_cargo = sysroot / "bin" / exe_name
sibling_cargo = rustc_bin.parent / exe_name
has_sysroot_cargo = _is_runnable_cargo(
sysroot_cargo, timeout_sec
) and _cargo_usable_in_cwd(
sysroot_cargo, probe_cwd, timeout_sec, build_cwd=build_cwd
)
explicit_cargo = _validate_explicit_cargo_env()
if explicit_cargo is not None:
env_cargo = os.environ["CARGO"]
if _is_rustup_proxy(explicit_cargo):
if has_sysroot_cargo:
return Path(os.path.abspath(sysroot_cargo))
raise RuntimeError(
f"CARGO={env_cargo!r} is a rustup proxy without a usable "
f"sysroot cargo at {sysroot_cargo}"
)
if _cargo_usable_in_cwd(
explicit_cargo, probe_cwd, timeout_sec, build_cwd=build_cwd
):
return explicit_cargo
# A cwd-sensitive wrapper (e.g. a directory-override `cargo` shim) may
# run in the caller cwd while delegating to the toolchain sysroot.
if (
has_sysroot_cargo
and _run_cargo_version(explicit_cargo, timeout_sec) is not None
):
return Path(os.path.abspath(sysroot_cargo))
raise RuntimeError(
f"CARGO={env_cargo!r} does not point to a runnable cargo binary "
"usable across working directories; pass a valid cargo or unset "
"CARGO"
)
if has_sysroot_cargo:
return Path(os.path.abspath(sysroot_cargo))
if (
sibling_cargo != sysroot_cargo
and _is_runnable_cargo(sibling_cargo, timeout_sec)
and _cargo_usable_in_cwd(
sibling_cargo, probe_cwd, timeout_sec, build_cwd=build_cwd
)
):
return Path(os.path.abspath(sibling_cargo))
which_cargo = shutil.which("cargo")
if which_cargo:
found = Path(os.path.abspath(which_cargo))
if _is_runnable_cargo(found, timeout_sec) and _cargo_usable_in_cwd(
found, probe_cwd, timeout_sec, build_cwd=build_cwd
):
return found
return None
def _is_runnable_rustc(rustc_bin: Path, timeout_sec: int) -> bool:
"""Return True when `rustc_bin -vV` executes and prints host metadata."""
try:
ver = subprocess.run(
[str(rustc_bin), "--version", "--verbose"],
capture_output=True,
text=True,
env=_sanitized_probe_env(),
timeout=timeout_sec,
)
except (OSError, subprocess.TimeoutExpired):
return False
return (
ver.returncode == 0
and "commit-hash:" in ver.stdout
and "host:" in ver.stdout
)
SUPPORTED_EXTRACT_HOST_TRIPLE = "x86_64-unknown-linux-gnu"
REQUIRED_EXTRACT_HOST_CFGS = frozenset(
{
'target_arch="x86_64"',
'target_os="linux"',
'target_pointer_width="64"',
'target_endian="little"',
}
)
def _is_supported_extract_host(
rustc_bin: Path,
host_triple: str,
timeout_sec: int,
cwd: Path | None = None,
) -> bool:
"""Return True iff `rustc_bin` targets `x86_64-unknown-linux-gnu`."""
if host_triple != SUPPORTED_EXTRACT_HOST_TRIPLE:
return False
try:
cfg = subprocess.run(
[str(rustc_bin), "--print", "cfg"],
capture_output=True,
text=True,
env=_sanitized_probe_env(),
cwd=str(cwd) if cwd is not None else None,
timeout=timeout_sec,
)
except (OSError, subprocess.TimeoutExpired):
return False
if cfg.returncode != 0:
return False
cfg_lines = {line.strip() for line in cfg.stdout.splitlines()}
return REQUIRED_EXTRACT_HOST_CFGS.issubset(cfg_lines)
def _probe_rustc_candidate(
rustc_bin: Path,
pinned_commit: str,
timeout_sec: int,
*,
build_cwd: Path | None = None,
) -> tuple[Path, Path, str, str] | None:
"""Verify `rustc_bin` matches `pinned_commit` on x86_64-unknown-linux-gnu."""
_assert_no_ambient_toolchain_configs(Path.cwd(), check_cargo_home=True)
check_build_cwd = (
build_cwd if (build_cwd is not None and build_cwd.is_dir()) else None
)
if check_build_cwd is not None:
_assert_no_ambient_toolchain_configs(
check_build_cwd, check_root_dot_cargo=True, check_cargo_home=True
)
resolved_rustc = Path(os.path.abspath(rustc_bin))
if not resolved_rustc.is_file():
return None
caller_info = _query_rustc_info(resolved_rustc, timeout_sec)
if caller_info is None:
return None
commit_hash, host_triple, sysroot = caller_info
if commit_hash != pinned_commit or not _is_supported_extract_host(
resolved_rustc, host_triple, timeout_sec
):
return None
sysroot_path = Path(sysroot)
lib_dir = sysroot_path / "lib"
rustlib_dir = sysroot_path / "lib" / "rustlib" / host_triple / "lib"
if not lib_dir.is_dir() or not rustlib_dir.is_dir():
return None
has_sysroot_driver = any(
p.name.startswith("librustc_driver") and p.is_file()
for p in lib_dir.iterdir()
)
# Base `rustc` ships `<sysroot>/lib/librustc_driver*` even without the
# `rustc-dev` (`rustc_private`) component. Check target `rustlib` for both
# `librustc_driver*` and `librustc_middle*` metadata/libs.
has_rustlib_driver = any(
p.name.startswith("librustc_driver") and p.is_file()
for p in rustlib_dir.iterdir()
)
has_rustlib_middle = any(
p.name.startswith("librustc_middle") and p.is_file()
for p in rustlib_dir.iterdir()
)
if not (has_sysroot_driver and has_rustlib_driver and has_rustlib_middle):
return None
with tempfile.TemporaryDirectory(prefix="anneal-rustc-probe-") as probe_tmp:
probe_cwd = Path(probe_tmp)
_assert_no_ambient_toolchain_configs(probe_cwd, check_cargo_home=True)
probe_dirs = [probe_cwd]
if check_build_cwd is not None:
probe_dirs.append(check_build_cwd)
if _is_rustup_proxy(resolved_rustc):
needs_sysroot_rustc = True
else:
needs_sysroot_rustc = False
for d in probe_dirs:
dir_info = _query_rustc_info(resolved_rustc, timeout_sec, cwd=d)
if (
dir_info is None
or dir_info[0] != commit_hash
or dir_info[1] != host_triple
or dir_info[2] != sysroot
or not _is_supported_extract_host(
resolved_rustc, host_triple, timeout_sec, cwd=d
)
):
needs_sysroot_rustc = True
break
if needs_sysroot_rustc:
rustc_exe = "rustc.exe" if os.name == "nt" else "rustc"
sysroot_rustc = sysroot_path / "bin" / rustc_exe
if not sysroot_rustc.is_file():
return None
for d in probe_dirs:
sr_info = _query_rustc_info(sysroot_rustc, timeout_sec, cwd=d)
if (
sr_info is None
or sr_info[0] != pinned_commit
or sr_info[1] != host_triple
or sr_info[2] != sysroot
or not _is_supported_extract_host(
sysroot_rustc, host_triple, timeout_sec, cwd=d
)
):
return None
resolved_rustc = Path(os.path.abspath(sysroot_rustc))
cargo_bin = _resolve_cargo_for_rustc(
resolved_rustc,
sysroot_path,
probe_cwd,
timeout_sec,
build_cwd=check_build_cwd,
)
if cargo_bin is None:
return None
return resolved_rustc, cargo_bin, sysroot, host_triple
def _resolve_extract_toolchain(
anneal_root: Path,
explicit_rustc: str | Path | None,
timeout_sec: int,
) -> tuple[Path, Path, str, str] | None:
"""Resolve the pinned nightly `rustc` with `rustc-dev` and `cargo`."""
_assert_no_ambient_toolchain_configs(
anneal_root, check_root_dot_cargo=True, check_cargo_home=True
)
_assert_no_ambient_toolchain_configs(Path.cwd(), check_cargo_home=True)
_validate_explicit_cargo_env()
pinned_commit = _read_pinned_compiler_commit(anneal_root)
if explicit_rustc is not None:
explicit_cand = _resolve_executable_token(explicit_rustc)
if explicit_cand is None:
return None
return _probe_rustc_candidate(
explicit_cand, pinned_commit, timeout_sec, build_cwd=anneal_root
)
env_rustc = os.environ.get("RUSTC")
if env_rustc is not None:
if not env_rustc:
raise RuntimeError(
"RUSTC is empty; set RUSTC to a runnable pinned nightly "
"rustc or unset RUSTC"
)
env_cand = _resolve_executable_token(env_rustc)
if env_cand is None or not _is_runnable_rustc(env_cand, timeout_sec):
raise RuntimeError(
f"RUSTC={env_rustc!r} does not point to a runnable rustc "
"binary; pass a valid rustc or unset RUSTC"
)
resolved = _probe_rustc_candidate(
env_cand, pinned_commit, timeout_sec, build_cwd=anneal_root
)
if resolved is None:
raise RuntimeError(
f"RUSTC={env_rustc!r} is not the pinned nightly rustc "
f"({pinned_commit}) on an x86_64-unknown-linux-gnu host with "
"rustc-dev artifacts and cargo; pass a valid rustc or unset RUSTC"
)
return resolved
which_rustc = shutil.which("rustc")
if which_rustc:
cand = Path(os.path.abspath(which_rustc))
resolved = _probe_rustc_candidate(
cand, pinned_commit, timeout_sec, build_cwd=anneal_root
)
if resolved is not None:
return resolved
return None
def _add_unique_path(paths: list[Path], cand: Path) -> None:
resolved = Path(os.path.abspath(cand))
if resolved not in paths:
paths.append(resolved)
def _parse_cargo_json_artifacts(
stdout: str,
extern_rlibs: dict[str, Path],
deps_dirs: list[Path] | None = None,
) -> tuple[Path | None, Path | None]:
"""Extract direct-dep `.rlib` paths, `deps` dirs, and executables."""
capture_bin: Path | None = None
unit_bin: Path | None = None
for line in stdout.splitlines():
line = line.strip()
if not line.startswith("{"):
continue
try:
msg = json.loads(line)
except json.JSONDecodeError:
continue
if msg.get("reason") != "compiler-artifact":
continue
target = msg.get("target", {})
name = target.get("name")
kinds = target.get("kind", [])
is_test = bool(msg.get("profile", {}).get("test"))
filenames = msg.get("filenames")
if isinstance(filenames, list) and deps_dirs is not None:
for fname in filenames:
if not isinstance(fname, str) or not fname:
continue
fpath = Path(os.path.abspath(fname))
if fpath.parent.name == "deps":
_add_unique_path(deps_dirs, fpath.parent)
if name in EXTRACT_DIRECT_DEPS and not is_test:
for fname in filenames if isinstance(filenames, list) else []:
if isinstance(fname, str) and fname.endswith(".rlib"):
rpath = Path(os.path.abspath(fname))
extern_rlibs[name] = rpath
if deps_dirs is not None:
_add_unique_path(deps_dirs, rpath.parent)
break
elif name in ("anneal-rustc-capture", "anneal_rustc_capture"):
exe = msg.get("executable")
if exe:
exe_path = Path(os.path.abspath(exe))
if deps_dirs is not None:
if exe_path.parent.name == "deps":
_add_unique_path(deps_dirs, exe_path.parent)
elif (exe_path.parent / "deps").is_dir():
_add_unique_path(deps_dirs, exe_path.parent / "deps")
if "lib" in kinds and is_test:
unit_bin = exe_path
elif "bin" in kinds and not is_test:
capture_bin = exe_path
return capture_bin, unit_bin
def _build_extract_baseline(
*,
anneal_root: Path,
rustc_bin: Path,
cargo_bin: Path,
sysroot: str,
host_triple: str,
base_target_dir: Path,
need_capture: bool,
need_unit: bool,
timeout_sec: int,
) -> tuple[Path | None, Path | None, tuple[Path, ...], dict[str, Path]]:
"""Build unmodified `anneal-rustc-capture` bin/lib-tests and dep rlibs."""
_assert_no_ambient_toolchain_configs(
anneal_root, check_root_dot_cargo=True, check_cargo_home=True
)
base_target_dir.mkdir(parents=True, exist_ok=True)
env = _extract_subprocess_env(
rustc_bin, sysroot, base_target_dir, host_triple, cargo_cwd=anneal_root
)
manifest_path = anneal_root / "Cargo.toml"
build_timeout = max(timeout_sec, 180)
extern_rlibs: dict[str, Path] = {}
deps_dirs: list[Path] = []
capture_bin: Path | None = None
unit_bin: Path | None = None
if need_unit:
try:
proc = subprocess.run(
[
str(cargo_bin),
"test",
"--locked",
"--offline",
"--no-run",
"--manifest-path",
str(manifest_path),
"-p",
"anneal-rustc-capture",
"--lib",
"--target",
host_triple,
"--config",
'profile.dev.panic="unwind"',
"--target-dir",
str(base_target_dir),
"--message-format=json",
],
capture_output=True,
text=True,
env=env,
cwd=str(anneal_root),
timeout=build_timeout,
)
except subprocess.TimeoutExpired as exc:
raise RuntimeError(
"baseline anneal-rustc-capture lib-test build timed out after "
f"{build_timeout}s"
) from exc
except OSError as exc:
raise RuntimeError(
"failed to execute cargo for baseline anneal-rustc-capture "
f"lib-test build: {exc}"
) from exc
if proc.returncode != 0:
raise RuntimeError(
"baseline anneal-rustc-capture lib-test build failed:\n"
f"{proc.stderr[-1000:]}"
)
_, parsed_unit = _parse_cargo_json_artifacts(
proc.stdout, extern_rlibs, deps_dirs
)
unit_bin = parsed_unit
if unit_bin is None or not unit_bin.is_file():
raise RuntimeError(
"baseline cargo test --lib produced no test executable"
)
if need_capture:
try:
proc = subprocess.run(
[
str(cargo_bin),
"build",
"--locked",
"--offline",
"--manifest-path",
str(manifest_path),
"-p",
"anneal-rustc-capture",
"--bin",
"anneal-rustc-capture",
"--target",
host_triple,
"--config",
'profile.dev.panic="unwind"',
"--target-dir",
str(base_target_dir),
"--message-format=json",
],
capture_output=True,
text=True,
env=env,
cwd=str(anneal_root),
timeout=build_timeout,
)
except subprocess.TimeoutExpired as exc:
raise RuntimeError(
"baseline anneal-rustc-capture binary build timed out after "
f"{build_timeout}s"
) from exc
except OSError as exc:
raise RuntimeError(
"failed to execute cargo for baseline anneal-rustc-capture "
f"binary build: {exc}"
) from exc
if proc.returncode != 0:
raise RuntimeError(
"baseline anneal-rustc-capture binary build failed:\n"
f"{proc.stderr[-1000:]}"
)
parsed_cap, _ = _parse_cargo_json_artifacts(
proc.stdout, extern_rlibs, deps_dirs
)
capture_bin = parsed_cap
if capture_bin is None or not capture_bin.is_file():
raise RuntimeError(
"baseline cargo build --bin produced no capture executable"
)
missing_deps = [d for d in EXTRACT_DIRECT_DEPS if d not in extern_rlibs]
if missing_deps:
raise RuntimeError(
f"baseline cargo build missing direct dep rlibs: {missing_deps}"
)
host_deps_dir = Path(os.path.abspath(base_target_dir / "debug" / "deps"))
if host_deps_dir.is_dir():
_add_unique_path(deps_dirs, host_deps_dir)
if not deps_dirs:
_add_unique_path(deps_dirs, host_deps_dir)
return capture_bin, unit_bin, tuple(deps_dirs), extern_rlibs
def _extract_diag_text(parsed: dict[str, object] | None) -> str:
"""Flatten top-level diagnostics and per-item unsupported reasons."""
if not isinstance(parsed, dict):
return ""
parts: list[str] = []
diags = parsed.get("diagnostics")
if isinstance(diags, list):
parts.extend(str(d) for d in diags)
unsup = parsed.get("unsupported")
if isinstance(unsup, list):
for item in unsup:
if isinstance(item, dict) and "reason" in item:
parts.append(str(item["reason"]))
return "\n".join(parts)
def _run_extract_capture(
capture_bin: Path,
source_text: str,
*,
capture_scope: str,
select_root: str,
instantiate_json: str,
allow_unstable_features: tuple[str, ...] = (),
stdlib_crate: str = "",
panic_strategy: str = "",
exclude_traits: tuple[str, ...] = (),
work_dir: Path,
tag: str,
sysroot: str,
host_triple: str,
env: dict[str, str],
timeout_sec: int,
) -> tuple[int, dict[str, object] | None, str]:
"""Run `anneal-rustc-capture capture` on an isolated temporary crate."""
src_file = work_dir / f"{tag}_lib.rs"
src_file.write_text(source_text, encoding="utf-8")
out_dir = work_dir / f"{tag}_out"
crate_name = stdlib_crate or "demo"
cmd = [
str(capture_bin),
"capture",
"--crate-root",
str(src_file),
"--crate-name",
crate_name,
"--edition",
"2024",
"--target",
host_triple,
"--out-dir",
str(out_dir),
"--sysroot",
sysroot,
"--source-file",
str(src_file),
]
if stdlib_crate:
cmd.extend(["--stdlib-crate", stdlib_crate])
if panic_strategy:
cmd.extend(["--panic", panic_strategy])
for feat in allow_unstable_features:
cmd.extend(["--allow-unstable-feature", feat])
for trait_path in exclude_traits:
cmd.extend(["--exclude-trait", trait_path])
if capture_scope == "crate":
cmd.extend(["--scope", "crate"])
elif capture_scope == "instantiate":
cmd.extend(["--instantiate", instantiate_json])
else:
cmd.extend(["--select", select_root])
try:
proc = subprocess.run(
cmd,
capture_output=True,
text=True,
env=env,
cwd=str(work_dir),
timeout=timeout_sec,
)
except subprocess.TimeoutExpired:
return -1, None, f"capture timed out after {timeout_sec}s"
except OSError as exc:
return -1, None, f"capture launch failed: {exc}"
parsed: dict[str, object] | None = None
for line in reversed(proc.stdout.splitlines()):
stripped = line.strip()
if stripped.startswith("{"):
try:
obj = json.loads(stripped)
if isinstance(obj, dict):
parsed = obj
break
except json.JSONDecodeError:
continue
combined = (proc.stdout + "\n" + proc.stderr).strip()
return proc.returncode, parsed, combined
def _run_extract_unit_test(
unit_bin: Path,
test_name: str,
*,
work_dir: Path,
env: dict[str, str],
timeout_sec: int,
) -> tuple[int, str]:
"""Execute one exact Rust unit test from `anneal-rustc-capture`."""
try:
proc = subprocess.run(
[str(unit_bin), "--exact", test_name, "--nocapture"],
capture_output=True,
text=True,
env=env,
cwd=str(work_dir),
timeout=timeout_sec,
)
except subprocess.TimeoutExpired:
return -1, f"unit test timed out after {timeout_sec}s"
except OSError as exc:
return -1, f"unit test launch failed: {exc}"
return proc.returncode, (proc.stdout + "\n" + proc.stderr).strip()
def _copy_mutated_extract_src(
anneal_root: Path,
guard: ExtractGuard,
mut_src_dir: Path,
) -> str | None:
"""Copy `trusted/rustc-capture/src/*.rs` and apply one guard mutation."""
src_root = anneal_root / "trusted/rustc-capture/src"
mut_src_dir.mkdir(parents=True, exist_ok=True)
target_name = Path(guard.target_file).name
found_target = False
for rs_file in src_root.glob("*.rs"):
text = rs_file.read_text(encoding="utf-8")
if rs_file.name == target_name:
found_target = True
try:
text = apply_single_guard_mutation(
text,
guard.anchor,
guard.replacement,
guard_id=guard.guard_id,
)
except ValueError as exc:
return str(exc)
(mut_src_dir / rs_file.name).write_text(text, encoding="utf-8")
if not found_target:
return f"target file {guard.target_file} not found under {src_root}"
return None
def _compile_mutated_extract_unit(
rustc_bin: Path,
mut_src_dir: Path,
out_bin: Path,
*,
host_triple: str,
deps_dirs: tuple[Path, ...],
extern_rlibs: dict[str, Path],
sysroot: str,
env: dict[str, str],
timeout_sec: int,
) -> tuple[bool, str]:
"""Compile mutated `anneal-rustc-capture` lib unit tests directly."""
cmd = [
str(rustc_bin),
"--crate-name",
"anneal_rustc_capture",
"--edition=2024",
"--target",
host_triple,
"--test",
"-C",
"panic=unwind",
"-C",
"debuginfo=0",
]
for d_dir in deps_dirs:
cmd.extend(["-L", f"dependency={d_dir}"])
for dep_name in EXTRACT_DIRECT_DEPS:
cmd.extend(["--extern", f"{dep_name}={extern_rlibs[dep_name]}"])
cmd.extend([
"-L",
f"native={Path(sysroot) / 'lib'}",
"-C",
f"link-arg=-Wl,-rpath,{Path(sysroot) / 'lib'}",
str(mut_src_dir / "lib.rs"),
"-o",
str(out_bin),
])
try:
proc = subprocess.run(
cmd,
capture_output=True,
text=True,
env=env,
cwd=str(out_bin.parent),
timeout=timeout_sec,
)
except subprocess.TimeoutExpired:
return False, f"mutated unit-test rustc timed out after {timeout_sec}s"
if proc.returncode != 0:
return False, (
f"mutated unit-test build failed (rc={proc.returncode}): "
f"{(proc.stdout + proc.stderr).strip()[:300]}"
)
return True, ""
def _compile_mutated_extract_capture(
rustc_bin: Path,
mut_src_dir: Path,
tmp_path: Path,
out_bin: Path,
*,
host_triple: str,
deps_dirs: tuple[Path, ...],
extern_rlibs: dict[str, Path],
sysroot: str,
env: dict[str, str],
timeout_sec: int,
) -> tuple[bool, str]:
"""Compile mutated `anneal-rustc-capture` library + binary directly."""
mut_rlib = tmp_path / "libanneal_rustc_capture.rlib"
lib_cmd = [
str(rustc_bin),
"--crate-name",
"anneal_rustc_capture",
"--edition=2024",
"--target",
host_triple,
"--crate-type",
"lib",
"-C",
"panic=unwind",
"-C",
"debuginfo=0",
]
for d_dir in deps_dirs:
lib_cmd.extend(["-L", f"dependency={d_dir}"])
for dep_name in EXTRACT_DIRECT_DEPS:
lib_cmd.extend(["--extern", f"{dep_name}={extern_rlibs[dep_name]}"])
lib_cmd.extend([str(mut_src_dir / "lib.rs"), "-o", str(mut_rlib)])
try:
lib_proc = subprocess.run(
lib_cmd,
capture_output=True,
text=True,
env=env,
cwd=str(tmp_path),
timeout=timeout_sec,
)
except subprocess.TimeoutExpired:
return False, f"mutated lib rustc timed out after {timeout_sec}s"
if lib_proc.returncode != 0:
return False, (
f"mutated lib build failed (rc={lib_proc.returncode}): "
f"{(lib_proc.stdout + lib_proc.stderr).strip()[:300]}"
)
bin_cmd = [
str(rustc_bin),
"--crate-name",
"anneal_rustc_capture",
"--edition=2024",
"--target",
host_triple,
"--crate-type",
"bin",
"-C",
"panic=unwind",
"-C",
"debuginfo=0",
]
for d_dir in deps_dirs:
bin_cmd.extend(["-L", f"dependency={d_dir}"])
bin_cmd.extend([
"--extern",
f"anneal_rustc_capture={mut_rlib}",
"-L",
f"native={Path(sysroot) / 'lib'}",
"-C",
f"link-arg=-Wl,-rpath,{Path(sysroot) / 'lib'}",
str(mut_src_dir / "main.rs"),
"-o",
str(out_bin),
])
try:
bin_proc = subprocess.run(
bin_cmd,
capture_output=True,
text=True,
env=env,
cwd=str(tmp_path),
timeout=timeout_sec,
)
except subprocess.TimeoutExpired:
return False, f"mutated bin rustc timed out after {timeout_sec}s"
if bin_proc.returncode != 0:
return False, (
f"mutated bin build failed (rc={bin_proc.returncode}): "
f"{(bin_proc.stdout + bin_proc.stderr).strip()[:300]}"
)
return True, ""
def _check_one_extract_guard(
guard: ExtractGuard,
*,
anneal_root: Path,
rustc_bin: Path,
sysroot: str,
host_triple: str,
deps_dirs: tuple[Path, ...],
extern_rlibs: dict[str, Path],
timeout_sec: int,
) -> GuardResult:
t0 = time.monotonic()
with tempfile.TemporaryDirectory(
prefix=f"anneal-gmut-{guard.guard_id}-"
) as tmp:
tmp_path = Path(tmp)
env = _extract_subprocess_env(
rustc_bin, sysroot, tmp_path, host_triple
)
mut_src_dir = tmp_path / "src"
mut_err = _copy_mutated_extract_src(anneal_root, guard, mut_src_dir)
if mut_err is not None:
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=mut_err,
)
if guard.mode == "unit":
mut_unit_bin = tmp_path / "mut_unit"
ok, err = _compile_mutated_extract_unit(
rustc_bin,
mut_src_dir,
mut_unit_bin,
host_triple=host_triple,
deps_dirs=deps_dirs,
extern_rlibs=extern_rlibs,
sysroot=sysroot,
env=env,
timeout_sec=timeout_sec,
)
if not ok:
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=err,
)
s_rc, s_out = _run_extract_unit_test(
mut_unit_bin,
guard.sanity_unit_test,
work_dir=tmp_path,
env=env,
timeout_sec=timeout_sec,
)
if s_rc != 0 or "1 passed; 0 failed" not in s_out:
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=(
f"positive unit sanity {guard.sanity_unit_test} broke "
f"(rc={s_rc}): {s_out[:220]}"
),
)
rc, out = _run_extract_unit_test(
mut_unit_bin,
guard.unit_test_name,
work_dir=tmp_path,
env=env,
timeout_sec=timeout_sec,
)
if rc == 0 and "1 passed; 0 failed" in out:
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="SURVIVED",
duration_sec=time.monotonic() - t0,
detail=f"unit test {guard.unit_test_name} still passed on mutant",
)
if (
rc == 101
and f"test {guard.unit_test_name} ... FAILED" in out
and "0 passed; 1 failed" in out
):
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="KILLED",
duration_sec=time.monotonic() - t0,
detail=f"unit test {guard.unit_test_name} failed as expected",
)
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=f"unexpected unit-test outcome rc={rc}: {out[:240]}",
)
# mode == "capture"
mut_cap_bin = tmp_path / "mut_capture"
ok, err = _compile_mutated_extract_capture(
rustc_bin,
mut_src_dir,
tmp_path,
mut_cap_bin,
host_triple=host_triple,
deps_dirs=deps_dirs,
extern_rlibs=extern_rlibs,
sysroot=sysroot,
env=env,
timeout_sec=timeout_sec,
)
if not ok:
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=err,
)
sanity_scope = "crate" if guard.capture_scope == "crate" else "select"
sanity_source = EXTRACT_POSITIVE_SANITY_SOURCE
sanity_exclude: tuple[str, ...] = ()
if guard.exclude_traits:
sanity_scope = "crate"
sanity_source = EXCLUDE_TRAIT_POSITIVE_SANITY_SOURCE
sanity_exclude = EXCLUDE_TRAIT_POSITIVE_SANITY_TRAITS
s_rc, s_parsed, s_out = _run_extract_capture(
mut_cap_bin,
sanity_source,
capture_scope=sanity_scope,
select_root="selected",
instantiate_json="",
exclude_traits=sanity_exclude,
work_dir=tmp_path,
tag="sanity",
sysroot=sysroot,
host_triple=host_triple,
env=env,
timeout_sec=timeout_sec,
)
if (
s_rc != 0
or not isinstance(s_parsed, dict)
or s_parsed.get("status") != "captured"
):
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=(
f"positive capture sanity broke on mutant "
f"(rc={s_rc}, parsed={s_parsed!r}): {s_out[:200]}"
),
)
rc, parsed, out = _run_extract_capture(
mut_cap_bin,
guard.negative_source,
capture_scope=guard.capture_scope,
select_root=guard.select_root,
instantiate_json=guard.instantiate_json,
allow_unstable_features=guard.allow_unstable_features,
stdlib_crate=guard.stdlib_crate,
panic_strategy=guard.panic_strategy,
exclude_traits=guard.exclude_traits,
work_dir=tmp_path,
tag="neg",
sysroot=sysroot,
host_triple=host_triple,
env=env,
timeout_sec=timeout_sec,
)
status_field = parsed.get("status") if isinstance(parsed, dict) else None
if rc == 0 and status_field == "captured":
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="KILLED",
duration_sec=time.monotonic() - t0,
detail="negative capture witness flipped from unsupported to captured",
)
if rc == 1 and status_field == guard.expected_baseline_status:
diag_text = (
out
if status_field == "compiler_failed"
else _extract_diag_text(parsed)
)
if (
not guard.expected_baseline_diagnostic
or guard.expected_baseline_diagnostic in diag_text
):
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="SURVIVED",
duration_sec=time.monotonic() - t0,
detail=(
"mutant still rejected witness: "
f"{diag_text[:200]!r}"
),
)
if (
guard.allow_downstream_fallback
and rc == 1
and status_field == "unsupported"
):
fallback_diag = _extract_diag_text(parsed)
if (
(
not guard.expected_baseline_diagnostic
or guard.expected_baseline_diagnostic not in fallback_diag
)
and guard.expected_fallback_diagnostic
and guard.expected_fallback_diagnostic in fallback_diag
):
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="KILLED",
duration_sec=time.monotonic() - t0,
detail=(
"precedence guard bypassed; fell through to downstream "
f"refusal: {fallback_diag[:160]!r}"
),
)
return GuardResult(
suite="extract_guards",
guard_id=guard.guard_id,
target_file=guard.target_file,
status="ERROR",
duration_sec=time.monotonic() - t0,
detail=(
f"unexpected capture result rc={rc} status={status_field!r} "
f"out={out[:220]}"
),
)
FORBIDDEN_FIXTURE_TOKENS_RE = re.compile(
r"\b(?:sorry|admit|native_decide|ofReduceBool|axiom|unsafe)\b"
)
LEAN_CHAR_LIT_RE = re.compile(
r"'(?:[^'\\\r\n]|\\(?:[\\\"'ntr0]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}))'"
)
LEAN_IMPORT_HEADER_RE = re.compile(
r"(?:^|(?<=[\s;]))(?:(?:public|meta)\s+)*"
r"import(?![A-Za-z0-9_'!?»])(?:\s+all(?![A-Za-z0-9_'!?»]))?"
)
_LEAN_MOD_SEGMENT_PATTERN = r"(?:«[^»\r\n]+»|[A-Za-z_][A-Za-z0-9_'!?]*)"
LEAN_IDENT_RE = re.compile(
rf"{_LEAN_MOD_SEGMENT_PATTERN}(?:\.{_LEAN_MOD_SEGMENT_PATTERN})*"
)
_LEAN_QUOTED_SEG_RE = re.compile(r"«([^»\r\n]+)»")
LEAN_IMPORT_STOP_KEYWORDS = frozenset({
"prelude",
"module",
"public",
"meta",
"import",
"all",
"theorem",
"def",
"lemma",
"abbrev",
"opaque",
"axiom",
"inductive",
"structure",
"class",
"instance",
"example",
"namespace",
"section",
"end",
"open",
"export",
"variable",
"universe",
"set_option",
"attribute",
"private",
"protected",
"noncomputable",
"partial",
"unsafe",
"deriving",
"initialize",
"builtin_initialize",
"macro",
"macro_rules",
"syntax",
"elab",
"elab_rules",
"notation",
"infix",
"infixl",
"infixr",
"prefix",
"postfix",
"mutual",
"reducible",
"scoped",
"local",
"sorry",
"admit",
"native_decide",
"ofReduceBool",
"run_cmd",
"eval",
"check",
"print",
"reduce",
"guard_msgs",
"unseal",
"seal",
"irreducible_def",
})
def _strip_lean_comments_and_strings(text: str) -> str:
"""Strip Lean comments, string literals, and char literals for linting."""
out: list[str] = []
i = 0
n = len(text)
block_depth = 0
in_str = False
while i < n:
ch = text[i]
nxt = text[i + 1] if i + 1 < n else ""
if block_depth > 0:
if ch == "/" and nxt == "-":
block_depth += 1
i += 2
continue
if ch == "-" and nxt == "/":
block_depth -= 1
if block_depth == 0:
out.append(" ")
i += 2
continue
if ch == "\n":
out.append("\n")
i += 1
continue
if in_str:
if ch == "\\" and i + 1 < n:
if text[i + 1] == "\n":
out.append("\n")
i += 2
continue
if ch == '"':
in_str = False
out.append(" ")
elif ch == "\n":
out.append("\n")
i += 1
continue
if ch == "/" and nxt == "-":
block_depth = 1
i += 2
continue
if ch == "-" and nxt == "-":
while i < n and text[i] != "\n":
i += 1
continue
if ch == "r" and (
i == 0
or not (text[i - 1].isalnum() or text[i - 1] in ("_", "'", "»"))
):
j = i + 1
while j < n and text[j] == "#":
j += 1
if j < n and text[j] == '"':
close_seq = '"' + ("#" * (j - (i + 1)))
k = j + 1
while k < n:
if text.startswith(close_seq, k):
out.append(" ")
i = k + len(close_seq)
break
if text[k] == "\n":
out.append("\n")
k += 1
else:
i = n
continue
if ch == '"':
in_str = True
i += 1
continue
if ch == "'" and (
i == 0 or not (text[i - 1].isalnum() or text[i - 1] in ("_", "'"))
):
m_char = LEAN_CHAR_LIT_RE.match(text, i)
if m_char is not None:
out.append(" ")
i = m_char.end()
continue
out.append(ch)
i += 1
return "".join(out)
def _find_forbidden_fixture_tokens(text: str) -> list[str]:
cleaned = _strip_lean_comments_and_strings(text)
return sorted(set(FORBIDDEN_FIXTURE_TOKENS_RE.findall(cleaned)))
def _normalize_lean_module_token(raw_tok: str) -> str:
"""Strip Lean guillemet quotes (`«...»`) from module name segments."""
return _LEAN_QUOTED_SEG_RE.sub(r"\1", raw_tok)
def _extract_lean_imports(text: str) -> list[str]:
"""Extract imported Lean modules across multiline/`public`/`meta`/`all`.
Parses both plain identifiers and guillemet-quoted (`«...»`) hierarchical
segments and raises `ValueError` fail-closed if an `import` clause contains
an unrecognized or unclosed token.
"""
cleaned = _strip_lean_comments_and_strings(text)
cleaned = cleaned.replace("\r\n", "\n").replace("\r", "\n")
imports: list[str] = []
n = len(cleaned)
pos = 0
while pos < n:
m = LEAN_IMPORT_HEADER_RE.search(cleaned, pos)
if m is None:
break
cur = m.end()
pos = cur
if cur >= n or not cleaned[cur].isspace():
raise ValueError(
f"unrecognized Lean import syntax near "
f"{cleaned[m.start():m.end() + 24]!r}"
)
parsed_any = False
while True:
while cur < n and cleaned[cur].isspace():
cur += 1
if cur >= n or cleaned[cur] == ";":
break
if parsed_any and cleaned[cur] in ("#", "@"):
break
tok = LEAN_IDENT_RE.match(cleaned, cur)
if tok is None:
raise ValueError(
f"unrecognized Lean import token near {cleaned[cur:cur + 40]!r}"
)
raw_mod = tok.group(0)
end = tok.end()
if end < n and not (
cleaned[end].isspace() or cleaned[end] == ";"
):
raise ValueError(
f"unrecognized Lean import token near {cleaned[cur:end + 24]!r}"
)
if (
"." not in raw_mod
and "«" not in raw_mod
and raw_mod in LEAN_IMPORT_STOP_KEYWORDS
):
break
imports.append(_normalize_lean_module_token(raw_mod))
parsed_any = True
pos = end
cur = end
if not parsed_any:
raise ValueError(
f"import clause yielded no module name near "
f"{cleaned[m.start():m.start() + 40]!r}"
)
return imports
def _compute_true_semantics_downstream(
trusted_lean_dir: Path,
) -> dict[str, set[str]]:
"""Compute true transitive downstream closure across `SEMANTICS_MODULES`."""
sem_set = set(SEMANTICS_MODULES)
direct_importers: dict[str, set[str]] = {m: set() for m in SEMANTICS_MODULES}
for mod in SEMANTICS_MODULES:
mod_path = trusted_lean_dir / f"{mod}.lean"
if not mod_path.is_file():
continue
for mod_tok in _extract_lean_imports(
mod_path.read_text(encoding="utf-8")
):
imp = mod_tok.replace(".", "/")
if imp in sem_set:
direct_importers[imp].add(mod)
closure: dict[str, set[str]] = {}
for mod in SEMANTICS_MODULES:
visited = {mod}
stack = [mod]
while stack:
cur = stack.pop()
for nxt in direct_importers.get(cur, ()):
if nxt not in visited:
visited.add(nxt)
stack.append(nxt)
closure[mod] = visited
return closure
def _collect_fixture_semantics_imports(
fixtures_dir: Path,
mod: str,
cache: dict[str, set[str]],
) -> set[str]:
"""Return all `Trusted/MirSemantics/*` modules transitively imported."""
if mod in cache:
return cache[mod]
sem_set = set(SEMANTICS_MODULES)
found: set[str] = set()
cache[mod] = found
path = fixtures_dir / f"{mod}.lean"
if not path.is_file():
return found
for mod_tok in _extract_lean_imports(path.read_text(encoding="utf-8")):
imp_slash = mod_tok.replace(".", "/")
if imp_slash in sem_set:
found.add(imp_slash)
elif (fixtures_dir / f"{imp_slash}.lean").is_file():
found.update(
_collect_fixture_semantics_imports(
fixtures_dir, imp_slash, cache
)
)
cache[mod] = found
return found
def validate_catalog_invariants(
anneal_root: Path,
*,
lean_only: bool = False,
) -> list[str]:
"""Check static catalog invariants without invoking Lean or rustc.
When `lean_only` is True (used by `ci-core` Lean-only sandboxes that omit
`trusted/rustc-capture/src/`), metadata invariants across all four suites
and source anchors across the three Lean suites are checked without reading
`trusted/rustc-capture/src/*.rs`.
Returns a list of error strings (empty when all invariants hold).
"""
errors: list[str] = []
seen_ids: set[str] = set()
fixtures_dir = anneal_root / "ci/fixtures/guard_mutation"
trusted_lean_dir = anneal_root / "trusted/lean"
semantics_dir = trusted_lean_dir / "Trusted/MirSemantics"
if semantics_dir.is_dir():
discovered_sem = {
f"Trusted/MirSemantics/{p.stem}"
for p in semantics_dir.glob("*.lean")
}
overlap = set(SEMANTICS_MODULES) & set(NON_GUARD_SEMANTICS_MODULES)
if overlap:
errors.append(
"SEMANTICS_MODULES and NON_GUARD_SEMANTICS_MODULES overlap: "
f"{sorted(overlap)}"
)
missing_exclusions = (
set(NON_GUARD_SEMANTICS_MODULES) - discovered_sem
)
if missing_exclusions:
errors.append(
"NON_GUARD_SEMANTICS_MODULES references missing file(s): "
f"{sorted(missing_exclusions)}"
)
uncovered_dir_mods = (
discovered_sem
- set(SEMANTICS_MODULES)
- set(NON_GUARD_SEMANTICS_MODULES)
)
if uncovered_dir_mods:
errors.append(
"Trusted/MirSemantics/ has modules outside SEMANTICS_MODULES "
f"and NON_GUARD_SEMANTICS_MODULES: {sorted(uncovered_dir_mods)}"
)
try:
true_downstream = _compute_true_semantics_downstream(trusted_lean_dir)
except ValueError as exc:
errors.append(str(exc))
true_downstream = {}
fixture_import_cache: dict[str, set[str]] = {}
checked_fixture_files: set[Path] = set()
for helper in FIXTURE_HELPERS_END_TO_END:
hp = fixtures_dir / f"{helper}.lean"
if hp.is_file():
checked_fixture_files.add(hp)
bad_toks = _find_forbidden_fixture_tokens(
hp.read_text(encoding="utf-8")
)
if bad_toks:
errors.append(
f"{helper}.lean: forbidden fixture tokens {bad_toks}"
)
for guard in MIR_SEMANTICS_GUARDS:
if guard.guard_id in seen_ids:
errors.append(f"duplicate guard_id: {guard.guard_id}")
seen_ids.add(guard.guard_id)
if guard.target_module not in SEMANTICS_DOWNSTREAM:
errors.append(
f"{guard.guard_id}: unknown target_module {guard.target_module}"
)
target_path = anneal_root / guard.target_file
if not target_path.is_file():
errors.append(f"{guard.guard_id}: missing target_file {target_path}")
else:
text = target_path.read_text(encoding="utf-8")
try:
apply_single_guard_mutation(
text, guard.anchor, guard.replacement, guard_id=guard.guard_id
)
except ValueError as exc:
errors.append(str(exc))
fixture_path = fixtures_dir / f"{guard.fixture_module}.lean"
if not fixture_path.is_file():
errors.append(
f"{guard.guard_id}: missing fixture_module {fixture_path}"
)
else:
ftext = fixture_path.read_text(encoding="utf-8")
if fixture_path not in checked_fixture_files:
checked_fixture_files.add(fixture_path)
bad_toks = _find_forbidden_fixture_tokens(ftext)
if bad_toks:
errors.append(
f"{guard.fixture_module}.lean: forbidden fixture "
f"tokens {bad_toks}"
)
try:
find_theorem_line_span(ftext, guard.theorem_name)
except ValueError as exc:
errors.append(f"{guard.guard_id}: {exc}")
sanity_path = fixtures_dir / f"{guard.sanity_module}.lean"
if not sanity_path.is_file():
errors.append(
f"{guard.guard_id}: missing sanity_module {sanity_path}"
)
elif sanity_path not in checked_fixture_files:
checked_fixture_files.add(sanity_path)
bad_toks = _find_forbidden_fixture_tokens(
sanity_path.read_text(encoding="utf-8")
)
if bad_toks:
errors.append(
f"{guard.sanity_module}.lean: forbidden fixture "
f"tokens {bad_toks}"
)
if guard.target_module in SEMANTICS_DOWNSTREAM:
rebuilt = set(SEMANTICS_DOWNSTREAM[guard.target_module])
omitted_downstream = (
true_downstream.get(guard.target_module, set()) - rebuilt
)
for mod_label, mod_name in (
("fixture_module", guard.fixture_module),
("sanity_module", guard.sanity_module),
):
try:
trans_imps = _collect_fixture_semantics_imports(
fixtures_dir, mod_name, fixture_import_cache
)
except ValueError as exc:
errors.append(
f"{guard.guard_id}: {mod_label} {mod_name}: {exc}"
)
continue
stale_imps = sorted(trans_imps & omitted_downstream)
if stale_imps:
errors.append(
f"{guard.guard_id}: {mod_label} {mod_name} "
f"transitively imports {stale_imps} outside "
f"SEMANTICS_DOWNSTREAM[{guard.target_module!r}]"
)
for guard in (*AUDIT_HEADER_GUARDS, *AUDIT_BOUNDARY_GUARDS):
if guard.guard_id in seen_ids:
errors.append(f"duplicate guard_id: {guard.guard_id}")
seen_ids.add(guard.guard_id)
if isinstance(guard, AuditBoundaryGuard):
if guard.mode == "spec-preflight":
if guard.fixture_id not in VALID_SPEC_BOUNDARY_FIXTURE_IDS:
errors.append(
f"{guard.guard_id}: unknown spec-preflight fixture_id "
f"{guard.fixture_id!r}"
)
elif guard.mode == "target-audit":
if guard.fixture_id not in VALID_TARGET_BOUNDARY_FIXTURE_IDS:
errors.append(
f"{guard.guard_id}: unknown target-audit fixture_id "
f"{guard.fixture_id!r}"
)
elif guard.mode == "audit":
if guard.fixture_id not in VALID_AUDIT_BOUNDARY_FIXTURE_IDS:
errors.append(
f"{guard.guard_id}: unknown audit fixture_id "
f"{guard.fixture_id!r}"
)
else:
errors.append(f"{guard.guard_id}: invalid mode {guard.mode!r}")
target_path = anneal_root / guard.target_file
if not target_path.is_file():
errors.append(f"{guard.guard_id}: missing target_file {target_path}")
else:
text = target_path.read_text(encoding="utf-8")
try:
apply_single_guard_mutation(
text, guard.anchor, guard.replacement, guard_id=guard.guard_id
)
except ValueError as exc:
errors.append(str(exc))
for guard in EXTRACT_GUARDS:
if guard.guard_id in seen_ids:
errors.append(f"duplicate guard_id: {guard.guard_id}")
seen_ids.add(guard.guard_id)
if guard.mode not in ("capture", "unit"):
errors.append(f"{guard.guard_id}: invalid mode {guard.mode!r}")
elif guard.mode == "unit":
if not guard.unit_test_name:
errors.append(f"{guard.guard_id}: missing unit_test_name")
else:
if not guard.negative_source.strip():
errors.append(f"{guard.guard_id}: missing negative_source")
if guard.capture_scope not in ("select", "crate", "instantiate"):
errors.append(
f"{guard.guard_id}: invalid capture_scope {guard.capture_scope!r}"
)
if guard.expected_baseline_status not in (
"unsupported",
"compiler_failed",
):
errors.append(
f"{guard.guard_id}: invalid expected_baseline_status "
f"{guard.expected_baseline_status!r}"
)
if guard.capture_scope == "instantiate" and not guard.instantiate_json:
errors.append(f"{guard.guard_id}: missing instantiate_json")
if guard.stdlib_crate not in ("", "core"):
errors.append(
f"{guard.guard_id}: invalid stdlib_crate {guard.stdlib_crate!r}"
)
if guard.stdlib_crate and guard.allow_unstable_features:
errors.append(
f"{guard.guard_id}: stdlib_crate and allow_unstable_features "
"are mutually exclusive"
)
if guard.allow_unstable_features and (
guard.allow_unstable_features
!= tuple(sorted(set(guard.allow_unstable_features)))
or any(
not re.fullmatch(r"[a-z][a-z0-9_]*", f)
for f in guard.allow_unstable_features
)
):
errors.append(
f"{guard.guard_id}: invalid or unsorted "
f"allow_unstable_features {guard.allow_unstable_features!r}"
)
if guard.allow_downstream_fallback and (
not guard.expected_baseline_diagnostic
or not guard.expected_fallback_diagnostic
):
errors.append(
f"{guard.guard_id}: allow_downstream_fallback requires "
"expected_baseline_diagnostic and "
"expected_fallback_diagnostic"
)
if not lean_only:
target_path = anneal_root / guard.target_file
if not target_path.is_file():
errors.append(
f"{guard.guard_id}: missing target_file {target_path}"
)
else:
text = target_path.read_text(encoding="utf-8")
try:
apply_single_guard_mutation(
text,
guard.anchor,
guard.replacement,
guard_id=guard.guard_id,
)
except ValueError as exc:
errors.append(str(exc))
return errors
def _parse_shard_spec(spec: str) -> tuple[int, int]:
"""Parse a 1-based `<index>/<total>` shard specification."""
parts = spec.strip().split("/")
if (
len(parts) != 2
or not (parts[0].isascii() and parts[0].isdigit())
or not (parts[1].isascii() and parts[1].isdigit())
):
raise ValueError(
f"invalid --shard specification {spec!r}: expected <index>/<total>"
)
index, total = int(parts[0]), int(parts[1])
if total < 1 or index < 1 or index > total:
raise ValueError(
f"invalid --shard specification {spec!r}: require 1 <= index <= total"
)
return index, total
def _shard_slice(items: list, shard: tuple[int, int] | None) -> list:
if shard is None:
return items
index, total = shard
return [item for pos, item in enumerate(items) if pos % total == index - 1]
def _select_guards(
suite: str,
name_filter: str | None,
shard: tuple[int, int] | None = None,
) -> tuple[
list[MirSemanticsGuard],
list[AuditHeaderGuard],
list[AuditBoundaryGuard],
list[ExtractGuard],
]:
mir_guards = (
list(MIR_SEMANTICS_GUARDS)
if suite in ("all", "mir_semantics")
else []
)
audit_guards = (
list(AUDIT_HEADER_GUARDS)
if suite in ("all", "audit_headers")
else []
)
boundary_guards = (
list(AUDIT_BOUNDARY_GUARDS)
if suite in ("all", "audit_boundary")
else []
)
extract_guards = (
list(EXTRACT_GUARDS)
if suite in ("all", "extract_guards")
else []
)
if name_filter:
mir_guards = [g for g in mir_guards if name_filter in g.guard_id]
audit_guards = [g for g in audit_guards if name_filter in g.guard_id]
boundary_guards = [
g for g in boundary_guards if name_filter in g.guard_id
]
extract_guards = [
g for g in extract_guards if name_filter in g.guard_id
]
if shard is not None:
mir_guards = _shard_slice(mir_guards, shard)
audit_guards = _shard_slice(audit_guards, shard)
boundary_guards = _shard_slice(boundary_guards, shard)
extract_guards = _shard_slice(extract_guards, shard)
return mir_guards, audit_guards, boundary_guards, extract_guards
def run_guard_mutation_suite(
*,
anneal_root: Path,
lean_bin: Path | None,
rustc_bin: str | Path | None = None,
suite: str = "all",
lean_only: bool = False,
name_filter: str | None = None,
shard: tuple[int, int] | None = None,
jobs: int = 4,
timeout_sec: int = 60,
) -> dict[str, object]:
"""Run baseline verification and all selected single-guard mutations."""
t_start = time.monotonic()
if lean_only and suite == "extract_guards":
raise RuntimeError(
"--lean-only cannot be combined with --suite extract_guards"
)
anneal_root = Path(os.path.abspath(anneal_root))
if lean_bin is not None:
lean_bin = Path(os.path.abspath(lean_bin))
catalog_errors = validate_catalog_invariants(
anneal_root, lean_only=lean_only
)
if catalog_errors:
raise RuntimeError(
"guard catalog validation failed:\n - "
+ "\n - ".join(catalog_errors)
)
mir_guards, audit_guards, boundary_guards, extract_guards = _select_guards(
suite, name_filter, shard=shard
)
need_lean = bool(mir_guards or audit_guards or boundary_guards)
if lean_only and not need_lean:
raise RuntimeError(
f"no Lean guards matched suite={suite!r} filter={name_filter!r} "
"under --lean-only"
)
if not need_lean and not extract_guards:
raise RuntimeError(
f"no guards matched suite={suite!r} filter={name_filter!r}"
)
if need_lean and lean_bin is None:
raise RuntimeError(
"Lean binary is required for mir_semantics / audit_* suites"
)
trusted_lean_dir = anneal_root / "trusted/lean"
fixtures_dir = anneal_root / "ci/fixtures/guard_mutation"
results: list[GuardResult] = []
skipped_suites: list[str] = []
baseline_sec = 0.0
with tempfile.TemporaryDirectory(prefix="anneal-gmut-base-") as base_tmp:
base_path = Path(base_tmp)
base_olean_dir = base_path / "olean"
base_olean_dir.mkdir()
# --------------------------------------------------------------
# Suite 1: Trusted/MirSemantics/ baseline + mutants
# --------------------------------------------------------------
if mir_guards:
assert lean_bin is not None
t_base = time.monotonic()
for mod in (*BASE_TRUSTED_MODULES, *SEMANTICS_MODULES):
res = _compile_module(
lean_bin,
trusted_lean_dir,
mod,
base_olean_dir,
lean_path=[base_olean_dir],
timeout_sec=timeout_sec,
)
if res.returncode != 0:
raise RuntimeError(
f"baseline trusted module {mod} failed to compile:\n"
f"{res.stdout}\n{res.stderr}"
)
# Verify baseline helpers, positive sanity checks, and every
# negative refutation module pass cleanly on unmodified TCB.
needed_fixtures = sorted({g.fixture_module for g in mir_guards})
needed_sanity = sorted({g.sanity_module for g in mir_guards})
baseline_fixture_mods: list[str] = [
*FIXTURE_HELPERS_END_TO_END,
*needed_sanity,
*needed_fixtures,
]
for mod in baseline_fixture_mods:
f_src = (fixtures_dir / f"{mod}.lean").read_text(
encoding="utf-8"
)
bad_toks = _find_forbidden_fixture_tokens(f_src)
if bad_toks:
raise RuntimeError(
f"baseline fixture {mod}.lean contains forbidden "
f"tokens: {bad_toks}"
)
res = _compile_module(
lean_bin,
fixtures_dir,
mod,
base_olean_dir,
lean_path=[base_olean_dir],
timeout_sec=timeout_sec,
)
combined = res.stdout + "\n" + res.stderr
if res.returncode != 0 or "uses 'sorry'" in combined:
raise RuntimeError(
f"baseline fixture {mod} failed on unmodified TCB "
f"(rc={res.returncode}):\n{combined}"
)
baseline_sec += time.monotonic() - t_base
worker_count = max(1, min(jobs, len(mir_guards)))
with ThreadPoolExecutor(max_workers=worker_count) as pool:
future_map = {
pool.submit(
_check_one_mir_guard,
guard,
anneal_root=anneal_root,
lean_bin=lean_bin,
base_olean_dir=base_olean_dir,
fixtures_dir=fixtures_dir,
timeout_sec=timeout_sec,
): guard
for guard in mir_guards
}
mir_by_id: dict[str, GuardResult] = {}
for fut in as_completed(future_map):
res = fut.result()
mir_by_id[res.guard_id] = res
results.extend(mir_by_id[g.guard_id] for g in mir_guards)
# --------------------------------------------------------------
# Suite 2 & 3: Audit header and boundary guards
# --------------------------------------------------------------
if audit_guards or boundary_guards:
assert lean_bin is not None
t_audit_base = time.monotonic()
sysroot = _query_lean_sysroot(lean_bin, timeout_sec)
tb_olean_dir = base_path / "tb_olean"
tb_olean_dir.mkdir()
tb_src_dir = anneal_root / "trusted/audit"
compiled_mods: set[str] = set()
for guard in audit_guards:
mod_name = Path(guard.target_file).stem
if mod_name not in compiled_mods:
comp = _compile_module(
lean_bin,
tb_src_dir,
mod_name,
tb_olean_dir,
lean_path=[],
timeout_sec=timeout_sec,
)
if comp.returncode != 0:
raise RuntimeError(
f"baseline {Path(guard.target_file).name} failed to compile:\n"
f"{comp.stdout}\n{comp.stderr}"
)
compiled_mods.add(mod_name)
check_dir = base_path / f"base_{guard.guard_id}"
check_dir.mkdir()
rc, parsed, out = _run_audit_headers(
lean_bin,
tb_olean_dir,
sysroot,
guard.negative_source,
check_dir,
module_name=mod_name,
timeout_sec=timeout_sec,
)
if not (
rc == 1
and isinstance(parsed, dict)
and parsed.get("ok") is False
and parsed.get("category") == "policy"
):
raise RuntimeError(
f"baseline {mod_name} did not policy-reject "
f"{guard.guard_id}: rc={rc} parsed={parsed!r} out={out}"
)
spec_reqs: dict[str, dict[str, object]] = {}
target_reqs: dict[str, dict[str, object]] = {}
audit_reqs: dict[str, dict[str, object]] = {}
if boundary_guards:
if "TrustedBoundary" not in compiled_mods:
comp = _compile_module(
lean_bin,
tb_src_dir,
"TrustedBoundary",
tb_olean_dir,
lean_path=[],
timeout_sec=timeout_sec,
)
if comp.returncode != 0:
raise RuntimeError(
"baseline TrustedBoundary.lean failed to compile:\n"
f"{comp.stdout}\n{comp.stderr}"
)
compiled_mods.add("TrustedBoundary")
fixtures_root = base_path / "boundary_fixtures"
fixtures_root.mkdir()
spec_reqs, target_reqs, audit_reqs = _build_boundary_fixtures(
anneal_root=anneal_root,
lean_bin=lean_bin,
tb_olean_dir=tb_olean_dir,
sysroot=sysroot,
fixtures_root=fixtures_root,
timeout_sec=timeout_sec,
)
for sanity_name, sanity_req in (
("spec_sanity", spec_reqs["spec_sanity"]),
("target_sanity", target_reqs["target_sanity"]),
("audit_sanity", audit_reqs["audit_sanity"]),
):
s_dir = base_path / f"base_{sanity_name}"
s_dir.mkdir()
s_rc, s_parsed, s_out = _run_tb_request(
lean_bin,
tb_olean_dir,
sanity_req,
s_dir,
tag=sanity_name,
timeout_sec=timeout_sec,
)
if (
s_rc != 0
or not isinstance(s_parsed, dict)
or s_parsed.get("ok") is not True
):
raise RuntimeError(
f"baseline boundary sanity {sanity_name} failed: "
f"rc={s_rc} parsed={s_parsed!r} out={s_out}"
)
for guard in boundary_guards:
req_map = (
spec_reqs
if guard.mode == "spec-preflight"
else target_reqs
if guard.mode == "target-audit"
else audit_reqs
)
neg_req = req_map[guard.fixture_id]
b_dir = base_path / f"base_{guard.guard_id}"
b_dir.mkdir()
rc, parsed, out = _run_tb_request(
lean_bin,
tb_olean_dir,
neg_req,
b_dir,
tag="base_neg",
timeout_sec=timeout_sec,
)
if not (
rc == 1
and isinstance(parsed, dict)
and parsed.get("ok") is False
and parsed.get("category") == "policy"
):
raise RuntimeError(
f"baseline TrustedBoundary did not policy-reject "
f"{guard.guard_id}: rc={rc} parsed={parsed!r} "
f"out={out}"
)
baseline_sec += time.monotonic() - t_audit_base
# Cap concurrent `TrustedBoundary.lean` compilations to 2 workers
# to keep peak memory bounded on 4-vCPU CI runners.
total_tb = len(audit_guards) + len(boundary_guards)
audit_workers = max(1, min(jobs, 2, total_tb))
with ThreadPoolExecutor(max_workers=audit_workers) as pool:
if audit_guards:
future_map = {
pool.submit(
_check_one_audit_guard,
guard,
anneal_root=anneal_root,
lean_bin=lean_bin,
sysroot=sysroot,
timeout_sec=timeout_sec,
): guard
for guard in audit_guards
}
audit_by_id: dict[str, GuardResult] = {}
for fut in as_completed(future_map):
res = fut.result()
audit_by_id[res.guard_id] = res
results.extend(audit_by_id[g.guard_id] for g in audit_guards)
if boundary_guards:
b_future_map = {
pool.submit(
_check_one_boundary_guard,
guard,
anneal_root=anneal_root,
lean_bin=lean_bin,
sanity_req=(
spec_reqs["spec_sanity"]
if guard.mode == "spec-preflight"
else target_reqs["target_sanity"]
if guard.mode == "target-audit"
else audit_reqs["audit_sanity"]
),
negative_req=(
spec_reqs[guard.fixture_id]
if guard.mode == "spec-preflight"
else target_reqs[guard.fixture_id]
if guard.mode == "target-audit"
else audit_reqs[guard.fixture_id]
),
timeout_sec=timeout_sec,
): guard
for guard in boundary_guards
}
boundary_by_id: dict[str, GuardResult] = {}
for fut in as_completed(b_future_map):
res = fut.result()
boundary_by_id[res.guard_id] = res
results.extend(
boundary_by_id[g.guard_id] for g in boundary_guards
)
# --------------------------------------------------------------
# Suite 4: trusted/rustc-capture/src/ extraction & profile guards
# --------------------------------------------------------------
if extract_guards:
if lean_only:
print(
"NOTE: skipping extract_guards suite (--lean-only "
"requested)",
file=sys.stderr,
)
skipped_suites.append("extract_guards")
toolchain = None
else:
toolchain = _resolve_extract_toolchain(
anneal_root, rustc_bin, timeout_sec
)
if toolchain is None:
if (
suite == "extract_guards"
or rustc_bin is not None
or not need_lean
):
raise RuntimeError(
"pinned nightly rustc with rustc-dev (matching "
"trusted/rustc-capture/src/ir.rs COMPILER_COMMIT) "
"and cargo on an x86_64-unknown-linux-gnu host "
"are required for extract_guards; pass --rustc "
"<path> or set RUSTC"
)
print(
"NOTE: skipping extract_guards suite (pinned "
"x86_64-unknown-linux-gnu nightly rustc with "
"rustc-dev not available in environment)",
file=sys.stderr,
)
skipped_suites.append("extract_guards")
if toolchain is not None:
r_bin, c_bin, r_sysroot, host_triple = toolchain
t_ext_base = time.monotonic()
need_capture = any(g.mode == "capture" for g in extract_guards)
need_unit = any(g.mode == "unit" for g in extract_guards)
base_target_dir = base_path / "extract_target"
cap_bin, unit_bin, deps_dirs, extern_rlibs = (
_build_extract_baseline(
anneal_root=anneal_root,
rustc_bin=r_bin,
cargo_bin=c_bin,
sysroot=r_sysroot,
host_triple=host_triple,
base_target_dir=base_target_dir,
need_capture=need_capture,
need_unit=need_unit,
timeout_sec=timeout_sec,
)
)
ext_env = _extract_subprocess_env(
r_bin, r_sysroot, base_target_dir, host_triple
)
if need_unit:
assert unit_bin is not None
needed_tests = sorted(
{
t
for g in extract_guards
if g.mode == "unit"
for t in (g.sanity_unit_test, g.unit_test_name)
}
)
for test_name in needed_tests:
u_rc, u_out = _run_extract_unit_test(
unit_bin,
test_name,
work_dir=base_target_dir,
env=ext_env,
timeout_sec=timeout_sec,
)
if u_rc != 0 or "1 passed; 0 failed" not in u_out:
raise RuntimeError(
f"baseline rustc-capture unit test {test_name} "
f"failed (rc={u_rc}):\n{u_out[-500:]}"
)
if need_capture:
assert cap_bin is not None
ext_base_work = base_path / "extract_base_work"
ext_base_work.mkdir()
for s_scope in sorted(
{
"crate" if g.capture_scope == "crate" else "select"
for g in extract_guards
if g.mode == "capture"
}
):
s_rc, s_parsed, s_out = _run_extract_capture(
cap_bin,
EXTRACT_POSITIVE_SANITY_SOURCE,
capture_scope=s_scope,
select_root="selected",
instantiate_json="",
work_dir=ext_base_work,
tag=f"sanity_{s_scope}",
sysroot=r_sysroot,
host_triple=host_triple,
env=ext_env,
timeout_sec=timeout_sec,
)
if (
s_rc != 0
or not isinstance(s_parsed, dict)
or s_parsed.get("status") != "captured"
):
raise RuntimeError(
f"baseline capture sanity ({s_scope}) failed "
f"(rc={s_rc}, parsed={s_parsed!r}):\n"
f"{s_out[-400:]}"
)
if any(
g.exclude_traits
for g in extract_guards
if g.mode == "capture"
):
x_rc, x_parsed, x_out = _run_extract_capture(
cap_bin,
EXCLUDE_TRAIT_POSITIVE_SANITY_SOURCE,
capture_scope="crate",
select_root="selected",
instantiate_json="",
exclude_traits=EXCLUDE_TRAIT_POSITIVE_SANITY_TRAITS,
work_dir=ext_base_work,
tag="sanity_exclude_trait",
sysroot=r_sysroot,
host_triple=host_triple,
env=ext_env,
timeout_sec=timeout_sec,
)
if (
x_rc != 0
or not isinstance(x_parsed, dict)
or x_parsed.get("status") != "captured"
):
raise RuntimeError(
"baseline capture sanity (exclude-trait) failed "
f"(rc={x_rc}, parsed={x_parsed!r}):\n"
f"{x_out[-400:]}"
)
capture_guards = [
g for g in extract_guards if g.mode == "capture"
]
base_workers = max(1, min(jobs, len(capture_guards)))
def _verify_base_capture(guard: ExtractGuard) -> None:
b_rc, b_parsed, b_out = _run_extract_capture(
cap_bin,
guard.negative_source,
capture_scope=guard.capture_scope,
select_root=guard.select_root,
instantiate_json=guard.instantiate_json,
allow_unstable_features=guard.allow_unstable_features,
stdlib_crate=guard.stdlib_crate,
panic_strategy=guard.panic_strategy,
exclude_traits=guard.exclude_traits,
work_dir=ext_base_work,
tag=f"neg_{guard.guard_id}",
sysroot=r_sysroot,
host_triple=host_triple,
env=ext_env,
timeout_sec=timeout_sec,
)
b_status = (
b_parsed.get("status")
if isinstance(b_parsed, dict)
else None
)
b_diag = _extract_diag_text(b_parsed)
if b_rc != 1 or b_status != guard.expected_baseline_status:
raise RuntimeError(
f"baseline anneal-rustc-capture did not "
f"reject {guard.guard_id} with exit code 1 "
f"and status "
f"{guard.expected_baseline_status!r} "
f"(rc={b_rc}, status={b_status!r}):\n"
f"{b_out[-400:]}"
)
diag_haystack = (
b_out
if guard.expected_baseline_status == "compiler_failed"
else b_diag
)
if (
guard.expected_baseline_diagnostic
and guard.expected_baseline_diagnostic
not in diag_haystack
):
raise RuntimeError(
f"baseline rejection for {guard.guard_id} "
f"lacked expected diagnostic "
f"{guard.expected_baseline_diagnostic!r}; "
f"got: {diag_haystack[:300]!r}"
)
with ThreadPoolExecutor(max_workers=base_workers) as pool:
futs = [
pool.submit(_verify_base_capture, g)
for g in capture_guards
]
for fut in as_completed(futs):
fut.result()
baseline_sec += time.monotonic() - t_ext_base
ext_workers = max(1, min(jobs, len(extract_guards)))
with ThreadPoolExecutor(max_workers=ext_workers) as pool:
e_future_map = {
pool.submit(
_check_one_extract_guard,
guard,
anneal_root=anneal_root,
rustc_bin=r_bin,
sysroot=r_sysroot,
host_triple=host_triple,
deps_dirs=deps_dirs,
extern_rlibs=extern_rlibs,
timeout_sec=timeout_sec,
): guard
for guard in extract_guards
}
ext_by_id: dict[str, GuardResult] = {}
for fut in as_completed(e_future_map):
res = fut.result()
ext_by_id[res.guard_id] = res
results.extend(ext_by_id[g.guard_id] for g in extract_guards)
total = len(results)
killed = sum(1 for r in results if r.status == "KILLED")
survived = sum(1 for r in results if r.status == "SURVIVED")
errors = sum(1 for r in results if r.status == "ERROR")
report: dict[str, object] = {
"total": total,
"killed": killed,
"survived": survived,
"errors": errors,
"kill_rate_pct": (100.0 * killed / total) if total else 0.0,
"baseline_sec": round(baseline_sec, 3),
"total_sec": round(time.monotonic() - t_start, 3),
"skipped_suites": skipped_suites,
"skipped_reason": (
"--lean-only requested"
if lean_only and skipped_suites
else ("toolchain unavailable" if skipped_suites else None)
),
"results": [asdict(r) for r in results],
}
if shard is not None:
report["shard"] = f"{shard[0]}/{shard[1]}"
return report
def _default_anneal_root() -> Path:
return Path(__file__).resolve().parent.parent
def _resolve_lean_binary(explicit: str | Path | None) -> Path:
if explicit is not None:
cand = _resolve_executable_token(explicit)
if cand is None:
raise SystemExit(f"Lean binary not found: {explicit}")
return cand
env_lean = os.environ.get("ANNEAL_LEAN")
if env_lean:
cand = _resolve_executable_token(env_lean)
if cand is not None:
return cand
found = shutil.which("lean")
if found:
return Path(os.path.abspath(found))
raise SystemExit(
"Lean binary not specified; pass --lean <path> or set ANNEAL_LEAN"
)
def _format_summary(report: dict[str, object]) -> str:
lines: list[str] = []
for entry in report["results"]: # type: ignore[index]
lines.append(
f"[{entry['status']:8s}] ({entry['suite']:14s}) "
f"{entry['guard_id']:42s} {entry['duration_sec']:5.2f}s "
f"{entry['detail']}"
)
skipped = report.get("skipped_suites")
if isinstance(skipped, list) and skipped:
reason = report.get("skipped_reason") or "toolchain unavailable"
lines.append(f"Skipped suites ({reason}): {', '.join(skipped)}")
lines.append(
f"Guard-mutation summary: {report['killed']}/{report['total']} killed "
f"({report['kill_rate_pct']:.1f}%), {report['survived']} survived, "
f"{report['errors']} errors "
f"(baseline {report['baseline_sec']:.2f}s, total {report['total_sec']:.2f}s)"
)
return "\n".join(lines)
def main(argv: list[str] | None = None) -> int:
parser = argparse.ArgumentParser(
description=(
"Run single-guard mutation checks against Trusted/MirSemantics/, "
"TrustedBoundary.lean, and trusted/rustc-capture/src/."
)
)
parser.add_argument(
"--anneal-root",
type=Path,
default=_default_anneal_root(),
help="Path to the `anneal/` directory (defaults to script parent).",
)
parser.add_argument(
"--lean",
type=str,
default=None,
help="Path to the pinned `lean` executable (falls back to ANNEAL_LEAN / PATH).",
)
parser.add_argument(
"--rustc",
type=str,
default=None,
help=(
"Path to the pinned nightly `rustc` with `rustc-dev` for "
"extract_guards (falls back to RUSTC / PATH)."
),
)
parser.add_argument(
"--suite",
choices=(
"all",
"mir_semantics",
"audit_headers",
"audit_boundary",
"extract_guards",
),
default="all",
help="Which guard-mutation suite(s) to execute.",
)
parser.add_argument(
"--filter",
dest="name_filter",
default=None,
help="Optional substring filter on guard_id.",
)
parser.add_argument(
"--jobs",
type=int,
default=min(4, os.cpu_count() or 1),
help="Maximum parallel worker threads (default: min(4, CPU count)).",
)
parser.add_argument(
"--timeout-sec",
type=int,
default=60,
help="Per-invocation timeout in seconds (default: 60).",
)
parser.add_argument(
"--json-out",
type=Path,
default=None,
help="Optional file path to write the structured JSON report.",
)
parser.add_argument(
"--lean-only",
action="store_true",
help=(
"Execute only the Lean suites (mir_semantics, audit_headers, "
"audit_boundary) without probing rustc or reading "
"trusted/rustc-capture/src/."
),
)
parser.add_argument(
"--shard",
type=str,
default=None,
help=(
"Optional 1-based `<index>/<total>` deterministic round-robin shard "
"partition applied independently within each selected suite."
),
)
parser.add_argument(
"--list",
action="store_true",
help="Validate static catalog invariants, list all guards, and exit.",
)
args = parser.parse_args(argv)
shard: tuple[int, int] | None = None
if args.shard is not None:
try:
shard = _parse_shard_spec(args.shard)
except ValueError as exc:
print(f"ERROR: {exc}", file=sys.stderr)
return 2
anneal_root = Path(os.path.abspath(args.anneal_root))
json_out = (
Path(os.path.abspath(args.json_out))
if args.json_out is not None
else None
)
if args.list:
if args.lean_only and args.suite == "extract_guards":
print(
"ERROR: --lean-only cannot be combined with "
"--suite extract_guards",
file=sys.stderr,
)
return 1
errors = validate_catalog_invariants(
anneal_root, lean_only=args.lean_only
)
if errors:
for err in errors:
print(f"ERROR: {err}", file=sys.stderr)
return 1
mir_guards, audit_guards, boundary_guards, extract_guards = (
_select_guards(args.suite, args.name_filter, shard=shard)
)
if args.lean_only:
extract_guards = []
total = (
len(mir_guards)
+ len(audit_guards)
+ len(boundary_guards)
+ len(extract_guards)
)
if total == 0:
print(
f"ERROR: no guards matched suite={args.suite!r} "
f"filter={args.name_filter!r} shard={args.shard!r}",
file=sys.stderr,
)
return 1
for g in mir_guards:
print(f"mir_semantics {g.guard_id:42s} {g.target_file}")
for g in audit_guards:
print(f"audit_headers {g.guard_id:42s} {g.target_file}")
for g in boundary_guards:
print(f"audit_boundary {g.guard_id:42s} {g.target_file}")
for g in extract_guards:
print(f"extract_guards {g.guard_id:42s} {g.target_file}")
print(f"Total cataloged guards: {total}")
return 0
mir_g, audit_g, boundary_g, _ = _select_guards(
args.suite, args.name_filter, shard=shard
)
need_lean = bool(mir_g or audit_g or boundary_g)
lean_bin = _resolve_lean_binary(args.lean) if need_lean else None
try:
report = run_guard_mutation_suite(
anneal_root=anneal_root,
lean_bin=lean_bin,
rustc_bin=args.rustc,
suite=args.suite,
lean_only=args.lean_only,
name_filter=args.name_filter,
shard=shard,
jobs=args.jobs,
timeout_sec=args.timeout_sec,
)
except (RuntimeError, subprocess.SubprocessError) as exc:
print(f"FAIL: {exc}", file=sys.stderr)
return 1
print(_format_summary(report))
if json_out is not None:
json_out.parent.mkdir(parents=True, exist_ok=True)
json_out.write_text(
json.dumps(report, indent=2) + "\n", encoding="utf-8"
)
if report["killed"] != report["total"] or report["errors"] != 0:
return 1
return 0
if __name__ == "__main__":
sys.exit(main())