Commit Graph

20126 Commits

Author SHA1 Message Date
Konrad `ktoso` Malawski
a78d1bc47a Merge pull request #40179 from ktoso/wip-dist-func-protos
[Distributed] Improve error messages for protocol conformances
2021-11-16 15:07:35 +09:00
Pavel Yaskevich
49c366870c [BuilderTransform] Don't skip multi-statement closures during pre-check
Each of the elements in the result builder has to be fully pre-checked
now that multi-statement inference has been enabled.
2021-11-15 16:48:38 -08:00
Pavel Yaskevich
d5a82c5f4a [TypeChecker] NFC: Fix merge conflict in typeCheckBinding 2021-11-15 16:48:38 -08:00
Pavel Yaskevich
aa3b8867a3 [ConstraintSystem] Attempt conjunction before closure result or generic parameter holes
Closure result type or generic parameter associated with such a location
could bw inferred from a body of a multi-statement closure (when inference
is enabled), so we need to give closure a chance to run before attemtping
a hole for such positions in diagnostic mode.
2021-11-15 16:42:06 -08:00
Pavel Yaskevich
8b901544ee [MiscDiagnostics] Introduce a base class for diagnostic walkers
Put some common logic related to local declaration to the base
class and refactor other walkers to use it instead of `ASTWalker`.
2021-11-15 16:42:05 -08:00
Pavel Yaskevich
3072a68b72 [Sema/CodeCompletion] Leave complex closure bodies unchecked
Preserve pre SE-0326 for code completion, so it could be ported
gradually.
2021-11-15 16:42:05 -08:00
Pavel Yaskevich
8dddc89127 [PreCheck] Avoid patterns that appear in closures when multi-statement inference is enabled
Scope down previous check to avoid walking into patterns that appear
in multi-statement closures if the inference is enabled.
2021-11-15 16:42:05 -08:00
Pavel Yaskevich
7b0f68c05f [Diagnostics] Apply "unhandled throw" diagnostic for for-in loop in closures
Extract diagnostic into a method and use it while type-checking
`for-in` in top-level code and in closures.
2021-11-15 16:42:05 -08:00
Pavel Yaskevich
8d1aeacc06 [CSClosure] Warn about defer being the last element in the closure body 2021-11-15 16:42:05 -08:00
Pavel Yaskevich
9509eef7a3 [TypeChecker/Constness] Diagnostics: Walk into multi-statement closures when inference is enabled
When multi-statement closure inference is enabled it's body is
type-checked together with enclosing context, so they could be
walked directly just like single-expressions ones.
2021-11-15 16:42:05 -08:00
Pavel Yaskevich
3555299e19 [TypeChecker] Teach declaration type-checking about LeaveClosureBodyUnchecked flag
Propagate `LeaveClosureBodyUnchecked` flag from `typeCheckASTNodeAtLoc`
down to declaration checker to skip checking closures associated with
pattern binding entry initializers. This is no-op until multi-statement
inference becomes enabled by default.
2021-11-15 16:42:05 -08:00
Pavel Yaskevich
83033198c3 [TypeChecker] Fix constraint solver to respect LeaveClosureBodyUnchecked flag 2021-11-15 16:42:05 -08:00
Pavel Yaskevich
3927f56dbd [ConstraintSystem] Warn about discarded expressions found in multi-statement closures 2021-11-15 16:42:04 -08:00
Pavel Yaskevich
990d8c8bce [Sema] DebuggerTestingTransform: avoid re-using AST nodes in generated code
While building a closure to inject `checkExpect` code, clone member
references associated with assignment. Re-using AST nodes is generally
invalid. This is visible with multi-statement closure inference enabled,
because the body is type-checked together with enclosing context
and both elements end up sharing `DeclRefExpr` and `MemberRefExpr`s.
2021-11-15 16:42:04 -08:00
Pavel Yaskevich
9218ca0d88 Merge pull request #40159 from xedin/rdar-85021348
[Diagnostics] Determine affected elements early in collection element…
2021-11-15 12:39:00 -08:00
Pavel Yaskevich
21350a99c1 Merge pull request #40130 from xedin/rdar-83610106-with-locals
[CSApply/Distributed] Identify implicitly throwing calls while applying solution
2021-11-15 11:04:16 -08:00
Hamish Knight
76c6254779 [AST] Refactor KeyPathExpr constructors
Now that the CSApply just uses components, we can
better split up the key path constructors to either
accept a set of resolved components, or a parsed
root or path.
2021-11-15 12:25:18 +00:00
Hamish Knight
d6ac93efb1 [CS] Don't set parsed paths for dynamic member key paths
The logic here could form AST loops due to passing
in `anchor` for the key path's parsed path.

