Commit Graph

1238 Commits

Author SHA1 Message Date
Mark Lacey
43775e817d Disallow some implicit pointer conversions in autoclosures.
Disallow implicit conversion or arguments from Array, String, and
InOut (formed by &) to pointer types if the argument is for an
@autoclosure parameter.

These conversions were really only intended to be used for C/ObjC
interop, and in some contexts like autoclosures they are not safe.

Fixes: rdar://problem/31538995
2018-05-16 12:13:25 -07:00
Pavel Yaskevich
58fb0ac6a7 [CSApply] Make sure that indexing into an r-value tuple produces r-value
This is modeled in constraint system in a way
that when member type is resolved by `resolveOverload`
it would take r-value type of the element at
specified index, but if it's a type variable it
could still be bound to l-value later, so r-value
result has to be enforced by coercion if necessary.

Resolves: rdar://problem/39931475
2018-05-16 00:20:46 -07:00
Robert Widmann
6ed7e4af59 Merge pull request #16088 from orakaro/exp
More detail diagnostic when downcast to CoreFoundation Type
2018-05-08 21:46:06 -04:00
Doug Gregor
ebf9cdcc44 [AST] Collapse storage for ConcreteDeclRef.
Rather than ASTContext-allocating ConcreteDeclRef’s storage when there is a
non-empty substitution map, put the SubstitutionMap directly in the
ConcreteDeclRef. Simplify the various interfaces along the way.
2018-05-02 13:39:21 -07:00
Doug Gregor
192234415d [AST] Store SubstitutionMaps in ConcreteDeclRef and Witness data structures.
Replace two prominent uses of SubstitutionList, in ConcreteDeclRef and
Witness, with SubstitutionMap. Deal with the myriad places where we
now have substitution maps and need substitution lists (or vice versa)
caused by this change.

Overall, removes ~50 explicit uses of SubstitutionList (of ~400).
2018-05-02 13:38:14 -07:00
Slava Pestov
7b8359279d Sema: Eliminate typeCheckExpression() calls from convertLiteralInPlace()
This code dates back to the dark ages when forming substitutions
was something only the constraint solver could do.

Now that findNamedWitnessImpl() returns a ConcreteDeclRef instead
of a ValueDecl, we don't have to build a whole constraint system
and type check it just to form substitutions for the call.
2018-05-01 17:40:52 -06:00
Slava Pestov
2db629368e Sema: Support for abstract conformance in findNamedWitnessImpl() 2018-05-01 17:40:51 -06:00
Slava Pestov
7c6fc5ab8b Sema: Remove some obsolete logic from adjustSelfTypeForMember() 2018-04-30 18:59:20 -06:00
Slava Pestov
1da4430ecb Sema: Refactor findNamedWitnessImpl() to return a ConcreteDeclRef 2018-04-30 18:57:16 -06:00
Slava Pestov
754e8e2716 Sema: Eradicate uses of typeCheckExpressionShallow() from IfExpr and IfStmt rewriting
Instead of spinning up a new ConstraintSystem and solving it, we can
just directly construct a call to getBuiltinLogicValue().
2018-04-30 18:57:16 -06:00
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