Commit Graph

9332 Commits

Author SHA1 Message Date
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
Kuba Mracek
6f4ae28520 [ASTMangler] Pass ASTContext to all instantiations of ASTMangler 2024-12-02 15:01:04 -08:00
Erik Eckstein
a1334973c9 SILPrinter: don't print operand types in static initializers of globals
This was missing from https://github.com/swiftlang/swift/pull/77763
2024-11-22 15:19:25 +01:00
eeckstein
29f6f01a46 Merge pull request #77763 from eeckstein/sil-printing
SIL: don't print operand types in textual SIL
2024-11-22 06:42:29 +01:00
Doug Gregor
077fec052c Pretend that swift_willThrowTypedImpl doesn't use its generic metadata 2024-11-21 12:39:41 -08:00
Erik Eckstein
d59d35765c SIL: add -Xllvm -sil-print-no-uses to not print use-list comments in textual SIL 2024-11-21 18:49:52 +01:00
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
Andrew Trick
ff21ddefa6 Merge pull request #77675 from atrick/endapply_utils
[NFC] Utilities for lifetime dependent coroutines
2024-11-18 09:44:25 -08:00
Andrew Trick
4612728581 [NFC] Add BeginApplyInst::getEndApplyUses() API.
A begin_apply token may be used by operands that do not end the coroutine:
mark_dependence.

We need an API that gives us only the coroutine-ending uses. This blocks
~Escapable accessors.

end_borrow is considered coroutine-ending even though it does not actually
terminate the coroutine.

We cannot simply ask isLifetimeEnding, because end_apply and abort_apply do not
end any lifetime.
2024-11-18 01:37:00 -08:00
Slava Pestov
47156e006b AST: Introduce ProtocolConformanceRef::forAbstract() 2024-11-16 16:16:06 -05:00
Nate Chandler
73de4de8a0 [CoroutineAccessors] TBDify synthesized defaults. 2024-11-13 21:33:08 -08:00
Nate Chandler
e76dc2d5e4 [Devirtualizer] Replace begin_apply allocations.
When devirtualizing a yield_once_2 begin_apply, replace all uses of the
allocation address, just as is done with the token.
2024-11-13 21:33:07 -08:00