Commit Graph

1378 Commits

Author SHA1 Message Date
Huon Wilson
d4fbca1183 [Sema/CS] std::function -> llvm::function_ref for some non-escaping params. 2018-05-01 08:29:08 +10:00
Slava Pestov
17c9b2b74a IDE: Don't store TypeVariableTypes into CodeCompletionExprs
Instead, generate the type variable in ConstraintGenerator.
However, we only want to generate it if we're type checking
from inside TypeChecker::typeCheckCompletionSequence(), so
add an isActivated() flag to CodeCompletionExpr. If it is
not set, constraint generation will simply fail on an
expression containing a CodeCompletionExpr.
2018-04-27 22:33:07 -07:00
Orakaro
305dcbc27a Check null of getReferencedDecl() 2018-04-28 00:24:58 +09:00
Pavel Yaskevich
aa2b25b3dd Merge pull request #15868 from xedin/solver-get-params
[Sema] Attempt to replace usages of `getInput()` with `getParams()`
2018-04-26 23:32:15 -07:00
Pavel Yaskevich
3de6b3decb [Sema] NFC: remove AnyFunction::equalParams which takes type as a parameter 2018-04-26 20:00:57 -07:00
Pavel Yaskevich
3c64680a91 [Diagnostics] Switch CalleeCandidateInfo to use FunctionType::getParams() 2018-04-26 17:33:08 -07:00
Pavel Yaskevich
9f55371aac [CSApply] Switch to use AnyFunctionType::getParams() instead of getInput() 2018-04-26 17:33:08 -07:00
Pavel Yaskevich
57ad592844 [Sema] Switch computeDefaultMap to use AnyFunctionType::getParams() 2018-04-26 17:33:08 -07:00
Orakaro
05b78bd984 Reword Note message and use variable name instead 2018-04-27 02:48:44 +09:00
Slava Pestov
e31bd92eee Sema: Fix crash in IfExpr diagnostics
Fixes <rdar://problem/39586166>.
2018-04-25 22:09:14 -07:00
Orakaro
cf68bfb3dd Separate suggestion into different NOTE 2018-04-25 22:07:44 +09:00
Orakaro
cd4c11a034 Fix SR-7015 2018-04-21 23:02:35 +09:00
Huon Wilson
18683f305d Merge pull request #15587 from huonw/minmax
[Sema] Perform name lookup in outer scopes in some cases involving conditional conformances
2018-04-20 22:33:07 +10:00
Huon Wilson
0c53d44e53 [Sema] Consider outer max/min selection deprecated.
We warn and provide fixits, so that we're able restrict this behaviour to Swift
4 only by eagerly migrating people off of it.
2018-04-20 17:27:32 +10:00
Huon Wilson
285c2a469b [CS] Add decl-ref outer alternatives as non-favored options.
Given something like `max(1, 2)` inside a type that conforms to Sequence, this
allows the compiler to consider Swift.max as well as the two methods with that
name on Sequence.
2018-04-20 00:55:11 +10:00
Doug Gregor
3b896e0a41 [Collection upcast optimization] Address review feedback.
All NFC cleanups.
2018-04-18 09:26:52 -07:00
Doug Gregor
eaba3b3192 [Type checker] Factor out the collection upcast peephole code.
While here, cope with extra parentheses as well. They shouldn't
inhibit this optimization.
2018-04-17 15:21:48 -07:00
Doug Gregor
10c53f4cd8 [Type checker] Extend the upcast-of-literal peephole to dictionary literals.
When the operand of a collection upcast is a dictionary literal,
upcast the elements of the collection instead. This avoids going
through the dynamic-casting machinery.
2018-04-17 14:50:46 -07:00
Doug Gregor
4acbf586eb [AST] Optimize collection upcasts of array literals.
When we form a collection upcast of an array literal, upcast the
individual elements directly so we avoid a call through the
runtime. This both improves code generation and sidesteps a regression
involving the inability to dynamically cast function types.

Fixes SR-7362 / rdar://problem/39218656.
2018-04-17 14:08:14 -07:00
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