-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Soft casting with if/is
#959
Merged
Merged
Commits on Jun 25, 2024
-
Configuration menu - View commit details
-
Copy full SHA for f6f5443 - Browse repository at this point
Copy the full SHA f6f5443View commit details -
This commit introduces a new feature into the parser, typechecker, and formatter. The work for code gen will be in the next commit. I was able to leverage some existing infrastructure by making using of `AssignmentPattern`. A new field `is` was introduced into `IfBranch`. This field holds a generic `Option<Is>` meaning a new generic has to be introduced into `IfBranch`. When used in `UntypedExpr`, `IfBranch` must use `AssignmentPattern`. When used in `TypedExpr`, `IfBranch` must use `TypedPattern`. The parser was updated such that we can support this kind of psuedo grammar: `if <expr:condition> [is [<pattern>: ]<annotation>]` This can be read as, when parsing an `if` expression, always expect an expression after the keyword `if`. And then optionally there may be this `is` stuff, and within that you may optionally expect a pattern followed by a colon. We will always expect an annotation. This first expression is still saved as the field `condition` in `IfBranch`. If `pattern` is not there AND `expr:condition` is `UntypedExpr::Var` we can set the pattern to be `Pattern::Var` with the same name. From there shadowing should allow this syntax sugar to feel kinda magical within the `IfBranch` block that follow. The typechecker doesn't need to be aware of the sugar described above. The typechecker looks at `branch.is` and if it's `Some(is)` then it'll use `infer_assignment` for some help. Because of the way that `is` can inject variables into the scope of the branch's block and since it's basically just like how `expect` works minus the error we get to re-use that helper method. It's important to note that in the typechecker, if `is` is `Some(_)` then we do not enforce that `condition` is of type `Bool`. This is because the bool itself will be whether or not the `is` itself holds true given a PlutusData payload. When `is` is None, we do exactly what was being done previously so that plain `if` expressions remain unaffected with no semantic changes. The formatter had to be made aware of the new changes with some simple changes that need no further explanation.
Configuration menu - View commit details
-
Copy full SHA for 6fec3d5 - Browse repository at this point
Copy the full SHA 6fec3d5View commit details -
feat: code gen support for if/is
Co-authored-by: Kasey White <kwhitemsg@gmail.com>
Configuration menu - View commit details
-
Copy full SHA for 88ca7cc - Browse repository at this point
Copy the full SHA 88ca7ccView commit details -
Configuration menu - View commit details
-
Copy full SHA for c80ba52 - Browse repository at this point
Copy the full SHA c80ba52View commit details -
Configuration menu - View commit details
-
Copy full SHA for 654a84c - Browse repository at this point
Copy the full SHA 654a84cView commit details -
Configuration menu - View commit details
-
Copy full SHA for 497a48d - Browse repository at this point
Copy the full SHA 497a48dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 676bf44 - Browse repository at this point
Copy the full SHA 676bf44View commit details -
Configuration menu - View commit details
-
Copy full SHA for 74e1010 - Browse repository at this point
Copy the full SHA 74e1010View commit details -
Configuration menu - View commit details
-
Copy full SHA for 59ac477 - Browse repository at this point
Copy the full SHA 59ac477View commit details -
Configuration menu - View commit details
-
Copy full SHA for ffc337e - Browse repository at this point
Copy the full SHA ffc337eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 4387e78 - Browse repository at this point
Copy the full SHA 4387e78View commit details -
Configuration menu - View commit details
-
Copy full SHA for eb37371 - Browse repository at this point
Copy the full SHA eb37371View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8cb3cb3 - Browse repository at this point
Copy the full SHA 8cb3cb3View commit details -
Configuration menu - View commit details
-
Copy full SHA for defb771 - Browse repository at this point
Copy the full SHA defb771View commit details -
Fix codegen tree traversal to be updated for the otherwise field and …
…future proof the traversal function
Configuration menu - View commit details
-
Copy full SHA for b63994e - Browse repository at this point
Copy the full SHA b63994eView commit details -
Configuration menu - View commit details
-
Copy full SHA for 2a8dacd - Browse repository at this point
Copy the full SHA 2a8dacdView commit details -
Configuration menu - View commit details
-
Copy full SHA for 86df4d8 - Browse repository at this point
Copy the full SHA 86df4d8View commit details -
Configuration menu - View commit details
-
Copy full SHA for 493b053 - Browse repository at this point
Copy the full SHA 493b053View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1b1f879 - Browse repository at this point
Copy the full SHA 1b1f879View commit details
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.