Commit Graph

1177 Commits

Author SHA1 Message Date
Chris Lattner
45a88b0aca Now that the top level "diagnoseConstraintFailure" engine can handle multiple
constraints of each kind, enhance FailureDiagnosis::diagnoseGeneralConversionFailure to 
ignore conversion constraints that are either trivially resolvable (like Int conforming
to IntegerLiteralConvertible) or constraints that cannot be resolved because a type 
variable is ambiguous.

This eliminates the last (known to me at least!) source of diagnostics that end up
complaining about obviously incorrect issues.


Swift SVN r31065
2015-08-07 04:18:11 +00:00
Dave Abrahams
493ae5294f Kill some dead code
Swift SVN r31056
2015-08-06 20:04:17 +00:00
Chris Lattner
8c88ebc535 now that we have a simpler structure for the overal CSDiag algorithm, change
diagnoseGeneralFailure to be named diagnoseConstraintFailure and change how
it works:
Now it ranks unresolved constraints  in the system based on kind (e.g. whether
they are favored, member constraints ahead of conversion constraints, etc) and
then tries to emit a diagnostic for each failure kind one after another.

This means that if there are multiple failed conversion constraints, but one
is obviously satisfiable, that we continue on to diagnose the next one.  This 
clears up a swath of embarassing diagnostics and refixes:
<rdar://problem/19658691> QoI: Incorrect diagnostic for calling nonexistent members on literals



Swift SVN r31046
2015-08-06 05:55:28 +00:00
Chris Lattner
1fe2883fe8 another NFC refactoring: CSDiags is now split into 3 really separate
pieces: Failure diagnosis (which should shrink over time), Expr diagnosis
(which should grow over time), and constraint diagnosis (which should shrink
over time but be the ultimate backstop).  This sets up the layers so that
all but the last can "return false" with impunity if they have no bright
ideas based on the context they know about.  


Swift SVN r31043
2015-08-06 04:57:10 +00:00
Chris Lattner
daa24e507d now that the computation of conversion constraints is detangled, we can localize
the FailureDiagnosis::conversionConstraint state to be a local variable in
diagnoseGeneralConversionFailure(), unblocking other progress. NFC.



Swift SVN r31042
2015-08-06 04:40:17 +00:00
Chris Lattner
072868d3f6 Simplify the implementation of visitCoerceExpr/visitForcedCheckedCastExpr,
and diagnoseGeneralConversionFailure().  The previous approach of trying
to dig into anchors would often lead to complaining about types at 
different levels in the same diagnostic, and the complexity of the former
code isn't needed now that other changes have landed.



Swift SVN r31036
2015-08-06 00:58:55 +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
Chris Lattner
b0410ffc3b Remove dead code left around in previous commit.
Swift SVN r31029
2015-08-05 21:51:14 +00:00
Chris Lattner
7bfe2eb07d Pull the diagnostics for noescape and throws function type violations onto the
expr infrastructure, resolving rdar://22158167.


Swift SVN r31028
2015-08-05 21:45:10 +00:00
Chris Lattner
4a5be366c2 add a new ContinueAfterFailures default argument to ConstraintSystem::simplify,
and use it in the diagnostics path (only!) to revisit active constraints that
are left in the system after a failure is found.  This improves a number of 
otherwise sad diagnostics in the testsuite and resolves rdar://22083115.

The one QoI regression (in throwing_functions.swift) is now tracked by 22158167.



Swift SVN r31027
2015-08-05 20:57:39 +00:00
Chris Lattner
df60eccbf5 unbreak compiler_crashers_fixed/26558-swift-constraints-constraintsystem-gettypeofmemberreference.swift,
I'll reduce a testcase later.


Swift SVN r31020
2015-08-05 00:57:19 +00:00
Chris Lattner
8ef04bd42e Make callee analysis of UnresolvedDotExpr more specific by looking for candidates
have have been directly resolved.  This has very little impact on the testsuite
right now, but unblocks other progress.



Swift SVN r31019
2015-08-05 00:24:32 +00:00
Chris Lattner
33d44ea915 Rework diagnoseGeneralOverloadFailure a bit, making it more self contained
and to handle disjunction constraints by printing an overload set.


Swift SVN r31018
2015-08-04 23:35:08 +00:00
Chris Lattner
b6fbccc1c1 Fix <rdar://problem/21544303> QoI: "Unexpected trailing closure" should have a fixit to insert a 'do' statement
which is gratuitous QoI, but also something that people reasonably hit when used to C programming.



Swift SVN r30986
2015-08-04 06:01:21 +00:00
Chris Lattner
7a73392087 improve diagnostics relating to closure result types, both when they are
explicitly written and disagree with context, and when context provides a
non-explicitly written type that disagrees with the body of the closure.



Swift SVN r30984
2015-08-04 05:41:04 +00:00
Chris Lattner
748845aa4d Now that we have contextual type information more generally available, start
using it to improve closure diagnostics by inferring the types of otherwise
untyped closure paramdecls from this context information.  This 
resolves:

<rdar://problem/20371273> Type errors inside anonymous functions don't provide enough information
producing 
  error: binary operator '==' cannot be applied to operands of type 'Int' and 'UInt'
  note: overloads for '==' exist with these partially matching parameter lists: (UInt, UInt), (Int, Int)

and:
<rdar://problem/20978044> QoI: Poor diagnostic when using an incorrect tuple element in a closure
producing:
error: value of tuple type '(Int, Int)' has no member '2'

and probably a lot more.  We're still limited from getting things like "foo.map {...}" because 
we're not doing type subsitutions from the base into the protocol extension member.



