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

Remove MonoItems. #112126

Closed
wants to merge 1 commit into from
Closed

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented May 31, 2023

PR #97168 was created to address this comment in record_accesses:

// We collect this into a `SmallVec` to avoid calling `is_inlining_candidate` in the lock.
// FIXME: Call `is_inlining_candidate` when pushing to `neighbors` in `collect_items_rec`
// instead to avoid creating this `SmallVec`.

It removed the need for the SmallVec (a good thing) by introducing MonoItems, which introduced some additional complexity (a bad thing).

However, the reason the SmallVec was being used in the first place -- "to avoid calling is_inlining_candidate in the lock" -- isn't necessary, as far as I can tell. Perhaps it was at one point.

So this commit just moves what is left of the call to is_inlining_candidate -- a call the innocuous instantiation_mode -- inside the lock. This avoids the complexity of MonoItems sometimes computing inlining data and sometimes not.

r? @wesleywiser

PR rust-lang#97168 was created to address this comment in `record_accesses`:

// We collect this into a `SmallVec` to avoid calling `is_inlining_candidate` in the lock.
// FIXME: Call `is_inlining_candidate` when pushing to `neighbors` in `collect_items_rec`
// instead to avoid creating this `SmallVec`.

It removed the need for the `SmallVec` (a good thing) by introducing
`MonoItems`, which introduced some additional complexity (a bad thing).

However, the reason the `SmallVec` was being used in the first place --
"to avoid calling `is_inlining_candidate` in the lock" -- isn't
necessary, as far as I can tell. Perhaps it was at one point.

So this commit just moves what is left of the call to
`is_inlining_candidate` -- a call the innocuous `instantiation_mode` --
inside the lock. This avoids the complexity of `MonoItems` sometimes
computing inlining data and sometimes not.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 31, 2023
@nnethercote
Copy link
Contributor Author

cc @SparrowLii, @cjgillot

self.targets.push(*mono_item);
if *inlined {
let is_inlined = mono_item.instantiation_mode(tcx) == InstantiationMode::LocalCopy;
Copy link
Member

@SparrowLii SparrowLii May 31, 2023

Choose a reason for hiding this comment

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

The key lies in the cost of calling instantiation_mode. Calling it within the lock will increase the locking time. It's not clear to me that if this has a noticeable effect on the efficiency of monomorphization. cc @Zoxc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The comment was added in #67756. Reviewers asked for more explanation in comments, but the PR author refused. It seems like it was for a deadlock. I ran the ui tests with the parallel front-end enabled without problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#112128 is an alternative approach that avoids the whole locking issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

instantiation_mode uses queries so it could potentially invoke a lot of the compiler (including the query deadlock handler). I'm not confident this is unproblematic here (ignoring the performance reasons to not do it). I'd rather keep code inside locks small and predictable.

@nnethercote
Copy link
Contributor Author

#112128 is a better approach.

@nnethercote nnethercote deleted the rm-MonoItems branch May 31, 2023 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants