Skip to content

Commit 6a9cf1d

Browse files
---
yaml --- r: 326107 b: refs/heads/master-next c: fa5b0f3 h: refs/heads/master i: 326105: 6bdaf2f 326103: acfbf47
1 parent 8915836 commit 6a9cf1d

File tree

72 files changed

+1539
-1263
lines changed

Some content is hidden

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

72 files changed

+1539
-1263
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: e052da7d8886fa0439677852e8f7830b20c2e1da
3-
refs/heads/master-next: b59cc7ad6a304f2917232df6d37d3e1d1aad4b17
3+
refs/heads/master-next: fa5b0f30a95d140c7dd2934ddf0f6b61be560239
44
refs/tags/osx-passed: b6b74147ef8a386f532cf9357a1bde006e552c54
55
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-a: 6bb18e013c2284f2b45f5f84f2df2887dc0f7dea
66
refs/tags/swift-2.2-SNAPSHOT-2015-12-01-b: 66d897bfcf64a82cb9a87f5e663d889189d06d07

branches/master-next/CHANGELOG.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,63 @@ CHANGELOG
2626
Swift Next
2727
----------
2828

29+
* [SR-11298][]:
30+
31+
A class-constrained protocol extension, where the extended protocol does
32+
not impose a class constraint, will now infer the constraint implicitly.
33+
34+
```swift
35+
protocol Foo {}
36+
class Bar: Foo {
37+
var someProperty: Int = 0
38+
}
39+
40+
// Even though 'Foo' does not impose a class constraint, it is automatically
41+
// inferred due to the Self: Bar constraint.
42+
extension Foo where Self: Bar {
43+
var anotherProperty: Int {
44+
get { return someProperty }
45+
// As a result, the setter is now implicitly nonmutating, just like it would
46+
// be if 'Foo' had a class constraint.
47+
set { someProperty = newValue }
48+
}
49+
}
50+
```
51+
52+
As a result, this could lead to code that currently compiles today to throw an error.
53+
54+
```swift
55+
protocol Foo {
56+
var someProperty: Int { get set }
57+
}
58+
59+
class Bar: Foo {
60+
var someProperty = 0
61+
}
62+
63+
extension Foo where Self: Bar {
64+
var anotherProperty1: Int {
65+
get { return someProperty }
66+
// This will now error, because the protocol requirement
67+
// is implicitly mutating and the setter is implicitly
68+
// nonmutating.
69+
set { someProperty = newValue } // Error
70+
}
71+
}
72+
```
73+
74+
**Workaround**: Define a new mutable variable inside the setter that has a reference to `self`:
75+
76+
```swift
77+
var anotherProperty1: Int {
78+
get { return someProperty }
79+
set {
80+
var mutableSelf = self
81+
mutableSelf.someProperty = newValue // Okay
82+
}
83+
}
84+
```
85+
2986
* [SE-0253][]:
3087

3188
Values of types that declare `func callAsFunction` methods can be called
@@ -51,7 +108,7 @@ Swift Next
51108

52109
* [SR-4206][]:
53110

54-
A method override is no longer allowed to have a generic signature with
111+
A method override is no longer allowed to have a generic signature with
55112
requirements not imposed by the base method. For example:
56113

