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

Restructure Definitions and Assigns in preparation for writing to arr… #28526

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

mikebenfield
Copy link
Collaborator

Restructure Definitions and Assigns in preparation for writing to arrays, etc.

Specifically:

  • AssociatedConstant and AssociatedFunction are moved out of AccessExpression to become variants of Expression.

  • A new type DefinitionPlace is the place in a DefinitionStatement.

  • ConstantDeclaration is gone - Definition can handle its case.

  • SSA pass now produces Definitions instead of Assigns.

  • The Place in an AssignStatement is now an Identifier. (In the future it will become a new type, capable of handling writes to arrays, structs, and tuples.)

@mikebenfield mikebenfield requested a review from d0cd March 12, 2025 20:08
@mikebenfield mikebenfield force-pushed the restructure-defs-public branch 2 times, most recently from 0295f6e to 69b0e45 Compare March 13, 2025 15:44
@mikebenfield
Copy link
Collaborator Author

Oh also the commit message is backward - I didn't remove ConstDeclaration; I removed the ability of DefinitionStatement to handle consts. I'll fix that later.

}

fn visit_assign(&mut self, _input: &'a AssignStatement) -> String {
panic!("DefinitionStatement's should not exist in SSA form.")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
panic!("DefinitionStatement's should not exist in SSA form.")
panic!("AssignStatement's should not exist in SSA form.")

@@ -35,8 +35,8 @@ impl Assigner {

/// Constructs the assignment statement `place = expr;`.
/// This function should be the only place where `AssignStatement`s are constructed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// This function should be the only place where `AssignStatement`s are constructed.
/// This function should be the only place where `DefinitionStatement`s are constructed.

@@ -57,12 +57,13 @@ impl AssignerInner {

/// Constructs the assignment statement `place = expr;`.
/// This function should be the only place where `AssignStatement`s are constructed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// This function should be the only place where `AssignStatement`s are constructed.
/// This function should be the only place where `DefinitionStatement`s are constructed.

fn reconstruct_definition(&mut self, _: DefinitionStatement) -> (Statement, Self::AdditionalOutput) {
unreachable!("`DefinitionStatement`s should not exist in the AST at this phase of compilation.")
fn reconstruct_definition(&mut self, mut input: DefinitionStatement) -> (Statement, Self::AdditionalOutput) {
// Check the lhs of the assignment to see any of variables are used.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Check the lhs of the assignment to see any of variables are used.
// Check the lhs of the definition to see any of variables are used.

@@ -1,14 +1,8 @@
namespace = "Compile"
expectation = "Fail"
outputs = ["""
Error [ETYC0372000]: invalid assignment target
--> compiler-test:5:9
Error [EPAR0370005]: expected ; -- found '='
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way this error can be made more informative?

Copy link
Collaborator

@d0cd d0cd left a comment

Choose a reason for hiding this comment

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

Overall, these changes look good to me since the compiled programs do not change. Left a couple of nits. Before merging, it would be good to verify that the documentation is consistent with the new AST.

@mikebenfield
Copy link
Collaborator Author

Which documentation? You're referring to comments in the code?

@mikebenfield mikebenfield force-pushed the restructure-defs-public branch from 80a6ff2 to 1cb7dc3 Compare March 25, 2025 15:59
…ays, etc.

Specifically:

- AssociatedConstant and AssociatedFunction are moved out of AccessExpression to
become variants of Expression.

- A new type DefinitionPlace is the place in a DefinitionStatement.

- ConstantDeclaration is gone - Definition can handle its case.

- SSA pass now produces Definitions instead of Assigns.

- The Place in an AssignStatement is now an Identifier.
(In the future it will become a new type, capable of handling writes to arrays,
structs, and tuples.)
@mikebenfield mikebenfield force-pushed the restructure-defs-public branch from 1cb7dc3 to 4834474 Compare March 25, 2025 16:40
@mikebenfield mikebenfield merged commit e6aa4e6 into mainnet Mar 25, 2025
9 checks passed
@mikebenfield mikebenfield deleted the restructure-defs-public branch March 25, 2025 18:58
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.

2 participants