Commit Graph

602 Commits

Author SHA1 Message Date
Mark Lacey
ee0538c5bf Merge pull request #17536 from rudkx/rdar41306933
[ConstraintSystem] Use the type cache to read types in constraint gen…
2018-06-26 23:05:39 -07:00
Mark Lacey
16a0808f2c Revert "[TypeChecker] Fix crash with Objective C keypaths." 2018-06-26 17:18:12 -07:00
Mark Lacey
d48fea83dd [ConstraintSystem] Use the type cache to read types in constraint generation.
We should pretty much always be reading
expression types out of the type cache in the constraint system.

We only see key path applications here on the path where we are
diagnosing a failure.

I haven't yet managed to come up with a test case that reproduces a crash
here.

Fixes: rdar://problem/41306933
2018-06-26 17:13:13 -07:00
Mark Lacey
e0ce5fcbd9 [TypeChecker] Fix crash with Objective C keypaths.
We have a crash reported but do not have a test case and my attempt at
creating one was unsuccessful. It seems like the issue is that we have
an invalid decl that we attempt to access the interface type on,
though, so hopefully this fixes the issue.

I also tweaked the constraint generator to bail out when
checkObjCKeyPathExpr fails.

Potentially fixes: rdar://problem/40955755
2018-06-25 17:46:19 -07:00
Robert Widmann
7e8aa9fcc6 [NFC] Rename @lvalue Locator Path Element
8271c1a removed the last hacky usage of ArrayElementType,
leaving behind just the @lvalue-to-inout conversions.  Rename
the locator path element to reflect this and do a bit of cleanup on the
unrelated-but-near-enough other hack RValueAdjustment.
2018-05-26 16:48:41 -07:00
Slava Pestov
b3bc06e75e Merge pull request #16766 from AnthonyLatsis/generalize_declared_here
[Sema] Generalize the 'declared here' diagnostic
2018-05-22 19:47:53 -07:00
fischertony
7313a90eb1 [Sema] Generalize the 'declared here' diagnostic 2018-05-22 18:17:15 +03:00
Ravi Kandhadai
f1ff8a61a5 [Sema] Add Sema checks for detecting large integer literals that
overflow Builtin.Int2048 and add tests for checking the
correctness of the diagnostics.
2018-05-21 18:41:44 -07: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
c89a4a5cd5 Sema: Remove dead code from ExprCleaner and CleanupIllFormedExpressionRAII 2018-04-28 00:11:47 -07:00
Slava Pestov
3cb14a0acc Sema: Cleanup now that Expr types can't have type variables 2018-04-28 00:11:47 -07: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
Pavel Yaskevich
3de6b3decb [Sema] NFC: remove AnyFunction::equalParams which takes type as a parameter 2018-04-26 20:00:57 -07:00
Pavel Yaskevich
9f55371aac [CSApply] Switch to use AnyFunctionType::getParams() instead of getInput() 2018-04-26 17:33:08 -07:00
Pavel Yaskevich
f929885d80 [CSGen] Switch to use AnyFunctionType::getParams() instead of getInput() 2018-04-26 17:33:08 -07: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
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
Huon Wilson
a108c5830a [Sema] Store the outer results of lookup for unqualified possible-method-calls. 2018-04-20 00:55:07 +10:00
Mark Lacey
9a7497aa17 Opportunistic fix to allow \Derived.property to be inferred as \Base.property.
Noticed this opportunity while reading through the keypath type checking code.
2018-04-12 09:55:40 -07:00
Nathan Hawes
9200218122 Merge pull request #15688 from nathawes/rdar38149042-code-completion-hits-visitOpenExistentialExpr-unreachable
[CSGen][CSDiag] Update SanitizeExpr to sanitize OpenExistentialExpr
2018-04-04 13:56:23 -07:00
Mark Lacey
72f4b3d3b8 NFC: Minor cleanup to make createTypeVariable options default to zero.
Many (perhaps most?) calls to createTypeVariable explicitly pass 0 for
options. This change just defaults the parameter to 0 and removes all
the explicit 0's in the code.
2018-04-03 10:19:38 -07:00
Nathan Hawes
d367dfc3ff Merge pull request #15627 from nathawes/reachable-unreachables
[CSGen] Mark visitDynamicMemberRefExpr as unreachable to match ExprRewriter and update SanitizeExpr to handle them
2018-04-02 12:32:44 -07:00
Nathan Hawes
136b5eff8b [CSGen][CSDiag] Update SanitizeExpr to santize OpenExistentialExpr
They can show up when re-typechecking via diag or code-completion and were
only being sanitized out in one place in CSDiag. Moved that logic into
SanitizeExpr.

