Commit Graph

1238 Commits

Author SHA1 Message Date
Kavon Farvardin
b0fb7c54b2 Merge pull request #60399 from kavon/fix-97646309
Fix crash when emitting force-unwrap-and-call expression for optional ObjC methods
2022-08-10 16:27:56 -07:00
Slava Pestov
9d96ed940f AST: Rename 'canonical wrt. generic signature' to 'reduced'
We had two notions of canonical types, one is the structural property
where it doesn't contain sugared types, the other one where it does
not contain reducible type parameters with respect to a generic
signature.

Rename the second one to a 'reduced type'.
2022-08-09 12:46:31 -04:00
Kavon Farvardin
d3f644a154 [SILGen] fix crash invoking global-actor qualified optional ObjC async method
Due to some changes in how the AST is constructed by CSApply to handle
global actors from @preconcurrency declarations, the AST for a force-call to
an optional ObjC method that is part of a global-actor qualified protocol, such as:

```
import Foundation

@MainActor
@objc protocol P {
  @objc optional func generateMaybe() async
}

extension P {
  func test() async -> Void {
        await self.generateMaybe!()
    }
}
```

now contains a function conversion in between the forced-value operation and the dynamic-ref:

```
(force_value_expr type='@MainActor () async -> ()'
  (optional_evaluation_expr implicit type='(@MainActor () async -> ())?'
    (inject_into_optional implicit type='(@MainActor () async -> ())?'
      (function_conversion_expr implicit type='@MainActor () async -> ()'   <<<<< new!
        (bind_optional_expr implicit type='() async -> ()'
          (dynamic_member_ref_expr type='(() async -> ())?' ... )))))
```

For compatibility with how ObjC does message sends to these optional methods, in Swift there
is a difference between how something like `a.method!()` and the following are compiled:

```
let meth = a.method!
meth()
```

The former will directly call the optional method and let the "unknown selector" error be emitted
if it's not implemented. But the latter will query the dynamic method and inject that result into an
`Optional<...>` to then be forced, yielding a "force-unwrap nil" error. It's a subtle difference but
those two scenarios lead to different code paths in SILGen.

Now, this patch fixes the issue by enhancing the recognition of these direct call scenarios so that it
can look past these function conversions. Because that recognition already tries to ignore implicit
conversions, this is not something new. The problem was that we weren't considering implicit conversions
between the optional-evaluation and bind-optional expressions.

This patch is intentionally precise about what kind of function conversions can be skipped, because I
do not know if all of them are OK to blindly skip or not. We might need to expand that in the future.

Resolves rdar://97646309
2022-08-03 14:20:47 -07:00
Hamish Knight
6e51841d14 [AST] Enforce that composeTuple drops parameter flags
Callers may either assert that the parameter flags
are empty, or ask for them to be dropped.
2022-08-02 13:56:31 +01:00
Michael Gottesman
f1182a73da [no-implicit-copy] Remove auto +1 param signature change called by noimplicit copy in favor of following normal convention.
I also added a bunch of tests for both the trivial/non-trivial case as well as
some docs to SIL.rst.
2022-07-19 16:39:03 -07:00
Doug Gregor
c8f4b09809 Merge pull request #59949 from DougGregor/super-call-concurrency-adjust
Cope with concurrency-related function type adjustments in calls to "super".
2022-07-07 13:53:18 -07:00
Doug Gregor
aa2270a043 Cope with concurrency-related function type adjustments in calls to "super".
Fixes rdar://96545062.
2022-07-07 10:05:02 -07:00
Doug Gregor
cff02f8a0f Merge pull request #59926 from DougGregor/sink-actor-hop-for-get-access
Emit actor hop as part of call to the getter.
2022-07-06 16:16:09 -07:00
Doug Gregor
bc8bd4ea60 Emit actor hop as part of call to the getter.
When emitting a call to the getter for storage, emit the actor hop (and
hop back) as part of the call itself, rather than around the whole
initialization. This address a bug involving initialization with an
optional binding in an `if let`, where the hop-back would only be
performed on the non-nil branch.

Fixes rdar://96487805 / FB10562197
2022-07-06 13:14:50 -07:00
Konrad `ktoso` Malawski
728c007fb9 [Distributed] Implement witnesses for sync or non-throw dist reqs
[Distributed] generic and inner test; without one edge case

[Distributed] fix distributed_thunk test; unsure about those extra hops, could remove later

