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

Create NormalizeTy query #44984

Merged
merged 9 commits into from
Oct 24, 2017
Merged

Create NormalizeTy query #44984

merged 9 commits into from
Oct 24, 2017

Conversation

Maaarcocr
Copy link
Contributor

As part of the effort to solve #44891, I've created the normalize_ty query.

As outlined in the issue this meant:

  • renamed normalize_associated_type() to normalize_associated_type_in()
  • created the normalize_ty query
  • substituted the use of memoize with the query

This PR is not ready. While running tests, one of the incremental ones failed. This is the error I got.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @eddyb (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@eddyb
Copy link
Member

eddyb commented Oct 2, 2017

r? @nikomatsakis

@rust-highfive rust-highfive assigned nikomatsakis and unassigned eddyb Oct 2, 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.

Looks great! I left a few minor nits.

}

/// Fully normalizes any associated types in `value`, using an
/// empty environment and `Reveal::All` mode (therefore, suitable
/// only for monomorphized code during trans, basically).
pub fn normalize_associated_type<T>(self, value: &T) -> T
pub fn normalize_associated_type_in<T>(self, value: &T) -> T
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: can we call this normalize_associated_types_in (i.e., pluralize type)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked the codebase and there already exists a function named this way, here. Would it be a problem if we had 2 different functions with the same name? (Mainly for people reading both of them).

Copy link
Member

Choose a reason for hiding this comment

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

Ideally only one of them would remain as the public API, if I'm not mistaken.

Copy link
Contributor

@nikomatsakis nikomatsakis Oct 4, 2017

Choose a reason for hiding this comment

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

Hmm. So really these functions serve two distinct roles:

  • The existing normalize_associated_types_in (implemented on Inherited) are used during type-checking, and hence may have a non-empty environment and/or inference variables. That particular one partly exists to silently register the extra obligations that comes from normalization.
  • The normalize_associated_type function in contrast is intended to be used after monomorphization, and it forces an empty environment and Reveal::All. In this mode, we don't expect extra obligations to matter to the user, so we handle them internally.

I think its pretty clear that the "naming convention" distinguishing the two is... not sufficient. </understatement>

