Commit Graph

63 Commits

Author SHA1 Message Date
Dmitri Gribenko
efaa39ea79 stdlib: add first argument labels and some other changes to conform to API guidelines 2016-02-15 23:47:54 -08:00
Max Moiseev
61c837209b Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-04 16:13:39 -08:00
Doug Gregor
ecfde0e71c Start parsing names with argument labels.
Basic implementatation of SE-0021, naming functions with argument
labels. Handle parsing of compound function names in various
unqualified-identifier productions, updating the AST representation of
various expressions from Identifiers to DeclNames. The result doesn't
capture all of the source locations we want; more on that later.

As part of this, remove the parsing code for the "selector-style"
method names, since we now have a replacement. The feature was never
publicized and doesn't make sense in Swift, so zap it outright.
2016-01-20 17:09:01 -08:00
Doug Gregor
7d70b704e4 Merge commit '5e11e3f7287427d386636a169c4065c0373931a8' into swift-3-api-guidelines 2016-01-19 23:18:20 -08:00
Doug Gregor
38c1de69e4 Reinstate "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit ce7b2bcf09, tweaking
a few validation tests appropriately (1 crasher fixed, two -verify
tests that needed updating).
2016-01-14 00:21:48 -08:00
Erik Eckstein
ce7b2bcf09 Revert "[SR-511][Parse] Add 'associatedtype' keyword and fixit"
This reverts commit 2b2e9dc80e.

It broke some compiler crasher tests
2016-01-13 20:42:58 -08:00
gregomni
2b2e9dc80e [SR-511][Parse] Add 'associatedtype' keyword and fixit
Adds an associatedtype keyword to the parser tokens, and accepts either
typealias or associatedtype to create an AssociatedTypeDecl, warning
that the former is deprecated. The ASTPrinter now emits associatedtype
for AssociatedTypeDecls.

Separated AssociatedType from TypeAlias as two different kinds of
CodeCompletionDeclKinds. This part probably doesn’t turn out to be
absolutely necessary currently, but it is nice cleanup from formerly
specifically glomming the two together.

And then many, many changes to tests. The actual new tests for the fixits
is at the end of Generics/associated_types.swift.
2016-01-13 17:54:31 -08:00
Max Moiseev
a7339e67ac Merge remote-tracking branch 'origin' into swift-3-api-guidelines 2015-12-22 11:36:07 -08:00
Chris Lattner
5e224842b4 Reapply "Move the testsuite off ++/-- completely."
This reverts commit 38b483df22.
2015-12-21 21:02:50 -08:00
Michael Gottesman
38b483df22 Revert "Move the testsuite off ++/-- completely."
This reverts commit bc6583630c.
2015-12-21 19:21:42 -06:00
Chris Lattner
bc6583630c Move the testsuite off ++/-- completely. 2015-12-21 15:11:49 -08:00
Doug Gregor
a97ab6dd14 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2015-12-18 10:15:47 -08:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
Maxim Moiseev
1b6244f3ee integer types renamed 2015-12-10 17:03:40 -08:00
Maxim Moiseev
c678a839dc IndexType => Index 2015-12-09 17:16:42 -08:00
Dmitri Gribenko
31598d41bf Rename GeneratorType to IteratorProtocol 2015-12-07 17:08:32 -08:00
David Farler
93b6962478 Warn when using 'var' bindings in function parameters
These will no longer be allowed in a future Swift release.

rdar://problem/23172698
2015-11-03 17:24:20 -08:00
Chris Lattner
b6de061dd6 Rework assignment diagnostics to be built in terms of contextual types,
where we type check the destination first, then apply its type to the source.

This allows us to get diagnostics for assignments that are as good as PBD
initializers and other cases.


Swift SVN r31404
2015-08-22 05:16:07 +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
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
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
Doug Gregor
cf0c0c1954 Preference protocol inheritance when comparing two declarations as overloads.
Fixes rdar://problem/21926788.

Swift SVN r30473
2015-07-21 23:47:17 +00:00
Chris Lattner
5d3dc0d77b Now that sufficient complexity is pushed into the right corners of the compiler,
we can start taking advantage of ambiguously typed subexpressions in CSDiags.  We
start by validating the callee function of ApplyExprs, which substantially improves
our abilities to generate precise diagnostics about malformed calls.

