Skip to content

Commit 76adb59

Browse files
committed
Revert "Pull SE-0081 into Swift 3.0 Preview 1" (#2860)
1 parent 30a30e1 commit 76adb59

17 files changed

+44
-159
lines changed

CHANGELOG.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,6 @@ Note: This is in reverse chronological order, so newer entries are added to the
33
Swift 3.0
44
---------
55

6-
* [SE-0081](https://github.com/apple/swift-evolution/blob/master/proposals/0081-move-where-expression.md)
7-
"Move 'where' clause to end of declaration" is implemented, allowing you to
8-
write 'where' clauses after the signature for a declaration, but before its
9-
body. For example, before:
10-
11-
```swift
12-
func anyCommonElements<T : SequenceType, U : SequenceType
13-
where T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element>
14-
(lhs: T, _ rhs: U) -> Bool
15-
{
16-
...
17-
}
18-
```
19-
20-
after:
21-
22-
```swift
23-
func anyCommonElements<T : SequenceType, U : SequenceType>(lhs: T, _ rhs: U) -> Bool
24-
where T.Generator.Element: Equatable, T.Generator.Element == U.Generator.Element>
25-
{
26-
...
27-
}
28-
```
29-
30-
The old form is still accepted for compatibility, but will eventually be rejected.
31-
326
* [SE-0071](https://github.com/apple/swift-evolution/blob/master/proposals/0071-member-keywords.md):
337
"Allow (most) keywords in member references" is implemented. This allows the
348
use of members after a dot without backticks, e.g. "foo.default".

include/swift/Parse/Parser.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,13 +1240,9 @@ class Parser {
12401240
ParserResult<GenericParamList> parseGenericParameters();
12411241
ParserResult<GenericParamList> parseGenericParameters(SourceLoc LAngleLoc);
12421242
ParserResult<GenericParamList> maybeParseGenericParams();
1243-
ParserStatus parseFreestandingGenericWhereClause(GenericParamList *&GPList);
1244-
12451243
ParserStatus parseGenericWhereClause(SourceLoc &WhereLoc,
12461244
SmallVectorImpl<RequirementRepr> &Requirements,
12471245
bool &FirstTypeInComplete);
1248-
1249-
12501246

12511247
//===--------------------------------------------------------------------===//
12521248
// Availability Specification Parsing

lib/Parse/ParseDecl.cpp

Lines changed: 7 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,10 +2930,10 @@ ParserResult<IfConfigDecl> Parser::parseDeclIfConfig(ParseDeclOptions Flags) {
29302930
///
29312931
/// \verbatim
29322932
/// decl-typealias:
2933-
/// 'typealias' identifier generic-params? '=' type requirement-clause?
2933+
/// 'typealias' identifier generic-params? '=' type
29342934
/// \endverbatim
2935-
ParserResult<TypeDecl> Parser::
2936-
parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
2935+
ParserResult<TypeDecl> Parser::parseDeclTypeAlias(Parser::ParseDeclOptions Flags,
2936+
DeclAttributes &Attributes) {
29372937
ParserPosition startPosition = getParserPosition();
29382938
SourceLoc TypeAliasLoc = consumeToken(tok::kw_typealias);
29392939
Identifier Id;
@@ -2991,13 +2991,6 @@ parseDeclTypeAlias(Parser::ParseDeclOptions Flags, DeclAttributes &Attributes) {
29912991
if (UnderlyingTy.isNull())
29922992
return Status;
29932993

2994-
// Parse a 'where' clause if present, adding it to our GenericParamList.
2995-
if (Tok.is(tok::kw_where)) {
2996-
auto whereStatus = parseFreestandingGenericWhereClause(genericParams);
2997-
if (whereStatus.shouldStopParsing())
2998-
return whereStatus;
2999-
}
3000-
30012994
auto *TAD = new (Context) TypeAliasDecl(TypeAliasLoc, Id, IdLoc,
30022995
UnderlyingTy.getPtrOrNull(),
30032996
genericParams, CurDeclContext);
@@ -4415,8 +4408,7 @@ void Parser::consumeAbstractFunctionBody(AbstractFunctionDecl *AFD,
44154408
/// \verbatim
44164409
/// decl-func:
44174410
/// attribute-list? ('static' | 'class')? 'mutating'? 'func'
4418-
/// any-identifier generic-params? func-signature where-clause?
4419-
/// stmt-brace?
4411+
/// any-identifier generic-params? func-signature stmt-brace?
44204412
/// \endverbatim
44214413
///
44224414
/// \note The caller of this method must ensure that the next token is 'func'.
@@ -4565,13 +4557,6 @@ Parser::parseDeclFunc(SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
45654557
return SignatureStatus;
45664558
}
45674559

4568-
// Parse a 'where' clause if present, adding it to our GenericParamList.
4569-
if (Tok.is(tok::kw_where)) {
4570-
auto whereStatus = parseFreestandingGenericWhereClause(GenericParams);
4571-
if (whereStatus.shouldStopParsing())
4572-
return whereStatus;
4573-
}
4574-
45754560
// Protocol method arguments may not have default values.
45764561
if (Flags.contains(PD_InProtocol) && DefaultArgs.HasDefaultArgument) {
45774562
diagnose(FuncLoc, diag::protocol_method_argument_init);
@@ -4701,7 +4686,7 @@ bool Parser::parseAbstractFunctionBodyDelayed(AbstractFunctionDecl *AFD) {
47014686
/// \verbatim
47024687
/// decl-enum:
47034688
/// 'enum' attribute-list identifier generic-params? inheritance?
4704-
/// where-clause? '{' decl-enum-body '}'
4689+
/// '{' decl-enum-body '}'
47054690
/// decl-enum-body:
47064691
/// decl*
47074692
/// \endverbatim
@@ -4744,14 +4729,6 @@ ParserResult<EnumDecl> Parser::parseDeclEnum(ParseDeclOptions Flags,
47444729
Status |= parseInheritance(Inherited, /*classRequirementLoc=*/nullptr);
47454730
UD->setInherited(Context.AllocateCopy(Inherited));
47464731
}
4747-
4748-
// Parse a 'where' clause if present, adding it to our GenericParamList.
4749-
if (Tok.is(tok::kw_where)) {
4750-
auto whereStatus = parseFreestandingGenericWhereClause(GenericParams);
4751-
if (whereStatus.shouldStopParsing())
4752-
return whereStatus;
4753-
UD->setGenericParams(GenericParams);
4754-
}
47554732

47564733
SourceLoc LBLoc, RBLoc;
47574734
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_enum)) {
@@ -4989,7 +4966,7 @@ bool Parser::parseNominalDeclMembers(SourceLoc LBLoc, SourceLoc &RBLoc,
49894966
/// \verbatim
49904967
/// decl-struct:
49914968
/// 'struct' attribute-list identifier generic-params? inheritance?
4992-
/// where-clause? '{' decl-struct-body '}
4969+
/// '{' decl-struct-body '}
49934970
/// decl-struct-body:
49944971
/// decl*
49954972
/// \endverbatim
@@ -5035,14 +5012,6 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
50355012
Status |= parseInheritance(Inherited, /*classRequirementLoc=*/nullptr);
50365013
SD->setInherited(Context.AllocateCopy(Inherited));
50375014
}
5038-
5039-
// Parse a 'where' clause if present, adding it to our GenericParamList.
5040-
if (Tok.is(tok::kw_where)) {
5041-
auto whereStatus = parseFreestandingGenericWhereClause(GenericParams);
5042-
if (whereStatus.shouldStopParsing())
5043-
return whereStatus;
5044-
SD->setGenericParams(GenericParams);
5045-
}
50465015

50475016
SourceLoc LBLoc, RBLoc;
50485017
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_struct)) {
@@ -5078,7 +5047,7 @@ ParserResult<StructDecl> Parser::parseDeclStruct(ParseDeclOptions Flags,
50785047
/// \verbatim
50795048
/// decl-class:
50805049
/// 'class' attribute-list identifier generic-params? inheritance?
5081-
/// where-clause? '{' decl-class-body '}
5050+
/// '{' decl-class-body '}
50825051
/// decl-class-body:
50835052
/// decl*
50845053
/// \endverbatim
@@ -5124,14 +5093,6 @@ ParserResult<ClassDecl> Parser::parseDeclClass(SourceLoc ClassLoc,
51245093
CD->setInherited(Context.AllocateCopy(Inherited));
51255094
}
51265095

5127-
// Parse a 'where' clause if present, adding it to our GenericParamList.
5128-
if (Tok.is(tok::kw_where)) {
5129-
auto whereStatus = parseFreestandingGenericWhereClause(GenericParams);
5130-
if (whereStatus.shouldStopParsing())
5131-
return whereStatus;
5132-
CD->setGenericParams(GenericParams);
5133-
}
5134-
51355096
SourceLoc LBLoc, RBLoc;
51365097
if (parseToken(tok::l_brace, LBLoc, diag::expected_lbrace_class)) {
51375098
LBLoc = PreviousLoc;
@@ -5415,13 +5376,6 @@ Parser::parseDeclInit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
54155376
Attributes.add(new (Context) RethrowsAttr(throwsLoc));
54165377
}
54175378

5418-
// Parse a 'where' clause if present, adding it to our GenericParamList.
5419-
if (Tok.is(tok::kw_where)) {
5420-
auto whereStatus = parseFreestandingGenericWhereClause(GenericParams);
5421-
if (whereStatus.shouldStopParsing())
5422-
return whereStatus;
5423-
}
5424-
54255379
auto *SelfDecl = ParamDecl::createUnboundSelf(ConstructorLoc, CurDeclContext);
54265380

54275381
Scope S2(this, ScopeKind::ConstructorBody);

lib/Parse/ParseGeneric.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -260,44 +260,3 @@ ParserStatus Parser::parseGenericWhereClause(
260260

261261
return Status;
262262
}
263-
264-
265-
/// Parse a free-standing where clause attached to a declaration, adding it to
266-
/// a generic parameter list that may (or may not) already exist.
267-
ParserStatus Parser::
268-
parseFreestandingGenericWhereClause(GenericParamList *&genericParams) {
269-
assert(Tok.is(tok::kw_where) && "Shouldn't call this without a where");
270-
271-
// Push the generic arguments back into a local scope so that references will
272-
// find them.
273-
Scope S(this, ScopeKind::Generics);
274-
275-
if (genericParams)
276-
for (auto pd : genericParams->getParams())
277-
addToScope(pd);
278-
279-
SmallVector<RequirementRepr, 4> Requirements;
280-
if (genericParams)
281-
Requirements.append(genericParams->getRequirements().begin(),
282-
genericParams->getRequirements().end());
283-
284-
SourceLoc WhereLoc;
285-
bool FirstTypeInComplete;
286-
auto result = parseGenericWhereClause(WhereLoc, Requirements,
287-
FirstTypeInComplete);
288-
if (result.shouldStopParsing() || Requirements.empty())
289-
return result;
290-
291-
if (!genericParams)
292-
genericParams = GenericParamList::create(Context, SourceLoc(),
293-
{}, WhereLoc, Requirements,
294-
SourceLoc());
295-
else
296-
genericParams = GenericParamList::create(Context,
297-
genericParams->getLAngleLoc(),
298-
genericParams->getParams(),
299-
WhereLoc, Requirements,
300-
genericParams->getRAngleLoc());
301-
return ParserStatus();
302-
}
303-

test/Generics/associated_self_constraints.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protocol P {
6363
struct IP<T> : P {
6464
typealias A = T
6565

66-
init<O:P>(x:O) where O.A == IP.A {
66+
init<O:P where O.A == IP.A>(x:O) {
6767
_onNext = { (item: A) in x.onNext(item) }
6868
}
6969

test/Generics/function_defs.swift

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ func testOrdered<T : Ordered>(_ x: T, y: Int) {
189189
//===----------------------------------------------------------------------===//
190190
// Requires clauses
191191
//===----------------------------------------------------------------------===//
192-
func conformanceViaRequires<T>(_ t1: T, t2: T) -> Bool
193-
where T : EqualComparable, T : MethodLessComparable {
192+
func conformanceViaRequires<T
193+
where T : EqualComparable, T : MethodLessComparable
194+
>(_ t1: T, t2: T) -> Bool {
194195
let b1 = t1.isEqual(t2)
195196
if b1 || t1.isLess(t2) {
196197
return true
@@ -207,8 +208,7 @@ protocol AcceptsAnElement {
207208
func accept(_ e : Element)
208209
}
209210

210-
func impliedSameType<T : GeneratesAnElement>(_ t: T)
211-
where T : AcceptsAnElement {
211+
func impliedSameType<T : GeneratesAnElement where T : AcceptsAnElement>(_ t: T) {
212212
t.accept(t.makeIterator())
213213
let e = t.makeIterator(), e2 = t.makeIterator()
214214
if e.isEqual(e2) || e.isLess(e2) {
@@ -226,9 +226,10 @@ protocol GeneratesAssoc2 {
226226
func get() -> Assoc2
227227
}
228228

229-
func simpleSameType<T : GeneratesAssoc1, U : GeneratesAssoc2>
230-
(_ t: T, u: U) -> Bool
231-
where T.Assoc1 == U.Assoc2 {
229+
func simpleSameType
230+
<T : GeneratesAssoc1, U : GeneratesAssoc2 where T.Assoc1 == U.Assoc2>
231+
(_ t: T, u: U) -> Bool
232+
{
232233
return t.get().isEqual(u.get()) || u.get().isLess(t.get())
233234
}
234235

@@ -243,9 +244,9 @@ protocol GeneratesMetaAssoc2 {
243244
}
244245

245246
func recursiveSameType
246-
<T : GeneratesMetaAssoc1, U : GeneratesMetaAssoc2, V : GeneratesAssoc1>
247+
<T : GeneratesMetaAssoc1, U : GeneratesMetaAssoc2, V : GeneratesAssoc1
248+
where T.MetaAssoc1 == V.Assoc1, V.Assoc1 == U.MetaAssoc2>
247249
(_ t: T, u: U)
248-
where T.MetaAssoc1 == V.Assoc1, V.Assoc1 == U.MetaAssoc2
249250
{
250251
t.get().accept(t.get().makeIterator())
251252
let e = t.get().makeIterator(), e2 = t.get().makeIterator()
@@ -264,9 +265,12 @@ protocol P2 {
264265
func getAssocP1() -> AssocP1
265266
}
266267

267-
func beginsWith2<E0: P1, E1: P1>(_ e0: E0, _ e1: E1) -> Bool
268-
where E0.Element == E1.Element,
269-
E0.Element : EqualComparable
268+
func beginsWith2<
269+
E0: P1, E1: P1
270+
where
271+
E0.Element == E1.Element,
272+
E0.Element : EqualComparable
273+
>(_ e0: E0, _ e1: E1) -> Bool
270274
{
271275
}
272276

test/Generics/generic_types.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ struct formattedTestS<T : MyFormattedPrintable> {
6363
}
6464
}
6565

66-
struct GenericReq<T : IteratorProtocol, U : IteratorProtocol>
67-
where T.Element == U.Element {
68-
}
66+
struct GenericReq<
67+
T : IteratorProtocol, U : IteratorProtocol where T.Element == U.Element
68+
> {}
6969

7070
func getFirst<R : IteratorProtocol>(_ r: R) -> R.Element {
7171
var r = r
@@ -138,8 +138,11 @@ var d2 : Dictionary<String, Int>
138138
d1["hello"] = d2["world"]
139139
i = d2["blarg"]
140140

141-
struct RangeOfPrintables<R : Sequence>
142-
where R.Iterator.Element : MyFormattedPrintable {
141+
struct RangeOfPrintables<
142+
R : Sequence
143+
where
144+
R.Iterator.Element : MyFormattedPrintable
145+
> {
143146
var r : R
144147

145148
func format() -> String {
@@ -304,7 +307,7 @@ struct X4 : P, Q {
304307
typealias AssocQ = String
305308
}
306309

307-
struct X5<T, U> where T: P, T: Q, T.AssocP == T.AssocQ { } // expected-note{{requirement specified as 'T.AssocP' == 'T.AssocQ' [with T = X4]}}
310+
struct X5<T, U where T: P, T: Q, T.AssocP == T.AssocQ> { } // expected-note{{requirement specified as 'T.AssocP' == 'T.AssocQ' [with T = X4]}}
308311

309312
var y: X5<X4, Int> // expected-error{{'X5' requires the types 'AssocP' (aka 'Int') and 'AssocQ' (aka 'String') be equivalent}}
310313

@@ -331,4 +334,4 @@ struct UnsolvableInheritance2<T : U.A, U : T.A> {}
331334
// expected-error@-1 {{inheritance from non-protocol, non-class type 'U.A'}}
332335
// expected-error@-2 {{inheritance from non-protocol, non-class type 'T.A'}}
333336

334-
enum X7<T> where X7.X : G { case X } // expected-error{{'X' is not a member type of 'X7<T>'}}
337+
enum X7<T where X7.X : G> { case X } // expected-error{{'X' is not a member type of 'X7<T>'}}

test/IRGen/mixed_objc_native_protocol_constraints.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
protocol Fooable { func foo() }
77

8-
class A<B: Fooable> where B: AnyObject{
8+
class A<B: Fooable where B: AnyObject> {
99
}

test/decl/nested.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@ class OuterNonGenericClass {
7878
init(t: T) { super.init(); self.t = t }
7979
}
8080

81-
class InnerGenericClass<U> : OuterNonGenericClass // expected-error {{type 'InnerGenericClass' nested in generic function}}
82-
where U : Racoon, U.Stripes == T {
81+
class InnerGenericClass<U where U : Racoon, U.Stripes == T> : OuterNonGenericClass { // expected-error {{type 'InnerGenericClass' nested in generic function}}
8382
let t: T
8483

8584
init(t: T) { super.init(); self.t = t }
@@ -152,8 +151,7 @@ class OuterGenericClass<T> {
152151
init(t: T) { super.init(); self.t = t }
153152
}
154153

155-
class InnerGenericClass<U> : OuterGenericClass<U> // expected-error {{type 'InnerGenericClass' nested in generic function}}
156-
where U : Racoon, U.Stripes == T {
154+
class InnerGenericClass<U where U : Racoon, U.Stripes == T> : OuterGenericClass<U> { // expected-error {{type 'InnerGenericClass' nested in generic function}}
157155
let t: T
158156

159157
init(t: T) { super.init(); self.t = t }

test/decl/typealias/typealias.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ typealias BadC<T,T> = MyType<String, T> // expected-error {{definition conflict
4848

4949
typealias Tuple2<T1, T2> = (T1, T2)
5050

51-
typealias Tuple3<T1> = (T1, T1) where T1 : Hashable
52-
53-
5451
let _ : Tuple2<Int, String> = (1, "foo")
5552
let _ : Tuple2 = (1, "foo")
5653
let _ : Tuple2<Int, String> = ("bar", // expected-error {{cannot convert value of type 'String' to specified type 'Int'}}

0 commit comments

Comments
 (0)