Commit Graph

1685 Commits

Author SHA1 Message Date
Andrew Trick
b28cd59dfc [NFC] TypeLowering: add CustomDeinit.
Teach SIL type lowering to recursively track custom vs. default deinit status.

Determine whether each type recursively only has default deinitialization. This
includes any recursive deinitializers that may be invoked by releasing a
reference held by this type.

If a type only has default deinitialization, then the deinitializer cannot
have any semantically-visible side effects. It cannot write to any memory
2025-11-11 17:29:45 -08:00
Meghana Gupta
21cc1a185b Add memory lifetime verification support for borrow accessors 2025-11-06 10:55:42 -08:00
Meghana Gupta
778ad0dfb5 Add SIL verification to ensure we don't return local addresses 2025-11-06 10:55:39 -08:00
Doug Gregor
38c23bcdda [Serialization] Allow near-misses when matching imported Clang declarations
Fixes the rest of rdar://137014448.
2025-11-02 07:21:15 -08:00
Kavon Farvardin
2d881bdc9c ManualOwnership: provide ability to apply to entire compilation unit
With this patch, I'm flipping the polarity of things.

The flag `-enable-experimental-feature ManualOwnership` now turns on the diagnostics,
but they're all silenced by default. So, you need to add -Wwarning or -Werror to
your build settings to turn on the specific diagnostics you care about.

These are the diagnostic groups relevant to the feature:

- SemanticCopies aka "explicit copies mode"
- DynamicExclusivity

For example, the build setting `-Werror SemanticCopies` now gives you errors about
explicit copies, just as before, but now you can make them just warnings with -Wwarning.

To opt-out a declaration from everything when using the feature, use @_noManualOwnership.

@_manualOwnership is no longer an attribute as a result.

resolves rdar://163372569
2025-10-24 18:54:07 -07:00
Kavon Farvardin
135e02c1d9 ManualOwnership: improve diagnostics & testing 2025-10-24 16:59:44 -07:00
Kavon Farvardin
6b858b411c ManualOwnership: introduce 'DynamicExclusivity'
We can add warnings about dynamic exclusivity
checks that may happen on an access, with
explainers about why they happen for safety.
2025-10-24 16:59:44 -07:00
Kavon Farvardin
95a6719117 ManualOwnership: introduce 'SemanticCopies' diagnostic group
This includes documentation to explain how to understand
these diagnostics.
2025-10-24 16:59:41 -07:00
Kuba (Brecka) Mracek
eb23d3bc0a Merge pull request #85074 from kubamracek/section
SE-0492: Stabilize @_section/@_used into @section/@used
2025-10-24 12:29:48 -07:00
Meghana Gupta
cc0e75ca03 Merge pull request #85040 from meg-gupta/returnborrowpr
Introduce return_borrow and unchecked_ownership instructions for use with borrow accessors
2025-10-23 10:45:55 -07:00
Erik Eckstein
f32d4be69f SIL Verifier: don't run read-only access scope verification in lowered SIL
LoadableByAddress in lowered SIL can insert `copy_addr`s inside read-only access scope.

rdar://163248403
2025-10-23 14:59:02 +02:00
Meghana Gupta
e116df3628 Introduce return_borrow instruction 2025-10-23 05:18:59 -07:00
Kuba Mracek
adeb40f261 SE-0492: Stabilize @_section/@_used into @section/@used
Removes the underscored prefixes from the @_section and @_used attributes, making them public as @section and @used respectively. The SymbolLinkageMarkers experimental feature has been removed as these attributes are now part of the standard language. Implemented expression syntactic checking rules per SE-0492.

Major parts:
- Renamed @_section to @section and @_used to @used
- Removed the SymbolLinkageMarkers experimental feature
- Added parsing support for the old underscored names with deprecation warnings
- Updated all tests and examples to use the new attribute names
- Added syntactic validation for @section to align with SE-0492 (reusing the legality checker by @artemcm)
- Changed @DebugDescription macro to explicitly use a tuple type instead of type inferring it, to comply with the expression syntax rules
- Added a testcase for the various allowed and disallowed syntactic forms, `test/ConstValues/SectionSyntactic.swift`.
2025-10-22 16:05:39 -07:00
Erik Eckstein
4f1cbbd07d SIL Verifier: verify that inside a read-only access scope there are no stores to the memory location
This will e.g. catch violations like
```
  %1 = begin_access [read] %0
  store %2 to %0
  end_access %1
```