However setting a parsed path here seems to be a
holdover from the CSDiag days, so set the path to
`nullptr` and rip out and the rest of the synthesis
and SanitizeExpr logic for it.

rdar://85236369
2021-11-15 12:25:17 +00:00
Hamish Knight
15098e22bd [AST] Rename resolveComponents -> setComponents
The naming here has bothered me for a little while
now, it just sets the components, it doesn't
resolve anything.
2021-11-15 12:25:17 +00:00
Konrad `ktoso` Malawski
f58b133a84 [Distributed] adjust conformance error messages a bit 2021-11-15 11:11:55 +09:00
Becca Royal-Gordon
36bae62b19 Print Sendable conformances for clang types 2021-11-12 23:13:29 -08:00
Becca Royal-Gordon
e130826686 [NFC] Attach SynthesizedFile to any FileUnit
Gives us a place to stuff synthesized declarations for, among other things, imported Clang decls.
2021-11-12 23:13:29 -08:00
Becca Royal-Gordon
7549278314 Allow imported types to add a Sendable conformance
...by using `__attribute__((swift_attr("@Sendable")))`. `@_nonSendable` will "beat" `@Sendable`, while `@_nonSendable(_assumed)` will not.

This commit also checks if `SwiftAttr` supports `#pragma clang attribute` and, if it does, defines `__SWIFT_ATTR_SUPPORTS_SENDABLE_DECLS` in imported headers so they know they can apply these attributes in an auditing style.
2021-11-12 23:13:29 -08:00
Pavel Yaskevich
70360eb8c6 [TypeCheckConcurrency] Stop exposing isAsynchronousContext as no longer useful
`ConstraintSystem` has its own method to determine this.
2021-11-12 21:16:06 -08:00
Pavel Yaskevich
fc0f05f416 [TypeChecker] Implement distributed thunk identification in expr rewritter
This logic cannot live in `ActorIsolationChecker` because
all of the relevant information is only accessible through
constraint system while applying solutions.
2021-11-12 21:15:59 -08:00
Pavel Yaskevich
115af99031 [CSApply] Mark call to distributed thunks as implicitly throwing
Use newly added `isDistributedThunk` check to determine whether
the given call is to a remote distributed actor and if so mark
it as implicitly throwing.

Resolves: rdar://83610106
2021-11-12 12:41:30 -08:00
Pavel Yaskevich
3cebfddac6 [Distributed] Add a way to determine if particular reference is to distributed thunk
Make it possible for type-checker to determine whether the given
reference in the given context represents a call to a remote distributed
actor.
2021-11-12 12:41:29 -08:00
Pavel Yaskevich
920669d7d7 [Concurrency] Extract the check for async context to the namespace
It's useful not only inside of isolation checking but in the
type-checker as well.
2021-11-12 12:41:29 -08:00
Pavel Yaskevich
0b4ec1c31e [ConstraintSystem] Add accessor to check whether target represents async let init 2021-11-12 12:41:29 -08:00
Slava Pestov
67535303b6 RequirementMachine: Move implementation of StructuralRequirementsRequest and ProtocolDependenciesRequest to RequirementLowering.cpp 2021-11-12 14:30:46 -05:00
Pavel Yaskevich
4343227d19 [Diagnostics] Determine affected elements early in collection element mismatches
Diagnostics cannot assume that solution would always be applied
to the constraint system, so all of the elements affected by the
mismatch have to be determined by the fix.

Resolves: rdar://85021348
2021-11-12 10:10:44 -08:00
Pavel Yaskevich
6b5564c293 Merge pull request #40110 from xedin/rdar-85166519
[Diagnostics] Don't assume that contextual type for optional chain is optional
2021-11-10 16:24:21 -08:00
Robert Widmann
658de80ca8 Merge pull request #39627 from CodaFi/the-replacements
Suggest Replacement Types for Invalid Placeholders
2021-11-10 16:23:29 -08:00
Slava Pestov
ce77849aff Merge pull request #40108 from AnthonyLatsis/sr15460
AssociatedTypeInference: Fix regression introduced in 1cf9622
2021-11-09 21:04:53 -05:00
Pavel Yaskevich
c4b3f86a70 [Diagnostics] Don't assume that contextual type for optional chain is optional
While checking validity of the optional chain, let's not assume
that the contextual type associated with is optional because
enclosing expression could too be invalid.

