Skip to content

Commit 4bb68a3

Browse files
committed
Update for rebase
1 parent 833c25c commit 4bb68a3

File tree

8 files changed

+76
-50
lines changed

8 files changed

+76
-50
lines changed

include/swift/Parse/Parser.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,8 @@ class Parser {
11591159
tok::kw_Any,
11601160
tok::kw_Self,
11611161
tok::kw__,
1162-
tok::kw_var);
1162+
tok::kw_var,
1163+
tok::kw_let);
11631164
}
11641165

11651166
ParserStatus parseTypeAttributeList(ParamDecl::Specifier &Specifier,

lib/Basic/LangOptions.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ using namespace swift;
3232
LangOptions::LangOptions() {
3333
// Note: Introduce default-on language options here.
3434
#ifndef NDEBUG
35-
#warning "reinstate parser round trip features once SwiftSyntax support is done"
36-
//Features.insert(Feature::ParserRoundTrip);
37-
//Features.insert(Feature::ParserValidation);
35+
Features.insert(Feature::ParserRoundTrip);
36+
Features.insert(Feature::ParserValidation);
3837
#endif
3938
}
4039

lib/Parse/ParsePattern.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -262,17 +262,20 @@ Parser::parseParameterClause(SourceLoc &leftParenLoc,
262262
|| Tok.isContextualKeyword("consuming")
263263
|| Tok.isContextualKeyword("isolated")
264264
|| Tok.isContextualKeyword("_const")))) {
265-
// is this token the identifier of an argument label?
266-
bool partOfArgumentLabel = lookahead<bool>(1, [&](CancellableBacktrackingScope &) {
267-
if (Tok.is(tok::colon))
268-
return true; // isolated :
269-
270-
return Tok.canBeArgumentLabel() && peekToken().is(tok::colon);
271-
});
272-
273-
if (partOfArgumentLabel)
274-
break;
275-
265+
// is this token the identifier of an argument label? `inout` is a
266+
// reserved keyword but the other modifiers are not.
267+
if (!Tok.is(tok::kw_inout)) {
268+
bool partOfArgumentLabel = lookahead<bool>(1, [&](CancellableBacktrackingScope &) {
269+
if (Tok.is(tok::colon))
270+
return true; // isolated :
271+
272+
return Tok.canBeArgumentLabel() && peekToken().is(tok::colon);
273+
});
274+
275+
if (partOfArgumentLabel)
276+
break;
277+
}
278+
276279
if (Tok.isContextualKeyword("isolated")) {
277280
// did we already find an 'isolated' type modifier?
278281
if (param.IsolatedLoc.isValid()) {

lib/SILGen/SILGenProlog.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,19 @@ struct ArgumentInitHelper {
376376

377377
// If our argument was owned, we use no implicit copy. Otherwise, we
378378
// use no copy.
379-
auto kind = MarkMustCheckInst::CheckKind::NoConsumeOrAssign;
380-
if (pd->isOwned())
379+
MarkMustCheckInst::CheckKind kind;
380+
switch (pd->getValueOwnership()) {
381+
case ValueOwnership::Default:
382+
case ValueOwnership::Shared:
383+
case ValueOwnership::InOut:
384+
kind = MarkMustCheckInst::CheckKind::NoConsumeOrAssign;
385+
break;
386+
387+
case ValueOwnership::Owned:
381388
kind = MarkMustCheckInst::CheckKind::ConsumableAndAssignable;
389+
break;
390+
}
391+
382392
value = SGF.B.createMarkMustCheckInst(loc, value, kind);
383393
SGF.emitManagedRValueWithCleanup(value);
384394
return completeUpdate(value);

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,8 +2353,7 @@ NeverNullType TypeResolver::resolveType(TypeRepr *repr,
23532353
case TypeReprKind::Attributed:
23542354
return resolveAttributedType(cast<AttributedTypeRepr>(repr), options);
23552355
case TypeReprKind::Ownership:
2356-
return resolveSpecifierTypeRepr(cast<SpecifierTypeRepr>(repr), options);
2357-
2356+
return resolveOwnershipTypeRepr(cast<OwnershipTypeRepr>(repr), options);
23582357
case TypeReprKind::Isolated:
23592358
return resolveIsolatedTypeRepr(cast<IsolatedTypeRepr>(repr), options);
23602359
case TypeReprKind::CompileTimeConst:

om.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

test/Parse/ownership_modifiers.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ func argumentLabel(__owned __shared: Int) {}
4040
func argumentLabel(borrowingInClosure: (borrowing consuming: Int) -> ()) {} // expected-error{{function types cannot have argument labels}}
4141
func argumentLabel(consumingInClosure: (consuming borrowing: Int) -> ()) {} // expected-error{{function types cannot have argument labels}}
4242
func argumentLabel(sharedInClosure: (__shared __owned: Int) -> ()) {} // expected-error{{function types cannot have argument labels}}
43-
func argumentLabel(ownedInClosure: (__shared __owned: Int) -> ()) {} // expected-error{{function types cannot have argument labels}}
43+
func argumentLabel(ownedInClosure: (__owned __shared: Int) -> ()) {} // expected-error{{function types cannot have argument labels}}
4444

45-
func argumentLabel(anonBorrowingInClosure: (_ consuming: Int) -> ()) {}
46-
func argumentLabel(anonConsumingInClosure: (_ borrowing: Int) -> ()) {}
47-
func argumentLabel(anonSharedInClosure: (_ __owned: Int) -> ()) {}
45+
func argumentLabel(anonBorrowingInClosure: (_ borrowing: Int) -> ()) {}
46+
func argumentLabel(anonConsumingInClosure: (_ consuming: Int) -> ()) {}
47+
func argumentLabel(anonSharedInClosure: (_ __shared: Int) -> ()) {}
4848
func argumentLabel(anonOwnedInClosure: (_ __owned: Int) -> ()) {}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// This is a variation of `ownership_modifiers.swift` with the expected error
4+
// lines removed, so that the file is parsed by the SwiftSyntax parser
5+
// and we validate that both parsers correctly handle this file.
6+
7+
struct borrowing {}
8+
struct consuming {}
9+
10+
struct Foo {}
11+
12+
func foo(x: borrowing Foo) {}
13+
func bar(x: consuming Foo) {}
14+
func baz(x: (borrowing Foo, consuming Foo) -> ()) {}
15+
16+
// `borrowing` and `consuming` are contextual keywords, so they should also
17+
// continue working as type and/or parameter names
18+
19+
func zim(x: borrowing) {}
20+
func zang(x: consuming) {}
21+
func zung(x: borrowing consuming) {}
22+
func zip(x: consuming borrowing) {}
23+
func zap(x: (borrowing, consuming) -> ()) {}
24+
func zoop(x: (borrowing consuming, consuming borrowing) -> ()) {}
25+
26+
// Parameter specifier names are regular identifiers in other positions,
27+
// including argument labels.
28+
29+
func argumentLabel(borrowing consuming: Int) {}
30+
func argumentLabel(consuming borrowing: Int) {}
31+
func argumentLabel(__shared __owned: Int) {}
32+
func argumentLabel(__owned __shared: Int) {}
33+
34+
// We should parse them as argument labels in function types, even though that
35+
36+
// isn't currently supported.
37+
38+
func argumentLabel(anonBorrowingInClosure: (_ borrowing: Int) -> ()) {}
39+
func argumentLabel(anonConsumingInClosure: (_ consuming: Int) -> ()) {}
40+
func argumentLabel(anonSharedInClosure: (_ __shared: Int) -> ()) {}
41+
func argumentLabel(anonOwnedInClosure: (_ __owned: Int) -> ()) {}

0 commit comments

Comments
 (0)