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

Fix an ICE encountered in clippy that will be possible to trigger in rustc in the future #61041

Closed
wants to merge 23 commits into from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented May 22, 2019

cc rust-lang/rust-clippy#4121

I have not been able to build code that errors today. In order to have that we'd need to be running const eval with generic substitutions in scope. We may be able to trigger the code via const propagation, but I think that just bails very early in many cases.

@rust-highfive
Copy link
Collaborator

r? @estebank

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 22, 2019
@oli-obk
Copy link
Contributor Author

oli-obk commented May 22, 2019

cc @eddyb @varkor you're probably interested in const eval of constants with generics in scope

@@ -0,0 +1,51 @@
error[E0601]: `main` function not found in crate `too_generic_eval_ice`
Copy link
Contributor

Choose a reason for hiding this comment

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

add fn main() {} to get rid of this unnecessary error?

}
// Stack frames beyond the first stackframe have their own set of substs and it would be
// absolutely wrong to use them for any further substitutions. So we just yield the substs
// after region erasing and let the caller figure out if that is good enough for them.
Copy link
Member

Choose a reason for hiding this comment

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

I'm confused, why is the thing to substitute being called substs? Usually we call it something generic like value.
Also, this doesn't seem right.

What I would do, if there is any stack frame, is always call subst_and_normalize_erasing_regions and then check if that still needs_subst - because if it does, the entire execution (i.e. what self.param_env applies to) is "too generic".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider the following function

fn foo<U>() -> usize {
    let v: Vec<U> = Vec::new();
    v.len()
}

When evaluating Vec::new() e.g. due to const propagation, we'd create a stack frame for Vec::new. If the type were Vec<i32> the substs would be [i32] and we'd substitute and be monomorphic from now on. Since the type is Vec<U>, we'd substitute the T in Vec<T>::new with U (our substs are [U]). This is why we need to substitute the [T] substs of Vec<T>::new with [U].

We can preemptively return TooGeneric as you suggested, but that would prevent us from const propagating calls to foo, even though that is totally fine to evaluate even though it's still polymorphic.

Copy link
Member

Choose a reason for hiding this comment

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

Okay then you should just never return TooGeneric, even when there are no frames?

And in your example, with the code as written, you would have [T] and not substitute it to/with [U] because you're just not calling subst_and_normalize_erasing_regions anymore in that case.
Am I missing something?

@estebank
Copy link
Contributor

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned estebank May 22, 2019
@matthiaskrgr
Copy link
Member

What's the status of this?

@oli-obk
Copy link
Contributor Author

oli-obk commented May 29, 2019

I'm still trying to figure out how it all works. @eddyb raises extremely valid points, and I need to think about how to do this. The current "fix" is not correct and will just ICE in other situations.

@bors
Copy link
Contributor

bors commented Jun 8, 2019

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

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 1, 2019
@Dylan-DPC-zz
Copy link

ping from triage @oli-obk any updates?

@RalfJung
Copy link
Member

I think I ran into this with RalfJung@a4fbd43: after that change, I get an ICE when building compiler_builtins during bootstrap:

error: internal compiler error: src/librustc/ty/subst.rs:557: type parameter `Self/#0` (Self/0) out of range when substituting (root type=Some(<Self as float::Float>::Int)) substs=[]

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:584:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
error: aborting due to previous error


note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.38.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -Z external-macro-backtrace -Z always-encode-mir -Z mir-emit-retag -Z mir-opt-level=0 -Z force-unstable-if-unmarked -C opt-level=2 -C debuginfo=1 -C prefer-dynamic -C panic=abort -C debug-assertions=no -C link-args=-Wl,-rpath,$ORIGIN/../lib --crate-type lib

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `compiler_builtins`.

So maybe that commit could be added here, then we'll have a testcase already?

@eddyb
Copy link
Member

eddyb commented Jul 16, 2019

