Commit Graph

9293 Commits

Author SHA1 Message Date
Slava Pestov
abf59a3584 Merge pull request #79293 from slavapestov/fix-issue-79244
SIL: Fix type lowering of 'unowned T' where 'T' is a type parameter
2025-02-12 03:19:23 -05:00
Slava Pestov
c1d4589fb7 SIL: Fix type lowering of 'unowned T' where 'T' is a type parameter
The abstraction pattern's generic signature does not describe
the substituted type, and it may not be present at all.

Fixes https://github.com/swiftlang/swift/issues/79244.
2025-02-11 14:25:35 -05:00
eeckstein
aa0833b0b3 Merge pull request #79110 from eeckstein/verify_mark_dependence
SIL: Fix memory behavior of mark_dependence
2025-02-11 06:39:43 +01:00
John McCall
7bbca2c491 Merge pull request #79228 from rjmccall/trivial-isolated-any-autoclosure
Be sure to clear `@isolated(any)` from the constant function type
2025-02-10 23:55:25 -05:00
Erik Eckstein
6a6d3f0b13 SIL: handle mark_dependence in the MemoryLifetimeVerifier
The check is not perfect, because it only checks that the base operand is alive _at_ the mark_dependence.
Ideally it should check that the base operand is alive during the whole lifetime of the value operand.
2025-02-10 17:57:47 +01:00
Erik Eckstein
a88cb49ee8 SIL: define a memory-read effect on the mark_dependence base value
If the base value of a mark_dependence is an address, that memory location must be initialized at the mark_dependence.
This requires that the mark_dependence is considered to read from the base address.
2025-02-10 17:57:47 +01:00
Amritpan Kaur
4de2486ad9 [SILGen] Emit property descriptors for protocol extensions
but not for protocol requirements.
2025-02-09 10:19:44 -08:00
John McCall
b099009df6 Be sure to clear @isolated(any) from the constant function type.
I'm not completely sure why this code pattern triggers this --- or really,
why other code patterns don't --- but it's easy to fix.

Fixes rdar://142636640
2025-02-07 17:12:19 -05:00
Michael Gottesman
7e350bb4ce Revert "[concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated."
This reverts commit 0cb64638d0.
2025-02-06 14:05:06 -08:00
Michael Gottesman
f05f08c2c0 Revert "[concurrency] Make ActorIsolation::Nonisolated -> CallerIsolationInheriting and delete CallerIsolationInheriting."
This reverts commit 543b1e6ca3.
2025-02-06 14:04:30 -08:00
Andrew Trick
01c3343b05 Fix mark_dependence ownership: compatibility with owned values
This fixes an OSSA verification bug introduced here:

    commit 79b649854b
    Author: Meghana Gupta <meghanavgupta@gmail.com>
    Date:   Wed Jan 22 01:24:49 2025

        Fix operand ownership of mark_dependence [nonescaping] of address values

The bug only showed up with mark_dependence [nonescaping], which means mainly
affects `~Escapable` types. Adddressors happened to work because SILGen was
emitting a borrow scope around them.

Rather than reverting the change above, this fix migrates mark_dependence
[nonescaping] to an implicit borrow scope.

Fixes rdar://144199759 (Assert: mark_dependence [nonescaping]:
ownership incompatible with an owned value)
2025-02-05 16:23:14 -08:00
Andrew Trick
e705a6d7c3 Temporarily introduce AnyInteriorPointer operand ownership.
This is necessary to fix a recent OSSA bug that breaks common occurrences on
mark_dependence [nonescaping]. Rather than reverting that change above, we make
forward progress toward implicit borrows scopes, as was the original intention.

In the near future, all InteriorPointer instructions will create an implicit
borrow scope. This means we have the option of not emitting extraneous
begin/end_borrow instructions around intructions like ref_element_addr,
open_existential, and project_box. After that, we can also migrate
GuaranteedForwarding instructions like tuple_extract and struct_extract.
2025-02-05 16:23:02 -08:00
Michael Gottesman
543b1e6ca3 [concurrency] Make ActorIsolation::Nonisolated -> CallerIsolationInheriting and delete CallerIsolationInheriting. 2025-02-03 10:56:08 -08:00
Michael Gottesman
0cb64638d0 [concurrency] Add Concurrent/ConcurrentUnsafe and use it instead of ActorIsolation::Nonisolated.
This is just the first part of a larger transition.
2025-02-03 10:56:06 -08:00
Kuba (Brecka) Mracek
7d257c9a05 Revert "[embedded] Don't emit extensions to API descriptor under Embedded Swift, avoid compiler crash" 2025-01-31 11:01:52 -08:00
Kuba (Brecka) Mracek
fd9777e500 Merge pull request #78986 from kubamracek/embedded-api-descriptor
[embedded] Don't emit extensions to API descriptor under Embedded Swift, avoid compiler crash
2025-01-31 11:01:45 -08:00
Anthony Latsis
34f9b80cbc Merge pull request #78750 from AnthonyLatsis/oryza-sativa
[Gardening] Fix some set but not used variables
2025-01-31 04:29:05 +00:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Michael Gottesman
37720323d2 Merge pull request #78997 from gottesmm/wire-up-execution
[concurrency] Wire up execution(concurrent)/execution(caller)
2025-01-29 16:53:11 -08:00
Michael Gottesman
d79fcb6d84 [caller-isolation] Teach Sema how to handle isolation of explicit @execution({concurrent,caller}). 2025-01-28 13:48:44 -08:00
Kuba Mracek
636c82dfda [embedded] Don't emit extensions to API descriptor under Embedded Swift, avoid compiler crash 2025-01-28 11:13:57 -08:00
Nate Chandler
41bee47169 [Gardening] Sunk static function to use.
Now that the other caller of the function has been removed, it's more
convenient to have it adjacent to the only remaining caller.
2025-01-28 10:44:30 -08:00
Nate Chandler
ad9e090243 [SIL] Only visit final on-stack pai lifetime ends.
In OSSA, the `partial_apply [on_stack]` instruction produces a value
with odd characteristics that correspond to the fact that it is lowered
to a stack-allocating instruction.  Among these characteristics is the
fact that copies of such values aren't load bearing.

