Commit Graph

9116 Commits

Author SHA1 Message Date
Mark Lacey
e83131da30 Assert if we attempt to bind a type involving ErrorType. 2017-07-13 13:22:44 -07:00
Robert Widmann
e3bb2bef64 Prevent potential bindings to ErrorType 2017-07-13 13:22:44 -07:00
Maxim Moiseev
4d70a7c4c5 Merge pull request #10856 from moiseev/color-literal-init
[overlay] Hide the _ExpressibleByColorLiteral initizlier from code completion
2017-07-13 10:40:59 -07:00
swift-ci
f3fec7cb1c Merge pull request #10916 from DougGregor/recursive-protocol-constraints 2017-07-12 16:38:12 -07:00
Pavel Yaskevich
1bafc98b0e Merge pull request #10909 from xedin/rdar-33044867
[QoI] Don't try to lookup members on incorrect type during Objective-C KeyPath validation
2017-07-12 14:29:00 -07:00
Pavel Yaskevich
481401f6c3 [QoI] Don't try to lookup members on incorrect type during Objective-C KeyPath validation
While trying to validate Objective-C keypath components
don't assume that type of the component is always correct, check
before trying to see if it's bridged type or has members.

Resolves: rdar://problem/33044867
2017-07-12 14:04:10 -07:00
Doug Gregor
1e3bd76b75 [Constraint solver] Teach checkTypeOfBinding() to avoid dependent member types.
We don't want to explore these bindings anyway, so reject them earlier.
2017-07-12 12:51:24 -07:00
Max Moiseev
391d49a31e [overlay] Hide the _ExpressibleByColorLiteral initializer from code completion.
Fixes: <rdar://problem/32726800>
2017-07-12 09:05:06 -07:00
Robert Widmann
6ee20e59ab Merge pull request #10488 from CodaFi/a-parametric-equation
Switch over function input matching to use Params
2017-07-11 18:32:36 -07:00
Slava Pestov
c197df6e7f Sema: Fix type checking without applying solution in presence of anonymous closure parameters
Even if we don't apply the solution, we still end up writing
types into ParamDecls of closures contained the expression.

Make sure this is idempotent by disabling 'cleanup', which
avoids setting them to ErrorTypes, and teaching ExprCleaner
to clear out types of VarDecls.

This is a hack that will get better once the constraint
system type map stuff is further along.

Fixes <rdar://problem/33219081>.
2017-07-11 17:00:35 -07:00
Doug Gregor
ff7bfa8b29 [Type checker] Handle inferred @objc for all accessor kinds.
Due to the wanton use of 'if' rather than 'switch', non-observing,
non-get/set ccessors that got marked '@objc' would cause an
assertion. Fix the materializeForSet case from the bug report as well
as the addressor case.

Fixes SR-5025 / rdar://problem/32426538.
2017-07-11 15:41:19 -07:00
Doug Gregor
8def4d8759 [Type checker] Factor out "isBindable" check for matchTypes. NFC
Thanks to Pavel (@xedin) for the feedback.
2017-07-11 15:41:19 -07:00
swift-ci
6e3eeb6799 Merge pull request #10891 from xedin/note-flush-cleanup 2017-07-11 15:40:43 -07:00
Doug Gregor
1e043ab179 Merge pull request #10883 from DougGregor/dont-bind-dependent-member-types
[Type checker] Don't allow type variables to bind to dependent members.
2017-07-11 15:38:58 -07:00
Robert Widmann
d5328ea3cb Switch over function input matching to use Params
Currently handles non-constructor-based applies and function
parameter comparisons.
2017-07-11 15:17:31 -07:00
Pavel Yaskevich
9bfee4e53d [QoI] NFC: Remove use of .flush() when emitting notes for missing try 2017-07-11 15:08:34 -07:00
Slava Pestov
ba7b699b0f Merge pull request #10884 from slavapestov/generic-subscript-materialize-for-set-infer-requirements
Sema: Explicitly infer requirements from subscript element type for materializeForSet
2017-07-11 14:09:58 -07:00
Mark Lacey
2e9dc6b6b4 Merge pull request #10881 from rudkx/fix-rdar33239714
[Constraint system] Improve SE-0110 exception by allowing optional in…
2017-07-11 13:58:45 -07:00
Pavel Yaskevich
6d539117a9 Merge pull request #10838 from xedin/rdar-33040113
[QoI] Provide fix-it for missing "try" when calling throwing function
2017-07-11 13:47:24 -07:00
Alex Hoppen
ec6fc4d54d Merge pull request #9989 from ahoppen/introduce-special-declnames
Introduce special decl names
2017-07-11 22:22:42 +02:00
Slava Pestov
9f6265f99a Sema: Explicitly infer requirements from subscript element type for materializeForSet
The interface type for materializeForSet does not mention the
element type of a subscript, so Sema was not inferring
requirements that were implied by the element type but not
explicitly stated in the generic signature.

