Commit Graph

241 Commits

Author SHA1 Message Date
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
Xi Ge
ef3b45871b [CodeComplete] Complete arguments of call expressions.
When users invoke code completion at an argument position, we suggest argument names,
if required however not specified, or a list of argument values. These values are annotated
with their type relation to the expected argument types, so that
Xcode can prioritize those values that apply over those that do not.
This also fixes: rdar://21727063

Swift SVN r31505
2015-08-26 22:01:25 +00:00
Chris Willmore
9c1f3e907a Revert "Transform EditorPlaceholderExpr into trap if executed in playground mode."
This reverts commit r31481, which apparently needed some parallel
changes to SourceKit and broke the build as a result.

Swift SVN r31483
2015-08-26 05:28:04 +00:00
Chris Willmore
0addd80bb3 Transform EditorPlaceholderExpr into trap if executed in playground mode.
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.

<rdar://problem/21167372> transform EditorPlaceholderExpr into fatalError()

Swift SVN r31481
2015-08-26 04:50:55 +00:00
Xi Ge
9ed7a57865 [Parser] When parsing error occurs on arguments, we still try to preserve the call expression.
This allows tools, like code completion or jumping to definition, to be able to resolve
function names even though the argument is wrong.

Swift SVN r31387
2015-08-21 19:41:11 +00:00
Chris Lattner
6358c3049d Now that we consistently propagate contextual type information when it
is available, use it to start producing useful diagnostics for contextually
typed member references.


Swift SVN r31362
2015-08-20 17:07:15 +00:00
Xi Ge
c33e3efe59 [CodeComplete] Complete the right hand side of assignment expressions.
When users complete the right-hand side of an assignment expression, we only
show the results whose types are convertible to those of the left-hand side.

Swift SVN r31357
2015-08-20 01:35:30 +00:00
Chris Lattner
61de97b063 Switch string literal type checking to work more like other literals: if
it already has a type, don't re-type-check the literal.  This improves a
diagnostic involved with 20491794.


Swift SVN r31330
2015-08-19 04:58:36 +00:00
Chris Lattner
b51e9cf6b4 micro code cleanups, nfc.
Swift SVN r31271
2015-08-17 19:59:05 +00:00
Xi Ge
5a16d37dbf [CodeComplete] Address Ben's comments on r31063, r31083 and r31195.
Swift SVN r31254
2015-08-14 23:48:56 +00:00
Xi Ge
0bab23961a [CodeComplete] Refine the code completion results for unresolved members by using constraint solver.
Before this commit, for unresolved members, code completion suggests all visible enum elements
 and option set types. To refine the results, this commit uses constraint solver to infer
the type of unresolved members by analyzing parental expressions. If the solver has solutions,
we complete the unresolved member, otherwise abort.
rdar://16659653

Swift SVN r31195
2015-08-13 00:19:58 +00:00
Chris Lattner
a899872d91 Reapply r31105, with some fixes to invalid unconstrained generics. These fixes correct
the regressions that r31105 introduced in the validation tests, as well as fixing a number
of other validation tests as well.

Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.





Swift SVN r31130
2015-08-11 06:06:05 +00:00
Chris Lattner
2204dbcbfd revert r31105, it causes some regressions on validation tests.
Swift SVN r31107
2015-08-10 15:01:22 +00:00
Chris Lattner
de79b60c89 Introduce a new UnresolvedType to the type system, and have CSDiags start to use it
as a way to get more type information out of incorrect subexpressions.  UnresolvedType
generally just propagates around the type system like a type variable:
 - it magically conforms to all protocols
 - it CSGens as an unconstrained type variable.
 - it ASTPrints as _, just like a type variable.

The major difference is that UnresolvedType can be used outside the context of a
ConstraintSystem, which is useful for CSGen since it sets up several of them to 
diagnose subexpressions w.r.t. their types.

For now, our use of this is extremely limited: when a closureexpr has no contextual
type available and its parameters are invalid, we wipe them out with UnresolvedType
(instead of the previous nulltype dance) to get ambiguities later on.

We also introduce a new FreeTypeVariableBinding::UnresolvedType approach for
constraint solving (and use this only in one place in CSDiags so far, to resolve
the callee of a CallExpr) which solves a system and rewrites any leftover type 
variables as UnresolvedTypes.  This allows us to get more precise information out,
for example, diagnosing:

 func r22162441(lines: [String]) {
   lines.map { line in line.fooBar() }
 }