Resolves rdar://problem/38149042
2018-04-02 11:42:09 -07:00
David Zarzycki
42890e97ef Merge pull request #15597 from davezarzycki/more_TVO_CanBindToInOut_removal
[Sema] NFC: More TVO_CanBindToInOut removal
2018-03-31 16:39:07 -04:00
Nathan Hawes
0145439a2b [CSGen] Mark visitDynamicMemberRefExpr as unreachable to match ExprRewriter and update SanitizeExpr to handle them
We were hitting an unreachable in visitDynamicMemberExpr in ExprRewriter when
re-typechecking during a salvage. Check for these earlier (in CSGen) and update
SanitizeExpr to handle them.

Resolves rdar://problem/39055736
2018-03-30 17:17:21 -07:00
Mark Lacey
f47218cb86 Emit a different diagnostic for Swift 3/4 for 'as T!'.
We ended up supporting these coercions for Swift 3/4 via disjunctions,
so change our warning to one saying that it's deprecated rather than
erroneously telling the user that we're treating '!' as if it
were '?'.

Fixes rdar://problem/37121121.
2018-03-30 09:15:15 -07:00
David Zarzycki
94a540db4b [Sema] NFC: More TVO_CanBindToInOut removal
If we're willing to tolerate less specific diagnostics, then we can
remove more instances of TVO_CanBindToInOut. After this change, there is
only one client of TVO_CanBindToInOut.
2018-03-30 09:22:37 -04:00
David Zarzycki
18abd7e44c Merge pull request #15542 from davezarzycki/nfc_opt_weak_var_typechecking
[Sema] NFC - Make #15419 work with weak vars
2018-03-28 19:17:53 -04:00
David Zarzycki
c8e17157af [Sema] Remove unneeded uses of TVO_CanBindToInOut 2018-03-28 14:25:13 -04:00
David Zarzycki
f4d4a3d6c6 [Sema] NFC - Generalize #15419 to work with weak vars 2018-03-28 07:40:50 -04:00
David Zarzycki
b97ec692ec [Sema] NFC - Bypass more Pattern type variables
Rather than throw away the result of simplifying the expression if the
resulting is InOutType, see if the user explicitly created the
InOutType. If they did not, then the RValue type is fine.
2018-03-27 14:42:16 -04:00
David Zarzycki
62b5dc110d [Sema] NFC: Use exhaustive switches in PatternKind::Named
Also, flip the polarity so that programmers that add new
ReferenceOwnership kinds know what to do.
2018-03-27 11:06:56 -04:00
Mark Lacey
9385dbb3fb Fix exponential type checking of tuple literals.
This fixes two easy cases where we would go exponential in type
checking tuple literals.

Instead of generating a conversion to a single type variable (which
results in one large constraint system), we generate a conversion ot
the same type that appears in the initializer expression (which for
tuples is a tuple type, which naturally splits the constraint system).

I experimented with trying to generalize this further, but ran into
problems getting it working, so for now this will have to do.

Fixes rdar://problem/20233198.
2018-03-26 14:46:03 -07:00
Nathan Hawes
d6894b82b3 Merge pull request #15247 from nathawes/rdar38144409-code-completion-assertion-hit-in-getTypeOfReference
[code-completion] Fix assertion hit in getTypeOfReference via code completion
2018-03-23 12:08:41 -07:00
Nathan Hawes
781539c5c3 [code-completion] Use the SanitizeExpr ASTWalker along all paths to the constraint based type checker
Code completions calls typecheckUnresolvedExpression when completing unresolved members.
This calls an overload of solve() that bypasses sanitization, and without it we hit an
assertion failure in getTypeOfReference.

Resolves rdar://problem/38144409.
2018-03-22 10:21:11 -07:00
Mark Lacey
994c2d1acd Improve type join for function types.
It is still not completely general, but this moves things along a
little bit.
2018-03-21 11:51:54 -07:00
Pavel Yaskevich
49a25f4d0f [ConstraintSystem] NFC: Use correct locator for function result type variables 2018-03-14 11:41:47 -07:00
Huon Wilson
e307e54098 [AST] Explicitly track things marked __owned. 2018-03-08 12:36:24 +11:00
Huon Wilson
78bdc95ce3 Merge pull request #14874 from huonw/at-owned-cleanup
Various refactorings for __owned.
2018-03-02 14:20:21 -08:00
Huon Wilson
b94c5364f5 [NFC] Rename 'Ownership' to 'ReferenceOwnership'.
There's really two forms of ownership: references and values. Renaming
to make way for better distinguishing of the two.
2018-03-02 11:38:28 -08:00
Mark Lacey
758570982a Start stubbing out more parts of Type::join().
Improve support for Optional among other things.

Return Any when it is really the best answer given the types involved,
or nullptr if we cannot yet produce an accurate result.

This implementation returns Any? when joining Any with an
Optional<T>. In our type system both Any and Any? are effectively
subtypes of one another since each can hold all the values that the
other can hold. So this choice is somewhat arbitrary, but does line up
nicely with the notion that T is always a subtype of T?.
2018-02-28 23:13:59 -08:00
Pavel Yaskevich
79d706463b Merge pull request #13664 from xedin/finalize-expr-type-cache
[ConstraintSystem] Only set types on expressions in presence of solution
2018-02-13 21:43:34 -08:00
Mark Lacey
dc8c88058f Fix an issue with the constraint favoring code in the constraint optimizer.
The code was favoring overloads where *either* argument matched its
parameter type and where both parameter types were the same. This
is really overly broad and can result in bugs like the one here, where
we only attempt the
  (Int, Int) -> Bool
overload of '!=' despite the fact that it means forcing an
optional. We should select the
  <T>(T?, T?) -> Bool
overload instead, and inject the non-optional operand into an optional.

Making this require *both* arguments to match mostly disables this
optimization, though, since for somethin like "a"+"b"+"c" the second
add has a type variable and string literal as arugments.

So instead, we'll just disable this in cases where one argument is the
optional of the other, to ensure we never try forcing one side. This
also means we'll disable the optimization in cases where we would
inject one operand into an optional, but that's likely find as we
don't have long chains of expressions where that happens.

Fixes rdar://problem/37073401.
2018-02-13 10:24:30 -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
5613d39636 IUO: Hoist the IUO disjunction creation to a better place.
We should just create the disjunction straight-away in resolveOverload
rather than doing it deep inside type variable binding.
2018-01-09 15:45:52 -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
Mark Lacey
3a7c523129 IUO: Finish up support for subscript. 2018-01-04 19:32:31 -08:00
Mark Lacey
41479f6334 IUO: Start creating the DeclForImplicitlyUnwrappedOptional OverloadChoice.
Use this in places where we have a decl that is marked with the
ImplicitlyUnwrappedOptionalAttr so that we can distinguish in the
solver which decls need to be potentially unwrapped in order to type
check successfully.
2018-01-04 14:00:36 -08:00