Skip to content

[go1.20] Moving DCE to isolate filter naming #1337

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

Closed
wants to merge 1 commit into from

Conversation

grantnelson-wf
Copy link
Collaborator

@grantnelson-wf grantnelson-wf commented Jul 31, 2024

The dead-code elimination (DCE) code has two filter strings and dependencies as a set of strings. The strings have special meanings such as both empty strings indicate always alive. To help facilitate future changes to DCE, I'm moving the DCE code to it's own package. Also I'm making some methods to set a decl's DCE filters and deps to ensure that the names are continued to be set the same as new changes are made.

These changes should have only minor functional changes, everything should continue to function as before. These changes are mostly a minor refactor to encapsulate DCE design decisions. The CI should continue to pass.

This is related to #1270 work since the future changes to DCE is to include removal of dead generic code instantiations, e.g. allow List[int] to be alive and List[string] be dead separately.

@nevkontakte
Copy link
Member

I think I'd like to take a step further and move all DCE-related logic into a separate compiler/internal/dce package.

@grantnelson-wf grantnelson-wf marked this pull request as draft August 1, 2024 16:38
@grantnelson-wf grantnelson-wf force-pushed the encapDCE branch 3 times, most recently from 9fc41fa to e1c4f12 Compare August 1, 2024 22:21
@grantnelson-wf grantnelson-wf marked this pull request as ready for review August 1, 2024 22:22
Copy link
Member

@nevkontakte nevkontakte left a comment

Choose a reason for hiding this comment

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

I left a few suggestions, but generally I'm quite happy with this direction. Thanks!

//
// Note that calling CollectDCEDeps() inside another CollectDCEDeps() call is
// not allowed.
func (fc *funcContext) CollectDCEDeps(f func()) []string {
func (fc *funcContext) CollectDCEDeps(dce *dce.Info, f func()) {
Copy link
Member

Choose a reason for hiding this comment

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

Consider this an optional request, but I would move this method into the dce package as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved to dce.Collector

}

// SetAsAlive marks the declaration as alive, meaning it will not be eliminated.
// This must be done after the SetName method is called.
Copy link
Member

Choose a reason for hiding this comment

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

Let's make this method panic if this invariant is violated.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Instead of a panic, I made the explicitly marking as alive use an alive flag instead of clearing out the names. Now, if the names aren't set or if the alive flag is set true, the decl is alive. This allows the decl to be marked as alive before or after naming without effecting the naming.

Copy link
Member

Choose a reason for hiding this comment

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

Since we are factoring this this logic out into its own package, it would be good to add at least some rudimentary tests

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added some tests

@grantnelson-wf grantnelson-wf marked this pull request as draft August 5, 2024 21:45
@grantnelson-wf grantnelson-wf force-pushed the encapDCE branch 3 times, most recently from 6382c16 to a802b89 Compare August 8, 2024 19:11
@grantnelson-wf grantnelson-wf marked this pull request as ready for review August 8, 2024 19:16
@grantnelson-wf
Copy link
Collaborator Author

grantnelson-wf commented Aug 16, 2024

@nevkontakte and @flimzy as I've been working on the generics DCE, I've pushed a few updates to this PR, but I think it has reached a stable point where this PR (hopefully) is a good foundation to build the generics DCE off of. However, I haven't fully figured out the generics DCE yet; I just didn't want to get this out and immediately change it all for generics 😆. Anyway, I think I've address the prior change requests and this PR should be ready for review again.

It just occurred to me too. This PR is for the go1.20 branch but since a lot of the generics work is in master, should I be targeting master instead?

@grantnelson-wf
Copy link
Collaborator Author

Moving this over to master in #1339

@grantnelson-wf grantnelson-wf deleted the encapDCE branch August 22, 2024 15:51
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