@RalfJung Among other things that there are existing uses of monomorphize in the function you're changing, they need to be removed in order to avoid ICEs.
In general, monomorphize(monomorphize(x)) is meaningless, as you can think of monomorphize as being T in A -> T in B so if you pass the result again to monomorphize, it won't be a noop, but instead try to interpret something that's in B as if it were in A.

@RalfJung
Copy link
Member

Oh, that's good to know. I thought monomorphize would be idempotent.

Seems like something worth tracking in the type then?

@RalfJung
Copy link
Member

RalfJung commented Jul 16, 2019

@eddyb I am still seeing this ICE after removing the double-monomorphization with RalfJung@a8754d4d33.

ICE backtrace
error: internal compiler error: src/librustc/ty/subst.rs:557: type parameter `Self/#0` (Self/0) out of range when substituting (root type=Some(<Self as float::Float>::Int)) substs=[]

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:584:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/libunwind.rs:88
   1: backtrace::backtrace::trace_unsynchronized
             at /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.29/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:47
   3: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:36
   4: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:200
   5: std::panicking::default_hook
             at src/libstd/panicking.rs:214
   6: <alloc::boxed::Box<F> as core::ops::function::Fn<A>>::call
             at /home/r/src/rust/rustc/src/liballoc/boxed.rs:780
   7: rustc::util::common::panic_hook
             at src/librustc/util/common.rs:40
   8: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:481
   9: std::panicking::begin_panic
             at /home/r/src/rust/rustc/src/libstd/panicking.rs:411
  10: rustc_errors::Handler::span_bug
             at /home/r/src/rust/rustc/<::std::macros::panic macros>:4
  11: rustc::util::bug::opt_span_bug_fmt::{{closure}}
             at src/librustc/util/bug.rs:35
  12: rustc::ty::context::tls::with_opt::{{closure}}
             at src/librustc/ty/context.rs:1994
  13: rustc::ty::context::tls::with_context_opt
             at src/librustc/ty/context.rs:1944
  14: rustc::ty::context::tls::with_opt
             at src/librustc/ty/context.rs:1994
  15: rustc::util::bug::opt_span_bug_fmt
             at src/librustc/util/bug.rs:32
  16: rustc::util::bug::span_bug_fmt
             at src/librustc/util/bug.rs:23
  17: rustc::ty::subst::SubstFolder::ty_for_param
             at src/librustc/ty/subst.rs:557
  18: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_ty
             at src/librustc/ty/subst.rs:506
  19: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::TyS>::fold_with
             at src/librustc/ty/structural_impls.rs:1077
  20: <rustc::ty::subst::Kind as rustc::ty::fold::TypeFoldable>::super_fold_with
             at src/librustc/ty/subst.rs:154
  21: rustc::ty::fold::TypeFoldable::fold_with
             at src/librustc/ty/fold.rs:50
  22: rustc::ty::subst::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::List<rustc::ty::subst::Kind>>::super_fold_with::{{closure}}
             at src/librustc/ty/subst.rs:386
  23: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &mut F>::call_once
             at /home/r/src/rust/rustc/src/libcore/ops/function.rs:279
  24: core::option::Option<T>::map
             at /home/r/src/rust/rustc/src/libcore/option.rs:447
  25: <core::iter::adapters::Map<I,F> as core::iter::traits::iterator::Iterator>::next
             at /home/r/src/rust/rustc/src/libcore/iter/adapters/mod.rs:570
  26: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
             at /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/smallvec-0.6.10/lib.rs:1357
  27: <smallvec::SmallVec<A> as core::iter::traits::collect::FromIterator<<A as smallvec::Array>::Item>>::from_iter
             at /home/r/.cargo/registry/src/github.com-1ecc6299db9ec823/smallvec-0.6.10/lib.rs:1342
  28: core::iter::traits::iterator::Iterator::collect
             at /home/r/src/rust/rustc/src/libcore/iter/traits/iterator.rs:1464
  29: rustc::ty::subst::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::List<rustc::ty::subst::Kind>>::super_fold_with
             at src/librustc/ty/subst.rs:386
  30: rustc::ty::fold::TypeFoldable::fold_with
             at src/librustc/ty/fold.rs:50
  31: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for rustc::ty::sty::ProjectionTy>::super_fold_with
             at src/librustc/macros.rs:340
  32: rustc::ty::fold::TypeFoldable::fold_with
             at src/librustc/ty/fold.rs:50
  33: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::TyS>::super_fold_with
             at src/librustc/ty/structural_impls.rs:1048
  34: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_ty
             at src/librustc/ty/subst.rs:509
  35: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::TyS>::fold_with
             at src/librustc/ty/structural_impls.rs:1077
  36: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::sty::Const>::super_fold_with
             at src/librustc/ty/structural_impls.rs:1346
  37: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_const
             at src/librustc/ty/subst.rs:530
  38: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::sty::Const>::fold_with
             at /home/r/src/rust/rustc/src/librustc/ty/structural_impls.rs:1355
  39: <T as rustc::ty::subst::Subst>::subst_spanned
             at /home/r/src/rust/rustc/src/librustc/ty/subst.rs:427
  40: rustc::ty::subst::Subst::subst
             at /home/r/src/rust/rustc/src/librustc/ty/subst.rs:413
  41: rustc_mir::interpret::eval_context::InterpCx<M>::monomorphize_with_substs
             at src/librustc_mir/interpret/eval_context.rs:373
  42: rustc_mir::interpret::eval_context::InterpCx<M>::monomorphize
             at src/librustc_mir/interpret/eval_context.rs:357
  43: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_const_to_op
             at src/librustc_mir/interpret/operand.rs:532
  44: rustc_mir::transform::const_prop::ConstPropagator::eval_constant
             at src/librustc_mir/transform/const_prop.rs:369
  45: rustc_mir::transform::const_prop::ConstPropagator::eval_operand
             at src/librustc_mir/transform/const_prop.rs:437
  46: rustc_mir::transform::const_prop::ConstPropagator::const_prop
             at src/librustc_mir/transform/const_prop.rs:452
  47: <rustc_mir::transform::const_prop::ConstPropagator as rustc::mir::visit::MutVisitor>::visit_statement
             at src/librustc_mir/transform/const_prop.rs:783
  48: rustc::mir::visit::MutVisitor::super_basic_block_data
             at /home/r/src/rust/rustc/src/librustc/mir/visit.rs:314
  49: rustc::mir::visit::MutVisitor::visit_basic_block_data
             at /home/r/src/rust/rustc/src/librustc/mir/visit.rs:81
  50: rustc::mir::visit::MutVisitor::super_body
             at /home/r/src/rust/rustc/src/librustc/mir/visit.rs:272
  51: rustc::mir::visit::MutVisitor::visit_body
             at /home/r/src/rust/rustc/src/librustc/mir/visit.rs:75
  52: <rustc_mir::transform::const_prop::ConstProp as rustc_mir::transform::MirPass>::run_pass
             at src/librustc_mir/transform/const_prop.rs:99
  53: rustc_mir::transform::run_passes::{{closure}}::{{closure}}
             at src/librustc_mir/transform/mod.rs:172
  54: rustc_mir::transform::run_passes::{{closure}}
             at src/librustc_mir/transform/mod.rs:179
  55: rustc_mir::transform::run_passes
             at src/librustc_mir/transform/mod.rs:185
  56: rustc_mir::transform::optimized_mir
             at src/librustc_mir/transform/mod.rs:244
  57: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:997
  58: rustc::ty::query::__query_compute::optimized_mir
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:948
  59: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::optimized_mir>::compute
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:989
  60: rustc::dep_graph::graph::DepGraph::with_task_impl
             at /home/r/src/rust/rustc/src/librustc/dep_graph/graph.rs:334
  61: rustc::dep_graph::graph::DepGraph::with_task
             at /home/r/src/rust/rustc/src/librustc/dep_graph/graph.rs:202
  62: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:556
  63: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:275
  64: rustc::ty::context::tls::enter_context::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1866
  65: rustc::ty::context::tls::set_tlv
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1799
  66: rustc::ty::context::tls::enter_context
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1865
  67: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:274
  68: rustc::ty::context::tls::with_related_context::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1972
  69: rustc::ty::context::tls::with_context::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1955
  70: rustc::ty::context::tls::with_context_opt
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1944
  71: rustc::ty::context::tls::with_context
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1955
  72: rustc::ty::context::tls::with_related_context
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1968
  73: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::start_query
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:263
  74: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:548
  75: rustc::ty::query::plumbing::with_diagnostics
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:209
  76: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query_with_job
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:547
  77: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:376
  78: rustc::ty::query::TyCtxtAt::optimized_mir
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:1074
  79: rustc::ty::query::<impl rustc::ty::context::TyCtxt>::optimized_mir
             at /home/r/src/rust/rustc/src/librustc/ty/query/plumbing.rs:1066
  80: rustc_metadata::encoder::EncodeContext::encode_optimized_mir
             at src/librustc_metadata/encoder.rs:1031
  81: rustc_metadata::encoder::EncodeContext::encode_info_for_item
             at src/librustc_metadata/encoder.rs:0
  82: core::ops::function::FnOnce::call_once
             at /home/r/src/rust/rustc/src/libcore/ops/function.rs:231
  83: rustc_metadata::encoder::EncodeContext::record
             at src/librustc_metadata/encoder.rs:314
  84: <rustc_metadata::encoder::EncodeContext as rustc::hir::intravisit::Visitor>::visit_item
             at src/librustc_metadata/encoder.rs:1663
  85: <rustc::hir::itemlikevisit::DeepVisitor<V> as rustc::hir::itemlikevisit::ItemLikeVisitor>::visit_item
             at /home/r/src/rust/rustc/src/librustc/hir/itemlikevisit.rs:70
  86: rustc::hir::Crate::visit_all_item_likes
             at /home/r/src/rust/rustc/src/librustc/hir/mod.rs:782
  87: rustc_metadata::encoder::EncodeContext::encode_info_for_items
             at src/librustc_metadata/encoder.rs:325
  88: rustc_metadata::encoder::EncodeContext::encode_crate_root
             at src/librustc_metadata/encoder.rs:428
  89: rustc_metadata::encoder::encode_metadata::{{closure}}
             at src/librustc_metadata/encoder.rs:1893
  90: rustc::dep_graph::graph::DepGraph::with_ignore::{{closure}}::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/dep_graph/graph.rs:159
  91: rustc::ty::context::tls::enter_context::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1866
  92: rustc::ty::context::tls::set_tlv
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1799
  93: rustc::ty::context::tls::enter_context
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1865
  94: rustc::dep_graph::graph::DepGraph::with_ignore::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/dep_graph/graph.rs:158
  95: rustc::ty::context::tls::with_context::{{closure}}
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1955
  96: rustc::ty::context::tls::with_context_opt
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1944
  97: rustc::ty::context::tls::with_context
             at /home/r/src/rust/rustc/src/librustc/ty/context.rs:1955
  98: rustc::dep_graph::graph::DepGraph::with_ignore
             at /home/r/src/rust/rustc/src/librustc/dep_graph/graph.rs:152
  99: rustc_metadata::encoder::encode_metadata
             at src/librustc_metadata/encoder.rs:1875
  100: rustc_metadata::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::cstore::CStore>::encode_metadata
             at src/librustc_metadata/cstore_impl.rs:554
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
query stack during panic:
#0 [optimized_mir] processing `float::conv::__fixsfsi`
end of query stack
error: aborting due to previous error

