Commit Graph

1263 Commits

Author SHA1 Message Date
Pavel Yaskevich
7009207491 [ConstraintSystem] Adjust handling of incorrect member references on protocol metatypes
Since it's now possible to refer to static members declared on a protocol
metatype if result type conforms to the protocol we need to adjust failure
detection to identify that conformance failure means and invalid reference
in certain situations.
2021-02-23 11:32:24 -08:00
Pavel Yaskevich
b05678f18e [ConstraintSystem] Allow static member references on protocol metatypes 2021-02-23 11:31:43 -08:00
Holly Borla
11028350a7 Merge pull request #35589 from Jumhyn/placeholder-types
[AST, Sema] Replace HoleType with PlaceholderType
2021-02-22 08:35:37 -08:00
Frederick Kellison-Linn
8539782c9a [Sema] Rename convertInferableTypes to replaceInferableTypesWithTypeVars 2021-02-19 14:35:03 -05:00
Slava Pestov
cd724d4924 Merge pull request #35988 from slavapestov/simplify-does-storage-produce-lvalue
Sema: Simplify doesStorageProduceLValue() a bit
2021-02-18 12:29:04 -05:00
Doug Gregor
7c336ea19a Add support for @concurrent attribute on closures. 2021-02-16 22:19:47 -08:00
Frederick Kellison-Linn
e4ea1678dc Rename HoleType to PlaceholderType
HoleType basically served the same purpose as PlaceholderType. This commit unifies the two.
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
fbb78cd006 [Sema] Convert placeholder types to type vars wherever we open generics
Rename `openUnboundGenericTypes` to `convertInferableTypes`. In addition to unbound generics, this method also converts placeholder types to fresh type variables.
2021-02-16 22:59:19 -05:00
Frederick Kellison-Linn
e508fb3733 [Sema] Introduce placeholder handler to TypeResolver
For now, don't do anything useful in clients. Specifying a placeholder type is still an error
2021-02-16 22:59:18 -05:00
Slava Pestov
0865dc144f Sema: Simplify doesStorageProduceLValue() a bit
The isGetterMutating() and isSetterMutating() checks already return
false if the storage is a static property or defined on a reference
type, so the isStatic() and hasReferenceSemantics() checks were not
needed.
2021-02-15 23:11:09 -05:00
Philippe Hausler
9a3d613345 [Sema] Corrections for for-await-in syntax to prevent specific bad code-gen scenarios and improve diagnostics
SILGen verification crash when no other async functions are called in a function body not marked as async when a for-await-in syntax is used. This corrects the diagnostics to ensure that the type check effects sees the proper async call that the for-await-in syntax infers.

