Skip to content

Commit 2b3f2a9

Browse files
authored
Merge pull request #1826 from swiftwasm/main
[pull] swiftwasm from main
2 parents 38486cf + 67af4ce commit 2b3f2a9

21 files changed

+270
-134
lines changed

include/swift/AST/DiagnosticsSema.def

+3
Original file line numberDiff line numberDiff line change
@@ -4149,6 +4149,9 @@ ERROR(actor_isolated_self_independent_context,none,
41494149
"actor-isolated %0 %1 can not be referenced from an "
41504150
"'@actorIndependent' context",
41514151
(DescriptiveDeclKind, DeclName))
4152+
ERROR(actor_isolated_partial_apply,none,
4153+
"actor-isolated %0 %1 can not be partially applied",
4154+
(DescriptiveDeclKind, DeclName))
41524155
WARNING(concurrent_access_local,none,
41534156
"local %0 %1 is unsafe to reference in code that may execute "
41544157
"concurrently",

include/swift/AST/ExtInfo.h

+20-4
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ class ASTExtInfoBuilder {
275275
: bits(bits), clangTypeInfo(clangTypeInfo) {}
276276

277277
public:
278-
// Constructor with all defaults.
278+
/// An ExtInfoBuilder for a typical Swift function: @convention(swift),
279+
/// @escaping, non-throwing, non-differentiable.
279280
ASTExtInfoBuilder()
280281
: ASTExtInfoBuilder(Representation::Swift, false, false,
281282
DifferentiabilityKind::NonDifferentiable, nullptr) {}
@@ -447,6 +448,8 @@ class ASTExtInfo {
447448
};
448449

449450
public:
451+
/// An ExtInfo for a typical Swift function: @convention(swift), @escaping,
452+
/// non-throwing, non-differentiable.
450453
ASTExtInfo() : builder() { builder.checkInvariants(); };
451454

452455
/// Create a builder with the same state as \c this.
@@ -598,17 +601,22 @@ class SILExtInfoBuilder {
598601
}
599602

600603
public:
601-
// Constructor with all defaults.
602-
SILExtInfoBuilder() : SILExtInfoBuilder(0, ClangTypeInfo(nullptr)) {}
604+
/// An ExtInfoBuilder for a typical Swift function: thick, @escaping,
605+
/// non-pseudogeneric, non-differentiable.
606+
SILExtInfoBuilder()
607+
: SILExtInfoBuilder(makeBits(SILFunctionTypeRepresentation::Thick, false,
608+
false, false,
609+
DifferentiabilityKind::NonDifferentiable),
610+
ClangTypeInfo(nullptr)) {}
603611

604-
// Constructor for polymorphic type.
605612
SILExtInfoBuilder(Representation rep, bool isPseudogeneric, bool isNoEscape,
606613
bool isAsync, DifferentiabilityKind diffKind,
607614
const clang::Type *type)
608615
: SILExtInfoBuilder(makeBits(rep, isPseudogeneric, isNoEscape, isAsync,
609616
diffKind),
610617
ClangTypeInfo(type)) {}
611618

619+
// Constructor for polymorphic type.
612620
SILExtInfoBuilder(ASTExtInfoBuilder info, bool isPseudogeneric)
613621
: SILExtInfoBuilder(makeBits(info.getSILRepresentation(), isPseudogeneric,
614622
info.isNoEscape(), info.isAsync(),
@@ -686,25 +694,30 @@ class SILExtInfoBuilder {
686694

687695
// Note that we don't have setters. That is by design, use
688696
// the following with methods instead of mutating these objects.
697+
LLVM_NODISCARD
689698
SILExtInfoBuilder withRepresentation(Representation rep) const {
690699
return SILExtInfoBuilder((bits & ~RepresentationMask) | (unsigned)rep,
691700
shouldStoreClangType(rep) ? clangTypeInfo
692701
: ClangTypeInfo());
693702
}
703+
LLVM_NODISCARD
694704
SILExtInfoBuilder withIsPseudogeneric(bool isPseudogeneric = true) const {
695705
return SILExtInfoBuilder(isPseudogeneric ? (bits | PseudogenericMask)
696706
: (bits & ~PseudogenericMask),
697707
clangTypeInfo);
698708
}
709+
LLVM_NODISCARD
699710
SILExtInfoBuilder withNoEscape(bool noEscape = true) const {
700711
return SILExtInfoBuilder(noEscape ? (bits | NoEscapeMask)
701712
: (bits & ~NoEscapeMask),
702713
clangTypeInfo);
703714
}
715+
LLVM_NODISCARD
704716
SILExtInfoBuilder withAsync(bool isAsync = true) const {
705717
return SILExtInfoBuilder(isAsync ? (bits | AsyncMask) : (bits & ~AsyncMask),
706718
clangTypeInfo);
707719
}
720+
LLVM_NODISCARD
708721
SILExtInfoBuilder
709722
withDifferentiabilityKind(DifferentiabilityKind differentiability) const {
710723
return SILExtInfoBuilder(
@@ -750,13 +763,16 @@ class SILExtInfo {
750763
};
751764

752765
public:
766+
/// An ExtInfo for a typical Swift function: thick, @escaping,
767+
/// non-pseudogeneric, non-differentiable.
753768
SILExtInfo() : builder() { builder.checkInvariants(); };
754769

755770
SILExtInfo(ASTExtInfo info, bool isPseudogeneric)
756771
: builder(info.intoBuilder(), isPseudogeneric) {
757772
builder.checkInvariants();
758773
}
759774

775+
/// A default ExtInfo but with a Thin convention.
760776
static SILExtInfo getThin() {
761777
return SILExtInfoBuilder(SILExtInfoBuilder::Representation::Thin, false,
762778
false, false,

include/swift/AST/PrintOptions.h

+2-17
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ModuleDecl;
3838
enum DeclAttrKind : unsigned;
3939
class SynthesizedExtensionAnalyzer;
4040
struct PrintOptions;
41-
41+
class SILPrintContext;
4242

4343
/// Necessary information for archetype transformation during printing.
4444
struct TypeTransformContext {
@@ -594,22 +594,7 @@ struct PrintOptions {
594594
static PrintOptions printDocInterface();
595595

596596
/// Retrieve the set of options suitable for printing SIL functions.
597-
static PrintOptions printSIL(bool printFullConvention = false) {
598-
PrintOptions result;
599-
result.PrintLongAttrsOnSeparateLines = true;
600-
result.PrintStorageRepresentationAttrs = true;
601-
result.AbstractAccessors = false;
602-
result.PrintForSIL = true;
603-
result.PrintInSILBody = true;
604-
result.PreferTypeRepr = false;
605-
result.PrintIfConfig = false;
606-
result.OpaqueReturnTypePrinting =
607-
OpaqueReturnTypePrintingMode::StableReference;
608-
if (printFullConvention)
609-
result.PrintFunctionRepresentationAttrs =
610-
PrintOptions::FunctionRepresentationMode::Full;
611-
return result;
612-
}
597+
static PrintOptions printSIL(const SILPrintContext *silPrintCtx = nullptr);
613598

614599
static PrintOptions printQualifiedSILType() {
615600
PrintOptions result = PrintOptions::printSIL();

lib/AST/ASTDumper.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -3792,6 +3792,7 @@ namespace {
37923792

37933793
OS << "\n";
37943794
Indent += 2;
3795+
// [TODO: Improve-Clang-type-printing]
37953796
if (!T->getClangTypeInfo().empty()) {
37963797
std::string s;
37973798
llvm::raw_string_ostream os(s);
@@ -3842,6 +3843,7 @@ namespace {
38423843
OS << '\n';
38433844
T->getInvocationSubstitutions().dump(OS, SubstitutionMap::DumpStyle::Full,
38443845
Indent+2);
3846+
// [TODO: Improve-Clang-type-printing]
38453847
if (!T->getClangTypeInfo().empty()) {
38463848
std::string s;
38473849
llvm::raw_string_ostream os(s);

lib/AST/Expr.cpp

+27-13
Original file line numberDiff line numberDiff line change
@@ -2007,17 +2007,37 @@ Expr *AutoClosureExpr::getSingleExpressionBody() const {
20072007
}
20082008

20092009
Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
2010+
auto maybeUnwrapOpenExistential = [](Expr *expr) {
2011+
if (auto *openExistential = dyn_cast<OpenExistentialExpr>(expr)) {
2012+
expr = openExistential->getSubExpr()->getSemanticsProvidingExpr();
2013+
if (auto *ICE = dyn_cast<ImplicitConversionExpr>(expr))
2014+
expr = ICE->getSyntacticSubExpr();
2015+
}
2016+
2017+
return expr;
2018+
};
2019+
2020+
auto maybeUnwrapOptionalEval = [](Expr *expr) {
2021+
if (auto optEval = dyn_cast<OptionalEvaluationExpr>(expr))
2022+
expr = optEval->getSubExpr();
2023+
if (auto inject = dyn_cast<InjectIntoOptionalExpr>(expr))
2024+
expr = inject->getSubExpr();
2025+
if (auto erasure = dyn_cast<ErasureExpr>(expr))
2026+
expr = erasure->getSubExpr();
2027+
if (auto bind = dyn_cast<BindOptionalExpr>(expr))
2028+
expr = bind->getSubExpr();
2029+
return expr;
2030+
};
2031+
20102032
switch (getThunkKind()) {
20112033
case AutoClosureExpr::Kind::None:
20122034
break;
20132035

20142036
case AutoClosureExpr::Kind::SingleCurryThunk: {
20152037
auto *body = getSingleExpressionBody();
20162038
body = body->getSemanticsProvidingExpr();
2017-
2018-
if (auto *openExistential = dyn_cast<OpenExistentialExpr>(body)) {
2019-
body = openExistential->getSubExpr()->getSemanticsProvidingExpr();
2020-
}
2039+
body = maybeUnwrapOpenExistential(body);
2040+
body = maybeUnwrapOptionalEval(body);
20212041

20222042
if (auto *outerCall = dyn_cast<ApplyExpr>(body)) {
20232043
return outerCall->getFn();
@@ -2034,18 +2054,12 @@ Expr *AutoClosureExpr::getUnwrappedCurryThunkExpr() const {
20342054
AutoClosureExpr::Kind::SingleCurryThunk);
20352055
auto *innerBody = innerClosure->getSingleExpressionBody();
20362056
innerBody = innerBody->getSemanticsProvidingExpr();
2037-
2038-
if (auto *openExistential = dyn_cast<OpenExistentialExpr>(innerBody)) {
2039-
innerBody = openExistential->getSubExpr()->getSemanticsProvidingExpr();
2040-
if (auto *ICE = dyn_cast<ImplicitConversionExpr>(innerBody))
2041-
innerBody = ICE->getSyntacticSubExpr();
2042-
}
2057+
innerBody = maybeUnwrapOpenExistential(innerBody);
2058+
innerBody = maybeUnwrapOptionalEval(innerBody);
20432059

20442060
if (auto *outerCall = dyn_cast<ApplyExpr>(innerBody)) {
20452061
if (auto *innerCall = dyn_cast<ApplyExpr>(outerCall->getFn())) {
2046-
if (auto *declRef = dyn_cast<DeclRefExpr>(innerCall->getFn())) {
2047-
return declRef;
2048-
}
2062+
return innerCall->getFn();
20492063
}
20502064
}
20512065
}

lib/IRGen/IRGenDebugInfo.cpp

+20-4
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,24 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
660660
isa<ConstructorDecl>(DeclCtx);
661661
}
662662

663+
void createImportedModule(llvm::DIScope *Context,
664+
ModuleDecl::ImportedModule M, llvm::DIFile *File,
665+
unsigned Line) {
666+
// For overlays of Clang modules also emit an import of the underlying Clang
667+
// module. The helps the debugger resolve types that are present only in the
668+
// underlying module.
669+
if (const clang::Module *UnderlyingClangModule =
670+
M.importedModule->findUnderlyingClangModule()) {
671+
DBuilder.createImportedModule(
672+
Context,
673+
getOrCreateModule(
674+
{*const_cast<clang::Module *>(UnderlyingClangModule)},
675+
UnderlyingClangModule),
676+
File, 0);
677+
}
678+
DBuilder.createImportedModule(Context, getOrCreateModule(M), File, Line);
679+
}
680+
663681
llvm::DIModule *getOrCreateModule(const void *Key, llvm::DIScope *Parent,
664682
StringRef Name, StringRef IncludePath,
665683
uint64_t Signature = ~1ULL,
@@ -1871,8 +1889,7 @@ void IRGenDebugInfoImpl::finalize() {
18711889
ModuleDecl::ImportFilterKind::ImplementationOnly});
18721890
for (auto M : ModuleWideImports)
18731891
if (!ImportedModules.count(M.importedModule))
1874-
DBuilder.createImportedModule(MainFile, getOrCreateModule(M), MainFile,
1875-
0);
1892+
createImportedModule(MainFile, M, MainFile, 0);
18761893

18771894
// Finalize all replaceable forward declarations.
18781895
for (auto &Ty : ReplaceMap) {
@@ -2113,10 +2130,9 @@ void IRGenDebugInfoImpl::emitImport(ImportDecl *D) {
21132130

21142131
assert(D->getModule() && "compiler-synthesized ImportDecl is incomplete");
21152132
ModuleDecl::ImportedModule Imported = { D->getAccessPath(), D->getModule() };
2116-
auto DIMod = getOrCreateModule(Imported);
21172133
auto L = getDebugLoc(*this, D);
21182134
auto *File = getOrCreateFile(L.Filename);
2119-
DBuilder.createImportedModule(File, DIMod, File, L.Line);
2135+
createImportedModule(File, Imported, File, L.Line);
21202136
ImportedModules.insert(Imported.importedModule);
21212137
}
21222138

lib/SIL/IR/AbstractionPattern.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,7 @@ void AbstractionPattern::print(raw_ostream &out) const {
827827
}
828828
getType().dump(out);
829829
out << ", ";
830+
// [TODO: Improve-Clang-type-printing]
830831
// It would be better to use print, but we need a PrintingPolicy
831832
// for that, for which we need a clang LangOptions, and... ugh.
832833
clang::QualType(getClangType(), 0).dump();

lib/SIL/IR/SILPrinter.cpp

+22-7
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ void SILType::dump() const {
459459
static void printSILFunctionNameAndType(
460460
llvm::raw_ostream &OS, const SILFunction *function,
461461
llvm::DenseMap<CanType, Identifier> &sugaredTypeNames,
462-
bool printFullConvention = false) {
462+
const SILPrintContext *silPrintContext = nullptr) {
463463
function->printName(OS);
464464
OS << " : $";
465465
auto *genEnv = function->getGenericEnvironment();
@@ -496,7 +496,7 @@ static void printSILFunctionNameAndType(
496496
sugaredTypeNames[archetypeTy->getCanonicalType()] = name;
497497
}
498498
}
499-
auto printOptions = PrintOptions::printSIL(printFullConvention);
499+
auto printOptions = PrintOptions::printSIL(silPrintContext);
500500
printOptions.GenericSig = genSig;
501501
printOptions.AlternativeTypeNames =
502502
sugaredTypeNames.empty() ? nullptr : &sugaredTypeNames;
@@ -571,8 +571,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
571571
SILPrintContext &PrintCtx,
572572
llvm::DenseMap<CanType, Identifier> *AlternativeTypeNames = nullptr)
573573
: Ctx(PrintCtx), PrintState{{PrintCtx.OS()},
574-
PrintOptions::printSIL(
575-
PrintCtx.printFullConvention())},
574+
PrintOptions::printSIL(&PrintCtx)},
576575
LastBufferID(0) {
577576
PrintState.ASTOptions.AlternativeTypeNames = AlternativeTypeNames;
578577
PrintState.ASTOptions.PrintForSIL = true;
@@ -2685,8 +2684,7 @@ void SILFunction::print(SILPrintContext &PrintCtx) const {
26852684
OS << "[ossa] ";
26862685

26872686
llvm::DenseMap<CanType, Identifier> sugaredTypeNames;
2688-
printSILFunctionNameAndType(OS, this, sugaredTypeNames,
2689-
PrintCtx.printFullConvention());
2687+
printSILFunctionNameAndType(OS, this, sugaredTypeNames, &PrintCtx);
26902688

26912689
if (!isExternalDeclaration()) {
26922690
if (auto eCount = getEntryCount()) {
@@ -2971,7 +2969,7 @@ static void printFileIDMap(SILPrintContext &Ctx, const FileIDMap map) {
29712969
}
29722970

29732971
void SILProperty::print(SILPrintContext &Ctx) const {
2974-
PrintOptions Options = PrintOptions::printSIL(Ctx.printFullConvention());
2972+
PrintOptions Options = PrintOptions::printSIL(&Ctx);
29752973

29762974
auto &OS = Ctx.OS();
29772975
OS << "sil_property ";
@@ -3612,3 +3610,20 @@ ID SILPrintContext::getID(const SILNode *node) {
36123610
ID R = {ID::SSAValue, ValueToIDMap[node]};
36133611
return R;
36143612
}
3613+
3614+
PrintOptions PrintOptions::printSIL(const SILPrintContext *ctx) {
3615+
PrintOptions result;
3616+
result.PrintLongAttrsOnSeparateLines = true;
3617+
result.PrintStorageRepresentationAttrs = true;
3618+
result.AbstractAccessors = false;
3619+
result.PrintForSIL = true;
3620+
result.PrintInSILBody = true;
3621+
result.PreferTypeRepr = false;
3622+
result.PrintIfConfig = false;
3623+
result.OpaqueReturnTypePrinting =
3624+
OpaqueReturnTypePrintingMode::StableReference;
3625+
if (ctx && ctx->printFullConvention())
3626+
result.PrintFunctionRepresentationAttrs =
3627+
PrintOptions::FunctionRepresentationMode::Full;
3628+
return result;
3629+
}

lib/SILGen/SILGen.cpp

+1-8
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,7 @@ SILGenModule::getKeyPathProjectionCoroutine(bool isReadAccess,
411411
: ParameterConvention::Indirect_In_Guaranteed },
412412
};
413413

414-
auto extInfo =
415-
SILFunctionType::ExtInfoBuilder(SILFunctionTypeRepresentation::Thin,
416-
/*pseudogeneric*/ false,
417-
/*non-escaping*/ false,
418-
/*async*/ false,
419-
DifferentiabilityKind::NonDifferentiable,
420-
/*clangFunctionType*/ nullptr)
421-
.build();
414+
auto extInfo = SILFunctionType::ExtInfo::getThin();
422415

423416
auto functionTy = SILFunctionType::get(sig, extInfo,
424417
SILCoroutineKind::YieldOnce,

lib/SILGen/SILGenFunction.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,10 @@ void SILGenFunction::emitArtificialTopLevel(Decl *mainDecl) {
696696
};
697697
auto NSApplicationMainType = SILFunctionType::get(
698698
nullptr,
699-
SILFunctionType::ExtInfoBuilder()
700-
// Should be C calling convention, but NSApplicationMain
701-
// has an overlay to fix the type of argv.
702-
.withRepresentation(SILFunctionType::Representation::Thin)
703-
.build(),
704-
SILCoroutineKind::None, ParameterConvention::Direct_Unowned, argTypes,
699+
// Should be C calling convention, but NSApplicationMain
700+
// has an overlay to fix the type of argv.
701+
SILFunctionType::ExtInfo::getThin(), SILCoroutineKind::None,
702+
ParameterConvention::Direct_Unowned, argTypes,
705703
/*yields*/ {},
706704
SILResultInfo(argc->getType().getASTType(), ResultConvention::Unowned),
707705
/*error result*/ None, SubstitutionMap(), SubstitutionMap(),

0 commit comments

Comments
 (0)