This is the minimal introduction of this concept to CSDiags, a lot of refactoring
is yet to come, however, this is enough to resolve:

<rdar://problem/21080030> Bad diagnostic for invalid method call in boolean expression
<rdar://problem/21784170> Incongruous `unexpected trailing closure` error in `init` function which is cast and called without trailing closure.

one of the testcases from:
<rdar://problem/20789423> Unclear diagnostic for multi-statement closure with no return type

and a bunch of other places where we got weird "unexpected trailing closure" 
diagnostics that made no sense.  As usual, it is two steps forward and one step back,
as this exposed some other weird latent issues like:
<rdar://problem/21900971> QoI: Bogus conversion error in generics case




Swift SVN r30429
2015-07-21 01:06:55 +00:00
Jordan Rose
ad43abda1a Scale back the restriction on extending protocols via typealias.
It's safe to do this as long as the protocol has already been fully type-checked,
and we can guarantee that if the protocol lives in another module.

The next commit shows why this is useful: "extension dispatch_queue_t" is much
nicer than "extension OS_dispatch_queue".

Swift SVN r30099
2015-07-11 00:13:29 +00:00
Chris Lattner
63f99a486c Move CallExpr diagnostics over to the same overload candidate diagnosis
facilities used by operators etc.  This required a bunch of changes to make
the diagnostics changes strictly an improvement:

  - Teach the new path about calls to TypeExprs.
  - Teach evaluateCloseness some simple things about varargs.
  - Make the generic diagnosis logic produce a better error when there is 
    exactly one match.

Overall, the resultant diagnostics are a step forward: we now produce candidate
set notes more uniformly, and the messages about some existing ones are 
more specific.  This is just another stepping stone towards progress though.



Swift SVN r30057
2015-07-10 04:26:42 +00:00
Doug Gregor
18ad549ecb Add another protocol-conformance-via-extension example, from Dmitri.
Swift SVN r29096
2015-05-28 04:20:53 +00:00
Doug Gregor
a72a16181a Override checking: ignore members found in non-class/class extension contexts.
Fixes rdar://problem/21075287.

Swift SVN r29095
2015-05-28 04:20:48 +00:00
Doug Gregor
dc70099dad Stop requiring 'final' on members of protocol extensions.
We're not sure when or if we want 'final' on protocol extension
members, so accept it but don't complain one way or another. We zap
this early on so that we don't end up printing it in generated
interfaces. Fixes rdar://problem/21112901.

Swift SVN r29040
2015-05-26 23:27:27 +00:00
Doug Gregor
98314777f2 Allow a protocol extension to define a default implementation for a requirement of its own protocol.
Based on Dave’s hack, this allows one to define a “default implementation” as, e.g.,

  protocol P {
    func foo()
  }

  extension P {
    final func foo() { … }
  }

Swift SVN r28949
2015-05-23 03:40:41 +00:00
Doug Gregor
1d277c1c06 Retain the 'self' type and generic signature in overload signatures.
This information keeps declarations in differently-constrained
protocol extensions separate. Fixes rdar://problem/21060743 and
enables the (N+1)st iteration of the default implementations hack.

Swift SVN r28887
2015-05-21 21:32:45 +00:00
Doug Gregor
c60c6d9207 Dependent member types are always dependent.
Swift SVN r28794
2015-05-19 22:40:12 +00:00
Chris Lattner
e4b6afb9ae Start moving the testsuite to the "_ = foo()" idiom for evaluating an
expression but ignoring its value.  This is the right canonical way to do
this.  NFC, just testsuite changes.



Swift SVN r28638
2015-05-15 20:15:54 +00:00
Doug Gregor
b4d7680744 Consider constrained protocol extension signatures in overload signatures.
This allows us to overload properties and subscripts with the same
signature in differently-constrained protocol extensions. Previously,
such overloads would be considered to be erroneous redeclarations.

Swift SVN r28610
2015-05-15 04:47:53 +00:00
Chris Lattner
7059871abf Convert some 'var' bindings to 'let' when they are not mutated, some
var/let bindings to _ when they are never used, and use some values that
are only written.  This is a testsuite cleanup, NFC. More to come.