Also, fix all the sil tests which violate that.
2025-10-22 20:55:21 +02:00
Meghana Gupta
25f0e2f934 [NFC] Replace @guaranteed_addr by @guaranteed_address 2025-10-20 09:05:37 -07:00
Meghana Gupta
a0c939bd3b Use @inout result convention for mutate accessors 2025-10-20 09:05:32 -07:00
Michael Gottesman
a9d409d526 Merge pull request #83346 from gottesmm/pr-df6aafa41c61b9a9a6ee4965a1564ec2946a0dc9
[concurrency] Change #isolated to mask out the TBI bits of the witness pointer of the implicit isolated any Actor pointer so we can do optimizations on TBI supporting platforms in the future.
2025-10-17 17:02:43 -07:00
Doug Gregor
39a36d9216 Merge pull request #84948 from DougGregor/extern-c-asmname
[SILGen] Map the @_extern(c) C function name over to the asmname of a SIL function
2025-10-16 18:27:00 -07:00
Michael Gottesman
fe9c21fd87 [sil] Add a new instruction cast_implicit_actor_to_optional_actor.
This instruction converts Builtin.ImplicitActor to Optional<any Actor>. In the
process of doing so, it masks out the bits we may have stolen from the witness
table pointer of Builtin.ImplicitActor. The bits that we mask out are the bottom
two bits of the top nibble of the TBI space on platforms that support TBI (that
is bit 60,61 on arm64). On platforms that do not support TBI, we just use the
bottom two tagged pointer bits (0,1).

By using an instruction, we avoid having to represent the bitmasking that we are
performing at the SIL level and can instead just make the emission of the
bitmasking an IRGen detail. It also allows us to move detection if we are
compiling for AArch64 to be an IRGen flag instead of a LangOpts flag.

The instruction is a guaranteed forwarding instruction since we want to treat
its result as a borrowed projection from the Builtin.ImplicitActor.
2025-10-16 10:52:04 -07:00
eeckstein
b1774aab03 Merge pull request #84945 from eeckstein/fix-debugvar-verification
SILVerifier: relax the check for debug vars with different types
2025-10-16 12:58:31 +02:00
Doug Gregor
4b745170c3 [SILGen] Map the @_extern(c) C function name over to the asmname of a SIL function
`@_extern(c)` is meant for referencing C functions defined outside of
this Swift file. Instead of using the C function name as the SIL
function name, which is prone to collisions across different Swift
modules, place make the C function name the "asmname" of the
corresponding SIL function. Show that this prevents deserialization
errors when there are conflicting Swift-level types for the same
`@_extern(c)`-named symbol across modules.

Part of rdar://137014448.
Instead of using the C name as the mangled name of a SIL function
2025-10-15 23:19:12 -07:00
Erik Eckstein
395db88f6f SILVerifier: relax the check for debug vars with different types
Allow two identical debug variables have different types if the types are or contain local archetypes.
When cloning SIL (e.g. in LoopUnroll) local archetypes are uniqued and therefore distinct in cloned instructions.

Fixes a SIL verification error
https://github.com/swiftlang/swift/issues/84899
rdar://162660981
2025-10-16 07:14:46 +02:00
Doug Gregor
081b5cd1e8 [SIL] Serialize section name correctly and model it on global variables
Fixes rdar://162549960.
2025-10-15 20:44:11 -07:00
Doug Gregor
3e1ea3c0f7 [SIL] Add asmname attribute to SIL functions and global variables
The asmname attribute allows one to specify the name that will be used
when lowering a given SIL declaration to LLVM IR. It is not currently
exposed in the surface language.

Make sure this attribute round-trips through the parser and
serialization.

Part of rdar://137014448O.
2025-10-15 20:44:09 -07:00
John McCall
46623cb6c7 Merge pull request #84811 from rjmccall/verify-dead-end-edges
Strengthen the SIL verifier's rules for edges into dead-end regions
2025-10-11 18:16:56 -04:00
John McCall
90995b82f4 Teach the SIL verifier to enforce stronger rules around
edges into dead-end regions.

- Only treat edges *into* dead-end regions as special; edges internal
  the region must use the normal rules.

- Conservatively merge information along those edges rather than just
  picking one at random. This requires us to not walk into the region
  until we've processed all of the edges to it.

- Make sure we prevent *any* stack allocations from being deallocated
  if the stack is inconsistent entering a block.

