Split Assign into local variable and field assignment#20
Draft
keyboardDrummer-bot wants to merge 2 commits intomainfrom
Draft
Split Assign into local variable and field assignment#20keyboardDrummer-bot wants to merge 2 commits intomainfrom
keyboardDrummer-bot wants to merge 2 commits intomainfrom
Conversation
Add a new FieldAssign constructor to StmtExpr that takes a target expression, a member Identifier, and a value. The existing Assign constructor now only accepts Identifier LHS targets. Previously, field assignments were represented as Assign [FieldSelect target member] value, requiring pattern matching on the target list to distinguish field writes from local variable assignments. The new FieldAssign constructor makes this distinction explicit in the type. Closes #19
Owner
|
@keyboardDrummer-bot can the assign constructor be And once you have that, can we also enable this multi assign in the grammar? |
…n grammar rule
- Assign constructor now takes (targets : List (AstNode Identifier)) instead of
(targets : List (AstNode StmtExpr)), enforcing at the type level that assign
targets are identifiers (not arbitrary expressions).
- Added multiAssign grammar rule: (a, b) := value for multi-target assignments.
Single-target assign still uses: a := value.
- Updated all passes to work with the new target type:
- Passes that recursed into targets (MapStmtExpr, FilterPrelude, Resolution,
CoreGroupingAndOrdering, TypeHierarchy, HeapParameterization) no longer need
to since targets are just identifiers.
- LaurelToCoreTranslator, ConstrainedTypeElim, LiftImperativeExpressions,
InferHoleTypes simplified by accessing .val directly as Identifier.
- PythonToLaurel updated to construct AstNode Identifier targets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #19
Summary
Adds a new
FieldAssignconstructor toStmtExprfor field assignments, separating them from local variable assignments, and strengthens theAssignconstructor to only acceptIdentifiertargets:Previously, field assignments were represented as
Assign [FieldSelect target member] value, requiring pattern matching on the target list to distinguish field writes from local variable assignments. The newFieldAssignconstructor makes this distinction explicit in the type, andAssigntargets are nowList (AstNode Identifier)instead ofList (AstNode StmtExpr), enforcing at the type level that assign targets are identifiers.Grammar
a := value(a, b) := value(newmultiAssignrule)obj#field := value(parsed viaassign+fieldAccess, translated toFieldAssign)Changes
Core type change (
Laurel.lean):Assignnow takesList (AstNode Identifier)targets (wasList (AstNode StmtExpr))FieldAssigntakes atarget: AstNode StmtExprandmember: IdentifierGrammar (
LaurelGrammar.st):multiAssignrule for(targets) := valuesyntaxParser (
ConcreteToAbstractTreeTranslator.lean):assignextracts the identifier name from the target, or producesFieldAssignfor field access targetsmultiAssignparses comma-separated identifiersPrinter (
AbstractToConcreteTreeTranslator.lean):Assignprints asassign(identifier, value)Assignprints asmultiAssign(targets, value)FieldAssignprints asassign(fieldAccess(target, member), value)All Laurel passes: Updated to work with
AstNode Identifiertargets. Passes that previously recursed into targets (MapStmtExpr, FilterPrelude, Resolution, CoreGroupingAndOrdering, TypeHierarchy, HeapParameterization) no longer need to since targets are just identifiers.Python frontend (
PythonToLaurel.lean):AstNode Identifiertargets forAssignFieldAssignTesting
All existing tests pass (the only failure is the pre-existing
StrataTest.DDM.Integration.Java.TestGenwhich requires a missing jar file).