diff --git a/StrataBoole/Verify.lean b/StrataBoole/Verify.lean index 940ab27..bbcf244 100644 --- a/StrataBoole/Verify.lean +++ b/StrataBoole/Verify.lean @@ -1178,12 +1178,9 @@ def toCoreProgram (p : Boole.Program) (gctx : GlobalContext := {}) (fileName : S let mut modMap : Std.HashMap String (List (Core.Expression.Ident × Lambda.LMonoTy)) := {} for cmd in cmds do match cmd with - | .command_var _ b => - match b with - | .bind_mk _ ⟨_, n⟩ _ ty => - match (toCoreMonoType ty).run' { gctx := gctx } with - | .ok mty => varTypes := varTypes.insert n mty - | .error _ => pure () + | .command_var _ (.bind_mk _ ⟨_, n⟩ _ ty) => + let mty ← (toCoreMonoType ty).run' { fileName := fileName, gctx := gctx } + varTypes := varTypes.insert n mty | .boole_procedure _ nameAnn _ _ _ _ specAnn _ => let mods ← collectModifiesFromSpec fileName nameAnn.val specAnn.val varTypes if !mods.isEmpty then modMap := modMap.insert nameAnn.val mods diff --git a/StrataBooleTest.lean b/StrataBooleTest.lean index fe4c6d3..9c12693 100644 --- a/StrataBooleTest.lean +++ b/StrataBooleTest.lean @@ -24,6 +24,7 @@ import StrataBooleTest.lemmas_and_axioms import StrataBooleTest.local_functions import StrataBooleTest.nat_detection import StrataBooleTest.global_readonly_call +import StrataBooleTest.unsupported_global import StrataBooleTest.grammar_extensions import StrataBooleTest.insertion_sort import StrataBooleTest.loop_simple diff --git a/StrataBooleTest/unsupported_global.lean b/StrataBooleTest/unsupported_global.lean new file mode 100644 index 0000000..270a29a --- /dev/null +++ b/StrataBooleTest/unsupported_global.lean @@ -0,0 +1,75 @@ +/- + Copyright Strata Contributors + + SPDX-License-Identifier: Apache-2.0 OR MIT +-/ + +import StrataBoole.MetaVerifier + +/-! +# Unsupported global types must fail lowering + +Boole encodes each top-level `var` as an implicit parameter of every +procedure. The only place that registers those globals is the pre-pass in +`toCoreProgram`: it lowers the declared type with `toCoreMonoType` and inserts +the name into `globalVarTypes`. + +The old pre-pass discarded a type-lowering error and continued. An unused +`var g : real` therefore produced a Core program whose procedures had no `g` +parameter — the same Core shape as a program that never declared `g`. The +pre-pass now propagates that error, so lowering fails at the declaration. + +The empty procedure is intentional. The body never mentions `g`, so no later +check can mask a silent drop; the only evidence of retention is the Core +parameter list. +-/ + +namespace Strata + +/-- Parse and lower a Boole program; surface the diagnostic as a string. -/ +private def lower (p : StrataDDM.Program) : Except String Core.Program := do + let prog ← (Boole.getProgram p).mapError toString + (Boole.toCoreProgram prog p.globalContext).mapError fun e => + toString (e.format none) + +/-! ## Rejection: a global whose type Core cannot lower -/ + +-- `g` is unused. Before the fix, lowering succeeded and `noop` had no inputs. +private def unusedRealGlobal := +#strata +program Boole; +var g : real; +procedure noop() returns () {}; +#end + +-- Keep only the stable part of the diagnostic: source ranges shift with edits. +/-- info: Except.error "Unsupported Boole type" -/ +#guard_msgs in +#eval show Except String Unit from + match lower unusedRealGlobal with + | .error e => + if (e.splitOn "Unsupported Boole type").length > 1 then + .error "Unsupported Boole type" + else + .error e + | .ok _ => .ok () + +/-! ## Retention: the same shape with a supported type -/ + +-- Same unused global and empty procedure. `int` lowers, so `g` is registered +-- and appears as a read-only input of every procedure — including this one. +private def unusedIntGlobal := +#strata +program Boole; +var g : int; +procedure noop() returns () {}; +#end + +/-- info: Except.ok ["g"] -/ +#guard_msgs in +#eval show Except String (List String) from do + let cp ← lower unusedIntGlobal + let some proc := cp.findProcByString? "noop" | .error "missing noop" + return proc.header.inputs.toList.map fun (id, _) => id.name + +end Strata