Skip to content

Commit

Permalink
Store static initializers in metadata instead of the MIR of statics.
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Oct 9, 2023
1 parent 2fde99e commit 7a7456d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
9 changes: 9 additions & 0 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ provide! { tcx, def_id, other, cdata,
asyncness => { table_direct }
fn_arg_names => { table }
generator_kind => { 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 => {
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1034,11 +1034,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)
}
// Full-fledged functions + closures
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
let generics = tcx.generics_of(def_id);
Expand Down Expand Up @@ -1439,6 +1437,12 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
let data = self.tcx.generator_kind(def_id).unwrap();
record!(self.tables.generator_kind[def_id] <- data);
}
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);
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ define_tables! {
asyncness: Table<DefIndex, ty::Asyncness>,
fn_arg_names: Table<DefIndex, LazyArray<Ident>>,
generator_kind: Table<DefIndex, LazyValue<hir::GeneratorKind>>,
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>>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ rustc_queries! {
tcx.def_path_str(key)
}
cache_on_disk_if { true }
separate_provide_extern
}

/// Evaluates const items or anonymous constants
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/parameterized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ trivially_parameterized_over_tcx! {
crate::middle::exported_symbols::SymbolExportInfo,
crate::middle::resolve_bound_vars::ObjectLifetimeDefault,
crate::mir::ConstQualifs,
crate::mir::interpret::AllocId,
ty::AssocItemContainer,
ty::Asyncness,
ty::DeducedParamAttrs,
Expand Down

0 comments on commit 7a7456d

Please sign in to comment.