-
Notifications
You must be signed in to change notification settings - Fork 13k
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
minor refactorings around InferCtxt::enter
#49020
Closed
nikomatsakis
wants to merge
5
commits into
rust-lang:master
from
nikomatsakis:chalkify-cleanup-enter-sig
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d5d5f59
do not give ownership of the `InferCtxt` away
nikomatsakis e5bbb5d
modernize the `enter` signature
nikomatsakis f1f209d
remove `'tcx` from signature of `InferCtxtBuilder` and friends
nikomatsakis c850274
adopt `impl Trait` for `tls::enter`
nikomatsakis 84252f6
make Inherited builder give by reference
nikomatsakis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -189,7 +189,7 @@ impl<'a, 'tcx> MaybeInProgressTables<'a, 'tcx> { | |
/// `bar()` will each have their own `FnCtxt`, but they will | ||
/// share the inherited fields. | ||
pub struct Inherited<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { | ||
infcx: InferCtxt<'a, 'gcx, 'tcx>, | ||
infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why the extra indirection? |
||
|
||
tables: MaybeInProgressTables<'a, 'tcx>, | ||
|
||
|
@@ -587,14 +587,14 @@ impl<'a, 'gcx, 'tcx> Deref for FnCtxt<'a, 'gcx, 'tcx> { | |
/// Helper type of a temporary returned by Inherited::build(...). | ||
/// Necessary because we can't write the following bound: | ||
/// F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(Inherited<'b, 'gcx, 'tcx>). | ||
pub struct InheritedBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { | ||
infcx: infer::InferCtxtBuilder<'a, 'gcx, 'tcx>, | ||
pub struct InheritedBuilder<'a, 'gcx: 'a> { | ||
infcx: infer::InferCtxtBuilder<'a, 'gcx>, | ||
def_id: DefId, | ||
} | ||
|
||
impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> { | ||
pub fn build(tcx: TyCtxt<'a, 'gcx, 'gcx>, def_id: DefId) | ||
-> InheritedBuilder<'a, 'gcx, 'tcx> { | ||
-> InheritedBuilder<'a, 'gcx> { | ||
let hir_id_root = if def_id.is_local() { | ||
let node_id = tcx.hir.as_local_node_id(def_id).unwrap(); | ||
let hir_id = tcx.hir.definitions().node_to_hir_id(node_id); | ||
|
@@ -610,17 +610,18 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> { | |
} | ||
} | ||
|
||
impl<'a, 'gcx, 'tcx> InheritedBuilder<'a, 'gcx, 'tcx> { | ||
fn enter<F, R>(&'tcx mut self, f: F) -> R | ||
where F: for<'b> FnOnce(Inherited<'b, 'gcx, 'tcx>) -> R | ||
{ | ||
impl<'a, 'gcx> InheritedBuilder<'a, 'gcx> { | ||
fn enter<'tcx, R>( | ||
&'tcx mut self, | ||
f: impl FnOnce(&Inherited<'_, 'gcx, 'tcx>) -> R, | ||
) -> R { | ||
let def_id = self.def_id; | ||
self.infcx.enter(|infcx| f(Inherited::new(infcx, def_id))) | ||
self.infcx.enter(|infcx| f(&Inherited::new(infcx, def_id))) | ||
} | ||
} | ||
|
||
impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> { | ||
fn new(infcx: InferCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> Self { | ||
fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> Self { | ||
let tcx = infcx.tcx; | ||
let item_id = tcx.hir.as_local_node_id(def_id); | ||
let body_id = item_id.and_then(|id| tcx.hir.maybe_body_owned_by(id)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it started here - why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can revert that part if you like -- I was actually working towards a goal with this patch series that didn't work out, so it's not really important either way (I just figured I'd land some of the incidental changes).
That said, I always get annoyed that enter gives me ownership of an
InferCtxt
, when almost everything wants a reference. I'd be quite surprised if the indrection aroundInherited
cost performance.