This led to assertion failures in SILGen because the
materializeForSet calls the getter and setter, which does
have these requirements.

Fixes <rdar://problem/33219034>, <https://bugs.swift.org/browse/SR-5420>.
2017-07-11 13:18:27 -07:00
Doug Gregor
138b0361d2 [Type checker] Don't allow type variables to bind to dependent members.
When a type variable binds to an (unresolved) dependent member type,
it prevents us from inferring the type variable and adds no useful
information to the system. Refuse to bind type variables to dependent
member types.

Fixes rdar://problem/32697033.
2017-07-11 13:03:16 -07:00
John McCall
928afc6ab8 Merge pull request #10866 from rjmccall/bridging-rework
Substantially rework how SILGen handles bridging
2017-07-11 15:40:23 -04:00
Mark Lacey
8605b29951 [Constraint system] Improve SE-0110 exception by allowing optional injection.
There was an oversight in the exception that was added to SE-0110 to
maintain compatibility for closure arguments. We were not allowing
optional injection to happen for the closure being passed in, so things
like:
  func test(_ fn: ((Int, Int))->()) {}
  test { x, y in }
worked, but
  func test(_ fn: (((Int, Int))->())?) {}
  test { x, y in }
did not.

Fixes SR-5433 (rdar://problem/33239714).
2017-07-11 11:19:28 -07:00
Joe Groff
963c58c4b5 Push subscript label allocation for KeyPathComponents into the root constructor.
A preemptive strike against memory management bugs in the future.
2017-07-11 10:25:56 -07:00
Alex Hoppen
f8c2692f79 Introduce special decl names
Special DeclNames represent names that do not have an identifier in the
surface language. This implies serializing the information about whether
a name is special together with its identifier (if it is not special)
in both the module file and the swift lookup table.
2017-07-11 19:04:13 +02:00
John McCall
7f22faf968 Substantially rework how SILGen handles bridging as part of laying the
ground work for the syntactic bridging peephole.

- Pass source and dest formal types to the bridging routines in addition
  to the dest lowered type.  The dest lowered type is still necessary
  in order to handle non-standard abstraction patterns for the dest type.

- Change bridging abstraction patterns to store bridged formal types
  instead of the formal type.

- Improve how SIL type lowering deals with import-as-member patterns.

- Fix some AST bugs where inadequate information was being stored in
  various expressions.

- Introduce the idea of a converting SGFContext and use it to regularize
  the existing id-as-Any conversion peephole.

- Improve various places in SILGen to emit directly into contexts.
2017-07-11 12:45:13 -04:00
Joe Groff
7a92acbc37 Merge pull request #10870 from jckarter/key-path-failure-diagnosis-with-resolved-components
Sema: Allow KeyPath and KeyPathApplicationExprs to re-type-check during failure diagnosis.
2017-07-11 08:17:01 -07:00
Mark Lacey
8d9f97cdc5 Fix another subtle SE-0110-related break.
The change to roll back a part of SE-0110 to allow multi-argument
functions to be passed in places where functions taking a tuple are
expected resulted in a regression in some cases where the fix would
strip off the last ParenType from single-argument functions.

Instead of stripping off parens from both function types we're trying to
match when they both have them, strip off none. This ensures that we
don't get summarily rejected in the nested matchTypes call by other
SE-0110-related code that bails if the two types do not have the same
"parenness".

Fixes rdar://problem/33043106 / SR-5387.
2017-07-10 17:36:53 -07:00
Joe Groff
51672d3bbf Sema: Allow KeyPath and KeyPathApplicationExprs to re-type-check during failure diagnosis.
Fixes SR-5034 | rdar://problem/32488872.
2017-07-10 16:43:34 -07:00
Joe Groff
8bf2b37856 Merge pull request #10862 from jckarter/key-path-labeled-subscript
Sema: Feed argument label and constraint locator info from key path subscript components into getCalleeDeclAndArgs.
2017-07-10 16:17:34 -07:00
Jordan Rose
1ab51ea3bd Hack: allow dropping noescape-ness when overriding ObjC methods (#10775)
In today's Swift, only non-optional function parameters can be
non-escaping (and are by default). An optional function parameter uses
a function type as a generic argument to Optional, and like any other
generics that's considered an opaque and therefore possibly escaping
use of the type. This is certainly unfortunate since it means a
function parameter cannot be both Optional and non-escaping.

However, this "unfortunate" becomes a concrete problem when dealing
with Objective-C, which /does/ allow applying its 'noescape' attribute
to a callback block marked 'nullable'. This is fine for /uses/ of
methods with such parameters, but prevents anyone from /overriding/
these methods.

This patch pokes a very narrow hole into the override checking to
accomodate this: if a declaration comes from Objective-C, and it has
an optional, non-escaping closure parameter, it's okay to override it
in Swift with an optional, escaping closure parameter. This isn't
strictly safe because a caller could be relying on the
non-escaping-ness, but we don't have anything better for now. (This
behavior will probably be deprecated in the future.)

(Some people have noted that the old 'noescape' type attribute in
Swift still works, albeit with a warning. That's not something people
should have to type, though---we want to remove it from the language,
as described in SE-0103.)

rdar://problem/32903155
2017-07-10 16:03:37 -07:00
Pavel Yaskevich
f6beec681b Merge pull request #10849 from xedin/rdar-33190087
[ConstraintSolver] Fix `shrink` to use correct primary expression as a candidate
2017-07-10 15:05:27 -07:00
Joe Groff
6ad01d63f6 Sema: Feed argument label and constraint locator info from key path subscript components into getCalleeDeclAndArgs.
Fixes SR-5189 | rdar://problem/32713662.
2017-07-10 14:55:08 -07:00
Pavel Yaskevich
78aa1e0cd6 [ConstraintSolver] Fix shrink to use correct primary expression as a candidate
When trying to identify candidates for shrinking we are missing the case
when apply expression is a source of the assignment operator, which leads
to incorrect results in some situations, because shrink is going to miss
some required contextual information about assignment.

Resolves: rdar://problem/33190087
2017-07-10 12:28:54 -07:00
Doug Gregor
f03685b6d0 Introduce a command-line option to limit the # of typo corrections.
Typo correction can be particularly expensive, so introduce a
command-line flag to limit the number of typo corrections we will
perform per type-checker instance. Default this limit to 10.

Addresses rdar://problem/28469270 to some extent.
2017-07-10 11:40:35 -07:00
Doug Gregor
a6516a90c6 [Type checker] Bump warning about unavailable witnesses to an error in Swift 4
Swift 3 allowed a requirement to be satisfied by an unavailable
witness, which doesn't make sense. We've been warning about it in
Swift 3 for a while; make it an error in Swift 4.
2017-07-10 11:40:35 -07:00
Pavel Yaskevich
b7ab7491e6 [QoI] Provide fix-it for missing "try" when calling throwing function
When calling a throwing function without 'try', let's suggest multiple
possibilities of note + fix-it for user to choose from.

Resolves: rdar://problem/33040113
2017-07-09 19:22:43 -07:00
Mark Lacey
de0d0ba7c4 Merge pull request #10835 from rudkx/enable-type-map
[Constraint system] A few more type map updates.
2017-07-09 17:49:38 -07:00
Mark Lacey
6eb71e4d51 [Constraint system] A few more type map updates. 2017-07-09 13:24:42 -07:00
Mark Lacey
63601ae24e Merge pull request #10834 from rudkx/refactor-binding-code
[Constraint system] Begin refactoring type variable binding selection.
2017-07-09 13:09:44 -07:00
Mark Lacey
916ce8994b [Constraint system] Update type map code for recursion through salvage().
When we track which expressions we're already in the middle of type
checking, we need to ensure that we also track the constraint system
which has the types for that expression, and then transfer those types
into our current constraint system so that we do not fail to look them up.
2017-07-09 12:11:31 -07:00
Mark Lacey
7cd4102d01 [Constraint system] Begin refactoring type variable binding selection.
Split out the code for selecting potential bindings into a separate file
as a first step before refactoring it for improved clarity and ease of
modification.
2017-07-09 10:29:42 -07:00
Joe Groff
04453d1ddc Merge pull request #10810 from jckarter/keypath-apply-lvalue
Sema: Coerce [keyPath:] index to rvalue.
2017-07-07 13:50:08 -07:00
Joe Groff
a3c6dbc469 Sema: Coerce [keyPath:] index to rvalue.
Fixes SR-5384 | rdar://problem/33160409.
2017-07-07 10:31:32 -07:00
Robert Widmann
9a4fb8c2f0 Merge pull request #10790 from CodaFi/disjunction-junction
[Gardening] Rename getInOutOrLValueObjectType to getWithoutSpecifierType
2017-07-06 11:28:21 -07:00
Pavel Yaskevich
be204f27d2 Merge pull request #10779 from xedin/rdar-33135487
[QoI] Don't try to lookup members on incorrect type while diagnosing keypath components
2017-07-06 10:04:42 -07:00
Robert Widmann
957d633185 Rename getInOutOrLValueObjectType to getWithoutSpecifierType
Prepares the AST for a future in which more than just inout and
@lvalue need to be stripped off of ephemeral types.
2017-07-06 09:35:04 -07:00
Alex Hoppen
ff6747de77 Merge pull request #10745 from ahoppen/diagnostics-adjustments-declname
[Diag] Change function diagnostics to take a DeclName parameter
2017-07-06 13:26:56 +02:00
Alex Hoppen
4534e2fbf7 Merge pull request #10744 from ahoppen/diagnostics-adjustment
Diagnostic adjustment DeclBaseName -> Identifier
2017-07-06 13:26:35 +02:00