for-await-in syntax was missing a diagnistic hint for inserting a try when the protocol conformance of the sequence shows a potential of throwing. (also there was a superfluous check for the nominal type in that type check (which was removed).

for-await-in syntax and for-try-await-in syntax did not infer async or throwing to closure constraints, both were added to properly identify the asyncy-ness/throwy-ness of the iteration.
2021-02-04 09:22:05 -08:00
Doug Gregor
b7a86bb3bc Type check withoutActuallyEscaping on async functions
Fixes rdar://73695354.
2021-01-29 16:25:08 -08:00
Pavel Yaskevich
fda3dc5127 Merge pull request #35607 from xedin/type-vars-accepts-set
[AST] Adjust `TypeBase::getTypeVariables` to accept a set
2021-01-27 09:51:45 -08:00
Pavel Yaskevich
b03dc63634 [AST] Adjust TypeBase::getTypeVariables to accept a set
Currently the pattern is to collect the type variables and then unique
them. Instead of asking clients to do uniquing, let's just accept a set
as an argument.
2021-01-26 18:13:34 -08:00
Varun Gandhi
86b123a35c [Sema] Diagnose type error on Clang type mismatch.
Fixes rdar://71904525.
2021-01-25 18:51:13 -08:00
Pavel Yaskevich
72888ca29b [ConstraintSystem] NFC: Extract PotentialBindings and auxiliary struct from ConstraintSystem
This opens up a posibility of using `PotentialBindings`
in `ConstraintGraphNode` and other places in `ConstraintGraph`.
2021-01-15 15:03:54 -08:00
Pavel Yaskevich
afec25271e [ConstraintSystem] Extract PotentialBinding and its auxiliary classes into a separate header
Create a new namespace - `swift::constraints::inference` and associate
`PotentialBinding` with it. This way it would be possible for constraint
graph to operate on `PotentialBinding(s)` in the future.
2021-01-15 15:03:24 -08:00
Pavel Yaskevich
f6637276fd [ConstraintSystem] Increase score only if members found on Optional and its unwrapped type
Unresolved member lookup is allowed to perform implicit optional
unwrap of a base type to find members. Previously if there were
any members directly on `Optional`, lookup would stop there. But
since SR-13815 it became possible for solver to attempt members
found on unwrapped type even if there are viable ones on
`Optional` as well.

New score kind has been introduced to guard against possible ambiguities
with new scheme - `SK_UnresolvedMemberViaOptional`. It's used very
time member found via base type unwrap is attempted. Unfortunately,
doing so can lead to behavior changes in existing code because it's
possible that base was wrapped into optional implicitly based on
context e.g. unresolved member passed in as an argument to a parameter
of optional type.

To fix situations like that, `SK_UnresolvedMemberViaOptional` should
only be increased if there is a mix of members to attempt - both directly
on `Optional` and on unwrapped type, in all other cases score should stay
the same because there could be no ambiguity.

Resolves: rdar://73027153
2021-01-13 09:12:03 -08:00
Pavel Yaskevich
bede9c8991 Merge pull request #35343 from xedin/refactor-check-availability
[TypeChecker] NFC: Unify logic in `checkDeclarationAvailaibility` and…
2021-01-11 11:45:38 -08:00
Pavel Yaskevich
fd4ce3bddb [TypeChecker] NFC: Unify logic in checkDeclarationAvailaibility and ConstraintSystem::isDeclUnavailable 2021-01-11 00:08:31 -08:00
Pavel Yaskevich
2a6f279b45 [ConstraintSystem] NFC: Remove obsolete used/checked conformances cache 2021-01-08 12:55:49 -08:00
Pavel Yaskevich
5f20eb661e [Diagnostics] Adjust requirement failures to retrieve conformance information from locator
Conditional conformances previously relied on `CheckedConformances`
cache to retrieve information about conditional requirements from
base conformance, but that is not really necessary anymore since
`ConformanceRequirement` element could provide all required info.
2021-01-08 12:55:14 -08:00
Pavel Yaskevich
fc05d4a6db Merge pull request #35225 from xedin/refactor-literal-bindings
[CSBindings] Refactor literal protocol requirement handling
2021-01-07 17:34:05 -08:00
Pavel Yaskevich
33f34d15f6 Merge pull request #35281 from xedin/rdar-72819046
[Diagnostics] Special case requirement failures related to `return` statement/expression
2021-01-07 08:56:15 -08:00
Pavel Yaskevich
4917d4314b [ConstraintSystem] Use new ConformanceRequirement to record checked conformances and conditional requirements 2021-01-06 11:01:35 -08:00
Pavel Yaskevich
2393a7c9a4 [CSBindings] Represent literal requirements as a struct instead of a tuple
Doing so streamlines access to the information associated with literal
protocol requirements and allows to add more helpers.

Also cache default type in the struct itself for easy access.
2021-01-04 10:32:08 -08:00
Pavel Yaskevich
e676e05f13 [CSBindings] Transform literal requirements into bindings when type variable is attempted 2021-01-04 09:20:14 -08:00
Pavel Yaskevich
731810e184 [CSBindings] Check literal coverage as new bindings/requirements are discovered
One more step towards incrementality of binding inference. Instead of
trying to determine literal protocol coverage during finalization
of the bindings, let's do that as soon as new bindings and/or literal
protocol requirements are discovered.
2021-01-04 09:20:14 -08:00
Pavel Yaskevich
650c54b822 [CSBindings] Split literals from other protocol requirements
Literal protocol requirements are handled differently from other
protocols, they require additional contextual information (such
as coverage, direct/transitive distinction), and participate in
binding inference (could be turned into default bindings).
2021-01-04 09:20:14 -08:00
Slava Pestov
e675bee26c AST: Split off DependencyCollector.h from EvaluatorDependencies.h
Also remove some unnecessary #includes from DependencyCollector.h,
which necessitated adding #includes in various other files.
2020-12-23 00:00:25 -05:00
Slava Pestov
2c5abd88b0 Merge pull request #35132 from slavapestov/optimize-is-unavailable
Sema: Optimize ConstraintSystem::is{Decl,Conformance}Unavailable
2020-12-17 13:06:41 -05:00
Pavel Yaskevich
3e1b01ac7a Merge pull request #35098 from xedin/dont-precompute-default-bindings
[CSBindings] Don't generate bindings for defaults
2020-12-17 00:33:37 -08:00
Slava Pestov
486562a191 Sema: Optimize ConstraintSystem::is{Decl,Conformance}Unavailable
Let's avoid creating an ExportContext, which computes a bunch of
irrelevant stuff. Also, delay the expensive call to
overApproximateAvailabilityAtLocation() unless we know the
declaration is conditionally unavailable.
2020-12-16 21:34:26 -05:00
Slava Pestov
bf23faa3ed Merge pull request #35112 from slavapestov/request-evaluator-caching-optimization
Hacks to avoid request evaluator caching overhead
2020-12-16 19:15:50 -05:00
Slava Pestov
008a97ef4e AST: Convert IsAsyncHandlerRequest to use separate caching 2020-12-15 23:43:05 -05:00
Pavel Yaskevich
9649b76042 [CSBindings] Don't generate bindings for defaults
Let's keep defaults separate from direct and transitive bindings,
that would make it easier to handle them in incremental model.

Instead of generating bindings for defaults and adding to the main
set, let's allow producer to choose what to do with them once type
variable has been picked for attempting.
2020-12-15 13:17:41 -08:00
Pavel Yaskevich
8e4207e0d8 [ConstraintSystem] NFC: Simplify type var producer/step by referencing constraint system from bindings 2020-12-11 00:30:39 -08:00
Pavel Yaskevich
22b34e8f36 [CSBindings] Let producer record a binding for a hole
As a step towards making binding inference more incremental, let's
make producer responsible for adding hole type binding instead of
doing so in `finalize`.
2020-12-10 15:39:38 -08:00
Pavel Yaskevich
50cc0f040f [ConstraintSystem] NFC: Extract requiresOptionalAdjustment so it could be used for default bindings 2020-12-09 13:34:30 -08:00
Pavel Yaskevich
e6784292cc [ConstraintSystem] Make binding producer responsible for attemping Any last
Instead of doing that while collecting bindings, let's move `Any`
to the end of the list when type variable has been selected to be
attempted next.
2020-12-09 13:34:01 -08:00
Pavel Yaskevich
ef673c74f1 [ConstraintSystem] Handle binding nullability in producer instead of collector
Wrapping bindings into optional type based on presence of
an `ExpressibleByNilLiteral` conformance requirement should
be done after type variable has been selected for attempting.
Otherwise such upfront work would be wasteful since it doesn't
affect binding ranking in any way.
2020-12-09 13:34:01 -08:00
Pavel Yaskevich
276e1a2ad0 Merge pull request #34989 from xedin/rdar-71525503
[ConstraintSystem] Adjust `getFunctionArgApplyInfo` to respect holes
2020-12-07 16:15:28 -08:00
Pavel Yaskevich
a046eaf477 [ConstraintSystem] Adjust getFunctionArgApplyInfo to respect holes
Detect that direct callee couldn't be resolved e.g. due to an
invalid reference or a missing member and fail instead of
triggering an assert.

Resolves: rdar://problem/71525503
2020-12-07 13:55:57 -08:00
Frederick Kellison-Linn
a53b1e4f3f [Sema] Always look through optionals for unresolved member lookup 2020-12-04 12:11:10 -05:00
Nathan Hawes
1eb05b7760 Merge pull request #34733 from nathawes/migrate-unresolved-completion
[CodeCompletion][Sema][Parse] Migrate unresolved member completion to the solver-based completion implementation
2020-11-19 01:26:43 -08:00
Nathan Hawes
86ddd52204 [Sema] Extract out expression-contains-completion-loc check into a method on ConstraintSystem (NFC) 2020-11-19 09:32:38 +11:00
Slava Pestov
0ff82ca051 Sema: Check conformance availability when ranking solutions
This completes the work on <rdar://problem/35158274>, and also
adds a test case for <rdar://problem/50627401>.
2020-11-10 17:52:51 -05:00
Pavel Yaskevich
d7c6c00e04 Merge pull request #34614 from xedin/improvements-to-ambiguity-diags
[Diagnostic] Improve diagnostics for situations with ambiguity caused by conformance requirements
2020-11-09 16:07:11 -08:00
Pavel Yaskevich
2e2792e3e3 [ConstraintSystem] Adjust diagnoseAmbiguity to use a local slice of overloads
Compute a slice of ambiguous overload choices related to an aggregated fix
and if such a slice points to a single overload diagnose it as non-ambiguous.
2020-11-06 10:42:25 -08:00
Doug Gregor
33cfbbdd72 [Concurrency] Don't diagnose missing "self." in async let autoclosures. 2020-11-04 23:18:51 -08:00