Skip to content

Commit 26be8f6

Browse files
authored
---
yaml --- r: 326254 b: refs/heads/master-next c: 92d5827 h: refs/heads/master
1 parent 4f88f50 commit 26be8f6

Some content is hidden

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

59 files changed

+1098
-584
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: 64ed0a40773faf6d6cc6c1ca1ffc715a574d400f
3+
refs/heads/master-next: 92d58279f829e38a286c31850a04db8cbf6409c4
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/cmake/modules/SwiftHandleGybSources.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ function(handle_gyb_sources dependency_out_var_name sources_var_name arch)
121121
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/DeclNodes.py"
122122
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/ExprNodes.py"
123123
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/GenericNodes.py"
124+
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/NodeSerializationCodes.py"
124125
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/PatternNodes.py"
126+
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/SILOnlyNodes.py"
125127
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/StmtNodes.py"
126128
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/TypeNodes.py"
127129
"${SWIFT_SOURCE_DIR}/utils/gyb_syntax_support/Token.py"

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ class LazyResolver {
6060
/// consistency and provides the value a type.
6161
virtual void resolveDeclSignature(ValueDecl *VD) = 0;
6262

63-
/// Resolve the generic environment of the given protocol.
64-
virtual void resolveProtocolEnvironment(ProtocolDecl *proto) = 0;
65-
6663
/// Resolve the type of an extension.
6764
///
6865
/// This can be called to ensure that the members of an extension can be

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,24 @@
2222

2323
namespace swift {
2424
/// Generates AST nodes from Syntax nodes.
25+
class Parser;
2526
class ASTGen {
2627
ASTContext &Context;
2728

2829
/// Type cache to prevent multiple transformations of the same syntax node.
2930
llvm::DenseMap<syntax::SyntaxNodeId, TypeRepr *> TypeCache;
3031

31-
PersistentParserState **ParserState;
32+
Parser &P;
3233

3334
// FIXME: remove when Syntax can represent all types and ASTGen can handle them
3435
/// Types that cannot be represented by Syntax or generated by ASTGen.
3536
llvm::DenseMap<SourceLoc, TypeRepr *> Types;
3637

38+
llvm::DenseMap<SourceLoc, DeclAttributes> ParsedDeclAttrs;
39+
3740
public:
38-
ASTGen(ASTContext &Context, PersistentParserState **ParserState)
39-
: Context(Context), ParserState(ParserState) {}
41+
ASTGen(ASTContext &Context, Parser &P)
42+
: Context(Context), P(P) {}
4043

4144
SourceLoc generate(syntax::TokenSyntax Tok, SourceLoc &Loc);
4245

@@ -70,6 +73,15 @@ class ASTGen {
7073
llvm::SmallVector<TypeRepr *, 4>
7174
generate(syntax::GenericArgumentListSyntax Args, SourceLoc &Loc);
7275

76+
GenericParamList *
77+
generate(syntax::GenericParameterClauseListSyntax clause, SourceLoc &Loc);
78+
GenericParamList *
79+
generate(syntax::GenericParameterClauseSyntax clause, SourceLoc &Loc);
80+
Optional<RequirementRepr>
81+
generate(syntax::GenericRequirementSyntax req, SourceLoc &Loc);
82+
LayoutConstraint
83+
generate(syntax::LayoutConstraintSyntax req, SourceLoc &Loc);
84+
7385
/// Copy a numeric literal value into AST-owned memory, stripping underscores
7486
/// so the semantic part of the value can be parsed by APInt/APFloat parsers.
7587
static StringRef copyAndStripUnderscores(StringRef Orig, ASTContext &Context);
@@ -102,6 +114,8 @@ class ASTGen {
102114

103115
ValueDecl *lookupInScope(DeclName Name);
104116

117+
void addToScope(ValueDecl *D, bool diagnoseRedefinitions = true);
118+
105119
TypeRepr *cacheType(syntax::TypeSyntax Type, TypeRepr *TypeAST);
106120

107121
TypeRepr *lookupType(syntax::TypeSyntax Type);
@@ -112,6 +126,10 @@ class ASTGen {
112126
bool hasType(const SourceLoc &Loc) const;
113127

114128
TypeRepr *getType(const SourceLoc &Loc) const;
129+
130+
void addDeclAttributes(DeclAttributes attrs, SourceLoc Loc);
131+
bool hasDeclAttributes(SourceLoc Loc) const;
132+
DeclAttributes getDeclAttributes(SourceLoc Loc) const;
115133
};
116134
} // namespace swift
117135

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@ class Lexer {
200200
ParsedTrivia &TrailingTriviaResult) {
201201
Result = NextToken;
202202
if (TriviaRetention == TriviaRetentionMode::WithTrivia) {
203-
LeadingTriviaResult = {LeadingTrivia};
204-
TrailingTriviaResult = {TrailingTrivia};
203+
std::swap(LeadingTriviaResult, LeadingTrivia);
204+
std::swap(TrailingTriviaResult, TrailingTrivia);
205205
}
206206
if (Result.isNot(tok::eof))
207207
lexImpl();

branches/master-next/include/swift/Parse/ParsedSyntaxBuilders.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace swift {
3030
class ParsedRawSyntaxRecorder;
3131
class SyntaxParsingContext;
3232

33-
% for node in SYNTAX_NODES:
33+
% for node in SYNTAX_NODES + SILONLY_NODES:
3434
% if node.is_buildable():
3535
% child_count = len(node.children)
3636
class Parsed${node.name}Builder {

branches/master-next/include/swift/Parse/ParsedSyntaxNodes.h.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ namespace swift {
2828
% # Emit the non-collection classes first, then emit the collection classes
2929
% # that reference these classes.
3030

31-
% for node in SYNTAX_NODES:
31+
% for node in SYNTAX_NODES + SILONLY_NODES:
3232
% if not node.is_syntax_collection():
3333
class Parsed${node.name};
3434
% end
3535
% end
3636

37-
% for node in SYNTAX_NODES:
37+
% for node in SYNTAX_NODES + SILONLY_NODES:
3838
% if node.is_syntax_collection():
3939
using Parsed${node.name} =
4040
ParsedSyntaxCollection<syntax::SyntaxKind::${node.syntax_kind}>;
4141
% end
4242
% end
4343

44-
% for node in SYNTAX_NODES:
44+
% for node in SYNTAX_NODES + SILONLY_NODES:
4545
% if not node.is_syntax_collection():
4646
% qualifier = "" if node.is_base() else "final"
4747
% for line in dedented_lines(node.description):

branches/master-next/include/swift/Parse/ParsedSyntaxRecorder.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class SyntaxParsingContext;
3131

3232
struct ParsedSyntaxRecorder {
3333

34-
% for node in SYNTAX_NODES:
34+
% for node in SYNTAX_NODES + SILONLY_NODES:
3535
% if node.children:
3636
% child_params = []
3737
% for child in node.children:

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,11 +695,19 @@ class Parser {
695695
/// plain Tok.is(T1) check).
696696
bool skipUntilTokenOrEndOfLine(tok T1);
697697

698+
//-------------------------------------------------------------------------//
699+
// Ignore token APIs.
700+
// This is used when we skip gabage text in the source text.
701+
702+
/// Ignore the current single token.
698703
void ignoreToken();
699704
void ignoreToken(tok Kind) {
705+
/// Ignore the current single token asserting its kind.
700706
assert(Tok.is(Kind));
701707
ignoreToken();
702708
}
709+
/// Conditionally ignore the current single token if it matches with the \p
710+
/// Kind.
703711
bool ignoreIf(tok Kind) {
704712
if (!Tok.is(Kind))
705713
return false;
@@ -1173,7 +1181,8 @@ class Parser {
11731181
using TypeASTResult = ParserResult<TypeRepr>;
11741182
using TypeResult = ParsedSyntaxResult<ParsedTypeSyntax>;
11751183

1176-
LayoutConstraint parseLayoutConstraint(Identifier LayoutConstraintID);
1184+
ParsedSyntaxResult<ParsedLayoutConstraintSyntax>
1185+
parseLayoutConstraintSyntax();
11771186

11781187
TypeResult parseTypeSyntax();
11791188
TypeResult parseTypeSyntax(Diag<> MessageID, bool HandleCodeCompletion = true,
@@ -1597,8 +1606,19 @@ class Parser {
15971606
//===--------------------------------------------------------------------===//
15981607
// Generics Parsing
15991608

1609+
ParserResult<GenericParamList> parseSILGenericParams();
1610+
1611+
ParserStatus parseSILGenericParamsSyntax(
1612+
Optional<ParsedGenericParameterClauseListSyntax> &result);
1613+
1614+
ParsedSyntaxResult<ParsedGenericParameterClauseSyntax>
1615+
parseGenericParameterClauseSyntax();
1616+
1617+
ParsedSyntaxResult<ParsedGenericWhereClauseSyntax>
1618+
parseGenericWhereClauseSyntax(bool &FirstTypeInComplete,
1619+
bool AllowLayoutConstraints = false);
1620+
16001621
ParserResult<GenericParamList> parseGenericParameters();
1601-
ParserResult<GenericParamList> parseGenericParameters(SourceLoc LAngleLoc);
16021622
ParserStatus parseGenericParametersBeforeWhere(SourceLoc LAngleLoc,
16031623
SmallVectorImpl<GenericTypeParamDecl *> &GenericParams);
16041624
ParserResult<GenericParamList> maybeParseGenericParams();

branches/master-next/include/swift/Syntax/SyntaxBuilders.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace syntax {
2929

3030
class SyntaxArena;
3131

32-
% for node in SYNTAX_NODES:
32+
% for node in SYNTAX_NODES + SILONLY_NODES:
3333
% if node.is_buildable():
3434
% child_count = len(node.children)
3535
class ${node.name}Builder {

branches/master-next/include/swift/Syntax/SyntaxFactory.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ struct SyntaxFactory {
7171
static Syntax
7272
makeBlankCollectionSyntax(SyntaxKind Kind);
7373

74-
% for node in SYNTAX_NODES:
74+
% for node in SYNTAX_NODES + SILONLY_NODES:
7575
% if node.children:
7676
% child_params = []
7777
% for child in node.children:

branches/master-next/include/swift/Syntax/SyntaxKind.h.gyb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from gyb_syntax_support import *
33
from gyb_syntax_support.kinds import SYNTAX_BASE_KINDS
44
grouped_nodes = { kind: [] for kind in SYNTAX_BASE_KINDS }
5-
for node in SYNTAX_NODES:
5+
for node in SYNTAX_NODES + SILONLY_NODES:
66
grouped_nodes[node.base_kind].append(node)
77
# -*- mode: C++ -*-
88
# Ignore the following admonition; it applies to the resulting .h file only
@@ -89,12 +89,14 @@ struct WrapperTypeTraits<syntax::SyntaxKind> {
8989
return 0;
9090
case syntax::SyntaxKind::Unknown:
9191
return 1;
92-
% for name, nodes in grouped_nodes.items():
93-
% for node in nodes:
92+
% for node in SYNTAX_NODES:
9493
case syntax::SyntaxKind::${node.syntax_kind}:
9594
return ${SYNTAX_NODE_SERIALIZATION_CODES[node.syntax_kind]};
96-
% end
9795
% end
96+
% for node in SILONLY_NODES:
97+
case syntax::SyntaxKind::${node.syntax_kind}:
98+
% end
99+
llvm_unreachable("unserializable syntax kind");
98100
}
99101
llvm_unreachable("unhandled kind");
100102
}
@@ -122,6 +124,10 @@ struct ScalarReferenceTraits<syntax::SyntaxKind> {
122124
case syntax::SyntaxKind::${node.syntax_kind}:
123125
return "\"${node.syntax_kind}\"";
124126
% end
127+
% for node in SILONLY_NODES:
128+
case syntax::SyntaxKind::${node.syntax_kind}:
129+
% end
130+
llvm_unreachable("unserializable syntax kind");
125131
}
126132
llvm_unreachable("unhandled kind");
127133
}

branches/master-next/include/swift/Syntax/SyntaxNodes.h.gyb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,21 @@ namespace syntax {
3232
% # Emit the non-collection classes first, then emit the collection classes
3333
% # that reference these classes.
3434

35-
% for node in SYNTAX_NODES:
35+
% for node in SYNTAX_NODES + SILONLY_NODES:
3636
% if not node.is_syntax_collection():
3737
class ${node.name};
3838
% end
3939
% end
4040

41-
% for node in SYNTAX_NODES:
41+
% for node in SYNTAX_NODES + SILONLY_NODES:
4242
% if node.is_syntax_collection():
4343
using ${node.name} =
4444
SyntaxCollection<SyntaxKind::${node.syntax_kind},
4545
${node.collection_element_type}>;
4646
% end
4747
% end
4848

49-
% for node in SYNTAX_NODES:
49+
% for node in SYNTAX_NODES + SILONLY_NODES:
5050
% if not node.is_syntax_collection():
5151
% qualifier = "" if node.is_base() else "final"
5252
% for line in dedented_lines(node.description):

branches/master-next/include/swift/Syntax/SyntaxVisitor.h.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ namespace syntax {
3232
struct SyntaxVisitor {
3333
virtual ~SyntaxVisitor() {}
3434

35-
% for node in SYNTAX_NODES:
35+
% for node in SYNTAX_NODES + SILONLY_NODES:
3636
% if is_visitable(node):
3737
virtual void visit(${node.name} node);
3838
% end

branches/master-next/lib/AST/ASTVerifier.cpp

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -176,22 +176,6 @@ template <typename T> T *getOverriddenDeclIfAvailable(T *decl) {
176176

177177
return cast_or_null<T>(decl->getOverriddenDecl());
178178
}
179-
180-
// Retrieve the generic signature of the innermost context that has been forced
181-
// so far.
182-
//
183-
// This avoids kicking off the request for a generic signature in the verifier.
184-
static GenericSignature *
185-
getNearestForcedGenericSignatureOfContext(DeclContext *dc) {
186-
do {
187-
if (auto decl = dc->getAsDecl())
188-
if (auto GC = decl->getAsGenericContext())
189-
if (GC->hasComputedGenericSignature())
190-
return GC->getGenericSignature();
191-
} while ((dc = dc->getParent()));
192-
193-
return nullptr;
194-
}
195179
} // namespace
196180

197181
class Verifier : public ASTWalker {
@@ -208,8 +192,9 @@ class Verifier : public ASTWalker {
208192
using ScopeLike = llvm::PointerUnion<DeclContext *, BraceStmt *>;
209193
SmallVector<ScopeLike, 4> Scopes;
210194

211-
/// The stack of context generic signatures.
212-
SmallVector<GenericSignature *, 2> GenericSig;
195+
/// The stack of generic contexts.
196+
using GenericLike = llvm::PointerUnion<DeclContext *, GenericSignature *>;
197+
SmallVector<GenericLike, 2> Generics;
213198

214199
/// The stack of optional evaluations active at this point.
215200
SmallVector<OptionalEvaluationExpr *, 4> OptionalEvaluations;
@@ -632,7 +617,7 @@ class Verifier : public ASTWalker {
632617
}
633618

634619
// Otherwise, the archetype needs to be from this scope.
635-
if (GenericSig.empty() || !GenericSig.back()) {
620+
if (Generics.empty() || !Generics.back()) {
636621
Out << "AST verification error: archetype outside of generic "
637622
"context: " << root->getString() << "\n";
638623
return true;
@@ -643,13 +628,20 @@ class Verifier : public ASTWalker {
643628
auto *archetypeEnv = rootPrimary->getGenericEnvironment();
644629
auto *archetypeSig = archetypeEnv->getGenericSignature();
645630

646-
if (GenericSig.back() != archetypeSig) {
631+
auto genericCtx = Generics.back();
632+
GenericSignature *genericSig;
633+
if (auto *genericDC = genericCtx.dyn_cast<DeclContext *>())
634+
genericSig = genericDC->getGenericSignatureOfContext();
635+
else
636+
genericSig = genericCtx.get<GenericSignature *>();
637+
638+
if (genericSig != archetypeSig) {
647639
Out << "Archetype " << root->getString() << " not allowed "
648640
<< "in this context\n";
649641
Out << "Archetype generic signature: "
650642
<< archetypeSig->getAsString() << "\n";
651643
Out << "Context generic signature: "
652-
<< GenericSig.back()->getAsString() << "\n";
644+
<< genericSig->getAsString() << "\n";
653645

654646
return true;
655647
}
@@ -704,16 +696,16 @@ class Verifier : public ASTWalker {
704696

705697
void pushScope(DeclContext *scope) {
706698
Scopes.push_back(scope);
707-
GenericSig.push_back(::getNearestForcedGenericSignatureOfContext(scope));
699+
Generics.push_back(scope);
708700
}
709701
void pushScope(BraceStmt *scope) {
710702
Scopes.push_back(scope);
711703
}
712704
void popScope(DeclContext *scope) {
713705
assert(Scopes.back().get<DeclContext*>() == scope);
714-
assert(GenericSig.back() == ::getNearestForcedGenericSignatureOfContext(scope));
706+
assert(Generics.back().get<DeclContext*>() == scope);
715707
Scopes.pop_back();
716-
GenericSig.pop_back();
708+
Generics.pop_back();
717709
}
718710
void popScope(BraceStmt *scope) {
719711
assert(Scopes.back().get<BraceStmt*>() == scope);
@@ -2687,14 +2679,15 @@ class Verifier : public ASTWalker {
26872679
const auto &witness = normal->getWitness(req);
26882680

26892681
if (auto *genericEnv = witness.getSyntheticEnvironment())
2690-
GenericSig.push_back(genericEnv->getGenericSignature());
2682+
Generics.push_back(genericEnv->getGenericSignature());
26912683

26922684
verifyChecked(witness.getRequirementToSyntheticSubs());
26932685
verifyChecked(witness.getSubstitutions());
26942686

26952687
if (auto *genericEnv = witness.getSyntheticEnvironment()) {
2696-
assert(GenericSig.back() == genericEnv->getGenericSignature());
2697-
GenericSig.pop_back();
2688+
assert(Generics.back().get<GenericSignature*>()
2689+
== genericEnv->getGenericSignature());
2690+
Generics.pop_back();
26982691
}
26992692

27002693
continue;

0 commit comments

Comments
 (0)