Skip to content

Commit 6336b88

Browse files
authored
Merge pull request #1111 from swiftwasm/master
[pull] swiftwasm from master
2 parents 18324fe + b78bd2e commit 6336b88

File tree

60 files changed

+1263
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1263
-231
lines changed

docs/Lexicon.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,12 @@ and *zero* protocols; the latter is the `Any` type).
167167
Describes a type or function where making changes will break binary
168168
compatibility. See [LibraryEvolution.rst](LibraryEvolution.rst).
169169

170+
## gardening
171+
172+
Describes contributions which fix code that is not executed
173+
(such as in a manifesto or README) and written text
174+
(correcting typos and grammatical errors).
175+
170176
## generic environment
171177

172178
Provides context for interpreting a type that may have generic parameters

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,10 @@ WARNING(tbd_only_supported_in_whole_module,none,
230230
"TBD generation is only supported when the whole module can be seen",
231231
())
232232

233+
ERROR(tbd_not_supported_with_cmo,none,
234+
"Test-Based InstallAPI (TBD) is not support with cross-module-optimization",
235+
())
236+
233237
WARNING(linker_directives_choice_confusion,none,
234238
"only one of -emit-ldadd-cfile-path and -module-installname-map-file can be specified;"
235239
"the c file won't be generated",

include/swift/AST/SemanticAttrs.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ SEMANTICS_ATTR(ARRAY_GET_ELEMENT_ADDRESS, "array.get_element_address")
5151
SEMANTICS_ATTR(ARRAY_INIT, "array.init")
5252
SEMANTICS_ATTR(ARRAY_INIT_EMPTY, "array.init.empty")
5353
SEMANTICS_ATTR(ARRAY_MAKE_MUTABLE, "array.make_mutable")
54+
SEMANTICS_ATTR(ARRAY_END_MUTATION, "array.end_mutation")
5455
SEMANTICS_ATTR(ARRAY_MUTATE_UNKNOWN, "array.mutate_unknown")
5556
SEMANTICS_ATTR(ARRAY_PROPS_IS_NATIVE_TYPE_CHECKED, "array.props.isNativeTypeChecked")
5657
SEMANTICS_ATTR(ARRAY_RESERVE_CAPACITY_FOR_APPEND, "array.reserve_capacity_for_append")
@@ -67,6 +68,8 @@ SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_PARTIAL_NEVER,
6768
"optimize.sil.specialize.generic.partial.never")
6869
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_GENERIC_SIZE_NEVER,
6970
"optimize.sil.specialize.generic.size.never")
71+
SEMANTICS_ATTR(OPTIMIZE_SIL_SPECIALIZE_OWNED2GUARANTEE_NEVER,
72+
"optimize.sil.specialize.owned2guarantee.never")
7073

7174
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_INTERPOLATION, "oslog.message.init_interpolation")
7275
SEMANTICS_ATTR(OSLOG_MESSAGE_INIT_STRING_LITERAL, "oslog.message.init_stringliteral")

