Commit Graph

1246 Commits

Author SHA1 Message Date
Michael Gottesman
525ba8c07b [move-only] When passing a move only struct address, pass it as a true borrowed parameter.
This ensures that the address move checker does not have to perform any unsound
access scope expansions. One note is that the current approach does not work for
class member refs since in SILGenLValue, a class is considered a base of the
SILGenLValue access which is immediately evaluated (causing a copy) rather than
evaluated later at formal evaluation time. I have a few ways of working around
this issue but am going to fix it in a subsequent commit when I fix this for
classes and also read coroutines.

rdar://99616492
2022-11-10 17:20:32 -08:00
swift-ci
fd6fd76dae Merge pull request #42513 from jsoref/spelling-silgen
Spelling silgen
2022-11-09 23:28:43 -08:00
Josh Soref
9a6bf46c0f Spelling silgen
* actually
* arbitrary
* cargo-culted
* clazz
* constrained
* continuation
* coordinator
* coroutine
* derivative
* destroyer
* given
* have
* imported
* initialization
* items
* necessarily
* occurring
* omitting
* overridden
* parameter
* possible
* predecessor
* preparation
* resilience
* should
* struct
* that
* the
* throwing
* unexpectedly
* uniqueness
* using
* value
* villain

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2022-11-09 21:44:17 -05:00
Michael Gottesman
14c687a577 [move-only] Emit the move only marker for move only trivial enums.
Just an oversight I discovered when writing the enum deinit tests.
2022-10-24 20:05:04 -07:00
Hamish Knight
9b29f75b99 [SILGen] NFC: Remove unused emitApplyMethod 2022-10-06 20:29:47 +01:00
Doug Gregor
5191c315e1 Eliminate ImplicitActorHopTarget in favor of ActorIsolation.
The generalized ActorIsolation is enough to represent everything that
ImplicitActorHopTarget can do, and we were mapping between the two way
too often, so collapse them.
2022-08-23 23:19:46 -07:00
Nate Chandler
3c78a0bb90 [SILGen] Only lexical types get lexical lifetimes.
Only emit `begin_borrow [lexical]` and only mark `alloc_stack`s
`[lexical]` when the variable in question's lifetime is lexical, not
eager move.
2022-08-22 15:28:00 -07:00
Meghana Gupta
196994fc11 Fix store_borrow generation in SILGen
This change ensures all store_borrows are ended with an end_borrow, and uses of the store_borrow
destination are all in the enclosing store_borrow scope and via the store_borrow return address.

Fix tests to reflect new store_borrow pattern
2022-08-16 15:08:22 -07:00
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