Skip to content

Introduce remove_unused_params pass, to run just before zombie removal. #715

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

Merged
merged 4 commits into from
Aug 10, 2021
Merged

Introduce remove_unused_params pass, to run just before zombie removal. #715

merged 4 commits into from
Aug 10, 2021

Conversation

eddyb
Copy link
Contributor

@eddyb eddyb commented Aug 10, 2021

By removing (transitively) dead fn parameters, this PR also removes their matching arguments, which could be invalid (i.e. zombies).

The main usecase is #[track_caller], which is becoming more prevalent in core.
The added test fails before this PR with:

error: constant arrays/structs cannot contain pointers to other constants
  --> $DIR/track_caller.rs:16:5
   |
16 |     track_caller_maybe_panic(x);
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: Stack:
           track_caller::main
           Unnamed function ID %17

This allows updating past rust-lang/rust#86664 (which gets transitively called from mem::replace).

Also, I tried using this to remove our hardcoded panic hacks, but it's not compatible with -C debuginfo=2 (even if the %x.dbg.spill stack slots have no debuginfo attached, they're still created and stored to, so they get in the way).

@eddyb eddyb requested a review from khyperia August 10, 2021 08:42
@eddyb eddyb enabled auto-merge (rebase) August 10, 2021 08:52
.iter()
.map(|inst| inst.result_type.unwrap())
.collect();
let new_func_type = builder.type_function(return_type, new_param_types);
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrmpf. O(n^2) linear search here for dedup isn't great, but I guess it's fine, usually not many functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

"usually not many" - famous last words ;)

@eddyb eddyb merged commit 7f5e2e7 into EmbarkStudios:main Aug 10, 2021
@eddyb eddyb deleted the dezombie-dead-params branch August 10, 2021 09:46
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.

3 participants