[Distributed] Remove type pretending in getSILFunctionType; it is not needed

It seems our constant replacement in the earlier phases is enough, and
we don't need this trick at all.

[Distributed] Use thunk when calling cross-actor on DA protocols
2022-07-04 19:02:11 +09:00
Konrad `ktoso` Malawski
ef525424f6 Merge pull request #59700 from xedin/distributed-computed-properties-via-accessor-thunk
[Distributed] Implement distributed computed properties via special accessor
2022-06-30 16:04:36 +09:00
Pavel Yaskevich
59ec5ab552 [Distributed] SILGen: Remove isDistributed flags from accessor code 2022-06-29 14:49:10 -07:00
Pavel Yaskevich
5bdf94f346 [Distributed] Remove commented out code and print statements 2022-06-29 14:49:10 -07:00
Konrad `ktoso` Malawski
febfef97d4 [Distributed] Skeleton implementation of distributed computed properties 2022-06-29 14:49:04 -07:00
Michael Gottesman
6a24087f90 Merge pull request #59611 from gottesmm/moveonly-rebase
[no-implicit-copy] Update SILGen/move checker to work with new patterns from copyable_to_moveonly and friends.
2022-06-28 13:45:15 -07:00
Konrad `ktoso` Malawski
6a2778645f Revert "Merge pull request #59481 from xedin/distributed-computed-properties"
This reverts commit 8125a85a8f, reversing
changes made to 728971c5b7.
2022-06-25 08:49:00 +09:00
Michael Gottesman
3088fe1a01 [move-only] Add support in SILGen for unwrapping moveonlywrapped values before materializing for a function argument.
I discovered this as I began to write some Interpreter tests for move only. This
was triggered by SILGen attempting to pass a non-trivial type to StringBuilder
which is generic, so we needed to materialize.

I also discovered a small bug where we were not properly ignoring class_method
in the move only type eliminator. I just folded the small fix + a test for that
into this commit.
2022-06-22 15:31:57 -07:00
Michael Gottesman
0d11e8ef69 [no-implicit-copy] Update SILGen/move checker to work with new patterns from copyable_to_moveonly and friends.
This involved doing the following:

1. Update the move only checker to look for new patterns.

2. Teach emitSemanticStore to use a moveonlywrapper_to_copyable to store moveonly
   values into memory. The various checkers will validate that this code is
   correct.

3. When emitting an apply, always unwrap move only variables. In the
   future, I am going to avoid this if a parameter is explicitly marked as also
   being moveonly (e.x.: @moveOnly parameter or @noEscape argument).

4. Convert from moveOnly -> copyable on return inst automatically in SILGen.

5. Fix SILGenLValue emission so we emit an error diagnostic later rather than
   crash. This is needed to keep SILGen emitting move only addresses (that is no
   implicit copy address only lets) in a form that the move only checker then
   will error upon. Without this change, SILGen crashes instead of emitting an
   error diagnostic in the following test:
   .//test/SILOptimizer/move_only_checker_addressonly_fail.swift
