Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update typechecking to construct type annoted AST #504

Merged
merged 13 commits into from
Jan 7, 2025

Conversation

john-h-kastner-aws
Copy link
Contributor

Issue #, if available:

Adds a new TypedExpr type which is constructed by the updated typechecking procedure and updates the soundness proof for these changes.

Description of changes:

Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
@@ -167,7 +178,7 @@ def typeOfInₛ (ety₁ ety₂ : EntityType) (x₁ x₂ : Expr) (env : Environme
then .anyBool
else .ff

def typeOfHasTag (ety : EntityType) (x : Expr) (t : Expr) (c : Capabilities) (env : Environment) : ResultType :=
def typeOfHasTag (ety : EntityType) (x : Expr) (t : Expr) (c : Capabilities) (env : Environment) : Except TypeError (CedarType × Capabilities) :=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sad that typeOfHasTag and typeOfGetTag don't return ResultType like other typeOf functions :D

(I see below why it's done, but the asymmetry makes me sad.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about doing some renaming later. Maybe changing the alias for Except TypeError (CedarType × Capabilities) to ResultTypedExpr and keeping ResultType as Except TypeError (CedarType × Capabilities) so things look a bit more symmetric at these definitions. I like small diffs though, and that kind of blows it up.

| .entity ety =>
match env.ets.attrs? ety with
| .some rty => hasAttrInRecord rty x a c false
| .some rty => do
let (ty', c) ← hasAttrInRecord rty x a c false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern repeats a lot in the code:

do 
  let (ty, c) ← ...
  ok ty c

I might be tempted to hide it in a helper function. If we had a variant for ok that accepts a pair rather than two arguments, we could rewrite these as just one line, e.g.:

do ok (← hasAttrInRecord rty x a c false)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to do something clever here but Lean's handling of default arguments was getting in the way. Might take another look

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's fair. We can do a second pass after this one is merged.

(It all looks good / correct to me. These are just nits.)

Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
Copy link
Contributor

@cdisselkoen cdisselkoen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
Signed-off-by: John Kastner <jkastner@amazon.com>
@john-h-kastner-aws john-h-kastner-aws merged commit 7b4d013 into main Jan 7, 2025
6 checks passed
@john-h-kastner-aws
Copy link
Contributor Author

Merging this in it's current state. I'll follow up with at least another smaller PR to tidy some things up

@john-h-kastner-aws john-h-kastner-aws deleted the type_annot_ast branch January 8, 2025 18:32
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.

3 participants