Skip to content

Use schema in TPE to reduce has/hasTag/in/==/is - #997

Open
john-h-kastner-aws wants to merge 1 commit into
mainfrom
tpe-has-reduction-proof
Open

Use schema in TPE to reduce has/hasTag/in/==/is#997
john-h-kastner-aws wants to merge 1 commit into
mainfrom
tpe-has-reduction-proof

Conversation

@john-h-kastner-aws

@john-h-kastner-aws john-h-kastner-aws commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Extends the TPE model so that has, hasTag, in, ==, and is reduce to literals when type information in the schema (plus error-freedom) is enough to reach a concrete value.

Large diff because TPE.evaluate now needs a schema.

Key changes addings this functions with calls at appropriate sites.

/-- Does the schema prove that applying this operation to types `ty₁` and `ty₂` must produce `false`? -/
def mustBeFalse (env : TypeEnv) (op₂ : BinaryOp) (ty₁ ty₂ : CedarType) : Bool :=
  match op₂, ty₁, ty₂ with
  | .mem, .entity ety₁, .entity ety₂
  | .mem, .entity ety₁, .set (.entity ety₂) => !env.descendentOf ety₁ ety₂
  | .eq,  .entity ety₁, .entity ety₂        => ety₁ != ety₂
  | .hasTag, .entity ety, .string           => env.ets.tags? ety == some .none
  | _, _, _                                 => false
/-- Does the schema prove that a value of type `ty₁` cannot have attribute `a`? -/
def cannotHaveAttr (env : TypeEnv) (ty₁ : CedarType) (a : Attr) : Bool :=
  match ty₁ with
  | .record rty => (rty.find? a).isNone
  | .entity ety =>
    match env.ets.attrs? ety with
    | .some rty => (rty.find? a).isNone
    | .none     => false
  | _ => false

Issue #, if available:

Description of changes:

@john-h-kastner-aws
john-h-kastner-aws requested a review from luxas July 29, 2026 17:09
Extends the TPE model so that `has`, `hasTag`, `in`, `==`, and `is`
reduce to literals when type information in the schema (plus
error-freedom) is enought to reach a concrete value.

Signed-off-by: jkastner <jkastner@amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant