Commit Graph

1378 Commits

Author SHA1 Message Date
Hamish
ab820497ad [Sema] Don't treat non-class archetypes as non-optional when casting to them 2018-02-07 11:34:30 +00:00
Arnold Schwaighofer
5f595ac430 Merge pull request #14411 from aschwaighofer/sema_require_layout_generic_params
Sema: Request the layout for generic parameters if there is a body
2018-02-06 06:18:21 -08:00
Mark Lacey
be8defb29e Rename lookThroughAllAnyOptionalTypes to lookThroughAllOptionalTypes. 2018-02-05 23:59:01 -08:00
Mark Lacey
7f805ba2bc Replace classifyAsOptionalType with isOptionalDecl. 2018-02-05 23:59:00 -08:00
Mark Lacey
b4b66bc8e8 Replace getAnyOptionalObjectType with getOptionalObjectType. 2018-02-05 23:59:00 -08:00
Arnold Schwaighofer
ea6308994d Sema: Request the layout for generic parameters if there is a body
Generic parameters can become sources of metadata types and
conformances. To access them the layout needs to be available to IRGen.

rdar://37086144
SR-6879
2018-02-05 10:12:47 -08:00
Mark Lacey
3654dcc8fe Remove getImplicitlyUnwrappedOptionalObjectType. 2018-02-03 10:57:11 -08:00
Mark Lacey
3f9689e477 Remove lookThroughImplicitlyUnwrappedOptionalType. 2018-02-03 10:57:10 -08:00
Mark Lacey
8d115b8e73 Revert "Allow inout arguments that differ in optionality than the expected parameter."
This partially reverts commit 8685ee01a1.

The tests are still in place, but the code change is no longer necessary
now that IUOs are removed from the type system.

Fixes: rdar://problem/37013789
2018-01-31 12:15:58 -08:00
Mark Lacey
f08823757a IUO: Generate Optional<T> rather than ImplicitlyUnwrappedOptional<T>.
Stop creating ImplicitlyUnwrappedOptional<T> so that we can remove it
from the type system.

Enable the code that generates disjunctions for Optional<T> and
rewrites expressions based on the original declared type being 'T!'.

Most of the changes supporting this were previously merged to master,
but some things were difficult to merge to master without actually
removing IUOs from the type system:
- Dynamic member lookup and dynamic subscripting
- Changes to ensure the bridging peephole still works

Past commits have attempted to retain as much fidelity with how we
were printing things as possible. There are some cases where we still
are not printing things the same way:
- In diagnostics we will print '?' rather than '!'
- Some SourceKit and Code Completion output where we print a Type
  rather than Decl.

Things like module printing via swift-ide-test attempt to print '!'
any place that we now have Optional types that were declared as IUOs.

There are some diagnostics regressions related to the fact that we can
no longer "look through" IUOs. For the same reason some output and
functionality changes in Code Completion. I have an idea of how we can
restore these, and have opened a bug to investigate doing so.

There are some small source compatibility breaks that result from
this change:
- Results of dynamic lookup that are themselves declared IUO can in
  rare circumstances be inferred differently. This shows up in
  test/ClangImporter/objc_parse.swift, where we have
    var optStr = obj.nsstringProperty
  Rather than inferring optStr to be 'String!?', we now infer this to
  be 'String??', which is in line with the expectations of SE-0054.
  The fact that we were only inferring the outermost IUO to be an
  Optional in Swift 4 was a result of the incomplete implementation of
  SE-0054 as opposed to a particular design. This should rarely cause
  problems since in the common-case of actually using the property rather
  than just assigning it to a value with inferred type, we will behave
  the same way.
- Overloading functions with inout parameters strictly by a difference
  in optionality (i.e. Optional<T> vs. ImplicitlyUnwrappedOptional<T>)
  will result in an error rather than the diagnostic that was added
  in Swift 4.1.
- Any place where '!' was being used where it wasn't supposed to be
  allowed by SE-0054 will now treat the '!' as if it were '?'.
  Swift 4.1 generates warnings for these saying that putting '!'
  in that location is deprecated. These locations include for example
  typealiases or any place where '!' is nested in another type like
  `Int!?` or `[Int!]`.

