Commit Graph

29 Commits

Author SHA1 Message Date
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
Chris Lattner
7daaa22d93 Completely reimplement/redesign the AST representation of parameters.
Parameters (to methods, initializers, accessors, subscripts, etc) have always been represented
as Pattern's (of a particular sort), stemming from an early design direction that was abandoned.
Being built on top of patterns leads to patterns being overly complicated (e.g. tuple patterns
have to have varargs and default parameters) and make working on parameter lists complicated
and error prone.  This might have been ok in 2015, but there is no way we can live like this in
2016.

Instead of using Patterns, carve out a new ParameterList and Parameter type to represent all the
parameter specific stuff.  This simplifies many things and allows a lot of simplifications.
Unfortunately, I wasn't able to do this very incrementally, so this is a huge patch.  The good
news is that it erases a ton of code, and the technical debt that went with it.  Ignoring test
suite changes, we have:
   77 files changed, 2359 insertions(+), 3221 deletions(-)

This patch also makes a bunch of wierd things dead, but I'll sweep those out in follow-on
patches.

Fixes <rdar://problem/22846558> No code completions in Foo( when Foo has error type
Fixes <rdar://problem/24026538> Slight regression in generated header, which I filed to go with 3a23d75.

Fixes an overloading bug involving default arguments and curried functions (see the diff to
Constraints/diagnostics.swift, which we now correctly accept).

Fixes cases where problems with parameters would get emitted multiple times, e.g. in the
test/Parse/subscripting.swift testcase.

The source range for ParamDecl now includes its type, which permutes some of the IDE / SourceModel tests
(for the better, I think).

Eliminates the bogus "type annotation missing in pattern" error message when a type isn't
specified for a parameter (see test/decl/func/functions.swift).

This now consistently parenthesizes argument lists in function types, which leads to many diffs in the
SILGen tests among others.

This does break the "sibling indentation" test in SourceKit/CodeFormat/indent-sibling.swift, and
I haven't been able to figure it out.  Given that this is experimental functionality anyway,
I'm just XFAILing the test for now.  i'll look at it separately from this mongo diff.
2015-12-31 19:24:46 -08:00
Doug Gregor
efbba06906 Same-type requirements for the nested types of equivalent types are inferred.
The archetype builder was improperly propagating the requirement
source of a same-type requirement down to the inferred same-type
requirements for the nested types, causing a huge number of redundant
same-type requirements to show up in the canonical generic signatures
used for mangling. Mark such same-type requirements as inferred, which
shrinks the mangled name of LazyCollectionType.flatten from 4844 bytes
to 358 bytes.

Fixes rdar://problem/22861623.

Swift SVN r32356
2015-10-01 00:13:44 +00:00
Doug Gregor
f898887894 Eliminate getConformsTo() callback from the archetype builder.
The getConformsTo() callback was responsible for forcing the
collection of the requirements directly placed on an associated type,
which then get added to the archetype builder. This resulted in an
unhealthy dependency on the list of protocols attached to TypeDecl
(which should go away). Instead, retrieve the requirements from the
associated type's archetype (once it's been computed) or directly from
its list of "inherited" types (while we're building the generic
signature for the protocol itself).

Swift SVN r31332
2015-08-19 06:42:27 +00:00
Slava Pestov
00d6b27d80 ArchetypeBuilder: Attempt to reconcile differing superclass requirements when one is a subclass of the other
Swift SVN r30061
2015-07-10 04:59:20 +00:00
Slava Pestov
710df51450 ArchetypeBuilder: Only infer requirements for the innermost set of generic parameters
Fixes <rdar://problem/21366651>.

Swift SVN r30056
2015-07-10 03:01:54 +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
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
Doug Gregor
16927ccb3d Revert "Move the computation of generic signatures into the archetype builder."
This reverts commit r23030.

This puts non-primary archetypes back in the all-archetypes list,
which is the deepest underlying problem behind
rdar://problem/19049566.

Conflicts:
	lib/AST/ArchetypeBuilder.cpp
	validation-test/compiler_crashers/0033-error.swift
	validation-test/compiler_crashers/035-multiple-typecheck-segfault.swift

Swift SVN r24333
2015-01-09 23:19:28 +00:00
Doug Gregor
72e9ca5d67 Move the computation of generic signatures into the archetype builder.
The archetype builder is responsible for figuring out what should go
into a generic signature anyway, so move the generic signature
creation there. This will also allow us to eliminate some code
duplication across Sema and AST.

Fixes compiler crasher 033.

