This page documents Regula 4.34.0. The latest release is Regula 0.11.1: this page in Regula 0.11.1.
RG1006: Unsafe and partial declarations require exact helper authentication
- Category Declaration
- Scope declaration
- Subreason
escape-hatch
An owned declaration is marked unsafe or partial and is not the exactly authenticated code-generation helper of a safe recursive definition.
What to do. Write a safe, terminating definition (structural recursion or termination_by), or move the unsafe/partial code out of the claimed surface.
- Requirement
- Claimed modules declare nothing
unsafeorpartial; recursion is structural or proved terminating. - Reported in
- Enforcement
- Strict, like every rule: see how rules are enforced.
Checked example
Violating input
Fixture.leansource examples/rules/RG1006/Violation.lean/-! # Identity
Identity on natural numbers. -/
/-- The identity function on natural numbers. -/
unsafe def identity (n : Nat) : Nat := n
Findings of the violating run
RG1006 error violation fresh file, claim kernel-only
Declaration identity at Fixture.lean, line 5, column 12
identity (def) [unsafe] type=Nat โ Nat axioms=[] -> kernel-onlyCorrection
Fixture.lean /-! # Identity
Identity on natural numbers. -/
/-- The identity function on natural numbers. -/
- unsafe def identity (n : Nat) : Nat := n
+ def identity (n : Nat) : Nat := n
Fixture.leansource examples/rules/RG1006/Fixed.lean/-! # Identity
Identity on natural numbers. -/
/-- The identity function on natural numbers. -/
def identity (n : Nat) : Nat := n
The correction keeps identity's domain and body and removes the unnecessary unsafe marker.
Checked by a fresh single-file audit of <example>/Fixture.lean (axiomGate --file, claim kernel-only, execution checked): violating run rejected, corrected run completed.
How to fix it
-
Remove an unnecessary
unsafemarker. -
Replace
partial defby a definition with structural recursion or atermination_bymeasure anddecreasing_byproof. -
If the computation must stay unsafe or partial, move it to a separate, unclaimed dependency package; a claimed module cannot import an excluded module of its own package (RG2004). Where a claimed executable reaches it, it is reported as a trusted
unsafe-computationorpartial-computationboundary, which fails under checked execution (RG3002).
Why it matters
A positive proof surface must consist of kernel-checked definitions. Unsafe and partial code can be executed, but it cannot serve as logical evidence, and reasoning about it silently depends on its runtime behavior.
What triggers it
Authored unsafe and partial declarations are escape hatches: an unsafe declaration is checked only in Lean's unsafe mode, cannot be used by safe declarations or proofs and is not replayed as logical evidence, and a partial definition has no termination proof. They are rejected with applicability escape-hatch.
The only exception is the range-less partial helper Lean generates for a safe, termination-checked recursive def, admitted when every condition of standard ยง7.4 holds, including fresh-frontend attribution of the exact source.
Required proof shape
A total replacement keeps the same domain and result type; if it changes behavior, state and prove the relation to the intended function.
What a passing result establishes
No authored unsafe or partial declaration is on the claimed surface; every admitted generated helper satisfied all ยง7.4 conditions.
It does not establish:
-
That unsafe or partial code elsewhere is logically unsound; the rule concerns evidence, not a claim that such code is wrong.
-
Termination proofs' adequacy for cost claims.
It leaves these review obligations open: R-QUALIFY, R-COST, R-INTENT.
Configuration and exceptions
partial_fixpoint helpers are not covered by the recursive-helper exception.
Limitations and unsupported cases
The helper exception is conservative: elaborators defined in the audited module, run_tac or by_elab in the recursion's proofs make the checker reject a definition Lean accepts.
Editor feedback may be pending until the project command completes the fresh-frontend check.
Sources
- Normative clauses
- standard ยง7.4 Inventory Every Owned Declaration
- Checklist rows
COMP-02,THEOREM-05,THEOREM-01,DECL-03,BUILD-01- Detector, policy and proof sources
lean/RegulaPolicy/Decision.lean,lean/Regula/Checker/Frontend.lean,lean/RegulaCore/Policy.lean- Proved linkage
- The shared declaration decision
RegulaPolicy.declarationFailure(its first failed requirement,declarationFailure_ordered) is mapped to a rule by the injectiveRegula.ruleForFailure. Project, file and documentation audits run it throughRegula.Checker.Policy.checked_memberRule(ruleForMember_eq); the editor runsRegula.Linter.checked_editorDecision. For the same member and request, the editor passes exactly when the project decision selects no rule (Regula.Checker.Policy.editor_decision_none_iff), a rule it renders is the project decision's rule (editor_decision_rule), and a pending result withholds a project rule whose failure needs generated-role evidence (editor_decision_pending). The editor's request domain is the project's without teaching (editor_request_sound,editor_request_complete). The observed declaration fields and generated-role evidence are hypotheses of these theorems.RegulaPolicy.authorizedUnsafeRecHelpers_iffcharacterizes the authenticated recursion helpers.