with: value of type 'String' has no member 'fooBar'
instead of: type of expression is ambiguous without more context

This improves a number of other diagnostics as well, but is just the infrastructural
stepping stone for greater things.



Swift SVN r31105
2015-08-10 06:18:27 +00:00
Chris Lattner
442de4d4b0 fix <rdar://problem/22162441> Crash from failing to diagnose nonexistent method access inside closure
When CSGen was analyzing a DeclRefExpr reference, it was accidentally 
applying some magic only to anonymous closure parameters, not named ones,
leading to a silent CSGen failure.  Fix this by handling all closure parameters
the same way.



Swift SVN r31098
2015-08-08 19:09:15 +00:00
Jordan Rose
185326755c 'try?' is supposed to stack optionals, not merge them.
More rdar://problem/21692467

Swift SVN r31059
2015-08-06 21:02:40 +00:00
Jordan Rose
2801d47e59 Add Parse and Sema support for 'try?'.
rdar://problem/21692467

Swift SVN r31030
2015-08-05 22:17:25 +00:00
Jordan Rose
953424072e Guard "object literals" feature with SWIFT_ENABLE_OBJECT_LITERALS.
This is not a feature we're releasing at the moment, so provide a way
to turn it off.

rdar://problem/21935551

Swift SVN r30966
2015-08-04 00:16:52 +00:00
Slava Pestov
6171df6a13 Sema: Don't favor extension methods over protocol requirements
This bug triggered when three pre-conditions held:

- A protocol requirement method signature involves archetypes built
  from associated types
- A protocol extension provides a default implementation of this method
- The method is called from another method in the same extension,
  with a parameter of the associated type

In this case, the archetypes in the signature would match exactly
and we would end up picking the extension method over the protocol
method, which would not even be considered. As a result, the
extension method would be dispatch statically instead of using
witness method dispatch, which is wrong.

Hopefully one day we can model default implementations as real
overrides and not overloads.

Note that the test is a SILGen test even though the bug is in Sema,
since its easier to detect the problem at the SIL level.

Fixes <rdar://problem/21995666>.

Swift SVN r30847
2015-07-31 04:46:35 +00:00
Slava Pestov
d1d5bcfb8c Small cleanups to overload-related code, NFC
ProtocolType::get() is weird...

Swift SVN r30846
2015-07-31 04:46:33 +00:00
John McCall
b75f5f2450 Type-check catch patterns in closures as necessary in order
to decide whether they're exhaustive.

Unfortunately, we can't actually just type-check the pattern
because it might be dependent on other local type-checking state,
like the types of arguments or variables defined within the closure.
So instead we try to recognize a very specific pattern shape that
should be safe to coerce.

Also, this potentially introduces redundant diagnostics because
of the double-check, but it's tricky to do anything about it.
I think it's better to have these potential redundancies than
to infer a throwing closure type with 'catch let e as NSError',
though.

rdar://21715350

Swift SVN r30701
2015-07-27 22:57:47 +00:00
Slava Pestov
65b317fa36 Sema: Fix infinite recursion when checking if class with circular inheritance has failable initializer
Fixes <rdar://problem/19919421>.

Swift SVN r30677
2015-07-27 00:40:45 +00:00
Chris Lattner
449e835941 this went with the former patch, bad cherrypick
Swift SVN r30657
2015-07-26 18:58:46 +00:00
Chris Lattner
622b6469fe rename a local variable, nfc
Swift SVN r30649
2015-07-26 05:18:23 +00:00
Chris Lattner
04cca603c8 Start peering through the fog of ClosureExprs, using ambiguously typed subexprs to
diagnose problems inside of them instead of punting on them completely.

This leads to substantially better error messages in many cases, fixing:
 <rdar://problem/19870975> Incorrect diagnostic for failed member lookups within closures passed as arguments ("(_) -> _")
 <rdar://problem/21883806> Bogus "'_' can only appear in a pattern or on the left side of an assignment" is back
 <rdar://problem/20712541> QoI: Int/UInt mismatch produces useless error inside a block

and possibly others.  We are not yet capitalizing on available type information we do
have about closure exprs, so there are some cases where we produce
  "error: type of expression is ambiguous without more context"
when this isn't strictly true, but this is still a huge step forward.



