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

lib/IRGen/IRGenSIL.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,13 +2288,16 @@ void IRGenSILFunction::visitFunctionRefBaseInst(FunctionRefBaseInst *i) {
22882288
fn, NotForDefinition, false /*isDynamicallyReplaceableImplementation*/,
22892289
isa<PreviousDynamicFunctionRefInst>(i));
22902290
llvm::Value *value;
2291-
if (fn->isAsync()) {
2291+
auto isSpecialAsyncWithoutCtxtSize =
2292+
fn->isAsync() && fn->getName().equals("swift_task_future_wait");
2293+
if (fn->isAsync() && !isSpecialAsyncWithoutCtxtSize) {
22922294
value = IGM.getAddrOfAsyncFunctionPointer(fn);
22932295
value = Builder.CreateBitCast(value, fnPtr->getType());
22942296
} else {
22952297
value = fnPtr;
22962298
}
2297-
FunctionPointer fp = FunctionPointer(fnType, value, sig);
2299+
FunctionPointer fp =
2300+
FunctionPointer(fnType, value, sig, isSpecialAsyncWithoutCtxtSize);
22982301

22992302
// Store the function as a FunctionPointer so we can avoid bitcasting
23002303
// or thunking if we don't need to.

lib/SIL/IR/SILPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
14511451
}
14521452

