Commit Graph

1092 Commits

Author SHA1 Message Date
Chris Lattner
c988712e7b don't abort on this failure mode, even though nothing in the testsuite provokes it.
Swift SVN r30845
2015-07-31 04:45:33 +00:00
Chris Lattner
5a2577a1b5 improve the diagnostic for invoking a method on an exsitential that is not allowed,
fixing <rdar://problem/22020088> QoI: missing member diagnostic on optional gives worse error message than existential/bound generic/etc



Swift SVN r30844
2015-07-31 04:45:01 +00:00
Chris Lattner
7851d348a8 merge the ErrorDoesNotHaveInitOnInstance complexity into the normal
"member not found" diagnostic machinery.


Swift SVN r30842
2015-07-31 04:23:07 +00:00
Chris Lattner
b53f38010d refactor/localize some constraint ivars into local variables, NFC.
Swift SVN r30826
2015-07-31 00:08:24 +00:00
Chris Lattner
50be7e4ecf reapply r30789, r30795, r30796, r30797, without r30787 which causes a compile time hit:
- Produce more specific diagnostics relating to different kinds of invalid
 - add a testcase, nfc
 - Reimplement FailureDiagnosis::diagnoseGeneralMemberFailure in terms of

Not including r30787 means that we still generate bogus diagnostics like:
[1, 2, 3].doesntExist(0)  // expected-error {{type 'Int2048' does not conform to protocol 'IntegerLiteralConvertible'}}

But it is an existing and separable problem from the issues addressed here.



Swift SVN r30819
2015-07-30 23:31:56 +00:00
Ben Langmuir
c1a2955ef6 Revert r30787, r30789, r30795, r30796, r30797
r30787 causes our tests to time out; the other commits depend on r30787.

Revert "revert part of my previous patch."
Revert "Produce more specific diagnostics relating to different kinds of invalid"
Revert "add a testcase, nfc"
Revert "- Reimplement FailureDiagnosis::diagnoseGeneralMemberFailure in terms of"
Revert "Fix places in the constraint solver where it would give up once a single "

Swift SVN r30805
2015-07-30 17:44:22 +00:00
Chris Lattner
98a445384a Produce more specific diagnostics relating to different kinds of invalid
member references:

- Use of instance members from types
- Use of type members from instances
- Use of mutating getters.

This surely resolves some radars, but I'll have to dig them out later.


Swift SVN r30796
2015-07-30 06:26:43 +00:00
Chris Lattner
fe04ebfd2f - Reimplement FailureDiagnosis::diagnoseGeneralMemberFailure in terms of
performMemberLookup, eliminating a ton of duplicated logic, but keeping the
  same general behavior.

- Now that r30787 landed, we can have diagnoseGeneralMemberFailure inform
  clients when a member lookup fails due to referencing a candidate decl of
  ErrorType (i.e, it is already invalid somehow).  When this happens, there is
  no reason to diagnose a problem, because the original issue has been diagnosed
  and anything we produce now is just garbage.

The second point cleans up a bunch of bogus diagnostics in the testsuite, which are
*actually* due to upstream error that are already diagnosed.



Swift SVN r30789
2015-07-30 05:28:16 +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
7215709b8d use llvm_unreachable.
Swift SVN r30736
2015-07-28 23:59:45 +00:00
Chris Lattner
d31911e36d fix <rdar://problem/21974772> SegFault in FailureDiagnosis::visitInOutExpr
Swift SVN r30733
2015-07-28 23:45:57 +00:00
Dave Abrahams
1f39e3c411 Fix bad warning suppression
sorry about that last commit.

Swift SVN r30730
2015-07-28 22:47:29 +00:00
Dave Abrahams
87b1e35a9b Clean up fallthrough warnings
Swift SVN r30729
2015-07-28 22:43:57 +00:00
Chris Lattner
b7221889f7 update a test I failed to update, and add a hack to avoid a regressing a validation test.
Swift SVN r30716
2015-07-28 15:36:31 +00:00
Chris Lattner
ede0c50856 Revamp how value & type member constraint failures are diagnosed, eliminating the
"unavoidable failure" path, along with Failure::DoesNotHaveNonMutatingMember and
just doing some basic disambiguation in CSDiags.

This provides some benefits:
 - Allows us to plug in much more specific diagnostics for the existing "only has 
   mutating members" diagnostic, including producing notes for why the base expr
   isn't mutable (see e.g. test/Sema/immutability.swift diffs).
 - Corrects issues where we'd drop full decl name info for selector references.
 - Wordsmiths diagnostics to not complain about "values of type Foo.Type" instead 
   complaining about "type Foo"
 - Where before we would diagnose all failures with "has no member named", we now
   distinguish between when there is no member, and when you can't use it.  When you
   can't use it, you get a vauge "cannot use it" diagnostic, but...
 - This provides an infrastructure for diagnosing other kinds of problems (e.g. 
   trying to use a private member or a static member from an instance).
 - Improves a number of cases where failed type member constraints would produce uglier
   diagnostics than a different constraint failure would.
 - Resolves a number of rdars, e.g. (and probably others):
   <rdar://problem/20294245> QoI: Error message mentions value rather than key for subscript



