Skip to content

Commit

Permalink
change Subsmap to map to Partial.Expr (#362)
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Disselkoen <[email protected]>
  • Loading branch information
cdisselkoen authored Jun 14, 2024
1 parent 3ece1e2 commit 84e328e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 5 additions & 5 deletions cedar-lean/Cedar/Partial/Request.lean
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,18 @@ open Cedar.Data
open Cedar.Spec (EntityUID)

/--
Given a map of unknown-name to value, substitute the unknown in `UidOrUnknown`
if possible. If the `UidOrUnknown` is already known, or it's an unknown that doesn't
have a mapping in `subsmap`, return it unchanged.
Given a `Subsmap`, substitute the unknown in `UidOrUnknown` if possible. If
the `UidOrUnknown` is already known, or it's an unknown that doesn't have a
mapping in `subsmap`, return it unchanged.
Returns `none` if the substitution is invalid -- e.g., if trying to substitute
a non-`EntityUID` into `UidOrUnknown`.
-/
def UidOrUnknown.subst (subsmap : Subsmap) : UidOrUnknown → Option UidOrUnknown
| .known uid => some (.known uid)
| .unknown unk => match subsmap.m.find? unk with
| some (.value (.prim (.entityUID uid))) => some (.known uid)
| some (.residual (.unknown unk')) => some (.unknown unk') -- substituting an unknown with another unknown, we'll allow it
| some (.lit (.entityUID uid)) => some (.known uid)
| some (.unknown unk') => some (.unknown unk') -- substituting an unknown with another unknown, we'll allow it
| none => some (.unknown unk) -- no substitution available, return `unk` unchanged
| _ => none -- substitution is not for a literal UID or literal unknown. Not valid, return none

Expand Down
7 changes: 4 additions & 3 deletions cedar-lean/Cedar/Partial/Value.lean
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ instance : Coe Spec.Value Partial.Value where
coe := Partial.Value.value

/--
Defines a mapping from unknowns to values, for use in a substitution.
Defines a mapping from unknowns to the `Partial.Expr`s to replace them with
during a substitution.
-/
structure Subsmap where
m : Map Unknown Partial.Value
m : Map Unknown Partial.Expr

/--
Given a map of unknown-name to value, substitute all unknowns with the
Expand All @@ -66,7 +67,7 @@ def Expr.subst (subsmap : Subsmap) : Partial.Expr → Partial.Expr
| .record pairs => .record (pairs.attach₂.map λ ⟨(k, v), _⟩ => (k, v.subst subsmap))
| .call xfn xs => .call xfn (xs.map₁ λ ⟨x, _⟩ => x.subst subsmap)
| .unknown u => match subsmap.m.find? u with
| some val => val.asPartialExpr
| some x => x
| none => .unknown u -- no substitution available

/--
Expand Down

0 comments on commit 84e328e

Please sign in to comment.