Commit Graph

12803 Commits

Author SHA1 Message Date
Shubham Sandeep Rastogi
f91f8c5283 Merge pull request #81563 from rastogishubham/CompDir
Set the Compilation directory when generating the Skeleton CU
2025-05-23 14:39:16 -07:00
susmonteiro
7686f05f28 [cxx-interop] Ensure consistent checks for exportable fields 2025-05-23 15:21:34 +01:00
Shubham Sandeep Rastogi
b286b1c3a5 Set the Compilation directory when generating the Skeleton CU
When creating a skeleton Compile Unit, the DIFile passed
in, it always uses the include path. This leads to the DW_AT_comp_dir
being wrong, if the -file-compilation-dir option is passed, we need to
use the remapped compilation dir passed in to the DIFile instead.

This patch fixes that problem.
2025-05-22 08:37:10 -07:00
Susana Monteiro
e805d93d95 Merge pull request #81035 from swiftlang/susmonteiro/metadata-private-fields
[cxx-interop] Fix metadata mismatch regarding fields of structs
2025-05-21 19:25:08 +01:00
eeckstein
0ceb5171ff Merge pull request #81649 from eeckstein/global-inlinearray-initialization
Allow more complex InlineArray initializations to end up in a statically initialized global
2025-05-21 06:24:28 +02: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
Augusto Noronha
c8eba86c3e Merge pull request #79171 from augusto2112/debug-info-witness-table
[DebugInfo] Emit debug info for witness tables
2025-05-21 09:23:04 +09:00
Erik Eckstein
9052652651 add the prepareInitialization builtin.
It is like `zeroInitializer`, but does not actually initialize the memory.
It only indicates to mandatory passes that the memory is going to be initialized.
2025-05-20 20:46:33 +02:00
Stephen Canon
3aa7b592b6 Implement Builtin.select binding llvm select instruction (#81598)
Not used (yet), but needed to implement SIMD.replacing(with:where:) idiomatically, and probably useful otherwise.
2025-05-20 13:30:59 -04:00
susmonteiro
72b13b3b48 [cxx-interop] Fix metadata mismatch regarding fields of structs 2025-05-20 10:15:14 +01:00
Hamish Knight
3ec3421987 Merge pull request #81604 from hamishknight/pretty-crash
Adopt `ABORT` throughout the compiler
2025-05-20 10:05:03 +01:00
Hamish Knight
edca7c85ad Adopt ABORT throughout the compiler
Convert a bunch of places where we're dumping to stderr and calling
`abort` over to using `ABORT` such that the message gets printed to
the pretty stack trace. This ensures it gets picked up by
CrashReporter.
2025-05-19 20:55:01 +01:00
Erik Eckstein
a768037d0b IRGen: fix failing unconditional class casts
When unconditionally casting from a base to a final derived class, e.g. `base as! Derived`, the program did not abort with a trap.
Instead the resulting null-pointer caused a crash later in the program.
This fix inserts a trap condition for the failing case of such a cast.

rdar://151462303
2025-05-19 16:56:47 +02:00
Erik Eckstein
371e4ebd88 IRGen: extract generating a cond_fail into a utility function emitConditionalTrap
NFC
2025-05-19 16:56:47 +02:00
Erik Eckstein
078e479231 IRGen: move FailBBs from IRGenSILFunction to its base class IRGenFunction
NFC
2025-05-19 16:56:46 +02:00
Slava Pestov
f17baefd7a IRGen: Fix miscompile when a generic parameter is fixed to a tuple containing a pack
If you had something like:

    struct G<T> {
      func f<each U>(_: repeat each U) where T == (repeat each U) {}
    }

We would fulfill 'each U' from the metadata for 'G<(repeat each U)>',
by taking apart the tuple metadata for `(repeat each U)` and forming
a pack.

However this code path was only intended to kick in for a tuple
conformance witness thunk. In the general case, this optimization
is not correct, because if 'each U' is substituted with a
one-element pack, the generic argument of `G<(repeat each U)>` is
just that one element's metadata, and not a tuple. In fact, we
cannot distinguish the one-element tuple case, because the wrapped
element may itself be a tuple.

The fix is to just split off FulfillmentMap::searchTupleTypeMetadata()
from searchTypeMetadata(), and only call the former when we're in
the specific situation that requires it.

- Fixes https://github.com/swiftlang/swift/issues/78191.
- Fixes rdar://problem/135325886.
2025-05-16 17:34:11 -04:00
Dario Rexin
ee9c0cc14c Merge pull request #81530 from drexin/wip-151176697
[IRGen] Don't set HasLayoutString flag on non-copyable generic types
2025-05-15 15:27:26 -07:00
Dario Rexin
a904fee7fe [IRGen] Don't set HasLayoutString flag on non-copyable generic types
rdar://151176697

While generic types generally have layout strings (when enabled), non-copyable types don't, so
we have to make sure the flag does not get set.
2025-05-15 10:21:22 -07:00
Slava Pestov
b2e2b02a71 IRGen: Fix out-of-order task_dealloc with parameter pack metadata
We deallocate an instruction's packs at points where no further
control flow path uses the value. In the case of an alloc_stack,
this will be right after the dealloc_stack. Thus, if alloc_stack
allocates some packs to build type metadata for a tuple type
that contains a pack, and then proceeds to allocate a value
large enough to hold the tuple, we will free the second allocation
first, before we free the pack, as expected.

However, after stack allocating the value, alloc_stack does
some further work to emit debug info. This could result in
emission of additional metadata packs.

Split up the debug info emission into two parts; the first we do
before we perform the stack allocation, the rest we do after.

- Fixes https://github.com/swiftlang/swift/issues/67702.
- Fixes rdar://problem/141363236.
2025-05-15 12:22:21 -04:00
Shubham Sandeep Rastogi
80e8d3a127 Merge pull request #81463 from rastogishubham/AttachDebugLoc
Set debug location to Coroutine call expression
2025-05-13 17:30:55 -07:00
Shubham Sandeep Rastogi
17e756ba81 Set debug location to Coroutine call expression
If debug info generation is enabled, set debug location to the
coroutine call instruction to make sure there are no issues with invalid
debug information in LTO.

This happens because in LTO, if a call to a function doesn't contain a
debug location, we see the warning:

inlinable function call in a function with debug info must have a
!dbg location

ld: warning: Invalid debug info found, debug info will be stripped

Which then strips the debug info from the entire .o file linked into the
dylib.
2025-05-13 11:11:38 -07:00
eeckstein
66e07f04ac Merge pull request #81441 from eeckstein/vector_base_addr
SIL: introduce the `vector_base_addr` instruction and use it in `InlineArray`
2025-05-13 06:52:42 +02:00
Alejandro Alonso
9e24563bb7 Merge pull request #81365 from Azoy/my-existentials
[AST & Runtime] Correctly mangle extended existentials with inverse requirements
2025-05-12 13:21:07 -07:00
Erik Eckstein
a38db6439a SIL: add the vector_base_addr instruction
It derives the address of the first element of a vector, i.e. a `Builtin.FixedArray`, from the address of the vector itself.
Addresses of other vector elements can then be derived with `index_addr`.
2025-05-12 19:24:31 +02:00
Konrad `ktoso` Malawski
60694624e7 Merge pull request #81372 from ktoso/wip-sign-protocol-ptr
[Distributed] pointer auth protocol pointers as we use conformsToProtocol
2025-05-09 11:10:22 +09:00
Konrad `ktoso` Malawski
e4c0c79d65 Apply suggestions from code review 2025-05-09 06:24:14 +09:00
Dario Rexin
058638ee90 Merge pull request #81339 from drexin/wip-150722907
[IRGen] Emit llvm fneg operation for Builtin.fneg_*
2025-05-08 13:48:43 -07:00
Konrad 'ktoso' Malawski
d7152c789d [Distributed] pointer auth protocol pointers as we use conformsToProtocol 2025-05-08 13:05:53 +09:00
Dario Rexin
877a98f8ef [IRGen] Emit llvm fneg operation for Builtin.fneg_*
rdar://150722907

The original handling was a workaround before LLVM added the fneg operation. Now that it has it, we should use it.
2025-05-06 10:27:30 -07:00
Ludwig Hollmann
39aa950660 Update file header comments for headers in lib. 2025-05-04 22:26:26 +02:00
Dario Rexin
7634b82109 Merge pull request #81151 from drexin/wip-149985633
[IRGen] Use at least Int8 for extra tag bits
2025-05-01 16:03:51 -07:00
Meghana Gupta
3cad5c5924 Merge pull request #81043 from meg-gupta/fixcow
Insert end_cow_mutation_addr for lifetime dependent values dependent on mutable addresses
2025-05-01 07:26:28 -07:00
Dario Rexin
48ee212303 [IRGen] Use at least Int8 for extra tag bits
rdar://149985633

Using at least Int8 here allows LLVM to apply more optimizations, reducing code size, avoiding stack allocations and as a result often eliminating complete stack frames.
2025-04-30 15:55:17 -07:00
Zixu Wang
cd545300bf [APIGen] Don't record declarations from clang header files (#81086)
When Swift visits an `ExtensionDecl` from an `@objc @implementation`
extension, it fetches the implemented Objective-C interface declaration
from the header file and adds to the visitor.
We don't want these API records from `APIGenRecorder` for Swift API
descriptor, because we cannot correctly reason about their API access as
they depend on the header group which Swift doesn't know about.

Resolves rdar://148943382

<!--
If this pull request is targeting a release branch, please fill out the
following form:

https://github.com/swiftlang/.github/blob/main/PULL_REQUEST_TEMPLATE/release.md?plain=1

Otherwise, replace this comment with a description of your changes and
rationale. Provide links to external references/discussions if
appropriate.
If this pull request resolves any GitHub issues, link them like so:

  Resolves <link to issue>, resolves <link to another issue>.

For more information about linking a pull request to an issue, see:

https://docs.github.com/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
-->

<!--
Before merging this pull request, you must run the Swift continuous
integration tests.
For information about triggering CI builds via @swift-ci, see:

https://github.com/apple/swift/blob/main/docs/ContinuousIntegration.md#swift-ci

Thank you for your contribution to Swift!
-->
2025-04-30 15:37:06 -07:00
Alejandro Alonso
c165509147 Correctly emit inverse proto comps with extended shape symbolic refs 2025-04-30 13:43:01 -07:00
Meghana Gupta
35d62a4a36 Introduce end_cow_mutation_addr instruction 2025-04-30 13:39:45 -07:00
Augusto Noronha
66748f71eb [DebugInfo] Emit debug info for witness tables
This change emits debug info for witness tables passed into generic
functions when a generic type is constrained to a protocol. This
information is required for LLDB's generic expression evaluator
to work in such functions.

rdar://104446865
2025-04-30 11:18:19 -07:00
Slava Pestov
6b4710ed22 Merge pull request #81142 from slavapestov/more-type-subst-cleanup
Clean up duplicated opened existential archetype handling in SIL and more
2025-04-30 02:42:57 -04:00
Konrad 'ktoso' Malawski
e1dc854f8f [Concurrency] Change isIsolatingCurrent... to return Bool?
This changes the isIsolatingCurrentContext function to return `Bool?`
and removes all the witness table trickery we did previously to detect
if it was implemented or not. This comes at a cost of trying to invoke
it always, before `checkIsolated`, but it makes for an simpler
implementation and more checkable even by third party Swift code which
may want to ask this question.

Along with the `withSerialExecutor` function, this now enables us to
check the isolation at runtime when we have an `any Actor` e.g. from
`#isolation`.

Updates SE-0471 according to
https://forums.swift.org/t/se-0471-improved-custom-serialexecutor-isolation-checking-for-concurrency-runtime/78834/
review discussions
2025-04-29 20:08:55 +09:00
Slava Pestov
cf1572c65b AST: Add ASTContext::TheSelfType for convenience 2025-04-28 11:49:50 -04:00
Gabor Horvath
939ee49dcb [cxx-interop] Fix a crash with [[no_unique_address]]
Swift does not support storing fields in the padding of the previous
fields just yet, so let's not import fields like that from C++.
Represent them as opaque blobs instead.

Fixes #80764

rdar://149072458
2025-04-25 12:46:31 +01:00
Arnold Schwaighofer
7d72959028 Merge pull request #81037 from aschwaighofer/irgen_coroFrameAlloc_cleanup
IRGen: Centralize logic that decides whether the platform suppports typed malloc
2025-04-24 13:21:16 -07:00
Dario Rexin
4b7edce861 Merge pull request #80746 from drexin/wip-149007227
[IRGen] Set generic context before getting call emission in visitFull…
2025-04-23 15:37:17 -07:00
Arnold Schwaighofer
3f8c743aed IRGen: Centralize logic that decides whether the platform suppports typed malloc
NFC intended
2025-04-23 10:43:06 -07:00
Arnold Schwaighofer
521fb07523 LoadableByAddress: Fix shouldTransformYields to use substituted types
rdar://149281263
issues/80818
2025-04-21 13:46:41 -07:00
Konrad `ktoso` Malawski
d7887132a5 Merge pull request #80588 from ktoso/wip-regression-test-for-b-da-bad-access
[Distributed] Reproducer for generics and library evolution mode
2025-04-21 20:03:27 +09:00
eeckstein
ad82261cbd Merge pull request #80884 from eeckstein/embedded-error-message2
embedded: support default methods in existentials and improve embedded error reporting
2025-04-18 22:12:18 +02:00
Erik Eckstein
8e874cd2b2 SIL: add better support for specialized witness tables.
Store specialize witness tables in a separate lookup table in the module. This allows that for a normal conformance there can exist the original _and_ a specialized witness table.
Also, add a boolean property `isSpecialized` to `WitnessTable` which indicates whether the witness table is specialized or not.
2025-04-18 06:58:34 +02:00
Konrad 'ktoso' Malawski
957a95be63 [Distributed] Distributed actor usage through protocol with lib-evo must work
This corrects how we were dealing with dispatch thunks -- mostly be
removing a lot of special casing we did but doesn't seem necessary and
instead we correct and emit all the necessary information int TBD.

This builds on  https://github.com/swiftlang/swift/pull/74935 by further refining how we fixed that issue, and adds more regression tests. It also removes a load of special casing of distributed thunks in library evolution mode, which is great.

Resolves and adds regression test for for rdar://145292018

This is also a more proper fix to the previously resolved but in a not-great-way which caused other issues:
- resolves rdar://128284016
- resolves rdar://128310903
2025-04-18 11:21:01 +09:00
Arnold Schwaighofer
370b7e8219 LargeTypesReg2Mem: Add unchecked_bitwise_cast to the projections we need to propagate largeness from destination to source operand
rdar://148545382
2025-04-17 09:18:31 -07:00