Swift SVN r30547
2015-07-23 20:31:43 +00:00
Doug Gregor
f00e5bc6ab Allow a variadic parameter anywhere in the parameter list.
Requiring a variadic parameter to come at the end of the parameter
list is an old restriction that makes no sense nowadays, and which we
had all thought we had already lifted. It made variadic parameters
unusable with trailing closures or defaulted arguments, and made our
new print() design unimplementable.

Remove this restriction, replacing it with a less onerous and slightly
less silly restriction that we not have more than one variadic
parameter in a given parameter clause. Fixes rdar://problem/20127197.

Swift SVN r30542
2015-07-23 18:45:29 +00:00
Joe Pamer
a900fd7bc2 Fix a couple of common crashers related to functions with default arguments. (rdar://problem/21799331 and rdar://problem/21643052, plus dupes.)
If a function declaration possessed default parameters, and was invoked with a single argument expression that was modeled as a type variable, the compiler would often crash during type application.  This was due to the fact that during simplification, we would bind the type variable to the full tuple type of the parameter list. Later on, during constraint application, we would then look to whatever expression created the type variable for information on its default arguments - even if no such thing was possible. (E.g., we would examine, say, an IfExpr expecting to find information on its default arguments.) In these cases, we should have instead been binding the argument type variable to the first element of the parameter tuple.

Swift SVN r30486
2015-07-22 01:19:08 +00:00
John McCall
50a667b295 Instead of assuming that the return type of a closure
with no returns *must* be (), add a defaulting constraint
so that it will be inferred as () in the absence of
other possibilities.

The chief benefit here is that it allows better QoI when
the user simply hasn't yet written the return statement.

Doing this does regress a corner case where an attempt
to recover from an uncalled function leads to the
type-checker inferring a result for a closure that
doesn't make any sense at all.

Swift SVN r30476
2015-07-22 00:13:02 +00:00
Chris Lattner
79838f6dbe fix a case in CSGen where it gets an ErrorType back and splats it onto the AST,
instead of treating it as an erroneous subexpr.  This was causing <<error type>> to pop
out in diagnostics, and had a hackaround that dissolves now from CSDiags.



Swift SVN r30442
2015-07-21 05:03:38 +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
Devin Coughlin
c1caddae62 Remove experimental support for treating unavailable symbols as optional.
This has always been off by default and is a language direction we have decided not to
pursue.

Swift SVN r30355
2015-07-18 01:56:25 +00:00
John McCall
a0ee7b2772 Don't look through 'try!' in getSemanticsProvidingExpr().
To support this, make 'try' and 'try!' no longer IdentityExprs
and give them a common base class to simplify the sorts of
analyses and transformations that do want to treat them
as identity-like.

Note that getSPE() still looks through normal 'try', since
the overwhelming proportion of clients will consider it
semantically equivalent to the undecorated expression.

Change getValueProvidingExpr() to look through try!, since
it's allowed to return something with slightly different
semantics, and use it in the unused-result diagnostic.

Fixes a large number of bugs, mostly uncaught, with SILGen
peepholes that use getSPE() and therefore were accidentally
looking through try!.  <rdar://21515402>

Swift SVN r30224
2015-07-15 19:34:18 +00:00
Joe Pamer
3edab3db8d When walking overload groups during constraint analysis, defend against function/decl type mismatches. (rdar://problem/20162476)
Swift SVN r30202
2015-07-14 22:58:54 +00:00
Chris Lattner
8637bb4c01 fix <rdar://problem/21679169> compiler crashes on "{(=_=_)in"
Swift SVN r29914
2015-07-06 04:46:56 +00:00
Slava Pestov
e7d8c3c4bc Sema: Fix synthesis of materializeForSet for subscripts in protocol extensions
Since each override of a subscript protocol requirement provides
its own materializeForSet, there is no need to do dynamic dispatch,
a peer call to the setter suffices. However, since CodeSynthesis
runs at the AST level, it would create a SubscriptExpr which
overload resolution would later bind to the protocol requirement
subscript rather than the static witness in the extension.

This triggered an assertion. Solve the problem by binding the
actual ConcreteDeclRef of the SubscriptExpr at synthesis time,
and modifying CSGen to special-case SubscriptExprs that already
have a ConcreteDeclRef set.

Fixes <rdar://problem/21370629>.

Swift SVN r29906
2015-07-03 02:25:26 +00:00