Commit Graph

113 Commits

Author SHA1 Message Date
Doug Gregor
e164c6fc9a Don't permit type definitions within protocol extensions.
Similar to the limitation on defining types within protocols itself.

Swift SVN r26771
2015-03-31 18:56:02 +00:00
Doug Gregor
557751ba7e Protocol extensions cannot have inheritance clauses.
Swift SVN r26770
2015-03-31 18:55:58 +00:00
Doug Gregor
7ffe418626 Add a test mimicking the default definition of SequenceType's generate().
Swift SVN r26738
2015-03-30 23:36:54 +00:00
Doug Gregor
fbf841b279 'Self' in protocol extensions is not dynamic 'Self'.
Swift SVN r26737
2015-03-30 23:36:51 +00:00
Doug Gregor
085738069f Test ambiguous witnesses due to implementations in protocol extensions.
Swift SVN r26734
2015-03-30 22:27:43 +00:00
Doug Gregor
346ed6e815 Implement partial ordering for protocol extensions.
Compare the generic signatures so that we get appropriate partial
ordering among constrained extensions, extensions of inherited
protocols, etc. Finishes rdar://problem/20335936.

Swift SVN r26726
2015-03-30 21:11:14 +00:00
Doug Gregor
abee3281e3 Basic partial ordering for members of protocol extensions.
Implement simplistic partial ordering rules for members of protocol
extensions. Specifically:
  - A member of a concrete type is more specialized than a member of a
  protocol extension
  - A member of a protocol extension of P1 is more specialized than a
  member of a protocol extension of P2 if P1 inherits from P2

This achieves most of what rdar://problem/20335936 covers, but does
not yet handle ordering between constrained protocol extensions.

Swift SVN r26723
2015-03-30 19:14:48 +00:00
Doug Gregor
ccde6bb87d Allow protocol extensions to add further constraints via a trailing where clause.
Start parsing a "trailing" where clause for extension declarations, which follows the extended type name and (optional) inheritance clause. Such a where clause is only currently permitted for protocol extensions right now.

When used on a protocol extension, it allows one to create a more-constrained protocol extension, e.g.,

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

which appears to be working, at least in the obvious cases I've tried.

More cleanup, tests, and penance for the previous commit's "--crash" introductions still to come.

Swift SVN r26689
2015-03-29 05:42:37 +00:00
Doug Gregor
d0ab6890f8 Start allowing extensions of protocol types.
Remove the semantic restrictions that prohibited extensions of
protocol types, and start making some systematic changes so that
protocol extensions start to make sense:
  - Replace a lot of occurrences of isa<ProtocolDecl> and
    dyn_cast<ProtocolDecl> on DeclContexts to use the new
    DeclContext::isProtocolOrProtocolExtensionContext(), where we want
    that behavior to apply equally to protocols and protocol extensions.
  - Eliminate ProtocolDecl::getSelf() in favor of
    DeclContext::getProtocolSelf(), which produces the appropriate
    generic type parameter for the 'Self' of a protocol or protocol
    extension. Update all of the callers of ProtocolDecl::getSelf()
    appropriately.
  - Update extension validation to appropriately form generic
    parameter lists for protocol extensions.
  - Methods in protocol extensions always use the witnesscc calling
  convention.

At this point, we can type check and SILGen very basic definitions of
protocol extensions (without associated types, IRGen crashes, etc.)
with methods that can call protocol requirements, generic free
functions, and other methods within the same protocol extension.

This is identical to r26579; the prior commit addressed the underlying
conformance substitution problem that caused rdar://problem/20320393
and subsequent reversion of r26579.

Swift SVN r26639
2015-03-27 18:30:23 +00:00
Arnold Schwaighofer
a4ecf9c5a6 Revert "Teach normal name lookup to find members of protocol extensions."
It is breaking the bots.

This reverts commit r26617.

Swift SVN r26620
2015-03-27 02:27:13 +00:00
Doug Gregor
1e6b445cae Teach normal name lookup to find members of protocol extensions.
We do a silly little dance here of finding all of the members of
protocols and their extensions, then deleting the protocol members. In
the future, this is the place where we should handle the protocol
requirement -> witness mapping, including handling derived
conformances.

Basic protocol extensions seem to be working now:

  extension SequenceType {
    var myCount: Int {
      var result = 0
      for x in self {
        ++result
      }
      return result
    }
  }

  println(["a", "b", "c", "d"].myCount) // 4, duh

Swift SVN r26617
2015-03-27 00:10:21 +00:00
Doug Gregor
15852a1ab0 Allow a protocol extension to reference an associated type of its protocol.
... just a matter of using isProtocolOrProtocolExtensionContext()
rather than specifically checking for <ProtocolDecl>.

Swift SVN r26603
2015-03-26 21:23:38 +00:00
Doug Gregor
3d77855b31 Start allowing extensions of protocol types.
Remove the semantic restrictions that prohibited extensions of
protocol types, and start making some systematic changes so that
protocol extensions start to make sense:
  - Replace a lot of occurrences of isa<ProtocolDecl> and
    dyn_cast<ProtocolDecl> on DeclContexts to use the new
    DeclContext::isProtocolOrProtocolExtensionContext(), where we want
    that behavior to apply equally to protocols and protocol extensions.
  - Eliminate ProtocolDecl::getSelf() in favor of
    DeclContext::getProtocolSelf(), which produces the appropriate
    generic type parameter for the 'Self' of a protocol or protocol
    extension. Update all of the callers of ProtocolDecl::getSelf()
    appropriately.
  - Update extension validation to appropriately form generic
    parameter lists for protocol extensions.
  - Methods in protocol extensions always use the witnesscc calling
  convention.

At this point, we can type check and SILGen very basic definitions of
protocol extensions with methods that can call protocol requirements,
generic free functions, and other methods within the same protocol
extension.

Regresses four compiler crashers but improves three compiler
crashers... we'll call that "progress"; the four regressions all hit
the same assertion in the constraint system that will likely be
addressed as protocol extensions starts working.

Swift SVN r26579
2015-03-26 04:50:51 +00:00