Commit Graph

7229 Commits

Author SHA1 Message Date
Dario Rexin
3eca138203 [Test] Fix IRGen/abi_v7k.swift
rdar://155863017

The way enum tag bits are represented in the compiler has changed, which also caused the emitted code to slightly change.
2025-07-17 13:02:06 -07:00
Doug Gregor
3a54cf5b82 Merge pull request #83012 from DougGregor/no-mangled-name-span-metadata 2025-07-12 07:51:27 -07:00
Doug Gregor
badba55bf1 [IRGen] Mangling of nonisolated(nonsending) function types was introduced in Swift 6.2
We can't use mangled named when back-deploying earlier.
2025-07-11 14:24:54 -07:00
Doug Gregor
a73650c5ac Generalize test for 32-bit platforms 2025-07-11 14:24:53 -07:00
Doug Gregor
f3eca93e7f [IRGen] Don't use mangled names for metadata including Span et al when back-deploying
If back-deploying prior to the introduction of name mangling and
runtime support for invertible constraints (~Copyable, ~Escapable),
don't use mangled names to access metadata. The code already existed
for this, but had a carve-out that still used mangled names for
standard library types that have always existed but got generalized to
support non-copyable & non-escapable types.

Tweak that carve-out to not apply to types like Span that come from a
back-deployment library. Fixes crashes when using metadata for Span et
al on older platforms.

Fixes rdar://155639204.
2025-07-11 14:24:53 -07:00
Allan Shortlidge
e2fd14d143 Tests: Compensate for ptrauth in IRGen availability domain tests.
Resolves rdar://155596071.
2025-07-11 08:36:28 -07:00
Allan Shortlidge
5ffb301f8d Tests: Don't check for zeroext in IRGen availability domain tests.
Resolves rdar://155588692.
2025-07-11 08:35:09 -07:00
Allan Shortlidge
3d722e1919 ClangImporter: Generate and call custom availability domain predicates.
When importing custom availability domains with dynamic predicates from Clang
modules, synthesize predicate functions for `if #available` queries and call
them when generating SIL.

Resolves rdar://138441312.
2025-07-10 08:15:01 -07:00
Allan Shortlidge
e94713191c Tests: Clean up IRGen tests for custom availability.
Nest the `if #available` queries in functions so that it's easier to check the
resulting IR unambiguously.
2025-07-09 18:11:15 -07:00
Alexis Laferrière
cb3d82094a Merge pull request #82706 from xymus/cdecl-implementation-tests
Sema: Add `@cdecl @implementation` tests
2025-07-09 09:44:09 -07:00
Meghana Gupta
656210107f [Test] Update LLVM IR in lit test
rdar://155061133
2025-07-08 06:50:04 -07:00
eeckstein
010291fe65 Merge pull request #82728 from eeckstein/fix-allocbox-to-stack
MandatoryAllocBoxToStack: also handle new specialized functions and re-enable the pass again
2025-07-03 06:31:26 +02:00
Allan Shortlidge
ede7bdb5d7 Merge pull request #82671 from tshortli/zippered-miscompile-if-unavailable
SILGen: Fix `if #unavailable` mis-compile for zippered libraries
2025-07-02 16:05:51 -07:00
Alexis Laferrière
19360db247 IRGen: Add tests for @cdecl @implementation 2025-07-02 15:43:23 -07:00
Allan Shortlidge
4a76c04cf5 SILGen: Fix if #unavailable mis-compile for zippered libraries.
Inverted availability queries were mis-compiled for zippered libraries because
the code that emits calls to `isOSVersionAtLeastOrVariantVersionAtLeast()` was
not updated when the `if #unavailable` syntax was introduced (at that time
support for zippered libraries had not yet been upstreamed). The result of
these calls is now inverted when appropriate.

To make it easier to manage the growing complexity of supporting availability
queries, Sema now models the relevant information about an availability query
with the new `AvailabilityQuery` type. It encapsulates the domain for the
query, the result if it is known at compile time, and the version tuple
arguments to pass to a runtime invocation if applicable.

Resolves rdar://147929876.
2025-07-02 11:23:42 -07:00
Erik Eckstein
35edadca6c Revert "Optimizer: revert to legacy alloc-box-to-stack optimization"
This reverts commit 18499e2bbd.
2025-07-02 19:15:26 +02:00
Dario Rexin
6d08c664ca Merge pull request #82687 from drexin/wip-154525360
[Test] Fix IRGen/ptrauth-protocols.sil
2025-07-02 08:44:07 -07:00
Joe Groff
1c75d3b740 Merge pull request #82323 from jckarter/addressable-for-dependencies-vw-flag
Add an "addressable for dependencies" flag to value witness flags.
2025-07-01 13:02:17 -07:00
Dario Rexin
f52873ac15 [Test] Fix IRGen/ptrauth-protocols.sil
rdar://154525360