When visiting the lifetime-ending uses of a `partial_apply [on_stack]`
the lifetime ending uses of (transitive) copies of the partial_apply
must be considered as well.  Otherwise, the borrow scope it defins may be
incorrectly short:

```
%closure = partial_apply %fn(%value) // borrows %value
%closure2 = copy_value %closure
destroy_value %closure // does _not_ end borrow of %value!
...
destroy_value %closure2 // ends borrow of %value
...
destroy_value %value
```

Furthermore, _only_ the final such destroys actually count as the real
lifetime ends.  At least one client (OME) relies on
`visitOnStackLifetimeEnds` visiting at most a single lifetime end on any
path.

Rewrite the utility to use PrunedLiveness, tracking only destroys of
copies and forwards.  The final destroys are the destroys on the
boundary.

rdar://142636711
2025-01-28 10:44:30 -08:00
Nate Chandler
f9ddf8d4d7 [Test] Add for PAI::visitOnStackLifetimeEnds. 2025-01-28 10:44:29 -08:00
Nate Chandler
95b7b06bef [Test] Renamed test case.
Replaced a - with a _.
2025-01-28 10:44:29 -08:00
nate-chandler
8c63134570 Merge pull request #78682 from nate-chandler/rdar142636711_2
[TempRValueOpt] Invalidate insts when completing.
2025-01-27 12:53:57 -08:00
eeckstein
95f1dfbf07 Merge pull request #78885 from eeckstein/fix-without-actually-escaping
Fix two problems with `withoutActuallyEscaping`
2025-01-27 07:59:02 +01:00
eeckstein
6b58f8f701 Merge pull request #78846 from eeckstein/fix-is-lexical
SIL: look through `end_init_let_ref` instructions when checking for `isLexical`
2025-01-27 07:58:27 +01:00
Andrew Trick
f0144ab7b1 Merge pull request #78830 from atrick/fix-lifedep-trivial-deadend
SILGenCleanup: extend to handle trivial local var scopes
2025-01-25 15:34:35 -08:00
Meghana Gupta
d2936a15bc Merge pull request #78824 from meg-gupta/fixmdi
Fix operand ownership of mark_dependence [nonescaping] of address values
2025-01-24 14:59:36 -08:00
Erik Eckstein
000eaedd03 SIL: look through end_init_let_ref instructions when checking for isLexical
`end_init_let_ref` instructions are inserted in class initializers after all fields are initialized.
It's important to look through such instructions when checking the `isLexical` property of a value.

Fixes a mis-compile due to shrinking a lexical liferange of a class.
Part of rdar://140229560
2025-01-24 20:10:05 +01:00
Erik Eckstein
3ec5d7de24 SIL: replace the is_escaping_closure instruction with destroy_not_escaped_closure
The problem with `is_escaping_closure` was that it didn't consume its operand and therefore reference count checks were unreliable.
For example, copy-propagation could break it.
As this instruction was always used together with an immediately following `destroy_value` of the closure, it makes sense to combine both into a `destroy_not_escaped_closure`.
It
1. checks the reference count and returns true if it is 1
2. consumes and destroys the operand
2025-01-24 19:23:27 +01:00
Meghana Gupta
79b649854b Fix operand ownership of mark_dependence [nonescaping] of address values 2025-01-24 00:49:32 -08:00
Andrew Trick
1b72c7bbf6 SILGenCleanup: extend to handle trivial local var scopes
Improves OSSALifetimeCompletion to handle trivial variables when running from
SILGenCleanup. This only affects lifetime dependence diagnostics.

For the purpose of lifetime diagnostics, trivial local variables are only valid
within their lexical scope. Sadly, SILGen only know how to insert cleanup code
on normal function exits. SILGenCleanup relies on lifetime completion to fix
lifetimes on dead end paths.

  %var = move_value [var_decl]
  try_apply %f() : $..., normal bb1, error error
error:
  extend_lifetime %var <=== insert this
  unreachable

This allows Span to depend on local unsafe pointers AND be used within
throwing closures:

    _ = a.withUnsafeBufferPointer {
      let buffer = $0
      let view = Span(_unsafeElements: buffer)
      return view.withUnsafeBufferPointer(\.count)
    }
2025-01-23 12:42:43 -08:00
Michael Gottesman
082b824a8e [rbi] Change Region Based Isolation for closures to not use the AST and instead just use SIL.
The reason why I am doing this is that in certain cases the AST captures indices
will never actually line up with partial apply capture indices since we seem to
"smush" together closures and locally defined functions.

NOTE: The reason for the really small amount of test changes is that this change
does not change the actual output by design. The only cases I had to change were
a case where we began to emit a better diagnostic and also where I added code
coverage around _ and let _ since those require ignored_use to be implemented so
that they would be diagnosed (previously we just did not emit anything so we
couldn't emit the diagnostic at the SIL level).

rdar://142661388
2025-01-22 21:12:36 -08:00
Michael Gottesman
6058b1d9bd [silgen] Change SILGen to emit ignored_user for emitIgnoredExpr and black hole initialization. 2025-01-22 21:12:36 -08:00
Michael Gottesman
7ae56aab2e [sil] Add a new instruction ignored_use.
This is used for synthetic uses like _ = x that do not act as a true use but
instead only suppress unused variable warnings. This patch just adds the
instruction.

Eventually, we can use it to move the unused variable warning from Sema to SIL
slimmming the type checker down a little bit... but for now I am using it so
that other diagnostic passes can have a SIL instruction (with SIL location) so
that we can emit diagnostics on code like _ = x. Today we just do not emit
anything at all for that case so a diagnostic SIL pass would not see any
instruction that it could emit a diagnostic upon. In the next patch of this
series, I am going to add SILGen support to do that.
2025-01-22 21:12:36 -08:00
Becca Royal-Gordon
0ce403d680 [NFC] Add some pretty stack traces
These would have helped us to debug rdar://142693093 more quickly.
2025-01-21 17:33:09 -08:00
Nate Chandler
2eb3a86928 [NFC] SIL: Replaced a recursion with a worklist. 2025-01-16 08:18:30 -08:00
Nate Chandler
8c7f1484bb [Gardening] SIL: Move comment.
Move it to the lambda which it talks about.  The old location is in a
function which now enjoys multiple callers, and the comment applies to
only one.
2025-01-16 08:18:29 -08:00
nate-chandler
b59280c0f0 Merge pull request #78624 from nate-chandler/rdar142520491_2
[OSSACanonicalizeOwned] Fix liveness passed to completion.
2025-01-15 19:38:21 -08:00
Gábor Horváth
4ae5685536 Merge pull request #78544 from swiftlang/gaborh/calling-conv
[cxx-interop] Fix wrong calling convention for some C++ types
2025-01-14 10:12:29 +00:00
Nate Chandler
4135540f62 [NFC] PrunedLiveness: Permit postDomBlocks dupes.
According to the documentation,

```
It's ok if postDomBlocks has duplicates or extraneous blocks, as long
as they jointly post-dominate all live blocks that aren't on dead-end
paths.
```

Previously, though, duplicates resulted in trapping: each element of
`postDomBlocks` is pushed into a `BasicBlockWorklist`; when the second
occurrence of an element in `postDomBlocks` was encountered,
`BasicBlockWorklist::push` would trigger an assertion failure.

Here, `pushIfNotVisited` is called instead.
2025-01-13 17:00:30 -08:00
Erik Eckstein
cc308c97cf embedded: make sure to generate witness tables which are imported from other modules
In embedded swift all the code is generated in the top-level module.
De-serialized witness tables for class existentials must be code-gen'd and therefore made non-external.

Fixes an unresolved symbol linker error.
rdar://142561676
2025-01-13 14:08:35 +01:00
Nate Chandler
9f87e0a8c6 [SIL] Print AST types with print-module-on-error. 2025-01-12 15:32:54 -08:00
Ellie Shin
727fb8c32d Merge pull request #78258 from swiftlang/elsh/disallow-bypass-deser-check
Package CMO: add deserialization checks to ensure correct memory layout
2025-01-11 05:40:49 -08:00
Meghana Gupta
00b9dd58c5 Merge pull request #78557 from meg-gupta/fixcse
Look through forwarding instructions while querying ownership root
2025-01-10 19:45:45 -08:00
Meghana Gupta
6f375aa6b6 Look through forwarding instructions while querying ownership root
Fixes rdar://142507746
2025-01-10 11:52:06 -08:00
Gabor Horvath
8cde635433 [cxx-interop] Fix wrong calling convention for some C++ types
We erroneously used @autoreleased convention for C++ types in some
scenarios.
2025-01-10 12:42:47 +00:00
eeckstein
6b8c341b64 Merge pull request #78464 from eeckstein/sil-linker-error
SILLinker: convert an assert to a compiler error message
2025-01-09 07:44:47 +01:00