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

Liveness analysis for everybody #77281

Merged
merged 1 commit into from
Sep 30, 2020
Merged

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Sep 27, 2020

Perform liveness analysis for every body instead of limiting it to fns.

Fixes #77169.

@rust-highfive
Copy link
Collaborator

r? @oli-obk

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 27, 2020
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

LGTM!

I don't have too much experience with this code though, so I won't r+ this myself yet

src/test/ui/consts/control-flow/drop-pass.rs Outdated Show resolved Hide resolved
@oli-obk
Copy link
Contributor

oli-obk commented Sep 28, 2020

@bors try @rust-timer queue

I don't care whether this has a perf impact, but I'd like to know before merging so we make a concious decision about it

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion

@bors
Copy link
Contributor

bors commented Sep 28, 2020

⌛ Trying commit e39c078321402714fafe8907a275515637bcfb9d with merge 775f8455dd97e8fb2f22eeb9a943bece2c4a64f4...

if let FnKind::Method(..) = fk {
let parent = self.tcx.hir().get_parent_item(id);
if let Node::ImplItem(..) = self.tcx.hir().get(hir_id) {
let parent = self.tcx.hir().get_parent_item(hir_id);
if let Some(Node::Item(i)) = self.tcx.hir().find(parent) {
if i.attrs.iter().any(|a| self.tcx.sess.check_name(a, sym::automatically_derived)) {
return;
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if the parent relation in the DefId space is set up like this, but can you try whether

if let Some(parent) = self.tcx.parent(def_id) {
    if self.tcx.has_attr(parent, sym::automatically_derived) {
        return;
    }
}

also works? If so, please use that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, that works as well.

Part of the motivation for the current form of the check was to avoid using the automatically_derived attribute if it were to occur in completely unexpected place, like a crate or a module. Should I change it anyway?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should prevent such uses via other means, but you can also add an assert_eq!(self.tcx.def_kind(parent), DefKind::Impl) before the return to make sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do not prevent such uses this right now, so I used this as a part of condition. I would like to be extra conservative about any additional uses of this attribute since I think it is stabilized unintentionally and its purpose has changed over time.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh :/ that's not great. Yea let's go with a non-panicking version for now

@bors
Copy link
Contributor

bors commented Sep 28, 2020

☀️ Try build successful - checks-actions, checks-azure
Build commit: 775f8455dd97e8fb2f22eeb9a943bece2c4a64f4 (775f8455dd97e8fb2f22eeb9a943bece2c4a64f4)

@rust-timer
Copy link
Collaborator

Queued 775f8455dd97e8fb2f22eeb9a943bece2c4a64f4 with parent 535d27a, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (775f8455dd97e8fb2f22eeb9a943bece2c4a64f4): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

@bors rollup=never

Perform liveness analysis for every body instead of limiting it to fns.
@tmiasko
Copy link
Contributor Author

tmiasko commented Sep 29, 2020

The performance impact is limited, except for the many-assoc-items benchmark which contains mostly associated consts.

To a large degree we were paying the price of the computation already. The previous code was creating variables and lives nodes for all bodies, it just didn't always run the liveness analysis. Furthermore, when the liveness analysis didn't run, the live nodes and variables were included in the analysis of a parent if any.

@oli-obk
Copy link
Contributor

oli-obk commented Sep 30, 2020

@bors r+

I was expecting some sort of perf hit on assoc const heavy code, but this is a bugfix, so let's roll with it

@bors
Copy link
Contributor

bors commented Sep 30, 2020

📌 Commit 924e8aa has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 2020
@bors
Copy link
Contributor

bors commented Sep 30, 2020

⌛ Testing commit 924e8aa with merge 939cc3e...

@bors
Copy link
Contributor

bors commented Sep 30, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: oli-obk
Pushing 939cc3e to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Sep 30, 2020
@bors bors merged commit 939cc3e into rust-lang:master Sep 30, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 30, 2020
@tmiasko tmiasko deleted the liveness-everybody branch September 30, 2020 15:10
@bors bors mentioned this pull request Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unused variables lint does not work inside an array length expression
7 participants