Skip to content

Commit 377016c

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 86c447d + 4b06d1e commit 377016c

File tree

6 files changed

+76
-7
lines changed

6 files changed

+76
-7
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,7 @@ class BuiltinLiteralExpr : public LiteralExpr {
696696

697697
/// Set the builtin initializer that will be used to construct the
698698
/// literal.
699-
void setBuiltinInitializer(ConcreteDeclRef builtinInitializer) {
700-
BuiltinInitializer = builtinInitializer;
701-
}
699+
void setBuiltinInitializer(ConcreteDeclRef builtinInitializer);
702700
};
703701

704702
/// The 'nil' literal.

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ ASTMangler::mangleAnyDecl(const ValueDecl *Decl,
10061006

10071007
// We have a custom prefix, so finalize() won't verify for us. If we're not
10081008
// in invalid code (coming from an IDE caller) verify manually.
1009-
if (!Decl->isInvalid())
1009+
if (CONDITIONAL_ASSERT_enabled() && !prefix && !Decl->isInvalid())
10101010
verify(Storage.str(), Flavor);
10111011
return finalize();
10121012
}
@@ -1026,7 +1026,7 @@ std::string ASTMangler::mangleAccessorEntityAsUSR(AccessorKind kind,
10261026
appendAccessorEntity(getCodeForAccessorKind(kind), decl, isStatic);
10271027
// We have a custom prefix, so finalize() won't verify for us. If we're not
10281028
// in invalid code (coming from an IDE caller) verify manually.
1029-
if (!decl->isInvalid())
1029+
if (CONDITIONAL_ASSERT_enabled() && !decl->isInvalid())
10301030
verify(Storage.str().drop_front(USRPrefix.size()), Flavor);
10311031
return finalize();
10321032
}

lib/AST/Expr.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,14 @@ StringRef LiteralExpr::getLiteralKindDescription() const {
10891089
llvm_unreachable("Unhandled literal");
10901090
}
10911091

