Commit Graph

447 Commits

Author SHA1 Message Date
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
9be2802761 Calls to failable initializers produce the appropriate optional type.
Swift SVN r21295
2014-08-19 21:08:17 +00:00
Dmitri Hrybenko
938e7c2676 stdlib: introduce UnicodeScalarLiteralConvertible protocol
This allows UnicodeScalars to be constructed from an integer, rather
then from a string.  Not only this avoids an unnecessary memory
allocation (!) when creating a UnicodeScalar, this also allows the
compiler to statically check that the string contains a single scalar
value (in the same way the compiler checks that Character contains only
a single extended grapheme cluster).

rdar://17966622

Swift SVN r21198
2014-08-14 16:04:39 +00:00
Joe Pamer
cd4c8f8900 Remove an unnecessary null check that was preventing type member constraints from being added to some freshly opened type variables.
This addresses rdar://problem/17128913, of which there are likely dupes that have yet to be recognized as such.

Swift SVN r21034
2014-08-05 03:01:18 +00:00
Joe Groff
623aba1786 Encapsulate Substitution's state.
Expose Substitution's archetype, replacement, and conformances only through getters so we can actually assert invariants about them. To start, require  replacement types to be materializable in order to catch cases where the type-checker tries to bind type variables to lvalue or inout types, and require the conformance array to match the number of protocol conformances required by the archetype. This exposes some latent bugs in the test suite I've marked as failures for now:

- test/Constraints/overload.swift was quietly suffering from <rdar://problem/17507421>, but we didn't notice because we never tried to codegen it.
- test/SIL/Parser/array_roundtrip.swift doesn't correctly roundtrip substitutions, which I filed as <rdar://problem/17781140>.

Swift SVN r20418
2014-07-23 18:00:38 +00:00
Doug Gregor
bd9ead4371 Remove -[no-]strict-keyword-arguments.
Swift SVN r19850
2014-07-11 16:58:35 +00:00
Chris Lattner
35dcc3aa10 Move the @optional attribute to being a SIMPLE_DECL_ATTR, which
simplifies a bunch of code, makes them more consistent with the
other attributes, and is generally the newfangled way to do things.



Swift SVN r19779
2014-07-10 04:34:00 +00:00
Joe Pamer
470718d44a Add a missing null check to the archetype opener. This unfortunately won't make the new Range work any easier, but it essentially turns rdar://problem/17598049 into rdar://problem/17597651.
Swift SVN r19745
2014-07-09 21:46:29 +00:00
Doug Gregor
2f3f6acf21 Make "true" and "false" Boolean literal constants for the BooleanLiteralConvertible protocol.
Introduce the new BooleanLiteralConvertible protocol for Boolean
literals. Take "true" and "false" as real keywords (which is most of the
reason for the testsuite churn). Make Bool BooleanLiteralConvertible
and the default Boolean literal type, and ObjCBool
BooleanLiteralConvertible. Fixes <rdar://problem/17405310> and the
recent regression that made ObjCBool not work with true/false.


Swift SVN r19728
2014-07-09 16:57:35 +00:00
Jordan Rose
b892892871 Disallow use of TypeBase::getAs/isa/castAs with sugared types.
These methods all act on the desugared type, so the result would always be
false/null.

Also removes a few mistaken uses of getAs caught by this change.

Swift SVN r19585
2014-07-06 22:07:26 +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
Doug Gregor
39bcf3bd85 Re-sugar the types we deduce for type variables.
This makes us deduce types like "[Int]" and "[String : Int]" from
array/dictionary literals, giving a nicer REPL experience.


Swift SVN r19258
2014-06-26 22:04:47 +00:00
John McCall
7effec113c Change ImplicitlyUnwrappedOptional to be an enum type itself,
not a struct wrapping an Optional.

Among other things, this means you can now pattern-match on
an IUO.  It also makes it more convenient to build and destroy
them.

SILGen's type lowering should probably canonicalize one kind
of optional to the other so that we don't get silly abstraction
costs from conversion.

