Commit Graph

79 Commits

Author SHA1 Message Date
Doug Gregor
eb4f4643f6 Protocol conformance: handle derivable requirements before same-named requirements.
Other protocols can have requirements that match up with the
requirements of derivable protocols. In such cases, deriving the
requirement we know about *first* can mean that it will be used to
satisfy the requirement of some other protocol. This behavior has
always been order-dependent before, and the order changed in Swift 2.0
with the introduction of the protocol conformance table, causing
rdar://problem/22476643.

Now, when we see a requirement that looks like a derivable
requirement, go ahead and satisfy the witness for that derivable
requirement. This will, when needed, synthesize an actual witness for
the derivable requirement---that can also be used for the original
requirement---eliminating the ordering dependency and fixing
rdar://problem/22476643.

Swift SVN r32191
2015-09-23 23:08:35 +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
ada5487153 add fixit tests to random other tests.
Swift SVN r31006
2015-08-04 20:35:36 +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
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
1a0a0315fe wordsmith a diagnostic, NFC otherwise.
Swift SVN r30731
2015-07-28 23:35:25 +00:00
Chris Lattner
06cc05daa9 reword a diagnostic, as suggested by Jordan
Swift SVN r30712
2015-07-28 04:03:25 +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
Slava Pestov
c83cc8ccd6 Parser: Fix a couple of crashes when parsing invalid enum cases
Also make some diagnostic wording more consistent.

Fixes <rdar://problem/19582394>.

Swift SVN r30300
2015-07-17 04:31:03 +00:00
Jordan Rose
8b3d4acccd Allow enum elements with string raw values to default to the name of the element.
Just like enums with integer raw values can get autoincrementing case values,
enums with string raw values get the name of the element. The name is /not/
prefixed with the enum type because the purpose is presumably to interoperate
with a string-based system, which may require either writing or printing the
raw value as a string.

If an enum's raw type is both integer literal convertible and string literal
convertible, the integer side wins. That is, elements without raw values
will get auto-incremented integer values, rather than string values, and will
produce an error if an auto-incremented value cannot be generated.

rdar://problem/15819953

Swift SVN r29542
2015-06-22 00:28:23 +00:00
Ben Langmuir
bb78a4dd54 QoI: handling of leading '.' in an enum case declaration
1. Recover the case name for code completion.
2. Provide a specialized diagnostic with a fixit to remove the '.'

Swift SVN r29031
2015-05-26 16:47:29 +00:00
Joe Groff
a14b83ba2c SILGen: Allow partial applications of enum cases.
This isn't as straightforward as it should be, since EnumElementDecls aren't AbstractFunctionDecls, but luckily there's only one trivial curry level with a thin metatype parameter.

Swift SVN r28991
2015-05-24 19:39:02 +00:00
Chris Willmore
cedaafb7fe Don't consider invalid enum entries when looking up enum cases by name;
they may have been marked invalid because they're duplicates.

<rdar://problem/20922401> Compiler crash "ambiguity in enum case name
lookup?!"

Swift SVN r28487
2015-05-12 21:10:06 +00:00
Doug Gregor
126e404fe5 Reimplement inference of type witnesses with a separate non-recursive pass.
Inference of type witnesses for associated types was previously
implemented as part of value witness matching in the constraint
solver. This led to a number of serious problems, including:
  - Recursion problems with the solver hunting for a type witness,
  which triggers more attemts to match value witnesses...
  - Arbitrarily crummy attempts to break the recursion causing
  type-check failures in fun places.
  - Ordering dependencies abound: different results depending on which
  value witnesses were satisfied first, failures because of the order
  in which we attempted to infer type witnesses, etc.

This new implementation of type witness inference uses a separate pass
that occurs whenever we're looking for any type witness, and solves
all of the type witnesses within a given conformance
simultaneously. We still look at potential value witnesses to infer
type witnesses, but we match them structurally, without invoking the
constraint solver.

There are a few caveats to this implementation:
  * We're not currently able to infer type witnesses from value
  witnesses that are global operators, so some tricks involving global
  operators (*cough* ~> *cough*) might require some manually-specified
  type witnesses. Note that the standard library doesn't include any
  such cases.

  * Yes, it's another kind of solver. At simple one, fortunately.

On the other hand, this implementation should be a big step forward:
  * It's far more predictable, order-invariant, and non-recursive.
  * The diagnostics for failures to infer type witnesses have
  improved.

Fixes rdar://problem/20598513.

Swift SVN r27616
2015-04-23 00:20:05 +00:00
Jordan Rose
12c80f4a3a Check the raw values of an @objc enum eagerly during decl validation.
For @objc enums, raw values determine the representation values, so we have
to compute them eagerly in order for switch statements to work. Similarly,
if the enum is broken, we have to /fail/ eagerly so that we don't fall down
later on in IRGen.

