Skip to content

Commit

Permalink
Add asyncness table.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Feb 19, 2022
1 parent 7bacdb7 commit 6cc96a4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
9 changes: 0 additions & 9 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1431,15 +1431,6 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
constness == hir::Constness::Const
}

fn asyncness(self, id: DefIndex) -> hir::IsAsync {
match self.kind(id) {
EntryKind::Fn(data) => data.decode(self).asyncness,
EntryKind::AssocFn(data) => data.decode(self).fn_data.asyncness,
EntryKind::ForeignFn(data) => data.decode(self).asyncness,
_ => bug!("asyncness: expected function kind"),
}
}

fn is_foreign_item(self, id: DefIndex) -> bool {
match self.kind(id) {
EntryKind::ForeignImmStatic | EntryKind::ForeignMutStatic | EntryKind::ForeignFn(_) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
coerce_unsized_info => { table }
mir_const_qualif => { table }
rendered_const => { table }
asyncness => { table }

trait_def => { cdata.get_trait_def(def_id.index, tcx.sess) }
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
Expand All @@ -149,7 +150,6 @@ provide! { <'tcx> tcx, def_id, other, cdata,
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) }
asyncness => { cdata.asyncness(def_id.index) }
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
static_mutability => { cdata.static_mutability(def_id.index) }
generator_kind => { cdata.generator_kind(def_id.index) }
Expand Down
13 changes: 5 additions & 8 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
hir::TraitFn::Required(ref names) => self.encode_fn_param_names(names),
hir::TraitFn::Provided(body) => self.encode_fn_param_names_for_body(body),
};
FnData {
asyncness: m_sig.header.asyncness,
constness: hir::Constness::NotConst,
param_names,
}
record!(self.tables.asyncness[def_id] <- m_sig.header.asyncness);
FnData { constness: hir::Constness::NotConst, param_names }
} else {
bug!()
};
Expand Down Expand Up @@ -1264,8 +1261,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
ty::AssocKind::Fn => {
let fn_data = if let hir::ImplItemKind::Fn(ref sig, body) = ast_item.kind {
record!(self.tables.asyncness[def_id] <- sig.header.asyncness);
FnData {
asyncness: sig.header.asyncness,
// Can be inside `impl const Trait`, so using sig.header.constness is not reliable
constness: if self.tcx.is_const_fn_raw(def_id) {
hir::Constness::Const
Expand Down Expand Up @@ -1407,8 +1404,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
EntryKind::Const
}
hir::ItemKind::Fn(ref sig, .., body) => {
record!(self.tables.asyncness[def_id] <- sig.header.asyncness);
let data = FnData {
asyncness: sig.header.asyncness,
constness: sig.header.constness,
param_names: self.encode_fn_param_names_for_body(body),
};
Expand Down Expand Up @@ -1876,8 +1873,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {

match nitem.kind {
hir::ForeignItemKind::Fn(_, ref names, _) => {
record!(self.tables.asyncness[def_id] <- hir::IsAsync::NotAsync);
let data = FnData {
asyncness: hir::IsAsync::NotAsync,
constness: if self.tcx.is_const_fn_raw(def_id) {
hir::Constness::Const
} else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@ define_tables! {
coerce_unsized_info: Table<DefIndex, Lazy!(ty::adjustment::CoerceUnsizedInfo)>,
mir_const_qualif: Table<DefIndex, Lazy!(mir::ConstQualifs)>,
rendered_const: Table<DefIndex, Lazy!(String)>,
asyncness: Table<DefIndex, Lazy!(hir::IsAsync)>,

trait_item_def_id: Table<DefIndex, Lazy<DefId>>,
inherent_impls: Table<DefIndex, Lazy<[DefIndex]>>,
Expand Down Expand Up @@ -361,7 +362,6 @@ enum EntryKind {

#[derive(MetadataEncodable, MetadataDecodable)]
struct FnData {
asyncness: hir::IsAsync,
constness: hir::Constness,
param_names: Lazy<[Ident]>,
}
Expand Down

0 comments on commit 6cc96a4

Please sign in to comment.