Skip to content

Commit 905e64b

Browse files
skinnyBatmati865
authored andcommitted
Added lazy_normalization_consts feature, and removed the -Z flag.
1 parent 40887eb commit 905e64b

28 files changed

+171
-65
lines changed

src/librustc_feature/active.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,9 @@ declare_features! (
558558

559559
/// Allow negative trait implementations.
560560
(active, negative_impls, "1.44.0", Some(68318), None),
561+
562+
/// Lazily evaluate constants. Which allows constants to depend on type parameters.
563+
(active, lazy_normalization_consts, "1.44.0", Some(60471), None),
561564

562565
// -------------------------------------------------------------------------
563566
// feature-group-end: actual feature gates
@@ -575,4 +578,5 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
575578
sym::raw_dylib,
576579
sym::const_trait_impl,
577580
sym::const_trait_bound_opt_out,
581+
sym::lazy_normalization_consts,
578582
];

src/librustc_infer/infer/combine.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,13 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
165165
return self.unify_const_variable(!a_is_expected, vid, a);
166166
}
167167
(ty::ConstKind::Unevaluated(..), _)
168-
if self.tcx.sess.opts.debugging_opts.lazy_normalization =>
168+
if self.tcx.features().lazy_normalization_consts =>
169169
{
170170
relation.const_equate_obligation(a, b);
171171
return Ok(b);
172172
}
173173
(_, ty::ConstKind::Unevaluated(..))
174-
if self.tcx.sess.opts.debugging_opts.lazy_normalization =>
174+
if self.tcx.features().lazy_normalization_consts =>
175175
{
176176
relation.const_equate_obligation(a, b);
177177
return Ok(a);
@@ -660,9 +660,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
660660
}
661661
}
662662
}
663-
ty::ConstKind::Unevaluated(..)
664-
if self.tcx().sess.opts.debugging_opts.lazy_normalization =>
665-
{
663+
ty::ConstKind::Unevaluated(..) if self.tcx().features().lazy_normalization_consts => {
666664
Ok(c)
667665
}
668666
_ => relate::super_relate_consts(self, c, c),
@@ -671,7 +669,7 @@ impl TypeRelation<'tcx> for Generalizer<'_, 'tcx> {
671669
}
672670

673671
pub trait ConstEquateRelation<'tcx>: TypeRelation<'tcx> {
674-
/// Register am obligation that both constants must be equal to each other.
672+
/// Register an obligation that both constants must be equal to each other.
675673
///
676674
/// If they aren't equal then the relation doesn't hold.
677675
fn const_equate_obligation(&mut self, a: &'tcx ty::Const<'tcx>, b: &'tcx ty::Const<'tcx>);

src/librustc_infer/infer/equate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::combine::{CombineFields, RelationDir, ConstEquateRelation};
1+
use super::combine::{CombineFields, ConstEquateRelation, RelationDir};
22
use super::Subtype;
33

44
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};

src/librustc_infer/infer/nll_relate/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -997,9 +997,7 @@ where
997997
}
998998
}
999999
}
1000-
ty::ConstKind::Unevaluated(..)
1001-
if self.tcx().sess.opts.debugging_opts.lazy_normalization =>
1002-
{
1000+
ty::ConstKind::Unevaluated(..) if self.tcx().features().lazy_normalization_consts => {
10031001
Ok(a)
10041002
}
10051003
_ => relate::super_relate_consts(self, a, a),

src/librustc_middle/ty/relate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,9 @@ pub fn super_relate_tys<R: TypeRelation<'tcx>>(
431431
let t = relation.relate(&a_t, &b_t)?;
432432
match relation.relate(&sz_a, &sz_b) {
433433
Ok(sz) => Ok(tcx.mk_ty(ty::Array(t, sz))),
434-
// FIXME(lazy-normalization) Implement improved diagnostics for mismatched array
434+
// FIXME(lazy_normalization_consts) Implement improved diagnostics for mismatched array
435435
// length?
436-
Err(err) if relation.tcx().sess.opts.debugging_opts.lazy_normalization => Err(err),
436+
Err(err) if relation.tcx().features().lazy_normalization_consts => Err(err),
437437
Err(err) => {
438438
// Check whether the lengths are both concrete/known values,
439439
// but are unequal, for better diagnostics.

src/librustc_session/options.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,4 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
982982
"Link native libraries in the linker invocation."),
983983
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
984984
"hash algorithm of source files in debug info (`md5`, or `sha1`)"),
985-
lazy_normalization: bool = (false, parse_bool, [UNTRACKED],
986-
"lazily evaluate constants (experimental)"),
987985
}

src/librustc_span/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ symbols! {
408408
label_break_value,
409409
lang,
410410
lang_items,
411+
lazy_normalization_consts,
411412
let_chains,
412413
lhs,
413414
lib,

src/librustc_trait_selection/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
387387
}
388388

389389
fn fold_const(&mut self, constant: &'tcx ty::Const<'tcx>) -> &'tcx ty::Const<'tcx> {
390-
if self.selcx.tcx().sess.opts.debugging_opts.lazy_normalization {
390+
if self.selcx.tcx().features().lazy_normalization_consts {
391391
constant
392392
} else {
393393
constant.eval(self.selcx.tcx(), self.param_env)

src/librustc_typeck/collect.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,12 +1181,7 @@ fn generics_of(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::Generics {
11811181
Some(tcx.hir().local_def_id(parent_id))
11821182
}
11831183
Node::AnonConst(_) => {
1184-
// HACK(skinny121) Provide correct generics if `feature(const_generics)` is enabled, in
1185-
// addition to when the '-Z lazy-normalization' flag is used, so that trait
1186-
// implementations that have const generic parameters within the standard library still
1187-
// work. The feature check won't be necessary when lazy normalization is enabled by
1188-
// default.
1189-
if tcx.sess.opts.debugging_opts.lazy_normalization || tcx.features().const_generics {
1184+
if tcx.features().lazy_normalization_consts {
11901185
let parent_id = tcx.hir().get_parent_item(hir_id);
11911186
Some(tcx.hir().local_def_id(parent_id))
11921187
} else {

src/test/ui/const-generics/array-size-in-generic-struct-param.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![feature(const_generics)]
22
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
#![feature(lazy_normalization_consts)]
4+
//~^ WARN the feature `lazy_normalization_consts` is incomplete and may cause the compiler to crash
35

46
#[allow(dead_code)]
57
struct ArithArrayLen<const N: usize>([u32; 0 + N]);

0 commit comments

Comments
 (0)