Swift SVN r28406
2015-05-11 00:20:55 +00:00
Doug Gregor
2f0c1b151e Use the archetype for unqualified lookup within protocols and extensions thereof.
When performing unqualified lookup within a type context (or method
thereof) that is a protocol or a protocol extension, use the Self
archetype of the protocol or extension so we look in types implied by
the requirements as well. Part of rdar://problem/20509152, fixing the
example provided in rdar://problem/20694545.

Swift SVN r28363
2015-05-09 03:42:16 +00:00
Doug Gregor
0749486302 Let unqualified lookup find members of protocols and extensions thereof.
Members of protocols found via unqualified name lookup are mapped to
their corresponding witnesses, as we do for qualified name
lookup. This is the bulk of the compiler changes for
rdar://problem/20509152. Performing this mapping for unqualified name
lookup of types will follow.

Swift SVN r28333
2015-05-08 23:22:13 +00:00
Doug Gregor
a924e06025 Don't require 'Self.' within the where clause of a constrained extension.
Within the where clause of a constrained (protocol) extension, allow
us to find associated types of that protocol and anything it inherits
via unqualified lookup, e.g.,

  extension SequenceType where Generator.Element : Equatable { }

rather than

  extension SequenceType where Self.Generator.Element : Equatable { }

Implements rdar://problem/20722467.

Swift SVN r28208
2015-05-06 17:05:28 +00:00
Doug Gregor
11b820dbcc Ban extension of the 'AnyObject' protocol.
AnyObject won't always be a protocol, and it may be de-protocol'ified
well before we get the ability to extend an arbitrary type (if that
ever happens), so ban this for now.

Swift SVN r28120
2015-05-04 16:37:26 +00:00
Doug Gregor
5cfe5b3383 Diagnose attempts to extend a protocol via a typealias.
Fixes rdar://problem/20756244.

Swift SVN r28026
2015-05-01 05:34:29 +00:00
Doug Gregor
f53cb8a5e3 Avoid null conformances when comparing a potential requirement and witness.
We might be looking at a protocol requirement, which conforms to a
protocol but has a null conformance. Also, don't bother looking at
completeness: it doesn't matter. Fixes rdar://problem/20608438.

Swift SVN r27860
2015-04-28 04:57:51 +00:00
Doug Gregor
793b3326af Implement the new rules for argument label defaults.
The rule changes are as follows:
  * All functions (introduced with the 'func' keyword) have argument
  labels for arguments beyond the first, by default. Methods are no
  longer special in this regard.
  * The presence of a default argument no longer implies an argument
  label.

The actual changes to the parser and printer are fairly simple; the
rest of the noise is updating the standard library, overlays, tests,
etc.

With the standard library, this change is intended to be API neutral:
I've added/removed #'s and _'s as appropriate to keep the user
interface the same. If we want to separately consider using argument
labels for more free functions now that the defaults in the language
have shifted, we can tackle that separately.

Fixes rdar://problem/17218256.

Swift SVN r27704
2015-04-24 19:03:30 +00:00
Doug Gregor
2217e38cdf Compare the boolean results of isProtocolOrProtocolExtensionContext().
We were getting some bogus shadowing involving properties in protocols
vs. protocol extensions. Fixes rdar://problem/20608438.

Swift SVN r27683
2015-04-24 06:15: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
Doug Gregor
78cc7b75f8 Basic support for typealiases in protocol extensions.
Handle substitutions properly when a typealias declared in a protocol
extension is used to satisfy an associated type requirement. Fixes
rdar://problem/20564605.

Swift SVN r27490
2015-04-20 20:19:03 +00:00
Doug Gregor
57ecdc2f58 More "final" fixes for protocol extensions.
Swift SVN r26943
2015-04-03 18:37:20 +00:00
Doug Gregor
10934bb273 Start requiring 'final' on members of protocol extensions.
Part of rdar://problem/11735843.

Swift SVN r26941
2015-04-03 18:09:24 +00:00
Doug Gregor
eecba212a5 Add some tests for protocol extensions constraining to concrete types.
Swift SVN r26940
2015-04-03 16:21:41 +00:00
Doug Gregor
21765eb38d Allow name lookup to find initializers defined in protocol extensions.
For structs/enums, this was already the case. For classes, we simply
need to ensure that we always look at the extensions of protocols to
which the class conforms.

Swift SVN r26773
2015-03-31 18:56:08 +00:00