1
Fork 0

Merge impl_constness and is_const_fn_raw.

This commit is contained in:
Camille GILLOT 2022-03-13 11:12:50 +01:00
parent e62f483842
commit 15b2d1a97c
8 changed files with 52 additions and 63 deletions

View file

@ -14,7 +14,6 @@ use rustc_data_structures::sync::{Lock, LockGuard, Lrc, OnceCell};
use rustc_data_structures::unhash::UnhashMap;
use rustc_expand::base::{SyntaxExtension, SyntaxExtensionKind};
use rustc_expand::proc_macro::{AttrProcMacro, BangProcMacro, ProcMacroDerive};
use rustc_hir as hir;
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
use rustc_hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX, LOCAL_CRATE};
use rustc_hir::definitions::{DefKey, DefPath, DefPathData, DefPathHash};
@ -1419,19 +1418,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}
}
// This replicates some of the logic of the crate-local `is_const_fn_raw` query, because we
// don't serialize constness for tuple variant and tuple struct constructors.
fn is_const_fn_raw(self, id: DefIndex) -> bool {
let constness = match self.kind(id) {
EntryKind::AssocFn(_) | EntryKind::Fn | EntryKind::ForeignFn => {
self.root.tables.impl_constness.get(self, id).unwrap().decode(self)
}
EntryKind::Variant(..) | EntryKind::Struct(..) => hir::Constness::Const,
_ => hir::Constness::NotConst,
};
constness == hir::Constness::Const
}
fn is_foreign_item(self, id: DefIndex) -> bool {
match self.kind(id) {
EntryKind::ForeignStatic | EntryKind::ForeignFn => true,

View file

@ -163,7 +163,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
associated_item_def_ids => { cdata.get_associated_item_def_ids(tcx, def_id.index) }
associated_item => { cdata.get_associated_item(def_id.index) }
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
is_const_fn_raw => { cdata.is_const_fn_raw(def_id.index) }
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
item_attrs => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(def_id.index, tcx.sess)) }
trait_of_item => { cdata.get_trait_of_item(def_id.index) }

View file

@ -1048,6 +1048,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
};
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
record!(self.tables.impl_constness[def_id] <- hir::Constness::Const);
record!(self.tables.children[def_id] <- variant.fields.iter().map(|f| {
assert!(f.did.is_local());
f.did.index
@ -1077,6 +1078,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
};
record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
record!(self.tables.impl_constness[def_id] <- hir::Constness::Const);
self.encode_item_type(def_id);
if variant.ctor_kind == CtorKind::Fn {
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
@ -1155,6 +1157,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
};
record!(self.tables.repr_options[def_id] <- adt_def.repr());
record!(self.tables.impl_constness[def_id] <- hir::Constness::Const);
record!(self.tables.kind[def_id] <- EntryKind::Struct(self.lazy(data)));
self.encode_item_type(def_id);
if variant.ctor_kind == CtorKind::Fn {
@ -1417,6 +1420,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
hir::ItemKind::Struct(ref struct_def, _) => {
let adt_def = self.tcx.adt_def(def_id);
record!(self.tables.repr_options[def_id] <- adt_def.repr());
record!(self.tables.impl_constness[def_id] <- hir::Constness::Const);
// Encode def_ids for each field and method
// for methods, write all the stuff get_trait_method