Swift SVN r23030
2014-10-31 06:04:05 +00:00
Doug Gregor
d8a0c83345 Enumerate requirements in (roughly) the same order as we do when building generic signatures.
This will turn into "exactly" in a future commit, when we can build a
generic signature from an archetype builder (directly) and compare the
results.

Swift SVN r23010
2014-10-29 22:27:36 +00:00
Doug Gregor
1c712e069a Archetype builder: add witness markers to requirement enumeration
Swift SVN r23009
2014-10-29 22:27:35 +00:00
Doug Gregor
f270d7cf07 Archetype builder: don't prematurely lower to a dependent type when enumerating requirements.
Extend the contract for enumerateRequirements() a bit to preserve
archetype-to-archetype same-type constraints. Use that extra
information in the debug dump. NFC elsewhere.

Swift SVN r23008
2014-10-29 22:27:34 +00:00
Doug Gregor
dfa116600f Archetype builder: introduce "redundant" requirements to better track the requirements written in the source.
Essentially NFC at this point, but can be used for display purposes.

Swift SVN r22776
2014-10-15 21:51:31 +00:00
Mark Lacey
84b8f39cf8 Revert "Add requirements among distinct associated types with the same name."
This reverts commit r22680 because it causes a failure in one of the
check-swift-validation tests (parser/parse_stdlib.sil).

Swift SVN r22713
2014-10-13 23:09:03 +00:00
Doug Gregor
af898ff2e8 Add requirements among distinct associated types with the same name.
This pushes some of the extra same-type requirements introduced in r22649 into the generic signature. Doesn’t really have an effect outside of extending generic signatures slightly.

Swift SVN r22680
2014-10-10 23:48:01 +00:00
Doug Gregor
f9a6d88c19 Archetype builder: unify different associated types with the same name across protocols.
When we have two protocol conformance requirements for the same type
T, and each of those protocols has an associated type with a given
(shared) name N, infer a same-type requirement between the two. Only
really enabled for testing now; it doesn't feed into general type
checking yet.

Swift SVN r22649
2014-10-10 00:11:31 +00:00
Doug Gregor
59a355a67b Eliminate the notion of an archetype "index"; it's useless now. NFC
Swift SVN r22644
2014-10-09 22:43:54 +00:00
Doug Gregor
1380f758a5 Archetype builder: resolve nested types to associated types directly.
Effectively NFC because we're not making use of this information yet.

Swift SVN r22643
2014-10-09 21:52:34 +00:00
Doug Gregor
57ff959529 Add conformances with ArchetypeBuilder::PotentialArchetype::addConformance().
This means we'll get proper merging of requirement sources when
merging conformances due to same-type requirements.

Swift SVN r22642
2014-10-09 21:52:33 +00:00
Doug Gregor
f844ab4331 Store the generic type parameter type for non-associated potential archetypes.
This lets us map from potential archetypes back to dependent types
more efficiently, eliminating a linear search.

Swift SVN r22640
2014-10-09 21:52:32 +00:00
Doug Gregor
c4cd133737 Archetype builder: enumerate requirements directly from the potential archetypes.
Use this for the archetype builder debug dump so we can test it
without affecting compilation (yet).

Swift SVN r22639
2014-10-09 21:52:31 +00:00
Doug Gregor
91ddaf59eb Archetype builder: start tracking the locations and reasons for specific requirements.
Whenever we add a requirement, we now know

  (1) Why we added the requirement, e.g., whether it was explicitly written, inferred from a signature, or introduced by an outer scope.
  (2) Where in the source code that requirement originated.

Also add a debugging flag for dumping the archetype builder information, so we can write tests against it.

This is effectively NFC, but it's infrastructure to help a number of requirements-related tasks.

Swift SVN r22638
2014-10-09 21:52:28 +00:00
Ted Kremenek
fad874708e Adjust test cases.
Swift SVN r17964
2014-05-12 22:01:52 +00:00
Doug Gregor
28cc919fb4 Infer conformance requirements from the signature of a generic function.
When a specialization of a generic type occurs within the signature of
a generic function, it implies that the generic arguments meet the
requirements of the generic type. For example, in

  func printHashes<K, V>(dict : Dictionary<K, V>) {
    for (k, v) in dict {
        print("\(k.hashValue())\n")
    } 
  } 

the presence of Dictionary<K, V> in the signature implies that K and V
meet the requirements on Dictionary's generic parameters, i.e., that K
is Hashable. Thus, infer that K is Hashable in printHashes().

Fixes the easy part of <rdar://problem/14691708>. Same-type and
superclass requirements are more interesting.


<rdar://problem/14691708>


Swift SVN r7574
2013-08-26 16:46:38 +00:00