mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
is_coroutine -> is_coroutine_or_closure
This commit is contained in:
parent
d59f06fc64
commit
07adee7072
@ -3067,7 +3067,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
|
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
|
||||||
// Define a fallback for when we can't match a closure.
|
// Define a fallback for when we can't match a closure.
|
||||||
let fallback = || {
|
let fallback = || {
|
||||||
let is_closure = self.infcx.tcx.is_closure(self.mir_def_id().to_def_id());
|
let is_closure = self.infcx.tcx.is_closure_or_coroutine(self.mir_def_id().to_def_id());
|
||||||
if is_closure {
|
if is_closure {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@ -3277,7 +3277,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||||||
sig: ty::PolyFnSig<'tcx>,
|
sig: ty::PolyFnSig<'tcx>,
|
||||||
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
|
) -> Option<AnnotatedBorrowFnSignature<'tcx>> {
|
||||||
debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig);
|
debug!("annotate_fn_sig: did={:?} sig={:?}", did, sig);
|
||||||
let is_closure = self.infcx.tcx.is_closure(did.to_def_id());
|
let is_closure = self.infcx.tcx.is_closure_or_coroutine(did.to_def_id());
|
||||||
let fn_hir_id = self.infcx.tcx.local_def_id_to_hir_id(did);
|
let fn_hir_id = self.infcx.tcx.local_def_id_to_hir_id(did);
|
||||||
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(fn_hir_id)?;
|
let fn_decl = self.infcx.tcx.hir().fn_decl_by_hir_id(fn_hir_id)?;
|
||||||
|
|
||||||
|
@ -22,7 +22,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
|
|||||||
#[instrument(skip(self, body), level = "debug")]
|
#[instrument(skip(self, body), level = "debug")]
|
||||||
pub(super) fn check_signature_annotation(&mut self, body: &Body<'tcx>) {
|
pub(super) fn check_signature_annotation(&mut self, body: &Body<'tcx>) {
|
||||||
let mir_def_id = body.source.def_id().expect_local();
|
let mir_def_id = body.source.def_id().expect_local();
|
||||||
if !self.tcx().is_closure(mir_def_id.to_def_id()) {
|
if !self.tcx().is_closure_or_coroutine(mir_def_id.to_def_id()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let user_provided_poly_sig = self.tcx().closure_user_provided_sig(mir_def_id);
|
let user_provided_poly_sig = self.tcx().closure_user_provided_sig(mir_def_id);
|
||||||
|
@ -481,7 +481,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
|
|||||||
// `+multivalue` feature because the purpose of the wasm abi is to match
|
// `+multivalue` feature because the purpose of the wasm abi is to match
|
||||||
// the WebAssembly specification, which has this feature. This won't be
|
// the WebAssembly specification, which has this feature. This won't be
|
||||||
// needed when LLVM enables this `multivalue` feature by default.
|
// needed when LLVM enables this `multivalue` feature by default.
|
||||||
if !cx.tcx.is_closure(instance.def_id()) {
|
if !cx.tcx.is_closure_or_coroutine(instance.def_id()) {
|
||||||
let abi = cx.tcx.fn_sig(instance.def_id()).skip_binder().abi();
|
let abi = cx.tcx.fn_sig(instance.def_id()).skip_binder().abi();
|
||||||
if abi == Abi::Wasm {
|
if abi == Abi::Wasm {
|
||||||
function_features.push("+multivalue".to_string());
|
function_features.push("+multivalue".to_string());
|
||||||
|
@ -232,7 +232,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
|||||||
}
|
}
|
||||||
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
|
sym::thread_local => codegen_fn_attrs.flags |= CodegenFnAttrFlags::THREAD_LOCAL,
|
||||||
sym::track_caller => {
|
sym::track_caller => {
|
||||||
let is_closure = tcx.is_closure(did.to_def_id());
|
let is_closure = tcx.is_closure_or_coroutine(did.to_def_id());
|
||||||
|
|
||||||
if !is_closure
|
if !is_closure
|
||||||
&& let Some(fn_sig) = fn_sig()
|
&& let Some(fn_sig) = fn_sig()
|
||||||
@ -277,7 +277,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sym::target_feature => {
|
sym::target_feature => {
|
||||||
if !tcx.is_closure(did.to_def_id())
|
if !tcx.is_closure_or_coroutine(did.to_def_id())
|
||||||
&& let Some(fn_sig) = fn_sig()
|
&& let Some(fn_sig) = fn_sig()
|
||||||
&& fn_sig.skip_binder().unsafety() == hir::Unsafety::Normal
|
&& fn_sig.skip_binder().unsafety() == hir::Unsafety::Normal
|
||||||
{
|
{
|
||||||
@ -531,7 +531,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
|
|||||||
// would result in this closure being compiled without the inherited target features, but this
|
// would result in this closure being compiled without the inherited target features, but this
|
||||||
// is probably a poor usage of `#[inline(always)]` and easily avoided by not using the attribute.
|
// is probably a poor usage of `#[inline(always)]` and easily avoided by not using the attribute.
|
||||||
if tcx.features().target_feature_11
|
if tcx.features().target_feature_11
|
||||||
&& tcx.is_closure(did.to_def_id())
|
&& tcx.is_closure_or_coroutine(did.to_def_id())
|
||||||
&& codegen_fn_attrs.inline != InlineAttr::Always
|
&& codegen_fn_attrs.inline != InlineAttr::Always
|
||||||
{
|
{
|
||||||
let owner_id = tcx.parent(did.to_def_id());
|
let owner_id = tcx.parent(did.to_def_id());
|
||||||
|
@ -72,7 +72,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
|
|||||||
|
|
||||||
pub fn fn_sig(&self) -> PolyFnSig<'tcx> {
|
pub fn fn_sig(&self) -> PolyFnSig<'tcx> {
|
||||||
let did = self.def_id().to_def_id();
|
let did = self.def_id().to_def_id();
|
||||||
if self.tcx.is_closure(did) {
|
if self.tcx.is_closure_or_coroutine(did) {
|
||||||
let ty = self.tcx.type_of(did).instantiate_identity();
|
let ty = self.tcx.type_of(did).instantiate_identity();
|
||||||
let ty::Closure(_, args) = ty.kind() else { bug!("type_of closure not ty::Closure") };
|
let ty::Closure(_, args) = ty.kind() else { bug!("type_of closure not ty::Closure") };
|
||||||
args.as_closure().sig()
|
args.as_closure().sig()
|
||||||
|
@ -125,7 +125,8 @@ pub(super) fn check_fn<'a, 'tcx>(
|
|||||||
// ty_span == binding_span iff this is a closure parameter with no type ascription,
|
// ty_span == binding_span iff this is a closure parameter with no type ascription,
|
||||||
// or if it's an implicit `self` parameter
|
// or if it's an implicit `self` parameter
|
||||||
traits::SizedArgumentType(
|
traits::SizedArgumentType(
|
||||||
if ty_span == Some(param.span) && tcx.is_closure(fn_def_id.into()) {
|
if ty_span == Some(param.span) && tcx.is_closure_or_coroutine(fn_def_id.into())
|
||||||
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
ty_span
|
ty_span
|
||||||
|
@ -150,7 +150,7 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherLocalsVisitor<'a, 'tcx> {
|
|||||||
// ascription, or if it's an implicit `self` parameter
|
// ascription, or if it's an implicit `self` parameter
|
||||||
traits::SizedArgumentType(
|
traits::SizedArgumentType(
|
||||||
if ty_span == ident.span
|
if ty_span == ident.span
|
||||||
&& self.fcx.tcx.is_closure(self.fcx.body_id.into())
|
&& self.fcx.tcx.is_closure_or_coroutine(self.fcx.body_id.into())
|
||||||
{
|
{
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -520,7 +520,7 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
|
|||||||
let kind = tcx.def_kind(def_id);
|
let kind = tcx.def_kind(def_id);
|
||||||
let is_function = match kind {
|
let is_function = match kind {
|
||||||
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) => true,
|
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) => true,
|
||||||
_ => tcx.is_closure(def_id),
|
_ => tcx.is_closure_or_coroutine(def_id),
|
||||||
};
|
};
|
||||||
match (kind, body.source.promoted) {
|
match (kind, body.source.promoted) {
|
||||||
(_, Some(i)) => write!(w, "{i:?} in ")?,
|
(_, Some(i)) => write!(w, "{i:?} in ")?,
|
||||||
|
@ -197,7 +197,7 @@ pub struct ClosureTypeInfo<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn closure_typeinfo<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ClosureTypeInfo<'tcx> {
|
fn closure_typeinfo<'tcx>(tcx: TyCtxt<'tcx>, def: LocalDefId) -> ClosureTypeInfo<'tcx> {
|
||||||
debug_assert!(tcx.is_closure(def.to_def_id()));
|
debug_assert!(tcx.is_closure_or_coroutine(def.to_def_id()));
|
||||||
let typeck_results = tcx.typeck(def);
|
let typeck_results = tcx.typeck(def);
|
||||||
let user_provided_sig = typeck_results.user_provided_sigs[&def];
|
let user_provided_sig = typeck_results.user_provided_sigs[&def];
|
||||||
let captures = typeck_results.closure_min_captures_flattened(def);
|
let captures = typeck_results.closure_min_captures_flattened(def);
|
||||||
@ -217,7 +217,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn closure_captures(self, def_id: LocalDefId) -> &'tcx [&'tcx ty::CapturedPlace<'tcx>] {
|
pub fn closure_captures(self, def_id: LocalDefId) -> &'tcx [&'tcx ty::CapturedPlace<'tcx>] {
|
||||||
if !self.is_closure(def_id.to_def_id()) {
|
if !self.is_closure_or_coroutine(def_id.to_def_id()) {
|
||||||
return &[];
|
return &[];
|
||||||
};
|
};
|
||||||
self.closure_typeinfo(def_id).captures
|
self.closure_typeinfo(def_id).captures
|
||||||
|
@ -426,7 +426,10 @@ impl<'tcx> Instance<'tcx> {
|
|||||||
) -> Option<Instance<'tcx>> {
|
) -> Option<Instance<'tcx>> {
|
||||||
debug!("resolve(def_id={:?}, args={:?})", def_id, args);
|
debug!("resolve(def_id={:?}, args={:?})", def_id, args);
|
||||||
// Use either `resolve_closure` or `resolve_for_vtable`
|
// Use either `resolve_closure` or `resolve_for_vtable`
|
||||||
assert!(!tcx.is_closure(def_id), "Called `resolve_for_fn_ptr` on closure: {def_id:?}");
|
assert!(
|
||||||
|
!tcx.is_closure_or_coroutine(def_id),
|
||||||
|
"Called `resolve_for_fn_ptr` on closure: {def_id:?}"
|
||||||
|
);
|
||||||
Instance::resolve(tcx, param_env, def_id, args).ok().flatten().map(|mut resolved| {
|
Instance::resolve(tcx, param_env, def_id, args).ok().flatten().map(|mut resolved| {
|
||||||
match resolved.def {
|
match resolved.def {
|
||||||
InstanceDef::Item(def) if resolved.def.requires_caller_location(tcx) => {
|
InstanceDef::Item(def) if resolved.def.requires_caller_location(tcx) => {
|
||||||
@ -488,7 +491,7 @@ impl<'tcx> Instance<'tcx> {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if tcx.is_closure(def) {
|
if tcx.is_closure_or_coroutine(def) {
|
||||||
debug!(" => vtable fn pointer created for closure with #[track_caller]: {:?} for method {:?} {:?}",
|
debug!(" => vtable fn pointer created for closure with #[track_caller]: {:?} for method {:?} {:?}",
|
||||||
def, def_id, args);
|
def, def_id, args);
|
||||||
|
|
||||||
@ -658,7 +661,7 @@ fn polymorphize<'tcx>(
|
|||||||
// the unpolymorphized upvar closure would result in a polymorphized closure producing
|
// the unpolymorphized upvar closure would result in a polymorphized closure producing
|
||||||
// multiple mono items (and eventually symbol clashes).
|
// multiple mono items (and eventually symbol clashes).
|
||||||
let def_id = instance.def_id();
|
let def_id = instance.def_id();
|
||||||
let upvars_ty = if tcx.is_closure(def_id) {
|
let upvars_ty = if tcx.is_closure_or_coroutine(def_id) {
|
||||||
Some(args.as_closure().tupled_upvars_ty())
|
Some(args.as_closure().tupled_upvars_ty())
|
||||||
} else if tcx.type_of(def_id).skip_binder().is_coroutine() {
|
} else if tcx.type_of(def_id).skip_binder().is_coroutine() {
|
||||||
Some(args.as_coroutine().tupled_upvars_ty())
|
Some(args.as_coroutine().tupled_upvars_ty())
|
||||||
|
@ -547,7 +547,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
/// closure appears (and, sadly, a corresponding `NodeId`, since
|
/// closure appears (and, sadly, a corresponding `NodeId`, since
|
||||||
/// those are not yet phased out). The parent of the closure's
|
/// those are not yet phased out). The parent of the closure's
|
||||||
/// `DefId` will also be the context where it appears.
|
/// `DefId` will also be the context where it appears.
|
||||||
pub fn is_closure(self, def_id: DefId) -> bool {
|
pub fn is_closure_or_coroutine(self, def_id: DefId) -> bool {
|
||||||
matches!(self.def_kind(def_id), DefKind::Closure)
|
matches!(self.def_kind(def_id), DefKind::Closure)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -345,7 +345,7 @@ fn get_body_span<'tcx>(
|
|||||||
) -> Span {
|
) -> Span {
|
||||||
let mut body_span = hir_body.value.span;
|
let mut body_span = hir_body.value.span;
|
||||||
|
|
||||||
if tcx.is_closure(def_id.to_def_id()) {
|
if tcx.is_closure_or_coroutine(def_id.to_def_id()) {
|
||||||
// If the current function is a closure, and its "body" span was created
|
// If the current function is a closure, and its "body" span was created
|
||||||
// by macro expansion or compiler desugaring, try to walk backwards to
|
// by macro expansion or compiler desugaring, try to walk backwards to
|
||||||
// the pre-expansion call site or body.
|
// the pre-expansion call site or body.
|
||||||
|
@ -74,7 +74,7 @@ fn bcb_to_initial_coverage_spans<'a, 'tcx>(
|
|||||||
let expn_span = filtered_statement_span(statement)?;
|
let expn_span = filtered_statement_span(statement)?;
|
||||||
let span = unexpand_into_body_span(expn_span, body_span)?;
|
let span = unexpand_into_body_span(expn_span, body_span)?;
|
||||||
|
|
||||||
Some(CoverageSpan::new(span, expn_span, bcb, is_closure(statement)))
|
Some(CoverageSpan::new(span, expn_span, bcb, is_closure_or_coroutine(statement)))
|
||||||
});
|
});
|
||||||
|
|
||||||
let terminator_span = Some(data.terminator()).into_iter().filter_map(move |terminator| {
|
let terminator_span = Some(data.terminator()).into_iter().filter_map(move |terminator| {
|
||||||
@ -88,7 +88,7 @@ fn bcb_to_initial_coverage_spans<'a, 'tcx>(
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_closure(statement: &Statement<'_>) -> bool {
|
fn is_closure_or_coroutine(statement: &Statement<'_>) -> bool {
|
||||||
match statement.kind {
|
match statement.kind {
|
||||||
StatementKind::Assign(box (_, Rvalue::Aggregate(box ref agg_kind, _))) => match agg_kind {
|
StatementKind::Assign(box (_, Rvalue::Aggregate(box ref agg_kind, _))) => match agg_kind {
|
||||||
AggregateKind::Closure(_, _) | AggregateKind::Coroutine(_, _) => true,
|
AggregateKind::Closure(_, _) | AggregateKind::Coroutine(_, _) => true,
|
||||||
|
@ -1119,7 +1119,10 @@ fn create_fn_mono_item<'tcx>(
|
|||||||
source: Span,
|
source: Span,
|
||||||
) -> Spanned<MonoItem<'tcx>> {
|
) -> Spanned<MonoItem<'tcx>> {
|
||||||
let def_id = instance.def_id();
|
let def_id = instance.def_id();
|
||||||
if tcx.sess.opts.unstable_opts.profile_closures && def_id.is_local() && tcx.is_closure(def_id) {
|
if tcx.sess.opts.unstable_opts.profile_closures
|
||||||
|
&& def_id.is_local()
|
||||||
|
&& tcx.is_closure_or_coroutine(def_id)
|
||||||
|
{
|
||||||
crate::util::dump_closure_profile(tcx, instance);
|
crate::util::dump_closure_profile(tcx, instance);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ use rustc_span::Span;
|
|||||||
|
|
||||||
pub fn provide(providers: &mut Providers) {
|
pub fn provide(providers: &mut Providers) {
|
||||||
providers.upvars_mentioned = |tcx, def_id| {
|
providers.upvars_mentioned = |tcx, def_id| {
|
||||||
if !tcx.is_closure(def_id) {
|
if !tcx.is_closure_or_coroutine(def_id) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user