Skip to content

Commit 172093a

Browse files
Merge pull request #5425 from swiftwasm/main
[pull] swiftwasm from main
2 parents b907987 + 89b9e48 commit 172093a

File tree

78 files changed

+1759
-1876
lines changed

Some content is hidden

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

78 files changed

+1759
-1876
lines changed

Diff for: CMakeLists.txt

+4
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,10 @@ option(SWIFT_ENABLE_EXPERIMENTAL_CXX_INTEROP
614614
"Enable experimental C++ interop modules"
615615
FALSE)
616616

617+
option(SWIFT_ENABLE_CXX_INTEROP_SWIFT_BRIDGING_HEADER
618+
"Install the <swift/bridging> C++ interoperability header alongside compiler"
619+
TRUE)
620+
617621
option(SWIFT_ENABLE_EXPERIMENTAL_DISTRIBUTED
618622
"Enable experimental distributed actors and functions"
619623
FALSE)

Diff for: SwiftCompilerSources/Sources/Optimizer/PassManager/PassRegistration.swift

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ private func registerSwiftPasses() {
9292
registerPass(addressEscapeInfoDumper, { addressEscapeInfoDumper.run($0) })
9393
registerPass(accessDumper, { accessDumper.run($0) })
9494
registerPass(deadEndBlockDumper, { deadEndBlockDumper.run($0) })
95+
registerPass(memBehaviorDumper, { memBehaviorDumper.run($0) })
9596
registerPass(rangeDumper, { rangeDumper.run($0) })
9697
registerPass(runUnitTests, { runUnitTests.run($0) })
9798
registerPass(testInstructionIteration, { testInstructionIteration.run($0) })

Diff for: SwiftCompilerSources/Sources/Optimizer/TestPasses/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ swift_compiler_sources(Optimizer
1111
AccessDumper.swift
1212
DeadEndBlockDumper.swift
1313
EscapeInfoDumper.swift
14+
MemBehaviorDumper.swift
1415
SILPrinter.swift
1516
RangeDumper.swift
1617
RunUnitTests.swift
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//===--- MemBehaviorDumper.swift ------------------------------------------===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2023 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SIL
14+
15+
/// Prints the memory behavior of relevant instructions in relation to address values of the function.
16+
let memBehaviorDumper = FunctionPass(name: "dump-mem-behavior") {
17+
(function: Function, context: FunctionPassContext) in
18+
19+
let aliasAnalysis = context.aliasAnalysis
20+
21+
print("@\(function.name)")
22+
23+
let values = function.allValues
24+
25+
var currentPair = 0
26+
for inst in function.instructions where inst.shouldTest {
27+
28+
for value in values where value.definingInstruction != inst {
29+
30+
if value.type.isAddress || value is AddressToPointerInst {
31+
let read = aliasAnalysis.mayRead(inst, fromAddress: value)
32+
let write = aliasAnalysis.mayWrite(inst, toAddress: value)
33+
print("PAIR #\(currentPair).")
34+
print(" \(inst)")
35+
print(" \(value)")
36+
print(" r=\(read ? 1 : 0),w=\(write ? 1 : 0)")
37+
currentPair += 1
38+
}
39+
}
40+
}
41+
print()
42+
}
43+
44+
private extension Function {
45+
var allValues: [Value] {
46+
var values: [Value] = []
47+
for block in blocks {
48+
values.append(contentsOf: block.arguments.map { $0 })
49+
for inst in block.instructions {
50+
values.append(contentsOf: inst.results)
51+
}
52+
}
53+
return values
54+
}
55+
}
56+
57+
private extension Instruction {
58+
var shouldTest: Bool {
59+
switch self {
60+
case is ApplyInst,
61+
is TryApplyInst,
62+
is EndApplyInst,
63+
is BeginApplyInst,
64+
is AbortApplyInst,
65+
is BeginAccessInst,
66+
is EndAccessInst,
67+
is EndCOWMutationInst,
68+
is CopyValueInst,
69+
is DestroyValueInst,
70+
is EndBorrowInst,
71+
is LoadInst,
72+
is StoreInst,
73+
is CopyAddrInst,
74+
is BuiltinInst:
75+
return true
76+
default:
77+
return false
78+
}
79+
}
80+
}

Diff for: include/swift/AST/DiagnosticsParse.def

+7-3
Original file line numberDiff line numberDiff line change
@@ -1092,9 +1092,13 @@ NOTE(indent_expression_to_silence,none,
10921092
ERROR(expected_expr_throw,PointsToFirstBadToken,
10931093
"expected expression in 'throw' statement", ())
10941094

1095-
// Forget Statement
1096-
ERROR(expected_expr_forget,PointsToFirstBadToken,
1097-
"expected expression in 'forget' statement", ())
1095+
// Discard Statement
1096+
ERROR(expected_expr_discard,PointsToFirstBadToken,
1097+
"expected expression in 'discard' statement", ())
1098+
WARNING(forget_is_deprecated,PointsToFirstBadToken,
1099+
"'_forget' keyword is deprecated and will be removed soon; "
1100+
"use 'discard' instead",
1101+
())
10981102

10991103
// Await/Async
11001104
ERROR(expected_await_not_async,none,

Diff for: include/swift/AST/DiagnosticsSIL.def

+5-5
Original file line numberDiff line numberDiff line change
@@ -735,15 +735,15 @@ ERROR(noimplicitcopy_used_on_generic_or_existential, none,
735735
"@_noImplicitCopy can not be used on a generic or existential typed "
736736
"binding or a nominal type containing such typed things", ())
737737

738-
// forget statement
739-
ERROR(forget_nontrivial_storage,none,
740-
"can only 'forget' type %0 if it contains trivially-destroyed "
738+
// discard statement
739+
ERROR(discard_nontrivial_storage,none,
740+
"can only 'discard' type %0 if it contains trivially-destroyed "
741741
"stored properties at this time",
742742
(Type))
743-
NOTE(forget_nontrivial_storage_note,none,
743+
NOTE(discard_nontrivial_storage_note,none,
744744
"type %0 cannot be trivially destroyed",
745745
(Type))
746-
NOTE(forget_nontrivial_implicit_storage_note,none,
746+
NOTE(discard_nontrivial_implicit_storage_note,none,
747747
"type %0 implicitly contains %1 which cannot be trivially destroyed",
748748
(Type, Type))
749749

Diff for: include/swift/AST/DiagnosticsSema.def

+19-19
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,8 @@ ERROR(cannot_convert_yield_value_protocol,none,
493493
ERROR(cannot_convert_yield_value_nil,none,
494494
"nil is not compatible with expected yield type %0", (Type))
495495

496-
ERROR(cannot_convert_forget_value,none,
497-
"cannot convert value of type %0 to expected forget type %1",
496+
ERROR(cannot_convert_discard_value,none,
497+
"cannot convert value of type %0 to expected discard type %1",
498498
(Type,Type))
499499

500500
ERROR(cannot_convert_closure_result,none,
@@ -4609,30 +4609,30 @@ ERROR(opaque_type_var_no_underlying_type,none,
46094609

46104610

46114611
//------------------------------------------------------------------------------
4612-
// MARK: Forget Statement
4612+
// MARK: Discard Statement
46134613
//------------------------------------------------------------------------------
4614-
ERROR(forget_wrong_context_decl,none,
4615-
"'forget' statement cannot appear in %0",
4614+
ERROR(discard_wrong_context_decl,none,
4615+
"'discard' statement cannot appear in %0",
46164616
(DescriptiveDeclKind))
4617-
ERROR(forget_no_deinit,none,
4618-
"'forget' has no effect for type %0 unless it has a deinitializer",
4617+
ERROR(discard_no_deinit,none,
4618+
"'discard' has no effect for type %0 unless it has a deinitializer",
46194619
(Type))
4620-
ERROR(forget_wrong_context_closure,none,
4621-
"'forget' statement cannot appear in closure",
4620+
ERROR(discard_wrong_context_closure,none,
4621+
"'discard' statement cannot appear in closure",
46224622
())
4623-
ERROR(forget_wrong_context_misc,none,
4624-
"'forget' statement cannot appear in this context",
4623+
ERROR(discard_wrong_context_misc,none,
4624+
"'discard' statement cannot appear in this context",
46254625
())
4626-
ERROR(forget_wrong_context_copyable,none,
4627-
"'forget' statement can only appear in noncopyable type's member",
4626+
ERROR(discard_wrong_context_copyable,none,
4627+
"'discard' statement can only appear in noncopyable type's member",
46284628
(DescriptiveDeclKind))
4629-
ERROR(forget_wrong_context_nonconsuming,none,
4630-
"'forget' statement can only appear in consuming %0",
4629+
ERROR(discard_wrong_context_nonconsuming,none,
4630+
"'discard' statement can only appear in consuming %0",
46314631
(DescriptiveDeclKind))
4632-
ERROR(forget_wrong_not_self,none,
4633-
"you can only forget 'self'", ())
4634-
ERROR(forget_wrong_module,none,
4635-
"can only 'forget' from the same module defining type %0",
4632+
ERROR(discard_wrong_not_self,none,
4633+
"you can only discard 'self'", ())
4634+
ERROR(discard_wrong_module,none,
4635+
"can only 'discard' from the same module defining type %0",
46364636
(Type))
46374637

46384638
//------------------------------------------------------------------------------

Diff for: include/swift/AST/NameLookup.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ class FindLocalVal : public StmtVisitor<FindLocalVal> {
650650
void visitReturnStmt(ReturnStmt *) {}
651651
void visitYieldStmt(YieldStmt *) {}
652652
void visitThrowStmt(ThrowStmt *) {}
653-
void visitForgetStmt(ForgetStmt *) {}
653+
void visitDiscardStmt(DiscardStmt *) {}
654654
void visitPoundAssertStmt(PoundAssertStmt *) {}
655655
void visitDeferStmt(DeferStmt *DS) {
656656
// Nothing in the defer is visible.

Diff for: include/swift/AST/Stmt.h

+12-11
Original file line numberDiff line numberDiff line change
@@ -1510,25 +1510,26 @@ class ThrowStmt : public Stmt {
15101510
}
15111511
};
15121512

1513-
/// ForgetStmt - Consumes a noncopyable value and performs memberwise
1513+
/// DiscardStmt - Consumes a noncopyable value and performs memberwise
15141514
/// destruction of unconsumed fields, without invoking its deinit. Only
1515-
/// supported form is "forget self".
1516-
class ForgetStmt : public Stmt {
1515+
/// supported form is "discard self".
1516+
class DiscardStmt : public Stmt {
15171517
Expr *SubExpr;
1518-
SourceLoc ForgetLoc;
1518+
SourceLoc DiscardLoc;
15191519
AbstractFunctionDecl *InnermostMethod;
15201520

15211521
public:
1522-
explicit ForgetStmt(SourceLoc forgetLoc, Expr *subExpr)
1523-
: Stmt(StmtKind::Forget, /*Implicit=*/false),
1524-
SubExpr(subExpr), ForgetLoc(forgetLoc), InnermostMethod(nullptr) {}
1522+
explicit DiscardStmt(SourceLoc discardLoc, Expr *subExpr)
1523+
: Stmt(StmtKind::Discard, /*Implicit=*/false),
1524+
SubExpr(subExpr), DiscardLoc(discardLoc), InnermostMethod(nullptr) {}
15251525

1526-
SourceLoc getForgetLoc() const { return ForgetLoc; }
1526+
/// Location of the 'discard' keyword.
1527+
SourceLoc getDiscardLoc() const { return DiscardLoc; }
15271528

1528-
SourceLoc getStartLoc() const { return ForgetLoc; }
1529+
SourceLoc getStartLoc() const { return DiscardLoc; }
15291530
SourceLoc getEndLoc() const;
15301531
SourceRange getSourceRange() const {
1531-
return SourceRange(ForgetLoc, getEndLoc());
1532+
return SourceRange(DiscardLoc, getEndLoc());
15321533
}
15331534

15341535
Expr *getSubExpr() const { return SubExpr; }
@@ -1544,7 +1545,7 @@ class ForgetStmt : public Stmt {
15441545
}
15451546

15461547
static bool classof(const Stmt *S) {
1547-
return S->getKind() == StmtKind::Forget;
1548+
return S->getKind() == StmtKind::Discard;
15481549
}
15491550
};
15501551

Diff for: include/swift/AST/StmtNodes.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ STMT(Continue, Stmt)
6666
STMT(Fallthrough, Stmt)
6767
STMT(Fail, Stmt)
6868
STMT(Throw, Stmt)
69-
STMT(Forget, Stmt)
69+
STMT(Discard, Stmt)
7070
STMT(PoundAssert, Stmt)
7171
LAST_STMT(PoundAssert)
7272

Diff for: include/swift/Parse/Parser.h

+11-10
Original file line numberDiff line numberDiff line change
@@ -600,18 +600,19 @@ class Parser {
600600
cast<AccessorDecl>(CurDeclContext)->isCoroutine());
601601
}
602602

603-
/// `forget self` is the only valid phrase, but we peek ahead for just any
604-
/// identifier after `forget` to determine if it's the statement. This helps
605-
/// us avoid interpreting `forget(self)` as the statement and not a call.
606-
/// We also want to be mindful of statements like `forget ++ something` where
603+
/// `discard self` is the only valid phrase, but we peek ahead for just any
604+
/// identifier after `discard` to determine if it's the statement. This helps
605+
/// us avoid interpreting `discard(self)` as the statement and not a call.
606+
/// We also want to be mindful of statements like `discard ++ something` where
607607
/// folks have defined a custom operator returning void.
608608
///
609-
/// Later, type checking will verify that you're forgetting the right thing
610-
/// so that when people make a mistake, thinking they can `forget x` we give
609+
/// Later, type checking will verify that you're discarding the right thing
610+
/// so that when people make a mistake, thinking they can `discard x` we give
611611
/// a nice diagnostic.
612-
bool isContextualForgetKeyword() {
613-
// must be `forget` ...
614-
if (!Tok.isContextualKeyword("_forget"))
612+
bool isContextualDiscardKeyword() {
613+
// must be `discard` ...
614+
if (!(Tok.isContextualKeyword("_forget") // NOTE: support for deprecated _forget
615+
|| Tok.isContextualKeyword("discard")))
615616
return false;
616617

617618
// followed by either an identifier, `self`, or `Self`.
@@ -1860,7 +1861,7 @@ class Parser {
18601861
ParserResult<Stmt> parseStmtReturn(SourceLoc tryLoc);
18611862
ParserResult<Stmt> parseStmtYield(SourceLoc tryLoc);
18621863
ParserResult<Stmt> parseStmtThrow(SourceLoc tryLoc);
1863-
ParserResult<Stmt> parseStmtForget();
1864+
ParserResult<Stmt> parseStmtDiscard();
18641865
ParserResult<Stmt> parseStmtDefer();
18651866
ParserStatus
18661867
parseStmtConditionElement(SmallVectorImpl<StmtConditionElement> &result,

Diff for: include/swift/SILOptimizer/PassManager/Passes.def

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ PASS(MandatoryInlining, "mandatory-inlining",
301301
"Mandatory Inlining of Transparent Functions")
302302
PASS(Mem2Reg, "mem2reg",
303303
"Memory to SSA Value Conversion to Remove Stack Allocation")
304-
PASS(MemBehaviorDumper, "mem-behavior-dump",
304+
SWIFT_FUNCTION_PASS(MemBehaviorDumper, "dump-mem-behavior",
305305
"Print SIL Instruction MemBehavior from Alias Analysis over all Pairs")
306306
PASS(LSLocationPrinter, "lslocation-dump",
307307
"Print Load-Store Location Results Covering all Accesses")

Diff for: include/swift/Sema/ConstraintLocator.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ enum ContextualTypePurpose : uint8_t {
5454
CTP_YieldByValue, ///< By-value yield operand.
5555
CTP_YieldByReference, ///< By-reference yield operand.
5656
CTP_ThrowStmt, ///< Value specified to a 'throw' statement.
57-
CTP_ForgetStmt, ///< Value specified to a 'forget' statement.
57+
CTP_DiscardStmt, ///< Value specified to a 'discard' statement.
5858
CTP_EnumCaseRawValue, ///< Raw value specified for "case X = 42" in enum.
5959
CTP_DefaultParameter, ///< Default value in parameter 'foo(a : Int = 42)'.
6060

Diff for: lib/AST/ASTDumper.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1804,8 +1804,8 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
18041804
PrintWithColorRAII(OS, ParenthesisColor) << ')';
18051805
}
18061806

1807-
void visitForgetStmt(ForgetStmt *S) {
1808-
printCommon(S, "forget_stmt") << '\n';
1807+
void visitDiscardStmt(DiscardStmt *S) {
1808+
printCommon(S, "discard_stmt") << '\n';
18091809
printRec(S->getSubExpr());
18101810
PrintWithColorRAII(OS, ParenthesisColor) << ')';
18111811
}

Diff for: lib/AST/ASTPrinter.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -5403,8 +5403,8 @@ void PrintAST::visitThrowStmt(ThrowStmt *stmt) {
54035403
visit(stmt->getSubExpr());
54045404
}
54055405

5406-
void PrintAST::visitForgetStmt(ForgetStmt *stmt) {
5407-
Printer << "_forget" << " ";
5406+
void PrintAST::visitDiscardStmt(DiscardStmt *stmt) {
5407+
Printer << "discard" << " ";
54085408
visit(stmt->getSubExpr());
54095409
}
54105410

Diff for: lib/AST/ASTScopeCreation.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -500,9 +500,9 @@ class NodeAdder
500500
return p;
501501
}
502502

503-
ASTScopeImpl *visitForgetStmt(ForgetStmt *fs, ASTScopeImpl *p,
504-
ScopeCreator &scopeCreator) {
505-
visitExpr(fs->getSubExpr(), p, scopeCreator);
503+
ASTScopeImpl *visitDiscardStmt(DiscardStmt *ds, ASTScopeImpl *p,
504+
ScopeCreator &scopeCreator) {
505+
visitExpr(ds->getSubExpr(), p, scopeCreator);
506506
return p;
507507
}
508508

Diff for: lib/AST/ASTWalker.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1655,10 +1655,10 @@ Stmt *Traversal::visitThrowStmt(ThrowStmt *TS) {
16551655
return nullptr;
16561656
}
16571657

1658-
Stmt *Traversal::visitForgetStmt(ForgetStmt *FS) {
1659-
if (Expr *E = doIt(FS->getSubExpr())) {
1660-
FS->setSubExpr(E);
1661-
return FS;
1658+
Stmt *Traversal::visitDiscardStmt(DiscardStmt *DS) {
1659+
if (Expr *E = doIt(DS->getSubExpr())) {
1660+
DS->setSubExpr(E);
1661+
return DS;
16621662
}
16631663
return nullptr;
16641664
}

Diff for: lib/AST/Stmt.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ StringRef Stmt::getDescriptiveKindName(StmtKind K) {
8181
return "return";
8282
case StmtKind::Throw:
8383
return "throw";
84-
case StmtKind::Forget:
85-
return "forget";
84+
case StmtKind::Discard:
85+
return "discard";
8686
case StmtKind::PoundAssert:
8787
return "#assert";
8888
}
@@ -366,7 +366,7 @@ SourceLoc YieldStmt::getEndLoc() const {
366366

367367
SourceLoc ThrowStmt::getEndLoc() const { return SubExpr->getEndLoc(); }
368368

369-
SourceLoc ForgetStmt::getEndLoc() const { return SubExpr->getEndLoc(); }
369+
SourceLoc DiscardStmt::getEndLoc() const { return SubExpr->getEndLoc(); }
370370

371371
SourceLoc DeferStmt::getEndLoc() const {
372372
return tempDecl->getBody()->getEndLoc();

0 commit comments

Comments
 (0)