Skip to content

Commit

Permalink
Add EntryKind::TypeParam and EntryKind::ConstParam
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Mar 14, 2019
1 parent 7a23725 commit 6217ee1
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 21 deletions.
2 changes: 2 additions & 0 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,8 @@ impl<'tcx> EntryKind<'tcx> {
EntryKind::ForeignFn(_) => Def::Fn(did),
EntryKind::Method(_) => Def::Method(did),
EntryKind::Type => Def::TyAlias(did),
EntryKind::TypeParam => Def::TyParam(did),
EntryKind::ConstParam => Def::ConstParam(did),
EntryKind::Existential => Def::Existential(did),
EntryKind::AssociatedType(_) => Def::AssociatedTy(did),
EntryKind::AssociatedExistential(_) => Def::AssociatedExistential(did),
Expand Down
55 changes: 35 additions & 20 deletions src/librustc_metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1308,26 +1308,22 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
}
}

fn encode_info_for_ty_in_generic_param(
fn encode_info_for_generic_param(
&mut self,
(def_id, Untracked(encode_type)): (DefId, Untracked<bool>),
def_id: DefId,
entry_kind: EntryKind<'tcx>,
encode_type: bool,
) -> Entry<'tcx> {
debug!("IsolatedEncoder::encode_info_for_ty_in_generic_param({:?})", def_id);
let tcx = self.tcx;
Entry {
kind: EntryKind::Type,
kind: entry_kind,
visibility: self.lazy(&ty::Visibility::Public),
span: self.lazy(&tcx.def_span(def_id)),
attributes: LazySeq::empty(),
children: LazySeq::empty(),
stability: None,
deprecation: None,

ty: if encode_type {
Some(self.encode_item_type(def_id))
} else {
None
},
ty: if encode_type { Some(self.encode_item_type(def_id)) } else { None },
inherent_impls: LazySeq::empty(),
variances: LazySeq::empty(),
generics: None,
Expand All @@ -1338,6 +1334,22 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> {
}
}

fn encode_info_for_ty_param(
&mut self,
(def_id, Untracked(encode_type)): (DefId, Untracked<bool>),
) -> Entry<'tcx> {
debug!("IsolatedEncoder::encode_info_for_ty_param({:?})", def_id);
self.encode_info_for_generic_param(def_id, EntryKind::TypeParam, encode_type)
}

fn encode_info_for_const_param(
&mut self,
def_id: DefId,
) -> Entry<'tcx> {
debug!("IsolatedEncoder::encode_info_for_const_param({:?})", def_id);
self.encode_info_for_generic_param(def_id, EntryKind::ConstParam, true)
}

fn encode_info_for_closure(&mut self, def_id: DefId) -> Entry<'tcx> {
debug!("IsolatedEncoder::encode_info_for_closure({:?})", def_id);
let tcx = self.tcx;
Expand Down Expand Up @@ -1682,17 +1694,20 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> {

fn encode_info_for_generics(&mut self, generics: &hir::Generics) {
for param in &generics.params {
let encode_type = match param.kind {
GenericParamKind::Lifetime { .. } => continue,
GenericParamKind::Type { ref default, .. } => default.is_some(),
GenericParamKind::Const { .. } => true,
};
let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id);
self.record(
def_id,
IsolatedEncoder::encode_info_for_ty_in_generic_param,
(def_id, Untracked(encode_type)),
);
match param.kind {
GenericParamKind::Lifetime { .. } => continue,
GenericParamKind::Type { ref default, .. } => {
self.record(
def_id,
IsolatedEncoder::encode_info_for_ty_param,
(def_id, Untracked(default.is_some())),
);
}
GenericParamKind::Const { .. } => {
self.record(def_id, IsolatedEncoder::encode_info_for_const_param, def_id);
}
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/librustc_metadata/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,8 @@ pub enum EntryKind<'tcx> {
ForeignType,
GlobalAsm,
Type,
TypeParam,
ConstParam,
Existential,
Enum(ReprOptions),
Field,
Expand Down Expand Up @@ -335,7 +337,9 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for EntryKind<'gcx> {
EntryKind::ForeignType |
EntryKind::Field |
EntryKind::Existential |
EntryKind::Type => {
EntryKind::Type |
EntryKind::TypeParam |
EntryKind::ConstParam => {
// Nothing else to hash here.
}
EntryKind::Const(qualif, ref const_data) => {
Expand Down

0 comments on commit 6217ee1

Please sign in to comment.