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

Move monomorphize::resolve() to librustc #44896

Merged
merged 12 commits into from
Oct 3, 2017

Conversation

qmx
Copy link
Member

@qmx qmx commented Sep 28, 2017

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?

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

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

result
}


Copy link
Member

Choose a reason for hiding this comment

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

Two unnecessary empty lines.

get_fn(ccx, ty::Instance::resolve(ccx.tcx(),
ty::ParamEnv::empty(traits::Reveal::All),
def_id,
substs).unwrap())
Copy link
Member

@eddyb eddyb Sep 28, 2017

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.

(Some(ty::Instance::resolve(bcx.ccx.tcx(),
ty::ParamEnv::empty(traits::Reveal::All),
def_id,
substs).unwrap()),
Copy link
Member

Choose a reason for hiding this comment

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

Same indentation problem here.

let instance = ty::Instance::resolve(ccx.tcx(),
ty::ParamEnv::empty(traits::Reveal::All),
def_id,
substs).unwrap();
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

@alexcrichton alexcrichton added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 28, 2017
Copy link
Contributor

@nikomatsakis nikomatsakis left a 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. =)

@@ -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(),
Copy link
Contributor

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.)


/// The point where linking happens. Resolve a (def_id, substs)
/// pair to an instance.
pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>,
Copy link
Contributor

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.

Copy link
Contributor

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.

@@ -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.
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 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`.

substs: rcvr_substs
})
}
_ => {
Copy link
Contributor

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 }.

// These are both the same at trans time.
Ok(true)
}
_ => Err(()),
Copy link
Contributor

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(())

ccx.tcx(),
ty::ParamEnv::empty(traits::Reveal::All),
def_id,
substs,)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra comma

@arielb1
Copy link
Contributor

arielb1 commented Sep 30, 2017

r+ with stray comma fixed

@qmx
Copy link
Member Author

qmx commented Sep 30, 2017

@arielb1 there you go - I could swear I've fixed before :/

@@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

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

still a stray comma,

@arielb1
Copy link
Contributor

arielb1 commented Oct 1, 2017

@bors r+

@bors
Copy link
Contributor

bors commented Oct 1, 2017

📌 Commit 11e141e has been approved by arielb1

@bors
Copy link
Contributor

bors commented Oct 1, 2017

⌛ Testing commit 11e141e with merge 8e8b47f5c004d8f30dc4bb65cc60206ec2a81b88...

@bors
Copy link
Contributor

bors commented Oct 1, 2017

💔 Test failed - status-appveyor

@aidanhs
Copy link
Member

aidanhs commented Oct 2, 2017

@bors retry

#43402

@bors
Copy link
Contributor

bors commented Oct 2, 2017

⌛ Testing commit 11e141e with merge fa1d352c7c162da84114bbd4ab58edff3368ceff...

@bors
Copy link
Contributor

bors commented Oct 2, 2017

💔 Test failed - status-travis

@sfackler
Copy link
Member

sfackler commented Oct 2, 2017

@bors retry

@bors
Copy link
Contributor

bors commented Oct 3, 2017

⌛ Testing commit 11e141e with merge 6c39ff409c79d5d4acc5025988a45d10359189e6...

@bors
Copy link
Contributor

bors commented Oct 3, 2017

💔 Test failed - status-appveyor

@qmx
Copy link
Member Author

qmx commented Oct 3, 2017

Apparently, this is failing on a completely unrelated thing - test suite runs cleanly locally :(

@arielb1
Copy link
Contributor

arielb1 commented Oct 3, 2017

@bors
Copy link
Contributor

bors commented Oct 3, 2017

⌛ Testing commit 11e141e with merge 8891044...

bors added a commit that referenced this pull request Oct 3, 2017
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?
@bors
Copy link
Contributor

bors commented Oct 3, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing 8891044 to master...

@bors bors merged commit 11e141e into rust-lang:master Oct 3, 2017
@qmx qmx deleted the move-resolve-to-librustc branch October 3, 2017 15:01
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants