Commit Graph

10 Commits

Author SHA1 Message Date
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Nate Chandler
2436353377 [Test] Add regression test.
Fix is in https://github.com/apple/swift/pull/74157 .

rdar://129010265
2024-06-07 07:27:32 -07:00
Nate Chandler
c35b86a30d [SILGen] Borrow into in_guaranteed.
Don't create a copy in order to pass a value `@in_guaranteed`.  Just
`store_borrow` the value.

rdar://128710064
2024-06-06 15:45:22 -07:00
saehejkang
33c666a855 [SILGen]: Add test for parenthesized try expression 2024-04-29 17:57:02 -07:00
Nate Chandler
9f5a7c87c3 [SILGen] Fix leak in objc async thunk.
Fix a leak when emitting the native to foreign thunk for an async
function which fulfills an Objective-C protocol requirement which can be
fulfilled with either a value or an error via a nullable completion.

Previously, the SIL in question used to look like this:

```sil
  %maybe_completion = ...
  try_apply %impl..., normal success, ...

success(%value):
  switch_enum %maybe_completion...
      case some!enumelt: invoke
      case none!enumelt: ignore

ignore:
  br join

invoke(%completion):
  %some_value = enum Optional, some!enumelt, %value // consumes %value
  %guaranteed_some_value = begin_borrow %some_value
  %none_error = enum Optional, none!enumelt
  apply %completion(%guaranteed_some_value, %none_error)
  end_borrow %guaranteed_some_value
  destroy_value %some_value
  br join

join:
  destroy_value %maybe_completion
  ...
```

which leaks %value on the codepath through `ignore`.

Note that `%value` is consumed by the `enum` instruction, but
`%completion` is invoked with `%guaranteed_some_value`, a guaranteed
value.  So there is no need to consume %value in `invoke`.

Here, `%value` itself is borrowed and forwarded into an enum instruction
whose result is passed to `%completion`:

```sil
  %maybe_completion = ...
  try_apply %impl..., normal success, ...

success(%value):
  switch_enum %maybe_completion...
      case some!enumelt: invoke
      case none!enumelt: ignore

ignore:
  br join

invoke(%completion):
  %guaranteed_value = begin_borrow %value
  %guaranteed_some_value = enum Optional, some!enumelt, %guaranteed_value
  %none_error = enum Optional, none!enumelt
  apply %completion(%guaranteed_some_value, %none_error)
  end_borrow %guaranteed_some_value
  br join

join:
  destroy_value %maybe_completion
  destroy_value %value
  ...
```

Because an argument scope was already being created and a cleanup was
already being pushed for `%value`, nothing more is required to fix the
issue than to reorder the enum and the borrow.

rdar://119732084
2024-01-04 19:10:17 -08:00
Mike Ash
5928859970 [Test] Have rdar81421394.swift import Foundation.
This test occasionally fails due apparently not loading libswiftFoundation. The test relies on a bridging header to import the Foundation module, which seems iffy. Explicitly import Foundation instead.

rdar://114590327
2023-08-29 09:50:31 -04:00
Nate Chandler
b9ccde3771 SILFunctionType: Loosened assert.
Allowed SILFunctionType instances for pseudogeneric coroutines without
signatures to be created.  Such instances are created by
SILTypeSubstituter::substSILFunctionType when SILGen'ing a conformance
of a pseudogeneric type to a protocol featuring a coroutine requirement.

rdar://81421394
2023-04-19 17:53:15 -07:00
Nate Chandler
15ed62d5a7 [Test] Run more returned-as-async ObjC blocks.
Verify the recent fix at https://github.com/apple/swift/pull/42485.
2022-04-20 16:40:52 -07:00
Dmitri Gribenko
3de9e5ac77 Rename synthesized initializer test to follow the pattern
And also removed a test that is semantically a duplicate of the
synthesized initializer test.
2020-07-09 12:11:08 +02:00
zoecarver
096777eda7 [cxx-interop] Do not give the default C++ constructor's return statement a result.
The default C++ object constructor assigns the newly created object out of the function so, it should not return a value. Returning a value will trigger SILGen assertions.
2020-06-24 14:02:02 -07:00