2022-06-21 16:47:58 -07:00
Pavel Yaskevich
4fa74c238f [AST] ApplyExpr: Rename shouldApplyDistributedThunk to usesDistributedThunk
Since the thunk is applied to expression during solution application,
the use of this flag has shifted towards stating the fact.
2022-06-17 12:35:54 -07:00
Pavel Yaskevich
cae01486c6 [CSApply] Distributed: Inject distributed thunk when necessary
Replace distributed member references with distributed thunks
when access happens outside of distributed actor context. This
significantly simplifies distributed compute properties implementation.
2022-06-17 12:35:48 -07:00
Pavel Yaskevich
567924f7f6 [Distributed] SILGen: Remove isDistributed flags from accessor code 2022-06-17 12:12:16 -07:00
Pavel Yaskevich
b963c6d20f [Distributed] Remove commented out code and print statements 2022-06-17 12:12:16 -07:00
Konrad `ktoso` Malawski
5a5b7c007c towards distributed getters 2022-06-17 12:12:16 -07:00
Konrad `ktoso` Malawski
079bbcf517 wip 2022-06-17 12:12:16 -07:00
Joe Groff
fd2a8e7745 Merge pull request #59290 from jckarter/type-expansion-wmo-private-type
SILGen: Carry WMO of type lowering context to closure captures.
2022-06-08 08:21:06 -07:00
Joe Groff
6b6a557611 SILGen: Carry WMO of type lowering context to closure captures.
TypeConverter doesn't know by itself what SILModule it's currently lowering on
behalf of, so the existing code forming the TypeExpansionContext for opaque types
incorrectly set the isWholeModule flag to always false. This created a miscompile
when a public API contained a closure that captured a value involving private types
from another file in the same module because of mismatched type expansion contexts
inside and outside the closure. Fixes rdar://93821679
2022-06-06 19:51:40 -07:00
Slava Pestov
27fd1bdc55 SILGen: Emit calls to default argument generators at the right abstraction level
Fixes rdar://problem/90717725 / https://bugs.swift.org/browse/SR-16051.
2022-06-02 00:41:32 -04:00
Ehud Adler
4267958d51 Mapping decl base name to imported name 2022-05-18 10:31:04 -04:00
Meghana Gupta
2398181b14 Fix SILGen for yields that are @guaranteed but of trivial type when opaque values are enabled 2022-05-11 21:15:21 -07:00
Meghana Gupta
f3870767b4 Fixes in SILGen for opaque value support in coroutines (#58696) 2022-05-11 01:01:09 -07:00
Kavon Farvardin
814fb42554 fix nested suspension issue with objc async calls
when two objc async functions are composed with each other,
i.e., f(g()), then the clean-ups for g() would get emitted
at an unexpected time, namely, during the suspension for
the call to f(). This means that using a clean-up to emit
the executor-hop breadcrumb was incorrect. The hop could
appear between a get_async continuation and its matching
await_continuation, which is an unsupported nested suspension.

This commit fixes that by removing the use of the breadcrumb
clean-up in favor of providing that breadcrumb directly to
the result plan, so that it may be emitted later on when the
result plan sees fit.

Fixes rdar://91502776
2022-05-02 18:20:59 -07:00
Kavon Farvardin
cb952ed37e Revert "Revert "[SR-15703] Fix missing hop in error path of foreign async throws call""
This reverts commit 05214f0d00.
2022-04-27 14:11:44 -07:00
Kavon Farvardin
6f86e2980a Revert "Revert "Simplify lifetime extension for async ObjC calls.""
This reverts commit 8441e07c0b.
2022-04-27 14:11:36 -07:00
Kavon Farvardin
8441e07c0b Revert "Simplify lifetime extension for async ObjC calls."
This reverts commit 01d470ce32.

Just to be safe, I'm reverting this part of https://github.com/apple/swift/pull/41571
as well, until it can be reimplemented in light of issues where a hop
can appear between a get_continuation and an await_continuation

resolves rdar://91502776
2022-04-25 12:12:26 -07:00
Kavon Farvardin
05214f0d00 Revert "[SR-15703] Fix missing hop in error path of foreign async throws call"
This reverts commit afd26d3974 to solve
a critical miscompile caused by a hop_to_executor appearing between
a get_continuation and await_continuation instruction in SIL.

A reimplementation of SR-15703 will be forthcoming.

Fixes rdar://91502776
2022-04-25 11:00:37 -07:00
zoecarver
336cd29333 [cxx-interop] Add support for calling members of base classes on UFOs. 2022-04-21 13:40:59 -07:00
Anthony Latsis
62a2c9e265 Merge pull request #42137 from AnthonyLatsis/objc-optional-keypath
SILGen: Handle key paths with `@objc optional` property and subscript components
2022-04-02 13:53:25 +03:00
Anthony Latsis
8462493fc9 SILGen: Avoid passing an expression to emitDynamicSubscriptExpr 2022-04-01 17:15:32 +03:00
Anthony Latsis
b68457b6aa [NFC] Gardening: Clean up a redundant computation 2022-04-01 17:15:32 +03:00
Anthony Latsis
9666ea635d SILGenApply: Avoid passing an expression to emitDynamicMemberRefExpr 2022-04-01 17:15:12 +03:00
Joe Groff
d451203b7f SILGen: Emit async let entry points at correct abstraction level.
Avoid a reabstraction thunk every time an async let entry point is emitted,
by setting the context abstraction level while we emit the implicit closure.
Adjust some surrounding logic that breaks when we do this:

- When lowering a non-throwing function type against a throwing abstraction
  pattern, include the error type in the lowered substituted type. Async
  throwing and nonthrowing functions would require another thunk to convert
  away the throwingness of the async context, which would defeat the purpose.
- Adjust the code in IRGen that pads the initial context size for `async let`
  entry points so that it works when the entry point has not yet emitted, by
  marking the async function pointer to be padded later if it isn't defined
  yet.
2022-03-30 14:51:46 -07:00
Andrew Trick
caaad424d8 [SIL-opaque] Various SILGen fixes 2022-03-22 17:04:13 -07:00
Allan Shortlidge
c1e326cbb0 SILGen: Fix SILGen for accessor functions with @_backDeploy. Previously, the @_backDeploy attribute was ignored when generating SIL for accessors on declarations with the attribute since the accessor decls themselves were not directly annotated.
Also, emit an error when `@_backDeploy` is applied to coroutine accessors since they are not supported yet.

Resolves rdar://90112441
2022-03-11 11:07:04 -08:00
Konrad `ktoso` Malawski
5ab8e0834d [Distributed] Reimplement distributed call thunks completely in AST (#41616)
* [Distributed] dist actor always has default executor (currently)

* [Distributed] extra test for missing makeEncoder

* [DistributedDecl] Add DistributedActorSystem to known SDK types

* [DistributedActor] ok progress on getting the system via witness

* [Distributed] allow hop-to `let any: any X` where X is DistActor

* [Distributed] AST: Add an accessor to determine whether type is distributed actor

- Classes have specialized method on their declarations
- Archetypes and existentials check their conformances for
  presence of `DistributedActor` protocol.

* [Distributed] AST: Account for distributed members declared in class extensions

`getConcreteReplacementForProtocolActorSystemType` should use `getSelfClassDecl`
otherwise it wouldn't be able to find actor if the member is declared in an extension.

* [Distributed] fix ad-hoc requirement checks for 'mutating'

[PreChecker] LookupDC might be null, so account for that

* [Distributed] Completed AST synthesis for dist thunk

* [Distributed][ASTDumper] print pretty distributed in right color in AST dumps

* wip on making the local/remote calls

* using the _local to mark the localCall as known local

* [Distributed] fix passing Never when not throwing

* fix lifetime of mangled string

* [Distributed] Implement recordGenericSubstitution

* [Distributed] Dont add .

* [Distributed] dont emit thunk when func broken

* [Distributed] fix tests; cleanups

* [Distributed] cleanup, move is... funcs to DistributedDecl

* [Distributed] Remove SILGen for distributed thunks, it is in Sema now!

* [Distributed]  no need to check stored props in protocols

* remote not used flag

* fix mangling test

* [Distributed] Synthesis: Don't re-use AST nodes for `decodeArgument` references

* [Distributed] Synthesis: Make sure that each thunk parameter has an internal name

* [Distributed/Synthesis] NFC: Add a comment regarding empty internal parameter names

* [Distributed] NFC: Adjust distributed thunk manglings in the accessor section test-cases

* cleanup

* [Distributed] NFC: Adjust distributed thunk manglings in the accessor thunk test-cases

* review follow ups

* xfail some linux tests for now so we can land the AST thunk

* Update distributed_actor_remote_functions.swift

Co-authored-by: Pavel Yaskevich <xedin@apache.org>
2022-03-10 23:58:23 +09:00
Allan Shortlidge
f6ab0ae7a3 Merge pull request #41612 from tshortli/back-deploy-diagnose-decls
Update @_backDeploy ABI semantics and diagnose invalid declarations
2022-03-02 12:52:47 -08:00
Allan Shortlidge
0f890b86fa Sema: Diagnose use of the @_backDeploy attribute on non-final and @objc decls. 2022-03-01 16:37:32 -08:00
Joe Groff
fb178c6c65 Merge pull request #41549 from jckarter/disable-reabstraction-opt-for-foreign-convention
SILGen: Add missing processing to reabstraction fast-path.
2022-02-28 10:32:25 -08:00
swift-ci
e16b126f09 Merge pull request #41571 from kavon/SR-15703
[SR-15703] Fix missing hop in error path of foreign async throws call
2022-02-25 21:31:18 -08:00
Kavon Farvardin
afd26d3974 [SR-15703] Fix missing hop in error path of foreign async throws call
resolves rdar://89479707
2022-02-25 18:32:43 -07:00
Kavon Farvardin
01d470ce32 Simplify lifetime extension for async ObjC calls.
Since the clean-up is not unwind only, we can rely on the
clean-ups to be emitted on both result and throw paths.

This does slightly change when the hop_to_executor is emitted,
in those paths, but that shouldn't matter.

refactors solution for rdar://78982371
2022-02-25 18:32:13 -07:00