Commit Graph

574 Commits

Author SHA1 Message Date
Mark Lacey
3c9cb97c86 [ConstraintSystem] Add an option to disable the constraint solver perf hacks.
This is helpful in experimenting with constraint solver changes that
might help us remove some of these unsound options. It's not ever mean
to be enabled, but if we're able to remove the things guarded by the
option we can eventually remove the option.
2018-08-06 11:48:19 -07:00
Rintaro Ishizaki
d86725cf80 [ConstraintSystem] Ignore patterns in linked expression analysis (#18487)
Fixes an assertion hit in "pattern in binary expression" case.

rdar://problem/41071587
2018-08-04 11:26:09 +09:00
Pavel Yaskevich
e117dd966c [Sema] SE-0213: Fix LinkedExprAnalyzer to not record types for literal init
Literal initialization via coercion makes current incorrect logic
slightly more eager still, which leads to more chained arithmetic
operator expressions to be recognized as "symmetric" and their type
variables merged.

Although literal init via coercion does provide more type information,
let's treat it as regular initializer calls and don't record the types.

Resolves: rdar://problem/42750089
2018-07-30 20:38:47 -07:00
Pavel Yaskevich
2558060169 [CSGen] Restore var/let declaration type favoring 2018-07-29 17:22:38 -07:00
Pavel Yaskevich
97fa263119 [ConstraintSystem] Remove CleanupIllFormedExpressionRAII and its uses 2018-07-28 20:28:41 -07:00
Pavel Yaskevich
0a404529c3 [Sema] Adjust Diagnostics/IDE to not assume that parameters always have types 2018-07-28 20:28:41 -07:00
Pavel Yaskevich
398abdfb7c [CSSolver] Add closure parameter type caching
While inferring avoid associating type variables with closure
parameters, use cache instead and only set types when everything
is properly type-checked, this avoids multiple problems one of
them - leaking type variables outside of constraint system they
belong to.
2018-07-28 20:28:41 -07:00
Pavel Yaskevich
9156ecb6f4 Merge pull request #18285 from dingobye/sr8385
[Sema] Avoid merging type variables that can have different results in CS.
2018-07-28 09:28:23 -07:00
Pavel Yaskevich
624c183fe0 [ConstraintGraph] Change gatherConstraints to take SetVector
For stable iteration order, let's switch from `SmallPtrSet`
to `SetVector` which ensures insertion order iteration.
2018-07-27 15:34:15 -07:00
Ding Ye
617e057f03 [Sema] Avoid merging type variables that can have different results in CS.
This patch avoids merging type variables inside UnresolvedMemberExpr
and those outside, because they may not always be equivalent in CS.

Resolves: SR-8385.
2018-07-27 21:46:12 +10:00
Pavel Yaskevich
48dd1e837b [ConstraintGraph] Add filtering to gatherConstraints per type variable
Most of the use-cases of `gatherConstraints` require filtering
at least based on the constraint kind that caller is interested in,
so instead of returning unrelated results and asking caller to
filter separately, let's add that functionality directly to
`gatherConstraints`.
2018-07-26 22:41:15 -07:00
Pavel Yaskevich
dd798accd8 [ConstraintGraph] Use set to gather constraints for type variables
Since it's possible to find the same constraint through two different
but equivalent type variables, let's use a set to store constraints
instead of a vector to avoid processing the same constraint multiple
times.
2018-07-26 22:41:07 -07:00
Slava Pestov
90cd772228 AST: Remove getParameterLists() and friends from AbstractFunctionDecl subclasses
Now, an AbstractFunctionDecl always stores a single parameter list.

Furthermore, ConstructorDecl and DestructorDecl always store a
ParamDecl for 'self'.

FuncDecl only has a 'self' if it is a member of a nominal type or
extension, so we tail-allocate the storage for it.
2018-07-22 20:56:56 -07:00
Slava Pestov
e1da265873 Sema: Remove uses of AbstractFunctionDecl::getParameterLists() 2018-07-19 21:21:17 -07:00
David Zarzycki
d7922228da [Sema] NFC: Refactor AllowIUODeprecated into InCastOrCoercionExpression
InCastOrCoercionExpression is useful beyond IUO checking.
2018-07-19 13:53:47 -04:00
Pavel Yaskevich
9371aaa49b [TypeChecker/SE-0213] NFC: Add couple of additional test-cases 2018-07-17 12:08:59 -07:00
David Zarzycki
bae6cc6017 Merge pull request #17767 from davezarzycki/enable_opt_unowned_unmanaged
Enable optional unowned/unowned(unsafe) references
2018-07-17 14:13:44 -04:00
Pavel Yaskevich
8b3ea218e9 [Diagnostics] Suppress expression diagnostics for code completion
Any produced diagnostics are suppressed anyway by a special
diagnostic engine attached to the new type-checker, so there
no point of doing any of that work.

Resolves: rdar://problem/22996887
2018-07-16 12:18:34 -07:00
David Zarzycki
71472cfa96 Enable optional unowned/unowned(unsafe) references
John okayed this change in a comment on GitHub pull request: #16237
2018-07-11 14:33:23 -04:00
John McCall
34b0cbc11d Merge pull request #16237 from davezarzycki/metaprogram_ref_storage_types
[AST] NFC: Enable reference storage type meta-programming
2018-07-05 14:45:38 -04:00
David Zarzycki
6dc2b7fda9 [Sema] NFC: Adopt reference storage type meta-programming macros 2018-06-30 06:44:33 -04:00
John McCall
9bee3cac5a Generalize storage implementations to support generalized accessors.
The storage kind has been replaced with three separate "impl kinds",
one for each of the basic access kinds (read, write, and read/write).
This makes it far easier to mix-and-match implementations of different
accessors, as well as subtleties like implementing both a setter
and an independent read/write operation.

AccessStrategy has become a bit more explicit about how exactly the
access should be implemented.  For example, the accessor-based kinds
now carry the exact accessor intended to be used.  Also, I've shifted
responsibilities slightly between AccessStrategy and AccessSemantics
so that AccessSemantics::Ordinary can be used except in the sorts of
semantic-bypasses that accessor synthesis wants.  This requires
knowing the correct DC of the access when computing the access strategy;
the upshot is that SILGenFunction now needs a DC.

Accessor synthesis has been reworked so that only the declarations are
built immediately; body synthesis can be safely delayed out of the main
decl-checking path.  This caused a large number of ramifications,
especially for lazy properties, and greatly inflated the size of this
patch.  That is... really regrettable.  The impetus for changing this
was necessity: I needed to rework accessor synthesis to end its reliance
on distinctions like Stored vs. StoredWithTrivialAccessors, and those
fixes were exposing serious re-entrancy problems, and fixing that... well.
Breaking the fixes apart at this point would be a serious endeavor.
2018-06-30 05:19:03 -04:00
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