-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Move monomorphize::resolve() to librustc #44896
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc/ty/instance.rs
Outdated
result | ||
} | ||
|
||
|
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.
Two unnecessary empty lines.
src/librustc_trans/callee.rs
Outdated
get_fn(ccx, ty::Instance::resolve(ccx.tcx(), | ||
ty::ParamEnv::empty(traits::Reveal::All), | ||
def_id, | ||
substs).unwrap()) |
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.
The indentation here is off - it should be at least once to the right for the 3 above lines.
src/librustc_trans/mir/block.rs
Outdated
(Some(ty::Instance::resolve(bcx.ccx.tcx(), | ||
ty::ParamEnv::empty(traits::Reveal::All), | ||
def_id, | ||
substs).unwrap()), |
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.
Same indentation problem here.
src/librustc_trans/mir/constant.rs
Outdated
let instance = ty::Instance::resolve(ccx.tcx(), | ||
ty::ParamEnv::empty(traits::Reveal::All), | ||
def_id, | ||
substs).unwrap(); |
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.
Same here.
9789b66
to
9e24115
Compare
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.
OK I left a few thoughts. Most some pre-existing nits that aren't your fault, but which I would like to see fixed. The other question in my mind is whether to make this a query. We probably need some more guidelines on that point. =)
src/librustc_trans/callee.rs
Outdated
@@ -179,5 +180,8 @@ pub fn resolve_and_get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, | |||
substs: &'tcx Substs<'tcx>) | |||
-> ValueRef | |||
{ | |||
get_fn(ccx, monomorphize::resolve(ccx.tcx(), def_id, substs)) | |||
get_fn(ccx, ty::Instance::resolve(ccx.tcx(), |
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.
Nit: I try not to be a stickler on formatting (rustfmt can't come soon enough), but I find this particular line rather hard to parse. It looks to my eye like the lines below are additional arguments to get_fn
. I'd prefer to see ty::Instance::resolve
on a line of its own, and its arguments indented relative to it.
For example, you might do something like:
get_fn(
ccx,
ty::Instance::resolve(
ccx.tcx(),
ty::ParamEnv::empty(traits::Reveal::All),
def_id,
substs,
).unwrap(),
)
(I believe this is roughly what rustfmt would do here.)
src/librustc/ty/instance.rs
Outdated
|
||
/// The point where linking happens. Resolve a (def_id, substs) | ||
/// pair to an instance. | ||
pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>, |
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 wonder if this should be a query. Seems like a handy thing to cache.
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.
If we did make it a query, I'd prefer to see the provider moved into traits/instance
or something.
src/librustc/ty/instance.rs
Outdated
@@ -111,4 +115,192 @@ impl<'a, 'b, 'tcx> Instance<'tcx> { | |||
pub fn def_id(&self) -> DefId { | |||
self.def.def_id() | |||
} | |||
|
|||
/// The point where linking happens. Resolve a (def_id, substs) | |||
/// pair to an instance. |
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 think this comment could say a lot more. Example:
// Resolve a (def_id, substs) pair to an (optional) instance -- most commonly,
// this is used to find the precise code that will run for a trait method invocation,
// if known.
//
// Returns `None` if we cannot resolve `Instance` to a specific instance.
// For example, in a context like this,
//
// ```
// fn foo<T: Debug>(t: T) { ... }
// ```
//
// trying to resolve `Debug::fmt` applied to `T` will yield `None`, because we do not
// know what code ought to run. (Note that this setting is also affected by the
// `RevealMode` in the parameter environment.)
//
// Presuming that coherence and type-check have succeeded, if this method is invoked
// in a monomorphic context (i.e., like during trans), then it is guaranteed to return
// `Some`.
src/librustc/ty/instance.rs
Outdated
substs: rcvr_substs | ||
}) | ||
} | ||
_ => { |
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.
This is pre-existing, but I would rather see this match be made exhaustive. My usual rule of thumb is this:
If a new variant is added to
traits::Vtable
, how likely is that this code will have to be changed?
If the answer is anything other than "rather unlikely", the match should be exhaustive. Here I would say the answer is "very likely".
To make it exhaustive, I would probably remove the if
clauses from the various arms, and move them into the body. e.g., if Some(trait_id) == clone_trait { ... } else { None }
.
src/librustc/ty/instance.rs
Outdated
// These are both the same at trans time. | ||
Ok(true) | ||
} | ||
_ => Err(()), |
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.
Also pre-existing, but I would make this exhaustive by adding variants like:
(ty::ClosureKind::FnMut, _) |
(ty::ClosureKind::FnOnce, _) => Err(())
6028d9c
to
a29c770
Compare
src/librustc_trans/callee.rs
Outdated
ccx.tcx(), | ||
ty::ParamEnv::empty(traits::Reveal::All), | ||
def_id, | ||
substs,) |
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.
nit: extra comma
r+ with stray comma fixed |
@arielb1 there you go - I could swear I've fixed before :/ |
src/librustc_trans/callee.rs
Outdated
@@ -186,7 +186,7 @@ pub fn resolve_and_get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, | |||
ccx.tcx(), | |||
ty::ParamEnv::empty(traits::Reveal::All), | |||
def_id, | |||
substs,) | |||
.unwrap() | |||
substs, |
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.
still a stray comma,
@bors r+ |
📌 Commit 11e141e has been approved by |
⌛ Testing commit 11e141e with merge 8e8b47f5c004d8f30dc4bb65cc60206ec2a81b88... |
💔 Test failed - status-appveyor |
⌛ Testing commit 11e141e with merge fa1d352c7c162da84114bbd4ab58edff3368ceff... |
💔 Test failed - status-travis |
@bors retry |
⌛ Testing commit 11e141e with merge 6c39ff409c79d5d4acc5025988a45d10359189e6... |
💔 Test failed - status-appveyor |
Apparently, this is failing on a completely unrelated thing - test suite runs cleanly locally :( |
Move monomorphize::resolve() to librustc this moves `monomorphize::resolve(..)` to librustc, and re-enables inlining for some trait methods, fixing #44389 @nikomatsakis I've kept the calls to the new `ty::Instance::resolve(....)` always `.unwrap()`-ing for the moment, how/do you want to add more debugging info via `.unwrap_or()` or something like this? we still have some related `resolve_*` functions on monomorphize, but I wasn't sure moving them was into the scope for this PR too. @eddyb mind to take a look too?
☀️ Test successful - status-appveyor, status-travis |
this moves
monomorphize::resolve(..)
to librustc, and re-enables inlining for some trait methods, fixing #44389@nikomatsakis I've kept the calls to the new
ty::Instance::resolve(....)
always.unwrap()
-ing for the moment, how/do you want to add more debugging info via.unwrap_or()
or something like this?we still have some related
resolve_*
functions on monomorphize, but I wasn't sure moving them was into the scope for this PR too.@eddyb mind to take a look too?