This commit effectively means ImplicitlyUnwrappedOptional<T> is no
longer part of the type system, although I haven't actually removed
all of the code dealing with it yet.

ImplicitlyUnwrappedOptional<T> is is dead, long live implicitly
unwrapped Optional<T>!

Resolves rdar://problem/33272674.
2018-01-31 12:15:58 -08:00
Mark Lacey
f19c6a1417 Merge pull request #14242 from rudkx/rdar36913150
Allow inout arguments that differ in optionality than the expected pa…
2018-01-29 16:56:17 -08:00
Mark Lacey
8685ee01a1 Allow inout arguments that differ in optionality than the expected parameter.
Allow passing Optional<T> as inout where
ImplicitlyUnwrappedOptional<T> is expected, and vice-versa.

Swift 4.1 added a warning that overloading inouts by kind of optional
was deprecated and would be removed, but we didn't actually allow
people to remove an overload and pass arguments of the other kind of
optional to the remaining function.

Fixes rdar://problem/36913150
2018-01-29 15:07:44 -08:00
Joe Shajrawi
b267c1254d Sema: request member layout in the subscript_expr
The subscript_expr typechecker path is different than extension deceleration one - in rdar://problem/36704036, When doing emitVirtualMethodValue in IRGen we can miss the correct offset because we have a bad ClassDecl, The ClassDecl is junk / null

This PR makes said subscript_expr -> call_expr path Behave correctly by request the class layout
2018-01-25 15:24:16 -08:00
Mark Lacey
1ee740f906 Remove some disabled code to quiet the compiler build.
These will be re-enabled once IUOs are removed from the type system.
2018-01-23 17:46:29 -08:00
Mark Lacey
f86e9edf08 Add support for key paths for the new IUO implementation.
Should be strictly NFC at the moment since shouldForceUnwrapResult is always false on master.
2018-01-21 13:40:36 -08:00
Mark Lacey
7ce1ab764e Remove a direct setType on an expr in the constraint system.
Noticed by inspection.
2018-01-15 10:47:11 -08:00
Slava Pestov
9ff97367df AST: Rename hasFixedLayout() to isResilient() and flip polarity
In IRGen we call this isResilient() already in IRGen, and it's
more consistent to call it the same thing everywhere.
2018-01-11 21:57:42 -08:00
Argyrios Kyrtzidis
a70d67fab1 Merge pull request #13878 from akyrtzi/fix-crash-invalid-entity-walker
[AST] Make sure that if a TupleExpr is created with element names but not name locations, it is marked implicit as appropriate
2018-01-11 16:22:28 -08:00
Argyrios Kyrtzidis
f7e897ec4a [AST] Make sure that if a TupleExpr is created with element names but not name locations, it is marked implicit as appropriate
Fixes a crash for SourceEntityWalker which assumed that a non-implicit TupleExpr has source locations for its name elements.

Fixes SR-6517, rdar://35830880
2018-01-11 12:57:03 -08:00
Mark Lacey
43aebc832e Revert "IUO: Add support for non-subscript dynamic lookup." 2018-01-10 22:53:56 -08:00
Mark Lacey
a47d1f87c1 IUO: Add support for non-subscript dynamic lookup.
The subscript case will require some additional refactoring to
support.
2018-01-10 16:36:24 -08:00
Mark Lacey
33fcd72939 IUO: Small refactoring in support of dynamic lookup and keypaths.
Small refactoring which will make supporting dynamic lookup and
keypaths easier.
2018-01-10 16:13:50 -08:00
Mark Lacey
08e45b7a68 Merge pull request #13811 from rudkx/iuo-disjunctions-disabled
IUO: Create disjunctions for optional choices.
2018-01-08 18:32:42 -08:00
Mark Lacey
ad1dbac694 IUO: Create disjunctions for optional choices.
When binding an optional value, or function that returns an optional
value, if that value was produced from a decl that was declared an
IUO, create a disjunction.

After solving, make use of the disjunction choices in rewriting
expressions to force optionals where needed.

This is disabled for now, as it results in a source compatibility
issue without associated changes that actually start generating
Optional<T> in place of ImplicitlyUnwrappedOptional<T>. It's
complicated, but basically having two '??' (one returning T, one
returning T?) and creating a disjunction where the first (favored)
choice is ImplicitlyUnwrappedOptional<T> and second is T results in
our selecting the wrong '??' in some cases.
2018-01-08 14:31:03 -08:00
Arnold Schwaighofer
498f30bf0c Default argument generators of functions must return 'noescaping' function types
A default argument generator must not return a @noescape function type.
Returning a @noescape function is nonsense. That means the function escapes.

* Assert that we don't return @noescape function types
* Fix for throwing default arguments
* Add more test cases
* Adapt to mangling changes

Part of:
SR-5441
rdar://36116691
2018-01-08 07:53:06 -08:00
Mark Lacey
8dd11c0ad7 IUO: Fix the diagnostic for chaining from non-failable to failable init.
Rather than using the optional kind of the result type of the ctor we
chain to, check to see whether it has the IUO attribute set.
2018-01-06 20:02:18 -08:00
Slava Pestov
fbab72bd81 Sema: Fix crash when coercing a closure literal returning one uninhabited type to another
Silly corner case. Fixes <https://bugs.swift.org/browse/SR-4963>.
2018-01-05 23:41:41 -08:00
Mark Lacey
dbb293289a IUO: Replace one ConstraintLocator with two.
Replace ImplicitlyUnwrappedCoercionResult with the more general
ImplicitlyUnwrappedValue.

Add ImplicitlyUnwrappedDisjunctionChoice as a marker that indicates
that we've already created a disjunction from an
ImplicitlyUnwrappedValue, in order to avoid infinite recursion during
binding.

Also add support to buildDisjunctionForImplicitlyUnwrappedOptional for
functions returning optionals.

NFC.
2018-01-04 10:30:25 -08:00
Mark Lacey
8d86619fd7 IUO: Put the pieces in place to handle coercions and casts to IUO types.
For casts like 'x as T!' or 'x as! T!', generate a disjunction that
attempts to bind both the optional and non-optional T, preferring the
optional branch of the disjunction.

Note that this should effectively be NFC at the moment because we're
still generating the IUO type for T! rather than a plain optional, so
we first attempt the IUO type (as opposed to an Optional<T>) which
goes through existing logic that handles the IUOs as part of the type
system.

The new rewriting logic will actually do something once we switch over
to generating Optional<T> when T! is uttered.
2018-01-04 05:12:05 -08:00
swift-ci
d55466deea Merge pull request #13715 from rudkx/tweak-pointer-decl 2018-01-03 22:22:02 -08:00
Mark Lacey
347b52517a Minor tweak: Make it clear an auto variable is a pointer. 2018-01-03 21:32:34 -08:00
Mark Lacey
d1bb36425d IUO: Add overload choice kind for IUO decls.
Add a new OverloadChoiceKind for decls that are either IUO-typed, or
function-typed meaning that the function result type is IUO-typed.

Not currently used, so NFC.
2018-01-03 19:37:06 -08:00
David Zarzycki
1040d18227 [AST] NFC: Tail allocate TupleShuffleExpr data 2017-12-21 08:52:13 -05:00
David Zarzycki
dbb421ba95 [AST] NFC: Tail allocate ErasureExpr conformances 2017-12-20 09:35:15 -05:00
David Zarzycki
60d2f5586e [AST] QoI: Track DictionaryExpr commas and tail allocate CollectionExpr comma locs 2017-12-19 13:33:09 -05:00
Slava Pestov
bc990d38a8 Sema: Fix keypaths vs. lazy member validation
Constructing a keypath expression that references a class member
needs to validate all other members of the class (or a protocol,
but I couldn't reproduce a crash with that case -- added a test
anyway).

Fixes <rdar://problem/36083061>.
2017-12-17 19:10:18 -08:00
Mark Lacey
12e7caf5d7 Merge pull request #13357 from rudkx/remove-param-from-coerce-iuo-to-value
NFC: Remove unused locator param from coerceImpicitlyUnwrappedOptiona…
2017-12-10 13:50:50 -08:00
Mark Lacey
7eafe07f59 NFC: Remove unused locator param from coerceImpicitlyUnwrappedOptionalToValue. 2017-12-10 12:32:51 -08:00
Slava Pestov
336a97bc1a Sema: Diagnose invalid 'self.init' delegation where 'self' is an archetype
This is a corner case but would previously lead to a compiler crash
or miscompile.

Fixes <rdar://problem/21991470>, <https://bugs.swift.org/browse/SR-5022>.
2017-12-08 17:46:16 -08:00
Slava Pestov
71afed85d4 Sema: Clean up 'polymorphic use of non-required initializer' diagnostic 2017-12-08 17:46:16 -08:00
Doug Gregor
dc8b970051 [SE-0143] Eliminate assertions blocking the use of conditional conformances.
Early on in the development of conditional conformances, we put in a bunch
of assertions for code that uses `conformsToProtocol()` but wasn't handling
conditional conformances. Now, `conformsToProtocol()` handles conditional
conformances by default, and these assertions are tripping up code
that would work.

Remove the assertions and add test cases that used to trip up the
assertions (but now work).
2017-12-04 11:28:00 -08:00
Mark Lacey
fda51bb6b2 [ConstraintSystem] Eliminate the notion of FixKind::None
These purportedly mark that we should stop attempting fixes for a given
constraint, but in fact the only code creating these is clearly
unreachable so these serve no purpose.
2017-12-01 16:18:16 -08:00
Doug Gregor
e3a5318b97 [Type checker] Teach conformsToProtocol() to check conditional requirements.
conformsToProtocol() is the main way in which we check whether a given type
conforms to a given protocol. Extend it to check conditional requirements by
default, so that an unmodified caller will get the "does not conform" result
(with diagnostics when a location is present) rather than simply ignoring
the conditional requirements.

Some callers take responsibility for conditional requirements, e.g., to
push them into the constraint system. Allow those callers to opt out of
this checking, and do so wherever appropriate.

Fixes rdar://problem/35518088, where we were ignoring the conditional
requirements needed to verify that Equatable synthesis could be performed.
2017-11-21 21:02:00 -08:00
Doug Gregor
0b4b05a67b [Constraint application] Remove a bogus assertion.
THe constraint solver validates that any conditional requirements have
been satisfied; we don't need to fail here.
2017-11-17 10:52:04 -08:00
Pavel Yaskevich
92e2a25991 Merge pull request #12934 from xedin/rdar-35198459
[CSApply] Fix source breakage related to deep-equality types and SE-0110
2017-11-17 00:15:11 -08:00
Pavel Yaskevich
05d524d6e0 [CSApply] Fix source breakage related to deep-equality types and SE-0110
Fix problem related to Swift 3 mode (with assertions),
since Swift 3 mode allows passing arguments with extra parens
to parameters which don't expect them, it should be supported
by "deep equality" types e.g. Optional<T>:

```swift
func foo(_: (() -> Void)?) {}
func bar() -> ((()) -> Void)? { return nil }
foo(bar) // This expression should compile in Swift 3 mode
```

Resolves: rdar://problem/35198459
2017-11-16 21:56:24 -08:00
Pavel Yaskevich
7b121de1a0 [CSRanking] Change ranking to weight overload choices in evaluation order
Consider different overload choices for the same location in evaluation
order, this makes overload resolution more predictable because it's going
to follow expression bottom-up, that prevents situations when some
expressions are considered ambigious because choices taken further up
equate the score, instead each level is given distinct weight
based on evaluation order.

Resolves: rdar://problem/31888810
2017-11-16 13:38:24 -08:00
Slava Pestov
4096000530 Merge pull request #12942 from slavapestov/lazy-protocol-member-validation
Lazy protocol member validation
2017-11-15 18:03:40 -08:00
Slava Pestov
772bd7634c Sema: Lazily validate protocol members 2017-11-15 16:26:27 -08:00
Greg Parker
e8475cc130 Revert "Use conditional conformances to implement Equatable for Optional, Array and Dictionary" 2017-11-15 14:17:22 -08:00