include/swift/SILOptimizer/Analysis/ArraySemantic.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum class ArrayCallKind {
3131
kGetElement,
3232
kGetElementAddress,
3333
kMakeMutable,
34+
kEndMutation,
3435
kMutateUnknown,
3536
kReserveCapacityForAppend,
3637
kWithUnsafeMutableBufferPointer,
@@ -42,7 +43,8 @@ enum class ArrayCallKind {
4243
// before this comment.
4344
kArrayInit,
4445
kArrayUninitialized,
45-
kArrayUninitializedIntrinsic
46+
kArrayUninitializedIntrinsic,
47+
kArrayFinalizeIntrinsic
4648
};
4749

4850
/// Return true is the given function is an array semantics call.
@@ -78,6 +80,8 @@ class ArraySemanticsCall {
7880
ArraySemanticsCall(SILValue V, StringRef semanticName,
7981
bool matchPartialName);
8082

83+
ArraySemanticsCall() : SemanticsCall(nullptr) {}
84+
8185
/// Can we hoist this call.
8286
bool canHoist(SILInstruction *To, DominanceInfo *DT) const;
8387

include/swift/SILOptimizer/PassManager/Passes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ PASS(CopyForwarding, "copy-forwarding",
120120
"Copy Forwarding to Remove Redundant Copies")
121121
PASS(CopyPropagation, "copy-propagation",
122122
"Copy propagation to Remove Redundant SSA Copies")
123+
PASS(COWOpts, "cow-opts",
124+
"Optimize COW operations")
123125
PASS(Differentiation, "differentiation",
124126
"Automatic Differentiation")
125127
PASS(EpilogueARCMatcherDumper, "sil-epilogue-arc-dumper",

lib/ClangImporter/ImportName.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "clang/AST/ASTContext.h"
3535
#include "clang/Basic/IdentifierTable.h"
3636
#include "clang/Basic/Module.h"
37+
#include "clang/Basic/OperatorKinds.h"
3738
#include "clang/Lex/Preprocessor.h"
3839
#include "clang/Parse/Parser.h"
3940
#include "clang/Sema/Lookup.h"
@@ -1410,12 +1411,35 @@ ImportedName NameImporter::importNameImpl(const clang::NamedDecl *D,
14101411
case clang::DeclarationName::CXXConversionFunctionName:
14111412
case clang::DeclarationName::CXXDestructorName:
14121413
case clang::DeclarationName::CXXLiteralOperatorName:
1413-
case clang::DeclarationName::CXXOperatorName:
14141414
case clang::DeclarationName::CXXUsingDirective:
14151415
case clang::DeclarationName::CXXDeductionGuideName:
14161416
// TODO: Handling these is part of C++ interoperability.
14171417
return ImportedName();
14181418

1419+
case clang::DeclarationName::CXXOperatorName: {
1420+
auto op = D->getDeclName().getCXXOverloadedOperator();
1421+
switch (op) {
1422+
case clang::OverloadedOperatorKind::OO_Plus:
1423+
case clang::OverloadedOperatorKind::OO_Minus:
1424+
case clang::OverloadedOperatorKind::OO_Star:
1425+
case clang::OverloadedOperatorKind::OO_Slash:
1426+
if (auto FD = dyn_cast<clang::FunctionDecl>(D)) {
1427+
baseName = clang::getOperatorSpelling(op);
1428+
isFunction = true;
1429+
argumentNames.resize(FD->param_size());
1430+
} else {
1431+
// This can happen for example for templated operators functions.
1432+
// We don't support those, yet.
1433+
return ImportedName();
1434+
}
1435+
break;
1436+
default:
1437+
// We don't import these yet.
1438+
return ImportedName();
1439+
}
1440+
break;
1441+
}
1442+
14191443
case clang::DeclarationName::Identifier:
14201444
// Map the identifier.
14211445
baseName = D->getDeclName().getAsIdentifierInfo()->getName();

lib/Frontend/ModuleInterfaceBuilder.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "swift/AST/DiagnosticsSema.h"
2020
#include "swift/AST/FileSystem.h"
2121
#include "swift/AST/Module.h"
22-
#include "llvm/ADT/StringSet.h"
2322
#include "swift/Basic/Defer.h"
2423
#include "swift/Frontend/Frontend.h"
2524
#include "swift/Frontend/ModuleInterfaceSupport.h"
@@ -28,7 +27,6 @@
2827
#include "clang/Frontend/CompilerInstance.h"
2928
#include "clang/Lex/PreprocessorOptions.h"
3029
#include "llvm/ADT/Hashing.h"
31-
#include "llvm/ADT/StringSet.h"
3230
#include "llvm/Support/xxhash.h"
3331
#include "llvm/Support/Debug.h"
3432
#include "llvm/Support/CommandLine.h"
@@ -85,7 +83,6 @@ bool ModuleInterfaceBuilder::collectDepsForSerialization(
8583
InitialDepNames.push_back(interfacePath);
8684
InitialDepNames.insert(InitialDepNames.end(),
8785
extraDependencies.begin(), extraDependencies.end());
88-
llvm::StringSet<> AllDepNames;
8986
SmallString<128> Scratch;
9087

9188
for (const auto &InitialDepName : InitialDepNames) {
@@ -104,7 +101,7 @@ bool ModuleInterfaceBuilder::collectDepsForSerialization(
104101
if (!prebuiltCachePath.empty() && DepName.startswith(prebuiltCachePath))
105102
continue;
106103

107-
if (AllDepNames.insert(DepName).second && dependencyTracker) {
104+
if (dependencyTracker) {
108105
dependencyTracker->addDependency(DepName, /*isSystem*/IsSDKRelative);
109106
}
110107

lib/FrontendTool/FrontendTool.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,12 @@ static bool writeTBDIfNeeded(CompilerInstance &Instance) {
10041004
return false;
10051005
}
10061006

1007+
if (Invocation.getSILOptions().CrossModuleOptimization) {
1008+
Instance.getDiags().diagnose(SourceLoc(),
1009+
diag::tbd_not_supported_with_cmo);
1010+
return false;
1011+
}
1012+
10071013
const std::string &TBDPath = Invocation.getTBDPathForWholeModule();
10081014

10091015
return writeTBD(Instance.getMainModule(), TBDPath, tbdOpts);
@@ -1404,7 +1410,7 @@ static bool validateTBDIfNeeded(const CompilerInvocation &Invocation,
14041410
return false;
14051411
}
14061412

1407-
// Cross-module optimization does not yet support TBD validation.
1413+
// Cross-module optimization does not support TBD.
14081414
if (Invocation.getSILOptions().CrossModuleOptimization) {
14091415
return false;
14101416
}

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ SILValue swift::stripCastsWithoutMarkDependence(SILValue V) {
128128

129129
auto K = V->getKind();
130130
if (isRCIdentityPreservingCast(K) ||
131-
K == ValueKind::UncheckedTrivialBitCastInst) {
131+
K == ValueKind::UncheckedTrivialBitCastInst ||
132+
K == ValueKind::EndCOWMutationInst) {
132133
V = cast<SingleValueInstruction>(V)->getOperand(0);
133134
continue;
134135
}
@@ -308,7 +309,8 @@ bool swift::onlyAffectsRefCount(SILInstruction *user) {
308309
}
309310

310311
bool swift::mayCheckRefCount(SILInstruction *User) {
311-
return isa<IsUniqueInst>(User) || isa<IsEscapingClosureInst>(User);
312+
return isa<IsUniqueInst>(User) || isa<IsEscapingClosureInst>(User) ||
313+
isa<BeginCOWMutationInst>(User);
312314
}
313315

314316
bool swift::isSanitizerInstrumentation(SILInstruction *Instruction) {

lib/SIL/Utils/Projection.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,13 @@ Optional<ProjectionPath> ProjectionPath::getProjectionPath(SILValue Start,
371371

372372
auto Iter = End;
373373
while (Start != Iter) {
374-
Projection AP(Iter);
375-
if (!AP.isValid())
376-
break;
377-
P.Path.push_back(AP);
374+
// end_cow_mutation is not a projection, but we want to "see through" it.
375+
if (!isa<EndCOWMutationInst>(Iter)) {
376+
Projection AP(Iter);
377+
if (!AP.isValid())
378+
break;
379+
P.Path.push_back(AP);
380+
}
378381
Iter = cast<SingleValueInstruction>(*Iter).getOperand(0);
379382
}
380383

lib/SILOptimizer/Analysis/ArraySemantic.cpp

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ ArrayCallKind swift::getArraySemanticsKind(SILFunction *f) {
3333
.StartsWith("array.init", ArrayCallKind::kArrayInit)
3434
.Case("array.uninitialized", ArrayCallKind::kArrayUninitialized)
3535
.Case("array.uninitialized_intrinsic", ArrayCallKind::kArrayUninitializedIntrinsic)
36+
.Case("array.finalize_intrinsic", ArrayCallKind::kArrayFinalizeIntrinsic)
3637
.Case("array.check_subscript", ArrayCallKind::kCheckSubscript)
3738
.Case("array.check_index", ArrayCallKind::kCheckIndex)
3839
.Case("array.get_count", ArrayCallKind::kGetCount)
3940
.Case("array.get_capacity", ArrayCallKind::kGetCapacity)
4041
.Case("array.get_element", ArrayCallKind::kGetElement)
4142
.Case("array.make_mutable", ArrayCallKind::kMakeMutable)
43+
.Case("array.end_mutation", ArrayCallKind::kEndMutation)
4244
.Case("array.get_element_address",
4345
ArrayCallKind::kGetElementAddress)
4446
.Case("array.mutate_unknown", ArrayCallKind::kMutateUnknown)
@@ -101,10 +103,12 @@ bool swift::ArraySemanticsCall::isValidSignature() {
101103
}
102104
case ArrayCallKind::kCheckSubscript: {
103105
// Int, Bool, Self
104-
if (SemanticsCall->getNumArguments() != 3 ||
105-
!SemanticsCall->getArgument(0)->getType().isTrivial(*F))
106+
unsigned numArgs = SemanticsCall->getNumArguments();
107+
if (numArgs != 2 && numArgs != 3)
108+
return false;
109+
if (!SemanticsCall->getArgument(0)->getType().isTrivial(*F))
106110
return false;
107-
if (!SemanticsCall->getArgument(1)->getType().isTrivial(*F))
111+
if (numArgs == 3 && !SemanticsCall->getArgument(1)->getType().isTrivial(*F))
108112
return false;
109113
auto SelfConvention = FnTy->getSelfParameter().getConvention();
110114
return SelfConvention == ParameterConvention::Direct_Guaranteed ||
@@ -324,27 +328,26 @@ bool swift::ArraySemanticsCall::canHoist(SILInstruction *InsertBefore,
324328
// Not implemented yet.
325329
return false;
326330

327-
case ArrayCallKind::kCheckSubscript: {
328-
auto IsNativeArg = getArrayPropertyIsNativeTypeChecked();
329-
ArraySemanticsCall IsNative(IsNativeArg,
330-
"array.props.isNativeTypeChecked", true);
331-
if (!IsNative) {
332-
// Do we have a constant parameter?
333-
auto *SI = dyn_cast<StructInst>(IsNativeArg);
334-
if (!SI)
335-
return false;
336-
if (!isa<IntegerLiteralInst>(SI->getOperand(0)))
331+
case ArrayCallKind::kCheckSubscript:
332+
if (SILValue IsNativeArg = getArrayPropertyIsNativeTypeChecked()) {
333+
ArraySemanticsCall IsNative(IsNativeArg,
334+
"array.props.isNativeTypeChecked", true);
335+
if (!IsNative) {
336+
// Do we have a constant parameter?
337+
auto *SI = dyn_cast<StructInst>(IsNativeArg);
338+
if (!SI)
339+
return false;
340+
if (!isa<IntegerLiteralInst>(SI->getOperand(0)))
341+
return false;
342+
} else if (!IsNative.canHoist(InsertBefore, DT))
343+
// Otherwise, we must be able to hoist the function call.
337344
return false;
338-
} else if (!IsNative.canHoist(InsertBefore, DT))
339-
// Otherwise, we must be able to hoist the function call.
340-
return false;
341-
345+
}
342346
return canHoistArrayArgument(SemanticsCall, getSelf(), InsertBefore, DT);
343-
}
344347

345-
case ArrayCallKind::kMakeMutable: {
348+
case ArrayCallKind::kMakeMutable:
349+
case ArrayCallKind::kEndMutation:
346350
return canHoistArrayArgument(SemanticsCall, getSelf(), InsertBefore, DT);
347-
}
348351
} // End switch.
349352

350353
return false;
@@ -448,9 +451,8 @@ ApplyInst *swift::ArraySemanticsCall::hoistOrCopy(SILInstruction *InsertBefore,
448451
hoistOrCopySelf(SemanticsCall, InsertBefore, DT, LeaveOriginal);
449452

450453
SILValue NewArrayProps;
451-
if (Kind == ArrayCallKind::kCheckSubscript) {
454+
if (SILValue IsNativeArg = getArrayPropertyIsNativeTypeChecked()) {
452455
// Copy the array.props argument call.
453-
auto IsNativeArg = getArrayPropertyIsNativeTypeChecked();
454456
ArraySemanticsCall IsNative(IsNativeArg,
455457
"array.props.isNativeTypeChecked", true);
456458
if (!IsNative) {
@@ -492,8 +494,8 @@ ApplyInst *swift::ArraySemanticsCall::hoistOrCopy(SILInstruction *InsertBefore,
492494
return Call;
493495
}
494496

495-
case ArrayCallKind::kMakeMutable: {
496-
assert(!LeaveOriginal && "Copying not yet implemented");
497+
case ArrayCallKind::kMakeMutable:
498+
case ArrayCallKind::kEndMutation: {
497499
// Hoist the call.
498500
auto Call = hoistOrCopyCall(SemanticsCall, InsertBefore, LeaveOriginal, DT);
499501
return Call;
@@ -515,14 +517,15 @@ void swift::ArraySemanticsCall::removeCall() {
515517

516518
switch (getKind()) {
517519
default: break;
518-
case ArrayCallKind::kCheckSubscript: {
519-
// Remove all uses with the empty tuple ().
520-
auto EmptyDep = SILBuilderWithScope(SemanticsCall)
521-
.createStruct(SemanticsCall->getLoc(),
522-
SemanticsCall->getType(), {});
523-
SemanticsCall->replaceAllUsesWith(EmptyDep);
524-
}
525-
break;
520+
case ArrayCallKind::kCheckSubscript:
521+
if (!SemanticsCall->getType().isVoid()){
522+
// Remove all uses with the empty tuple ().
523+
auto EmptyDep = SILBuilderWithScope(SemanticsCall)
524+
.createStruct(SemanticsCall->getLoc(),
525+
SemanticsCall->getType(), {});
526+
SemanticsCall->replaceAllUsesWith(EmptyDep);
527+
}
528+
break;
526529
case ArrayCallKind::kGetElement: {
527530
// Remove the matching isNativeTypeChecked and check_subscript call.
528531
ArraySemanticsCall IsNative(getTypeCheckedArgument(),
@@ -552,11 +555,13 @@ SILValue
552555
swift::ArraySemanticsCall::getArrayPropertyIsNativeTypeChecked() const {
553556
switch (getKind()) {
554557
case ArrayCallKind::kCheckSubscript:
555-
return SemanticsCall->getArgument(1);
558+
if (SemanticsCall->getNumArguments() == 3)
559+
return SemanticsCall->getArgument(1);
560+
return SILValue();
556561
case ArrayCallKind::kGetElement:
557562
return getTypeCheckedArgument();
558563
default:
559-
llvm_unreachable("Must have an array.props argument");
564+
return SILValue();
560565
}
561566
}
562567

@@ -569,6 +574,7 @@ bool swift::ArraySemanticsCall::doesNotChangeArray() const {
569574
case ArrayCallKind::kGetCount:
570575
case ArrayCallKind::kGetCapacity:
571576
case ArrayCallKind::kGetElement:
577+
case ArrayCallKind::kEndMutation:
572578
return true;
573579
}
574580
}

lib/SILOptimizer/Analysis/EscapeAnalysis.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,7 @@ void EscapeAnalysis::analyzeInstruction(SILInstruction *I,
22852285
case SILInstructionKind::SelectValueInst:
22862286
analyzeSelectInst(cast<SelectValueInst>(I), ConGraph);
22872287
return;
2288+
case SILInstructionKind::EndCOWMutationInst:
22882289
case SILInstructionKind::StructInst:
22892290
case SILInstructionKind::TupleInst:
22902291
case SILInstructionKind::EnumInst: {

0 commit comments

Comments
 (0)