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

Very simple revamp of dead code elimination. #28507

Open
wants to merge 1 commit into
base: revise-testing
Choose a base branch
from

Conversation

mikebenfield
Copy link
Collaborator

Enable DCE by default. Eliminates useless
associated function calls.

Also threw in just a few changes to Display
implementations for some nodes.

Fixes #28504

@mikebenfield mikebenfield requested a review from d0cd February 11, 2025 21:35
@mikebenfield mikebenfield force-pushed the dead-code-class branch 3 times, most recently from 2867c59 to 460bc34 Compare February 12, 2025 18:18
@mikebenfield
Copy link
Collaborator Author

Alright see what you think of these changes. Also eliminates a couple new calls, in

non_async_after_complex_async.leo and expr_statement.leo

@mikebenfield mikebenfield force-pushed the dead-code-class branch 2 times, most recently from b1201cb to e49b6f3 Compare February 20, 2025 20:03
Some(expression) => Some(self.reconstruct_expression(expression).0),
None => Some(self.reconstruct_expression(Expression::Identifier(member.identifier)).0),
},
expression: member.expression.map(|expr| self.reconstruct_expression(expr).0),
Copy link
Collaborator

Choose a reason for hiding this comment

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

In the None case, the identifier is the expression. Would the new code skip that case? Maybe it makes sense to reorganize the StructVariableInitializer so that identifier is optional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems to me there actually is no decent way to handle this to cover every circumstance. Indeed identifier may be the expression, but in such a case, depending on what the pass is doing, it may want to leave member as None, or it may want to make a new member.

/// The set of used variables in the current function body.
pub(crate) used_variables: IndexSet<Symbol>,
/// Whether or not the variables are necessary.
pub(crate) is_necessary: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm for removing the pattern where we set is_necessary. It looks like instead we use the traversal to add used variables. Are we sure that there are not defaults in the traversal that might add something unwanted or skip something we'd want?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I don't believe so - if we're visiting an expression, we do want to visit every subexpression of it, and we do explicitly control when we visit expressions via StatementReconstructor

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.

The test build options are defined here. Note that for most tests, they are disabled. If DCE is now enabled by default, it might be worth adding more comprehensive tests to ensure correctness. If it's looking like it would be a heavy lift, another option is to not enable DCE just yet, and only fold in the refactorings in this PR.

@mikebenfield mikebenfield force-pushed the dead-code-class branch 2 times, most recently from bab0381 to fcb14ea Compare March 6, 2025 22:33
@mikebenfield mikebenfield added the blocked Blocked. label Mar 6, 2025
@mikebenfield
Copy link
Collaborator Author

Alright so here's what we discussed - don't eliminate any operations that may halt.

@mikebenfield mikebenfield removed the blocked Blocked. label Mar 11, 2025
@mikebenfield
Copy link
Collaborator Author

We actually probably want to wait a bit before merging this. There is a discussion here about which hash and commit functions may halt, and we likely want to know the outcome of that discussion so we know specifically which functions we consider side effect free.

Enable DCE by default. Eliminates useless
associated function calls.

Also threw in just a few changes to Display
implementations for some nodes.

Fixes #28504
@mikebenfield mikebenfield changed the base branch from mainnet to revise-testing March 26, 2025 19:30
@mikebenfield
Copy link
Collaborator Author

Alright, this should be ready to go now - it's confirmed that all hash functions except the Pedersen ones work for all inputs. I've rebased and now the base branch is revise-testing, to reduce big test diffs.

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.

[Bug] some dead Aleo Instructions code
2 participants