Swift SVN r30715
2015-07-28 07:04:22 +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
f360dec256 refactor CSDiag a bit to prepare clients of typeCheckChildIndependently
to be able to provide a contextual purpose.


Swift SVN r30670
2015-07-26 23:14:03 +00:00
Chris Lattner
8c3e62d7c5 Provide contextually sensitive conversion failure messages for situations in
which we have a contextual type that was the failure reason.  These are a bit
longer but also more explicit than the previous diagnostics.



Swift SVN r30669
2015-07-26 23:06:40 +00:00
Chris Lattner
66683f94f9 Eliminate the "IsReturnExpr" bit from the AST - it was a poorly maintained
version of the new CTP_ReturnStmt conversion, used to generate return-specific 
diagnostics.  Now that we have a general solution, we can just use that.

This improves diagnostics in returns for accessors, since they were apparently
not getting the bit set.


Swift SVN r30665
2015-07-26 22:05:40 +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
ad501d6da4 move ExistentialEraser (awesome name btw, I do not read it as an eraser of
existentials :-) into CSDiags, its only client.  Make the class private as
well.  NFC.


Swift SVN r30660
2015-07-26 20:53: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
467cd07968 Two changes:
- Improve handling of if_expr in a couple of ways: teach constraint simplification
   about IfThen/IfElse and teach CSDiags about the case when the cond expr doesn't match
   BooleanType.  This is rarely necessary, but CSDiags is all about cornercases, and this
   does fix a problem in a testcase.
 - Be a bit more specific about the constraint failure kind (e.g. say subtype) and when
   we have a protocol conformance failure, emit a specific diagnostic about it, instead of
   just saying that the types aren't convertible.




Swift SVN r30650
2015-07-26 05:31:12 +00:00
Chris Lattner
d91f5861d2 Change diagnoseFailure() for unavoidable failures to stop doing anything with
conversion failures, making a bunch of diagnostics more specific and useful.

UnavoidableFailures can be very helpful, but they can also be the first constraint
failure that the system happened to come across... which is not always the most
meaningful one.  CSDiag's expr processing machinery has a generally better way of
narrowing down which ones make the most sense.


Swift SVN r30647
2015-07-26 04:09:34 +00:00
Chris Lattner
0a3197390f Various changes:
- Don't "aka" a Builtin.Int2123 type, it just makes a bad diagnostic worse.
 - Split out the predicate that CSDiag uses to determine what a conversion
   constraint is to a helper fn, and add subtype constraints to the mix.
 - Move eraseTypeData into CSDiag (its own client) as a static function.
 - Make eraseTypeData be a bit more careful about literals, in an attempt to
   improve diagnostics when literals get re-type-checked.  It turns out that
   this still isn't enough as shown by the regression on the 
   decl/func/default-values.swift testcase, and the 
   Constraints/dictionary_literal.swift testcase where one bad diagnostic turns
   into another different one, but I'll keep working on it.
 - Beef up diagnoseContextualConversionError and the caller to it to be more
   self contained and principled about the conversion constraints it digs out
   of the system.  This improves the diagnostics on a couple of cases.



Swift SVN r30642
2015-07-26 00:29:40 +00:00
Chris Lattner
31e91a09d9 consolidate a duplicate diagnostic id into an existing one, and convert some
code to use a standardized approach to emitting "no arguments" call issues.


Swift SVN r30640
2015-07-25 21:38:48 +00:00
Chris Lattner
2b90306f87 remove ConversionTypes from ConstraintSystem and simplify code now that noone uses it.
Swift SVN r30637
2015-07-25 20:27:38 +00:00
Chris Lattner
b0449d5c65 Change typeCheckCondition and solveForExpression to stop using
setConversionType along with the constraints they install.  The constraints
should be enough by themselves, and CSDiags shouldn't need them to
bias the solution.

Of course, the constraints weren't enough, so improve CSDiags so that it can
do the right thing without them.



Swift SVN r30636
2015-07-25 20:25:09 +00:00
Chris Lattner
72e3c30c48 Change getBoundTypesFromConstraint to use simplifyLocatorToAnchor which is
more correct and general than "getDiagnosticTypeFromExpr".  Eliminate the
old function.


Swift SVN r30629
2015-07-25 16:45:51 +00:00
Chris Lattner
94bf2beb4c Add the ability for clients of typeCheckChildIndependently to specify a contextual type.
Swift SVN r30614
2015-07-25 01:25:42 +00:00
Chris Lattner
5fae58c67f remove getUserFriendlyTypeName.
Swift SVN r30613
2015-07-25 01:18:37 +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
1a61bab17c with recent changes, we can significantly simplify getUserFriendlyTypeName...
before eliminating it completely.


Swift SVN r30606
2015-07-25 00:24:50 +00:00
Chris Lattner
4e69aebbbd Introduce a new TCC_AllowLValue bit to inform
typeCheckArgumentChildIndependently when we want an lvalue back, 
instead of it always producing an lvalue.  Provide it in a couple of
places, the most interesting of which is when forming a call to an 
operator where an InOutExpr is implicitly provided by the fact that
the operator is an 'assignment' operator (something we don't actually
model right in the language at the moment for unary operators).