14531453
void visitMarkUninitializedInst(MarkUninitializedInst *MU) {
1454-
switch (MU->getKind()) {
1454+
switch (MU->getMarkUninitializedKind()) {
14551455
case MarkUninitializedInst::Var: *this << "[var] "; break;
14561456
case MarkUninitializedInst::RootSelf: *this << "[rootself] "; break;
14571457
case MarkUninitializedInst::CrossModuleRootSelf:
@@ -1466,7 +1466,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
14661466
*this << "[delegatingselfallocated] ";
14671467
break;
14681468
}
1469-
1469+
14701470
*this << getIDAndType(MU->getOperand());
14711471
}
14721472

lib/SILGen/SILGenFunction.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,14 @@ void SILGenFunction::emitFunction(FuncDecl *fd) {
517517
fd->getResultInterfaceType(), fd->hasThrows(), fd->getThrowsLoc());
518518
prepareEpilog(true, fd->hasThrows(), CleanupLocation(fd));
519519

520-
emitStmt(fd->getTypecheckedBody());
520+
if (fd->isAsyncHandler()) {
521+
// Async handlers are need to have their bodies emitted into a
522+
// detached task.
523+
// FIXME: Actually implement these properly.
524+
B.createBuiltinTrap(fd->getTypecheckedBody());
525+
} else {
526+
emitStmt(fd->getTypecheckedBody());
527+
}
521528

522529
emitEpilog(fd);
523530

lib/SILOptimizer/Analysis/ProtocolConformanceAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class NominalTypeWalker : public ASTWalker {
4747
/// (2) Walk over all ExtensionDecls to determine conformances.
4848
if (auto *e = dyn_cast<ExtensionDecl>(D)) {
4949
auto *ntd = e->getExtendedNominal();
50-
if (!isa<ProtocolDecl>(ntd)) {
50+
if (ntd && !isa<ProtocolDecl>(ntd)) {
5151
for (auto *conformance : e->getLocalConformances()) {
5252
if (isa<NormalProtocolConformance>(conformance)) {
5353
auto *proto = conformance->getProtocol();

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class DIMemoryObjectInfo {
194194

195195
/// True if this is an initializer that initializes stored properties.
196196
bool isNonDelegatingInit() const {
197-
switch (MemoryInst->getKind()) {
197+
switch (MemoryInst->getMarkUninitializedKind()) {
198198
case MarkUninitializedInst::Var:
199199
return false;
200200
case MarkUninitializedInst::RootSelf:
@@ -210,7 +210,8 @@ class DIMemoryObjectInfo {
210210
}
211211

212212
bool isRootSelf() const {
213-
return MemoryInst->getKind() == MarkUninitializedInst::RootSelf;
213+
return MemoryInst->getMarkUninitializedKind() ==
214+
MarkUninitializedInst::RootSelf;
214215
}
215216

216217
bool isDelegatingSelfAllocated() const {

lib/SILOptimizer/Mandatory/DiagnoseInvalidEscapingCaptures.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ const ParamDecl *getParamDeclFromOperand(SILValue value) {
158158
bool isUseOfSelfInInitializer(Operand *oper) {
159159
if (auto *PBI = dyn_cast<ProjectBoxInst>(oper->get())) {
160160
if (auto *MUI = dyn_cast<MarkUninitializedInst>(PBI->getOperand())) {
161-
switch (MUI->getKind()) {
161+
switch (MUI->getMarkUninitializedKind()) {
162162
case MarkUninitializedInst::Kind::Var:
163163
return false;
164164
case MarkUninitializedInst::Kind::RootSelf:

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
518518
auto *User = HeapBox->getSingleUse()->getUser();
519519
if (auto *MUI = dyn_cast<MarkUninitializedInst>(User)) {
520520
HeapBox = MUI;
521-
Kind = MUI->getKind();
521+
Kind = MUI->getMarkUninitializedKind();
522522
}
523523
}
524524

lib/Serialization/Deserialization.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3952,7 +3952,7 @@ class DeclDeserializer {
39523952
auto extendedType = MF.getType(extendedTypeID);
39533953
ctx.evaluator.cacheOutput(ExtendedTypeRequest{extension},
39543954
std::move(extendedType));
3955-
auto nominal = dyn_cast<NominalTypeDecl>(MF.getDecl(extendedNominalID));
3955+
auto nominal = dyn_cast_or_null<NominalTypeDecl>(MF.getDecl(extendedNominalID));
39563956
ctx.evaluator.cacheOutput(ExtendedNominalRequest{extension},
39573957
std::move(nominal));
39583958

@@ -3969,7 +3969,9 @@ class DeclDeserializer {
39693969
encodeLazyConformanceContextData(numConformances,
39703970
MF.DeclTypeCursor.GetCurrentBitNo()));
39713971

3972-
nominal->addExtension(extension);
3972+
if (nominal) {
3973+
nominal->addExtension(extension);
3974+
}
39733975

39743976
#ifndef NDEBUG
39753977
if (outerParams) {
@@ -6176,7 +6178,8 @@ void ModuleFile::finishNormalConformance(NormalProtocolConformance *conformance,
61766178
auto isConformanceReq = [](const Requirement &req) {
61776179
return req.getKind() == RequirementKind::Conformance;
61786180
};
6179-
if (conformanceCount != llvm::count_if(proto->getRequirementSignature(),
6181+
if (!isAllowModuleWithCompilerErrorsEnabled() &&
6182+
conformanceCount != llvm::count_if(proto->getRequirementSignature(),
61806183
isConformanceReq)) {
61816184
fatal(llvm::make_error<llvm::StringError>(
61826185
"serialized conformances do not match requirement signature",

lib/Serialization/Serialization.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,8 @@ void Serializer::writeASTBlockEntity(
13551355
using namespace decls_block;
13561356

13571357
// The conformance must be complete, or we can't serialize it.
1358-
assert(conformance->isComplete());
1358+
assert(conformance->isComplete() ||
1359+
getASTContext().LangOpts.AllowModuleWithCompilerErrors);
13591360
assert(NormalConformancesToSerialize.hasRef(conformance));
13601361

13611362
auto protocol = conformance->getProtocol();
@@ -1541,6 +1542,8 @@ static bool shouldSerializeMember(Decl *D) {
15411542
case DeclKind::Extension:
15421543
case DeclKind::Module:
15431544
case DeclKind::PrecedenceGroup:
1545+
if (D->getASTContext().LangOpts.AllowModuleWithCompilerErrors)
1546+
return false;
15441547
llvm_unreachable("decl should never be a member");
15451548

15461549
case DeclKind::MissingMember:
@@ -5050,7 +5053,9 @@ static void collectInterestingNestedDeclarations(
50505053
if (!nominalParent) {
50515054
const DeclContext *DC = member->getDeclContext();
50525055
nominalParent = DC->getSelfNominalTypeDecl();
5053-
assert(nominalParent && "parent context is not a type or extension");
5056+
assert(nominalParent ||
5057+
nestedType->getASTContext().LangOpts.AllowModuleWithCompilerErrors &&
5058+
"parent context is not a type or extension");
50545059
}
50555060
nestedTypeDecls[nestedType->getName()].push_back({
50565061
S.addDeclRef(nominalParent),
@@ -5115,8 +5120,10 @@ void Serializer::writeAST(ModuleOrSourceFile DC) {
51155120
.push_back({ getKindForTable(D), addDeclRef(D) });
51165121
} else if (auto ED = dyn_cast<ExtensionDecl>(D)) {
51175122
const NominalTypeDecl *extendedNominal = ED->getExtendedNominal();
5118-
extensionDecls[extendedNominal->getName()]
5119-
.push_back({ extendedNominal, addDeclRef(D) });
5123+
if (extendedNominal) {
5124+
extensionDecls[extendedNominal->getName()]
5125+
.push_back({ extendedNominal, addDeclRef(D) });
5126+
}
51205127
} else if (auto OD = dyn_cast<OperatorDecl>(D)) {
51215128
operatorDecls[OD->getName()]
51225129
.push_back({ getStableFixity(OD->getFixity()), addDeclRef(D) });

0 commit comments

Comments
 (0)