Skip to content

Commit fb37134

Browse files
Merge remote-tracking branch 'apple/main' into katei/merge-main-2021-04-20
2 parents 3db2940 + 89039a8 commit fb37134

File tree

90 files changed

+2632
-1635
lines changed

Some content is hidden

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

90 files changed

+2632
-1635
lines changed

docs/SIL.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4540,7 +4540,7 @@ prev_dynamic_function_ref
45404540
// $@convention(thin) T -> U must be a thin function type
45414541
// %1 has type $T -> U
45424542

4543-
Creates a reference to a previous implemenation of a `dynamic_replacement` SIL
4543+
Creates a reference to a previous implementation of a `dynamic_replacement` SIL
45444544
function.
45454545

45464546
For the following Swift code::

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4385,6 +4385,12 @@ ERROR(global_actor_from_nonactor_context,none,
43854385
"%0 %1 isolated to global actor %2 can not be %select{referenced|mutated|used 'inout'}4"
43864386
" from %select{this|a non-isolated}3%select{| synchronous}5 context",
43874387
(DescriptiveDeclKind, DeclName, Type, bool, unsigned, bool))
4388+
ERROR(actor_isolated_call,none,
4389+
"call to %0 function in a synchronous %1 context",
4390+
(ActorIsolation, ActorIsolation))
4391+
ERROR(actor_isolated_call_decl,none,
4392+
"call to %0 %1 %2 in a synchronous %3 context",
4393+
(ActorIsolation, DescriptiveDeclKind, DeclName, ActorIsolation))
43884394
ERROR(actor_isolated_partial_apply,none,
43894395
"actor-isolated %0 %1 can not be partially applied",
43904396
(DescriptiveDeclKind, DeclName))

include/swift/AST/Stmt.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,15 +1110,19 @@ class SwitchStmt final : public LabeledStmt,
11101110
friend TrailingObjects;
11111111

11121112
SourceLoc SwitchLoc, LBraceLoc, RBraceLoc;
1113+
/// The location of the last token in the 'switch' statement. For valid
1114+
/// 'switch' statements this is the same as \c RBraceLoc. If the '}' is
1115+
/// missing this points to the last token before the '}' was expected.
1116+
SourceLoc EndLoc;
11131117
Expr *SubjectExpr;
11141118

11151119
SwitchStmt(LabeledStmtInfo LabelInfo, SourceLoc SwitchLoc, Expr *SubjectExpr,
11161120
SourceLoc LBraceLoc, unsigned CaseCount, SourceLoc RBraceLoc,
1117-
Optional<bool> implicit = None)
1121+
SourceLoc EndLoc, Optional<bool> implicit = None)
11181122
: LabeledStmt(StmtKind::Switch, getDefaultImplicitFlag(implicit, SwitchLoc),
11191123
LabelInfo),
11201124
SwitchLoc(SwitchLoc), LBraceLoc(LBraceLoc), RBraceLoc(RBraceLoc),
1121-
SubjectExpr(SubjectExpr) {
1125+
EndLoc(EndLoc), SubjectExpr(SubjectExpr) {
11221126
Bits.SwitchStmt.CaseCount = CaseCount;
11231127
}
11241128

@@ -1129,6 +1133,7 @@ class SwitchStmt final : public LabeledStmt,
11291133
SourceLoc LBraceLoc,
11301134
ArrayRef<ASTNode> Cases,
11311135
SourceLoc RBraceLoc,
1136+
SourceLoc EndLoc,
11321137
ASTContext &C);
11331138

11341139
/// Get the source location of the 'switch' keyword.
@@ -1141,8 +1146,8 @@ class SwitchStmt final : public LabeledStmt,
11411146
SourceLoc getLoc() const { return SwitchLoc; }
11421147