1092-
IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned(ASTContext &C, unsigned value, SourceLoc loc) {
1092+
void BuiltinLiteralExpr::setBuiltinInitializer(
1093+
ConcreteDeclRef builtinInitializer) {
1094+
ASSERT(builtinInitializer);
1095+
BuiltinInitializer = builtinInitializer;
1096+
}
1097+
1098+
IntegerLiteralExpr * IntegerLiteralExpr::createFromUnsigned(
1099+
ASTContext &C, unsigned value, SourceLoc loc) {
10931100
llvm::SmallString<8> Scratch;
10941101
llvm::APInt(sizeof(unsigned)*8, value).toString(Scratch, 10, /*signed*/ false);
10951102
auto Text = C.AllocateCopy(StringRef(Scratch));

lib/SILGen/SILGenApply.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1717,6 +1717,37 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
17171717
return false;
17181718
}
17191719

1720+
static bool addsNonIsolatedNonSendingToAsyncFn(FunctionConversionExpr *fce) {
1721+
CanType oldTy = fce->getSubExpr()->getType()->getCanonicalType();
1722+
CanType newTy = fce->getType()->getCanonicalType();
1723+
1724+
if (auto oldFnTy = dyn_cast<AnyFunctionType>(oldTy)) {
1725+
if (auto newFnTy = dyn_cast<AnyFunctionType>(newTy)) {
1726+
// old type and new type MUST both be async
1727+
if (!oldFnTy->hasEffect(EffectKind::Async) ||
1728+
!newFnTy->hasEffect(EffectKind::Async))
1729+
return false;
1730+
1731+
// old type MUST NOT have nonisolated(nonsending).
1732+
if (oldFnTy->getIsolation().isNonIsolatedCaller())
1733+
return false;
1734+
1735+
// new type MUST nonisolated(nonsending)
1736+
if (!newFnTy->getIsolation().isNonIsolatedCaller())
1737+
return false;
1738+
1739+
// See if setting isolation of old type to nonisolated(nonsending)
1740+
// yields the new type.
1741+
auto addedNonIsolatedNonSending = oldFnTy->getExtInfo().withIsolation(
1742+
FunctionTypeIsolation::forNonIsolatedCaller());
1743+
1744+
return oldFnTy->withExtInfo(addedNonIsolatedNonSending) == newFnTy;
1745+
}
1746+
}
1747+
1748+
return false;
1749+
}
1750+
17201751
/// Ignore parentheses and implicit conversions.
17211752
static Expr *ignoreParensAndImpConversions(Expr *expr) {
17221753
while (true) {
@@ -1737,6 +1768,8 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
17371768
if (auto funcConv = dyn_cast<FunctionConversionExpr>(nextSubExpr)) {
17381769
if (addsGlobalActorToAsyncFn(funcConv))
17391770
nextSubExpr = funcConv->getSubExpr();
1771+
else if (addsNonIsolatedNonSendingToAsyncFn(funcConv))
1772+
nextSubExpr = funcConv->getSubExpr();
17401773
}
17411774

17421775
if (auto bind = dyn_cast<BindOptionalExpr>(nextSubExpr)) {
@@ -1774,7 +1807,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
17741807

17751808
auto openExistential = dyn_cast<OpenExistentialExpr>(arg);
17761809
if (openExistential)
1777-
arg = openExistential->getSubExpr();
1810+
arg = ignoreParensAndImpConversions(openExistential->getSubExpr());
17781811

17791812
auto dynamicMemberRef = dyn_cast<DynamicMemberRefExpr>(arg);
17801813
if (!dynamicMemberRef)

test/Inputs/clang-importer-sdk/usr/include/ObjCConcurrency.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ typedef void (^NonsendableCompletionHandler)(NSString * _Nullable, NSString * _N
133133
(void (^)(NSString *__nullable value,
134134
NSError *__nullable error))completionHandler
135135
MAIN_ACTOR;
136+
137+
- (void)startAt:(__nullable NSDate *)value
138+
completion:(void (^_Nonnull)(void))completion;
136139
@end
137140

138141
@protocol RefrigeratorDelegate<NSObject>

test/SILGen/objc_async.swift

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,31 @@ extension SlowServer: @retroactive FailableFloatLoader {
360360
// CHECK-NEXT: [[ZERO_FLOAT:%.*]] = builtin "zeroInitializer"() : $Float
361361
// CHECK-NEXT: [[BORROWED_SOME_NSERROR:%.*]] = begin_borrow [[SOME_NSERROR]] :
362362
// CHECK-NEXT: apply [[BORROWED_BLOCK]]([[ZERO_FLOAT]], [[BORROWED_SOME_NSERROR]])
363+
364+
// CHECK-LABEL: sil hidden [ossa] @$s10objc_async13testAnyObjectyySo10SlowServerCYaF : $@convention(thin) @async (@guaranteed SlowServer) -> () {
365+
// CHECK: bb0([[SLOWSERVER:%.*]] : @guaranteed $SlowServer):
366+
// CHECK: [[SLOWSERVER_C:%.*]] = copy_value [[SLOWSERVER]]
367+
// CHECK: [[SLOWSERVER_ANYOBJECT:%.*]] = init_existential_ref [[SLOWSERVER_C]]
368+
// CHECK: [[SLOWSERVER_ANYOBJECT_M:%.*]] = move_value [lexical] [var_decl] [[SLOWSERVER_ANYOBJECT]]
369+
// CHECK: debug_value [[SLOWSERVER_ANYOBJECT_M]] : $AnyObject, let, name "anyObjectSlowServer"
370+
// CHECK: [[SLOWSERVER_ANYOBJECT_M_B:%.*]] = begin_borrow [[SLOWSERVER_ANYOBJECT_M]]
371+
// CHECK: [[SLOWSERVER_ANYOBJECT_M_B_O:%.*]] = open_existential_ref [[SLOWSERVER_ANYOBJECT_M_B]]
372+
// CHECK: [[SLOWSERVER_ANYOBJECT_M_B_O_C:%.*]] = copy_value [[SLOWSERVER_ANYOBJECT_M_B_O]]
373+
// CHECK: [[METHOD:%.*]] = objc_method [[SLOWSERVER_ANYOBJECT_M_B_O_C]] : $@opened("{{.*}}", AnyObject) Self, #SlowServer.start!foreign : (SlowServer) -> (NSDate?) async -> (), $@convention(objc_method) (Optional<NSDate>, @convention(block) @Sendable () -> (), @opened("{{.*}}", AnyObject) Self) -> ()
374+
// CHECK: [[CONT:%.*]] = get_async_continuation_addr ()
375+
// CHECK: [[UNSAFE_CONT:%.*]] = struct $UnsafeContinuation<(), Never> ([[CONT]] : $Builtin.RawUnsafeContinuation)
376+
// CHECK: [[BLOCK:%.*]] = alloc_stack $@block_storage Any
377+
// CHECK: [[BLOCK_PROJECT:%.*]] = project_block_storage [[BLOCK]]
378+
// CHECK: [[BLOCK_PROJECT_EX:%.*]] = init_existential_addr [[BLOCK_PROJECT]]
379+
// CHECK: store [[UNSAFE_CONT]] to [trivial] [[BLOCK_PROJECT_EX]]
380+
// CHECK: merge_isolation_region [[BLOCK]] : $*@block_storage Any,
381+
// CHECK: [[CONT_HANDLER:%.*]] = function_ref @$sIeyBh_ytTz_ : $@convention(c) @Sendable (@inout_aliasable @block_storage Any) -> ()
382+
// CHECK: [[INIT_BLOCK_STORAGE_HEADER:%.*]] = init_block_storage_header [[BLOCK]] : $*@block_storage Any, invoke [[CONT_HANDLER]]
383+
// CHECK: merge_isolation_region [[SLOWSERVER_ANYOBJECT_M_B_O_C]] : $@opened("{{.*}}", AnyObject) Self, [[BLOCK]]
384+
// CHECK: apply [[METHOD]]({{%.*}}, [[INIT_BLOCK_STORAGE_HEADER]], [[SLOWSERVER_ANYOBJECT_M_B_O_C]])
385+
// CHECK: await_async_continuation [[CONT]] : $Builtin.RawUnsafeContinuation, resume bb1
386+
// CHECK: } // end sil function '$s10objc_async13testAnyObjectyySo10SlowServerCYaF'
387+
func testAnyObject(_ slowServer: SlowServer) async {
388+
let anyObjectSlowServer: AnyObject = slowServer
389+
await anyObjectSlowServer.start(at: nil)
390+
}

0 commit comments

Comments
 (0)