Commit Graph

23 Commits

Author SHA1 Message Date
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -08:00
Chris Lattner
7daaa22d93 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.
2015-12-31 19:24:46 -08:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Slava Pestov
533f42dd2f Closures and local functions only capture generic parameters if necessary
The CaptureInfo computed by Sema now records if the body of the
function uses any generic parameters from the outer context.
SIL type lowering only adds a generic signature if this is the
case, instead of unconditionally.

This might yield a marginal performance improvement in some cases,
but more interestingly will allow @convention(c) conversions from
generic context.

Swift SVN r32161
2015-09-22 21:08:28 +00:00
Joe Groff
7ebe973bb4 AST: Preserve hack to consider 'defer' function bodies to be @noescape.
Using a func decl lost this, which leads to some undesirable behavior when mutating values in 'defer' blocks, such as losing inout deshadowing.

Swift SVN r30788
2015-07-30 05:28:09 +00:00
John McCall
bc3b47b98a Infer the return type of a closure to be () if it contains no
return statements, or a return statement with no operand.

Also, fix a special-case diagnostic about converting a return
expression to (1) only apply to converting the actual return
expression, not an arbitrary sub-expression, and (2) use the
actual operand and return types, not the drilled-down types
that caused the failure.

Swift SVN r30420
2015-07-20 21:52:18 +00:00
Chris Lattner
3489840b8d rework our representation of capture lists to compute the "isDirect" bit up front
when computing the list.  This simplifies getLocalCaptures to *just* filter out
global captures, and paves the way for other enhancements.  NFC.


Swift SVN r25739
2015-03-04 01:56:48 +00:00
Joe Groff
94be8424ff Sema: Type checking for C function pointers.
Since a function pointer doesn't carry any context, we can only form a C function pointer from a static reference to a global function or a context-free local function or closure. (Or maybe a static function applied to its metatype, but that's not handled here yet.) As a placeholder for a to-be-bikeshedded surface syntax, let the existing @cc(cdecl) attribute appear in source text when the -enable-c-function-pointers frontend flag is passed.

Swift SVN r25308
2015-02-16 00:41:53 +00:00
Chris Lattner
58e0efc345 Enhance getDeclCaptureKind() to take the closure that is capturing the
given decl, and plumb the information down to it.  NFC since the argument
is currently dead.



Swift SVN r24132
2014-12-23 23:08:38 +00:00
Joe Groff
3e9d7c3076 Add accessors to AnyFunctionRef to the underlying function decl or closure expr.
Swift SVN r17280
2014-05-02 22:04:43 +00:00
Chris Lattner
108910c410 remove a now-dead function.
Swift SVN r13913
2014-02-14 18:13:28 +00:00
Chris Lattner
9ee7d99a46 switch a few things off of argument patterns, onto body patterns.
Swift SVN r13891
2014-02-14 01:33:14 +00:00
Chris Lattner
bc005219d1 Implement most of support for properties in function scope, part of rdar://15922884.
Most of the complexity here is teaching SILGen how to handle closed-over direct 
accesses to observing properties, since all of the getter/setter/willSet/didSet
members of the property are actually full closures when in a function body.

We generate correct but really terrible code here, since the setter captures the
willset/didset members themselves.  I'm not worrying about the performance of 
this construct though, functionality is what matters.


Swift SVN r13778
2014-02-11 06:23:14 +00:00
Joe Groff
d78a328c4f AST: Give AnyFunctionRef.h a getInterfaceType() method.
And make its methods all const. getInterfaceType() gives the interface type of an underlying AbstractFunctionDecl.

Swift SVN r10608
2013-11-20 22:30:44 +00:00
Dmitri Hrybenko
0900e992b9 Simplify AnyFunctionRef::getAsDeclContext()
Swift SVN r8322
2013-09-17 01:39:45 +00:00
Dmitri Hrybenko
f1f189f4e0 Rename PipeClosureExpr -> ClosureExpr
Swift SVN r8321
2013-09-17 01:37:36 +00:00
Dmitri Hrybenko
64cb7058e4 Add AnyFunctionRef::getArgParamPatterns()
... and simplify getFuncNaturalUncurryLevel() with it


Swift SVN r8317
2013-09-17 01:13:42 +00:00
Dmitri Hrybenko
a35edf252d AnyFunctionRef: add an assertion that it wraps a non-null AST node
Swift SVN r8312
2013-09-17 00:15:13 +00:00
Dmitri Hrybenko
9636b9fffb Migrate the last use of FuncExprLike to AnyFunctionRef
Swift SVN r8309
2013-09-16 23:54:29 +00:00
Dmitri Hrybenko
b18c38a322 Rename ImplicitClosureExpr -> AutoClosureExpr
Swift SVN r8304
2013-09-16 23:03:50 +00:00
Dmitri Hrybenko
f2cc4cb303 Rename CapturingExpr -> AbstractClosureExpr
Swift SVN r8299
2013-09-16 21:58:44 +00:00
Dmitri Hrybenko
3354dd402b Unify two implementations of TypeChecker::computeCaptures()
Swift SVN r8296
2013-09-16 21:17:00 +00:00
Dmitri Hrybenko
536ed954ad Remove FuncExpr. Add CaptureInfo to FuncDecl. Introduce AnyFunctionRef.
AnyFunctionRef is a universal function reference that can wrap all AST nodes
that represent functions and exposes a common interface to them.  Use it in two
places in SIL where CapturingExpr was used previously.

AnyFunctionRef allows further simplifications in other places, but these will
be done separately.


Swift SVN r8239
2013-09-14 02:15:48 +00:00