Commit Graph

673 Commits

Author SHA1 Message Date
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
Chris Lattner
3a03435a1e Now that we have various infrastructure improvements in place, we can
remove some unprincipled code from typeCheckChildIndependently that was
special casing some expr nodes.


Swift SVN r31407
2015-08-22 06:06:14 +00:00
Chris Lattner
b660cb3c8e Enhance the general parameter list matching logic in CSDiags to know about
argument list mismatches, and diagnose them with a very specific error when
they occur in member lookups.  This fixes
<rdar://problem/22356434> QoI: Missing diagnostic for invalid arguments passed to enum case constructor

where before we'd produce:

ee.swift:5:16: error: type of expression is ambiguous without more context
let list: E = .C(wrongLabel: 0)
              ~^~~~~~~~~~~~~~~~

now we produce:

ee.swift:1:17: error: incorrect argument label in call (have 'wrongLabel:', expected 'label:')
let list: E = .C(wrongLabel: 0)
                ^~~~~~~~~~~
                 label

I think that unresolved member exprs now get good diagnostics in all cases that they have
a contextual type, but of course there are lots more cases where we're not getting a 
contextual type.



Swift SVN r31402
2015-08-22 04:46:49 +00:00
Slava Pestov
e416bfbc4e SILGen: Refactor code for existentials
We need to be able to introduce and eliminate existentials inside
reabstraction thunks, so make this logic independent of RValue
and Expr emission.

NFC for now.

Swift SVN r31375
2015-08-21 02:26:57 +00:00
Slava Pestov
54aca7e322 AST: OpaqueValue::isUniquelyReferenced() is always true, NFC
Swift SVN r31366
2015-08-20 21:19:33 +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
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
0c288e0829 introduce a new UnresolvedTypeConversionExpr implicit conversion node for
conversions to and from UnresolvedType.  This will allow UnresolvedType to be
used more aggressively and predictably by CSDiags.  This is NFC, but used in
the next patch.


Swift SVN r31318
2015-08-18 23:41:11 +00:00
Chris Lattner
eb0131f927 refactor all of the constraint system "Fix" processing logic out of
ConstraintSystem::applySolution into its own helper function to reduce
indentation and make ConstraintSystem::applySolution much more simple
and obvious.  NFC.


Swift SVN r31290
2015-08-18 04:47:34 +00:00
Chris Lattner
1ad24fdfc2 rework how 'as' casts are diagnosed, removing a special case from CSApply and
allowing these failures to hook into other diagnostic goodies (e.g. the
"did you mean to use '!' or '?'?" cases showing in the testsuite).  That said,
by itself this doesn't have a huge impact, but avoids regressions with other
pending changes.


Swift SVN r31289
2015-08-18 04:35:41 +00:00
Chris Lattner
aaff09e76b When CSApply applies as Builtin type to a literal, use shallowClone to allocate a new
node, abandoning the old node.  This cuts of places where we'd end up retypechecking
the original expr and getting things like Builtin.Int2048 into the diagnostic.

This is NFC, because there is some crufty stuff avoiding this sitation in CSDiags that
needs to be removed for other reasons, this simply unblocks that.

I have a more aggressive approach in mind to actually fix how we model literals, but 
that isn't on my short-term todo list.



Swift SVN r31270
2015-08-17 18:08:23 +00:00
Slava Pestov
e5cb73fe41 SILGen: Clean up ErasureExpr lowering, NFC
This is a step towards partially-applying methods that return Self
on existentials.

- We model opening of both existential values and metatypes with
  OpenExistentialExpr, but erasure had two forms, ErasureExpr and
  MetatypeErasureExpr. Combine them into one, since both Sema and
  SILGen have similar code paths for each.

- If the source type of an ErasureExpr is a closed existential,
  have Sema emit an OpenExistentialExpr, and remove SILGen's
  openExistentialForErasure() path, which mostly duplicates
  openExistentialImpl().

- There was one difference between openExistentialForErasure() and
  openExistentialImpl(). The former would emit the opaque value in
  +0 context, and the latter in a +1 with initialization. The
  previous patch ensures that visitOpaqueValueExpr() generates
  equivalent code in both cases.

Swift SVN r31261
2015-08-16 16:45:48 +00:00
Chris Lattner
42d53dc414 Fix:
<rdar://problem/18397777> QoI: special case comparisons with nil
<rdar://problem/18042123> QoI: Fixit for "if !optional" should suggest "if optional == nil"



Swift SVN r31204
2015-08-13 04:36:43 +00:00
Jordan Rose
77d8a079af Special-case trying to force a 'try?' expression.
...both in the message and in the fix-it, which offers to change it to
'try!'.