In other parts of the code, we've used the trans_ prefix to distinguish the case of an empty environment with Reveal::All -- or at least code that runs after type-checking. @eddyb doesn't like that for the -- quite correct! -- reason that the code is generally applicable beyond trans. For example, MIR optimizations may want to use these pathways (though those may not have an empty environment, so that's slightly different).

I think a lot of this comes down to whether you are running "before" or "after" typeck -- in particular, after typeck you know that errors should not occur, which can simplify the code and function signatures in various ways. So perhaps we can call this new function normalize_associated_types_after_typeck? We could also rename the existing trans_ things in a similar vein.

Copy link
Member

Choose a reason for hiding this comment

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

Oh if one of them is only in rustc_typeck then I got confused a bit, it certainly feels like the name shows up in a few places.

How about we just propagate the ParamEnv in more places and just make sure that in rustc_trans we give a Reveal::All? That seems simpler and less headache-inducing.

Copy link
Contributor

Choose a reason for hiding this comment

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

@eddyb the signature currently is T -> T. I agree with changing it to (ParamEnv, T) -> T but that is not enough to remove the need for two functions. In particular, there are also "auxiliary obligations" and we have to decide what to do with them. The FnCtxt version ("during typeck") enrolls them into the fulfillment context. This version we are editing here solves them, assering that there are no errors (because it runs after type-check). The unifier form would probably propagate them back but nobody really wants that.

Copy link
Member

Choose a reason for hiding this comment

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

Right, then, just take a Reveal and don't put trans in the name?

Copy link
Contributor

Choose a reason for hiding this comment

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

@eddyb I don't see how that solves the problem. First off, taking a parameter environment -- not just reveal -- seems like the right thing to do (and is orthogonal from how we handle subobligations). Second, even if we just took a reveal, I still think we want a naming convention to distinguish these two cases ("expects to run after typeck" vs "does not").

Copy link
Contributor

Choose a reason for hiding this comment

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

One option would be to use a combinator approach. Something like tcx.post_typeck().normalize_associated_types_in(...)?


impl<'tcx> QueryDescription for queries::normalize_ty<'tcx> {
fn describe(_tcx: TyCtxt, _: Ty) -> String {
format!("normalising types")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: "normalizing"


fn normalize_ty_node<'tcx>(_: Ty<'tcx>) -> DepConstructor<'tcx> {
DepConstructor::NormalizeTy
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: newline at end of file

fn describe(_tcx: TyCtxt, _: Ty) -> String {
format!("normalising types")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: newline at end of file

@bors
Copy link
Contributor

bors commented Oct 4, 2017

☔ The latest upstream changes (presumably #44901) made this pull request unmergeable. Please resolve the merge conflicts.

@shepmaster shepmaster added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 6, 2017
@nikomatsakis
Copy link
Contributor

@Maaarcocr needs rebase =)

@Maaarcocr
Copy link
Contributor Author

@nikomatsakis Done 😄 were you able to understand why the error I'm experiencing is happening?

@nikomatsakis
Copy link
Contributor

@Maaarcocr yep you need to add the NormalizeTy variant into this list right here

@nikomatsakis
Copy link
Contributor

Also, before landing, we really do need to pick a name for this new function I think. I propose we use the trans_ prefix for now -- since it's already in use -- but longer term I think I want to adopt the name post_typeck, since I think that's the important invariant. Or maybe we can find a way to factor it another way so that the distinction isn't even needed.

@Maaarcocr
Copy link
Contributor Author

@nikomatsakis I have used the trans_ prefix. It seems that the failing test has be corrected now in my local setup 😄

@bors
Copy link
Contributor

bors commented Oct 12, 2017

☔ The latest upstream changes (presumably #44967) made this pull request unmergeable. Please resolve the merge conflicts.

@bors
Copy link
Contributor

bors commented Oct 13, 2017

☔ The latest upstream changes (presumably #45261) made this pull request unmergeable. Please resolve the merge conflicts.

@nikomatsakis
Copy link
Contributor

@eddyb and I were talking on IRC about following the naming scheme of fully_normalize_or_panic. I'd be happy with calling it fully_normalize_associated_types_in -- which to me implies that we will indeed process all subobligations. I'd also be happy with naming it trans_ and then converting all the trans_ functions together to adopt a different naming scheme.

@Maaarcocr
Copy link
Contributor Author

@nikomatsakis I don't have a strong preference about this. I will rebase the branch now.

@nikomatsakis
Copy link
Contributor

@Maaarcocr great! Let's go with the fully_ naming then. We can remove the other trans_ functions at some later time I guess.

@nikomatsakis
Copy link
Contributor

@Maaarcocr btw this still needs to be rebased again :(

@Maaarcocr
Copy link
Contributor Author

Maaarcocr commented Oct 16, 2017

@nikomatsakis i had a problem while rebasing (with the llvm git submodule) and asked on the main impl period lobby on Gitter. Should I ask this kind of questions on IRC to have a higher chance to get an answer?

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 16, 2017
@nikomatsakis
Copy link
Contributor

@Maaarcocr looks like an unused import

@nikomatsakis
Copy link
Contributor

[00:06:08] error: unused import: `util::common::MemoizationMap`

[00:06:08]   --> /checkout/src/librustc/traits/trans/mod.rs:25:5

[00:06:08]    |

[00:06:08] 25 | use util::common::MemoizationMap;

[00:06:08]    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

[00:06:08]    |

@bors
Copy link
Contributor

bors commented Oct 21, 2017

☔ The latest upstream changes (presumably #45381) made this pull request unmergeable. Please resolve the merge conflicts.

@Maaarcocr
Copy link
Contributor Author

@michaelwoerister thanks! It seems like now all tests are green 😄 @nikomatsakis are there any other issues that I need to solve before merging this? 😄

@michaelwoerister
Copy link
Member

@Maaarcocr Excellent :)

@kennytm kennytm added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 23, 2017
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Oct 23, 2017

📌 Commit 5c51bf5 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Oct 23, 2017

⌛ Testing commit 5c51bf5 with merge 9ba208b9896b9df8bebebd6cb322fcf09927a08c...

@bors
Copy link
Contributor

bors commented Oct 23, 2017

💔 Test failed - status-travis

@kennytm
Copy link
Member

kennytm commented Oct 24, 2017

@bors retry

macOS 3-hour timed out.

@kennytm kennytm 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 Oct 24, 2017
@bors
Copy link
Contributor

bors commented Oct 24, 2017

⌛ Testing commit 5c51bf5 with merge a789fa0...

bors added a commit that referenced this pull request Oct 24, 2017
Create NormalizeTy query

As part of the effort to solve #44891,  I've created the normalize_ty query.

As outlined in the issue this meant:

- renamed `normalize_associated_type()` to `normalize_associated_type_in()`
- created the `normalize_ty` query
- substituted the use of memoize with the query

This PR is not ready. While running tests, one of the incremental ones failed. [This](https://pastebin.com/vGhH6bv6) is the error I got.
@bors
Copy link
Contributor

bors commented Oct 24, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

None yet

9 participants