Stream: t-compiler/help

Topic: #69913


Bastian Kauschke (Mar 18 2020 at 20:08, on Zulip):

@varkor @eddyb

I am currently looking at https://github.com/rust-lang/rust/issues/69913
The actually problem is more general than the issue.

The compiler currently seems to always panics if a const generic is used in a type and the const generics feature is not enabled.

struct S<const V: usize>;

fn test<const A: usize>(v: S<{A + 1}>) {

}
struct B<const A: usize>([u8; A + 1]);
fn test<const A: usize>() {
    let _: [u8; A + 1];
}

etc all panic during const eval.

More specifically at

  15: <rustc::ty::subst::SubstFolder as rustc::ty::fold::TypeFolder>::fold_const
  16: rustc::ty::normalize_erasing_regions::<impl rustc::ty::context::TyCtxt>::subst_and_normalize_erasing_regions
  17: rustc_mir::interpret::operand::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_operand
  18: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::eval_rvalue_into_place
  19: rustc_mir::interpret::step::<impl rustc_mir::interpret::eval_context::InterpCx<M>>::run
  20: rustc_mir::const_eval::eval_queries::const_eval_raw_provider
  21: rustc::ty::query::__query_compute::const_eval_raw
  22: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_raw>::compute
  23: rustc::dep_graph::graph::DepGraph::with_task_impl
  24: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  25: rustc_mir::const_eval::eval_queries::const_eval_validated_provider
  26: rustc::ty::query::__query_compute::const_eval_validated
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_validated>::compute
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  30: rustc_mir::const_eval::eval_queries::const_eval_validated_provider
  31: rustc::ty::query::__query_compute::const_eval_validated
  32: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::const_eval_validated>::compute
  33: rustc::dep_graph::graph::DepGraph::with_task_impl
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: rustc::mir::interpret::queries::<impl rustc::ty::context::TyCtxt>::const_eval_resolve
  36: rustc::ty::sty::Const::eval::{{closure}}
  37: rustc::ty::sty::Const::eval
  38: rustc::ty::structural_impls::<impl rustc::ty::fold::TypeFoldable for &rustc::ty::TyS>::super_fold_with
  39: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc::ty::fold::TypeFolder>::fold_ty
  40: rustc::ty::structural_impls::fold_list
  41: <rustc_infer::infer::InferCtxt as rustc_trait_selection::infer::InferCtxtExt>::partially_normalize_associated_types_in
  42: rustc::ty::context::GlobalCtxt::enter_local
  43: rustc_typeck::check::wfcheck::check_item_well_formed
  44: rustc::ty::query::__query_compute::check_item_well_formed
  45: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors for rustc::ty::query::queries::check_item_well_formed>::compute
  46: rustc::dep_graph::graph::DepGraph::with_task_impl
  47: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  48: <rustc_typeck::check::wfcheck::CheckTypeWellFormedVisitor as rustc_hir::itemlikevisit::ParItemLikeVisitor>::visit_item

Considering that this problem will be removed once const generics are stable and the first error message can be fixed quite easily,
would it be acceptable to stop compilation before this(i.e. before generating mir) in case const generics are used without the feature?

eddyb (Mar 18 2020 at 20:28, on Zulip):

oh dear

eddyb (Mar 18 2020 at 20:28, on Zulip):

this is because I hackily made const_generics also enable the correct behavior for generics_of

eddyb (Mar 18 2020 at 20:31, on Zulip):

the behavior we can't do by default before lazy normalization

eddyb (Mar 18 2020 at 20:32, on Zulip):

@Bastian Kauschke we could stop compilation yeah but I'm not sure what the best way to do it is

Bastian Kauschke (Mar 18 2020 at 20:33, on Zulip):

abort(1) :laughing:

eddyb (Mar 18 2020 at 20:33, on Zulip):

I mean to detect it

eddyb (Mar 18 2020 at 20:33, on Zulip):

short of making the feature-gating error fatal

Bastian Kauschke (Mar 18 2020 at 20:41, on Zulip):

We might add a new StashKey and use stash_diagnostic. If you think this is an acceptable way to solve this issue, I would gladly try and implement this.

varkor (Mar 18 2020 at 21:14, on Zulip):

short of making the feature-gating error fatal
maybe this isn't completely unreasonable… better than an ICE

varkor (Mar 18 2020 at 21:15, on Zulip):

the behavior we can't do by default before lazy normalization

soon :fingers_crossed:

Bastian Kauschke (Mar 19 2020 at 09:58, on Zulip):

Looking at generics_of, what prevents us from doing the same for AnonConst when const generics are not enabled?

Bastian Kauschke (Mar 19 2020 at 11:52, on Zulip):

/what goes wrong if the hack is used without the feature flag

Bastian Kauschke (Mar 19 2020 at 12:12, on Zulip):

tried it out :cry: I see the problem now

eddyb (Mar 19 2020 at 14:25, on Zulip):

yeah cycle errors

eddyb (Mar 19 2020 at 14:25, on Zulip):

lazy normalization fixes the cycle errors

eddyb (Mar 19 2020 at 14:25, on Zulip):

it's like a 3 year old issue at this point

varkor (Mar 19 2020 at 14:36, on Zulip):

maybe we can just get away with waiting — lazy normalisation should merge soon (though I'm not sure how long we'll need to wait to stabilise it)

Charles Lew (Mar 19 2020 at 16:02, on Zulip):

Speaking of lazy normalization, currently the oldest open tracking issue is about inherent associated types, which is not yet implemented. Is it also blocked on lazy normalization? How much work will it need to get it implemented (on nightly)?

centril (Mar 19 2020 at 16:03, on Zulip):

(ref: https://github.com/rust-lang/rust/issues/8995)

varkor (Mar 19 2020 at 20:31, on Zulip):

@Charles Lew: as I understand it, though @nikomatsakis would be the person to ask, there are two aspects of lazy normalisation — that for consts, and that for traits

varkor (Mar 19 2020 at 20:31, on Zulip):

currently, @Ben Lewis is working on const lazy normalisation, which unblocks quite a lot of the const generics work

varkor (Mar 19 2020 at 20:32, on Zulip):

but this won't unblock the traits features

Charles Lew (Mar 20 2020 at 03:19, on Zulip):

ty!

Last update: Sep 27 2020 at 13:30UTC