More rdar://problem/22259867.

Swift SVN r31201
2015-08-13 03:08:18 +00:00
Jordan Rose
a690885f5c Properly parenthesize 'try?' in fix-its.
It's not /really/ an infix operator, but it behaves like a very low
precedence prefix operator. On the other hand, 'try' and 'try!' can
freely move in and out of all the operations we add in fix-its, so
don't bother.

rdar://problem/22259867

Swift SVN r31200
2015-08-13 03:08:17 +00:00
Jordan Rose
a26716290c When adding " != nil" to an optional in an 'if', we may need parens.
...such as with 'try?'.

rdar://problem/22259712

Swift SVN r31199
2015-08-13 03:08:15 +00:00
Joe Pamer
10afd159e4 Following up on r31169, take Jordan's CR feedback and uncomment the two currently disabled migration aid overloads for 'print'.
Swift SVN r31176
2015-08-12 18:10:35 +00:00
Joe Pamer
cd492d96b5 Fix a type checker crash when the object type of a ForceValueExpr is an 'Any'.
This allows us to remove the workaround generic overloads for "print" without sacrificing good diagnostics for its unavailable overloads. (rdar://problem/21499048, rdar://problem/21582758, rdar://problem/22126141)

Swift SVN r31169
2015-08-12 15:59:31 +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
5237e5f279 adjust two places to deal with the ParamDecls in closureexprs that have
no type set on them.  This is the minimal fix to address the regressions
on two validation tests, but another approach (not involving null types)
seems like it would be a good idea to investigate on mainline.


Swift SVN r31099
2015-08-08 20:26:57 +00:00
Jordan Rose
1abfc745f5 Update comment in coerceClosureExprToVoid. NFC.
Swift SVN r31093
2015-08-08 00:27:57 +00:00
Jordan Rose
410083dfc9 Warn on unused results in single-expression closures coerced to Void.
...just like an unused result anywhere else.

Swift SVN r31091
2015-08-08 00:23:05 +00:00
Jordan Rose
74c634524e Pull 'try' et al inside RebindSelfInConstructorExprs.
And give a proper warning when you use 'try?' in a non-failable init.

And do the right thing when trying to SILGen 'try?' delegating to a
failable throwing init.

And make sure DI understands that this is, in fact, an initialization.

More rdar://problem/21692467

Swift SVN r31060
2015-08-06 21:02:43 +00:00
Jordan Rose
6b12b9130e Disallow nesting 'self.init' or 'super.init' inside other expressions.
In addition to being confusing, it makes it harder to implement
'try? self.init(...)' properly. (Next commit!)

Swift SVN r31034
2015-08-05 22:17:41 +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
Chris Willmore
3485a97cd4 Diagnose ambiguous initializer resolution.
Fix construction and simplication of constructor member locators, so
that locators involving constructor members can be simplified during
diagnosis.

<rdar://problem/21427130> Swift can't discriminate on arity of function parameters

Swift SVN r30932
2015-08-02 12:12:19 +00:00
Joe Groff
78491237e2 Sema: Base whether the base of a property lookup needs to be 'inout' on whether any of its accessors is mutating.
Instead of relying on the reference semantics of the base to make this decision, look at the getter and setter to see if either is mutating to decide whether the base of a property lookup should be inout. This should be the final fix for rdar://problem/21578832.

Swift SVN r30887
2015-07-31 22:38:54 +00:00
Slava Pestov
20ff9df27f Sema: More robust in the face of missing stdlib protocols
This came up with SourceKit fuzz testing on the stdlib. I don't have a
reduced testcase right now.

Progress on <rdar://problem/19554069>.

Swift SVN r30882
2015-07-31 21:22:51 +00:00
Jordan Rose
3524fdaccd Fix placement of '!' in fix-it for chaining to a failable initializer.
Swift SVN r30858
2015-07-31 18:41:06 +00:00
Chris Lattner
f2746eaf7b Add inout expr validation to the SyntacticUseRestrictions checker
in MiscDiagnostics, allowing us to correctly and consistently reject 
InOutExprs that do not appear in argument contexts.


Swift SVN r30746
2015-07-29 01:02:46 +00:00
Chris Lattner
794f9d9b74 fix <rdar://problem/18496742> Passing ternary operator expression as inout crashes Swift compiler
and some related crashers.



Swift SVN r30734
2015-07-28 23:52:12 +00:00
Chris Lattner
922a7f53b3 consolidate the diagnostics produced by the "Failure" case and the expr walker in CSDiags to
get the same wording, fixing <rdar://problem/21964599> Different diagnostics for the same issue

While I'm in the area, remove some dead code.



Swift SVN r30713
2015-07-28 04:43:37 +00:00
Chris Lattner
aa68b5adf7 add a 'purpose' for convertType in typeCheckExpression which will allow us
to produce more specific and helpful diagnostics.  NFC since it isn't 
used yet.


Swift SVN r30664
2015-07-26 21:48:50 +00:00
Chris Lattner
4cba61fbb0 Refactor things a bit, NFC:
typeCheckExpression takes a convertType and a contextualType, but the only
client of contextualType is pattern binding initialization that wants to
provide a hint to the initializer, but the type may not be fully formed
(e.g. just Array instead of Array<Int>) so it can't provide a full 
convertType to that type.

After trying various ways of eliminating the concept and failing, repaint it
instead:  instead of typeCheckExpression taking *both* a convertType and a
contextualType (even though they are mutually exclusive), have it only take
a single convertType and add a bit to TypeCheckExprOptions to indicate whether
it is a hint or a strong conversion.  This simplifies all the callers of
typeCheckExpression and makes further evolution simpler.



Swift SVN r30658
2015-07-26 20:38:57 +00:00
Chris Lattner
622ea5e2f6 wind down most of CSDiag's uses of getUserFriendlyTypeName to pass the Type
directly into the diagnostics subsystem.  This ensures a more consistent 
treatment of type printing (e.g. catches a case where a diagnostic didn't 
single quote the type) and gives these diagnostics access to "aka".


Swift SVN r30609
2015-07-25 00:54:05 +00:00
Chris Lattner
6a27182712 two unrelated changes:
- Have DiagnosticEngine produce "aka" annotations for sugared types.
 - Fix the "optional type '@lvalue C?' cannot be used as a boolean; test for '!= nil' instead"
   diagnostic to stop printing @lvalue noise.

This addresses:
<rdar://problem/19036351> QoI: Print minimally-desugared 'aka' types like Clang does



Swift SVN r30587
2015-07-24 20:22:20 +00:00
Joe Pamer
2d86296827 When converting a closure's function type to a non-escaping function type, only propagate the 'throws' ExtInfo bit if necessary. (rdar://problem/21881995)
Swift SVN r30556
2015-07-23 23:35:42 +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
Chris Lattner
0001dc27bb remove support for the experiemental "character literals" feature.
Swift SVN r30509
2015-07-22 22:35:19 +00:00
Chris Lattner
9fd3f3bf23 Reimplement checking for incorrect partial applications in MiscDiagnostics (instead of
CSApply).  The code is somewhat simpler there, more correct (fixing the FIXME in the 
testcase) and doesn't run afoul of CSDiags trying to type check partial AST 
subexpressions.


Swift SVN r30425
2015-07-21 00:50:05 +00:00
Chris Lattner
ab487a17b5 Introduce a new TypeCheckExprFlags::AllowUnresolvedTypeVariables option,
which allows solving of a constraint system to succeed without emitting
errors in the face of ambiguous solutions.  This is important for CSDiag
because it is in the business of trying to solve subexpressions of a global
expression - and it wants to know the difference between a subexpression
that is inherently impossible to solve, vs one that is simply ambiguous
because its context has been removed.

Use this in CSDiag's typeCheckChildIndependently() to provide it an
extra flag that enables this behavior.  This is currently unused, so NFC 
with this patch.


Swift SVN r30402
2015-07-20 16:16:54 +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
Slava Pestov
edcd279d75 Sema: Fix infinite loop in lookThroughIdentityExprs()
This regression was introduced in r30224.

Fixes <rdar://problem/21875219>.

Swift SVN r30336
2015-07-17 22:27:34 +00:00
Doug Gregor
fdf5c64bd7 Force implicit unwrapping in self.init/super.init within the AST
... rather than having SILGen do it. This is NFC, but feels more correct.

Swift SVN r30276
2015-07-16 22:21:55 +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
Doug Gregor
90e5fbad47 Start allowing self.init/super.init calls to be forced with '!'.
Adjust our placement of RebindSelfInConstructorExpr to fall outside of
a force-value expression (!), allowing, e.g.,

  self.init(somethingThatCanFail: x)!

and

  super.init(somehtingThatCanFail: x)!

Start suggesting '!' when chaining/delegating to a failable
initializer from a non-failable one, in addition to suggesting that
the enclosing initializer become failable.

Note that DI cannot handle this yet, so this is only the Sema part of
rdar://problem/18497407.

Swift SVN r30219
2015-07-15 17:35:11 +00:00