rdar://problem/19775284

Swift SVN r25282
2015-02-13 20:31:43 +00:00
Dmitri Hrybenko
3b04d1b013 tests: reorganize tests so that they actually use the target platform
Most tests were using %swift or similar substitutions, which did not
include the target triple and SDK.  The driver was defaulting to the
host OS.  Thus, we could not run the tests when the standard library was
not built for OS X.

Swift SVN r24504
2015-01-19 06:52:49 +00:00
Joe Groff
32e6db3f2d Parse signs onto float literals the same way we handle integer literals.
Provides consistency in behavior, particularly in enum raw values, where we reject non-literals. Factor out a common NumberLiteralExpr base for integer and float literals that handles the common sign and representation stuff. Fixes rdar://problem/16504472.

Swift SVN r23390
2014-11-18 00:55:02 +00:00
Joe Groff
53af706676 Sema: Fix logic inversion that threw away significant bits of enum raw value literals.
Fixes rdar://problem/18878717.

Swift SVN r23283
2014-11-12 21:03:12 +00:00
Doug Gregor
7764f64cf8 Simplify assertion machinery in the standard library.
This change includes a number of simplifications that allow us to
eliminate the type checker hack that specifically tries
AssertString. Doing so provides a 25% speedup in the
test/stdlib/ArrayNew.swift test (which is type-checker bound).

The specific simplifications here:
  - User-level
  assert/precondition/preconditionalFailure/assertionFailer/fatalError
  always take an autoclosure producing a String, eliminating the need
  for the StaticString/AssertString dance.
  - Standard-library internal _precondition/_sanityCheck/etc. always
  take a StaticString. When we want to improve the diagnostics in the
  standard library, we can provide a separate overload or
  differently-named function.
  - Remove AssertString, AssertStringType, StaticStringType, which are
  no longer used or needed
  - Remove the AssertString hack from the compiler
  - Remove the "BooleanType" overloads of these functions, because
  their usefuless left when we stopped making optional types conform
  to BooleanType (sorry, should have been a separate patch).



Swift SVN r22139
2014-09-19 17:56:50 +00:00
Doug Gregor
4dca192b18 Switch IntegerLiteralConvertible over to initializers.
Swift SVN r21986
2014-09-16 21:59:15 +00:00
Joe Groff
8338e69c86 Actually set up the 'rawValue' argument label on derived enum initializers.
Somehow, protocol conformance checking didn't actually care that this was missing...

Swift SVN r21898
2014-09-12 01:29:51 +00:00
Dmitri Hrybenko
ea48185358 stdlib: don't silently truncate Float80 literals
We used to first truncate them to Float64, and then construct a Float80.

Swift SVN r21433
2014-08-25 13:21:54 +00:00
Chris Lattner
fcb6b3df07 Fix <rdar://problem/17391625> Swift Compiler Crashes when Declaring a Variable and didSet in an Extension
This moves a crude parser check for stored properties in enums & extensions into Sema, and changes it
to be correct (rejecting the case that caused the crash in the radar) as well as more descriptive.



Swift SVN r20695
2014-07-29 21:19:56 +00:00
Joe Groff
e152c4d7a4 Sema: Disallow partial applications of payloaded enum case constructors.
Fixes <rdar://problem/16304750>, which was frequently taking down SourceKit on partially-entered enum constructions.

Swift SVN r20459
2014-07-24 02:39:56 +00:00
Dave Abrahams
6d1095f44e Protocol names end in "Type," "ible," or "able"
Mechanically add "Type" to the end of any protocol names that don't end
in "Type," "ible," or "able."  Also, drop "Type" from the end of any
associated type names, except for those of the *LiteralConvertible
protocols.

There are obvious improvements to make in some of these names, which can
be handled with separate commits.

Fixes <rdar://problem/17165920> Protocols `Integer` etc should get
uglier names.

Swift SVN r19883
2014-07-12 17:29:57 +00:00
Joe Pamer
a314db950e Remove another point of non-determinism while tracking failed constraints, and use this as an opportunity to improve certain diagnostics. (rdar://problem/16808495)
Swift SVN r19244
2014-06-26 19:48:48 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Joe Groff
5d8a7ff9e7 Allow multiple comma-separated enum elements in a 'case' decl.
Introduce an EnumCaseDecl for source fidelity to track the 'case' location and ordering of EnumElementDecls. Parse a comma-separated list of EnumElementDecls after a 'case' token.

Swift SVN r8509
2013-09-20 19:51:13 +00:00