Code gen has changed to emit additional stores that will get eliminated in optimized builds.
2025-07-01 09:06:42 -07:00
eeckstein
83d7dbb3f5 Merge pull request #82668 from eeckstein/revert-abts
Optimizer: revert to legacy alloc-box-to-stack optimization
2025-07-01 17:49:42 +02:00
Erik Eckstein
18499e2bbd Optimizer: revert to legacy alloc-box-to-stack optimization
The new implementation causes some problems
rdar://154686063, rdar://154713388
2025-07-01 07:02:36 +02:00
Augusto Noronha
0c20222aea Merge pull request #81700 from augusto2112/revert-debug-info-witness-table
Revert "Merge pull request #79171 from augusto2112/debug-info-witness…
2025-06-30 15:28:15 -07:00
finagolfin
55cee0144d [test] Fix or disable tests for 32-bit platforms (#82501)
Fix two IRGen tests that are failing on Android armv7 and disable eight ClangImporter, C++ Interop, and SILOptimizer tests, two of which that were already failing on other 32-bit platforms.
2025-06-30 10:39:26 +05:30
Anthony Latsis
39e011e083 Merge pull request #82572 from swiftlang/jepa5
[test] Fix duplicate LABEL directive in recently reenabled test
2025-06-28 00:45:34 +01:00
Anthony Latsis
d04f91ea58 [test] Fix duplicate LABEL directive in recently reenabled test
This test was partially reenabled by fixing misspelled FileCheck
directives in https://github.com/swiftlang/swift/pull/81426.
I had failed to notice that some arm64e checks are duplicated.
2025-06-27 19:55:53 +01:00
nate-chandler
76fd74753b Merge pull request #82510 from nate-chandler/rdar80334865
[IRGen] Sign these function pointers.
2025-06-26 12:02:07 -07:00
Nate Chandler
c108d480ab [IRGen] Sign these function pointers.
Value witness tables for prespecialized metadata for multi payload enums
contain references to `swift_getMultiPayloadEnumTagSinglePayload` and
`swift_storeMultiPayloadEnumTagSinglePayload`.  On platforms with
ptrauth, those functions must be signed.  Use the same helper when
adding these functions to the table as is used to add every single other
function to the table.

rdar://80334865
2025-06-25 16:24:40 -07:00
Dave Lee
ce7a3b39a4 IRGen: Emit objc type encoding for ivars (#81967)
ObjC ivar metadata has up to now emitted an empty string for the ivar's objc type encoding. Conversely, ObjC property metadata is emitted with an objc type encoding. This changes the compiler to also emit an objc type encoding for ivars.

The motivation for this change is for lldb to print ivars of classes declared in Objective-C but implemented in Swift, as defined in [SE-0436](https://github.com/swiftlang/swift-evolution/blob/main/proposals/0436-objc-implementation.md). Without the presence of type encoding for ivars, lldb is unable to present to the user the ivars/properties of instances of such classes.

rdar://138569299
2025-06-25 15:39:23 -07:00
Dario Rexin
e802a4c104 [Test] Disable IRGen/generic_tuples.swift on arm64e
rdar://153961233

This test will fail on arm64e targets, because ptrauth is not handled.
2025-06-23 11:47:41 -07:00
Erik Eckstein
6714a72256 Optimizer: re-implement and improve the AllocBoxToStack pass
This pass replaces `alloc_box` with `alloc_stack` if the box is not escaping.
The original implementation had some limitations. It could not handle cases of local functions which are called multiple times or even recursively, e.g.

```
public func foo() -> Int {
  var i = 1

  func localFunction() { i += 1 }

  localFunction()
  localFunction()
  return i
}

```

The new implementation (done in Swift) fixes this problem with a new algorithm.
It's not only more powerful, but also simpler: the new pass has less than half lines of code than the old pass.

The pass is invoked in the mandatory pipeline and later in the optimizer pipeline.
The new implementation provides a module-pass for the mandatory pipeline (whereas the "regular" pass is a function pass).
This is required because the mandatory pass needs to remove originals of specialized closures, which cannot be done from a function-pass.
In the old implementation this was done with a hack by adding a semantic attribute and deleting the function later in the pipeline.

I still kept the sources of the old pass for being able to bootstrap the compiler without a host compiler.

rdar://142756547
2025-06-20 08:15:04 +02:00
Dario Rexin
545cf1ee0a Merge pull request #82240 from drexin/wip-149882902
[IRGen] Emit null check before swift_conformsToProtocol for nullable …
2025-06-18 15:56:39 -07:00
Joe Groff
7e99e84070 Add an "addressable for dependencies" flag to value witness flags.
This may be useful for type layout of borrow fields in the future, should we
decide that addressable-for-dependencies borrows should always be represented
by a pointer. rdar://153650278
2025-06-18 12:47:16 -07:00
Dario Rexin
2a3999049f [IRGen] Emit null check before swift_conformsToProtocol for nullable metatypes
rdar://149882902

swift_conformsToProtocol does not properly handle nullptr values, which can currently be passed if the source type is an optional metatype. This change adds emission of a null check before calling the runtime function in these cases.
2025-06-13 17:00:11 -07:00
Stephen Canon
9259c3eec4 Add new interleave and deinterleave builtins (#81689)
Ideally we'd be able to use the llvm interleave2 and deinterleave2
intrinsics instead of adding these, but deinterleave currently isn't
available from Swift, and even if you hack that in, the codegen from
LLVM is worse than what shufflevector produces for both x86 and arm. So
in the medium-term we'll use these builtins, and hope to remove them in
favor of [de]interleave2 at some future point.
2025-06-12 12:01:53 -04:00
Allan Shortlidge
3f305a48c8 AST: Re-map macOS 16 aligned availability versions to 26.
- watchOS 12 -> 26
- visionOS 3 -> 26
- macos 16 -> 26
- iOS 19 -> 26
- tvOS 19 -> 26

The version numbers for `if #available(...)` queries are intentionally not
re-mapped.
2025-06-10 22:11:05 -07:00
Meghana Gupta
7d454533a0 Merge pull request #82067 from meg-gupta/lifetimeunderscored
Update spelling for representing lifetime dependencies to @_lifetime
2025-06-09 19:01:31 -07:00
Meghana Gupta
44e05fa858 [NFC] Update tests and diagnostics 2025-06-07 12:49:01 -07:00
Erik Eckstein
d6cbaf6ebd MandatoryPerformanceOptimizations: only set the [perf_constraint] flag for callees of performance constraint functions
It used to also set it for functions which are referenced from a global with a const/section attribute - even if not performance attribute was present in the whole module. This is unnecessary and can lead to worse code generation.

rdar://152665294
2025-06-06 20:08:16 +02:00
Saleem Abdulrasool
51645d00a3 Merge pull request #81754 from compnerd/closed
IRGen: honour `-static-libclosure` in block creation
2025-06-03 08:35:07 -07:00
Anthony Latsis
d0b00504d8 Merge pull request #81426 from AnthonyLatsis/quercus-ilex
[test] Fix misspelled FileCheck directives
2025-05-30 17:54:28 +01:00
Ryan Mansfield
257e833c27 Re-add UNSUPPORTED for watchos arm64_32 in lto_autolink.swift.
Tests are failing with:

<unknown>:0: error: unknown target triple 'arm64_32-unknown-linux-gnu'
<unknown>:0: error: clang importer creation failed
2025-05-29 14:22:44 -04:00
Anthony Latsis
43e79a3d3b [test] Match nocapture to succeed both on main and rebranch in reenabled tests
Both the syntax and relative order of the LLVM `nocapture` parameter
attribute changed upstream in
https://github.com/llvm/llvm-project/pull/123181.
To reduce conflicts with rebranch, adjust FileCheck patterns to expect
both syntaxes and orders anywhere the presence of the attribute is not
critical to the test. These changes are temporary and will be cleaned
up once rebranch is merged into main.
2025-05-29 15:10:09 +01:00
Anthony Latsis
0a1b8b0d50 [test] Fix misspelled FileCheck directives 2025-05-29 15:09:36 +01:00
Allan Shortlidge
7387f85ba2 Merge pull request #81767 from tshortli/fix-zippered-custom-availability-queries
SILGen: Fix `if #available` for unavailable custom domains in zippered modules
2025-05-26 22:26:49 -07:00
Allan Shortlidge
4aa516aebb SILGen: Fix if #available for unavailable custom domains in zippered modules.
When generating SIL for an `if #available(SomeDomain)` query in code being
compiled for a zippered target, the generated code was mis-compiled if
`SomeDomain` were disabled at compile time. Empty version ranges need to be
handled explicitly by `SILGenFunction::emitZipperedOSVersionRangeCheck()`.

SILGen still miscompiles `if #unavailable` queries generally in code compiled
for a zippered target (rdar://147929876).

Resolves rdar://150888941.
2025-05-25 08:27:12 -07:00
Saleem Abdulrasool
c0993d466d IRGen: honour -static-libclosure in block creation
When creating a block, ensure that we correctly associate the DLL
Storage on the `_NSConcreteStackBlock` root object declaration based
upon whether we are generating code with `-static-libclosure` being
passed to the clang importer or not.
2025-05-24 08:23:42 -07:00
Erik Eckstein
198d4ab0bb Optimizer: run TempRValueElimination also at Onone
Introduce a new pass MandatoryTempRValueElimination, which works as the original TempRValueElimination, except that it does not remove any alloc_stack instruction which are associated with source variables.

Running this pass at Onone helps to reduce copies of large structs, e.g. InlineArrays or structs containing InlineArrays.
Copying large structs can be a performance problem, even at Onone.

rdar://151629149
2025-05-23 18:56:56 +02:00
finagolfin
8e40f0b380 Merge pull request #81695 from finagolfin/lto
[test] Fix IRGen/lto_autolink on Darwin arm64 platforms too
2025-05-22 10:01:24 +05:30
Augusto Noronha
680fbc566f Revert "Merge pull request #79171 from augusto2112/debug-info-witness-table"
This reverts commit c8eba86c3e, reversing
changes made to 98c3993503.
2025-05-22 11:45:37 +09:00
Slava Pestov
490edfa523 Merge pull request #81564 from slavapestov/fix-issue-78191
IRGen: Fix miscompile when a generic parameter is fixed to a tuple containing a pack
2025-05-21 00:06:59 -04:00