Swift SVN r18991
2014-06-18 23:27:08 +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
Chris Lattner
60fc0e6cd2 Implement <rdar://problem/16951729> nil should be a literal type
This is all goodness, and eliminates a major source of implicit conversions.
One thing this regresses on though, is that we now reject "x == nil" where
x is an option type and the element of the optional is not Equtatable.  If
this is important, there are ways to enable this, but directly testing it as
a logic value is more straight-forward.

This does not include support for pattern matching against nil, that will be
a follow on patch.



Swift SVN r18918
2014-06-15 22:59:03 +00:00
Doug Gregor
0f1f518a17 Type checker: allow dictionary upcasts, including bridging upcasts.
This is the type checker portion of <rdar://problem/17114737>.

Swift SVN r18887
2014-06-14 04:34:44 +00:00
Doug Gregor
1789c4ccbc Collapse CollectionBridgedConversionExpr into CollectionUpcastConversionExpr.
Semantically, these expressions handle the same thing: an upcast of a
collection when the underlying element types of the source are
subtypes of or can be bridged to subtypes of the destination. This
reduces some branching in the type checker and eliminates duplication
in SILGen.

Swift SVN r18865
2014-06-13 16:32:47 +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
Joe Pamer
50ef69c745 Allow for implicit forcing of enumerated unchecked optional values. (rdar://problem/16265970, rdar://problem/16569776, rdar://problem/16931457)
Swift SVN r18145
2014-05-16 00:06:39 +00:00
Joe Pamer
1e5b9116d4 More array casting work:
- Continue adding support for checked downcasts of array types (rdar://problem/16535104)
- Fix non-bridged array conversions post-r17868
- Fix rdar://problem/16773693
- Add tests for NSArray coercions to and from Array<T>

Swift SVN r17957
2014-05-12 20:49:42 +00:00
Doug Gregor
05a283a58c When dealing with argument tuple conversions, keep the parentheses around
This is fairly ugly, because we're halfway between a-function-type-takes-a-tuple and a-function-type-takes-a-set-of-parameters. However, it's another step toward -strict-keyword-arguments.

Swift SVN r17727
2014-05-08 23:20:47 +00:00
Chris Lattner
c8003816ad change this to isa<> since we're using a bool return.
Swift SVN r17684
2014-05-08 05:14:10 +00:00
Chris Lattner
e489a7024a Switch array default construction to its canonical type sugar form
of T[]() instead of Array<T>().

I didn't do this in the guts of Array.swift because the abstraction
is harmful in the implementation of Array itself.

NFC.



Swift SVN r17683
2014-05-08 05:13:08 +00:00
Joe Pamer
edb4946f66 Begin updating type checking of array upcasts to conform with the new spec.
Also, call through DaveA's new entry point for upcasts on Array<T>.

Swift SVN r17564
2014-05-06 21:32:22 +00:00
Joe Pamer
ab576bb84b The constraint solver should try to diagnose all failures, rather than use a catch-all error message.
Swift SVN r17335
2014-05-03 23:03:50 +00:00
Ted Kremenek
4e70269c53 More renaming 'unchecked optional' to 'implicitly unwrapped optional'.
Swift SVN r17236
2014-05-02 06:22:01 +00:00
Ted Kremenek
050fd53af7 Rename UncheckedOptional to ImplicitlyUnwrappedOptional.
Swift SVN r17232
2014-05-02 06:13:57 +00:00
Doug Gregor
3d3ff6811a Add a pile of missing #includes exposed by pruning includes in top-of-tree LLVM.
Swift SVN r17157
2014-05-01 14:26:34 +00:00
Doug Gregor
72e32c93af Make argument names default to keyword arguments in the cases where Objective-C has names.
Introduce a model where an argument name is a keyword argument if: 

  - It is an argument to an initializer, or
  - It is an argument to a method after the first argument, or
  - It is preceded by a back-tick (`), or
  - Both a keyword argument name and an internal parameter name are
    specified. 

Provide diagnostics Fix-Its to clean up cases where the user is
probably confused, i.e.,

  - "_ x: Int" -> "x: Int" where "x" would not have been a keyword
  argument anyway
  - "x x: Int" -> "`x: Int"

This covers the compiler side of <rdar://problem/16741975> and
<rdar://problem/16742001>.

Update the AST printer to print in this form, never printing just 
a type for a parameter name because we're also going to adopt
<rdar://problem/16737312> and it was easier to move the tests once
rather than twice.

Standard library and test updates coming separately.




Swift SVN r17056
2014-04-30 00:04:04 +00:00
Dmitri Hrybenko
669f633070 Add "single extended grapheme cluster" literals (SEGCL) -- a subset of
double-quoted string literals that contain a single extended grapheme cluster

SEGCL by default infer type String, but you can ask to infer Character
for them.

Single quoted literals continue to infer Character.

Actual extended grapheme cluster segmentation is not implemented yet,
<rdar://problem/16755123> Implement extended grapheme cluster
segmentation in libSwiftBasic

This is part of
<rdar://problem/16363872> Remove single quoted characters

Swift SVN r17034
2014-04-29 14:08:16 +00:00
Doug Gregor
321911a059 Add infrastructure for applying fixes during constraint solving.
Introduce some infrastructure that allows us to speculatively apply
localized fixes to expressions during constraint solving to fix minor
typos and omissions. At present, we're able to introduce the fixes
during constraint simplification, prefer systems with fewer fixes when
there are multiple fixes, and diagnose the fixes with Fix-Its.

Actually rewriting the AST to reflect what the Fix-Its are doing is
still not handled.

As a start, introduce a fix that adds '()' if it appears to have been
forgotton, producing a diagnostic like this if it works out:

t.swift:8:3: error: function produces expected type 'B'; did you mean
to call it with '()'?
f(g)
  ^
   ()

Note that we did regress in one test case
(test/NameBinding/multi-file.swift), because that diagnostic was
getting lucky with the previous formulation.

Swift SVN r16937
2014-04-27 19:04:04 +00:00
Joe Pamer
066f5e6da5 Allow for simple upcast conversions between array types. (Part 1 of the fix for rdar://problem/16540403)
Swift SVN r16836
2014-04-25 19:52:05 +00:00
Doug Gregor
53b84c121e Switch ValueDecl::getObjCSelector() and friends over to ObjCSelector.
Formatting names into strings repeatedly, and using those for semantic
analysis, is generally considered poor form. Additionally, use the
camelCase utilities to perform the string manipulation we need, and
cache results on the ObjCAttr so we don't repeatedly do string
manipulation.

Swift SVN r16334
2014-04-14 22:02:51 +00:00
Joe Pamer
18f3bf67b0 More progress towards getting same-type constraints working correctly.
Swift SVN r16023
2014-04-07 21:31:52 +00:00
Joe Pamer
b9fdfe3063 Begin softening some restrictions on self-recursive constraints on associated types. This will prevent cases of infinite recursion while building archetypes.
Swift SVN r16022
2014-04-07 21:31:50 +00:00
John McCall
f1180f5e6d in order to work correctly for non-@objc protocols.
Language features like erasing concrete metatype
values are also left for the future.  Still, baby steps.

The singleton ordinary metatype for existential types
is still potentially useful; we allow it to be written
as P.Protocol.

I've been somewhat cavalier in making code accept
AnyMetatypeType instead of a more specific type, and
it's likely that a number of these places can and
should be more restrictive.
When T is an existential type, parse T.Type as an
ExistentialMetatypeType instead of a MetatypeType.

An existential metatype is the formal type
 \exists t:P . (t.Type)
whereas the ordinary metatype is the formal type
 (\exists t:P . t).Type
which is singleton.  Our inability to express that
difference was leading to an ever-increasing cascade
of hacks where information is shadily passed behind
the scenes in order to make various operations with
static members of protocols work correctly.

This patch takes the first step towards fixing that
by splitting out existential metatypes and giving
them a pointer representation.  Eventually, we will
need them to be able to carry protocol witness tables

Swift SVN r15716
2014-04-01 00:38:28 +00:00
Joe Groff
9f7dab725c Make the ASTContext parameter to MetatypeType::get optional for type-checked types.
We can just get it from the instance type, if the instance type has been fully initialized, which is the case except during parsing of type decls when the decls' own types are being formed.

Swift SVN r15598
2014-03-29 02:50:30 +00:00
Joe Pamer
4bb68502a7 Take more steps towards allowing associated types referenced within constraints to conform to concrete types. This allows me to lift some restrictions I added a couple of weeks ago, and addresses rdar://problem/16333042 and rdar://problem/16284599.
(These changes also address the type-check aspects of rdar://problem/16369105, but there are still some SIL generation issues that I need to work through before I can call that work done.)

Swift SVN r15337
2014-03-21 21:44:59 +00:00
Joe Pamer
d91482ca66 Fix some issues with type parameter resolution.
In a couple of cases, we weren't properly extracting the correct archetype type from generic type parameters.  This was causing various crashes and strange errors throughout the system.  (See rdar://problem/16296421, rdar://problem/16273217, rdar://problem/16329242)

Swift SVN r15213
2014-03-18 23:52:07 +00:00
Joe Pamer
53c69a956f Fix validation of implicit 'self' variable declarations on methods with recursive associated types as constraints. In these cases, the compiler should not crash while type checking member accesses on 'self'. (rdar://problem/16281468)
Swift SVN r14934
2014-03-11 23:42:59 +00:00
Joe Groff
24e9fed6db Sema: Don't create locators with null archetypes.
And remove a stray assert(false) that shouldn't be there that I noticed by inspection.

Swift SVN r14903
2014-03-11 01:56:35 +00:00
Joe Groff
9f12e2e4a4 Enable same-type concrete constraints, e.g. <T: P where T.Assoc == Int>
Let ArchetypeType nested types and PotentialArchetypes be bound to concrete types in addition to archetypes. Constraints to outer context archetypes still suffer type-checker issues, but constraints to true concrete types should work now.

Swift SVN r14832
2014-03-08 17:18:17 +00:00
Joe Pamer
e05e04ab0e Address more feedback for r14800
Swift SVN r14807
2014-03-08 00:03:57 +00:00
Joe Pamer
6fe2917646 John gave me some style advice on r14800 - this change folds in his feedback.
Swift SVN r14803
2014-03-07 23:25:23 +00:00
Joe Pamer
dce0673db1 We should avoid fixing type variables to optional types that wrap the type variable itself. When solving for the type variable, this will lead to the creation of a constraint where the variable is adjacent to itself. Such constraints are not permitted and will cause the compiler to crash. (rdar://problem/15727642)
Swift SVN r14800
2014-03-07 22:47:48 +00:00
Joe Groff
1585b625f9 Sema: Wire up compound name lookup to UnresolvedSelectorExpr.
Resolve selector references using compound name lookup, pushing DeclNames a bit deeper through the type-checker and diagnostics as necessary.

Swift SVN r14791
2014-03-07 20:52:30 +00:00
Joe Pamer
3684658771 When resolving generic type aliases within protocols, the type aliases themselves may be modeled as substitutions, and not strictly as type variables. Not accounting for this lead to rdar://problem/16228026 and rdar://problem/16228058, wherein the compiler could crash if the open type alias was referenced from within a generic type instantiation.
Swift SVN r14746
2014-03-06 19:47:41 +00:00
Chris Lattner
d758e0dfe3 Eliminate more "DynamicLookup" in favor of "AnyObject", this is the
bulk of finishing rdar://13327098.


Swift SVN r14653
2014-03-04 22:15:46 +00:00
Chris Lattner
11bedff2f3 the swift.Slice type got removed a long time ago, being replaced with
what is now Swift.Array.  Update various internal stuff to refer to
Array instead of Slice.  NFC.


Swift SVN r14567
2014-03-02 06:21:37 +00:00
Doug Gregor
d92f1a3158 Inherit complete object initializers when a class supports it.
Teach name lookup to find complete object initializers in its
superclass when the current class overrides all of the subobject
initializers of its direct superclass.

Clean up the implicit declaration of constructors, so we don't rely on
callers in the type checker doing the right thing.

When we refer to a constructor within the type checker, always use the
type through which the constructor was found as the result of
construction, so that we can type-check uses of inherited complete
object initializers. Fixed a problem with the creation of
OpenExistentialExprs when the base object is a metatype.

The changes to the code completion tests are an improvement: we're
generating ExprSpecific completion results when referring to the
superclass initializer with the same signature as the initializer
we're in after "super.".

Swift SVN r14551
2014-03-01 00:51:21 +00:00