Commit Graph

15871 Commits

Author SHA1 Message Date
Hamish Knight
25cfa13a95 [CS] Remove isDynamic param from buildMemberRef
Callers were either just passing
choice.getKind() == OverloadChoiceKind::DeclViaDynamic
or passing false. Inline the check into the function
and assert for callers that don't expect a decl
from dynamic lookup.
2019-11-21 16:21:57 -08:00
Hamish Knight
3e34c8c1b2 [CS] NFC: Use SIMPLE_LOCATOR_PATH_ELT in a couple of switches
This avoids us having to add new cases in the common case
of adding a new simple locator element.
2019-11-21 16:21:57 -08:00
Harlan Haskins
1b24c79fe4 [AST] Add attributes for hasMissingDesignatedInitializers and inheritsConvenienceInitializers
We're planning to emit these attributes in module interfaces, but until
we land that patch, we want to parse these attributes and ignore them.

Part of rdar://51249311
2019-11-21 15:45:34 -08:00
Pavel Yaskevich
b5f89cf0eb [TypeChecker] User interface type while validating keypath dynamic subscript parameter
Avoid unnecessary parameter type substitutions.
2019-11-21 15:14:34 -08:00
Xi Ge
7f8c04e0b7 AST: introduce a new attribute @_originallDefinedIn to the AST
We need this attribute to teach compiler to use a different name from the current
module name when generating runtime symbol names for a declaration. This is to serve
the workflow of refactoring a symbol from one library to another without breaking the existing
ABI.

This patch focuses on parsing and serializing the attribute, so @_originallyDefinedIn
will show up in AST, swiftinterface files and swiftmodule files.

rdar://55268186
2019-11-21 14:25:57 -08:00
Pavel Yaskevich
f7ee402d2f Merge pull request #28400 from xedin/rdar-57201781
[ConstraintSystem] Introduce notion of constraint system phase
2019-11-21 13:17:34 -08:00
Doug Gregor
ec68fe4bc4 Merge pull request #28408 from apple/revert-28355-no-opt-ast-casts
Revert "[Constraint application] Stop optimizing casts in the AST."
2019-11-21 12:01:04 -08:00
kelvin13
e4dc295d64 fix conflicts 2019-11-21 12:42:10 -06:00
Doug Gregor
60e501d80b [Type checker] Remove an unnecessary cycle break.
The `hasInterfaceType()` check should only be used for cycle breaking, and in
this case was preventing us from properly establishing the capabilities of
a property wrapper.

Fixes rdar://problem/57350503 and several dupes.
2019-11-21 10:00:18 -08:00
Doug Gregor
7f50537933 Revert "[Constraint application] Stop optimizing casts in the AST." 2019-11-21 09:19:04 -08:00
swift_jenkins
f584bc4b9c Merge remote-tracking branch 'origin/master' into master-next 2019-11-21 04:00:10 -08:00
Suyash Srijan
4c85dd65ae Merge pull request #28216 from theblixguy/fix/SR-11762
[Typechecker] Fix _modify for properties using a property wrapper
2019-11-21 11:42:03 +00:00
Pavel Yaskevich
e3a4b4ffc9 [ConstraintSystem] Fix ConstraintGenerator to change phase to "constraint generation" and back 2019-11-21 00:08:58 -08:00
swift_jenkins
b3621c97d7 Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 23:00:50 -08:00
Doug Gregor
4907a984b4 Merge pull request #28355 from DougGregor/no-opt-ast-casts
[Constraint application] Stop optimizing casts in the AST.
2019-11-20 22:57:22 -08:00
swift_jenkins
15f6c8f0bc Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 22:00:12 -08:00
Robert Widmann
7ff18dfc5c Merge pull request #28358 from CodaFi/witness-protection-program
Ensure that we have a valid witness to IteratorProtocol.next()
2019-11-20 21:59:48 -08:00
swift_jenkins
4ade1e126e Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 19:00:44 -08:00
Robert Widmann
631202943f Merge pull request #28392 from CodaFi/a-captive-audience
Run checkPatternBindingCaptures on Extensions
2019-11-20 18:56:42 -08:00
Pavel Yaskevich
addc2b06ab [ConstraintSystem] Introduce notion of constraint system phase
Some constraint transformations require knowledge about what state
constraint system is currently in e.g. `constraint generation`,
`solving` or `diagnostics` to make a decision whether simplication
is possible. Notable example is `keypath dynamic member lookup`
which requires a presence of `applicable fn` constraint to retrieve
some contextual information.

