Skip to content

Commit e267725

Browse files
authored
Merge pull request #2241 from swiftwasm/main
[pull] swiftwasm from main
2 parents 4baea30 + 5aab24b commit e267725

39 files changed

+428
-2057
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,9 +1287,9 @@ void
12871287
SILCloner<ImplClass>::visitMarkUninitializedInst(MarkUninitializedInst *Inst) {
12881288
SILValue OpValue = getOpValue(Inst->getOperand());
12891289
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
1290-
recordClonedInstruction(
1291-
Inst, getBuilder().createMarkUninitialized(getOpLocation(Inst->getLoc()),
1292-
OpValue, Inst->getKind()));
1290+
recordClonedInstruction(Inst, getBuilder().createMarkUninitialized(
1291+
getOpLocation(Inst->getLoc()), OpValue,
1292+
Inst->getMarkUninitializedKind()));
12931293
}
12941294

12951295
template<typename ImplClass>

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4127,8 +4127,7 @@ class MarkUninitializedInst
41274127
ThisKind(K) {}
41284128

41294129
public:
4130-
4131-
Kind getKind() const { return ThisKind; }
4130+
Kind getMarkUninitializedKind() const { return ThisKind; }
41324131

41334132
bool isVar() const { return ThisKind == Var; }
41344133
bool isRootSelf() const {

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,9 @@ PrintOptions PrintOptions::printSwiftInterfaceFile(bool preferTypeRepr,
150150

151151
class ShouldPrintForModuleInterface : public ShouldPrintChecker {
152152
bool shouldPrint(const Decl *D, const PrintOptions &options) override {
153+
if (!D)
154+
return false;
155+
153156
// Skip anything that is marked `@_implementationOnly` itself.
154157
if (D->getAttrs().hasAttribute<ImplementationOnlyAttr>())
155158
return false;

lib/AST/DeclContext.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,12 +532,17 @@ void AccessScope::dump() const {
532532

533533
if (auto *decl = getDeclContext()->getAsDecl()) {
534534
llvm::errs() << Decl::getKindName(decl->getKind()) << " ";
535-
if (auto *ext = dyn_cast<ExtensionDecl>(decl))
536-
llvm::errs() << ext->getExtendedNominal()->getName();
537-
else if (auto *named = dyn_cast<ValueDecl>(decl))
535+
if (auto *ext = dyn_cast<ExtensionDecl>(decl)) {
536+
auto *extended = ext->getExtendedNominal();
537+
if (extended)
538+
llvm::errs() << extended->getName();
539+
else
540+
llvm::errs() << "(null)";
541+
} else if (auto *named = dyn_cast<ValueDecl>(decl)) {
538542
llvm::errs() << named->getName();
539-
else
543+
} else {
540544
llvm::errs() << (const void *)decl;
545+
}
541546

542547
SourceLoc loc = decl->getLoc();
543548
if (loc.isValid()) {

lib/ClangImporter/ImportDecl.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7463,9 +7463,20 @@ void SwiftDeclConverter::importNonOverriddenMirroredMethods(DeclContext *dc,
74637463
Impl.importMirroredDecl(objcMethod, dc, getVersion(), proto)) {
74647464
members.push_back(imported);
74657465

7466-
for (auto alternate : Impl.getAlternateDecls(imported))
7466+
for (auto alternate : Impl.getAlternateDecls(imported)) {
74677467
if (imported->getDeclContext() == alternate->getDeclContext())
74687468
members.push_back(alternate);
7469+
}
7470+
7471+
if (Impl.SwiftContext.LangOpts.EnableExperimentalConcurrency &&
7472+
!getVersion().supportsConcurrency()) {
7473+
auto asyncVersion = getVersion().withConcurrency(true);
7474+
if (auto asyncImport = Impl.importMirroredDecl(
7475+
objcMethod, dc, asyncVersion, proto)) {
7476+
if (asyncImport != imported)
7477+
members.push_back(asyncImport);
7478+
}
7479+
}
74697480
}
74707481
}
74717482
}

lib/Demangling/NodePrinter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,6 +2145,7 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
21452145
return nullptr;
21462146
case Node::Kind::ImplFunctionConventionName:
21472147
assert(false && "Already handled in ImplFunctionConvention");
2148+
return nullptr;
21482149
case Node::Kind::ImplErrorResult:
21492150
Printer << "@error ";
21502151
printChildren(Node, " ");

lib/IDE/ModuleInterfacePrinting.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ static bool printModuleInterfaceDecl(Decl *D,
247247
// a cross-module extension.
248248
if (!extensionHasClangNode(Ext)) {
249249
auto ExtendedNominal = Ext->getExtendedNominal();
250-
if (Ext->getModuleContext() == ExtendedNominal->getModuleContext())
250+
if (!ExtendedNominal ||
251+
Ext->getModuleContext() == ExtendedNominal->getModuleContext())
251252
return false;
252253
}
253254
}

lib/IRGen/Callee.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,28 @@ namespace irgen {
155155

156156
Signature Sig;
157157

158+
bool isFunctionPointerWithoutContext = false;
159+
158160
public:
159161
/// Construct a FunctionPointer for an arbitrary pointer value.
160162
/// We may add more arguments to this; try to use the other
161163
/// constructors/factories if possible.
162164
explicit FunctionPointer(KindTy kind, llvm::Value *value,
163165
PointerAuthInfo authInfo,
164-
const Signature &signature)
165-
: Kind(kind), Value(value), AuthInfo(authInfo), Sig(signature) {
166+
const Signature &signature,
167+
bool isWithoutCtxt = false)
168+
: Kind(kind), Value(value), AuthInfo(authInfo), Sig(signature),
169+
isFunctionPointerWithoutContext(isWithoutCtxt) {
166170
// The function pointer should have function type.
167171
assert(value->getType()->getPointerElementType()->isFunctionTy());
168172
// TODO: maybe assert similarity to signature.getType()?
169173
}
170174

171175
// Temporary only!
172176
explicit FunctionPointer(KindTy kind, llvm::Value *value,
173-
const Signature &signature)
174-
: FunctionPointer(kind, value, PointerAuthInfo(), signature) {}
177+
const Signature &signature, bool
178+
isWithoutCtxt = false)
179+
: FunctionPointer(kind, value, PointerAuthInfo(), signature, isWithoutCtxt) {}
175180

176181
static FunctionPointer forDirect(IRGenModule &IGM,
177182
llvm::Constant *value,
@@ -243,6 +248,10 @@ namespace irgen {
243248

244249
/// Form a FunctionPointer whose KindTy is ::Function.
245250
FunctionPointer getAsFunction(IRGenFunction &IGF) const;
251+
252+
bool useStaticContextSize() const {
253+
return isFunctionPointerWithoutContext;
254+
}
246255
};
247256

248257
class Callee {

lib/IRGen/GenCall.cpp

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,7 +1830,7 @@ void irgen::extractScalarResults(IRGenFunction &IGF, llvm::Type *bodyType,
18301830
std::pair<llvm::Value *, llvm::Value *> irgen::getAsyncFunctionAndSize(
18311831
IRGenFunction &IGF, SILFunctionTypeRepresentation representation,
18321832
FunctionPointer functionPointer, llvm::Value *thickContext,
1833-
std::pair<bool, bool> values) {
1833+
std::pair<bool, bool> values, Size initialContextSize) {
18341834
assert(values.first || values.second);
18351835
bool emitFunction = values.first;
18361836
bool emitSize = values.second;
@@ -1997,11 +1997,16 @@ std::pair<llvm::Value *, llvm::Value *> irgen::getAsyncFunctionAndSize(
19971997
}
19981998
llvm::Value *size = nullptr;
19991999
if (emitSize) {
2000-
auto *ptr = functionPointer.getRawPointer();
2001-
auto *descriptorPtr =
2002-
IGF.Builder.CreateBitCast(ptr, IGF.IGM.AsyncFunctionPointerPtrTy);
2003-
auto *sizePtr = IGF.Builder.CreateStructGEP(descriptorPtr, 1);
2004-
size = IGF.Builder.CreateLoad(sizePtr, IGF.IGM.getPointerAlignment());
2000+
if (functionPointer.useStaticContextSize()) {
2001+
size = llvm::ConstantInt::get(IGF.IGM.Int32Ty,
2002+
initialContextSize.getValue());
2003+
} else {
2004+
auto *ptr = functionPointer.getRawPointer();
2005+
auto *descriptorPtr =
2006+
IGF.Builder.CreateBitCast(ptr, IGF.IGM.AsyncFunctionPointerPtrTy);
2007+
auto *sizePtr = IGF.Builder.CreateStructGEP(descriptorPtr, 1);
2008+
size = IGF.Builder.CreateLoad(sizePtr, IGF.IGM.getPointerAlignment());
2009+
}
20052010
}
20062011
return {fn, size};
20072012
}
@@ -2270,7 +2275,8 @@ class AsyncCallEmission final : public CallEmission {
22702275
llvm::Value *dynamicContextSize32;
22712276
std::tie(calleeFunction, dynamicContextSize32) = getAsyncFunctionAndSize(
22722277
IGF, CurCallee.getOrigFunctionType()->getRepresentation(),
2273-
CurCallee.getFunctionPointer(), thickContext);
2278+
CurCallee.getFunctionPointer(), thickContext,
2279+
std::make_pair(true, true), layout.getSize());
22742280
auto *dynamicContextSize =
22752281
IGF.Builder.CreateZExt(dynamicContextSize32, IGF.IGM.SizeTy);
22762282
contextBuffer = emitAllocAsyncContext(IGF, dynamicContextSize);
@@ -4494,13 +4500,20 @@ llvm::Value *FunctionPointer::getPointer(IRGenFunction &IGF) const {
44944500
switch (Kind.value) {
44954501
case KindTy::Value::Function:
44964502
return Value;
4497-
case KindTy::Value::AsyncFunctionPointer:
4498-
auto *descriptorPtr =
4499-
IGF.Builder.CreateBitCast(Value, IGF.IGM.AsyncFunctionPointerPtrTy);
4500-
auto *addrPtr = IGF.Builder.CreateStructGEP(descriptorPtr, 0);
4501-
return IGF.emitLoadOfRelativePointer(
4502-
Address(addrPtr, IGF.IGM.getPointerAlignment()), /*isFar*/ false,
4503-
/*expectedType*/ getFunctionType()->getPointerTo());
4503+
case KindTy::Value::AsyncFunctionPointer: {
4504+
if (!isFunctionPointerWithoutContext) {
4505+
auto *descriptorPtr =
4506+
IGF.Builder.CreateBitCast(Value, IGF.IGM.AsyncFunctionPointerPtrTy);
4507+
auto *addrPtr = IGF.Builder.CreateStructGEP(descriptorPtr, 0);
4508+
return IGF.emitLoadOfRelativePointer(
4509+
Address(addrPtr, IGF.IGM.getPointerAlignment()), /*isFar*/ false,
4510+
/*expectedType*/ getFunctionType()->getPointerTo());
4511+
} else {
4512+
return IGF.Builder.CreateBitOrPointerCast(
4513+
Value, getFunctionType()->getPointerTo());
4514+
}
4515+
}
4516+
45044517
}
45054518
}
45064519

lib/IRGen/GenCall.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,8 @@ namespace irgen {
313313
std::pair<llvm::Value *, llvm::Value *> getAsyncFunctionAndSize(
314314
IRGenFunction &IGF, SILFunctionTypeRepresentation representation,
315315
FunctionPointer functionPointer, llvm::Value *thickContext,
316-
std::pair<bool, bool> values = {true, true});
316+
std::pair<bool, bool> values = {true, true},
317+
Size initialContextSize = Size(0));
317318
llvm::CallingConv::ID expandCallingConv(IRGenModule &IGM,
318319
SILFunctionTypeRepresentation convention);
319320

0 commit comments

Comments
 (0)