Swift SVN r30971
2015-08-04 00:55:06 +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 Lattner
6d3a1cc6fc improve a diagnostic, resolving a fixme.
Swift SVN r30951
2015-08-03 18:37:03 +00:00
Chris Lattner
23e942f122 Reimplement the "multi-statement closures require an explicit return type"
as a proper error, and change it to not be incorrect.  Multi-statement
closures *only* need a return type if they cannot be inferred.

This fixes:
<rdar://problem/22086634> "multi-statement closures require an explicit return type" should be an error not a note


Swift SVN r30937
2015-08-02 21:30:51 +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
Chris Willmore
0c9de6edef Diagnose ambiguous overload resolution correctly in more cases.
Take expression depth and preorder traversal index into account when
deciding which unresolved overload to complain about, rather than giving
up if there are two exprs with the same number of overloads. Don't
consider solutions with fixes when emitting ambiguous-system
diagnostics.

Swift SVN r30931
2015-08-02 11:38:12 +00:00
Chris Lattner
bd03e48090 teach typeCheckArgumentChildIndependently how to propagate type information
down to call argument lists that have more than one operand (heavily leveraging
"computeTupleShuffle").  This resolves a great number of QoI radars, including
things like:
<rdar://problem/19981782> QoI: poor diagnostic for call to memcmp with UInt length parameter

where we used to produce:

error: cannot invoke 'memcmp' with an argument list of type '([UInt8], [UInt8], UInt)'
    return memcmp(left, right, UInt(left.count)) == 0
           ^
note: expected an argument list of type '(UnsafePointer<Void>, UnsafePointer<Void>, Int)'

but now we produce:
error: cannot convert value of type 'UInt' to expected argument type 'Int'
    return memcmp(left, right, UInt(left.count)) == 0
                               ^~~~~~~~~~~~~~~~

which is more "to the point"



Swift SVN r30930
2015-08-02 05:51:26 +00:00
Chris Lattner
9e7f602198 Handle diagnosing unbound archetypes in the outer level ambiguity diagnostics
machinery, instead of in multiple places in CSSolver and CSDiags.  This leads
to more predictable behavior (e.g. by removing the UnboundGenericParameter
failure kind) and eliminates a class of "'_' is not convertible to 'FooType'"
diagnostics.



Swift SVN r30923
2015-08-01 22:16:56 +00:00
Chris Lattner
9d9b8aaf35 move protocol conformance errors away from being diagnosed as a Failure, instead
putting it into the expr diagnostics path, allowing more contextual messages.


Swift SVN r30920
2015-08-01 18:31:59 +00:00
Chris Lattner
f02a16f517 refactor diagnoseFailureForExpr and the code surrounding it to make it
clear that it *always* produces a diagnostic.  NFC.


Swift SVN r30919
2015-08-01 17:46:20 +00:00
Chris Lattner
bdaf954982 when recursively type checking an expression with its contextual type and
other constraints intentionally ripped off, tell the recursive solution that
we can tolerate an ambiguous result.  The point of this walk is not to
produce a concrete type for the subexpression, it is to expose any structural
errors within that subsystem that don't depend on the contextual constraints.


Swift SVN r30917
2015-08-01 17:31:49 +00:00
Chris Lattner
54c752183f when diagnosing an invalid conversion between two function types, strip off irrelevant
noescape/throws bits to avoid confusing the issue with folks who don't know that you can
pass a nothrow closure to a throw parameter (which are going to be pervasive in the 
stdlib)


Swift SVN r30912
2015-08-01 05:38:40 +00:00
Chris Lattner
dcfc6180cf improve QoI of inout argument failures, and strip some single element tuple labels.
Swift SVN r30908
2015-08-01 05:20:23 +00:00
Chris Lattner
97e6a50148 Start using contextual information from function calls to diagnose issues in their
argument.  For now we start with some of the most simple cases: single argument 
calls.  This dramatically improves the QoI for error messages in argument lists,
typically turning a error+note combo into a single specific error message.

Some minor improvements coming (and also generalizing this to n-ary calls), but it 
is nice that all the infrastructure is starting to come together...



Swift SVN r30905
2015-08-01 04:37:52 +00:00
Chris Lattner
5c5e993a08 teach the logic in FailureDiagnosis::diagnoseFailure to retypecheck
inner expression nodes when contextual type information is provided for
them.  NFC since this type information is never provided yet.


Swift SVN r30884
2015-07-31 21:26:41 +00:00
Chris Lattner
31ef950f11 add a special case diagnostic for invalid uses of 'nil' in certain contexts,
so we complain about 'nil' instead of NilLiteralConvertible.  This doesn't have
much effect on the testsuite at the moment, but will when other changes land.


Swift SVN r30873
2015-07-31 20:49:53 +00:00
Chris Lattner
5ece5cadbf the onlyFailures argument to savlageExpr is always false,
constant prop it away.  NFC.


Swift SVN r30862
2015-07-31 19:53:22 +00:00
Chris Lattner
e6263314b8 Infrastructure for passing type information from call sites down to argument
expressions.  This is currently diabled, so NFC.


Swift SVN r30861
2015-07-31 19:40:11 +00:00
Chris Lattner
aca1a9afc2 actually, remove typeIsSpecialized entirely. With other changes that have gone in,
it is the same as !hasTypeVariable.


Swift SVN r30859
2015-07-31 18:50:29 +00:00
Chris Lattner
0d2b2ffb0b invert the sense of typeIsNotSpecialized to typeIsSpecialized to
avoid double negatives in client code, NFC.


Swift SVN r30856
2015-07-31 18:38:17 +00:00
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