Store static initializers in metadata instead of the MIR of statics.
This commit is contained in:
parent
95004e5ae2
commit
be6ccf13e3
6 changed files with 23 additions and 7 deletions
|
@ -41,8 +41,8 @@ pub fn provide(providers: &mut Providers) {
|
|||
providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
|
||||
providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
|
||||
providers.eval_static_initializer_raw = |tcx, def_id| {
|
||||
assert!(tcx.is_static(def_id));
|
||||
let instance = ty::Instance::mono(tcx, def_id);
|
||||
assert!(tcx.is_static(def_id.to_def_id()));
|
||||
let instance = ty::Instance::mono(tcx, def_id.to_def_id());
|
||||
let gid = rustc_middle::mir::interpret::GlobalId { instance, promoted: None };
|
||||
let param_env = ty::ParamEnv::reveal_all();
|
||||
Ok(tcx.eval_to_allocation_raw(param_env.and(gid))?.alloc_id)
|
||||
|
|
|
@ -250,6 +250,15 @@ provide! { tcx, def_id, other, cdata,
|
|||
fn_arg_names => { table }
|
||||
coroutine_kind => { table_direct }
|
||||
coroutine_for_closure => { table }
|
||||
eval_static_initializer_raw => {
|
||||
Ok(cdata
|
||||
.root
|
||||
.tables
|
||||
.eval_static_initializer_raw
|
||||
.get(cdata, def_id.index)
|
||||
.map(|lazy| lazy.decode((cdata, tcx)))
|
||||
.unwrap_or_else(|| panic!("{def_id:?} does not have eval_static_initializer_raw")))
|
||||
}
|
||||
trait_def => { table }
|
||||
deduced_param_attrs => { table }
|
||||
is_type_alias_impl_trait => {
|
||||
|
|
|
@ -1045,11 +1045,9 @@ fn should_encode_mir(
|
|||
(true, mir_opt_base)
|
||||
}
|
||||
// Constants
|
||||
DefKind::AnonConst
|
||||
| DefKind::InlineConst
|
||||
| DefKind::AssocConst
|
||||
| DefKind::Static(..)
|
||||
| DefKind::Const => (true, false),
|
||||
DefKind::AnonConst | DefKind::InlineConst | DefKind::AssocConst | DefKind::Const => {
|
||||
(true, false)
|
||||
}
|
||||
// Coroutines require optimized MIR to compute layout.
|
||||
DefKind::Closure if tcx.is_coroutine(def_id.to_def_id()) => (false, true),
|
||||
// Full-fledged functions + closures
|
||||
|
@ -1454,6 +1452,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
|
|||
.coroutine_for_closure
|
||||
.set_some(def_id.index, self.tcx.coroutine_for_closure(def_id).into());
|
||||
}
|
||||
if let DefKind::Static(_) = def_kind {
|
||||
if !self.tcx.is_foreign_item(def_id) {
|
||||
let data = self.tcx.eval_static_initializer_raw(def_id).unwrap();
|
||||
record!(self.tables.eval_static_initializer_raw[def_id] <- data);
|
||||
}
|
||||
}
|
||||
if let DefKind::Enum | DefKind::Struct | DefKind::Union = def_kind {
|
||||
self.encode_info_for_adt(local_id);
|
||||
}
|
||||
|
|
|
@ -443,6 +443,7 @@ define_tables! {
|
|||
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
|
||||
coroutine_kind: Table<DefIndex, hir::CoroutineKind>,
|
||||
coroutine_for_closure: Table<DefIndex, RawDefId>,
|
||||
eval_static_initializer_raw: Table<DefIndex, LazyValue<mir::interpret::AllocId>>,
|
||||
trait_def: Table<DefIndex, LazyValue<ty::TraitDef>>,
|
||||
trait_item_def_id: Table<DefIndex, RawDefId>,
|
||||
expn_that_defined: Table<DefIndex, LazyValue<ExpnId>>,
|
||||
|
|
|
@ -1079,6 +1079,7 @@ rustc_queries! {
|
|||
tcx.def_path_str(key)
|
||||
}
|
||||
cache_on_disk_if { key.is_local() }
|
||||
separate_provide_extern
|
||||
}
|
||||
|
||||
/// Evaluates const items or anonymous constants
|
||||
|
|
|
@ -63,6 +63,7 @@ trivially_parameterized_over_tcx! {
|
|||
crate::middle::lib_features::FeatureStability,
|
||||
crate::middle::resolve_bound_vars::ObjectLifetimeDefault,
|
||||
crate::mir::ConstQualifs,
|
||||
crate::mir::interpret::AllocId,
|
||||
ty::AssocItemContainer,
|
||||
ty::Asyncness,
|
||||
ty::DeducedParamAttrs,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue