Commit Graph

275 Commits

Author SHA1 Message Date
Doug Gregor
dccf3155f1 SE-0022: Implement parsing, AST, and semantic analysis for #selector. 2016-01-26 21:12:04 -08:00
Doug Gregor
8336419844 Include completion source location information compound DeclNames.
When one spells a compound declaration name in the source (e.g.,
insertSubview(_:aboveSubview:), keep track of the locations of the
base name, parentheses, and argument labels.
2016-01-25 14:13:13 -08:00
practicalswift
45049f2763 [gardening] Fix recently introduced typos 2016-01-22 22:37:54 +01:00
Joe Pamer
a59e78749d - When simplifying constraint systems generated for deeply nested binary expressions with homogeneous argument types, directly bind the parameter type variable to the argument type. This generally improves type check performance of such expressions.
- Fix the test invocation of a fixed compiler crasher - it now compiles and runs cleanly.
2016-01-22 12:34:34 -08:00
Joe Pamer
de3d8a5823 More effectively simplify constraint graphs for nested binary expressions with homogeneous argument types. For example, this allows us to typecheck expressions of the form "a + b + c + d", where each variable is of an array type, without getting a "too complex" error.
Note that the typecheck perf for these kinds of expressions still isn't fantastic, but at least they're now computationally feasible. I have further improvements planned for this area which should bring performance in line with expectations.
2016-01-22 12:34:34 -08:00
Joe Pamer
995913e1a5 Begin favoring the expected types of closures with single-expression bodies. 2016-01-22 12:34:34 -08:00
Joe Pamer
5f9d3f83c7 When deciding whether to favor an overload binding constraint for a binary operator, only propagate favored types downward if there's a good chance that the operator has symmetric operands (as for certain arithmetic operators, for example). 2016-01-22 12:34:33 -08:00
Joe Pamer
3aeed2736b Introduce more refinements to how certain linked expr kinds are analyzed before performing edge contraction. 2016-01-22 12:34:33 -08:00
Joe Pamer
e3752c0720 In the LinkedExprAnalyzer, merge equivalence classes directly, rather
than create redundant constraints that will later be removed.
2016-01-22 12:34:33 -08:00
Joe Pamer
0e149db993 Being updating LinkedExprAnalyzer to work with the edge contractor. 2016-01-22 12:34:33 -08:00
Chris Lattner
6723acccf9 Use TypeExpr::getInstanceType to simplify some code, NFC. 2016-01-22 12:05:59 -08:00
Doug Gregor
fd3f03f3be Remove UnresolvedConstructorExpr.
UnresolvedConstructorExpr is not providing any value here; it's
essentially just UnresolvedDotExpr where the name refers to an
initializer, so use that instead. NFC
2016-01-20 17:09:02 -08:00
Doug Gregor
c9c1d1390c [SE-0021] Allow naming of specific initializers via "self.init(foo:bar:)". 2016-01-20 17:09:02 -08:00
Doug Gregor
5f07f6b12f Remove all vestiges of UnresolvedSelectorExpr. NFC 2016-01-20 17:09:01 -08:00
John McCall
1f3b3142b4 Distinguish conformance and superclass generic requirements.
As part of this, use a different enum for parsed generic requirements.

NFC except that I noticed that ASTWalker wasn't visiting the second
type in a conformance constraint; fixing this seems to have no effect
beyond producing better IDE annotations.
2016-01-11 16:07:37 -08:00
Jacob Bandes-Storch
b97cb48c2b [AST] Fix inconsistent handling of generic args & params during BoundGenericType::getSubstitutions
A decl’s full GenericSignature is set during validateGenericTypeSignature().

Then during ConstraintSystem::openTypes(), in ReplaceDependentTypes, the GenericArgs list is built from the generic signature (via getGenericParamTypes()) and passed into a new BoundGenericType.

In BoundGenericType::getSubstitutions(), the GenericArgs are assumed to match getGenericParamsOfContext()->getParams().

However, in reality, the GenericArgs include all levels of generic args, whereas getGenericParamsOfContext() are the params of the innermost context only, so the params array is accessed past its end.

This commit changes NominalTypeDecl::getGenericParamTypes() to return the innermost params, in order to match the output of BoundGenericType::getGenericArgs(). For clarity and to hopefully prevent future confusion, we also rename getGenericParamTypes() to getInnermostGenericParamTypes().
2016-01-09 02:19:28 -08:00
Chris Lattner
95f07f02b9 rename AST/Parameter.h to AST/ParameterList.h now that Parameter is gone. 2016-01-03 14:47:44 -08:00
Chris Lattner
6afe77d597 Eliminate the Parameter type completely - now ParameterList is just
an overblown array of ParamDecl*'s that also keeps track of parenlocs
and has helper methods.
2016-01-03 14:45:38 -08:00
Chris Lattner
b170b700f8 move the rest of the state out of Parameter and into ParamDecl,
in prep for Parameter going away.  NFC.
2016-01-01 15:27:53 -08:00
Chris Lattner
4479b46ef0 move the TypeLoc for a parameter out of Parameter and onto ParamDecl. NFC. 2016-01-01 14:13:13 -08:00
Chris Lattner
84b3a2ecc1 remove the 'forFunctionParam' from getTypeForPattern since it is always false now, NFC. 2015-12-31 21:03:19 -08:00
Chris Lattner
cc3f173040 remove variadics, default args etc, from tuple patterns, and simplify
the Pattern::clone interface now that the complexity isn't needed.
This also removes support for serializing this state.
2015-12-31 20:12:12 -08:00
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
Chris Lattner
8f158151d0 Merge pull request #389 from gregomni/sr-114
Don't add constraints for invalid subscript declarations.
2015-12-10 22:11:25 -08:00
Chris Willmore
c99c02b5a6 Transform EditorPlaceholderExpr into trap if executed in playground
mode (take 2)

Allow untyped placeholder to take arbitrary type, but default to Void.
Add _undefined<T>() function, which is like fatalError() but has
arbitrary return type. In playground mode, merely warn about outstanding
placeholders instead of erroring out, and transform placeholders into
calls to _undefined(). This way, code with outstanding placeholders will
only crash when it attempts to evaluate such placeholders.

When generating constraints for an iterated sequence of type T, emit

    T convertible to $T1
    $T1 conforms to SequenceType

instead of

    T convertible to SequenceType

This ensures that an untyped placeholder in for-each sequence position
doesn't get inferred to have type SequenceType. (The conversion is still
necessary because the sequence may have IUO type.) The new constraint
system precipitates changes in CSSimplify and CSDiag, and ends up fixing
18741539 along the way.

(NOTE: There is a small regression in diagnosis of issues like the
following:

    class C {}
    class D: C {}
    func f(a: [C]!) { for _: D in a {} }

It complains that [C]! doesn't conform to SequenceType when it should be
complaining that C is not convertible to D.)

<rdar://problem/21167372>

(Originally Swift SVN r31481)
2015-12-10 22:05:16 -08:00
gregomni
8e0b01bec9 Don't add constraints for invalid subscript declarations.
This fixes the crash in sr-114. Adding constraints for the invalid operator decl means constraining to the error type, which fails an
assertion later on while binding an overload choice. In all the normal function/method overload choice cases, if the decl is invalid
that choice gets skipped (never generated), so this is just another case of the existing way of doing things
2015-12-10 21:57:04 -08:00
Justas Brazauskas
043c518b27 Fix typos 2015-12-09 17:54:54 +02:00
Xi Ge
485b31443f [TypeChecker] Fix a crash: Valid typeLoc does not imply nonnull type. rdar://23544224 2015-12-08 14:51:23 -08:00
ide-an
f92d0c89dc Fix typo 2015-12-06 00:13:03 +09:00
Chris Willmore
821a5a6462 Merge pull request #163 from jtbandes/master
Fix crash when considering invalid binary operator function for resolution.

<rdar://23719809&23720006>
2015-12-04 15:29:12 -08:00
Jacob Bandes-Storch
56e13fccfd Fix crash when considering invalid binary operator function for resolution <rdar://23719809&23720006>
This fixes compiler crashes resulting from an invalid FuncDecl which is later considered while resolving a binary application.
2015-12-04 14:43:12 -08:00
Young Seok Tony Kim
134eb638bb Fixed typo.
Handled issue #162
squashed multiple typo fix commits
2015-12-05 01:57:09 +09:00
Dmitri Hrybenko
2e51d23875 Un-ifdef object literals
Swift SVN r32880
2015-10-25 07:50:53 +00:00
Xi Ge
870497e753 [CodeComplete] Avoid the assertions of already-type-checked ASTs.
Constraint generator likes the input AST to be not type-checked yet. However,
in code completion, we usually feed CSGen a (at least partially)
type-checked AST to infer the types of unresolved members, which
may lead to assertion failures. So we override the asserted method in
the code completion part to avoid explosions.

Swift SVN r32732
2015-10-16 22:13:57 +00:00
Xi Ge
dd113d0f6c Reapply "[InterfacePrint] When printing a type interface, omit the extensions that are not applicable."
After fixing a dangling pointer.

Swift SVN r32672
2015-10-13 22:08:08 +00:00
Xi Ge
ad3c03243f Revert "[InterfacePrint] When printing a type interface, omit the extensions that are not applicable."
For unhappy bots

Swift SVN r32666
2015-10-13 20:36:06 +00:00
Xi Ge
59c4ca96e8 [InterfacePrint] When printing a type interface, omit the extensions that are not applicable.
Swift SVN r32663
2015-10-13 20:00:03 +00:00
Ben Langmuir
9448df6fae [CodeCompletion] Add initial support for completing infix operators
This allows us to start code-completing infix operators in postfix
expressions.  As a first step, this patch only handles completing
against the immediate LHS (so for example 1 == 1 <here> doesn't suggest
boolean operators yet).

The next step is to feed the leading sequence expression from the parser
in so we can consider how the operator being completed fits into the
whole sequence expression.

For rdar://problem/22460167

Swift SVN r32465
2015-10-06 20:48:03 +00:00
Slava Pestov
69981a63eb Fix a handful of compiler_crashers were failing on OS X but passing on Linux
I'm too lazy to XFAIL: these, so fix the crash instead.

Swift SVN r32188
2015-09-23 22:27:36 +00:00
Xi Ge
5fa75a2eb3 Avoid collecting type variable types as results, as an attempt to fix the following bot failures:
Swift SVN r31952
2015-09-15 00:17:22 +00:00
Xi Ge
8d67a4ad12 [CodeComplete] Propagate type relation descriptor to the first argument, or the only argument, of call exprs.
rdar://22688827

Swift SVN r31928
2015-09-14 19:43:36 +00:00
Xi Ge
ec4e469062 [CodeComplete] Introduce code completion expr to better preserve the context of the code completion token in ASTs.
Swift SVN r31908
2015-09-11 22:59:12 +00:00
Chris Lattner
db5f25d290 fix a compiler crasher that can happen when invalid code causes a SequenceExpr to get to
CSGen.


Swift SVN r31722
2015-09-05 23:41:12 +00:00
Xi Ge
08eda102ed [CodeComplete] Finish transforming archetypes to actual types in code completion results and update tests.
Swift SVN r31635
2015-09-02 20:18:16 +00:00
Xi Ge
f75ac75d3b [CodeComplete] Try to substitute archetypes with actual types in code completion results.
When completing type members, teach the code completion engine to
transform the archetypes appearing in code completion results to the
actual types. NFC

Swift SVN r31628
2015-09-02 06:22:20 +00:00
Chris Lattner
c9fb58c662 remove the CheckedCastOperand & AddressOf locators which are no longer needed. NFC.
Swift SVN r31617
2015-09-02 04:19:54 +00:00
Chris Lattner
c26ed58541 remove IfThen/IfElse locators which are no longer needed.
Swift SVN r31616
2015-09-02 03:44:56 +00:00
Chris Lattner
be6da087d6 remove the AssignSource and AssignDest locators, which are no longer needed.
Swift SVN r31615
2015-09-02 03:40:55 +00:00