Skip to content

Commit a0d0060

Browse files
authored
Rollup merge of #53850 - csmoe:const_to_alloc, r=RalfJung
Nuke the `const_to_allocation` query Closes #53847 r? @RalfJung `./x.py check` works anyway, let's checkout tests from ci.
2 parents f370814 + db7da0e commit a0d0060

File tree

7 files changed

+15
-28
lines changed

7 files changed

+15
-28
lines changed

Diff for: src/librustc/dep_graph/dep_node.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ use traits::query::{
7575
CanonicalPredicateGoal, CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpNormalizeGoal,
7676
};
7777
use ty::{TyCtxt, FnSig, Instance, InstanceDef,
78-
ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty, self};
78+
ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty};
7979
use ty::subst::Substs;
8080

8181
// erase!() just makes tokens go away. It's used to specify which macro argument
@@ -632,7 +632,6 @@ define_dep_nodes!( <'tcx>
632632
// queries). Making them anonymous avoids hashing the result, which
633633
// may save a bit of time.
634634
[anon] EraseRegionsTy { ty: Ty<'tcx> },
635-
[anon] ConstToAllocation { val: &'tcx ty::Const<'tcx> },
636635

637636
[input] Freevars(DefId),
638637
[input] MaybeUnusedTraitImport(DefId),

Diff for: src/librustc/ty/query/config.rs

-6
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,6 @@ impl<'tcx> QueryDescription<'tcx> for queries::super_predicates_of<'tcx> {
198198
}
199199
}
200200

201-
impl<'tcx> QueryDescription<'tcx> for queries::const_to_allocation<'tcx> {
202-
fn describe(_tcx: TyCtxt, val: &'tcx ty::Const<'tcx>) -> String {
203-
format!("converting constant `{:?}` to an allocation", val)
204-
}
205-
}
206-
207201
impl<'tcx> QueryDescription<'tcx> for queries::erase_regions_ty<'tcx> {
208202
fn describe(_tcx: TyCtxt, ty: Ty<'tcx>) -> String {
209203
format!("erasing regions from `{:?}`", ty)

Diff for: src/librustc/ty/query/mod.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use middle::exported_symbols::{SymbolExportLevel, ExportedSymbol};
3030
use mir::interpret::ConstEvalResult;
3131
use mir::mono::{CodegenUnit, Stats};
3232
use mir;
33-
use mir::interpret::{GlobalId, Allocation};
33+
use mir::interpret::GlobalId;
3434
use session::{CompileResult, CrateDisambiguator};
3535
use session::config::OutputFilenames;
3636
use traits::{self, Vtable};
@@ -286,11 +286,6 @@ define_queries! { <'tcx>
286286
/// other items (such as enum variant explicit discriminants).
287287
[] fn const_eval: const_eval_dep_node(ty::ParamEnvAnd<'tcx, GlobalId<'tcx>>)
288288
-> ConstEvalResult<'tcx>,
289-
290-
/// Converts a constant value to a constant allocation
291-
[] fn const_to_allocation: const_to_allocation(
292-
&'tcx ty::Const<'tcx>
293-
) -> &'tcx Allocation,
294289
},
295290

296291
TypeChecking {
@@ -706,12 +701,6 @@ fn erase_regions_ty<'tcx>(ty: Ty<'tcx>) -> DepConstructor<'tcx> {
706701
DepConstructor::EraseRegionsTy { ty }
707702
}
708703

709-
fn const_to_allocation<'tcx>(
710-
val: &'tcx ty::Const<'tcx>,
711-
) -> DepConstructor<'tcx> {
712-
DepConstructor::ConstToAllocation { val }
713-
}
714-
715704
fn type_param_predicates<'tcx>((item_id, param_id): (DefId, DefId)) -> DepConstructor<'tcx> {
716705
DepConstructor::TypeParamPredicates {
717706
item_id,

Diff for: src/librustc/ty/query/plumbing.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,6 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
10621062
DepKind::FulfillObligation |
10631063
DepKind::VtableMethods |
10641064
DepKind::EraseRegionsTy |
1065-
DepKind::ConstToAllocation |
10661065
DepKind::NormalizeProjectionTy |
10671066
DepKind::NormalizeTyAfterErasingRegions |
10681067
DepKind::ImpliedOutlivesBounds |

Diff for: src/librustc_mir/interpret/memory.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::ptr;
2222

2323
use rustc::ty::{self, Instance, query::TyCtxtAt};
2424
use rustc::ty::layout::{self, Align, TargetDataLayout, Size, HasDataLayout};
25-
use rustc::mir::interpret::{Pointer, AllocId, Allocation, ScalarMaybeUndef, GlobalId,
25+
use rustc::mir::interpret::{Pointer, AllocId, Allocation, ConstValue, ScalarMaybeUndef, GlobalId,
2626
EvalResult, Scalar, EvalErrorKind, AllocType, PointerArithmetic,
2727
truncate};
2828
pub use rustc::mir::interpret::{write_target_uint, read_target_uint};
@@ -340,9 +340,12 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
340340
// no need to report anything, the const_eval call takes care of that for statics
341341
assert!(tcx.is_static(def_id).is_some());
342342
EvalErrorKind::ReferencedConstant(err).into()
343-
}).map(|val| {
344-
// FIXME We got our static (will be a ByRef), now we make a *copy*?!?
345-
tcx.const_to_allocation(val)
343+
}).map(|const_val| {
344+
if let ConstValue::ByRef(_, allocation, _) = const_val.val {
345+
allocation
346+
} else {
347+
bug!("Matching on non-ByRef static")
348+
}
346349
})
347350
}
348351

Diff for: src/librustc_mir/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ pub fn provide(providers: &mut Providers) {
9393
shim::provide(providers);
9494
transform::provide(providers);
9595
providers.const_eval = interpret::const_eval_provider;
96-
providers.const_to_allocation = interpret::const_to_allocation_provider;
9796
providers.check_match = hair::pattern::check_match;
9897
}
9998

Diff for: src/librustc_typeck/check/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ use rustc::infer::{self, InferCtxt, InferOk, RegionVariableOrigin};
9494
use rustc::infer::anon_types::AnonTypeDecl;
9595
use rustc::infer::type_variable::{TypeVariableOrigin};
9696
use rustc::middle::region;
97-
use rustc::mir::interpret::{GlobalId};
97+
use rustc::mir::interpret::{ConstValue, GlobalId};
9898
use rustc::ty::subst::{CanonicalSubsts, UnpackedKind, Subst, Substs};
9999
use rustc::traits::{self, ObligationCause, ObligationCauseCode, TraitEngine};
100100
use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind, Visibility, ToPredicate, RegionKind};
@@ -1375,7 +1375,11 @@ fn maybe_check_static_with_link_section(tcx: TyCtxt, id: DefId, span: Span) {
13751375
};
13761376
let param_env = ty::ParamEnv::reveal_all();
13771377
if let Ok(static_) = tcx.const_eval(param_env.and(cid)) {
1378-
let alloc = tcx.const_to_allocation(static_);
1378+
let alloc = if let ConstValue::ByRef(_, allocation, _) = static_.val {
1379+
allocation
1380+
} else {
1381+
bug!("Matching on non-ByRef static")
1382+
};
13791383
if alloc.relocations.len() != 0 {
13801384
let msg = "statics with a custom `#[link_section]` must be a \
13811385
simple list of bytes on the wasm target with no \

0 commit comments

Comments
 (0)