Currently presence or absence of solver state is used to determine
whether constraint system is in `constraint generation` or `solving`
phase, but it's incorrect in case of `diagnoseFailureForExpr` which
tries to simplify leftover "active" constraints before it can attempt
type-check based diagnostics.

To make this more robust let's introduce (maybe temporarily until
type-check based diagnostics are completely obsoleted) a proper
notion of "phase" to constraint system so it is always clear what
transitions are allowed and what state constraint system is
currently in.

Resolves: rdar://problem/57201781
2019-11-20 18:34:51 -08:00
Doug Gregor
8d0612da97 [Constraint application] Stop optimizing casts in the AST.
Constraint application was rewriting conditional casts (as?) and
forced casts (as!) into coercions (as) at the AST level when it
determined that there was a coercion. Stop doing that: it's the
optimizer's job to remove such casts.
2019-11-20 16:36:29 -08:00
Doug Gregor
d379de8830 [Constraint solver] Switch coercion to be solution-based.
Rather than spinning up a new constraint system when performing an "as"
coercion, perform the coercion with the known solution, because we
already did all of the work to figure out how to perform the coercion.
2019-11-20 16:36:29 -08:00
swift_jenkins
f2c5becdc7 Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 16:00:01 -08:00
Robert Widmann
827d319cf6 Merge pull request #28386 from CodaFi/more-factors-at-play
[NFC] Refactor Overload Resolution a Bit
2019-11-20 15:56:04 -08:00
Hamish Knight
7e788b8ab9 [AST] Remove CallerDefaultArgumentExpr
Now that we use DefaultArgumentExpr for both kinds
of default arguments, this is no longer needed.
2019-11-20 15:07:33 -08:00
Hamish Knight
9b4779f34a [Sema] typeCheckParameterDefault can now always fail 2019-11-20 15:07:33 -08:00
Hamish Knight
c667d2b361 Use DefaultArgumentExpr for caller-side defaults
This commit changes how we represent caller-side
default arguments within the AST. Instead of
directly inserting them into the call-site, use
a DefaultArgumentExpr to refer to them indirectly.

The main goal of this change is to make it such
that the expression type-checker no longer cares
about the difference between caller-side and
callee-side default arguments. In particular, it
no longer cares about whether a caller-side
default argument is well-formed when type-checking
an apply. This is important because any
conversions introduced by the default argument
shouldn't affect the score of the resulting
solution.

Instead, caller-side defaults are now lazily
type-checked when we want to emit them in SILGen.
This is done through introducing a request, and
adjusting the logic in SILGen to be more lenient
with ErrorExprs. Caller-side defaults in primary
files are still also currently checked as a part
of the declaration by `checkDefaultArguments`.

