Skip to content
Draft
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
1 change: 1 addition & 0 deletions Strata.lean
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Strata.Util.Sarif
/- Strata Core -/
import Strata.Languages.Core.FactoryWF
import Strata.Languages.Core.StatementSemantics
import Strata.Languages.Core.Core
import Strata.Languages.Core.SarifOutput

/- Code Transforms -/
Expand Down
6 changes: 5 additions & 1 deletion Strata/Backends/CBMC/GOTO/SourceLocation.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module

import Lean.Data.Json
public import Lean.Data.Json

public section
namespace CProverGOTO
-------------------------------------------------------------------------------

Expand All @@ -28,3 +30,5 @@ instance : ToString SourceLocation where
else s!"{loc.file}:{loc.line}:{loc.column}"

-------------------------------------------------------------------------------
end CProverGOTO
end
3 changes: 3 additions & 0 deletions Strata/DDM/Integration/Categories.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module

public import Strata.DDM.AST
public import Std.Data.HashSet.Basic

public section
namespace Strata.DDM.Integration
Expand Down Expand Up @@ -34,3 +36,4 @@ def abstractCategories : Std.HashSet QualifiedIdent := Std.HashSet.ofList [
]

end Strata.DDM.Integration
end
9 changes: 4 additions & 5 deletions Strata/DL/Imperative/EvalError.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@

SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module



import Strata.DL.Imperative.PureExpr
public import Strata.DL.Imperative.PureExpr

namespace Imperative
open Std (ToFormat Format format)
Expand All @@ -17,7 +16,7 @@ open Std (ToFormat Format format)
`EvalError` denotes the kinds of errors that may arise during (partial)
evaluation of Imperative programs.
-/
inductive EvalError (P : PureExpr) where
public inductive EvalError (P : PureExpr) where
| InitVarExists (tid : P.TypedIdent) (existing_value : P.Expr)
| AssignVarNotExists (tid : P.Ident) (value : P.Expr)
| HavocVarNotExists (tid : P.Ident)
Expand Down Expand Up @@ -49,7 +48,7 @@ def EvalError.toFormat [ToFormat P.Expr] [ToFormat P.Ident] [ToFormat P.Ty]
instance [ToFormat P.Expr] [ToFormat P.Ident] [ToFormat P.Ty] : ToFormat (EvalError P) where
format := EvalError.toFormat

inductive EvalWarning (P : PureExpr) where
public inductive EvalWarning (P : PureExpr) where
| AssumeFail (label : String) (b : P.Expr)

def EvalWarning.toFormat [ToFormat P.Expr] [ToFormat P.Ident] [ToFormat P.Ty]
Expand Down
7 changes: 6 additions & 1 deletion Strata/DL/Imperative/HasVars.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@

SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module

import Strata.DL.Imperative.PureExpr
public import Strata.DL.Imperative.PureExpr

public section

namespace Imperative

Expand Down Expand Up @@ -46,3 +49,5 @@ class HasVarsTrans
abbrev HasVarsProcTrans (P : PureExpr) (PT : Type) := HasVarsTrans P PT PT

end Imperative

end
5 changes: 4 additions & 1 deletion Strata/DL/Imperative/PureExpr.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module


public section

namespace Imperative

Expand Down Expand Up @@ -64,3 +65,5 @@ class HasBoolVal (P : PureExpr) [HasBool P] [HasVal P] where
bool_is_val : (@HasVal.value P) HasBool.tt ∧ (@HasVal.value P) HasBool.ff

end Imperative

end
3 changes: 2 additions & 1 deletion Strata/DL/Lambda/MetaData.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module

namespace Lambda
/--
Expand All @@ -11,7 +12,7 @@ Metadata annotations.
[Stopgap] We will eventually design a structured metadata language that we will
modify along with our code transformation functions.
-/
structure Info where
public structure Info where
value : String
deriving DecidableEq, Repr

Expand Down
5 changes: 3 additions & 2 deletions Strata/DL/SMT/Basic.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@

SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module

@[inline] def BitVec.width {n : Nat} (_ : BitVec n) : Nat := n
@[inline] public def BitVec.width {n : Nat} (_ : BitVec n) : Nat := n

def BitVec.signedMin (n : Nat) : Int := - 2 ^ (n-1)

def BitVec.signedMax (n : Nat) : Int := 2 ^ (n-1) - 1

def BitVec.overflows (n : Nat) (i : Int) : Bool :=
public def BitVec.overflows (n : Nat) (i : Int) : Bool :=
i < (BitVec.signedMin n) ||
i > (BitVec.signedMax n)
10 changes: 5 additions & 5 deletions Strata/DL/SMT/CexParser.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
SPDX-License-Identifier: Apache-2.0 OR MIT
-/


module

import Std.Internal.Parsec.String

Expand All @@ -15,7 +15,7 @@ open Std (Format ToFormat format)
Represents a key-value pair, representing the value of a variable (key) in a
counterexample.
-/
structure KeyValue where
public structure KeyValue where
key: String
value: String
deriving Repr
Expand All @@ -24,11 +24,11 @@ instance : ToFormat KeyValue where
format kv := f!"({kv.key} {kv.value})"

/-- Represents a counterexample as a list of key-value pairs -/
structure CEx where
public structure CEx where
pairs: List KeyValue
deriving Repr

def CEx.format (cex : CEx) : Format :=
public def CEx.format (cex : CEx) : Format :=
go cex.pairs
where go pairs :=
match pairs with
Expand Down Expand Up @@ -90,7 +90,7 @@ def parseCEx1 : Parser CEx := do
ws
return { pairs := [] }))