The backtrace shows that it is the first monomorphize in eval_const_to_op that fails. The backtrace also involves const-prop -- of course it does, there is hardly any ICE for the Miri engine that does not.

@eddyb
Copy link
Member

eddyb commented Jul 18, 2019

@RalfJung It can't be idempotent, because it's a substitution from one domain to another (just realized that's a better phrasing.

The name monomorphize is kind of bad for that though, it makes more sense in codegen when the result is guaranteed not to refer to any parameters.
(Feel free to suggest a better name, maybe just frame_subst_and_normalize_erasing_regions?)

What constprop should do is use identity Substs, that match the ParamEnv it should already be using (otherwise it'd get ICEs all over the place).

@eddyb
Copy link
Member

eddyb commented Jul 18, 2019

Wait this PR is changing a function called subst_and_normalize_erasing_regions already, lol.
So what does monomorphize do then?

// after region erasing and let the caller figure out if that is good enough for them.
if self.stack.len() > 1 {
return Ok(self.tcx.erase_regions(&substs));
}
match self.stack.last() {
Some(frame) => Ok(self.tcx.subst_and_normalize_erasing_regions(
frame.instance.substs,
self.param_env,
&substs,
)),
Copy link
Member

Choose a reason for hiding this comment

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

New rounds of reviews: I'm pretty sure everything should use at least one frame, or you should keep a "top-level substs" just like param_env`.

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 went with the top level substs, because adding a new frame is way too expensive (not just in perf but also in "useless" API complexity) in some cases. We may be able to clean that up in the future.

} else {
Ok(substs)
},
None => err!(TooGeneric).into(),
Copy link
Member

Choose a reason for hiding this comment

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

New rounds of reviews: this should never happen (see other comments as to why).

But also (most/all?) TooGeneric errors should come from LayoutError::Unknown (which you should either turn into TooGeneric or handle like TooGeneric everywhere).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's also the problem that if we call tcx.normalize_and_erase_regions, at some point we'll end up hitting this assertion:

assert!(!value.needs_subst());
So I've gated various calls that will transitively call normalize_and_erase_regions with an if value.needs_subst() { return err!(TooGeneric); }. I'm not sure how important that assertion is or why it's there. I checked the PR that created it, but it didn't explain the assert.

@wirelessringo
Copy link

Ping from triage @oli-obk any updates on this?

@@ -291,22 +291,37 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
ty.is_freeze(*self.tcx, self.param_env, DUMMY_SP)
}

pub(super) fn subst_and_normalize_erasing_regions<T: TypeFoldable<'tcx>>(
/// Call this whenever you have a value that `needs_subst`. Not guaranteed to actually
Copy link
Member

@RalfJung RalfJung Aug 12, 2019

Choose a reason for hiding this comment

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

This advice seems wrong. It should be called whenever (and only when) you took something from the MIR of the current frame.

Maybe something like

    /// Call this on things you got out of the current frame's MIR, to bring it into the proper
    /// environment for this interpreter.
    ///
    /// This is not guarantee to actually monomorphize [...]

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-08-12T13:42:19.1361991Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-08-12T13:42:19.1550687Z ##[command]git config gc.auto 0
2019-08-12T13:42:19.1629529Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-08-12T13:42:19.1686000Z ##[command]git config --get-all http.proxy
2019-08-12T13:42:19.1828213Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/61041/merge:refs/remotes/pull/61041/merge
---
2019-08-12T13:42:56.1062515Z do so (now or later) by using -b with the checkout command again. Example:
2019-08-12T13:42:56.1062592Z 
2019-08-12T13:42:56.1062871Z   git checkout -b <new-branch-name>
2019-08-12T13:42:56.1062907Z 
2019-08-12T13:42:56.1063002Z HEAD is now at eb7d126a6 Merge 3aa550a09f5c83b23443349660de4d0929e85c31 into c01be67ea40266d6a4c3289654a07ddd7ce2a172
2019-08-12T13:42:56.1190803Z ##[section]Starting: Collect CPU-usage statistics in the background
2019-08-12T13:42:56.1193927Z ==============================================================================
2019-08-12T13:42:56.1194005Z Task         : Bash
2019-08-12T13:42:56.1194072Z Description  : Run a Bash script on macOS, Linux, or Windows
---
2019-08-12T14:15:55.5185807Z    Compiling ena v0.13.0
2019-08-12T14:15:55.9224576Z    Compiling rustc_version v0.2.3
2019-08-12T14:15:56.8950280Z    Compiling lock_api v0.1.3
2019-08-12T14:15:57.6365717Z    Compiling polonius-engine v0.9.0
2019-08-12T14:15:58.8647244Z thread 'rustc' panicked at 'no call frames exist', src/libcore/option.rs:1166:5
2019-08-12T14:15:58.8724974Z 
2019-08-12T14:15:58.8731227Z error: internal compiler error: unexpected panic
2019-08-12T14:15:58.8731325Z 
2019-08-12T14:15:58.8731451Z note: the compiler unexpectedly panicked. this is a bug.
2019-08-12T14:15:58.8731451Z note: the compiler unexpectedly panicked. this is a bug.
2019-08-12T14:15:58.8731515Z 
2019-08-12T14:15:58.8732231Z note: we would appreciate a bug report: ***/blob/master/CONTRIBUTING.md#bug-reports
2019-08-12T14:15:58.8734364Z note: rustc 1.38.0-dev running on x86_64-unknown-linux-gnu
2019-08-12T14:15:58.8734413Z 
2019-08-12T14:15:58.8734413Z 
2019-08-12T14:15:58.8734832Z note: compiler flags: -Z external-macro-backtrace -Z force-unstable-if-unmarked -C opt-level=2 -C debuginfo=0 -C prefer-dynamic -C debug-assertions=n -C link-args=-Wl,-rpath,$ORIGIN/../lib --crate-type lib
2019-08-12T14:15:58.8734900Z 
2019-08-12T14:15:58.8734952Z note: some of the compiler flags provided by cargo are hidden
2019-08-12T14:15:58.8768300Z error: Could not compile `crc32fast`.
2019-08-12T14:15:58.8768654Z warning: build failed, waiting for other jobs to finish...
2019-08-12T14:16:01.1852673Z error: build failed
2019-08-12T14:16:01.1874148Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "2" "--release" "--locked" "--color" "always" "--features" "" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
2019-08-12T14:16:01.1874148Z command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "2" "--release" "--locked" "--color" "always" "--features" "" "--manifest-path" "/checkout/src/rustc/Cargo.toml" "--message-format" "json"
2019-08-12T14:16:01.1874333Z expected success, got: exit code: 101
2019-08-12T14:16:01.1882027Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-08-12T14:16:01.1882237Z Build completed unsuccessfully in 0:26:39
2019-08-12T14:16:02.6190749Z ##[error]Bash exited with code '1'.
2019-08-12T14:16:02.6236830Z ##[section]Starting: Checkout
2019-08-12T14:16:02.6238716Z ==============================================================================
2019-08-12T14:16:02.6238796Z Task         : Get sources
2019-08-12T14:16:02.6238849Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@eddyb
Copy link
Member

eddyb commented Aug 12, 2019

IMO this PR should be retitled: clippy is just a coincidence, there are many things broken in miri wrt substitutions.

For the record, I've started my own attempt, based on @RalfJung's take on this, at https://github.com/rust-lang/rust/compare/master...eddyb:miri-subst?expand=1

And I've hit this peculiar bug: #56137 (comment)
From what I've been told, @oli-obk and/or @RalfJung have hit an assertion stemming from that, and have kept working around it, which can't be correct since the MIR is wrong 😭.

EDIT: opened #63495 to fix that bug.

@@ -531,14 +535,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
// in patterns via the `const_eval` module
crate fn eval_const_to_op(
&self,
val: &'tcx ty::Const<'tcx>,
value: ConstValue<'tcx>,
ty: Ty<'tcx>,
Copy link
Member

Choose a reason for hiding this comment

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

Please add a HACK/FIXME comment. Or even better, wait for #56137 to be fixed.

Copy link
Member

Choose a reason for hiding this comment

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

That is, rebase this on top of #63495.

Centril added a commit to Centril/rust that referenced this pull request Aug 14, 2019
 Remove redundant `ty` fields from `mir::Constant` and `hair::pattern::PatternRange`.

Fixes rust-lang#56137.

As a side-effect, associated const literals have the correct type now, which should make things easier for rust-lang#61041.

r? @oli-obk / @matthewjasper cc @davidtwco @varkor
Centril added a commit to Centril/rust that referenced this pull request Aug 14, 2019
 Remove redundant `ty` fields from `mir::Constant` and `hair::pattern::PatternRange`.

Fixes rust-lang#56137.

As a side-effect, associated const literals have the correct type now, which should make things easier for rust-lang#61041.

r? @oli-obk / @matthewjasper cc @davidtwco @varkor
Centril added a commit to Centril/rust that referenced this pull request Aug 14, 2019
 Remove redundant `ty` fields from `mir::Constant` and `hair::pattern::PatternRange`.

Fixes rust-lang#56137.

As a side-effect, associated const literals have the correct type now, which should make things easier for rust-lang#61041.

r? @oli-obk / @matthewjasper cc @davidtwco @varkor
Centril added a commit to Centril/rust that referenced this pull request Aug 14, 2019
 Remove redundant `ty` fields from `mir::Constant` and `hair::pattern::PatternRange`.

Fixes rust-lang#56137.

As a side-effect, associated const literals have the correct type now, which should make things easier for rust-lang#61041.

r? @oli-obk / @matthewjasper cc @davidtwco @varkor
Centril added a commit to Centril/rust that referenced this pull request Aug 15, 2019
 Remove redundant `ty` fields from `mir::Constant` and `hair::pattern::PatternRange`.

Fixes rust-lang#56137.

As a side-effect, associated const literals have the correct type now, which should make things easier for rust-lang#61041.

r? @oli-obk / @matthewjasper cc @davidtwco @varkor
Centril added a commit to Centril/rust that referenced this pull request Aug 16, 2019
 Remove redundant `ty` fields from `mir::Constant` and `hair::pattern::PatternRange`.

Fixes rust-lang#56137.

As a side-effect, associated const literals have the correct type now, which should make things easier for rust-lang#61041.

r? @oli-obk / @matthewjasper cc @davidtwco @varkor
@eddyb eddyb added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 18, 2019
@eddyb
Copy link
Member

eddyb commented Aug 18, 2019

(waiting on @oli-obk to deduplicate this with my own PR)

@xght
Copy link

xght commented Aug 18, 2019

I think this PR will fix #61432, maybe you can create a test case for it.

eddyb added a commit to eddyb/rust that referenced this pull request Aug 19, 2019
Centril added a commit to Centril/rust that referenced this pull request Aug 20, 2019
rustc_mir: fix miri substitution/"universe" discipline.

Alternative to rust-lang#61041, based on @RalfJung's own attempt at it.
I haven't done a full audit, but I believe everything is fixed now.

Fixes rust-lang#61432.
Closes rust-lang#61336, as a drive-by fix (for a subset of rust-lang#43408, that is already special-cased).

r? @oli-obk / @RalfJung cc @varkor @yodaldevoid
bors added a commit that referenced this pull request Aug 20, 2019
rustc_mir: fix miri substitution/"universe" discipline.

Alternative to #61041, based on @RalfJung's own attempt at it.
I haven't done a full audit, but I believe everything is fixed now.

Fixes #61432.
Closes #61336, as a drive-by fix (for a subset of #43408, that is already special-cased).

r? @oli-obk / @RalfJung cc @varkor @yodaldevoid
@bors
Copy link
Contributor

bors commented Aug 20, 2019

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

@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 20, 2019

Closing since #63497 fixed this in a cleaner way

@oli-obk oli-obk closed this Aug 20, 2019
@oli-obk oli-obk deleted the clippy_ice branch March 16, 2021 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet