Commit Graph

790 Commits

Author SHA1 Message Date
Chris Lattner
55fbe5a763 Remove Boolean as a special, privileged type used by Sema, and instead
use the concrete Bool type.  This eliminates a bunch of complexity and
makes diagnostics more concrete.
2016-07-17 15:14:24 -07:00
Robert Widmann
f97e5dcb0e [SE-0115][1/2] Rename *LiteralConvertible protocols to ExpressibleBy*Literal. This
change includes both the necessary protocol updates and the deprecation
warnings
suitable for migration.  A future patch will remove the renamings and
make this
a hard error.
2016-07-12 15:25:24 -07:00
Mark Lacey
30158adbf1 Merge pull request #3207 from rudkx/favor-call-overloads-cleanup
Minor clean-up of favorCallOverloads().
2016-06-30 08:02:45 -07:00
Ben Langmuir
d1fd8adbc4 [CodeCompletion] Workaround a bunch of issues with ErrorType in completion
The brief explanation is that we are using the type-checker in a
questionable way where for various reasons we can type-check the same
"context" expression more than once. Until we figure out how to stop
doing that, at least avoid this obvious source of issues with ErrorType
showing up during the initial (poor) typecheck and then blocking
progress when we do a more specific check later.

rdar://problem/26462306
rdar://problem/25248190
2016-06-27 16:50:30 -07:00
Mark Lacey
014633882e Minor clean-up of favorCallOverloads().
Small code shuffling to put related code together and a break from the
main loop earlier.

NFC.
2016-06-25 11:59:36 -07:00
John McCall
ddf49af810 Handle invalid contexts when computing the super type. 2016-06-22 08:48:12 -07:00
Slava Pestov
bbefeb2fc5 Sema: Better support for nested generic functions
There was a weird corner case with nested generic functions that
would fail in the SIL verifier with some nonsense about archetypes
out of context.

Fix this the "right" way, by re-working Sema function declaration
validation to assign generic signatures in a more principled way.

Previously, nested functions did not get an interface type unless
they themselves had generic parameters.

This was inconsistent with methods nested inside generic types,
which did get an interface type even if they themselves did not
have a generic parameter list.

There's some spill-over in SILGen from this change. Mostly it
makes things more consistent and fixes some corner cases.
2016-06-13 01:22:43 -07:00
Joe Groff
e72af82f04 Remove the unused isSome Optional intrinsics.
We already have detailed knowledge of Optional's layout in SILGen, so these intrinsics were almost unused. They were only used in a few obscure places by some optional-to-bool conversions, used by 'is [A]' collection tests and the codegen for 'lazy' properties. Change these over to generate an EnumIsCaseExpr that we can directly lower to a 'select_enum' instruction in SILGen, leading to better codegen and obviating the need for these intrinsic functions.
2016-06-08 09:31:47 -07:00
Argyrios Kyrtzidis
53847121f3 [IDE/Complete] Fix a bug where 'indices' property from Collections doesn't show up for code-completion.
rdar://26642818
2016-06-06 10:17:54 -07:00
Doug Gregor
01682af23a Revert "[Type checker] Be more rigorous about extracting argument labels from calls."
This reverts commit 93dac8f759.
2016-06-03 16:29:31 -07:00
Doug Gregor
93dac8f759 [Type checker] Be more rigorous about extracting argument labels from calls.
Whenever we have a call, retrieve the argument labels from the
argument structurally and associate them with the callee. We were
previously doing this as a separate AST walk (which was unnecessary),
so fold that into constraint generation for a CallExpr.

This is a slightly-pared-back version of
3753d779bc that isn't so rigid in its
interpretation of ASTs. I'll tighten up the semantics over time.
2016-06-03 14:45:21 -07:00
Doug Gregor
ee85891d11 Revert "[Type checker] Be more rigorous about extracting argument labels from calls."
This reverts commit 3753d779bc. It's
causing some type-inference problems I need to investigate.
2016-06-03 10:21:27 -07:00
Slava Pestov
0f17b899ae Sema: Remove some debug code, NFC 2016-06-02 18:20:17 -07:00
Doug Gregor
3753d779bc [Type checker] Be more rigorous about extracting argument labels from calls.
Whenever we have a call, retrieve the argument labels from the
argument structurally and associate them with the callee. We were
previously doing this as a separate AST walk (which was unnecessary),
so fold that into constraint generation for a CallExpr. We were also
allowing weird ASTs to effectively disable this information: tighten
that up and require that CallExprs always have a ParenExpr, TupleExpr,
or (as a temporary hack) a TypeExpr whose representation is a
TupleTypeRepr as their argument prior to type checking. This gives us
a more sane AST to work with, and guarantees that we aren't losing
label information.

From the user perspective, this should be NFC, because it's mostly AST
cleanup and staging.
2016-06-02 17:15:51 -07:00
Joe Pamer
39e7c77a47 When generating constraints for subscript expressions, look beyond array
slice types when deciding whether or not to create a fresh type variable
for the array's base expression. (rdar://problem/2639230)
2016-05-23 15:56:20 -07:00
Doug Gregor
9f0cec4984 SE-0062: Implement #keyPath expression.
Implement the Objective-C #keyPath expression, which maps a sequence
of @objc property accesses to a key-path suitable for use with
Cocoa[Touch]. The implementation handles @objc properties of types
that are either @objc or can be bridged to Objective-C, including the
collections that work with key-value coding (Array/NSArray,
Dictionary/NSDictionary, Set/NSSet).

Still to come: code completion support and Fix-Its to migrate string
literal keypaths to #keyPath.

Implements the bulk of SR-1237 / rdar://problem/25710611.
2016-05-18 23:30:15 -07:00
John McCall
a1c1693529 Change the names of the object-literal initializers to be
semantically unambiguous.

We didn't actually intend to change how programmers normally
constructed these types, but the change to the object literal
syntax accidentally caused these initializers to have very
natural-seeming signatures.  These initializers also created
possible ambiguities with the actual initializers.  Renaming
them to refer to their function as literal initializers is the
right thing to do.

Unfortunately, this provided to be somewhat annoying, as the
code was written to assume that the argument tuple following
e.g. #colorLiteral could be directly passed to the initializer.
We solve this by hacking on both ends of the constraint system:
during generation we form a conversion constraint to the
original, idealized parameter type, and during application we
rewrite the argument tuple type to use the actual labels.
This nicely limits the additional complexity to just the
parts dealing with object literals.

Note that we can't just implicitly rewrite the tuple expression
because that would break invariants tying the labels to physical
source ranges.  We also don't want to just change the literal
syntax again and break compatibility with existing uses.

rdar://26148507
2016-05-13 10:33:37 -07:00
Alex Hoppen
d2e045c8b5 Implement SE-0064 / SR-1239: #selector for property getters and setters
Implements the core functionality of SE-0064 / SR-1239, which
introduces support for accessing the Objective-C selectors of the
getter and setter of an @objc property via #selector(getter:
propertyName) and #selector(setter: propertyName).

Introduce a bunch of QoI around mistakes using #selector to refer to a
property without the "getter:" or "setter:", using Fix-Its to help the
user get it right. There is more to do in this area, still, but we
have an end-to-end feature working.

Much of the implementation and nearly all of the test cases are from
Alex Hoppen (@ahoppen). I've done a bit of refactoring, simplified the
AST representation, and replaced Alex's custom
expression-to-declaration logic with an extension to the constraint
solver. The last bit might be short-lived, based on swift-evolution
PR280, which narrows the syntax of #selector considerably.
2016-05-11 16:51:27 -07:00
Joe Pamer
2cdd7d64e1 "Sober up" the type checker by improving type inference over dictionary
literals that lack a contextual type.

This fixes SR-305
2016-04-26 17:39:13 -07:00
Ted Kremenek
b8bbed8c13 [WIP] Implement SE-0039 (Modernizing Playground Literals) (#2215)
* Implement the majority of parsing support for SE-0039.

* Parse old object literals names using new syntax and provide FixIt.

For example, parse "#Image(imageLiteral:...)" and provide a FixIt to
change it to "#imageLiteral(resourceName:...)".  Now we see something like:

test.swift:4:9: error: '#Image' has been renamed to '#imageLiteral
var y = #Image(imageLiteral: "image.jpg")
        ^~~~~~ ~~~~~~~~~~~~
        #imageLiteral resourceName

Handling the old syntax, and providing a FixIt for that, will be handled in a separate
commit.

Needs tests.  Will be provided in later commit once full parsing support is done.

* Add back pieces of syntax map for object literals.

* Add parsing support for old object literal syntax.

... and provide fixits to new syntax.

Full tests to come in later commit.

* Improve parsing of invalid object literals with old syntax.

* Do not include bracket in code completion results.

* Remove defunct code in SyntaxModel.

* Add tests for migration fixits.

* Add literals to code completion overload tests.

@akyrtzi told me this should be fine.

* Clean up response tests not to include full paths.

* Further adjust offsets.

* Mark initializer for _ColorLiteralConvertible in UIKit as @nonobjc.

* Put attribute in the correct place.
2016-04-25 07:19:26 -07:00
Chris Willmore
02a6be6d01 Allow parsing of function types in expr position (#2273)
Previously it was not possible to parse expressions of the form

    [Int -> Int]()

because no Expr could represent the '->' token and be converted later
into a FunctionTypeRepr. This commit introduces ArrowExpr which exists
solely to be converted to FunctionTypeRepr later by simplifyTypeExpr.

https://bugs.swift.org/browse/SR-502
2016-04-22 21:53:26 -07:00
Xi Ge
94187180a6 [CodeCompletion] Remove code completion results from extensions that can never apply. rdar://24562621 2016-04-08 16:32:47 -07:00
John McCall
563057ca98 When performing member lookup into a type during type-checking,
immediately discard as non-viable any declarations that cannot be
called due to argument-label mismatch.

This heuristic already existed, but it was badly out-of-date vs.
the current language rules on argument-passing.  Change it to use
the standard argument matching algorithm.

This greatly reduces the number of overloads we consider for certain
kinds of expression, most importantly explicit initialization syntax
('T(x)').  Ordinary type-matching will quickly reject such calls,
but backtracking will discard this rejection.  Thus this heuristic
can greatly decrease the total work done by the type-checker when
something else in the system is causing a combinatorial explosion.

The diagnostic changes in the test-suite seem acceptable to me.

Shout-out to Doug for pointing out multiple places where I didn't
need to reinvent the wheel.
2016-04-08 09:39:04 -07:00
practicalswift
abfecfde17 [gardening] if ([space]…[space]) → if (…), for(…) → for (…), while(…) → while (…), [[space]x, y[space]] → [x, y] 2016-04-04 16:22:11 +02:00
practicalswift
798877ae77 [gardening] "if (foo)[SPACE][SPACE]{" → "if (foo)[SPACE]{" 2016-04-03 22:57:05 +02:00
Ge Sen
5ad36b2962 [gardening] Put white spaces in between if/while clauses and braces where it is missing.
For instance:

'if (foo){' => 'if (foo) {'
2016-04-02 14:43:45 +08:00
Michael Gottesman
7361e35bb9 Revert "Putting white spaces in between if/while clauses and braces." 2016-04-01 22:00:25 -07:00
Ge Sen
7dd61bdfa9 [gardening] Put white spaces in between if/while clauses and braces where it is missing.
For instance:

'if (foo){' => 'if (foo) {'
2016-04-02 08:22:23 +08:00
Xi Ge
37f5a0390a [SourceKit] DocInfo: Add a new entry to indicate the default implementation of a protocol member in its extensions. rdar://25032869 2016-03-30 14:26:17 -07:00
Xi Ge
b313668ca2 IDETypeChecking: Add a function to collect protocol members who have default implementations in protocol extensions. Need for rdar://25032869 2016-03-29 18:01:53 -07:00
Alex Hoppen
b8f5c8a1a4 [Sema] Fixed SR-1062: Coercion in single expression closure with invalid signature caused segmentation fault 2016-03-28 10:50:04 +02:00
Xi Ge
92d520c885 ModulePrinting: Using constraint solver to decide the right overload to print in synthesized extensions. 2016-03-24 12:16:51 -07:00
gregomni
2c51abfe15 [SR-995] Handle name changes to ArrayLiteralConvertible associated type
This is just being more general and defensive to handle name changes in
the stdlib.
2016-03-23 19:32:54 -07:00
Xi Ge
b4d0cb4ffe ModulePrinting: Avoid printing duplicated members in synthesized extensions. 2016-03-23 15:19:16 -07:00
Max Moiseev
02006f20bc Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-09 16:05:03 -08:00
Ben Langmuir
95fed2af61 Make canSatisfy static 2016-03-08 20:49:23 -08:00
Max Moiseev
1fae0d1325 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-08 12:48:48 -08:00
Xi Ge
fb00e16a22 IDETypeChecking: Never replace archetypes with type variables when checking if two types eqaul. 2016-03-07 13:27:54 -08:00
Max Moiseev
7fe6916bf6 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-07 12:10:47 -08:00
Xi Ge
326514e397 ModulePrinting: when printing synthesized extensions, avoid printing requirements that are known to be true. 2016-03-03 17:42:35 -08:00
Max Moiseev
cf4bafe9e3 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-03-03 13:22:03 -08:00
Xi Ge
2f41702dd9 IDETypeChecking: Add two utilities canPossiblyConvertTo() and canPossiblyEqual(). 2016-03-02 12:28:02 -08:00
Xi Ge
4e8c8ffe07 IDETypeChecking: Add two utilities to IDETypeChecking.h which are isEqual() and LookUpTypeInContext(). NFC 2016-03-01 15:44:41 -08:00
Max Moiseev
a49dab6bf8 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-29 12:08:52 -08:00
Andrew Trick
445cdff829 Merge pull request #1468 from atrick/attr-kind
Move enums into AttrKind.h.
2016-02-27 21:20:11 -08:00
Dmitri Gribenko
a9f8d97d3e Replace 'unsigned int' with 'unsigned'
'unsigned' is more idiomatic in LLVM style.
2016-02-27 16:20:27 -08:00
Andrew Trick
ff02652108 Move enums into AttrKind.h.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.

PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
2016-02-26 21:10:22 -08:00
Joe Pamer
927d7f254d When analyzing an expression for linked sub-expressions, consider each component of an IfExpr separately.
This fixes rdar://problem/24707022
2016-02-25 17:18:07 -08:00
Max Moiseev
488b464f10 Merge remote-tracking branch 'origin/master' into swift-3-api-guidelines 2016-02-25 12:21:56 -08:00
Han Sangjin
7f4f3d2c70 Changed uint to unsigned int
The uint is not a standard C/C++ type. Some compiler environment may fail with it.
2016-02-25 14:09:03 +09:00