Skip to content

Commit 87b6786

Browse files
Merge remote-tracking branch 'apple/main' into katei/merge-main-2020-10-11
2 parents 02864f6 + 3bc381b commit 87b6786

File tree

135 files changed

+2751
-1370
lines changed

Some content is hidden

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

135 files changed

+2751
-1370
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ CHANGELOG
2727
Swift Next
2828
----------
2929

30+
* [SR-10069][]:
31+
32+
Function overloading now works in local contexts, making the following valid:
33+
34+
```swift
35+
func outer(x: Int, y: String) {
36+
func doIt(_: Int) {}
37+
func doIt(_: String) {}
38+
39+
doIt(x) // calls the first 'doIt(_:)' with an Int value
40+
doIt(y) // calls the second 'doIt(_:)' with a String value
41+
}
42+
```
43+
3044
* [SE-0284][]:
3145

3246
Functions, subscripts, and initializers may now have more than one variadic parameter, as long as all parameters which follow variadic parameters are labeled. This makes declarations like the following valid:
@@ -8196,6 +8210,7 @@ Swift 1.0
81968210
[SR-8974]: <https://bugs.swift.org/browse/SR-8974>
81978211
[SR-9043]: <https://bugs.swift.org/browse/SR-9043>
81988212
[SR-9827]: <https://bugs.swift.org/browse/SR-9827>
8213+
[SR-10069]: <https://bugs.swift.org/browse/SR-10069>
81998214
[SR-11298]: <https://bugs.swift.org/browse/SR-11298>
82008215
[SR-11429]: <https://bugs.swift.org/browse/SR-11429>
82018216
[SR-11700]: <https://bugs.swift.org/browse/SR-11700>

docs/HowToGuides/GettingStarted.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ toolchain as a one-off, there are a couple of differences:
9797
or a specific snapshot. You can update the branch/tag for all repositories
9898
as follows:
9999
```sh
100-
utils/update-checkout --branch mybranchname
100+
utils/update-checkout --scheme mybranchname
101101
# OR
102102
utils/update-checkout --tag mytagname
103103
```

include/swift/AST/ASTScope.h

