Skip to content

Commit 7daaa22

Browse files
committed
Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented as Pattern's (of a particular sort), stemming from an early design direction that was abandoned. Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns have to have varargs and default parameters) and make working on parameter lists complicated and error prone. This might have been ok in 2015, but there is no way we can live like this in 2016. Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the parameter specific stuff. This simplifies many things and allows a lot of simplifications. Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch. The good news is that it erases a ton of code, and the technical debt that went with it. Ignoring test suite changes, we have: 77 files changed, 2359 insertions(+), 3221 deletions(-) This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on patches. Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75. Fixes an overloading bug involving default arguments and curried functions (see the diff to Constraints/diagnostics.swift, which we now correctly accept). Fixes cases where problems with parameters would get emitted multiple times, e.g. in the test/Parse/subscripting.swift testcase. The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests (for the better, I think). Eliminates the bogus "type annotation missing in pattern" error message when a type isn't specified for a parameter (see test/decl/func/functions.swift). This now consistently parenthesizes argument lists in function types, which leads to many diffs in the SILGen tests among others. This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and I haven't been able to figure it out. Given that this is experimental functionality anyway, I'm just XFAILing the test for now. i'll look at it separately from this mongo diff.
1 parent 3077851 commit 7daaa22

File tree

125 files changed

+2528
-3388
lines changed

Some content is hidden

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

125 files changed

+2528
-3388
lines changed

include/swift/AST/AST.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "swift/AST/ExprHandle.h"
2626
#include "swift/AST/Initializer.h"
2727
#include "swift/AST/Module.h"
28+
#include "swift/AST/Parameter.h"
2829
#include "swift/AST/Pattern.h"
2930
#include "swift/AST/Stmt.h"
3031
#include "swift/AST/Types.h"

include/swift/AST/ASTVisitor.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
#include "llvm/Support/ErrorHandling.h"
2828

2929
namespace swift {
30+
class ParameterList;
31+
struct Parameter;
3032

3133
/// ASTVisitor - This is a simple visitor class for Swift expressions.
3234
template<typename ImplClass,
@@ -158,6 +160,16 @@ class ASTVisitor {
158160
A, ::std::forward<Args>(AA)...); \
159161
}
160162
#include "swift/AST/Attr.def"
163+
164+
bool visit(ParameterList *PL) {
165+
return static_cast<ImplClass*>(this)->visitParameterList(PL);
166+
}
167+
bool visit(Parameter &P) {
168+
return static_cast<ImplClass*>(this)->visitParameter(P);
169+
}
170+
171+
bool visitParameterList(ParameterList *PL) { return false; }
172+
bool visitParameter(Parameter &P) { return false; }
161173
};
162174

163175

include/swift/AST/ASTWalker.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class Stmt;
2525
class Pattern;
2626
class TypeRepr;
2727
struct TypeLoc;
28+
class ParameterList;
2829

2930
/// \brief An abstract class used to traverse an AST.
3031
class ASTWalker {
@@ -182,6 +183,18 @@ class ASTWalker {
182183
/// params in an AbstractFunctionDecl.
183184
virtual bool shouldWalkIntoFunctionGenericParams() { return false; }
184185

186+
/// walkToParameterListPre - This method is called when first visiting a
187+
/// ParameterList, before walking into its parameters. If it returns false,
188+
/// the subtree is skipped.
189+
///
190+
virtual bool walkToParameterListPre(ParameterList *PL) { return true; }
191+
192+
/// walkToParameterListPost - This method is called after visiting the
193+
/// children of a parameter list. If it returns false, the remaining
194+
/// traversal is terminated and returns failure.
195+
virtual bool walkToParameterListPost(ParameterList *PL) { return true; }
196+
197+
185198
protected:
186199
ASTWalker() = default;
187200
ASTWalker(const ASTWalker &) = default;

include/swift/AST/AnyFunctionRef.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ class AnyFunctionRef {
6161
getCaptureInfo().getLocalCaptures(Result);
6262
}
6363

64-
ArrayRef<Pattern *> getBodyParamPatterns() const {
64+
ArrayRef<ParameterList *> getParameterLists() const {
6565
if (auto *AFD = TheFunction.dyn_cast<AbstractFunctionDecl *>())
66-
return AFD->getBodyParamPatterns();
67-
return TheFunction.get<AbstractClosureExpr *>()->getParamPatterns();
66+
return AFD->getParameterLists();
67+
return TheFunction.get<AbstractClosureExpr *>()->getParameterLists();
6868
}
6969

7070
bool hasType() const {

include/swift/AST/ArchetypeBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ class ArchetypeBuilder {
289289
/// because the type \c Dictionary<K,V> cannot be formed without it.
290290
///
291291
/// \returns true if an error occurred, false otherwise.
292-
bool inferRequirements(Pattern *pattern, GenericParamList *genericParams);
292+
bool inferRequirements(ParameterList *params,GenericParamList *genericParams);
293293

294294
/// Finalize the set of requirements, performing any remaining checking
295295
/// required before generating archetypes.

0 commit comments

Comments
 (0)