Skip to content

Commit bdd20c4

Browse files
Merge pull request #4964 from swiftwasm/main
[pull] swiftwasm from main
2 parents 0db6d9a + 2a77692 commit bdd20c4

15 files changed

+120
-36
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ ParserResult<Expr> Parser::parseExprUnary(Diag<> Message, bool isExprBasic) {
619619
/// !
620620
/// [ expression ]
621621
ParserResult<Expr> Parser::parseExprKeyPath() {
622-
SyntaxParsingContext KeyPathCtx(SyntaxContext, SyntaxKind::KeyPathExpr);
622+
SyntaxParsingContext KeyPathCtx(SyntaxContext, SyntaxKind::OldKeyPathExpr);
623623
// Consume '\'.
624624
SourceLoc backslashLoc = consumeToken(tok::backslash);
625625
llvm::SaveAndRestore<bool> S(InSwiftKeyPath, true);

lib/Parse/ParseStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ ParserResult<Stmt> Parser::parseStmtYield(SourceLoc tryLoc) {
844844

845845
SmallVector<ExprListElt, 4> yieldElts;
846846
status = parseExprList(tok::l_paren, tok::r_paren, /*isArgumentList*/ false,
847-
lpLoc, yieldElts, rpLoc, SyntaxKind::ExprList);
847+
lpLoc, yieldElts, rpLoc, SyntaxKind::YieldExprList);
848848
for (auto &elt : yieldElts) {
849849
// We don't accept labels in a list of yields.
850850
if (elt.LabelLoc.isValid()) {

lib/Parse/Parser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,8 @@ static SyntaxKind getListElementKind(SyntaxKind ListKind) {
10431043
return SyntaxKind::TuplePatternElement;
10441044
case SyntaxKind::AvailabilitySpecList:
10451045
return SyntaxKind::AvailabilityArgument;
1046+
case SyntaxKind::YieldExprList:
1047+
return SyntaxKind::YieldExprListElement;
10461048
default:
10471049
return SyntaxKind::Unknown;
10481050
}

lib/PrintAsClang/ClangSyntaxPrinter.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,12 +342,12 @@ void ClangSyntaxPrinter::printIncludeForShimHeader(StringRef headerName) {
342342
"swiftToCxx'.\n";
343343
os << "#if __has_include(<../../../swift/swiftToCxx/" << headerName << ">)\n";
344344
os << "#include <../../../swift/swiftToCxx/" << headerName << ">\n";
345-
os << "#elif __has_include(<../../../../lib/swift/swiftToCxx/" << headerName
346-
<< ">)\n";
345+
os << "#elif __has_include(<../../../../../lib/swift/swiftToCxx/"
346+
<< headerName << ">)\n";
347347
os << "// "
348-
"'<toolchain>/usr/local/lib/clang/<version>/include/../../../../lib/"
348+
"'<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/"
349349
"swift/swiftToCxx'.\n";
350-
os << "#include <../../../../lib/swift/swiftToCxx/" << headerName << ">\n";
350+
os << "#include <../../../../../lib/swift/swiftToCxx/" << headerName << ">\n";
351351
os << "// Alternatively, allow user to find the header using additional "
352352
"include path into '<toolchain>/lib/swift'.\n";
353353
os << "#elif __has_include(<swiftToCxx/" << headerName << ">)\n";
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1
1+
2

lib/SIL/IR/OperandOwnership.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,31 @@ OPERAND_OWNERSHIP(PointerEscape, ProjectExistentialBox)
238238
OPERAND_OWNERSHIP(PointerEscape, UncheckedOwnershipConversion)
239239
OPERAND_OWNERSHIP(PointerEscape, ConvertEscapeToNoEscape)
240240

241+
// UncheckedBitwiseCast ownership behaves like RefToUnowned. It produces an
242+
// Unowned values from a non-trivial value, without consuming or borrowing the
243+
// non-trivial value. Unlike RefToUnowned, a bitwise cast works on a compound
244+
// value and may truncate the value. The resulting value is still Unowned and
245+
// should be immediately copied to produce an owned value. These happen for two
246+
// reasons:
247+
//
248+
// (1) A Builtin.reinterpretCast is used on a nontrivial type. If the result is
249+
// non-trivial, then, as part of emitting the cast, SILGen emits a copy_value
250+
// immediately after the unchecked_bitwise_cast for all uses of the cast.
251+
//
252+
// (2) SILGen emits special conversions using SILGenBuilder's
253+
// createUncheckedBitCast utility. For non-trivial types, this emits an
254+
// unchecked_bitwise_cast immediately followed by a copy.
255+
//
256+
// The only thing protecting the lifetime of the Unowned value is the cast
257+
// operand's PointerEscape ownership, which prevents OSSA analysis and blocks
258+
// most optimization of the incoming value.
259+
//
260+
// TODO: Verify that Unowned values are only used by copies and that the cast
261+
// operand's lifetime exceeds the copies.
262+
OPERAND_OWNERSHIP(PointerEscape, UncheckedBitwiseCast)
263+
241264
// Instructions that escape reference bits with unenforced lifetime.
242265
// TODO: verify that BitwiseEscape results always have a trivial type.
243-
OPERAND_OWNERSHIP(BitwiseEscape, UncheckedBitwiseCast)
244266
OPERAND_OWNERSHIP(BitwiseEscape, ValueToBridgeObject)
245267
OPERAND_OWNERSHIP(BitwiseEscape, RefToRawPointer)
246268
OPERAND_OWNERSHIP(BitwiseEscape, UncheckedTrivialBitCast)

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,26 @@ bool swift::findExtendedUsesOfSimpleBorrowedValue(
377377
return true;
378378
}
379379

380+
// TODO: refactor this with SSAPrunedLiveness::computeLiveness.
380381
bool swift::findUsesOfSimpleValue(SILValue value,
381382
SmallVectorImpl<Operand *> *usePoints) {
382383
for (auto *use : value->getUses()) {
383-
if (use->getOperandOwnership() == OperandOwnership::Borrow) {
384+
switch (use->getOperandOwnership()) {
385+
case OperandOwnership::PointerEscape:
386+
return false;
387+
case OperandOwnership::Borrow:
384388
if (!BorrowingOperand(use).visitScopeEndingUses([&](Operand *end) {
385-
if (end->getOperandOwnership() == OperandOwnership::Reborrow) {
386-
return false;
387-
}
388-
usePoints->push_back(end);
389-
return true;
390-
})) {
389+
if (end->getOperandOwnership() == OperandOwnership::Reborrow) {
390+
return false;
391+
}
392+
usePoints->push_back(end);
393+
return true;
394+
})) {
391395
return false;
392396
}
397+
break;
398+
default:
399+
break;
393400
}
394401
usePoints->push_back(use);
395402
}

test/Interop/SwiftToCxx/stdlib/swift-stdlib-in-cxx.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@
7171

7272
// CHECK: #if __has_include(<../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
7373
// CHECK-NEXT: #include <../../../swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
74-
// CHECK-NEXT: #elif __has_include(<../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
75-
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../lib/swift/swiftToCxx'.
76-
// CHECK-NEXT: #include <../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
74+
// CHECK-NEXT: #elif __has_include(<../../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>)
75+
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
76+
// CHECK-NEXT: #include <../../../../../lib/swift/swiftToCxx/_SwiftStdlibCxxOverlay.h>
7777
// CHECK-NEXT: // Alternatively, allow user to find the header using additional include path into '<toolchain>/lib/swift'.
7878
// CHECK-NEXT: #elif __has_include(<swiftToCxx/_SwiftStdlibCxxOverlay.h>)
7979
// CHECK-NEXT: #include <swiftToCxx/_SwiftStdlibCxxOverlay.h>

test/PrintAsCxx/empty.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
// CHECK-NEXT: // '<toolchain>/usr/lib/clang/<version>/include/../../../swift/swiftToCxx'.
3737
// CHECK-NEXT: #if __has_include(<../../../swift/swiftToCxx/_SwiftCxxInteroperability.h>)
3838
// CHECK-NEXT: #include <../../../swift/swiftToCxx/_SwiftCxxInteroperability.h>
39-
// CHECK-NEXT: #elif __has_include(<../../../../lib/swift/swiftToCxx/_SwiftCxxInteroperability.h>)
40-
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../lib/swift/swiftToCxx'.
41-
// CHECK-NEXT: #include <../../../../lib/swift/swiftToCxx/_SwiftCxxInteroperability.h>
39+
// CHECK-NEXT: #elif __has_include(<../../../../../lib/swift/swiftToCxx/_SwiftCxxInteroperability.h>)
40+
// CHECK-NEXT: // '<toolchain>/usr/local/lib/clang/<version>/include/../../../../../lib/swift/swiftToCxx'.
41+
// CHECK-NEXT: #include <../../../../../lib/swift/swiftToCxx/_SwiftCxxInteroperability.h>
4242
// CHECK-NEXT: // Alternatively, allow user to find the header using additional include path into '<toolchain>/lib/swift'.
4343
// CHECK-NEXT: #elif __has_include(<swiftToCxx/_SwiftCxxInteroperability.h>)
4444
// CHECK-NEXT: #include <swiftToCxx/_SwiftCxxInteroperability.h>

test/SILOptimizer/copy_propagation.sil

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ bb0(%instance : @owned $C):
875875
// CHECK-NOT: destroy_value
876876
// CHECK-LABEL: } // end sil function 'dont_extend_beyond_nonoverlapping_endaccess_after_destroyvalue_in_consuming_block'
877877
sil [ossa] @dont_extend_beyond_nonoverlapping_endaccess_after_destroyvalue_in_consuming_block : $@convention(thin) () -> () {
878+
bb0:
878879
%instance = apply undef() : $@convention(thin) () -> @owned C
879880
%addr = alloc_stack [lexical] $C, var
880881
%access = begin_access [static] [modify] %addr : $*C
@@ -885,3 +886,52 @@ sil [ossa] @dont_extend_beyond_nonoverlapping_endaccess_after_destroyvalue_in_co
885886
%retval = tuple()
886887
return %retval : $()
887888
}
889+
890+
sil @closureGetter : $@convention(thin) () -> @owned Optional<@Sendable @callee_guaranteed () -> ()>
891+
892+
// This pattern is produced by SILGen doUncheckedConversion.
893+
// rdar://100527903 (Overrelease of optional closure when using shorthand syntax)
894+
//
895+
// Copy propagation cannot handle a PointerEscape.
896+
//
897+
// CHECK-LABEL: sil hidden [ossa] @testBitwiseClosureEscape : $@convention(thin) () -> () {
898+
// CHECK: [[V:%.*]] = apply %0() : $@convention(thin) () -> @owned Optional<@Sendable @callee_guaranteed () -> ()>
899+
// CHECK: [[CP1:%.*]] = copy_value [[V]] : $Optional<@Sendable @callee_guaranteed () -> ()>
900+
// CHECK: destroy_value [[V]] : $Optional<@Sendable @callee_guaranteed () -> ()>
901+
// CHECK: [[CAST:%.*]] = unchecked_bitwise_cast [[CP1]] : $Optional<@Sendable @callee_guaranteed () -> ()> to $Optional<@callee_guaranteed () -> ()>
902+
// CHECK-NEXT: [[CASTCP:%.*]] = copy_value [[CAST]] : $Optional<@callee_guaranteed () -> ()>
903+
// CHECK: store [[CASTCP]] to [init]
904+
// CHECK: destroy_value [[CP1]] : $Optional<@Sendable @callee_guaranteed () -> ()>
905+
// CHECK-LABEL: } // end sil function 'testBitwiseClosureEscape'
906+
sil hidden [ossa] @testBitwiseClosureEscape : $@convention(thin) () -> () {
907+
bb0:
908+
%2 = function_ref @closureGetter : $@convention(thin) () -> @owned Optional<@Sendable @callee_guaranteed () -> ()>
909+
%3 = apply %2() : $@convention(thin) () -> @owned Optional<@Sendable @callee_guaranteed () -> ()>
910+
%13 = copy_value %3 : $Optional<@Sendable @callee_guaranteed () -> ()>
911+
%14 = alloc_stack $Optional<@callee_guaranteed () -> ()>
912+
destroy_value %3 : $Optional<@Sendable @callee_guaranteed () -> ()>
913+
%17 = unchecked_bitwise_cast %13 : $Optional<@Sendable @callee_guaranteed () -> ()> to $Optional<@callee_guaranteed () -> ()>
914+
%18 = copy_value %17 : $Optional<@callee_guaranteed () -> ()>
915+
store %18 to [init] %14 : $*Optional<@callee_guaranteed () -> ()>
916+
destroy_addr %14 : $*Optional<@callee_guaranteed () -> ()>
917+
destroy_value %13 : $Optional<@Sendable @callee_guaranteed () -> ()>
918+
dealloc_stack %14 : $*Optional<@callee_guaranteed () -> ()>
919+
%99 = tuple ()
920+
return %99 : $()
921+
}
922+
923+
// Lexical destroy hoisting cannot handle a PointerEscape.
924+
//
925+
// CHECK-LABEL: sil [ossa] @testNoLexicalHoistEscape : $@convention(thin) (@owned Optional<@Sendable @callee_guaranteed () -> ()>) -> @owned Optional<@callee_guaranteed () -> ()> {
926+
// CHECK: bb0(%0 : @owned $Optional<@Sendable @callee_guaranteed () -> ()>):
927+
// CHECK: [[CAST:%.*]] = unchecked_bitwise_cast %0 : $Optional<@Sendable @callee_guaranteed () -> ()> to $Optional<@callee_guaranteed () -> ()>
928+
// CHECK: [[COPY:%.*]] = copy_value [[CAST]] : $Optional<@callee_guaranteed () -> ()>
929+
// CHECK: destroy_value %0 : $Optional<@Sendable @callee_guaranteed () -> ()>
930+
// CHECK-LABEL: } // end sil function 'testNoLexicalHoistEscape'
931+
sil [ossa] @testNoLexicalHoistEscape : $@convention(thin) (@owned Optional<@Sendable @callee_guaranteed () -> ()>) -> @owned Optional<@callee_guaranteed () -> ()> {
932+
bb0(%0 : @owned $Optional<@Sendable @callee_guaranteed () -> ()>):
933+
%cast = unchecked_bitwise_cast %0 : $Optional<@Sendable @callee_guaranteed () -> ()> to $Optional<@callee_guaranteed () -> ()>
934+
%copy = copy_value %cast : $Optional<@callee_guaranteed () -> ()>
935+
destroy_value %0 : $Optional<@Sendable @callee_guaranteed () -> ()>
936+
return %copy : $Optional<@callee_guaranteed () -> ()>
937+
}

test/SILOptimizer/copy_propagation_borrow.sil

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,12 @@ bb3:
243243
// CHECK: bb1:
244244
// CHECK-NEXT: [[COPY:%.*]] = copy_value [[OUTERCOPY]] : $C
245245
// CHECK-NEXT: apply %{{.*}}([[COPY]]) : $@convention(thin) (@owned C) -> ()
246-
// CHECK-NEXT: destroy_value %0 : $C
247246
// CHECK-NEXT: br bb3
248247
// CHECK: bb2:
249-
// CHECK-NEXT: destroy_value %0 : $C
250248
// CHECK-NEXT: br bb3
251249
// CHECK: bb3:
252250
// CHECK-NEXT: destroy_value [[OUTERCOPY]] : $C
251+
// CHECK-NEXT: destroy_value %0 : $C
253252
// CHECK-LABEL: } // end sil function 'testLocalBorrowPostDomDestroy'
254253
sil [ossa] @testLocalBorrowPostDomDestroy : $@convention(thin) (@owned C) -> () {
255254
bb0(%0 : @owned $C):
@@ -285,11 +284,9 @@ bb3:
285284
// CHECK: bb1:
286285
// CHECK-NEXT: apply %{{.*}}([[OUTERCOPY]]) : $@convention(thin) (@guaranteed C) -> ()
287286
// CHECK-NEXT: apply %{{.*}}([[OUTERCOPY]]) : $@convention(thin) (@owned C) -> ()
288-
// CHECK-NEXT: destroy_value %0 : $C
289287
// CHECK-NEXT: br bb3
290288
// CHECK: bb2:
291289
// CHECK-NEXT: apply %{{.*}}([[OUTERCOPY]]) : $@convention(thin) (@guaranteed C) -> ()
292-
// CHECK-NEXT: destroy_value %0 : $C
293290
// CHECK-NEXT: destroy_value [[OUTERCOPY]] : $C
294291
// CHECK-NEXT: br bb3
295292
// CHECK: bb3:
@@ -328,13 +325,11 @@ bb3:
328325
// CHECK-NEXT: apply %{{.*}}([[OUTERCOPY]]) : $@convention(thin) (@guaranteed C) -> ()
329326
// CHECK-NEXT: [[ARGCOPY:%.*]] = copy_value [[OUTERCOPY]] : $C
330327
// CHECK-NEXT: apply %2([[OUTERCOPY]], [[ARGCOPY:%.*]]) : $@convention(thin) (@owned C, @owned C) -> ()
331-
// CHECK-NEXT: destroy_value %0 : $C
332328
// CHECK-NEXT: br bb3
333329
// CHECK: bb2:
334330
// CHECK-NEXT: apply %{{.*}}([[OUTERCOPY]]) : $@convention(thin) (@guaranteed C) -> ()
335331
//
336332
// This copy would be eliminated if the outer lifetime were also canonicalized (no unchecked_ownership_conversion)
337-
// CHECK-NEXT: destroy_value %0 : $C
338333
// CHECK-NEXT: [[COPY2:%.*]] = copy_value [[OUTERCOPY]] : $C
339334
// CHECK-NEXT: destroy_value [[COPY2]] : $C
340335
// CHECK-NEXT: destroy_value %4 : $C

test/StringProcessing/Parse/forward-slash-regex-skipping-allowed.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22

3-
// RUN: %target-swift-frontend -parse -enable-bare-slash-regex -disable-availability-checking -experimental-skip-all-function-bodies -stats-output-dir %t %s
3+
// RUN: %target-swift-frontend -parse -enable-bare-slash-regex -disable-availability-checking -experimental-skip-all-function-bodies -verify -stats-output-dir %t %s
44
// RUN: %{python} %utils/process-stats-dir.py --set-csv-baseline %t/stats.csv %t
55
// RUN: %FileCheck -input-file %t/stats.csv %s
66

@@ -13,6 +13,9 @@
1313
// we don't output any non-zero value.
1414
// CHECK-NOT: {{"Parse.NumFunctionsParsed" [^0]}}
1515

16+
// Ensures there is a parse error
17+
var : Int // expected-error{{expected pattern}}
18+
1619
// Balanced `{}`, so okay.
1720
func a() { / {}/ }
1821
func b() { / \{}/ }

0 commit comments

Comments
 (0)