Commit Graph

9293 Commits

Author SHA1 Message Date
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
Erik Eckstein
41dd3dc453 DeadObjectElimination: handle OSSA instructions when analyzing class destructors
Handle typical patterns which are generated by SILGen.
2024-12-24 12:00:22 +01:00
eeckstein
e6b9cb986f Merge pull request #78290 from eeckstein/sil-infrastructure
Some AST and SIL infrastructure additions and improvements
2024-12-20 07:18:32 +01:00
Erik Eckstein
4fdf16de1b SIL: add CanonicalType.canBeClass
And move the implementation of `SIL.Type.canBeClass` to the AST Type. The SIL Type just calls the AST Type implementation.
Also rename `SIL.Type.canonicalASTType` -> `SIL.Type.astType`.
2024-12-19 20:53:46 +01: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
eeckstein
22b31dcaa8 Merge pull request #78221 from eeckstein/pointers_in_c_unions
TypeLowering: assume that C unions can contain a pointer
2024-12-17 06:59:24 +01:00
omochimetaru
37c1775b78 vanish single tuple on lowering verification 2024-12-17 10:43:21 +09:00
Meghana Gupta
349c3f19a6 Merge pull request #78217 from meg-gupta/fixreborrowverify
Fix reborrow verifier to look through borrowed from
2024-12-16 15:58:53 -08: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
Meghana Gupta
4cab04e190 Fix reborrow verifier to look through borrowed from 2024-12-16 10:23:18 -08:00
Allan Shortlidge
8f5e37c57c Merge pull request #78183 from tshortli/silgen-name-linkage
SIL: Always give `@_silgen_name` forward declarations public linkage
2024-12-14 10:12:03 -08:00
nate-chandler
120cf432f1 Merge pull request #78180 from nate-chandler/rdar141246601
[OSSACompleteLifetime] Recurse into scoped addresses.
2024-12-14 08:44:00 -08: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
Nate Chandler
bf80307c03 [OSSACompleteLifetime] Recurse into scoped addrs.
Previously, when determining and completing lifetimes of scoped
addresses, `computeTransitiveLiveness` was used to determine the
liveness used for completing the lifetime.

That approach had two problems:
(1) The function does not find scope-ending uses of `load_borrow`s.
    The result was determining that the lifetime of the enclosing
    `store_borrow` ended before that of the `load_borrow`.
(2) The function did not complete lifetimes of values defined within the
    scoped address whose lifetimes the scoped address had to contain.
    This was an inconsistency between the handling of scoped addresses
    and that of values.

Here, both are addressed by implementing a `TransitiveAddressWalker` (as
`computeTransitiveLiveness`'s callee does) which not only visits
existing `end_borrow`s of `load_borrows` but completes them (and other
inner guaranteed values or scoped addresses).

rdar://141246601
2024-12-13 15:04:29 -08:00
Nate Chandler
618b99c3e9 [NFC] OSSACompleteLifetime: Extracted method.
In preparation to expand it.
2024-12-13 12:22:31 -08:00
Meghana Gupta
28e33af799 Merge pull request #78123 from meg-gupta/newflag
Add new flag -sil-ownership-verify-all
2024-12-13 10:00:41 -08:00
Meghana Gupta
8b1ecb8a71 Add new flag -sil-ownership-verify-all
This flag enables ownership verification after every transform.
2024-12-12 23:55:37 -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
Meghana Gupta
3542af99b2 Merge pull request #78109 from meg-gupta/ossablocklist1
Allow disabling ownership verification via blocklist
2024-12-11 13:40:58 -08:00
Meghana Gupta
b2ba59082c Merge pull request #78102 from meg-gupta/turnonverify
Turn on ownership verification in no-asserts build
2024-12-11 10:24:10 -08:00
Meghana Gupta
bb68264e0e Allow disabling ownership verification via blocklists 2024-12-11 03:41:07 -08:00
Meghana Gupta
c5a19b9354 Turn on ownership verification in no-asserts build 2024-12-10 16:48:24 -08: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
Nate Chandler
be7518b389 [OSSACompleteLifetime] Handle scoped addresses.
Complete scopes of scoped addresses (introduced by `store_borrow` and
`begin_access`) in dead end blocks via
`ScopedAddressValue::computeTransitiveLiveness`.

rdar://141037060
2024-12-06 16:22:24 -08:00
Nate Chandler
7fb5d31261 [NFC] OSSACompleteLifetime: Move function up.
Avoid a separate declaration.
2024-12-06 16:22:24 -08:00
Nate Chandler
36203de6d4 [NFC] OSSACompleteLifetime: Extracted function.
In preparation for adding a second caller.
2024-12-06 16:22:24 -08:00
Nate Chandler
c47c8ea72b [NFC] Return instruction from createScopeEnd. 2024-12-06 16:22:24 -08:00
nate-chandler
5637eaf3ca Merge pull request #77968 from nate-chandler/rdar139842132
[OSSACanonicalizeOwned] Record traversed defs and don't traverse copies of guaranteed values.
2024-12-06 07:00:20 -08: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
Nate Chandler
7012edc06f [Gardening] Test: Updated comment. 2024-12-05 07:31:19 -08: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
9c77074cac [Mangling] Establish a new mangling prefix for Embedded Swift: $e 2024-12-02 15:01:24 -08:00