Skip to content

Commit f9750c1

Browse files
committed
Add empty ConstKind::Abstract
Initial pass at expr/abstract const/s Address comments Switch to using a list instead of &[ty::Const], rm `AbstractConst` Remove try_unify_abstract_consts Update comments Add edits Recurse more More edits Prevent equating associated consts Move failing test to ui Changes this test from incremental to ui, and mark it as failing and a known bug. Does not cause the compiler to ICE, so should be ok.
1 parent 41e0363 commit f9750c1

File tree

40 files changed

+837
-778
lines changed

40 files changed

+837
-778
lines changed

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
561561
ty::ConstKind::Param(_) | ty::ConstKind::Placeholder(..) => {
562562
throw_inval!(TooGeneric)
563563
}
564+
ty::ConstKind::Expr(_) => throw_inval!(TooGeneric),
564565
ty::ConstKind::Error(reported) => {
565566
throw_inval!(AlreadyReported(reported))
566567
}

compiler/rustc_hir_analysis/src/check/dropck.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,18 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
193193
ty::PredicateKind::ConstEvaluatable(a),
194194
ty::PredicateKind::ConstEvaluatable(b),
195195
) => relator.relate(predicate.rebind(a), predicate.rebind(b)).is_ok(),
196+
/*
197+
) => {
198+
if let (Ok(Some(a)), Ok(Some(b))) = (
199+
tcx.expand_bound_abstract_const(tcx.bound_abstract_const(a.def), a.substs),
200+
tcx.expand_bound_abstract_const(tcx.bound_abstract_const(b.def), b.substs),
201+
) && a.ty() == b.ty() {
202+
return relator.relate(a, b).is_ok();
203+
} else {
204+
false
205+
}
206+
}
207+
*/
196208
(
197209
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_a, lt_a)),
198210
ty::PredicateKind::TypeOutlives(ty::OutlivesPredicate(ty_b, lt_b)),

compiler/rustc_infer/src/infer/freshen.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
248248
ty::ConstKind::Param(_)
249249
| ty::ConstKind::Value(_)
250250
| ty::ConstKind::Unevaluated(..)
251+
| ty::ConstKind::Expr(..)
251252
| ty::ConstKind::Error(_) => ct.super_fold_with(self),
252253
}
253254
}

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin
2323
use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
2424
use rustc_middle::mir::ConstraintCategory;
2525
use rustc_middle::traits::select;
26-
use rustc_middle::ty::abstract_const::{AbstractConst, FailureKind};
2726
use rustc_middle::ty::error::{ExpectedFound, TypeError};
2827
use rustc_middle::ty::fold::BoundVarReplacerDelegate;
2928
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
@@ -713,32 +712,6 @@ impl<'tcx> InferCtxt<'tcx> {
713712
TypeErrCtxt { infcx: self, typeck_results: None, fallback_has_occurred: false }
714713
}
715714

716-
/// calls `tcx.try_unify_abstract_consts` after
717-
/// canonicalizing the consts.
718-
#[instrument(skip(self), level = "debug")]
719-
pub fn try_unify_abstract_consts(
720-
&self,
721-
a: ty::UnevaluatedConst<'tcx>,
722-
b: ty::UnevaluatedConst<'tcx>,
723-
param_env: ty::ParamEnv<'tcx>,
724-
) -> bool {
725-
// Reject any attempt to unify two unevaluated constants that contain inference
726-
// variables, since inference variables in queries lead to ICEs.
727-
if a.substs.has_non_region_infer()
728-
|| b.substs.has_non_region_infer()
729-
|| param_env.has_non_region_infer()
730-
{
731-
debug!("a or b or param_env contain infer vars in its substs -> cannot unify");
732-
return false;
733-
}
734-
735-
let param_env_and = param_env.and((a, b));
736-
let erased = self.tcx.erase_regions(param_env_and);
737-
debug!("after erase_regions: {:?}", erased);
738-
739-
self.tcx.try_unify_abstract_consts(erased)
740-
}
741-
742715
pub fn is_in_snapshot(&self) -> bool {
743716
self.in_snapshot.get()
744717
}
@@ -1646,34 +1619,39 @@ impl<'tcx> InferCtxt<'tcx> {
16461619

16471620
// Postpone the evaluation of constants whose substs depend on inference
16481621
// variables
1622+
let tcx = self.tcx;
16491623
if substs.has_non_region_infer() {
1650-
let ac = AbstractConst::new(self.tcx, unevaluated);
1624+
let substs_erased = tcx.erase_regions(unevaluated.substs);
1625+
let ac = tcx.expand_bound_abstract_const(
1626+
tcx.bound_abstract_const(unevaluated.def),
1627+
substs_erased,
1628+
);
16511629
match ac {
16521630
Ok(None) => {
1653-
substs = InternalSubsts::identity_for_item(self.tcx, unevaluated.def.did);
1631+
substs = InternalSubsts::identity_for_item(tcx, unevaluated.def.did);
16541632
param_env = self.tcx.param_env(unevaluated.def.did);
16551633
}
16561634
Ok(Some(ct)) => {
1657-
if ct.unify_failure_kind(self.tcx) == FailureKind::Concrete {
1658-
substs = replace_param_and_infer_substs_with_placeholder(self.tcx, substs);
1659-
} else {
1635+
if ct.has_non_region_infer() || ct.has_non_region_param() {
16601636
return Err(ErrorHandled::TooGeneric);
1637+
} else {
1638+
substs = replace_param_and_infer_substs_with_placeholder(tcx, substs);
16611639
}
16621640
}
16631641
Err(guar) => return Err(ErrorHandled::Reported(guar)),
16641642
}
16651643
}
16661644

1667-
let param_env_erased = self.tcx.erase_regions(param_env);
1668-
let substs_erased = self.tcx.erase_regions(substs);
1645+
let param_env_erased = tcx.erase_regions(param_env);
1646+
let substs_erased = tcx.erase_regions(substs);
16691647
debug!(?param_env_erased);
16701648
debug!(?substs_erased);
16711649

16721650
let unevaluated = ty::UnevaluatedConst { def: unevaluated.def, substs: substs_erased };
16731651

16741652
// The return value is the evaluated value which doesn't contain any reference to inference
16751653
// variables, thus we don't need to substitute back the original values.
1676-
self.tcx.const_eval_resolve_for_typeck(param_env_erased, unevaluated, span)
1654+
tcx.const_eval_resolve_for_typeck(param_env_erased, unevaluated, span)
16771655
}
16781656

16791657
/// `ty_or_const_infer_var_changed` is equivalent to one of these two:

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -644,12 +644,6 @@ impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for Symbol {
644644
}
645645
}
646646

