Commit Graph

76 Commits

Author SHA1 Message Date
Doug Gregor
26dfec4e1a Add a test for constrained extensions of a generic class.
Swift SVN r29111
2015-05-28 20:42:51 +00:00
Doug Gregor
2dc383d4ec Allow constrained extensions to any generic type.
This permits, e.g., extending Array for all Hashable T's. However, it
does not permit extending Array for T == String. Part of
rdar://problem/21142043.

Swift SVN r29107
2015-05-28 18:39:23 +00:00
Doug Gregor
72f522ca7d Compute the source range of a TrailingWhereClause without tripping assertions.
Fixes rdar://problem/21001937.

Swift SVN r28825
2015-05-20 05:31:09 +00:00
Doug Gregor
340e4d8f8a Simplify parsing and representation of extension declarations.
Now that we don't have generic parameter lists at arbitrary positions
within the extended type of an extension declaration, simplify the
representation of the extended type down to a TypeLoc along with a
(compiler-synthesized) generic parameter list.

On the parsing side, just parse a type for the extended type, rather
than having a special grammar. We still reject anything that is not a
nominal type (of course), but it's simpler just to call it a type.

As a drive-by, fix the crasher when extending a type with module
qualification, rdar://problem/20900870.

Swift SVN r28469
2015-05-12 16:26:13 +00:00
Doug Gregor
985896905e Ban generic parameters on extensions.
We no longer allow extensions to provide generic parameters, and the
ability to parse the syntax

  extension Array<String> { ... }

is causing confusion. Fixes rdar://problem/20873336.

Swift SVN r28468
2015-05-12 16:26:04 +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
Roman Levenstein
984fcef576 Produce an error for generic parameters of functions if those parameters are not used in function signature.
If a generic parameter is not referred to from a function signature, it can never be inferred and thus such a function can never be invoked.

We now produce the following error:

generic parameter 'T' is not used in function signature
func f8<T> (x: Int) {}

This commit takes Jordan't comments on r28181 into account:
- it produces a shorter error message
- it does not change the compiler_crashers_fixed test and add a new expected error instead

Swift SVN r28194
2015-05-06 02:20:39 +00:00
Roman Levenstein
a3a25000ff Revert "Produce an error for generic parameters of functions if those parameters are not used in function signature."
This reverts commit r28181. I'll change it according to Jordan's comments and re-commit.

Swift SVN r28193
2015-05-06 02:20:36 +00:00
Roman Levenstein
ebe3fddbe6 Produce an error for generic parameters of functions if those parameters are not used in function signature.
If a generic parameter is not referred to from a function signature, it can never be inferred and thus such a function can never be invoked.

We now produce the following error:

There is no way to infer the generic parameter 'T' if it is not used in function signature
func f8<T> (x: Int) {}
             ^

Swift SVN r28181
2015-05-05 21:02:11 +00:00
Doug Gregor
e4f2cef6f7 Eliminate archetypes from interface types.
The culprit happened to be a type representation cloner for tuple type
representations that didn't actually clone anything. Introduce an
AST-level verifier that makes sure we catch any archetypes that slip
into interface types earlier in the future.

Fixes rdar://problem/18796397 and the three dupes I've found so far.

Swift SVN r28080
2015-05-02 05:28:57 +00:00
Chris Lattner
33fc37d831 Fix rdar://20477982 - REGRESSION: Accessing let-property with default value in init() can throw spurious error: 'self' used before all stored properties are initialized
in Xcode 6.4 I changed the compiler to start treating properties as rvalues in 
initializers when they have an initializer since they cannot be overwritten
in the initializer.  This has the unfortunate effect of typing derived member_refs
as rvalues as well, which causes SILGen to load the entire 'self' value instead of
just the member, triggering invalid DI errors in cases like this.

Fix this by always treating properties on self as lvalues in initializers.  Invalid
reassignments are already diagnosed by DI anyway, and the QoI of the error is better
from DI than from Sema (as shown by the testsuite change).



Swift SVN r27721
2015-04-25 21:40:50 +00:00
Doug Gregor
492388736c Separate the archetypes of extensions from those of their nominal types.
Start allowing extensions to redeclare type parameters, which will get
different archetypes from the original nominal type. When an extension
does not redeclare type parameters, silently clone the nominal type's
generic type parameters so we still get distinct type parameters.

When deserializing an extension, wire up its generic parameter list so
we get the right archetypes for its members. This doesn't change the
module format (that happened earlier).

When determining the substitutions for an associated type that comes
from a different declaration context from the conformance that will
own the witness, be sure to map into the conformance's
DeclContext. Otherwise, we'll end up with tangled archetypes.