def parseCEx (cex : String) : Except Format CEx :=
public def parseCEx (cex : String) : Except Format CEx :=
match parseCEx1 ⟨cex, cex.startValidPos⟩ with
| Std.Internal.Parsec.ParseResult.success _ result => Except.ok result
| Std.Internal.Parsec.ParseResult.error ⟨_, pos⟩ msg => Except.error s!"Parse error at {pos.offset}: {msg}"
Expand Down
20 changes: 17 additions & 3 deletions Strata/DL/SMT/Solver.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
SPDX-License-Identifier: Apache-2.0 OR MIT
-/

module

/-!
Based on Cedar's Term language.
(https://github.com/cedar-policy/cedar-spec/blob/main/cedar-lean/Cedar/SymCC/Solver.lean)
Expand All @@ -15,7 +17,7 @@ s-expressions encoded as strings. The interface is based on

namespace Strata.SMT

inductive Decision where
public inductive Decision where
| sat
| unsat
| unknown
Expand All @@ -31,16 +33,18 @@ deriving DecidableEq, Repr
each command. We don't have an error stream here, since we configure solvers to
run in quiet mode and not print anything to the error stream.
-/
structure Solver where
public structure Solver where
smtLibInput : IO.FS.Stream
smtLibOutput : Option IO.FS.Stream

abbrev SolverM (α) := ReaderT Solver IO α
public abbrev SolverM (α) := ReaderT Solver IO α

def SolverM.run (solver : Solver) (x : SolverM α) : IO α := ReaderT.run x solver

namespace Solver

public section

/--
Returns a Solver for the given path and arguments. This function expects
`path` to point to an SMT solver executable, and `args` to specify valid
Expand Down Expand Up @@ -84,12 +88,16 @@ def fileWriter (h : IO.FS.Handle) : IO Solver :=
def bufferWriter (b : IO.Ref IO.FS.Stream.Buffer) : IO Solver :=
return ⟨IO.FS.Stream.ofBuffer b, .none⟩

end

private def emitln (str : String) : SolverM Unit := do
-- dbg_trace "{str}" -- uncomment to see input sent to the solver
let solver ← read
solver.smtLibInput.putStr s!"{str}\n"
solver.smtLibInput.flush

public section

def setLogic (logic : String) : SolverM Unit :=
emitln s!"(set-logic {logic})"

Expand Down Expand Up @@ -145,11 +153,15 @@ def declareDatatypes (dts : List (String × List String × List String)) : Solve
let bodyStr := String.intercalate "\n " bodies
emitln s!"(declare-datatypes ({sortDeclStr})\n ({bodyStr}))"

end

private def readlnD (dflt : String) : SolverM String := do
match (← read).smtLibOutput with
| .some stdout => stdout.getLine
| .none => pure dflt

public section

def checkSat (vars : List String) : SolverM Decision := do
emitln "(check-sat)"
let result := (← readlnD "unknown").trim
Expand All @@ -171,6 +183,8 @@ def reset : SolverM Unit :=
def exit : SolverM Unit :=
emitln "(exit)"

end

end Solver

end Strata.SMT
3 changes: 3 additions & 0 deletions Strata/DL/SMT/TermType.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module

/-!
Based on Cedar's Term language.
Expand All @@ -11,6 +12,7 @@ This file defines the types of Terms. See `Term.lean` for the
definition of the Term language.
-/

public section
namespace Strata.SMT

inductive TermPrimType where
Expand Down Expand Up @@ -191,3 +193,4 @@ def TermType.isConstrType : TermType → Bool
| _ => false

end Strata.SMT
end
17 changes: 9 additions & 8 deletions Strata/DL/Util/Counter.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module

/-! ## Counter Generator
This file contains a counter generator `genCounter`, as well as its underlying
Expand All @@ -20,35 +21,35 @@

namespace Counter

structure CounterState where
public structure CounterState where
counter : Nat := 0
generated : List Nat := [] -- a set of numbers generated by the generator

instance : HasSubset CounterState where
public instance : HasSubset CounterState where
Subset σ₁ σ₂ := σ₁.generated.Subset σ₂.generated

@[simp]
def CounterState.emp : CounterState := { counter := 0, generated := [] }
public def CounterState.emp : CounterState := { counter := 0, generated := [] }

def WF (σ : CounterState)
public def WF (σ : CounterState)
:= (∀ c, c ∈ σ.generated → c < σ.counter)
∧ σ.generated.Nodup

def genCounter (σ : CounterState)
public def genCounter (σ : CounterState)
: Nat × CounterState
:= (σ.counter, { σ with
counter := σ.counter + 1,
generated := σ.counter :: σ.generated
})

theorem genCounterSubset : genCounter σ = (n, σ') → σ ⊆ σ' := by
public theorem genCounterSubset : genCounter σ = (n, σ') → σ ⊆ σ' := by
intros Hgen
simp [genCounter] at Hgen
simp [← Hgen, HasSubset.Subset]
intros a Hin
simp_all

theorem genCounterContains :
public theorem genCounterContains :
genCounter σ = (n, σ') →
n ∈ σ'.generated := by
intros Hgen
Expand All @@ -66,7 +67,7 @@ theorem genCounterValue :
theorem emptyCounterWF :
WF .emp := by simp [WF]

theorem genCounterWFMono :
public theorem genCounterWFMono :
WF σ →
genCounter σ = (n, σ') →
WF σ' := by
Expand Down
3 changes: 2 additions & 1 deletion Strata/DL/Util/DecidableEq.lean
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

SPDX-License-Identifier: Apache-2.0 OR MIT
-/
module

def beq_eq_DecidableEq
public def beq_eq_DecidableEq
{T : Type}
(beq : T → T → Bool)
(beq_eq : (x1 x2 : T) → beq x1 x2 = true ↔ x1 = x2) :
Expand Down
Loading
Loading