647-
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for &'tcx [ty::abstract_const::Node<'tcx>] {
648-
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> Self {
649-
ty::codec::RefDecodable::decode(d)
650-
}
651-
}
652-
653647
impl<'a, 'tcx> Decodable<DecodeContext<'a, 'tcx>> for &'tcx [(ty::Predicate<'tcx>, Span)] {
654648
fn decode(d: &mut DecodeContext<'a, 'tcx>) -> Self {
655649
ty::codec::RefDecodable::decode(d)

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ define_tables! {
366366
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,
367367
promoted_mir: Table<DefIndex, LazyValue<IndexVec<mir::Promoted, mir::Body<'static>>>>,
368368
// FIXME(compiler-errors): Why isn't this a LazyArray?
369-
thir_abstract_const: Table<DefIndex, LazyValue<&'static [ty::abstract_const::Node<'static>]>>,
369+
thir_abstract_const: Table<DefIndex, LazyValue<ty::Const<'static>>>,
370370
impl_parent: Table<DefIndex, RawDefId>,
371371
impl_polarity: Table<DefIndex, ty::ImplPolarity>,
372372
constness: Table<DefIndex, hir::Constness>,

compiler/rustc_middle/src/mir/pretty.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ impl<'tcx> Visitor<'tcx> for ExtraComments<'tcx> {
476476
// These variants shouldn't exist in the MIR.
477477
ty::ConstKind::Placeholder(_)
478478
| ty::ConstKind::Infer(_)
479+
| ty::ConstKind::Expr(_)
479480
| ty::ConstKind::Bound(..) => bug!("unexpected MIR constant: {:?}", literal),
480481
},
481482
ConstantKind::Unevaluated(uv, _) => {

compiler/rustc_middle/src/mir/syntax.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,15 +1185,17 @@ pub enum NullOp {
11851185
AlignOf,
11861186
}
11871187

1188-
#[derive(Copy, Clone, Debug, PartialEq, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
1188+
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
1189+
#[derive(HashStable, TyEncodable, TyDecodable, TypeFoldable, TypeVisitable)]
11891190
pub enum UnOp {
11901191
/// The `!` operator for logical inversion
11911192
Not,
11921193
/// The `-` operator for negation
11931194
Neg,
11941195
}
11951196

1196-
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq, TyEncodable, TyDecodable, Hash, HashStable)]
1197+
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)]
1198+
#[derive(TyEncodable, TyDecodable, HashStable, TypeFoldable, TypeVisitable)]
11971199
pub enum BinOp {
11981200
/// The `+` operator (addition)
11991201
Add,

compiler/rustc_middle/src/mir/type_foldable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ TrivialTypeTraversalAndLiftImpls! {
1616
UserTypeAnnotationIndex,
1717
BorrowKind,
1818
CastKind,
19-
BinOp,
2019
NullOp,
21-
UnOp,
2220
hir::Movability,
2321
BasicBlock,
2422
SwitchTargets,

compiler/rustc_middle/src/query/mod.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ rustc_queries! {
400400
/// Try to build an abstract representation of the given constant.
401401
query thir_abstract_const(
402402
key: DefId
403-
) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
403+
) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
404404
desc {
405405
|tcx| "building an abstract representation for `{}`", tcx.def_path_str(key),
406406
}
@@ -409,23 +409,14 @@ rustc_queries! {
409409
/// Try to build an abstract representation of the given constant.
410410
query thir_abstract_const_of_const_arg(
411411
key: (LocalDefId, DefId)
412-
) -> Result<Option<&'tcx [ty::abstract_const::Node<'tcx>]>, ErrorGuaranteed> {
412+
) -> Result<Option<ty::Const<'tcx>>, ErrorGuaranteed> {
413413
desc {
414414
|tcx|
415415
"building an abstract representation for the const argument `{}`",
416416
tcx.def_path_str(key.0.to_def_id()),
417417
}
418418
}
419419

420-
query try_unify_abstract_consts(key:
421-
ty::ParamEnvAnd<'tcx, (ty::UnevaluatedConst<'tcx>, ty::UnevaluatedConst<'tcx>
422-
)>) -> bool {
423-
desc {
424-
|tcx| "trying to unify the generic constants `{}` and `{}`",
425-
tcx.def_path_str(key.value.0.def.did), tcx.def_path_str(key.value.1.def.did)
426-
}
427-
}
428-
429420
query mir_drops_elaborated_and_const_checked(
430421
key: ty::WithOptConstParam<LocalDefId>
431422
) -> &'tcx Steal<mir::Body<'tcx>> {

0 commit comments

Comments
 (0)