+4-31
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,6 @@ class ASTScopeImpl {
194194
#pragma mark - source ranges
195195

196196
public:
197-
/// Return signum of ranges. Centralize the invariant that ASTScopes use ends.
198-
static int compare(SourceRange, SourceRange, const SourceManager &,
199-
bool ensureDisjoint);
200-
201197
CharSourceRange getCharSourceRangeOfScope(SourceManager &SM,
202198
bool omitAssertions = false) const;
203199
bool isCharSourceRangeCached() const;
@@ -224,7 +220,6 @@ class ASTScopeImpl {
224220
virtual NullablePtr<DeclAttribute> getDeclAttributeIfAny() const {
225221
return nullptr;
226222
}
227-
virtual NullablePtr<const void> getReferrent() const { return nullptr; }
228223

229224
#pragma mark - debugging and printing
230225

@@ -402,7 +397,6 @@ class ASTSourceFileScope final : public ASTScopeImpl {
402397
public:
403398
SourceFile *const SF;
404399
ScopeCreator *const scopeCreator;
405-
ASTScopeImpl *insertionPoint;
406400

407401
ASTSourceFileScope(SourceFile *SF, ScopeCreator *scopeCreator);
408402

@@ -470,9 +464,6 @@ class Portion {
470464
virtual NullablePtr<const ASTScopeImpl>
471465
getLookupLimitFor(const GenericTypeOrExtensionScope *) const;
472466

473-
virtual const Decl *
474-
getReferrentOfScope(const GenericTypeOrExtensionScope *s) const;
475-
476467
virtual NullablePtr<ASTScopeImpl>
477468
insertionPointForDeferredExpansion(IterableTypeScope *) const = 0;
478469
};
@@ -493,9 +484,6 @@ class Portion {
493484
NullablePtr<const ASTScopeImpl>
494485
getLookupLimitFor(const GenericTypeOrExtensionScope *) const override;
495486

496-
const Decl *
497-
getReferrentOfScope(const GenericTypeOrExtensionScope *s) const override;
498-
499487
NullablePtr<ASTScopeImpl>
500488
insertionPointForDeferredExpansion(IterableTypeScope *) const override;
501489
};
@@ -570,7 +558,6 @@ class GenericTypeOrExtensionScope : public ASTScopeImpl {
570558

571559
virtual Decl *getDecl() const = 0;
572560
NullablePtr<Decl> getDeclIfAny() const override { return getDecl(); }
573-
NullablePtr<const void> getReferrent() const override;
574561

575562
private:
576563
AnnotatedInsertionPoint
@@ -745,7 +732,6 @@ class GenericParamScope final : public ASTScopeImpl {
745732

746733
/// Actually holder is always a GenericContext, need to test if
747734
/// ProtocolDecl or SubscriptDecl but will refactor later.
748-
NullablePtr<const void> getReferrent() const override;
749735
std::string getClassName() const override;
750736
SourceRange
751737
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
@@ -788,8 +774,6 @@ class AbstractFunctionDeclScope final : public ASTScopeImpl {
788774
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
789775
Decl *getDecl() const { return decl; }
790776

791-
NullablePtr<const void> getReferrent() const override;
792-
793777
protected:
794778
NullablePtr<const GenericParamList> genericParams() const override;
795779
};
@@ -813,7 +797,6 @@ class ParameterListScope final : public ASTScopeImpl {
813797

814798
private:
815799
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
816-
SourceLoc fixupEndForBadInput(SourceRange) const;
817800

818801
public:
819802
std::string getClassName() const override;
@@ -902,7 +885,6 @@ class AttachedPropertyWrapperScope final : public ASTScopeImpl {
902885
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
903886
return attr;
904887
}
905-
NullablePtr<const void> getReferrent() const override;
906888

907889
private:
908890
void expandAScopeThatDoesNotCreateANewInsertionPoint(ScopeCreator &);
@@ -970,8 +952,6 @@ class PatternEntryDeclScope final : public AbstractPatternEntryScope {
970952
SourceRange
971953
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
972954

973-
NullablePtr<const void> getReferrent() const override;
974-
975955
protected:
976956
bool lookupLocalsOrMembers(DeclConsumer) const override;
977957
bool isLabeledStmtLookupTerminator() const override;
@@ -1072,7 +1052,6 @@ class CaptureListScope final : public ASTScopeImpl {
10721052
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
10731053
NullablePtr<Expr> getExprIfAny() const override { return expr; }
10741054
Expr *getExpr() const { return expr; }
1075-
NullablePtr<const void> getReferrent() const override;
10761055
bool lookupLocalsOrMembers(DeclConsumer) const override;
10771056
};
10781057

@@ -1094,7 +1073,6 @@ class ClosureParametersScope final : public ASTScopeImpl {
10941073
}
10951074
NullablePtr<Expr> getExprIfAny() const override { return closureExpr; }
10961075
Expr *getExpr() const { return closureExpr; }
1097-
NullablePtr<const void> getReferrent() const override;
10981076

10991077
protected:
11001078
ASTScopeImpl *expandSpecifically(ScopeCreator &scopeCreator) override;
@@ -1128,7 +1106,6 @@ class TopLevelCodeScope final : public ASTScopeImpl {
11281106
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
11291107
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
11301108
Decl *getDecl() const { return decl; }
1131-
NullablePtr<const void> getReferrent() const override;
11321109
};
11331110

11341111
/// The \c _@specialize attribute.
@@ -1153,7 +1130,6 @@ class SpecializeAttributeScope final : public ASTScopeImpl {
11531130
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
11541131
return specializeAttr;
11551132
}
1156-
NullablePtr<const void> getReferrent() const override;
11571133

11581134
protected:
11591135
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
@@ -1183,7 +1159,6 @@ class DifferentiableAttributeScope final : public ASTScopeImpl {
11831159
NullablePtr<DeclAttribute> getDeclAttributeIfAny() const override {
11841160
return differentiableAttr;
11851161
}
1186-
NullablePtr<const void> getReferrent() const override;
11871162

11881163
protected:
11891164
ASTScopeImpl *expandSpecifically(ScopeCreator &) override;
@@ -1214,7 +1189,6 @@ class SubscriptDeclScope final : public ASTScopeImpl {
12141189
public:
12151190
virtual NullablePtr<Decl> getDeclIfAny() const override { return decl; }
12161191
Decl *getDecl() const { return decl; }
1217-
NullablePtr<const void> getReferrent() const override;
12181192

12191193
protected:
12201194
NullablePtr<const GenericParamList> genericParams() const override;
@@ -1244,7 +1218,6 @@ class AbstractStmtScope : public ASTScopeImpl {
12441218
getSourceRangeOfThisASTNode(bool omitAssertions = false) const override;
12451219
virtual Stmt *getStmt() const = 0;
12461220
NullablePtr<Stmt> getStmtIfAny() const override { return getStmt(); }
1247-
NullablePtr<const void> getReferrent() const override;
12481221

12491222
protected:
12501223
bool isLabeledStmtLookupTerminator() const override;
@@ -1559,11 +1532,11 @@ class BraceStmtScope final : public AbstractStmtScope {
15591532
BraceStmt *const stmt;
15601533

15611534
/// Declarations which are in scope from the beginning of the statement.
1562-
SmallVector<ValueDecl *, 2> localFuncsAndTypes;
1535+
ArrayRef<ValueDecl *> localFuncsAndTypes;
15631536

15641537
/// Declarations that are normally in scope only after their
15651538
/// definition.
1566-
SmallVector<VarDecl *, 2> localVars;
1539+
ArrayRef<VarDecl *> localVars;
15671540

15681541
/// The end location for bindings introduced in this scope. This can
15691542
/// extend past the actual end of the BraceStmt in top-level code,
@@ -1573,8 +1546,8 @@ class BraceStmtScope final : public AbstractStmtScope {
15731546

15741547
public:
15751548
BraceStmtScope(BraceStmt *e,
1576-
SmallVector<ValueDecl *, 2> localFuncsAndTypes,
1577-
SmallVector<VarDecl *, 2> localVars,
1549+
ArrayRef<ValueDecl *> localFuncsAndTypes,
1550+
ArrayRef<VarDecl *> localVars,
15781551
SourceLoc endLoc)
15791552
: stmt(e),
15801553
localFuncsAndTypes(localFuncsAndTypes),

include/swift/AST/ActorIsolation.h

+29-11
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class raw_ostream;
2424

2525
namespace swift {
2626
class ClassDecl;
27+
class Type;
28+
29+
/// Determine whether the given types are (canonically) equal, declared here
30+
/// to avoid having to include Types.h.
31+
bool areTypesEqual(Type type1, Type type2);
2732

2833
/// Describes the actor isolation of a given declaration, which determines
2934
/// the actors with which it can interact.
@@ -37,20 +42,26 @@ class ActorIsolation {
3742
/// For example, a mutable stored property or synchronous function within
3843
/// the actor is isolated to the instance of that actor.
3944
ActorInstance,
40-
/// The declaration can refer to actor-isolated state, but can also be
41-
//// referenced from outside the actor.
42-
ActorPrivileged,
4345
/// The declaration is explicitly specified to be independent of any actor,
4446
/// meaning that it can be used from any actor but is also unable to
4547
/// refer to the isolated state of any given actor.
4648
Independent,
49+
/// The declaration is isolated to a global actor. It can refer to other
50+
/// entities with the same global actor.
51+
GlobalActor,
4752
};
4853

4954
private:
5055
Kind kind;
51-
ClassDecl *actor;
56+
union {
57+
ClassDecl *actor;
58+
Type globalActor;
59+
void *pointer;
60+
};
5261

5362
ActorIsolation(Kind kind, ClassDecl *actor) : kind(kind), actor(actor) { }
63+
ActorIsolation(Kind kind, Type globalActor)
64+
: kind(kind), globalActor(globalActor) { }
5465

5566
public:
5667
static ActorIsolation forUnspecified() {
@@ -61,23 +72,28 @@ class ActorIsolation {
6172
return ActorIsolation(Independent, nullptr);
6273
}
6374

64-
static ActorIsolation forActorPrivileged(ClassDecl *actor) {
65-
return ActorIsolation(ActorPrivileged, actor);
66-
}
67-
6875
static ActorIsolation forActorInstance(ClassDecl *actor) {
6976
return ActorIsolation(ActorInstance, actor);
7077
}
7178

79+
static ActorIsolation forGlobalActor(Type globalActor) {
80+
return ActorIsolation(GlobalActor, globalActor);
81+
}
82+
7283
Kind getKind() const { return kind; }
7384

7485
operator Kind() const { return getKind(); }
7586

7687
ClassDecl *getActor() const {
77-
assert(getKind() == ActorInstance || getKind() == ActorPrivileged);
88+
assert(getKind() == ActorInstance);
7889
return actor;
7990
}
8091

92+
Type getGlobalActor() const {
93+
assert(getKind() == GlobalActor);
94+
return globalActor;
95+
}
96+
8197
friend bool operator==(const ActorIsolation &lhs,
8298
const ActorIsolation &rhs) {
8399
if (lhs.kind != rhs.kind)
@@ -89,8 +105,10 @@ class ActorIsolation {
89105
return true;
90106

91107
case ActorInstance:
92-
case ActorPrivileged:
93108
return lhs.actor == rhs.actor;
109+
110+
case GlobalActor:
111+
return areTypesEqual(lhs.globalActor, rhs.globalActor);
94112
}
95113
}
96114

@@ -100,7 +118,7 @@ class ActorIsolation {
100118
}
101119

102120
friend llvm::hash_code hash_value(const ActorIsolation &state) {
103-
return llvm::hash_combine(state.kind, state.actor);
121+
return llvm::hash_combine(state.kind, state.pointer);
104122
}
105123
};
106124

include/swift/AST/Attr.def

+6
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,12 @@ SIMPLE_DECL_ATTR(actorIndependent, ActorIndependent,
578578
APIStableToAdd | APIBreakingToRemove,
579579
103)
580580

581+
SIMPLE_DECL_ATTR(globalActor, GlobalActor,
582+
OnClass | OnStruct | OnEnum | ConcurrencyOnly |
583+
ABIStableToAdd | ABIBreakingToRemove |
584+
APIStableToAdd | APIBreakingToRemove,
585+
104)
586+
581587
#undef TYPE_ATTR
582588
#undef DECL_ATTR_ALIAS
583589
#undef CONTEXTUAL_DECL_ATTR_ALIAS

include/swift/AST/AvailabilitySpec.h

+7
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class PlatformVersionConstraintAvailabilitySpec : public AvailabilitySpec {
8585

8686
SourceRange VersionSrcRange;
8787

88+
// Location of the macro expanded to create this spec.
89+
SourceLoc MacroLoc;
90+
8891
public:
8992
PlatformVersionConstraintAvailabilitySpec(PlatformKind Platform,
9093
SourceLoc PlatformLoc,
@@ -117,6 +120,10 @@ class PlatformVersionConstraintAvailabilitySpec : public AvailabilitySpec {
117120

118121
SourceRange getSourceRange() const;
119122

123+
// Location of the macro expanded to create this spec.
124+
SourceLoc getMacroLoc() const { return MacroLoc; }
125+
void setMacroLoc(SourceLoc loc) { MacroLoc = loc; }
126+
120127
void print(raw_ostream &OS, unsigned Indent) const;
121128

122129
static bool classof(const AvailabilitySpec *Spec) {

0 commit comments

Comments
 (0)