Commit Graph

1659 Commits

Author SHA1 Message Date
Sho Ikeda
3c399de5bd [gardening][Sema] Replace typedef with using 2018-04-03 22:12:48 +09:00
Hamish
4f8ad1afec [Sema] Revise #14875 in response to feedback
- Diagnose on the location of the '=' equals sign for assignments
- Use the variable decl as the location for the note
- Make AST node params 'const'
2018-04-02 23:05:33 +01:00
Hamish
92931b7434 Merge remote-tracking branch 'upstream/master' into warn-weak-insta-dealloc 2018-04-02 18:06:45 +01:00
Mark Lacey
4bd648be05 Fix the handling of IUOs in 'as!' casts.
We just needed to select the final type based on which branch of the
disjunction successfully type-checked the expression.

Fixes [SR-7208](https://bugs.swift.org/browse/SR-7208)
  and rdar://problem/37159360.
2018-03-30 11:57:38 -07:00
Robert Widmann
03580d2fe5 Add a parameter list to EnumElementDecl
This models, but does not plumb through, default arguments.
2018-03-28 00:05:56 -04:00
Hamish
89c9e03e48 [Sema] Revise #15280 in response to feedback (2)
Use VarDecl::isSelfParameter to check whether the base is 'self'.
2018-03-26 18:58:03 +01:00
Hamish
5f43627235 [Sema] Revise #15280 in response to feedback
Instead of passing the base expression of a member access to `getAccessSemanticsFromContext`, we now just pass a bool flag for whether this is a member access on the implicit 'self' declaration.
2018-03-24 21:13:47 +00:00
Hamish
8a78e15a0f [Sema] Only directly access members within didSet if accessed on 'self'
Currently we always directly access a member when mutating it in its own didSet/willSet observer (in order to prevent infinite recursion). However we also do this even when accessing the same member on a *different* instance.

This commit changes the behaviour such that only member accesses on the implicit 'self' declaration are accessed directly within that member's own willSet/didSet.

Note that this change has the potential to cause recursion in cases where it didn't previously, for example this will now infinitely recurse:

    struct S {
      var i = 0 {
        didSet {
          var s = self
          s.i = 5
        }
      }
    }

    var s = S()
    s.i = 2

I don't know how serious this impact is though.

Resolves SR-419.
2018-03-24 21:13:47 +00:00
Joe Groff
8346603e97 Merge pull request #15459 from jckarter/keypath-force-index-equatable
Sema: Ensure Equatable conformance is forced for key path indices.
2018-03-23 16:04:57 -07:00
Joe Groff
c931a06942 Sema: Ensure Equatable conformance is forced for key path indices.
We need to ensure that the conformance is fully reified during type checking since we will use it during SILGen for the keypath. Speculative fix for SR-7207.
2018-03-23 12:50:13 -07:00
Pavel Yaskevich
79b14c8916 [Sema] Improve diagnostics for non-escaping function types
Allow certain bindings and conversions involving non-escaping
function types to succeed in "diagnostic" mode to gather fixes
and diagnose such problems better, expecially related to
conversions to 'Any' and generic parameters.

Resolves: rdar://problem/38648760
2018-03-20 17:57:03 -07:00
Slava Pestov
9e66df7c16 Sema: Fix ASAN failure
This fixes a use-after-free regression from my fix for
<rdar://problem/38545956>.
2018-03-19 23:23:35 -07:00
Slava Pestov
d118654fa8 Sema: Peephole for 'nil' literal of Optional type 2018-03-18 00:13:55 -07:00
Mark Lacey
85f25003ce Replace uses of getOptionalObjectType(bool &).
Instead, use the one that doesn't have a reference parameter.
2018-03-16 21:19:49 -07:00
Slava Pestov
34fd4ae512 AST: Use DeclBaseName::Kind::Constructor
Fixes <rdar://problem/35852727>, <https://bugs.swift.org/browse/SR-1660>,
<https://bugs.swift.org/browse/SR-6557>.
2018-03-16 00:25:56 -07:00
Pavel Yaskevich
4850d54613 Merge pull request #15287 from xedin/rdar-38309176
[CSApply] Don't try to force propagate l-value access in "shallow" mode
2018-03-15 21:23:09 -07:00
Pavel Yaskevich
cdf6cb3f2c [CSApply] Don't try to force propagate l-value access in "shallow" mode
Some of the expressions call into `typeCheckExpressionShallow` while trying to
apply solutions, we need to respect the fact that sub-expressions might be
already properly type-checked while propagating l-value access kind.

Resolves: rdar://problem/38309176
2018-03-15 18:07:51 -07:00
Mark Lacey
2b1ad9c4fe Remove the ForceUnchecked ConversionRestrictionKind.
More post-IUO-rework cleanup.
2018-03-15 01:11:00 -07:00
Hamish
48f08bdbc7 [Sema] Diagnose immediate deallocation of instances assigned to non-owning variables
When performing a binding/assignment to a weak or unowned variable/property from an initialiser call, emit a warning that the instance will be immediately deallocated.
2018-03-08 16:32:35 +00:00
Sho Ikeda
cea6c03eb2 [gardening] Use !empty() over size() > 0 2018-03-08 09:21:09 +09:00
Mark Lacey
b9cd30331d [ConstraintSystem] Do not attempt to force references of unapplied functions.
We were inserting function conversion expressions that were then
turned into forces of values in cases where we merely referenced
functions, but did not actually call them.

Fixes rdar://problem/37241550.
2018-02-20 17:49:10 -08:00
Mark Lacey
649e0d977e Merge pull request #14692 from rudkx/rdar37240984
[ConstraintSystem] Implicitly force results of @optional protocol req…
2018-02-16 18:41:17 -08:00
Mark Lacey
4ee6ead47e [ConstraintSystem] Implicitly force results of @optional protocol requirements.
We were not handling IUO results of @optional protocol methods
properly, sometimes forcing the @optional requirement rather than the
result of the call.

Fixes rdar://problem/37240984.
2018-02-16 16:58:52 -08:00
Chris Lattner
a0fa5d11b4 Implement SE-0195, which introduces "Dynamic Member Lookup" Types (#14546)
* Implement the recently accepted SE-0195 proposal, which introduces "Dynamic
Member Lookup" Types.  This is a dusted off and updated version of PR13361,
which switches from DynamicMemberLookupProtocol to @dynamicMemberLookup as
was requested by the final review decision.  This also rebases it,
updates it for other changes in the compiler, fixes a bunch of bugs, and adds support for keypaths.  

Thank you to @rudx and @DougGregor in particular for the helpful review comments and test cases!
2018-02-16 16:19:50 -08:00
Pavel Yaskevich
8c17b925e6 [ConstraintSystem] Add TypeLoc caching to constraint system
This is useful for explicit casts and type expressions, where
type loc and expression types might be different, and allows
constraint solver to avoid setting opened types to expressions
which resolves multiple crashes.
2018-02-13 00:08:56 -08:00
Pavel Yaskevich
c0f5711ee5 [ConstraintSystem] Don't apply types to expressions until solution is found
Resolves: rdar://problem/36744895
2018-02-13 00:08:45 -08:00
Mark Lacey
d63bb3fc53 Remove most uses of OptionalTypeKind.
What remains are places where we are conflating optionality with
either nullability or failability.
2018-02-10 16:24:09 -08:00
Mark Lacey
a455db6c0b Merge pull request #14477 from rudkx/fix-sr6796
Restore a very narrow function argument conversion for -swift-version 4.
2018-02-07 22:58:42 -08:00
John McCall
b140b8c9f1 Merge pull request #13910 from hamishknight/dont-treat-archetype-as-nonoptional
[Sema] Don't treat archetypes as non-optional when casting to them
2018-02-08 00:37:10 -05:00
Mark Lacey
6310aca2c0 Restore a very narrow function argument conversion for -swift-version 4.
Allow functions with type `(()) -> T` to be passed in places where we
expect `() -> T`, but only for -swift-version 4 (for -swift-version 3
this already works due to other horrible things in CSSimplify.cpp).

We need to look at how we can help migrate these cases to
-swift-version 5, but in the meantime, but that is something we can
consider separately.
2018-02-07 18:07:43 -08:00
Mark Lacey
5c609f298d Fix unused code warning. 2018-02-07 17:25:19 -08:00
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