Commit Graph

323 Commits

Author SHA1 Message Date
practicalswift
31ff35e1dd Use 80 column headers consistently. 2016-01-04 01:35:02 +01:00
Chris Lattner
6afe77d597 Eliminate the Parameter type completely - now ParameterList is just
an overblown array of ParamDecl*'s that also keeps track of parenlocs
and has helper methods.
2016-01-03 14:45:38 -08:00
Doug Gregor
e1fe27bd5f [Constraint system] Eliminate DependentTypeOpener. NFC
Eliminate the last client of DependentTypeOpener,
RequirementTypeOpener, which tracked the opened Self type when doing
witness/requirement matching and substituted in the known type
witnesses for that protocol. It had a bunch of dead logic hanging
around from the days where we used the constraint system to deduce
type witnesses. Now, a simple substitution suffices.

With its last client gone, remove DependentTypeOpener as well.
2016-01-02 21:51:22 -08:00
Doug Gregor
75cb941440 [Constraint System] Kill the ArchetypeOpener; bind type variables instead. NFC
The ArchetypeOpener was used only to replace dependent types with
archetypes (or concrete types) within the opening context. We can do
the same simply by letting the constraint system create type variables
and then binding those type variables to the appropriate
archetypes/concrete types in that context.

Eliminate the two DependentTypeOpener entry points that were only used
by the ArchetypeOpener.
2016-01-02 15:28:12 -08:00
Chris Lattner
b170b700f8 move the rest of the state out of Parameter and into ParamDecl,
in prep for Parameter going away.  NFC.
2016-01-01 15:27:53 -08:00
Chris Lattner
a30ae2bf55 Merge pull request #836 from zachpanz88/new-year
Update copyright date
2015-12-31 19:36:14 -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
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
practicalswift
149b50d901 Fix typos in code (non-comment/documentation typos). 2015-12-28 11:42:15 +01:00
Slava Pestov
d6ea5d8717 Sema: Chain all generic parameter lists
Previously, methods on DeclContext for getting generic parameters
and signatures did not walk up from type contexts to function
contexts, or function contexts to function contexts.

Presumably this is because SIL doesn't completely support nested
generics yet, instead only handling these two special cases:

- non-generic local function inside generic function
- generic method inside generic type

For local functions nested inside generic functions, SIL expects
the closure to not have an interface type or generic signature,
even if the contextual type signature contains archetypes.
This should probably be revisited some day.

Recall that these cases are explicitly rejected by Sema diagnostics
because they lack SIL support:

- generic function inside generic function
- generic type inside generic function

After the previous patches in this series, it becomes possible to
construct types that are the same as before for the supported uses of
nested generics, while introducing a more self-consistent conceptual
model for the unsupported cases.

Some new tests show we generate diagnotics in various cases that
used to crash.

The conceptual model might still not be completely right, and of
course SIL, IRGen and runtime support is still missing.
2015-12-16 11:32:56 -08:00
Slava Pestov
74e575e638 Sema: Add DeclContext::getGenericTypeContextDepth()
Now that generic signatures of types include generic parameters
introduced by outer generic functions, we need to know to skip
them when forming bound generic types or substitutions.

Add a function that computes the depth of the innermost generic
context that is not a generic type context.
2015-12-15 22:59:38 -08:00
Ge Sen
7ac02d54ba Erase redundant whitespaces. 2015-12-10 13:35:06 +08:00
Doug Gregor
44b8d45288 Clean up inference of default arguments from imported APIs (mostly).
My temporary hackery around inferring default arguments from imported
APIs was too horrible. Make it slightly more sane by:

1) Actually marking these as default arguments in the type system,
rather than doing everything outside of the type system. This is a
step closer to what we would really do, if we go in this
direction. Put it behind the new -frontend flag
-enable-infer-default-arguments.

2) Only inferring a default argument from option sets and from
explicitly "nullable" parameters, as stated in the (Objective-)C API
or API notes. This eliminates a pile of spurious, non-sensical "=
nil"'s in the resulting output.

Note that there is one ugly tweak to the overloading rules to prefer
declarations with fewer defaulted arguments. This is a bad
implementation of what is probably a reasonable rule (prefer to bind
fewer default arguments), which intentionally only kicks in when we're
dealing with imported APIs that have default arguments.

Swift SVN r32078
2015-09-18 21:50:59 +00:00
Chris Lattner
77caeda1ff reduce indentation by using early exits, NFC.
Swift SVN r31743
2015-09-07 22:05:53 +00:00
Chris Lattner
f76cb5b6e6 Comment cleanups etc, and fix the implementation of Solution::hasUnresolvedTypeVars()
which is NFC since it has no callers.


Swift SVN r31742
2015-09-07 21:26:35 +00:00
Joe Pamer
828eb68e72 Commit DaveA's API changes to 'print', along with the compiler changes necessary to support them.
There's still work left to do. In terms of next steps, there's still rdar://problem/22126141, which covers removing the 'workaround' overloads for print (that prevent bogus overload resolution failures), as well as providing a decent diagnostic when users invoke print with 'appendNewline'.

Swift SVN r30976
2015-08-04 01:57:11 +00:00
Joe Pamer
65d804f36b Minor cleanup. NFC.
Swift SVN r30898
2015-08-01 01:45:21 +00:00
Joe Pamer
136cc5a909 Always look through vararg parameters when performing overload resolution. (A step towards a fix for rdar://problem/22056861)
Swift SVN r30896
2015-08-01 01:06:44 +00:00
Joe Pamer
8959a2e957 During overload resolution, if all other things are considered equal, consider empty protocol compositions when comparing refinement, and favor concrete types. (rdar://problem/22044607)
Swift SVN r30865
2015-07-31 20:24:15 +00:00
Joe Pamer
1f8ef258eb For types imported from Objective-C, convenience initializer inheritance may result in two seemingly identical initializers being added to the overload group of an initializer application. In such cases, rather than raise an ambiguity error, we should favor the most derived type's initializer. (rdar://problem/21979968)
Swift SVN r30779
2015-07-30 00:07:29 +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
adab4656fd Follow on to 30163.
Swift SVN r30165
2015-07-13 21:27:01 +00:00
Chris Lattner
c86e8bc0da use default argument, NFC.
Swift SVN r30164
2015-07-13 21:25:16 +00:00
Chris Lattner
85be767182 introduce a new ConstraintSystem::solveSingle helper function to simplify some
clients.  NFC.



Swift SVN r30163
2015-07-13 21:22:24 +00:00
Slava Pestov
e598bfb21b Sema: Fix typos in comments, NFC
Swift SVN r29933
2015-07-07 04:41:49 +00:00
Doug Gregor
bd891ea8f3 Extend the heinous hack for overloading with redeclared protocol requirements.
When two protocol requirements would otherwise be considered
"identical", take the one from the most-refined protocol. This whole
hack *should* go away when we properly handle overriding for protocol
requirements, but for now it fixes rdar://problem/21322215.

Swift SVN r29785
2015-06-29 19:54:32 +00:00
Doug Gregor
a30ca2a60d Replace bool parameter to TypeChecker::conformsToProtocol() with an option set.
NFC; we can extend this option set more readily later.

Swift SVN r27894
2015-04-29 00:08:22 +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
Chris Lattner
79ed57f9f2 standardize naming of tuples and tuple patterns on "elements".
Previously some parts of the compiler referred to them as "fields",
and most referred to them as "elements".  Use the more generic 'elements'
nomenclature because that's what we refer to other things in the compiler
(e.g. the elements of a bracestmt).

At the same time, make the API better by providing "getElement" consistently
and using it, instead of getElements()[i].

NFC.



Swift SVN r26894
2015-04-02 20:23:49 +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
0e74268ea5 Strongly prefer available declarations to unavailable ones in type checking.
Fixes rdar://problem/18847642, rdar://problem/16554496, and the
current 1_stdlib/Array.swift.

Swift SVN r25212
2015-02-12 01:01:11 +00:00
Jordan Rose
003821a956 Value-to-optional conversions are only subtypes for class references.
let x: Int? = 4 as Int // okay
  let f: (Int) -> Void = { (x: Int?) -> Void in println(x) } // error!

As part of this, remove an invalid "protection" of value-to-optional
conversions that involve T? -> T??. Unfortunately, this results in an
ambiguity in the following code:

  var z: Int?
  z = z ?? 42

Both of our overloads for ?? here require one value-to-optional conversion,
and the overload preference isn't conclusive. (Turns out (T?, T) and
(U?, U?) can be unified as T=U or as T=U?.) The best thing to do would be
to take our solved T=Int binding into account, but the type checker isn't
set up to do that at the moment.

After talking to JoeP, I ended up just hardcoding a preference against
the (T?, T?) -> T? overload of ??. This is only acceptable because both
overloads have the same result, and I'll be filing another Radar to
remove this hack in the future.

Part of rdar://problem/19600325

Swift SVN r25045
2015-02-06 20:41:51 +00:00
Doug Gregor
562b529d7a Start simplifying the "dependent type opener" contract.
The archetype opener only needs to perform basic substitutions; let it
do so, avoiding the creation of a pile of type variables that simply
get immediately bound.

Swift SVN r24399
2015-01-13 23:17:52 +00:00
Jordan Rose
2b0fbcbe80 Looking up conformances for a type isn't always a public use of the type.
Specifically, it's not when
- the conformance is being used within a function body (test included)
- the conformance is being used for or within a private type (test included)
- the conformance is being used to generate a diagnostic string

We're still a bit imprecise in some places (checking ObjC bridging), but
in general this means less of an issue for checking literals.

Swift SVN r23700
2014-12-05 00:23:24 +00:00
Jordan Rose
042569a3be Optional: Replace uses of Nothing with None.
llvm::Optional (like Swift.Optional!) uses None as its placeholder value,
not Nothing.

Swift SVN r22476
2014-10-02 18:51:42 +00:00
Doug Gregor
43b6ed364a Thread constraint locators through opening of generic types.
Locators that refer to opened type parameters now carry information
about the source location where we needed to open the type, so that
(for example) we can trace an opened type parameter back to the
location it was opened. As part of this, eliminate the "rootExpr"
fallback, because we're threading constraint locators everywhere.

This is infrastructural, and should be NFC.

Swift SVN r21919
2014-09-12 20:27:19 +00:00
Doug Gregor
692ff2f52a Enable imports of failable initializers by default.
Swift SVN r21699
2014-09-04 06:32:12 +00:00
Doug Gregor
397f4a9888 Remove user-defined conversions from the type checker.
Nobody is using this crufty old feature now, so remove it and the
complexity that goes along with it.

Swift SVN r21379
2014-08-21 21:59:49 +00:00
Doug Gregor
86b59b1294 Add a score kind for value-to-optional bindings, and ban them during partial ordering.
This is the semantic change we need to eliminate ambiguities when
introducing the new ?? overload. There is a minor regression here with
curried method references, which is covered by <rdar://problem/18006008>.


Swift SVN r21173
2014-08-13 16:19:56 +00:00
Doug Gregor
f52c6789db Track the minimum deployment target and use it for 'unavailable' computations.
Swift SVN r20955
2014-08-02 18:05:45 +00:00
Joe Pamer
12e598a4f3 Respond to CR feedback from Jordan:
- Change the comment preceding isDeclMoreConstrainedThan to a doc comment
- Add tests for comparisons between IUO values and 'nil'

Swift SVN r20352
2014-07-23 00:00:24 +00:00
Joe Pamer
e783ab1c0d Support equality comparisons between 'nil' and non-equatable optional types (rdar://problem/17489239)
To facilitate the removal of the BooleanType conformance from Optional<T>, we'll first need to support
equality comparisons between the 'nil' literal and optionals with non-equatable element types.

We can accomplish this via three changes:
- New overloads for "==" and "!=" that we can resolve against non-equatable optionals
- A tweak to our overload resolution algorithm that, when all other aspects of two overloads are
  considered equal, would favor the overload with a more "constrained" type parameter. This allows
  us to avoid ambiguities between generic overloads that are distinct, but whose parameters do not
  share a pairwise subtype relationship.
- A gross hack to favor overloads that do not require bindings to 'nil' when presented with an
  otherwise ambiguous set of solutions. (Essentially, in the face of a potential ambiguity, favor solutions
  that do not require bindings to _OptionalNilComparisonType over those that do.)

The third change is only necessary because we currently lack the ability to specify "negative" or
otherwise more expressive constraints, so we'll want to rethink the hack post-1.0. (I've filed
rdar://problem/17769974 to cover its removal.)

Swift SVN r20346
2014-07-22 22:59:07 +00:00
Doug Gregor
cb8e12368b Remove user conversions (@conversion __conversion) as a user feature.
We still have type checker support for user-defined conversions,
because the importer still synthesizes __conversion functions for CF
<-> NS classes.

Swift SVN r19813
2014-07-10 16:58:44 +00:00
Joe Groff
3c539b7f24 Sema: Look through optional types for .member lookup.
When we see a '.member' expression in optional context, look for the member in the optional's object type if it isn't found in Optional itself. <rdar://problem/16125392>

Swift SVN r19469
2014-07-02 16:33:45 +00:00
Joe Groff
fb7ef8c2a1 Sema: Allow inout-to-pointer conversions for pointers to arrays.
We need to admit a potential inout-to-pointer conversion even if the inout references an array, because we can have pointers to arrays. Add a short-circuit so that array-to-pointer conversions always beat inout-to-pointer conversions; both solutions could otherwise be considered valid for an UnsafePointer<Void>, and passing a pointer to the array reference rather than to the array data would be very bad.

Swift SVN r19270
2014-06-26 22:37:27 +00:00
Joe Groff
08a48565fb Sema: Introduce intrinsic pointer argument conversions.
Add primitive type-checker rules for pointer arguments. An UnsafePointer argument accepts:

- an UnsafePointer value of matching element type, or of any type if the argument is UnsafePointer<Void>,
- an inout parameter of matching element type, or of any type if the argument is UnsafePointer<Void>, or
- an inout Array parameter of matching element type, or of any type if the argument is UnsafePointer<Void>.

A ConstUnsafePointer argument accepts:

- an UnsafePointer, ConstUnsafePointer, or AutoreleasingUnsafePointer value of matching element type, or of any type if the argument is ConstUnsafePointer<Void>,
- an inout parameter of matching element type, or of any type if the argument is ConstUnsafePointer<Void>, or
- an inout or non-inout Array parameter of matching element type, or of any type if the argument is ConstUnsafePointer<Void>.

An AutoreleasingUnsafePointer argument accepts:

- an AutoreleasingUnsafePointer value of matching element type, or
- an inout parameter of matching element type.

This disrupts some error messages in unrelated tests, which is tracked by <rdar://problem/17380520>.

Swift SVN r19008
2014-06-19 18:03:10 +00:00
Doug Gregor
1c06c309bc Automatically reflect non-Foundation categories of bridged Objective-C classes onto their bridged value types.
This makes categories of NSString, NSArray, and NSDictionary available
on String, Array, and Dictionary. Note that we only consider
categories not present in the Objective-C Foundation module, because
we want to manually map those APIs ourselves. Hence, no changes to the
NSStringAPI. Implements <rdar://problem/13653329>.


Swift SVN r18920
2014-06-16 09:07:00 +00:00
Doug Gregor
5ca3882b06 Rename array upcast/bridge expressions to "collection".
This is staging for dictionary bridging upcasts.


Swift SVN r18840
2014-06-12 21:41:55 +00:00
Joe Pamer
1914df72f3 Begin making locators non-optional for constraints.
One difficulty in generating reasonable diagnostic data for type check failures has been the fact that many constraints had been synthesized without regard for where they were rooted in the program source. The result of this was that even though we would store failure information for specific constraints, we wouldn't emit it for lack of a source location. By making location data a non-optional component of constraints, we can begin diagnosing type check errors closer to their point of failure.

Swift SVN r18751
2014-06-09 17:49:46 +00:00