11431148
SourceLoc getStartLoc() const { return getLabelLocOrKeywordLoc(SwitchLoc); }
1144-
SourceLoc getEndLoc() const { return RBraceLoc; }
1145-
1149+
SourceLoc getEndLoc() const { return EndLoc; }
1150+
11461151
/// Get the subject expression of the switch.
11471152
Expr *getSubjectExpr() const { return SubjectExpr; }
11481153
void setSubjectExpr(Expr *e) { SubjectExpr = e; }

include/swift/Basic/LangOptions.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,8 @@ namespace swift {
274274
bool EnableInferPublicSendable = false;
275275

276276
/// Disable the implicit import of the _Concurrency module.
277-
bool DisableImplicitConcurrencyModuleImport = false;
277+
bool DisableImplicitConcurrencyModuleImport =
278+
!SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY;
278279

279280
/// Should we check the target OSs of serialized modules to see that they're
280281
/// new enough?

include/swift/Config.h.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88

99
#cmakedefine HAVE_PROC_PID_RUSAGE 1
1010

11+
#cmakedefine01 SWIFT_ENABLE_EXPERIMENTAL_CONCURRENCY
12+
1113
#endif // SWIFT_CONFIG_H

include/swift/IDE/CodeCompletion.h

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -599,21 +599,21 @@ class CodeCompletionResult {
599599
Identical,
600600
};
601601

602-
enum NotRecommendedReason {
603-
Redundant,
602+
enum class NotRecommendedReason {
603+
None = 0,
604+
RedundantImport,
604605
Deprecated,
605-
InvalidContext,
606+
InvalidAsyncContext,
606607
CrossActorReference,
607-
NoReason,
608+
VariableUsedInOwnDefinition,
608609
};
609610

610611
private:
611612
unsigned Kind : 3;
612613
unsigned AssociatedKind : 8;
613614
unsigned KnownOperatorKind : 6;
614615
unsigned SemanticContext : 3;
615-
unsigned NotRecommended : 1;
616-
unsigned NotRecReason : 3;
616+
unsigned NotRecommended : 4;
617617
unsigned IsSystem : 1;
618618

619619
/// The number of bytes to the left of the code completion point that
@@ -644,11 +644,10 @@ class CodeCompletionResult {
644644
CodeCompletionOperatorKind::None,
645645
StringRef BriefDocComment = StringRef())
646646
: Kind(Kind), KnownOperatorKind(unsigned(KnownOperatorKind)),
647-
SemanticContext(unsigned(SemanticContext)), NotRecommended(false),
648-
NotRecReason(NotRecommendedReason::NoReason),
647+
SemanticContext(unsigned(SemanticContext)),
648+
NotRecommended(unsigned(NotRecommendedReason::None)),
649649
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
650-
BriefDocComment(BriefDocComment),
651-
TypeDistance(TypeDistance) {
650+
BriefDocComment(BriefDocComment), TypeDistance(TypeDistance) {
652651
assert(Kind != Declaration && "use the other constructor");
653652
assert(CompletionString);
654653
if (isOperator() && KnownOperatorKind == CodeCompletionOperatorKind::None)
@@ -670,8 +669,8 @@ class CodeCompletionResult {
670669
ExpectedTypeRelation TypeDistance,
671670
StringRef BriefDocComment = StringRef())
672671
: Kind(Keyword), KnownOperatorKind(0),
673-
SemanticContext(unsigned(SemanticContext)), NotRecommended(false),
674-
NotRecReason(NotRecommendedReason::NoReason),
672+
SemanticContext(unsigned(SemanticContext)),
673+
NotRecommended(unsigned(NotRecommendedReason::None)),
675674
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
676675
BriefDocComment(BriefDocComment), TypeDistance(TypeDistance) {
677676
assert(CompletionString);
@@ -688,8 +687,8 @@ class CodeCompletionResult {
688687
CodeCompletionString *CompletionString,
689688
ExpectedTypeRelation TypeDistance)
690689
: Kind(Literal), KnownOperatorKind(0),
691-
SemanticContext(unsigned(SemanticContext)), NotRecommended(false),
692-
NotRecReason(NotRecommendedReason::NoReason),
690+
SemanticContext(unsigned(SemanticContext)),
691+
NotRecommended(unsigned(NotRecommendedReason::None)),
693692
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
694693
TypeDistance(TypeDistance) {
695694
AssociatedKind = static_cast<unsigned>(LiteralKind);
@@ -706,15 +705,14 @@ class CodeCompletionResult {
706705
unsigned NumBytesToErase,
707706
CodeCompletionString *CompletionString,
708707
const Decl *AssociatedDecl, StringRef ModuleName,
709-
bool NotRecommended,
710708
CodeCompletionResult::NotRecommendedReason NotRecReason,
711709
StringRef BriefDocComment,
712710
ArrayRef<StringRef> AssociatedUSRs,
713711
ArrayRef<std::pair<StringRef, StringRef>> DocWords,
714712
enum ExpectedTypeRelation TypeDistance)
715713
: Kind(ResultKind::Declaration), KnownOperatorKind(0),
716714
SemanticContext(unsigned(SemanticContext)),
717-
NotRecommended(NotRecommended), NotRecReason(NotRecReason),
715+
NotRecommended(unsigned(NotRecReason)),
718716
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
719717
ModuleName(ModuleName), BriefDocComment(BriefDocComment),
720718
AssociatedUSRs(AssociatedUSRs), DocWords(DocWords),
@@ -735,7 +733,7 @@ class CodeCompletionResult {
735733
unsigned NumBytesToErase,
736734
CodeCompletionString *CompletionString,
737735
CodeCompletionDeclKind DeclKind, bool IsSystem,
738-
StringRef ModuleName, bool NotRecommended,
736+
StringRef ModuleName,
739737
CodeCompletionResult::NotRecommendedReason NotRecReason,
740738
StringRef BriefDocComment,
741739
ArrayRef<StringRef> AssociatedUSRs,
@@ -745,11 +743,11 @@ class CodeCompletionResult {
745743
: Kind(ResultKind::Declaration),
746744
KnownOperatorKind(unsigned(KnownOperatorKind)),
747745
SemanticContext(unsigned(SemanticContext)),
748-
NotRecommended(NotRecommended), NotRecReason(NotRecReason),
749-
IsSystem(IsSystem), NumBytesToErase(NumBytesToErase),
750-
CompletionString(CompletionString), ModuleName(ModuleName),
751-
BriefDocComment(BriefDocComment), AssociatedUSRs(AssociatedUSRs),
752-
DocWords(DocWords), TypeDistance(TypeDistance) {
746+
NotRecommended(unsigned(NotRecReason)), IsSystem(IsSystem),
747+
NumBytesToErase(NumBytesToErase), CompletionString(CompletionString),
748+
ModuleName(ModuleName), BriefDocComment(BriefDocComment),
749+
AssociatedUSRs(AssociatedUSRs), DocWords(DocWords),
750+
TypeDistance(TypeDistance) {
753751
AssociatedKind = static_cast<unsigned>(DeclKind);
754752
assert(CompletionString);
755753
assert(!isOperator() ||
@@ -800,15 +798,15 @@ class CodeCompletionResult {
800798
}
801799

802800
NotRecommendedReason getNotRecommendedReason() const {
803-
return static_cast<NotRecommendedReason>(NotRecReason);
801+
return static_cast<NotRecommendedReason>(NotRecommended);
804802
}
805803

806804
SemanticContextKind getSemanticContext() const {
807805
return static_cast<SemanticContextKind>(SemanticContext);
808806
}
809807

810808
bool isNotRecommended() const {
811-
return NotRecommended;
809+
return getNotRecommendedReason() != NotRecommendedReason::None;
812810
}
813811

814812
unsigned getNumBytesToErase() const {

include/swift/SILOptimizer/Utils/ScopeOptUtils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ class AssertingScope {
6161
/// on Optional has value.
6262
void invalidateCleanup(unsigned cleanupIndex) {
6363
assert(!didPop && "Should not invalidate once popped?!");
64-
assert(cleanupIndex < cleanups.size());
6564
assert(cleanups[cleanupIndex].hasValue());
6665
cleanups[cleanupIndex] = None;
6766
}

include/swift/Sema/ConstraintSystem.h

Lines changed: 52 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,43 @@ class SolutionApplicationTargetsKey {
11111111
}
11121112
};
11131113

1114+
/// Describes the arguments to which a parameter binds.
1115+
/// FIXME: This is an awful data structure. We want the equivalent of a
1116+
/// TinyPtrVector for unsigned values.
1117+
using ParamBinding = SmallVector<unsigned, 1>;
1118+
1119+
/// The result of calling matchCallArguments().
1120+
struct MatchCallArgumentResult {
1121+
/// The direction of trailing closure matching that was performed.
1122+
TrailingClosureMatching trailingClosureMatching;
1123+
1124+
/// The parameter bindings determined by the match.
1125+
SmallVector<ParamBinding, 4> parameterBindings;
1126+
1127+
/// When present, the forward and backward scans each produced a result,
1128+
/// and the parameter bindings are different. The primary result will be
1129+
/// forwarding, and this represents the backward binding.
1130+
Optional<SmallVector<ParamBinding, 4>> backwardParameterBindings;
1131+
1132+
friend bool operator==(const MatchCallArgumentResult &lhs,
1133+
const MatchCallArgumentResult &rhs) {
1134+
if (lhs.trailingClosureMatching != rhs.trailingClosureMatching)
1135+
return false;
1136+
if (lhs.parameterBindings != rhs.parameterBindings)
1137+
return false;
1138+
return lhs.backwardParameterBindings == rhs.backwardParameterBindings;
1139+
}
1140+
1141+
/// Generate a result that maps the provided number of arguments to the same
1142+
/// number of parameters via forward match.
1143+
static MatchCallArgumentResult forArity(unsigned argCount) {
1144+
SmallVector<ParamBinding, 4> Bindings;
1145+
for (unsigned i : range(argCount))
1146+
Bindings.push_back({i});
1147+
return {TrailingClosureMatching::Forward, Bindings, None};
1148+
}
1149+
};
1150+
11141151
/// A complete solution to a constraint system.
11151152
///
11161153
/// A solution to a constraint system consists of type variable bindings to
@@ -1159,9 +1196,9 @@ class Solution {
11591196
llvm::SmallVector<ConstraintFix *, 4> Fixes;
11601197

11611198
/// For locators associated with call expressions, the trailing closure
1162-
/// matching rule that was applied.
1163-
llvm::SmallMapVector<ConstraintLocator*, TrailingClosureMatching, 4>
1164-
trailingClosureMatchingChoices;
1199+
/// matching rule and parameter bindings that were applied.
1200+
llvm::SmallMapVector<ConstraintLocator *, MatchCallArgumentResult, 4>
1201+
argumentMatchingChoices;
11651202

11661203
/// The set of disjunction choices used to arrive at this solution,
11671204
/// which informs constraint application.
@@ -1203,6 +1240,10 @@ class Solution {
12031240
/// A map from argument expressions to their applied property wrapper expressions.
12041241
llvm::MapVector<ASTNode, SmallVector<AppliedPropertyWrapper, 2>> appliedPropertyWrappers;
12051242

1243+
/// Record a new argument matching choice for given locator that maps a
1244+
/// single argument to a single parameter.
1245+
void recordSingleArgMatchingChoice(ConstraintLocator *locator);
1246+
12061247
/// Simplify the given type by substituting all occurrences of
12071248
/// type variables for their fixed types.
12081249
Type simplifyType(Type type) const;
@@ -2210,9 +2251,9 @@ class ConstraintSystem {
22102251
AppliedDisjunctions;
22112252

22122253
/// For locators associated with call expressions, the trailing closure
2213-
/// matching rule that was applied.
2214-
std::vector<std::pair<ConstraintLocator*, TrailingClosureMatching>>
2215-
trailingClosureMatchingChoices;
2254+
/// matching rule and parameter bindings that were applied.
2255+
std::vector<std::pair<ConstraintLocator *, MatchCallArgumentResult>>
2256+
argumentMatchingChoices;
22162257

22172258
/// The set of implicit value conversions performed by the solver on
22182259
/// a current path to reach a solution.
@@ -2709,8 +2750,8 @@ class ConstraintSystem {
27092750
/// The length of \c AppliedDisjunctions.
27102751
unsigned numAppliedDisjunctions;
27112752

2712-
/// The length of \c trailingClosureMatchingChoices;
2713-
unsigned numTrailingClosureMatchingChoices;
2753+
/// The length of \c argumentMatchingChoices.
2754+
unsigned numArgumentMatchingChoices;
27142755

27152756
/// The length of \c OpenedTypes.
27162757
unsigned numOpenedTypes;
@@ -3226,11 +3267,8 @@ class ConstraintSystem {
32263267

32273268
void recordPotentialHole(Type type);
32283269

3229-
void recordTrailingClosureMatch(
3230-
ConstraintLocator *locator,
3231-
TrailingClosureMatching trailingClosureMatch) {
3232-
trailingClosureMatchingChoices.push_back({locator, trailingClosureMatch});
3233-
}
3270+
void recordMatchCallArgumentResult(ConstraintLocator *locator,
3271+
MatchCallArgumentResult result);
32343272

32353273
/// Walk a closure AST to determine its effects.
32363274
///
@@ -5037,7 +5075,7 @@ class HandlePlaceholderType {
50375075
this->locator = cs.getConstraintLocator(locator);
50385076
}
50395077

5040-
Type operator()(PlaceholderTypeRepr *placeholderRepr) const {
5078+
Type operator()(ASTContext &ctx, PlaceholderTypeRepr *placeholderRepr) const {
50415079
return cs.createTypeVariable(
50425080
cs.getConstraintLocator(
50435081
locator, LocatorPathElt::PlaceholderType(placeholderRepr)),
@@ -5071,11 +5109,6 @@ static inline bool computeTupleShuffle(TupleType *fromTuple,
50715109
sources);
50725110
}
50735111

5074-
/// Describes the arguments to which a parameter binds.
5075-
/// FIXME: This is an awful data structure. We want the equivalent of a
5076-
/// TinyPtrVector for unsigned values.
5077-
using ParamBinding = SmallVector<unsigned, 1>;
5078-
50795112
/// Class used as the base for listeners to the \c matchCallArguments process.
50805113
///
50815114
/// By default, none of the callbacks do anything.
@@ -5143,20 +5176,6 @@ class MatchCallArgumentListener {
51435176
virtual bool relabelArguments(ArrayRef<Identifier> newNames);
51445177
};
51455178

5146-
/// The result of calling matchCallArguments().
5147-
struct MatchCallArgumentResult {
5148-
/// The direction of trailing closure matching that was performed.
5149-
TrailingClosureMatching trailingClosureMatching;
5150-
5151-
/// The parameter bindings determined by the match.
5152-
SmallVector<ParamBinding, 4> parameterBindings;
5153-
5154-
/// When present, the forward and backward scans each produced a result,
5155-
/// and the parameter bindings are different. The primary result will be
5156-
/// forwarding, and this represents the backward binding.
5157-
Optional<SmallVector<ParamBinding, 4>> backwardParameterBindings;
5158-
};
5159-
51605179
/// Match the call arguments (as described by the given argument type) to
51615180
/// the parameters (as described by the given parameter type).
51625181
///

0 commit comments

Comments
 (0)