Resolves: rdar://85166519
2021-11-09 09:42:45 -08:00
Holly Borla
68326d7721 Merge pull request #36931 from xedin/bind-value-types-early
[Perf][CSBindings] Attempt a type variable early if it's constrained by a s…
2021-11-09 09:31:25 -08:00
Anthony Latsis
3282b86d76 AssociatedTypeInference: Fix regression introduced in 1cf9622 2021-11-09 18:32:27 +03:00
Doug Gregor
8651e6ac03 Merge pull request #40090 from DougGregor/ibaction-implies-mainactor 2021-11-08 23:10:42 -08:00
Doug Gregor
546f22a3f3 Merge pull request #40088 from DougGregor/async-witness-matching-resolution 2021-11-08 20:45:05 -08:00
Robert Widmann
b8e16e80d9 Merge pull request #40059 from CodaFi/sequential-consistency 2021-11-08 18:31:30 -08:00
Doug Gregor
3ddf8c6921 Actor isolation inference: @IBAction implies @MainActor(unsafe)
@IBAction calls are always delivered in the main thread, so reflect that
by inferring `@MainActor(unsafe)` for such methods whenever no other
actor isolation is provided.

Implements rdar://84474640.
2021-11-08 16:37:58 -08:00
Doug Gregor
293e31658c Prefer witnesses with no difference effects to ones that have fewer effects.
One can overload on async vs. non-async, and the constraint solver has a
preference rule based on context. Extend that preference rule to
witness matching, so we prefer a witness that exactly matches the
effects of the requirement to one that has fewer effects.

Fixes rdar://84034057.
2021-11-08 16:36:39 -08:00
Doug Gregor
42d0e4d1f1 Merge pull request #40092 from DougGregor/closure-isolated-param-isolation
Isolate closures to their 'isolated' parameters.
2021-11-08 16:34:04 -08:00
Pavel Yaskevich
bbdc5b1c9c [CSBindings] Account for API change: isCGFloatType -> isCGFloat 2021-11-08 13:52:53 -08:00
Holly Borla
020c29b347 [CSBindings] Don't attempt to bind type variables early if the conversion
type is CGFloat or Double, and minimize the diagnostic impact of this
heuristic by only binding early for valid code.
2021-11-08 13:51:23 -08:00
Pavel Yaskevich
4799acfb20 [CSBindings] Attempt a type variable early if it's constrained by a struct/enum type
If a type variable has a subtype binding which came from a conversion/subtype/equality
constraint to a struct or enum (expect to `AnyHashable`, `Unsafe{Mutable}RawPointer`),
attempt it early because that type is the only choice which is not going to fail such
constraint.

For example, in cases like `$T argument convertible to Int` type variable could
only be bound to `Int`, `Int!`, or `@lvalue Int` to satisfy that constraint, so
it would make sense to attempt to bind it to `Int` early if it doesn't represent
a result of a member lookup (that's how IUO and/or `@lvalue` could be inferred)`
and doesn't have any direct disjunction associated with it e.g. for coercion or
optional matching.
2021-11-08 13:51:23 -08:00
Robert Widmann
22405cefea Plumb the "Is Type Sequence" Bit Through the Surface AST 2021-11-08 13:48:30 -08:00
Hamish Knight
6ef96c9e3d Merge pull request #40083 from hamishknight/dont-favor-tuple-elements 2021-11-08 21:32:45 +00:00
Richard Wei
efb3a49fdd Merge pull request #40063 from rxwei/rdar84716758
[AutoDiff] Plumb witness derivative generic signatures through SILGen.
2021-11-08 13:21:52 -08:00
Doug Gregor
f4ac02fd63 Isolate closures to their 'isolated' parameters.
When a closure has an isolated parameter, the closure itself is
isolated to that parameter. Capture this in the isolation of the
closure itself, so it is propagated to nested closures.

Fixes rdar://83733845.
2021-11-08 13:20:16 -08:00