Commit Graph

12816 Commits

Author SHA1 Message Date
swift-ci
f95ec5efc7 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-09 03:54:21 -07:00
Stephen Canon
396b055369 Implement Builtin.freeze for integer and integer-vector types. (#73519)
* Implement Builtin.freeze for integer and integer-vector types.

https://llvm.org/docs/LangRef.html#freeze-instruction

> If the argument is undef or poison, ‘freeze’ returns an arbitrary, but fixed, value of type ‘ty’. Otherwise, this instruction is a no-op and returns the input argument. All uses of a value returned by the same ‘freeze’ instruction are guaranteed to always observe the same value, while different ‘freeze’ instructions may yield different values.

It's most importation for integer and integer-vector types because floating-point results are generally not poison (except in the case of conversion from poison integer values).
However, we might want to implement this for other types as well in the future.

* Make builtin.freeze TrivialUse

Also fix filecheck patterns for its test to work with asserts build.
2024-05-09 06:41:02 -04:00
swift-ci
6cdf9d9813 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-08 11:54:29 -07:00
Egor Zhdan
1078fd3bd5 Merge pull request #73366 from apple/egorzhdan/frt-release-nullptr
[cxx-interop][IRGen] Do not try to retain/release a null pointer
2024-05-08 19:39:16 +01:00
swift-ci
626e3da99f Merge remote-tracking branch 'origin/main' into rebranch 2024-05-08 08:34:19 -07:00
Doug Gregor
280f566568 Revert "IRGen: memcpy instead of the outlined copy with take" 2024-05-07 23:42:47 -07:00
swift-ci
71a3dbe8c4 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-07 14:34:36 -07:00
Slava Pestov
ca91d04968 Merge pull request #73457 from slavapestov/bitwise-copyable-lookup-conformance-irgen
IRGen: Fix incorrect BitwiseCopyable conformance lookups
2024-05-07 17:22:40 -04:00
swift-ci
dc84b9c054 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-07 14:14:00 -07:00
Egor Zhdan
bd6da5dc64 [cxx-interop][IRGen] Do not try to retain/release a null pointer
This teaches IRGen to only emit a lifetime operation (retain or release) for a C++ foreign reference type if the pointer is not `nullptr`.

Previously the compiler would in some cases emit a release call for `nullptr`, which breaks the assumption that the argument to a custom release function is `_Nonnull`. For instance:
```
var globalOptional: MyRefType? = nil
func foo() { globalOptional = MyRefType.create() }
```
When emitting IR for the assignment operation to `globalOptional`, the compiler would emit code to first retrieve the existing value of `globalOptional` and release it. If the value is `nil`, it does not need to be released.

rdar://97532642
2024-05-07 20:20:45 +01:00
Slava Pestov
d5985158cb IRGen: Fix some more incorrect conformance checks 2024-05-07 10:37:49 -04:00
Slava Pestov
5d7e502299 IRGen: Fix incorrect conformance check
Fixes rdar://126637139, rdar://126779977.
2024-05-07 10:37:49 -04:00
Dario Rexin
03a71835b5 [IRGen] Add missing blocklist check for some CVW cases
rdar://127511568

The check was missing from getEnumTag and destructiveInjectEnumTag, which could cause the CVW functions to be used when the feature was blocked via blocklist.
2024-05-06 14:41:33 -07:00
Arnold Schwaighofer
62dc98295c IRGen: memcpy instead of the outlined copy with take
The outlined copy with take would instantiate metadata to call the value
witness table's copy function.

rdar://126751753
2024-05-06 12:17:17 -07:00
swift-ci
caf307833c Merge remote-tracking branch 'origin/main' into rebranch 2024-05-04 01:34:28 -07:00
Alastair Houghton
6afdcd311f Merge pull request #72061 from al45tair/eng/PR-123504095
[Linux][Runtime][IRGen] Mark metadata sections as retained and support section GC.
2024-05-04 09:23:06 +01:00
swift-ci
e1bf084cc6 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-03 22:34:10 -07:00
nate-chandler
768b3a4944 Merge pull request #73422 from nate-chandler/rdar127502242
[SIL] Hollow out Builtin.copy and deprecate _copy.
2024-05-03 22:19:47 -07:00
Nate Chandler
06921cfe84 [SIL] Hollow out Builtin.copy, deprecate _copy.
The copy operator has been implemented and doesn't use it.  Remove
`Builtin.copy` and `_copy` as much as currently possible.

Source compatibility requires that `_copy` remain in the stdlib.  It is
deprecated here and just uses the copy operator.

Handling old swiftinterfaces requires that `Builtin.copy` be defined.
Redefine it here as a passthrough--SILGen machinery will produce the
necessary copy_addr.

rdar://127502242
2024-05-03 15:56:25 -07:00
swift-ci
cdc5aae3ab Merge remote-tracking branch 'origin/main' into rebranch 2024-05-03 13:15:56 -07:00
Augusto Noronha
ef5aae1fea Merge pull request #72445 from augusto2112/zero-unsub-types-main
[DebugInfo] Always emit unsubsituted generic types with size 0
2024-05-03 13:13:59 -07:00
swift-ci
d9561451b4 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-02 22:54:11 -07:00
Dario Rexin
c1d732a9cb [IRGen] Fix alignment for imported C types in CVW
rdar://127279770

When an imported C type is over or under aligned, we did not use the alignment of the type, but computed the maximum alignment of its components, causing alignment issues in compact value witnesses.
2024-05-02 17:05:38 -07:00
swift-ci
e2ba5ea903 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-02 12:54:35 -07:00
Emil Pedersen
bf58b030c5 Merge pull request #73387 from Snowy1803/allocbox-fix
[DebugInfo] Fix loss of variables at -Onone
2024-05-02 12:39:17 -07:00
Emil Pedersen
c02f663f93 [DebugInfo] Fix AllocStackHoisting losing debug info
AllocStackHoisting was losing debug info, including at -Onone.
When two alloc_stacks of the same type are merged, one of them
would lose their debug variable. It is now salvaged, with an added
debug_value.

This case was previously only handled for noncopyable types, it is
now done in all cases.
2024-05-01 18:44:57 -07:00
Emil Pedersen
644509ea1c [DebugInfo] Fix LoadableByAddress losing debug info
LoadableByAddress was losing debug info, including at -Onone.
When converting a load-store pair to a copy_addr, the debug info
attached to the load was not salvaged.
Additionally, the wrong scope was being attached to other debug
values.
2024-05-01 18:44:33 -07:00
Becca Royal-Gordon
c3225b066e [NFC] Merge two category name accessors 2024-05-01 12:18:19 -07:00
swift-ci
7af405827e Merge remote-tracking branch 'origin/main' into rebranch 2024-05-01 08:16:56 -07:00
Alejandro Alonso
d380bf9ae3 Merge pull request #73277 from Azoy/fix-conditional-invertible
[IRGen] Fix misalignment of conditional invertible requirement counts
2024-05-01 08:10:46 -07:00
swift-ci
0d3ed3d63c Merge remote-tracking branch 'origin/main' into rebranch 2024-05-01 06:53:59 -07:00
Cyndy Ishida
84d36181a7 [TBDGen] Track unavailable declarations against the active platform for (#73284)
api generation

This resolves the bug where apijson files recorded declarations as
unavailable purely because it was unavailable on a unrelated platforms.

Resolves: rdar://113552185
2024-05-01 06:50:30 -07:00
swift-ci
480a3378d9 Merge remote-tracking branch 'origin/main' into rebranch 2024-04-30 20:54:40 -07:00
Becca Royal-Gordon
981233ad37 Merge pull request #73128 from beccadax/objcimpl-resilient
Handle resilient stored properties in objcImpl
2024-04-30 20:50:33 -07:00
Becca Royal-Gordon
f94ed6d606 Hide objcImpl resilience support behind feature
Resilence support will require changes to the Objective-C runtime to expand support for metadata initialization functions. Add a separate experimental feature flag to help with staging that support in, and modify diagnostics to not suggest increasing the minimum deployment target for now.
2024-04-30 12:03:46 -07:00
Becca Royal-Gordon
1dceb24802 Diagnose resilient properties in objcImpl
…when the deployment target is not high enough to support them.
2024-04-30 12:03:46 -07:00
Becca Royal-Gordon
d1f14e5814 Eliminate objcImpl field offset vectors
We really don’t need ‘em; we can just adjust the direct field offsets.

The runtime entry point currently uses a weird little hack that we will refactor away shortly.
2024-04-30 12:03:46 -07:00
Becca Royal-Gordon
427386feea Support resilient stored properties in objcImpl
When an @objc @implementation class requires the use of `ClassMetadataStrategy::Update` because some of its stored properties do not have fixed sizes, we adjust the direct field offsets during class realization by emitting a custom metadata update function which calls a new entry point in the Swift runtime. That entry point adjusts field offsets like `swift_updateClassMetadata2()`, but it only assumes that the class has Objective-C metadata, not Swift metadata.

This commit introduces an alternative mechanism which does the same thing without using any Swift-only metadata. It’s a rough implementation with important limitations:

• We’re currently using the field offset vector, which means that field offsets are being emitted into @objc @implementation classes; these will be removed.
• The new Swift runtime entry point duplicates a lot of `swift_updateClassMetadata2()`’s implementation; it will be refactored into something much smaller and more compact.
• Availability bounds for this feature have not yet been implemented.

Future commits in this PR will correct these issues.
2024-04-30 12:03:44 -07:00
swift-ci
a51df69c93 Merge remote-tracking branch 'origin/main' into rebranch 2024-04-29 10:34:28 -07:00
Emil Pedersen
ce68d74025 Merge pull request #73276 from Snowy1803/doc-and-fixes
[DebugInfo] Improve documentation & Fix discovered bugs
2024-04-29 10:22:46 -07:00
Alastair Houghton
a363719434 [IRGen] Set TargetOpts.UseInitArray in getIRTargetOptions().
IRGen sets up the `llvm::TargetOptions` by itself, rather than copying
them from the Clang instance (it has to do this, at present, because
Clang doesn't provide a way to get it to initialise one).

Unfortunately, it didn't set `UseInitArray`, which when linking with
GNU `ld` or `gold` is *fine* because those linkers automatically
convert `.ctors` and `.dtors` sections into `.init_array` and
`.fini_array` respectively.  *However*, `lld` does *not* do this
conversion, so when using `lld`, if the compiler generates a
constructor or destructor function, it won't be called(!)

The fix is to set `UseInitArray` properly; I chose to copy the setting
from Clang, just in case Clang knows of a reason why it shouldn't be
`true`.

rdar://123504095
2024-04-29 10:48:22 +01:00
Alastair Houghton
0a5653dbaf [IRGen] When creating a module object, mark __Swift_AST as used.
Without doing this, `__Swift_AST` gets stripped from the output.
We also need to call `IGM.finalize()` before `::performLLVM()` in the
`createSwiftModuleObjectFile()` function, so that we update the
section to mark it as retained.

rdar://123504095
2024-04-29 10:48:22 +01:00
Alastair Houghton
3c029ebd3f [IRGen] Use llvm.used on ELF instead of llvm.compiler.used.
We changed to `llvm.compiler.used` because of the behaviour of `gold`,
which refuses to coalesce sections that have different `SHF_GNU_RETAIN`
flags, which causes problems with metadata.

Originally I thought we were going to have to generate two sections
with distinct names and have the runtime look for both of them, but
it turns out that the runtime only wants to see sections that have
`SHF_GNU_RETAIN` in any case.  It's really the reflection code that
is interested in being able to see non-retained sections.  The upshot
is that we don't need to use `llvm.compiler.used`; it's just fine if
we have duplicate sections, as long as the reflection code looks for
them when it's inspecting an ELF image.

This also means we no longer need to pass `-z nostart-stop-gc` to the
linker if we're using `lld`.

rdar://123504095
2024-04-29 10:48:22 +01:00
Emil Pedersen
84dae7c37a [DebugInfo] Add support for constant debug values 2024-04-26 16:31:16 -07:00
Emil Pedersen
8ad3066011 [DebugInfo] Fix implicit deref on arithmetic expressions 2024-04-26 16:31:16 -07:00
Emil Pedersen
c2c16f53dd [DebugInfo] Fix undef debug values being removed 2024-04-26 16:31:16 -07:00
swift-ci
3c8a651a0d Merge remote-tracking branch 'origin/main' into rebranch 2024-04-26 04:54:47 -07:00
Arnold Schwaighofer
1846159657 Merge pull request #73270 from aschwaighofer/large_types_reg2mem_yield_begin_apply
LargeTypesReg2Mem: Fix yield and begin_apply instructions
2024-04-26 04:35:38 -07:00
Arnold Schwaighofer
f544aac75b Merge pull request #73269 from aschwaighofer/irgen_fix_large_c_argument_peephole
IRGen: Fix the load to indirect argument peephole
2024-04-26 04:34:55 -07:00
swift-ci
cf41bf0df7 Merge remote-tracking branch 'origin/main' into rebranch 2024-04-25 20:14:13 -07:00