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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions StrataBoole/Verify.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions StrataBooleTest.lean
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
75 changes: 75 additions & 0 deletions StrataBooleTest/unsupported_global.lean
Original file line number Diff line number Diff line change
@@ -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
Loading