Resolves SR-11085.
Resolves rdar://problem/56144412.
2019-11-20 15:07:32 -08:00
Robert Widmann
c4f833ed5c Run checkPatternBindingCaptures on Extensions
Resolves rdar://57348897
2019-11-20 14:44:21 -08:00
Robert Widmann
d31f6ed423 Drop the ASTContext parameter on FindCapturedVars
Just get it from the decl context
2019-11-20 14:41:55 -08:00
Suyash Srijan
6d9644774d [Typechecker] PropertyWrapperMutabilityRequest should not return None when parsing getter/setter from swiftinterface file 2019-11-20 21:26:09 +00:00
swift_jenkins
54bac60067 Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 11:39:19 -08:00
Robert Widmann
c11ffb5e19 Factor out the part of resolveOverload that fiddles with constraint system 2019-11-20 11:36:59 -08:00
Robert Widmann
d772338398 Refactor resolveOverloadForDeclWithSpecialTypeCheckingSemantics
Have it function more like getTypeOfMemberReference and clean up its caller a bit
2019-11-20 11:36:35 -08:00
Slava Pestov
2e65a14ed4 Merge pull request #28372 from slavapestov/typecheck-decl-primary
Kill ClosuresWithUncomputedCaptures and split off TypeCheckDeclPrimary.cpp from TypeCheckDecl.cpp
2019-11-20 14:29:31 -05:00
swift_jenkins
14724f762a Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 10:39:15 -08:00
Slava Pestov
15b5820996 Sema: Split off TypeCheckDeclPrimary.cpp from TypeCheckDecl.cpp
The new file contains the implementation of typeCheckDecl() and
various utility functions that it uses. This code runs for
declarations in primary files only.

TypeCheckDecl.cpp now mostly consists of evaluate() implementations
for requests together with some utility functions.

A few of the new function prototypes I added to TypeCheckDecl.h
are indicative of some code that could be refactored further.
Any utility functions shared by both TypeCheckDecl.cpp and
TypeCheckDeclPrimary.cpp should be wrapped up in requests in
order for the results to be cached.
2019-11-19 18:50:39 -05:00
Pavel Yaskevich
595f85fcb3 [Diagnostics] Properly diagnose missing optional unwrap(s) related to closure result 2019-11-19 15:15:30 -08:00
Pavel Yaskevich
e0e13aa97a [ConstraintSystem] Make ForceOptional fix a part of repairFailures
Instead of always attempting an optional unwrap fix if types differ
in optionality, let's make it more targeted for each applicable
locator and conversion.

In addition adjust a couple of uses of `ForceOptional` fix to avoid
recording the same fix multiple times and use appropriate `impact`
instead.
2019-11-19 15:15:29 -08:00
Pavel Yaskevich
38a6cfaad1 [CSDiagnostic] Convert force optional unwrap diagnostic into a contextual one
Record both sides of conversion where a form of force unwrap is
necessary to be able to produce tailored diagnostics such as for
an attempt to use optional type as a boolean.
2019-11-19 15:15:29 -08:00
Pavel Yaskevich
bdeaced0f2 [CSFix] Convert force optional unwrap fix into a contextual one 2019-11-19 15:15:29 -08:00
Slava Pestov
ef05accd31 Sema: Remove even more vestigial TypeChecker usages 2019-11-19 17:40:00 -05:00
Slava Pestov
636fc0f17e Sema: Compute captures when contextualizing closures 2019-11-19 17:18:07 -05:00
Owen Voorhees
a3946cdb50 Revert "Revert "[Diagnostic] Improve diagnostic for trailing closures in statement conditions (#25165)""
This reverts commit e3a6b67c63.
2019-11-19 13:24:20 -08:00
Robert Widmann
7e14e34ec6 Ensure that we have a valid witness to IteratorProtocol.next()
Resolves rdar://57003406
2019-11-19 11:41:50 -08:00
Slava Pestov
0bb323b75c Sema: Move buildAutoClosureExpr() from TypeChecker to ConstraintSystem 2019-11-19 14:02:21 -05:00
swift_jenkins
f69e40db09 Merge remote-tracking branch 'origin/master' into master-next 2019-11-19 09:59:26 -08:00
Nathan Hawes
7b33254b68 Merge pull request #28226 from nathawes/assertion-fixes
Fix some SourceKit assertion hits
2019-11-19 09:50:41 -08:00
swift_jenkins
c730cd448e Merge remote-tracking branch 'origin/master' into master-next 2019-11-18 21:20:17 -08:00
Slava Pestov
7c145fb7be Merge pull request #27951 from zoecarver/key-path-default-arg
Fix KeyPath with default arg
2019-11-19 00:04:51 -05:00
swift_jenkins
9811735f9e Merge remote-tracking branch 'origin/master' into master-next 2019-11-18 19:00:01 -08:00