Commit Graph

2410 Commits

Author SHA1 Message Date
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
Doug Gregor
6ae3d5db47 Only force immediate closure of an open existential when we opened one.
Fixes rdar://problem/21597711.

Swift SVN r30190
2015-07-14 18:11:13 +00:00
Chris Lattner
9ae1ff707c Add a new DisableStructuralChecks option to typeCheckExpr which allows CSDiag to
avoid emitting this diagnostics.  They are always irritating to it because they
are duplicative with whatever the actual type constraint problem is.  It also
interferes with there recursive structure of the problem.

Disabling them also allows us to shorten the black list of expr nodes that cannot
be handled in typeCheckIndependentSubExpression.



Swift SVN r30122
2015-07-11 22:28:40 +00:00
Chris Lattner
3edd82837f remove the isDiscarded bool from TypeChecker::solveForExpression
and getTypeOfExpressionWithoutApplying and change typeCheckExpression
to take it as a single-entry OptionSet, in prep for getting other 
options.  NFC.


Swift SVN r30121
2015-07-11 22:06:45 +00:00
Slava Pestov
fd141bead9 Sema: Remove unused inExpression parameter from ASTContext::getBridgedToObjC(), NFC
Progress on <rdar://problem/21215099>.

Swift SVN r29968
2015-07-08 06:49:27 +00:00
Chris Lattner
5d3d653784 remove unused field.
Swift SVN r29938
2015-07-07 05:58:11 +00:00
Chris Lattner
acecd187a3 fix <rdar://problem/21553065> Spurious diagnostic: '_' can only appear in a pattern or on the left side of an assignment
... by reimplementing the DiscardAssignmentExpr checker in MiscDiagnostics 
instead of being in CSApply (which gets run on partial expression ASTs).

Also, when type checking and salvaging an expression fails, do not generate 
structural diagnostics in addition to the type checker diagnostics, they are 
just noise.



Swift SVN r29937
2015-07-07 05:52:17 +00:00
Slava Pestov
e598bfb21b Sema: Fix typos in comments, NFC
Swift SVN r29933
2015-07-07 04:41:49 +00:00
Chris Lattner
c619fd0fda fix <rdar://problem/21087089> Fixit for <RawOptionSetType>.allZeros
to improve swift 1 -> 2 migration.



Swift SVN r29903
2015-07-02 23:45:12 +00:00
Doug Gregor
d44651f366 Allow type witness resolution for unqualified lookups.
Fixes rdar://problem/21512599.

Swift SVN r29894
2015-07-02 18:29:13 +00:00
Chris Lattner
f04d2bb828 Implement <rdar://problem/20336036> QoI: Add cast-removing fixit for "Forced cast from 'T' to 'T' always succeeds"
Swift SVN r29876
2015-07-02 00:28:44 +00:00
Chris Lattner
2afc0dbaa9 Minor improvements:
- Remove a weird special case for literals from TypeChecker::typeCheckCondition.
 - Enhance FailureDiagnosis::getTypeOfIndependentSubExpression to know about situations
   where recursive type checks fail (in some nested situation) but still produce a type
   for the top level of the expr tree.
 - Remove dead code from CSApply now that you can't branch on Builtin.Int1.

The first & second combine to slightly improve one case I've been looking at in 
test/expr/expressions.swift.




Swift SVN r29860
2015-07-01 22:53:37 +00:00
Doug Gregor
b646af0ec2 Eliminate some unnecessary uses of getAllArchetypes(). NFC
Swift SVN r29843
2015-07-01 18:14:52 +00:00
Slava Pestov
ee07ddc2bf Sema: Fix crash calling protocol extension methods returning Self on existential
In r26737, Sema was changed to not wrap Self occurring in a protocol
extension in a DynamicSelf. The commit message was rather terse but
I believe this is because the metadata for Self is bound to the static
base type, not the runtime base type.

However, we still need to substitute Self in the return type for the
static base type in the case where the base is an existential,
otherwise we get an open existential type leaking out.

Also remove the default argument for replaceCovariantResultType(),
every call site passed in a value and it seems bad to omit it on
accident.

Fixes <rdar://problem/21433694>.

Swift SVN r29802
2015-06-30 05:36:00 +00:00