Producing this uses the candidate list we get from analyzing the
function, which makes this the first example of using the callee to
provide type information when analyzing an argument subexpression.

All this work for NFC. :-)


Swift SVN r30600
2015-07-24 23:17:57 +00:00
Chris Lattner
e78bc00f43 split the collection and filtering of the CalleeCandidateInfo list into
two parts, allowing the collection of the candidate list to be done before
the argument expression is type checked.  NFC.


Swift SVN r30599
2015-07-24 23:02:29 +00:00
Chris Lattner
87442c6f5d remove dead code, nfc
Swift SVN r30595
2015-07-24 22:36:44 +00:00
Chris Lattner
cecf90469b generalize a bool into an option set, NFC.
Swift SVN r30590
2015-07-24 20:44:37 +00:00
Chris Lattner
629a35215f reapply r30570, now that Sema preserves type sugar more correctly:
type check the subexpressions of a callexpr more consistently, 
always checking the arguments independently (not just if one argument 
is inout). This routes around issues handling tuples, and brings more
consistency to the experience. Factor this logic out and use it for
operators and subscripts as well.



Swift SVN r30583
2015-07-24 18:21:48 +00:00
Ted Kremenek
f880276750 Revert "type check the subexpressions of a callexpr more consistently, always checking the arguments independently (not just if one argument is inout). This routes around issues handling tuples, and brings more consistency to the experience. Factor this logic out and use it for operators and subscripts as well."
This reverts commit r30570.

This was causing 'Swift :: stdlib/FixedPointDiagnostics.swift.gyb' to fail.

Swift SVN r30571
2015-07-24 07:48:39 +00:00
Chris Lattner
e28c907e86 type check the subexpressions of a callexpr more consistently, always checking the arguments
independently (not just if one argument is inout).  This routes around issues handling tuples,
and brings more consistency to the experience.  Factor this logic out and use it for operators 
and subscripts as well.

This improves a small collection of diagnostics, including the infamous:

   // Infer incompatible type.
-  func6(fn: {a,b->Float in 4.0 })    // expected-error {{cannot convert return expression of type 'Double' to expected return type 'Float'}}
+  func6(fn: {a,b->Float in 4.0 })    // expected-error {{cannot invoke 'func6' with an argument list of type '(fn: (_, _) -> Float)'}}
+  // expected-note @-1 {{expected an argument list of type '(fn: (Int, Int) -> Int)'}}




Swift SVN r30570
2015-07-24 06:14:27 +00:00
Chris Lattner
b947f60659 merge 4 diagnostics into 2 by changing the diagnostic to take a bool.
In a CallExpr, evaluate the function subexpr before the argument subexpr,
in prep for being able to use this type info to propagate them onto the
arguments when available.  NFC.



Swift SVN r30567
2015-07-24 05:28:23 +00:00
Chris Lattner
39adf6dbd3 fix unused variable warning introduced by my last patch
Swift SVN r30565
2015-07-24 05:02:17 +00:00
Chris Lattner
ef553f47cf fix a FIXME by having diagnoseGeneralOverloadFailure() re-typecheck the
argument of a failed call with typeCheckArbitrarySubExprIndependently,
which exposed some cases where ErrorType from outer solutions would be
left around on ParamDecls in ClosureExprs.  Fix this all, which has NFC
on the testsuite.


Swift SVN r30563
2015-07-24 05:00:18 +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
Chris Lattner
dff93b512b Now that we have the notion of an uncurry level, we can do a lot more
detailed analysis of callees, which give us overload sets in more cases,
producing notes more consistently, and producing much better diagnostics
for the curried cases in test/Constraints/diagnostics.swift.

This also allows us to eliminate getCalleeName, which simplifies things
in CSDiags.


Swift SVN r30491
2015-07-22 05:37:39 +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
a32947cbb2 Introduce the notion of an uncurry level to CalleeCandidateInfo to start
rationalizing how it handles members and curried functions, also paving
the way for future improvements.  This implements the infrastructure but
keeps the functionality the same (the only functionality change is that
it works a bit better with vardecls of function type).



Swift SVN r30464
2015-07-21 21:59:47 +00:00
Chris Lattner
a5e2a158cd refactor closeness computation to share code between SubscriptExprs and everything else. NFC
Swift SVN r30452
2015-07-21 18:00:36 +00:00
Chris Lattner
c16d2f7f94 refactor the code for collecting callee candidate lists and reporting available
overload sets out to a new CalleeCandidateInfo class in prep for other changes.  
NFC.


Swift SVN r30445
2015-07-21 06:03:17 +00:00
Chris Lattner
86439e9c4e Improve some diagnostics around invalid calls to ClosureExprs and random values of function type,
fixing:
<rdar://problem/20789423> Unclear diagnostic for multi-statement closure with no return type
<rdar://problem/21829141> BOGUS: unexpected trailing closure
<rdar://problem/21784170> Incongruous `unexpected trailing closure` error in `init` function which is cast and called without trailing closure.



Swift SVN r30443
2015-07-21 05:34:36 +00:00