Skip to content

Commit

Permalink
InstanceDef -> InstanceKind
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Jun 19, 2024
1 parent 94ddc55 commit 6bc4527
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 66 deletions.
30 changes: 15 additions & 15 deletions src/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ impl<'tcx> AnalysisCtxt<'tcx> {
}
}

pub fn analysis_instance_mir(&self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> {
pub fn analysis_instance_mir(&self, instance: ty::InstanceKind<'tcx>) -> &'tcx Body<'tcx> {
match instance {
ty::InstanceDef::Item(did) => {
ty::InstanceKind::Item(did) => {
let def_kind = self.def_kind(did);
match def_kind {
DefKind::Const
Expand All @@ -198,19 +198,19 @@ impl<'tcx> AnalysisCtxt<'tcx> {
_ => self.analysis_mir(did),
}
}
ty::InstanceDef::VTableShim(..)
| ty::InstanceDef::ReifyShim(..)
| ty::InstanceDef::Intrinsic(..)
| ty::InstanceDef::FnPtrShim(..)
| ty::InstanceDef::Virtual(..)
| ty::InstanceDef::ClosureOnceShim { .. }
| ty::InstanceDef::ConstructCoroutineInClosureShim { .. }
| ty::InstanceDef::CoroutineKindShim { .. }
| ty::InstanceDef::DropGlue(..)
| ty::InstanceDef::CloneShim(..)
| ty::InstanceDef::ThreadLocalShim(..)
| ty::InstanceDef::FnPtrAddrShim(..)
| ty::InstanceDef::AsyncDropGlueCtorShim(..) => self.mir_shims(instance),
ty::InstanceKind::VTableShim(..)
| ty::InstanceKind::ReifyShim(..)
| ty::InstanceKind::Intrinsic(..)
| ty::InstanceKind::FnPtrShim(..)
| ty::InstanceKind::Virtual(..)
| ty::InstanceKind::ClosureOnceShim { .. }
| ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
| ty::InstanceKind::CoroutineKindShim { .. }
| ty::InstanceKind::DropGlue(..)
| ty::InstanceKind::CloneShim(..)
| ty::InstanceKind::ThreadLocalShim(..)
| ty::InstanceKind::FnPtrAddrShim(..)
| ty::InstanceKind::AsyncDropGlueCtorShim(..) => self.mir_shims(instance),
}
}
}
2 changes: 1 addition & 1 deletion src/mir/drop_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn build_drop_shim<'tcx>(
);
block(&mut blocks, TerminatorKind::Return);

let source = MirSource::from_instance(ty::InstanceDef::DropGlue(def_id, Some(ty)));
let source = MirSource::from_instance(ty::InstanceKind::DropGlue(def_id, Some(ty)));
let mut body = new_body(
source,
blocks,
Expand Down
28 changes: 14 additions & 14 deletions src/monomorphize_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,31 +727,31 @@ fn visit_instance_use<'tcx>(
);

match instance.def {
ty::InstanceDef::Virtual(..) | ty::InstanceDef::Intrinsic(_) => {
ty::InstanceKind::Virtual(..) | ty::InstanceKind::Intrinsic(_) => {
if !is_direct_call {
bug!("{:?} being reified", instance);
}
}
ty::InstanceDef::ThreadLocalShim(..) => {
ty::InstanceKind::ThreadLocalShim(..) => {
bug!("{:?} being reified", instance);
}
ty::InstanceDef::DropGlue(_, None) | ty::InstanceDef::AsyncDropGlueCtorShim(_, None) => {
ty::InstanceKind::DropGlue(_, None) | ty::InstanceKind::AsyncDropGlueCtorShim(_, None) => {
// Don't need to emit noop drop glue if we are calling directly.
if !is_direct_call {
output.push(create_fn_mono_item(tcx, instance, source));
}
}
ty::InstanceDef::DropGlue(_, Some(_))
| ty::InstanceDef::AsyncDropGlueCtorShim(_, Some(_))
| ty::InstanceDef::VTableShim(..)
| ty::InstanceDef::ReifyShim(..)
| ty::InstanceDef::ClosureOnceShim { .. }
| ty::InstanceDef::ConstructCoroutineInClosureShim { .. }
| ty::InstanceDef::CoroutineKindShim { .. }
| ty::InstanceDef::Item(..)
| ty::InstanceDef::FnPtrShim(..)
| ty::InstanceDef::CloneShim(..)
| ty::InstanceDef::FnPtrAddrShim(..) => {
ty::InstanceKind::DropGlue(_, Some(_))
| ty::InstanceKind::AsyncDropGlueCtorShim(_, Some(_))
| ty::InstanceKind::VTableShim(..)
| ty::InstanceKind::ReifyShim(..)
| ty::InstanceKind::ClosureOnceShim { .. }
| ty::InstanceKind::ConstructCoroutineInClosureShim { .. }
| ty::InstanceKind::CoroutineKindShim { .. }
| ty::InstanceKind::Item(..)
| ty::InstanceKind::FnPtrShim(..)
| ty::InstanceKind::CloneShim(..)
| ty::InstanceKind::FnPtrAddrShim(..) => {
output.push(create_fn_mono_item(tcx, instance, source));
}
}
Expand Down
28 changes: 15 additions & 13 deletions src/preempt_count/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ memoize!(

assert!(matches!(
instance.def,
ty::InstanceDef::DropGlue(_, Some(_))
ty::InstanceKind::DropGlue(_, Some(_))
));

if cx
Expand Down Expand Up @@ -590,7 +590,7 @@ memoize!(

assert!(matches!(
instance.def,
ty::InstanceDef::DropGlue(_, Some(_))
ty::InstanceKind::DropGlue(_, Some(_))
));

let mir = crate::mir::drop_shim::build_drop_shim(cx, instance.def_id(), param_env, ty);
Expand Down Expand Up @@ -622,11 +622,13 @@ memoize!(
let (param_env, instance) = poly_instance.into_parts();
match instance.def {
// No Rust built-in intrinsics will mess with preemption count.
ty::InstanceDef::Intrinsic(_) => return Ok(0),
ty::InstanceKind::Intrinsic(_) => return Ok(0),
// Empty drop glue, then it definitely won't mess with preemption count.
ty::InstanceDef::DropGlue(_, None) => return Ok(0),
ty::InstanceDef::DropGlue(_, Some(ty)) => return cx.drop_adjustment(param_env.and(ty)),
ty::InstanceDef::Virtual(def_id, _) => {
ty::InstanceKind::DropGlue(_, None) => return Ok(0),
ty::InstanceKind::DropGlue(_, Some(ty)) => {
return cx.drop_adjustment(param_env.and(ty))
}
ty::InstanceKind::Virtual(def_id, _) => {
if let Some(adj) = cx.preemption_count_annotation(def_id).adjustment {
return Ok(adj);
}
Expand All @@ -637,7 +639,7 @@ memoize!(
}

let mut generic = false;
if matches!(instance.def, ty::InstanceDef::Item(_)) {
if matches!(instance.def, ty::InstanceKind::Item(_)) {
let poly_param_env = cx.param_env_reveal_all_normalized(instance.def_id());
let poly_args =
cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, instance.def_id()));
Expand Down Expand Up @@ -779,19 +781,19 @@ memoize!(

match instance.def {
// No Rust built-in intrinsics will mess with preemption count.
ty::InstanceDef::Intrinsic(_) => return Ok(()),
ty::InstanceKind::Intrinsic(_) => return Ok(()),
// Empty drop glue, then it definitely won't mess with preemption count.
ty::InstanceDef::DropGlue(_, None) => return Ok(()),
ty::InstanceDef::DropGlue(_, Some(ty)) => {
ty::InstanceKind::DropGlue(_, None) => return Ok(()),
ty::InstanceKind::DropGlue(_, Some(ty)) => {
return cx.drop_adjustment_check(param_env.and(ty));
}
// Checked by indirect checks
ty::InstanceDef::Virtual(_, _) => return Ok(()),
ty::InstanceKind::Virtual(_, _) => return Ok(()),
_ => (),
}

// Prefer to do polymorphic check if possible.
if matches!(instance.def, ty::InstanceDef::Item(_)) {
if matches!(instance.def, ty::InstanceKind::Item(_)) {
let poly_param_env = cx.param_env_reveal_all_normalized(instance.def_id());
let poly_args =
cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, instance.def_id()));
Expand Down Expand Up @@ -835,7 +837,7 @@ memoize!(
}

// Addition check for trait impl methods.
if matches!(instance.def, ty::InstanceDef::Item(_))
if matches!(instance.def, ty::InstanceKind::Item(_))
&& let Some(impl_) = cx.impl_of_method(instance.def_id())
&& let Some(trait_) = cx.trait_id_of_impl(impl_)
{
Expand Down
12 changes: 6 additions & 6 deletions src/preempt_count/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ memoize!(

assert!(matches!(
instance.def,
ty::InstanceDef::DropGlue(_, Some(_))
ty::InstanceKind::DropGlue(_, Some(_))
));

if cx
Expand Down Expand Up @@ -757,16 +757,16 @@ memoize!(

match instance.def {
// Rust built-in intrinsics does not refer to anything else.
ty::InstanceDef::Intrinsic(_) => return Ok(()),
ty::InstanceKind::Intrinsic(_) => return Ok(()),
// Empty drop glue, then it is a no-op.
ty::InstanceDef::DropGlue(_, None) => return Ok(()),
ty::InstanceDef::DropGlue(_, Some(ty)) => return cx.drop_check(param_env.and(ty)),
ty::InstanceKind::DropGlue(_, None) => return Ok(()),
ty::InstanceKind::DropGlue(_, Some(ty)) => return cx.drop_check(param_env.and(ty)),
// Can't check further here. Will be checked at vtable generation site.
ty::InstanceDef::Virtual(_, _) => return Ok(()),
ty::InstanceKind::Virtual(_, _) => return Ok(()),
_ => (),
}

if matches!(instance.def, ty::InstanceDef::Item(_)) {
if matches!(instance.def, ty::InstanceKind::Item(_)) {
let poly_param_env = cx.param_env_reveal_all_normalized(instance.def_id());
let poly_args =
cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, instance.def_id()));
Expand Down
34 changes: 17 additions & 17 deletions src/preempt_count/expectation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ impl<'tcx> AnalysisCtxt<'tcx> {
) -> Result<(), Error> {
match instance.def {
// No Rust built-in intrinsics will mess with preemption count.
ty::InstanceDef::Intrinsic(_) => unreachable!(),
ty::InstanceKind::Intrinsic(_) => unreachable!(),
// Empty drop glue, then it definitely won't mess with preemption count.
ty::InstanceDef::DropGlue(_, None) => unreachable!(),
ty::InstanceDef::DropGlue(_, Some(ty)) => {
ty::InstanceKind::DropGlue(_, None) => unreachable!(),
ty::InstanceKind::DropGlue(_, Some(ty)) => {
return self.report_drop_expectation_error(param_env, ty, expected, span, diag);
}
// Checked by indirect checks
ty::InstanceDef::Virtual(def_id, _) => {
ty::InstanceKind::Virtual(def_id, _) => {
let exp = self
.preemption_count_annotation(def_id)
.expectation
Expand Down Expand Up @@ -808,7 +808,7 @@ memoize!(

assert!(matches!(
instance.def,
ty::InstanceDef::DropGlue(_, Some(_))
ty::InstanceKind::DropGlue(_, Some(_))
));

if cx
Expand Down Expand Up @@ -930,7 +930,7 @@ memoize!(

assert!(matches!(
instance.def,
ty::InstanceDef::DropGlue(_, Some(_))
ty::InstanceKind::DropGlue(_, Some(_))
));

let mir = crate::mir::drop_shim::build_drop_shim(cx, instance.def_id(), param_env, ty);
Expand Down Expand Up @@ -963,13 +963,13 @@ memoize!(
let (param_env, instance) = poly_instance.into_parts();
match instance.def {
// No Rust built-in intrinsics will mess with preemption count.
ty::InstanceDef::Intrinsic(_) => return Ok(ExpectationRange::top()),
ty::InstanceKind::Intrinsic(_) => return Ok(ExpectationRange::top()),
// Empty drop glue, then it definitely won't mess with preemption count.
ty::InstanceDef::DropGlue(_, None) => return Ok(ExpectationRange::top()),
ty::InstanceDef::DropGlue(_, Some(ty)) => {
ty::InstanceKind::DropGlue(_, None) => return Ok(ExpectationRange::top()),
ty::InstanceKind::DropGlue(_, Some(ty)) => {
return cx.drop_expectation(param_env.and(ty))
}
ty::InstanceDef::Virtual(def_id, _) => {
ty::InstanceKind::Virtual(def_id, _) => {
if let Some(exp) = cx.preemption_count_annotation(def_id).expectation {
return Ok(exp);
}
Expand All @@ -980,7 +980,7 @@ memoize!(
}

let mut generic = false;
if matches!(instance.def, ty::InstanceDef::Item(_)) {
if matches!(instance.def, ty::InstanceKind::Item(_)) {
let poly_param_env = cx.param_env_reveal_all_normalized(instance.def_id());
let poly_args =
cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, instance.def_id()));
Expand Down Expand Up @@ -1123,19 +1123,19 @@ memoize!(

match instance.def {
// No Rust built-in intrinsics will mess with preemption count.
ty::InstanceDef::Intrinsic(_) => return Ok(()),
ty::InstanceKind::Intrinsic(_) => return Ok(()),
// Empty drop glue, then it definitely won't mess with preemption count.
ty::InstanceDef::DropGlue(_, None) => return Ok(()),
ty::InstanceDef::DropGlue(_, Some(ty)) => {
ty::InstanceKind::DropGlue(_, None) => return Ok(()),
ty::InstanceKind::DropGlue(_, Some(ty)) => {
return cx.drop_expectation_check(param_env.and(ty))
}
// Checked by indirect checks
ty::InstanceDef::Virtual(_, _) => return Ok(()),
ty::InstanceKind::Virtual(_, _) => return Ok(()),
_ => (),
}

// Prefer to do polymorphic check if possible.
if matches!(instance.def, ty::InstanceDef::Item(_)) {
if matches!(instance.def, ty::InstanceKind::Item(_)) {
let poly_param_env = cx.param_env_reveal_all_normalized(instance.def_id());
let poly_args =
cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, instance.def_id()));
Expand Down Expand Up @@ -1197,7 +1197,7 @@ memoize!(
}

// Addition check for trait impl methods.
if matches!(instance.def, ty::InstanceDef::Item(_))
if matches!(instance.def, ty::InstanceKind::Item(_))
&& let Some(impl_) = cx.impl_of_method(instance.def_id())
&& let Some(trait_) = cx.trait_id_of_impl(impl_)
{
Expand Down

0 comments on commit 6bc4527

Please sign in to comment.