Commit Graph

2410 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
Joe Groff
5ccb26b16c Merge pull request #78493 from jckarter/addressable-for-dependencies-3
SIL: Consider Builtin.FixedArray and @_rawLayout types to be structurally addressable-for-dependencies.
2025-01-08 20:11:00 -08:00
Joe Groff
b291cf42a1 SIL: Consider Builtin.FixedArray and @_rawLayout types to be structurally addressable-for-dependencies.
A primary purpose of these features is to enable persistent references into their storage, so it's
reasonable to assume this property for these types and types containing them.
2025-01-08 10:17:14 -08:00
Joe Groff
bc405c5f0a Merge pull request #78457 from jckarter/addressable-for-depedencies-2
`@_addressableForDependencies` fixes
2025-01-08 07:49:56 -08:00
Erik Eckstein
67b8c08ef1 SILLinker: convert an assert to a compiler error message
Having a wrong linkage can happen if the user "re-defines" an existing function with a wrong linkage, e.g. using `@_cdecl`.
2025-01-08 11:00:27 +01:00
elsh
c03abed00d Package optimization allows bypassing resilience, but that assumes the memory layout of the
decl being accessed is correct. When this assumption fails due to a deserialization error
of its members, the use site accesses the layout with a wrong field offset, resulting in
UB or a crash. The deserialization error is currently not caught at compile time due to
LangOpts.EnableDeserializationRecovery being enabled by default to allow for recovery of some
of the deserialization errors at a later time. In case of member deserialization, however,
it's not necessarily recovered later on.

This PR tracks whether member deserialization had an error by recursively loading members and
checking for deserialization error, and fails and emits a diagnostic. It provides a way to
prevent resilience bypassing when the deserialized decl's layout is incorrect.

Resolves rdar://132411524
2025-01-07 21:51:49 -08:00
Joe Groff
d9ee3f4de8 Make behavior changes for addressable types unconditional.
With the other fixes, it is now possible to build the stdlib without conditionalizing these
behaviors. This will allow libraries to adopt addressability as an experimental feature
without breaking ABI when interacting with other code.
2025-01-07 14:59:46 -08:00
Joe Groff
31ec17556c SIL: Only lower nominal types marked with @_addressableForDependencies as such.
I accidentally typoed the RecursiveProperties constructor so that every type
was getting treated as addressable-for-dependencies. Oops.
2025-01-06 18:16:28 -08:00
Allan Shortlidge
d0f63a0753 AST: Split Availability.h into multiple headers.
Put AvailabilityRange into its own header with very few dependencies so that it
can be included freely in other headers that need to use it as a complete type.

NFC.
2025-01-03 18:36:04 -08:00
Joe Groff
5c4406b5e8 Add an @_addressableForDependencies type attribute.
This attribute makes it so that a parameter of the annotated type, as well as
any type structurally containing that type as a field, becomes passed as
if `@_addressable` if the return value of the function has a dependency on
the parameter. This allows nonescapable values to take interior pointers into
such types.
2025-01-02 21:33:51 -08:00
Michael Gottesman
56f38c4172 [concurrency] Add support in SILGen/SIL for emitting and calling implicit leading parameters for CallerInheritingIsolation isolation.
This does not change region isolation yet to recognize these as effectively
nonisolated.
2025-01-02 13:18:54 -08:00
Michael Gottesman
b2a4f7e3cc [sil] Add to SIL and SILGen the ability to emit/represent implicit parameters.
I need this today to add the implicit isolated parameter... but I can imagine us
adding more implicit parameters in the future, so it makes sense to formalize it
so it is easier to do in the future.
2025-01-02 13:18:11 -08:00
Allan Shortlidge
17dfbf5053 AST: Adopt SemanticAvailableAttr for SpecializeAttr. 2024-12-19 08:40:00 -08:00
fahadnayyar
0f2637c32e Merge pull request #78230 from fahadnayyar/returns-retained-objc-support
[cxx-interop] Add support for SWIFT_RETURNS_(UN)RETAINED for ObjC APIs returning C++ FRT
2024-12-18 07:27:41 -08:00
Fahad Nayyar
426d471d1e [cxx-interop] Add support for SWIFT_RETURNS_(UN)RETAINED for ObjC APIs returning C++ FRT
rdar://135360972
2024-12-17 17:31:47 -08:00
nate-chandler
c6e8590837 Merge pull request #78229 from omochi/fix-variadic-optional-crash
Fix a crash in type lowering verification when using variadic optional tuples
2024-12-17 16:33:27 -08:00
Allan Shortlidge
95cc7319a1 SIL: Revert public linkage for @_silgen_name forward declarations.
It turns out that the stdlib build depends on `internal` functions with
`@_silgen_name` getting hidden linkage in some configurations. Instead of
messing with the linkage computation, just fix the `stdlib/Error.swift` test by
making `setWillThrowHandler` `public` to give it the right linkage.

Resolves rdar://141590619.
2024-12-17 08:35:01 -08:00
omochimetaru
37c1775b78 vanish single tuple on lowering verification 2024-12-17 10:43:21 +09:00
Erik Eckstein
0441359b37 TypeLowering: assume that C unions can contain a pointer
C unions are imported as opaque types. Therefore we have to assume that a union contains a pointer.
This is important for alias analysis to catch escaping pointers via C unions.

Fixes a miscompile.
rdar://141555290
2024-12-16 19:37:54 +01:00
Allan Shortlidge
87d625ecdc SIL: Always give @_silgen_name forward declarations public linkage.
When `@_silgen_name` is applied to a function with no body, it is a forward
declaration. It therefore must be treated as an external (public) declaration
regardless of the access level it was given in source.

Resolves rdar://141436934.
2024-12-13 16:48:18 -08:00
Usama Hameed
203f906364 Serialize/Deserialize source locations for instructions (#77281)
This commit adds support for serializing and deserializing source locations for instructions.
2024-12-12 16:15:44 +05:00
Arnold Schwaighofer
fa01d8d2f0 SIL: builtin willThrow does not modify memory or release
This enables access enforcement analysis to classify a dynamic begin_access in
access patterns (such as the one below) involving a throwing function as not
having nested conflicts.

```
struct Stack {
  var items : [UInt8]

  mutating func pop() throws -> UInt8 {
    guard let item = items.popLast() else { throw SomeErr.err }
    return item
  }
  ...
}

class Container {
  private var ref : Stack

  @inline(never)
  internal func someMethod() throws {
     try ref.pop()
  }
  ...
}
```
rdar://141182074
2024-12-10 11:27:27 -08:00
Erik Eckstein
95798d18a9 SILPrinter: fix double spaces printed in block arguments 2024-12-09 21:37:43 +01:00
eeckstein
c05c4db7ef Merge pull request #77972 from eeckstein/fix-verifier
SILVerifier: fix a wrong check for witness_method instructions
2024-12-05 18:38:09 +01:00
Erik Eckstein
d16a213c1d SILVerifier: fix a wrong check for witness_method instructions
Consider that the lookup-type can be an opaque return type.

Also fixing the SILPrinter.

Fixes a verifier crash
https://github.com/swiftlang/swift/issues/77955
140939536
2024-12-05 07:21:35 +01:00
Joe Groff
3c0b08dbcb Prototype an @_addressable attribute that puts an argument at a stable address.
Many APIs using nonescapable types would like to vend interior pointers to their
parameter bindings, but this isn't normally always possible because of representation
changes the caller may do around the call, such as moving the value in or out of memory,
bridging or reabstracting it, etc. `@_addressable` forces the corresponding parameter
to be passed indirectly in memory, in its maximally-abstracted representation.
[TODO] If return values have a lifetime dependency on this parameter, the caller must
keep this in-memory representation alive for the duration of the dependent value's
lifetime.
2024-12-03 20:39:23 -08:00
Allan Shortlidge
ecf7ac910e Merge pull request #77907 from tshortli/semantic-decl-availability
AST: Refactor semantic unavailability queries
2024-12-03 08:30:13 -08:00
Allan Shortlidge
b2cc10cd94 AST: Introduce Decl::isSemanticallyUnavailable().
Adopt it in a few places as a replacement for `Decl::getSemanticUnavailableAttr()`.
2024-12-02 23:00:43 -08:00
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00