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

extend stable hasher to support CanonicalTy #49091

Merged
merged 1 commit into from
Mar 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -902,13 +902,59 @@ for ty::TypeVariants<'gcx>
TyForeign(def_id) => {
def_id.hash_stable(hcx, hasher);
}
TyInfer(..) => {
bug!("ty::TypeVariants::hash_stable() - Unexpected variant {:?}.", *self)
TyInfer(infer_ty) => {
infer_ty.hash_stable(hcx, hasher);
}
}
}
}

impl_stable_hash_for!(enum ty::InferTy {
TyVar(a),
IntVar(a),
FloatVar(a),
FreshTy(a),
FreshIntTy(a),
FreshFloatTy(a),
Copy link
Member

Choose a reason for hiding this comment

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

The Fresh* variants are valid to hash?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are not confined to the local tcx:

match infer {
ty::FreshTy(_) |
ty::FreshIntTy(_) |
ty::FreshFloatTy(_) |
ty::CanonicalTy(_) => {
self.add_flags(TypeFlags::HAS_CANONICAL_VARS);
}
ty::TyVar(_) |
ty::IntVar(_) |
ty::FloatVar(_) => {
self.add_flags(TypeFlags::KEEP_IN_LOCAL_TCX)
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It just happens that we don't ever put them in query keys right now (and probably never will, but whatever).

Copy link
Contributor Author

@nikomatsakis nikomatsakis Mar 16, 2018

Choose a reason for hiding this comment

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

(To be honest, even the TyVar and so forth would be ok to hash -- in the sense that they are "stable-ish" -- it's just that it truly ought to be impossible... it would indicate some other problem if we did see them that would be worth knowing about.)

Well, I take that back. It's a bit dubious given that their meaning depends on the surrounding infcx. Anyway, ought to be impossible. =)

CanonicalTy(a),
});

impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
for ty::TyVid
{
fn hash_stable<W: StableHasherResult>(&self,
_hcx: &mut StableHashingContext<'a>,
_hasher: &mut StableHasher<W>) {
// TyVid values are confined to an inference context and hence
// should not be hashed.
bug!("ty::TypeVariants::hash_stable() - can't hash a TyVid {:?}.", *self)
}
}

impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
for ty::IntVid
{
fn hash_stable<W: StableHasherResult>(&self,
_hcx: &mut StableHashingContext<'a>,
_hasher: &mut StableHasher<W>) {
// IntVid values are confined to an inference context and hence
// should not be hashed.
bug!("ty::TypeVariants::hash_stable() - can't hash an IntVid {:?}.", *self)
}
}

impl<'a, 'gcx> HashStable<StableHashingContext<'a>>
for ty::FloatVid
{
fn hash_stable<W: StableHasherResult>(&self,
_hcx: &mut StableHashingContext<'a>,
_hasher: &mut StableHasher<W>) {
// FloatVid values are confined to an inference context and hence
// should not be hashed.
bug!("ty::TypeVariants::hash_stable() - can't hash a FloatVid {:?}.", *self)
}
}

impl_stable_hash_for!(struct ty::ParamTy {
idx,
name
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ macro_rules! __impl_stable_hash_field {

#[macro_export]
macro_rules! impl_stable_hash_for {
(enum $enum_name:path { $( $variant:ident $( ( $($arg:ident),* ) )* ),* }) => {
(enum $enum_name:path { $( $variant:ident $( ( $($arg:ident),* ) )* ),* $(,)* }) => {
impl<'a, 'tcx> ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $enum_name {
#[inline]
fn hash_stable<W: ::rustc_data_structures::stable_hasher::StableHasherResult>(&self,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/traits/query/dropck_outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl<'cx, 'gcx, 'tcx> At<'cx, 'gcx, 'tcx> {
let gcx = tcx.global_tcx();
let (c_ty, orig_values) = self.infcx.canonicalize_query(&self.param_env.and(ty));
let span = self.cause.span;
debug!("c_ty = {:?}", c_ty);
match &gcx.dropck_outlives(c_ty) {
Ok(result) if result.is_proven() => {
match self.infcx.instantiate_query_result(
Expand Down
22 changes: 22 additions & 0 deletions src/test/incremental/issue-49043.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Regression test for hashing involving canonical variables. In this
// test -- which has an intensional error -- the type of the value
// being dropped winds up including a type variable. Canonicalization
// would then produce a `?0` which -- in turn -- triggered an ICE in
// hashing.

// revisions:cfail1

fn main() {
println!("Hello, world! {}",*thread_rng().choose(&[0, 1, 2, 3]).unwrap());
//[cfail1]~^ ERROR cannot find function `thread_rng`
}