57114
```
@@ -7765,3 +7822,4 @@ Swift 1.0
77657822
[SR-8974]: <https://bugs.swift.org/browse/SR-8974>
77667823
[SR-9043]: <https://bugs.swift.org/browse/SR-9043>
77677824
[SR-9827]: <https://bugs.swift.org/browse/SR-9827>
7825+
[SR-11298]: <https://bugs.swift.org/browse/SR-11298>

branches/master-next/include/swift/AST/Decl.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,12 +1505,13 @@ class alignas(8) _GenericContext {
15051505
TrailingWhereClause *TrailingWhere = nullptr;
15061506

15071507
/// The generic signature of this declaration.
1508-
GenericSignature *GenericSig = nullptr;
1508+
llvm::PointerIntPair<GenericSignature *, 1, bool> GenericSigAndBit;
15091509
};
15101510

15111511
class GenericContext : private _GenericContext, public DeclContext {
15121512
friend class GenericParamListRequest;
1513-
1513+
friend class GenericSignatureRequest;
1514+
15141515
protected:
15151516
GenericContext(DeclContextKind Kind, DeclContext *Parent,
15161517
GenericParamList *Params);
@@ -1534,7 +1535,8 @@ class GenericContext : private _GenericContext, public DeclContext {
15341535
/// }
15351536
/// \endcode
15361537
bool isGeneric() const { return getGenericParams() != nullptr; }
1537-
1538+
bool hasComputedGenericSignature() const;
1539+
15381540
/// Retrieve the trailing where clause for this extension, if any.
15391541
TrailingWhereClause *getTrailingWhereClause() const {
15401542
return TrailingWhere;

branches/master-next/include/swift/AST/DeclContext.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
261261

262262
/// Returns the kind of context this is.
263263
DeclContextKind getContextKind() const;
264-
264+
265+
/// Returns whether this context has value semantics.
266+
bool hasValueSemantics() const;
267+
265268
/// Determines whether this context is itself a local scope in a
266269
/// code block. A context that appears in such a scope, like a
267270
/// local type declaration, does not itself become a local context.

branches/master-next/include/swift/AST/TypeCheckRequests.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,27 @@ class FunctionOperatorRequest :
11601160
bool isCached() const { return true; }
11611161
};
11621162

1163+
class GenericSignatureRequest :
1164+
public SimpleRequest<GenericSignatureRequest,
1165+
GenericSignature *(GenericContext *),
1166+
CacheKind::SeparatelyCached> {
1167+
public:
1168+
using SimpleRequest::SimpleRequest;
1169+
1170+
private:
1171+
friend SimpleRequest;
1172+
1173+
// Evaluation.
1174+
llvm::Expected<GenericSignature *>
1175+
evaluate(Evaluator &evaluator, GenericContext *value) const;
1176+
1177+
public:
1178+
// Separate caching.
1179+
bool isCached() const { return true; }
1180+
Optional<GenericSignature *> getCachedResult() const;
1181+
void cacheResult(GenericSignature *value) const;
1182+
};
1183+
11631184
// Allow AnyValue to compare two Type values, even though Type doesn't
11641185
// support ==.
11651186
template<>

branches/master-next/include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ SWIFT_REQUEST(TypeChecker, FunctionBuilderTypeRequest, Type(ValueDecl *),
4949
Cached, NoLocationInfo)
5050
SWIFT_REQUEST(TypeChecker, FunctionOperatorRequest, OperatorDecl *(FuncDecl *),
5151
Cached, NoLocationInfo)
52+
SWIFT_REQUEST(NameLookup, GenericSignatureRequest,
53+
GenericSignature *(GenericContext *),
54+
SeparatelyCached, NoLocationInfo)
5255
SWIFT_REQUEST(TypeChecker, InferredGenericSignatureRequest,
5356
GenericSignature *(ModuleDecl *, GenericSignature *,
5457
SmallVector<GenericParamList *, 2>,

branches/master-next/include/swift/Parse/HiddenLibSyntaxAction.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ class HiddenLibSyntaxAction : public SyntaxParseActions {
7070
std::pair<size_t, OpaqueSyntaxNode>
7171
lookupNode(size_t lexerOffset, syntax::SyntaxKind kind) override;
7272

73-
void discardRecordedNode(OpaqueSyntaxNode node) override;
74-
7573
OpaqueSyntaxNodeKind getOpaqueKind() override {
7674
return ExplicitAction->getOpaqueKind();
7775
}

branches/master-next/include/swift/Parse/LibSyntaxGenerator.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class LibSyntaxGenerator {
4444

4545
auto Recorded = Recorder.recordToken(Kind, Range, LeadingTriviaPieces,
4646
TrailingTriviaPieces);
47-
auto Raw = static_cast<RawSyntax *>(Recorded.takeOpaqueNode());
47+
auto Raw = static_cast<RawSyntax *>(Recorded.getOpaqueNode());
4848
return make<TokenSyntax>(Raw);
4949
}
5050

@@ -55,7 +55,7 @@ class LibSyntaxGenerator {
5555
auto Children = Node.getDeferredChildren();
5656

5757
auto Recorded = Recorder.recordRawSyntax(Kind, Children);
58-
RC<RawSyntax> Raw {static_cast<RawSyntax *>(Recorded.takeOpaqueNode()) };
58+
RC<RawSyntax> Raw {static_cast<RawSyntax *>(Recorded.getOpaqueNode()) };
5959
Raw->Release(); // -1 since it's transfer of ownership.
6060
return make<SyntaxNode>(Raw);
6161
}

branches/master-next/include/swift/Parse/ParsedRawSyntaxNode.h

Lines changed: 7 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ParsedRawSyntaxNode {
5151
CharSourceRange Range;
5252
};
5353
struct DeferredLayoutNode {
54-
MutableArrayRef<ParsedRawSyntaxNode> Children;
54+
ArrayRef<ParsedRawSyntaxNode> Children;
5555
};
5656
struct DeferredTokenNode {
5757
const ParsedTriviaPiece *TriviaPieces;
@@ -73,8 +73,8 @@ class ParsedRawSyntaxNode {
7373
bool IsMissing = false;
7474

7575
ParsedRawSyntaxNode(syntax::SyntaxKind k,
76-
MutableArrayRef<ParsedRawSyntaxNode> deferredNodes)
77-
: DeferredLayout({deferredNodes}),
76+
ArrayRef<ParsedRawSyntaxNode> deferredNodes)
77+
: DeferredLayout{deferredNodes},
7878
SynKind(uint16_t(k)), TokKind(uint16_t(tok::unknown)),
7979
DK(DataKind::DeferredLayout) {
8080
assert(getKind() == k && "Syntax kind with too large value!");
@@ -97,8 +97,6 @@ class ParsedRawSyntaxNode {
9797
assert(DeferredToken.NumTrailingTrivia == numTrailingTrivia &&
9898
"numLeadingTrivia is too large value!");
9999
}
100-
ParsedRawSyntaxNode(ParsedRawSyntaxNode &other) = delete;
101-
ParsedRawSyntaxNode &operator=(ParsedRawSyntaxNode &other) = delete;
102100

103101
public:
104102
ParsedRawSyntaxNode()
@@ -117,35 +115,6 @@ class ParsedRawSyntaxNode {
117115
assert(getTokenKind() == tokKind && "Token kind with too large value!");
118116
}
119117

120-
ParsedRawSyntaxNode &operator=(ParsedRawSyntaxNode &&other) {
121-
assert(DK != DataKind::Recorded);
122-
switch (other.DK) {
123-
case DataKind::Null:
124-
break;
125-
case DataKind::Recorded:
126-
RecordedData = std::move(other.RecordedData);
127-
break;
128-
case DataKind::DeferredLayout:
129-
DeferredLayout = std::move(other.DeferredLayout);
130-
break;
131-
case DataKind::DeferredToken:
132-
DeferredToken = std::move(other.DeferredToken);
133-
break;
134-
}
135-
SynKind = std::move(other.SynKind);
136-
TokKind = std::move(other.TokKind);
137-
DK = std::move(other.DK);
138-
IsMissing = std::move(other.IsMissing);
139-
other.reset();
140-
return *this;
141-
}
142-
ParsedRawSyntaxNode(ParsedRawSyntaxNode &&other) : ParsedRawSyntaxNode() {
143-
*this = std::move(other);
144-
}
145-
~ParsedRawSyntaxNode() {
146-
assert(DK != DataKind::Recorded);
147-
}
148-
149118
syntax::SyntaxKind getKind() const { return syntax::SyntaxKind(SynKind); }
150119
tok getTokenKind() const { return tok(TokKind); }
151120

@@ -167,36 +136,6 @@ class ParsedRawSyntaxNode {
167136
/// Primary used for a deferred missing token.
168137
bool isMissing() const { return IsMissing; }
169138

170-
void reset() {
171-
RecordedData = {};
172-
SynKind = uint16_t(syntax::SyntaxKind::Unknown);
173-
TokKind = uint16_t(tok::unknown);
174-
DK = DataKind::Null;
175-
IsMissing = false;
176-
}
177-
178-
ParsedRawSyntaxNode unsafeCopy() const {
179-
ParsedRawSyntaxNode copy;
180-
switch (DK) {
181-
case DataKind::DeferredLayout:
182-
copy.DeferredLayout = DeferredLayout;
183-
break;
184-
case DataKind::DeferredToken:
185-
copy.DeferredToken = DeferredToken;
186-
break;
187-
case DataKind::Recorded:
188-
copy.RecordedData = RecordedData;
189-
break;
190-
case DataKind::Null:
191-
break;
192-
}
193-
copy.SynKind = SynKind;
194-
copy.TokKind = TokKind;
195-
copy.DK = DK;
196-
copy.IsMissing = IsMissing;
197-
return copy;
198-
}
199-
200139
CharSourceRange getDeferredRange() const {
201140
switch (DK) {
202141
case DataKind::DeferredLayout:
@@ -214,24 +153,18 @@ class ParsedRawSyntaxNode {
214153
assert(isRecorded());
215154
return RecordedData.Range;
216155
}
217-
const OpaqueSyntaxNode &getOpaqueNode() const {
156+
OpaqueSyntaxNode getOpaqueNode() const {
218157
assert(isRecorded());
219158
return RecordedData.OpaqueNode;
220159
}
221-
OpaqueSyntaxNode takeOpaqueNode() {
222-
assert(isRecorded());
223-
auto opaque = RecordedData.OpaqueNode;
224-
reset();
225-
return opaque;
226-
}
227160

228161
// Deferred Layout Data ====================================================//
229162

230163
CharSourceRange getDeferredLayoutRange() const {
231164
assert(DK == DataKind::DeferredLayout);
232165
assert(!DeferredLayout.Children.empty());
233-
auto getLastNonNullChild = [this]() -> const ParsedRawSyntaxNode & {
234-
for (auto &Child : llvm::reverse(getDeferredChildren()))
166+
auto getLastNonNullChild = [this]() {
167+
for (auto &&Child : llvm::reverse(getDeferredChildren()))
235168
if (!Child.isNull())
236169
return Child;
237170
llvm_unreachable("layout node without non-null children");
@@ -245,28 +178,6 @@ class ParsedRawSyntaxNode {
245178
assert(DK == DataKind::DeferredLayout);
246179
return DeferredLayout.Children;
247180
}
248-
MutableArrayRef<ParsedRawSyntaxNode> getDeferredChildren() {
249-
assert(DK == DataKind::DeferredLayout);
250-
return DeferredLayout.Children;
251-
}
252-
ParsedRawSyntaxNode copyDeferred() const {
253-
ParsedRawSyntaxNode copy;
254-
switch (DK) {
255-
case DataKind::DeferredLayout:
256-
copy.DeferredLayout = DeferredLayout;
257-
break;
258-
case DataKind::DeferredToken:
259-
copy.DeferredToken = DeferredToken;
260-
break;
261-
default:
262-
llvm_unreachable("node not deferred");
263-
}
264-
copy.SynKind = SynKind;
265-
copy.TokKind = TokKind;
266-
copy.DK = DK;
267-
copy.IsMissing = IsMissing;
268-
return copy;
269-
}
270181

271182
// Deferred Token Data =====================================================//
272183

@@ -303,7 +214,7 @@ class ParsedRawSyntaxNode {
303214

304215
/// Form a deferred syntax layout node.
305216
static ParsedRawSyntaxNode makeDeferred(syntax::SyntaxKind k,
306-
MutableArrayRef<ParsedRawSyntaxNode> deferredNodes,
217+
ArrayRef<ParsedRawSyntaxNode> deferredNodes,
307218
SyntaxParsingContext &ctx);
308219

309220
/// Form a deferred token node.

branches/master-next/include/swift/Parse/ParsedRawSyntaxRecorder.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,14 @@ class ParsedRawSyntaxRecorder {
6060
/// \p kind. Missing optional elements are represented with a null
6161
/// ParsedRawSyntaxNode object.
6262
ParsedRawSyntaxNode recordRawSyntax(syntax::SyntaxKind kind,
63-
MutableArrayRef<ParsedRawSyntaxNode> elements);
63+
ArrayRef<ParsedRawSyntaxNode> elements);
6464

6565
/// Record a raw syntax collecton without eny elements. \p loc can be invalid
6666
/// or an approximate location of where an element of the collection would be
6767
/// if not missing.
6868
ParsedRawSyntaxNode recordEmptyRawSyntaxCollection(syntax::SyntaxKind kind,
6969
SourceLoc loc);
7070

71-
void discardRecordedNode(ParsedRawSyntaxNode &node);
72-
7371
/// Used for incremental re-parsing.
7472
ParsedRawSyntaxNode lookupNode(size_t lexerOffset, SourceLoc loc,
7573
syntax::SyntaxKind kind);

0 commit comments

Comments
 (0)