Skip to content

Commit 1596c6c

Browse files
authored
modules in Cedar.SymCC and Cedar.Thm.SymCC.Data (#895)
Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
1 parent 4134dc2 commit 1596c6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+915
-734
lines changed

cedar-lean/Cedar/Data/Int64.lean

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@ public def ofInt? (i : Int) : Option Int64 :=
4040
then .some (ofIntChecked i h)
4141
else .none
4242

43+
/-- We don't @[expose] the definition of `ofInt?`; but callers can use this
44+
theorem, which partially specifies its behavior -/
45+
public theorem ofInt?_some_iff {i : Int} :
46+
MIN ≤ i ∧ i ≤ MAX ↔ (ofInt? i).isSome
47+
:= by simp [ofInt?]
48+
49+
/-- Corollary of the above -/
50+
public theorem ofInt?_none_iff {i : Int} :
51+
i < MIN ∨ i > MAX ↔ (ofInt? i) = none
52+
:= by
53+
have h := ofInt?_some_iff (i := i)
54+
simp_all only [Option.isSome, gt_iff_lt]
55+
split at h
56+
· simp_all
57+
· by_cases i < MIN <;> simp_all
58+
4359
public def add? (i₁ i₂ : Int64) : Option Int64 := ofInt? (i₁.toInt + i₂.toInt)
4460

4561
public def sub? (i₁ i₂ : Int64) : Option Int64 := ofInt? (i₁.toInt - i₂.toInt)

cedar-lean/Cedar/Data/SizeOf.lean

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ public theorem sizeOf_lt_of_value [SizeOf α] [SizeOf β] {m : Map α β} {k :
6969
omega
7070
omega
7171

72+
public theorem sizeOf_lt_of_find? [SizeOf α] [SizeOf β] [DecidableEq α] {m : Map α β} {k : α} {v : β}
73+
(h : m.find? k = some v) :
74+
sizeOf v < sizeOf m
75+
:= by
76+
simp only [find?, toList] at h
77+
split at h <;> simp only [Option.some.injEq, reduceCtorEq] at h
78+
subst v
79+
rename_i h
80+
replace h := List.mem_of_find?_eq_some h
81+
have := List.sizeOf_lt_of_mem h
82+
simp_all only [sizeOf, Prod._sizeOf_1, _sizeOf_1]
83+
omega
84+
7285
public theorem sizeOf_lt_of_toList [SizeOf α] [SizeOf β] (m : Map α β) :
7386
sizeOf m.toList < sizeOf m
7487
:= by

cedar-lean/Cedar/Spec/Value.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ public inductive Value where
7272
| record (m : Map Attr Value)
7373
| ext (x : Ext)
7474

75+
----- SizeOf -----
76+
77+
public theorem Value.sizeOf_set' (s : Set Value) :
78+
sizeOf (Value.set s) = 1 + sizeOf s
79+
:= by simp [Value.set.sizeOf_spec]
80+
81+
public theorem Value.sizeOf_record' (m : Map Attr Value) :
82+
sizeOf (Value.record m) = 1 + sizeOf m
83+
:= by simp [Value.record.sizeOf_spec]
84+
7585
----- Coercions -----
7686

7787
@[expose]

cedar-lean/Cedar/SymCC/Authorizer.lean

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@
1414
limitations under the License.
1515
-/
1616

17+
module
18+
19+
public import Cedar.Spec
1720
import Cedar.SymCC.Enforcer
21+
public import Cedar.SymCC.Env
1822
import Cedar.SymCC.Compiler
23+
public import Cedar.SymCC.Result
1924

2025
/-!
2126
@@ -33,16 +38,18 @@ namespace Cedar.SymCC
3338

3439
open Factory Cedar.Spec
3540

36-
def compileWithEffect (effect : Effect) (policy : Policy) (εnv : SymEnv) : Result (Option Term) :=
41+
-- TODO: make `private` once files like AllowDeny.lean are made `module`s and can `import all` this file (they prove things about these functions and need access to internals in this file)
42+
public def compileWithEffect (effect : Effect) (policy : Policy) (εnv : SymEnv) : Result (Option Term) :=
3743
if policy.effect == effect
3844
then compile policy.toExpr εnv
3945
else .ok .none
4046

41-
def satisfiedPolicies (effect : Effect) (policies : Policies) (εnv : SymEnv) : Result Term := do
47+
-- TODO: make `private` once files like AllowDeny.lean are made `module`s and can `import all` this file (they prove things about these functions and need access to internals in this file)
48+
public def satisfiedPolicies (effect : Effect) (policies : Policies) (εnv : SymEnv) : Result Term := do
4249
let ts ← policies.filterMapM (compileWithEffect effect · εnv)
4350
anyTrue (eq · (someOf true)) ts
4451

45-
def isAuthorized (policies : Policies) (εnv : SymEnv) : Result Term := do
52+
public def isAuthorized (policies : Policies) (εnv : SymEnv) : Result Term := do
4653
let forbids ← satisfiedPolicies .forbid policies εnv
4754
let permits ← satisfiedPolicies .permit policies εnv
4855
and permits (not forbids)

cedar-lean/Cedar/SymCC/Compiler.lean

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
limitations under the License.
1515
-/
1616

17-
import Cedar.SymCC.Env
18-
import Cedar.SymCC.ExtFun
19-
import Cedar.SymCC.Factory
17+
module
18+
19+
public import Cedar.Spec
20+
public import Cedar.SymCC.Env
21+
public import Cedar.SymCC.ExtFun
22+
public import Cedar.SymCC.Factory -- TODO: this need not be a public import
23+
public import Cedar.SymCC.Result
2024

2125
/-!
2226
@@ -31,6 +35,8 @@ environment: using this Term for verification will neither miss bugs
3135
(soundness) nor produce false positives (completeness).
3236
-/
3337

38+
@[expose] public section -- TODO: make the public interface more granular/intentional, instead of having everything public and exposed
39+
3440
namespace Cedar.SymCC
3541

3642
open Cedar.Data Cedar.Spec Cedar.Validation

cedar-lean/Cedar/SymCC/Concretizer.lean

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@
1414
limitations under the License.
1515
-/
1616

17-
import Cedar.SymCC.Env
17+
module
18+
19+
public import Cedar.Data.SizeOf
20+
public import Cedar.Spec
21+
public import Cedar.SymCC.Env
22+
public import Cedar.SymCC.Factory -- TODO: this need not be a public import
23+
public import Cedar.SymCC.Term
1824

1925
/-!
2026
# Concretizing symbolic environments
@@ -28,6 +34,8 @@ complete.
2834
See Cedar.Thm.SymbolicCompilation for a statement of the completeness theorem.
2935
-/
3036

37+
@[expose] public section -- TODO: make the public interface more granular/intentional, instead of having everything public and exposed
38+
3139
namespace Cedar.Spec
3240

3341
open Data Spec
@@ -41,6 +49,16 @@ def Value.entityUIDs : Value → Set EntityUID
4149
| .set (Set.mk vs) => vs.mapUnion₁ (λ ⟨v, _⟩ => v.entityUIDs)
4250
| .record avs => avs.toList.mapUnion₃ (λ ⟨(_, v), _⟩ => v.entityUIDs)
4351
| .ext _ => Set.empty
52+
termination_by v => sizeOf v
53+
decreasing_by
54+
all_goals simp_wf
55+
· rename_i h
56+
have := List.sizeOf_lt_of_mem h
57+
omega
58+
· rename_i h
59+
have := Map.sizeOf_lt_of_toList avs
60+
simp at *
61+
omega
4462

4563
def Value.entityUID? : Value → Option EntityUID
4664
| .prim (.entityUID uid) => .some uid

cedar-lean/Cedar/SymCC/Data.lean

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,35 @@
1414
limitations under the License.
1515
-/
1616

17-
import Cedar.Data
17+
module
18+
19+
public import Cedar.Data
1820
import Cedar.Spec
1921

2022
/-!
2123
This file contains generic utility functions shared by `SymCC` modules.
2224
-/
2325

24-
@[inline] def BitVec.width {n : Nat} (_ : BitVec n) : Nat := n
26+
@[inline, expose] public def BitVec.width {n : Nat} (_ : BitVec n) : Nat := n
2527

26-
def BitVec.signedMin (n : Nat) : Int := - 2 ^ (n-1)
28+
public def BitVec.signedMin (n : Nat) : Int := - 2 ^ (n-1)
2729

28-
def BitVec.signedMax (n : Nat) : Int := 2 ^ (n-1) - 1
30+
public def BitVec.signedMax (n : Nat) : Int := 2 ^ (n-1) - 1
2931

30-
def BitVec.overflows (n : Nat) (i : Int) : Bool :=
32+
public def BitVec.overflows (n : Nat) (i : Int) : Bool :=
3133
i < (BitVec.signedMin n) ||
3234
i > (BitVec.signedMax n)
3335

3436
namespace Cedar.SymCC
3537

3638
open Cedar.Data
3739

38-
abbrev EntityTag (α) := Map String α
40+
public abbrev EntityTag (α) := Map String α
3941

40-
abbrev EntityTag.mk {α} (entity tag : α) : EntityTag α :=
42+
public abbrev EntityTag.mk {α} (entity tag : α) : EntityTag α :=
4143
Map.mk [("entity", entity), ("tag", tag)]
4244

43-
abbrev EntityTag.wf {α} : EntityTag α → Bool
45+
public abbrev EntityTag.wf {α} : EntityTag α → Bool
4446
| .mk _ _ => true
4547
| _ => false
4648

cedar-lean/Cedar/SymCC/Enforcer.lean

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
limitations under the License.
1515
-/
1616

17-
import Cedar.SymCC.Compiler
17+
module
18+
19+
public import Cedar.SymCC.Compiler -- TODO: this need not be a public import
1820

1921
/-!
2022
This file defines the algorithm for emitting well-formedness assumptions about
@@ -34,6 +36,8 @@ grounding procedure computes the footprint, and grounds the acyclicity and
3436
transitivity constraints on the set of entity terms in the footprint.
3537
-/
3638

39+
@[expose] public section -- TODO: make the public interface more granular/intentional, instead of having everything public and exposed
40+
3741
namespace Cedar.SymCC
3842

3943
open Cedar.Data

0 commit comments

Comments
 (0)