Skip to content

Commit

Permalink
Added lazy_normalization_consts feature, and removed the -Z flag.
Browse files Browse the repository at this point in the history
  • Loading branch information
skinnyBat authored and mati865 committed Apr 9, 2020
1 parent 40887eb commit 905e64b
Show file tree
Hide file tree
Showing 28 changed files with 171 additions and 65 deletions.
4 changes: 4 additions & 0 deletions src/librustc_feature/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ declare_features! (

/// Allow negative trait implementations.
(active, negative_impls, "1.44.0", Some(68318), None),

/// Lazily evaluate constants. Which allows constants to depend on type parameters.
(active, lazy_normalization_consts, "1.44.0", Some(60471), None),

// -------------------------------------------------------------------------
// feature-group-end: actual feature gates
Expand All @@ -575,4 +578,5 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
sym::raw_dylib,
sym::const_trait_impl,
sym::const_trait_bound_opt_out,
sym::lazy_normalization_consts,
];
10 changes: 4 additions & 6 deletions src/librustc_infer/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
return self.unify_const_variable(!a_is_expected, vid, a);
}
(ty::ConstKind::Unevaluated(..), _)
if self.tcx.sess.opts.debugging_opts.lazy_normalization =>
if self.tcx.features().lazy_normalization_consts =>
{
relation.const_equate_obligation(a, b);
return Ok(b);
}
(_, ty::ConstKind::Unevaluated(..))
if self.tcx.sess.opts.debugging_opts.lazy_normalization =>
if self.tcx.features().lazy_normalization_consts =>
{
relation.const_equate_obligation(a, b);
return Ok(a);
Expand Down Expand Up @@ -660,9 +660,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
}
}
}
ty::ConstKind::Unevaluated(..)
if self.tcx().sess.opts.debugging_opts.lazy_normalization =>
{
ty::ConstKind::Unevaluated(..) if self.tcx().features().lazy_normalization_consts => {
Ok(c)
}
_ => relate::super_relate_consts(self, c, c),
Expand All @@ -671,7 +669,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
}

pub trait ConstEquateRelation<'tcx>: TypeRelation<'tcx> {
/// Register am obligation that both constants must be equal to each other.
/// Register an obligation that both constants must be equal to each other.
///
/// If they aren't equal then the relation doesn't hold.
fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/equate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::combine::{CombineFields, RelationDir, ConstEquateRelation};
use super::combine::{CombineFields, ConstEquateRelation, RelationDir};
use super::Subtype;

use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
Expand Down
4 changes: 1 addition & 3 deletions src/librustc_infer/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,7 @@ where
}
}
}
ty::ConstKind::Unevaluated(..)
if self.tcx().sess.opts.debugging_opts.lazy_normalization =>
{
ty::ConstKind::Unevaluated(..) if self.tcx().features().lazy_normalization_consts => {
Ok(a)
}
_ => relate::super_relate_consts(self, a, a),
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/ty/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,9 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
let t = relation.relate(&a_t, &b_t)?;
match relation.relate(&sz_a, &sz_b) {
Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
// FIXME(lazy-normalization) Implement improved diagnostics for mismatched array
// FIXME(lazy_normalization_consts) Implement improved diagnostics for mismatched array
// length?
Err(err) if relation.tcx().sess.opts.debugging_opts.lazy_normalization => Err(err),
Err(err) if relation.tcx().features().lazy_normalization_consts => Err(err),
Err(err) => {
// Check whether the lengths are both concrete/known values,
// but are unequal, for better diagnostics.
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_session/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,4 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
"Link native libraries in the linker invocation."),
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
"hash algorithm of source files in debug info (`md5`, or `sha1`)"),
lazy_normalization: bool = (false, parse_bool, [UNTRACKED],
"lazily evaluate constants (experimental)"),
}
1 change: 1 addition & 0 deletions src/librustc_span/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ symbols! {
label_break_value,
lang,
lang_items,
lazy_normalization_consts,
let_chains,
lhs,
lib,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_trait_selection/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
}

fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
if self.selcx.tcx().sess.opts.debugging_opts.lazy_normalization {
if self.selcx.tcx().features().lazy_normalization_consts {
constant
} else {
constant.eval(self.selcx.tcx(), self.param_env)
Expand Down
7 changes: 1 addition & 6 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1181,12 +1181,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
Some(tcx.hir().local_def_id(parent_id))
}
Node::AnonConst(_) => {
// HACK(skinny121) Provide correct generics if `feature(const_generics)` is enabled, in
// addition to when the '-Z lazy-normalization' flag is used, so that trait
// implementations that have const generic parameters within the standard library still
// work. The feature check won't be necessary when lazy normalization is enabled by
// default.
if tcx.sess.opts.debugging_opts.lazy_normalization || tcx.features().const_generics {
if tcx.features().lazy_normalization_consts {
let parent_id = tcx.hir().get_parent_item(hir_id);
Some(tcx.hir().local_def_id(parent_id))
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
#![feature(lazy_normalization_consts)]
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash

#[allow(dead_code)]
struct ArithArrayLen<const N: usize>([u32; 0 + N]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,22 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default

warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
--> $DIR/array-size-in-generic-struct-param.rs:3:12
|
LL | #![feature(lazy_normalization_consts)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: constant expression depends on a generic parameter
--> $DIR/array-size-in-generic-struct-param.rs:5:38
--> $DIR/array-size-in-generic-struct-param.rs:7:38
|
LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
| ^^^^^^^^^^^^
|
= note: this may fail depending on what value the parameter takes

error: constant expression depends on a generic parameter
--> $DIR/array-size-in-generic-struct-param.rs:14:5
--> $DIR/array-size-in-generic-struct-param.rs:16:5
|
LL | arr: [u8; CFG.arr_size],
| ^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/const-generics/issues/issue-61336-1.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
#![feature(lazy_normalization_consts)]
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash

// build-pass

Expand Down
5 changes: 5 additions & 0 deletions src/test/ui/const-generics/issues/issue-61336-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default

warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
--> $DIR/issue-61336-1.rs:3:12
|
LL | #![feature(lazy_normalization_consts)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
2 changes: 2 additions & 0 deletions src/test/ui/const-generics/issues/issue-61336-2.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
#![feature(lazy_normalization_consts)]
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash

fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
[x; { N }]
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/const-generics/issues/issue-61336-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default

warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
--> $DIR/issue-61336-2.rs:3:12
|
LL | #![feature(lazy_normalization_consts)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
--> $DIR/issue-61336-2.rs:9:5
|
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/const-generics/issues/issue-61336.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
#![feature(lazy_normalization_consts)]
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash

fn f<T: Copy, const N: usize>(x: T) -> [T; N] {
[x; N]
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/const-generics/issues/issue-61336.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default

warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
--> $DIR/issue-61336.rs:3:12
|
LL | #![feature(lazy_normalization_consts)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
--> $DIR/issue-61336.rs:9:5
|
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/const-generics/issues/issue-61747.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
#![feature(lazy_normalization_consts)]
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash

struct Const<const N: usize>;

Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/const-generics/issues/issue-61747.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ LL | #![feature(const_generics)]
|
= note: `#[warn(incomplete_features)]` on by default

warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
--> $DIR/issue-61747.rs:5:12
|
LL | #![feature(lazy_normalization_consts)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

3 changes: 2 additions & 1 deletion src/test/ui/const-generics/issues/issue-61935.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// check-pass
// compile-flags: -Z lazy-normalization

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
#![feature(lazy_normalization_consts)]
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash

trait Foo {}

Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/const-generics/issues/issue-61935.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/issue-61935.rs:4:12
--> $DIR/issue-61935.rs:3:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
--> $DIR/issue-61935.rs:5:12
|
LL | #![feature(lazy_normalization_consts)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

1 change: 1 addition & 0 deletions src/test/ui/const-generics/issues/issue-66205.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#![allow(incomplete_features, dead_code, unconditional_recursion)]
#![feature(const_generics)]
#![feature(lazy_normalization_consts)]

fn fact<const N: usize>() {
fact::<{ N - 1 }>();
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/const-generics/issues/issue-67185-1.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// check-pass
// compile-flags: -Z lazy-normalization

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
#![feature(lazy_normalization_consts)]
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash

trait Baz {
type Quaks;
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/const-generics/issues/issue-67185-1.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/issue-67185-1.rs:4:12
--> $DIR/issue-67185-1.rs:3:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

warning: the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
--> $DIR/issue-67185-1.rs:5:12
|
LL | #![feature(lazy_normalization_consts)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

15 changes: 8 additions & 7 deletions src/test/ui/const-generics/issues/issue-67185-2.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// compile-flags: -Z lazy-normalization

#![feature(const_generics)]
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
#![feature(lazy_normalization_consts)]
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash

trait Baz {
type Quaks;
Expand All @@ -14,7 +14,8 @@ trait Bar {}
impl Bar for [u16; 4] {}
impl Bar for [[u16; 3]; 3] {}

trait Foo //~ ERROR mismatched types
trait Foo //~ ERROR the trait bound `[u16; 3]: Bar` is not satisfied [E0277]
//~^ ERROR the trait bound `[[u16; 3]; 2]: Bar` is not satisfied [E0277]
where
[<u8 as Baz>::Quaks; 2]: Bar,
<u8 as Baz>::Quaks: Bar,
Expand All @@ -24,12 +25,12 @@ trait Foo //~ ERROR mismatched types
struct FooImpl;

impl Foo for FooImpl {}
//~^ ERROR mismatched types
//~^^ ERROR mismatched types
//~^ ERROR the trait bound `[u16; 3]: Bar` is not satisfied [E0277]
//~^^ ERROR the trait bound `[[u16; 3]; 2]: Bar` is not satisfied [E0277]

fn f(_: impl Foo) {}
//~^ ERROR mismatched types
//~^^ ERROR mismatched types
//~^ ERROR the trait bound `[u16; 3]: Bar` is not satisfied [E0277]
//~^^ ERROR the trait bound `[[u16; 3]; 2]: Bar` is not satisfied [E0277]

fn main() {
f(FooImpl)
Expand Down
Loading

0 comments on commit 905e64b

Please sign in to comment.