Additionally, fix a bug which was incorrectly treating all blocks that
don't themselves exit the function as ultimately leading to unreachable,
which had inadvertently largely turned off the consistency check.
2025-10-11 02:12:19 -04:00
Meghana Gupta
5e325632ed Merge pull request #84746 from meg-gupta/mutateaccessorspr
Add support for mutate accessors
2025-10-08 11:08:59 -07:00
Gábor Horváth
0959bce25e Merge pull request #84612 from swiftlang/fix-overrelease-destroy-hoist
[cxx-interop] Delay lowering unowned convention until ownership elimination
2025-10-08 18:42:02 +01:00
Meghana Gupta
73bc2ac0b0 Map BorrowAndMutateAccessors experimental feature to swift-syntax equivalent 2025-10-07 14:39:22 -07:00
Meghana Gupta
4a29867a7b [NFC] Update end to end tests 2025-10-07 14:12:16 -07:00
Meghana Gupta
ea0e0173b4 Merge pull request #84595 from meg-gupta/moreborrowaccessors
Extend borrow accessor support
2025-10-03 11:14:49 -07:00
Gabor Horvath
5a63808235 Change the convention for reabstractions as well.
Remove SIL tests that are testing result conventions that are never
emitted by the compiler.
2025-10-03 14:58:48 +01:00
Kavon Farvardin
d58dd6e2c4 Merge pull request #84593 from kavon/manual-ownership/usability-fixes-5
ManualOwnership: don't diagnose unknown callees
2025-10-02 09:44:37 -07:00
Meghana Gupta
c86f2c0dbc Add a simple borrow accessor end to end test 2025-10-02 07:42:15 -07:00
Kavon Farvardin
f63117e01c ManualOwnership: don't diagnose unknown callees
Since the annotation is non-viral, we don't want to emit an error
when we counter a callee that is unknown.

resolves rdar://161407417
2025-09-30 10:13:45 -07:00
Arnold Schwaighofer
25a071efc8 Add experimental feature @inline(always)
The intent for `@inline(always)` is to act as an optimization control.
The user can rely on inlining to happen or the compiler will emit an error
message.

Because function values can be dynamic (closures, protocol/class lookup)
this guarantee can only be upheld for direct function references.

In cases where the optimizer can resolve dynamic function values the
attribute shall be respected.

rdar://148608854
2025-09-30 08:36:26 -07:00
eeckstein
a1e5a06c9e Merge pull request #84530 from eeckstein/remove-enable-oss-module-option
Remove the `-enable-ossa-modules` option
2025-09-27 07:35:40 +02:00
Erik Eckstein
2f124cf564 Remove the -enable-ossa-modules option.
OSSA modules are enabled by default.
The compiler still accepts this option but it has no effect.
2025-09-26 08:01:08 +02:00
Kavon Farvardin
a96e494c87 ManualOwnership: reword diagnostics
The term 'demand' didn't pass the hallway test.
2025-09-25 16:56:03 -07:00
Kavon Farvardin
e943c91158 ManualOwnership: improve diagnostics for address types
We can find the name of the source of a copy_addr to
give less confusing messages.
2025-09-25 16:26:16 -07:00
Kavon Farvardin
32263bb9b8 ManualOwnership: add workaround for vars
For a proof-of-concept quality feature,
we can just skip the pass causing problems until
a proper solution is implemented.
2025-09-25 15:53:18 -07:00
Kavon Farvardin
58a4a21c27 ManualOwnership: copy_addr [take] doesn't copy 2025-09-25 15:05:58 -07:00
Kavon Farvardin
0734267053 ManualOwnership: fix simple var assign
Was mistakenly counting a 'store' as
a copying instruction, when it's only a
consuming one.

SILGen was not handling lvalues that are
addresses for loadable types correctly,
when emitting a CopyExpr in ManualOwnership.
2025-09-24 17:00:24 -07:00
Kavon Farvardin
75bc2b5af2 ManualOwnership: more test coverage 2025-09-24 15:56:46 -07:00
Kavon Farvardin
03da43dc98 ManualOwnership: check closures 2025-09-24 14:41:29 -07:00
Kavon Farvardin
da49663079 ManualOwnership: avoid implicit SILMoveOnlyWrappedType's
These wrappers are detected by the move checking passes,
to support the implicit no-implicit-copy check for
parameters with ownership specifiers.

ManualOwnership already does this kind of checking, and the
two passes can interfere with each other, such as intercepting
diagnostics that are meant to be emitted by ManualOwnership.
2025-09-24 13:15:38 -07:00
Kavon Farvardin
da4f27e31b ManualOwnership: adjust CopyExpr emission
We were getting an address-based emission for loadable types,
if the result of a LoadExpr was explicit-copied. This emission
had extra hidden copies that could not be silenced.
2025-09-24 12:11:15 -07:00
Kavon Farvardin
c20ed75d19 ManualOwnership: imply MandatoryCopyPropagation
The usability of the feature depends on running
MandatoryCopyProp, which is in development.
2025-09-23 16:35:08 -07:00
Kavon Farvardin
80a61dd9dd ManualOwnership: variable names in diagnostics
Also tailor the messages it a bit based on uses, such
as closure captures.
2025-09-23 16:35:08 -07:00
Kavon Farvardin
bfce1170d4 ManualOwnership: diagnose copies of generics
copy_addr often is `Releasing`, which is `RefCounting | Deallocating`
2025-09-23 16:35:07 -07:00