Fixes rdar://problem/16519588.

Swift SVN r26483
2015-03-24 06:48:26 +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
Chris Lattner
a048b078e3 Implement: <rdar://problem/16181314> don't require immediate initialization of 'let' values
... now that we have an exquisitely shaved yak.

This provides a simple and uniform model for "let" constants: they are always either
immediately initialized in their declaration, or they are initialized dynamically
exactly once before any use.  

This is a simple generalization of our current model for initializers, but enables
the use of let constants in more cases in local context, e.g. patterns like this:

   let x : SomeThing

   if condition {
     x = foo()
   } else {
     x = bar()
   }
   use(x)

Previously this would have to be declared a "var" for no good reason: the value is
only ever initialized, never actually mutated.

The implementation of this is reasonably straight-forward now that the infrastructure
is in place: Sema treats 'let' constants as "settable" if they lack an initializer
(either in the declaration or in a non-PBD binding).  This exposes them as an lvalue
at the AST level.  SILGen then lowers these things to an alloc_stack, and DI enforces
the "initialization only" requirement that it already enforces for uninitialized 'let'
properties in structs/classes.



Swift SVN r23916
2014-12-13 07:17:44 +00:00
Doug Gregor
96aec03e68 Verify that an archetype is not referenced outside of its scope.
The changes to the decl/ext/generic test strip out testing of
extensions of nested generics, a feature whose syntax will change and
is fairly broken already.

Swift SVN r21750
2014-09-05 22:46:32 +00:00
Doug Gregor
7bc2309b34 Maintain some more type sugar through substitution involving dependent types
... not because it's useful for the user, but because it props up our
broken model for computing generic types.

Swift SVN r20852
2014-07-31 21:33:38 +00:00
Doug Gregor
d1f7336853 Infer requirements from the where clause of a generic parameter list.
This happens to be the rest of <rdar://problem/14691708>, but it's in
service of <rdar://problem/16974298>.

Swift SVN r20836
2014-07-31 18:12:12 +00:00
Doug Gregor
aa275ea3f6 Use the generic parameters of the context of a member to substitute into its type.
Swift SVN r20812
2014-07-31 05:15:10 +00:00
Joe Groff
baf466b55b Sema: Diagnose nested generics.
<rdar://problem/16028090>

Swift SVN r20808
2014-07-31 03:35:01 +00:00
Doug Gregor
e4b37bc105 Properly check whether we're in an extension when determining settability of a 'let' property.
We were checking for exact type equality of the DeclContexts, which
will not hold when extensions have their own archetypes. A near-term
fix would be to use interface types, but checking the nominal types is
a better long-term solution.

Swift SVN r20768
2014-07-30 20:27:33 +00:00
Doug Gregor
2550881420 Wire up and validate multiple levels of generic parameters in extensions.
This allows us to type-check extensions of nested generics, e.g.,

  extension Outer<T>.Inner<A, B> { ... }



Swift SVN r20738
2014-07-30 05:56:58 +00:00
Doug Gregor
b6394479a3 Test module names in extension matching.
Swift SVN r20731
2014-07-30 04:32:34 +00:00
Doug Gregor
fbbfe266f9 Check presence/absence/arity of generic parameters during extension binding.
Extension binding decides which nominal type declaration is extended
by a given extension, so perform basic validation to ensure that the
generic parameter lists provided in the extension make sense. Note
that we're not checking the actual generic parameters properly in
the nested case, so none of this actually works at all. That will come
next, over in extension validation.

Swift SVN r20724
2014-07-29 23:53:45 +00:00
Doug Gregor
657c53fb18 Small test of name lookup behavior for extensions with generic parameters.
Swift SVN r20707
2014-07-29 22:43:19 +00:00
Doug Gregor
2162893fbe Start validating the generic parameters on extensions.
Extensions must have the same number of generic parameters as the
generic type they extend, and cannot add any additional requirements
beyond those on the extended generic type (yet!). We use requirement
inference to allow one to provide fewer requirements on the extension
than exist on the generic type. The expectation here is that one won't
ever repeat the requirements from the generic type.

Swift SVN r20706
2014-07-29 22:43:18 +00:00
Doug Gregor
a0bc9274db Change parsing and representation of extensions to accommodate generic parameters.
The eventual goal for extensions of generic types is to require them
to specify their generic parameters, e.g.,

  extension Array<T> { ... }

rather than today's

  extension Array { ... }

Start parsing (optional) generic parameters here, and update the
representation of ExtensionDecl to accomodate this new grammar
production. Aside from the parser changes, there's no intended
functionality change here.

Swift SVN r20682
2014-07-29 19:17:00 +00:00