Skip to content

Commit 89c8005

Browse files
committed
Merge remote-tracking branch 'origin/main' into rebranch
2 parents 601af13 + 186493e commit 89c8005

20 files changed

+255
-48
lines changed

include/swift/ABI/Task.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -343,16 +343,16 @@ class AsyncTask : public HeapObject, public Job {
343343
};
344344

345345
struct GroupStatus {
346-
static const unsigned long maskReady = 0x00FFFFF0000000000l;
347-
static const unsigned long oneReadyTask = 0x00000010000000000l;
346+
static const unsigned long long maskReady = 0x00FFFFF0000000000ll;
347+
static const unsigned long long oneReadyTask = 0x00000010000000000ll;
348348

349-
static const unsigned long maskPending = 0x0000000FFFFF00000l;
350-
static const unsigned long onePendingTask = 0x00000000000100000l;
349+
static const unsigned long long maskPending = 0x0000000FFFFF00000ll;
350+
static const unsigned long long onePendingTask = 0x00000000000100000ll;
351351

352-
static const unsigned long maskWaiting = 0x000000000000FFFFFl;
353-
static const unsigned long oneWaitingTask = 0x00000000000000001l;
352+
static const unsigned long long maskWaiting = 0x000000000000FFFFFll;
353+
static const unsigned long long oneWaitingTask = 0x00000000000000001ll;
354354

355-
unsigned long status;
355+
unsigned long long status;
356356

357357
unsigned int readyTasks() {
358358
return (status & maskReady) >> 40;
@@ -436,7 +436,7 @@ class AsyncTask : public HeapObject, public Job {
436436
mutable std::mutex mutex;
437437

438438
/// Used for queue management, counting number of waiting and ready tasks
439-
std::atomic<unsigned long> status;
439+
std::atomic<unsigned long long> status;
440440

441441
/// Queue containing completed tasks offered into this channel.
442442
///

include/swift/IRGen/Linking.h

Lines changed: 80 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,24 @@ class LinkEntity {
130130
/// is a ConstructorDecl* inside a class.
131131
DispatchThunkInitializer,
132132

133-
/// A method dispatch thunk for an allocating constructor. The pointer is a
134-
/// ConstructorDecl* inside a protocol or a class.
133+
/// A method dispatch thunk for an allocating constructor. The pointer is
134+
/// a ConstructorDecl* inside a protocol or a class.
135135
DispatchThunkAllocator,
136136

137+
/// An async function pointer for a method dispatch thunk. The pointer is
138+
/// a FuncDecl* inside a protocol or a class.
139+
DispatchThunkAsyncFunctionPointer,
140+
141+
/// An async function pointer for a method dispatch thunk for an
142+
/// initializing constructor. The pointer is a ConstructorDecl* inside a
143+
/// class.
144+
DispatchThunkInitializerAsyncFunctionPointer,
145+
146+
/// An async function pointer for a method dispatch thunk for an allocating
147+
/// constructor. The pointer is a ConstructorDecl* inside a protocol or
148+
/// a class.
149+
DispatchThunkAllocatorAsyncFunctionPointer,
150+
137151
/// A method descriptor. The pointer is a FuncDecl* inside a protocol
138152
/// or a class.
139153
MethodDescriptor,
@@ -295,7 +309,7 @@ class LinkEntity {
295309

296310
/// The same as AsyncFunctionPointer but with a different stored value, for
297311
/// use by TBDGen.
298-
/// The pointer is a AbstractStorageDecl*.
312+
/// The pointer is an AbstractFunctionDecl*.
299313
AsyncFunctionPointerAST,
300314

301315
/// The pointer is a SILFunction*.
@@ -861,7 +875,8 @@ class LinkEntity {
861875
}
862876

863877
static LinkEntity
864-
forSILFunction(SILFunction *F, bool IsDynamicallyReplaceableImplementation) {
878+
forSILFunction(SILFunction *F,
879+
bool IsDynamicallyReplaceableImplementation=false) {
865880
LinkEntity entity;
866881
entity.Pointer = F;
867882
entity.SecondaryPointer = nullptr;
@@ -1100,12 +1115,36 @@ class LinkEntity {
11001115
return entity;
11011116
}
11021117

1103-
static LinkEntity forAsyncFunctionPointer(SILFunction *silFunction) {
1118+
static LinkEntity forAsyncFunctionPointer(LinkEntity other) {
11041119
LinkEntity entity;
1105-
entity.Pointer = silFunction;
1120+
entity.Pointer = other.Pointer;
11061121
entity.SecondaryPointer = nullptr;
1107-
entity.Data = LINKENTITY_SET_FIELD(
1108-
Kind, unsigned(LinkEntity::Kind::AsyncFunctionPointer));
1122+
1123+
switch (other.getKind()) {
1124+
case LinkEntity::Kind::SILFunction:
1125+
entity.Data = LINKENTITY_SET_FIELD(
1126+
Kind, unsigned(LinkEntity::Kind::AsyncFunctionPointer));
1127+
break;
1128+
1129+
case LinkEntity::Kind::DispatchThunk:
1130+
entity.Data = LINKENTITY_SET_FIELD(
1131+
Kind, unsigned(LinkEntity::Kind::DispatchThunkAsyncFunctionPointer));
1132+
break;
1133+
1134+
case LinkEntity::Kind::DispatchThunkInitializer:
1135+
entity.Data = LINKENTITY_SET_FIELD(
1136+
Kind, unsigned(LinkEntity::Kind::DispatchThunkInitializerAsyncFunctionPointer));
1137+
break;
1138+
1139+
case LinkEntity::Kind::DispatchThunkAllocator:
1140+
entity.Data = LINKENTITY_SET_FIELD(
1141+
Kind, unsigned(LinkEntity::Kind::DispatchThunkAllocatorAsyncFunctionPointer));
1142+
break;
1143+
1144+
default:
1145+
llvm_unreachable("Link entity kind cannot have an async function pointer");
1146+
}
1147+
11091148
return entity;
11101149
}
11111150

@@ -1115,6 +1154,39 @@ class LinkEntity {
11151154
return entity;
11161155
}
11171156

1157+
LinkEntity getUnderlyingEntityForAsyncFunctionPointer() const {
1158+
LinkEntity entity;
1159+
entity.Pointer = Pointer;
1160+
entity.SecondaryPointer = nullptr;
1161+
1162+
switch (getKind()) {
1163+
case LinkEntity::Kind::AsyncFunctionPointer:
1164+
entity.Data = LINKENTITY_SET_FIELD(
1165+
Kind, unsigned(LinkEntity::Kind::SILFunction));
1166+
break;
1167+
1168+
case LinkEntity::Kind::DispatchThunkAsyncFunctionPointer:
1169+
entity.Data = LINKENTITY_SET_FIELD(
1170+
Kind, unsigned(LinkEntity::Kind::DispatchThunk));
1171+
break;
1172+
1173+
case LinkEntity::Kind::DispatchThunkInitializerAsyncFunctionPointer:
1174+
entity.Data = LINKENTITY_SET_FIELD(
1175+
Kind, unsigned(LinkEntity::Kind::DispatchThunkInitializer));
1176+
break;
1177+
1178+
case LinkEntity::Kind::DispatchThunkAllocatorAsyncFunctionPointer:
1179+
entity.Data = LINKENTITY_SET_FIELD(
1180+
Kind, unsigned(LinkEntity::Kind::DispatchThunkAllocator));
1181+
break;
1182+
1183+
default:
1184+
llvm_unreachable("Link entity is not an async function pointer");
1185+
}
1186+
1187+
return entity;
1188+
}
1189+
11181190
void mangle(llvm::raw_ostream &out) const;
11191191
void mangle(SmallVectorImpl<char> &buffer) const;
11201192
std::string mangleAsString() const;

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ void swift::ide::printModuleInterface(
609609
}
610610

611611
auto ShouldPrintImport = [&](ImportDecl *ImportD) -> bool {
612+
if (ImportD->getAttrs().hasAttribute<ImplementationOnlyAttr>())
613+
return false;
614+
612615
if (!TargetClangMod)
613616
return true;
614617
if (ImportD->getModule() == TargetMod)

lib/IRGen/Callee.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ namespace irgen {
174174

175175
// Temporary only!
176176
explicit FunctionPointer(KindTy kind, llvm::Value *value,
177-
const Signature &signature, bool
178-
isWithoutCtxt = false)
177+
const Signature &signature,
178+
bool isWithoutCtxt = false)
179179
: FunctionPointer(kind, value, PointerAuthInfo(), signature, isWithoutCtxt) {}
180180

181181
static FunctionPointer forDirect(IRGenModule &IGM,

lib/IRGen/GenCall.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "swift/AST/ASTContext.h"
2121
#include "swift/AST/GenericEnvironment.h"
2222
#include "swift/Runtime/Config.h"
23+
#include "swift/IRGen/Linking.h"
2324
#include "swift/SIL/SILModule.h"
2425
#include "swift/SIL/SILType.h"
2526
#include "clang/AST/ASTContext.h"
@@ -379,7 +380,7 @@ llvm::CallInst *IRGenFunction::emitSuspendAsyncCall(ArrayRef<llvm::Value *> args
379380
auto *calleeContext = Builder.CreateExtractValue(id,
380381
(unsigned)AsyncFunctionArgumentIndex::Context);
381382
llvm::Constant *projectFn = cast<llvm::Constant>(args[1])->stripPointerCasts();
382-
// Get the caller context from the calle context.
383+
// Get the caller context from the callee context.
383384
llvm::Value *context = Builder.CreateCall(projectFn, {calleeContext});
384385
context = Builder.CreateBitCast(context, IGM.SwiftContextPtrTy);
385386
Builder.CreateStore(context, asyncContextLocation);
@@ -3640,9 +3641,10 @@ emitRetconCoroutineEntry(IRGenFunction &IGF, CanSILFunctionType fnType,
36403641
}
36413642

36423643
void irgen::emitAsyncFunctionEntry(IRGenFunction &IGF,
3643-
SILFunction *asyncFunction) {
3644+
const AsyncContextLayout &layout,
3645+
LinkEntity asyncFunction) {
36443646
auto &IGM = IGF.IGM;
3645-
auto size = getAsyncContextLayout(IGM, asyncFunction).getSize();
3647+
auto size = layout.getSize();
36463648
auto asyncFuncPointer = IGF.Builder.CreateBitOrPointerCast(
36473649
IGM.getAddrOfAsyncFunctionPointer(asyncFunction), IGM.Int8PtrTy);
36483650
auto *id = IGF.Builder.CreateIntrinsicCall(

lib/IRGen/GenCall.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,9 @@ namespace irgen {
415415
Address emitAllocAsyncContext(IRGenFunction &IGF, llvm::Value *sizeValue);
416416
void emitDeallocAsyncContext(IRGenFunction &IGF, Address context);
417417

418-
void emitAsyncFunctionEntry(IRGenFunction &IGF, SILFunction *asyncFunc);
418+
void emitAsyncFunctionEntry(IRGenFunction &IGF,
419+
const AsyncContextLayout &layout,
420+
LinkEntity asyncFunction);
419421

420422
/// Yield the given values from the current continuation.
421423
///

lib/IRGen/GenKeyPath.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ emitKeyPathComponent(IRGenModule &IGM,
922922
idKind = KeyPathComponentHeader::Pointer;
923923
// FIXME: Does this need to be signed?
924924
auto idRef = IGM.getAddrOfLLVMVariableOrGOTEquivalent(
925-
LinkEntity::forSILFunction(id.getFunction(), false));
925+
LinkEntity::forSILFunction(id.getFunction()));
926926

927927
idValue = idRef.getValue();
928928
// If we got an indirect reference, we'll need to resolve it at

lib/IRGen/GenMeta.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5354,14 +5354,14 @@ bool irgen::methodRequiresReifiedVTableEntry(IRGenModule &IGM,
53545354
}
53555355

53565356
llvm::GlobalValue *irgen::emitAsyncFunctionPointer(IRGenModule &IGM,
5357-
SILFunction *function,
5357+
llvm::Function *function,
5358+
LinkEntity entity,
53585359
Size size) {
53595360
ConstantInitBuilder initBuilder(IGM);
53605361
ConstantStructBuilder builder(
53615362
initBuilder.beginStruct(IGM.AsyncFunctionPointerTy));
5362-
builder.addRelativeAddress(
5363-
IGM.getAddrOfSILFunction(function, NotForDefinition));
5363+
builder.addRelativeAddress(function);
53645364
builder.addInt32(size.getValue());
53655365
return cast<llvm::GlobalValue>(IGM.defineAsyncFunctionPointer(
5366-
function, builder.finishAndCreateFuture()));
5366+
entity, builder.finishAndCreateFuture()));
53675367
}

lib/IRGen/GenMeta.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ namespace irgen {
4747
class Size;
4848
class StructLayout;
4949
class ClassLayout;
50+
class LinkEntity;
5051

5152
bool requiresForeignTypeMetadata(CanType type);
5253
bool requiresForeignTypeMetadata(NominalTypeDecl *decl);
@@ -183,7 +184,9 @@ namespace irgen {
183184
ArrayRef<Requirement> requirements);
184185

185186
llvm::GlobalValue *emitAsyncFunctionPointer(IRGenModule &IGM,
186-
SILFunction *function, Size size);
187+
llvm::Function *function,
188+
LinkEntity entity,
189+
Size size);
187190
} // end namespace irgen
188191
} // end namespace swift
189192

lib/IRGen/GenThunk.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ static FunctionPointer lookupMethod(IRGenFunction &IGF, SILDeclRef declRef) {
8181
return layout;
8282
};
8383

84+
if (funcTy->isAsync()) {
85+
auto layout = getAsyncContextLayout();
86+
auto entity = LinkEntity::forDispatchThunk(declRef);
87+
emitAsyncFunctionEntry(IGF, layout, entity);
88+
emitAsyncFunctionPointer(IGF.IGM, IGF.CurFn, entity, layout.getSize());
89+
}
90+
8491
// Protocol case.
8592
if (isa<ProtocolDecl>(decl->getDeclContext())) {
8693
// Find the witness table.
@@ -162,18 +169,25 @@ void IRGenModule::emitDispatchThunk(SILDeclRef declRef) {
162169
IGF.Builder.CreateRet(result);
163170
}
164171

172+
llvm::Constant *
173+
IRGenModule::getAddrOfAsyncFunctionPointer(LinkEntity entity) {
174+
return getAddrOfLLVMVariable(
175+
LinkEntity::forAsyncFunctionPointer(entity),
176+
NotForDefinition, DebugTypeInfo());
177+
}
178+
165179
llvm::Constant *
166180
IRGenModule::getAddrOfAsyncFunctionPointer(SILFunction *function) {
167181
(void)getAddrOfSILFunction(function, NotForDefinition);
168-
auto entity = LinkEntity::forAsyncFunctionPointer(function);
169-
return getAddrOfLLVMVariable(entity, NotForDefinition, DebugTypeInfo());
182+
return getAddrOfAsyncFunctionPointer(
183+
LinkEntity::forSILFunction(function));
170184
}
171185

172-
llvm::Constant *IRGenModule::defineAsyncFunctionPointer(SILFunction *function,
186+
llvm::Constant *IRGenModule::defineAsyncFunctionPointer(LinkEntity entity,
173187
ConstantInit init) {
174-
auto entity = LinkEntity::forAsyncFunctionPointer(function);
188+
auto asyncEntity = LinkEntity::forAsyncFunctionPointer(entity);
175189
auto *var = cast<llvm::GlobalVariable>(
176-
getAddrOfLLVMVariable(entity, init, DebugTypeInfo()));
190+
getAddrOfLLVMVariable(asyncEntity, init, DebugTypeInfo()));
177191
setTrueConstGlobal(var);
178192
return var;
179193
}

0 commit comments

Comments
 (0)