Commit Graph

13074 Commits

Author SHA1 Message Date
Hamish Knight
3ec3421987 Merge pull request #81604 from hamishknight/pretty-crash
Adopt `ABORT` throughout the compiler
2025-05-20 10:05:03 +01:00
swift-ci
ce8c62cbcf Merge remote-tracking branch 'origin/main' into rebranch 2025-05-19 15:37:21 -07: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
swift-ci
e3a98f8b0c Merge remote-tracking branch 'origin/main' into rebranch 2025-05-15 15:33:33 -07: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
swift-ci
ce84f96466 Merge remote-tracking branch 'origin/main' into rebranch 2025-05-15 14:18:57 -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
swift-ci
09c013502e Merge remote-tracking branch 'origin/main' into rebranch 2025-05-13 17:33:33 -07: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
swift-ci
cfe1e7ee67 Merge remote-tracking branch 'origin/main' into rebranch 2025-05-12 21:53:44 -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
swift-ci
d045f02246 Merge remote-tracking branch 'origin/main' into rebranch 2025-05-12 13:34:29 -07: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
swift-ci
607967d8fa Merge remote-tracking branch 'origin/main' into rebranch 2025-05-08 19:16:17 -07: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
swift-ci
50da3ee38d Merge remote-tracking branch 'origin/main' into rebranch 2025-05-08 13:56:36 -07: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
Anthony Latsis
0c536923c9 Manually merge branch 'main' into rebranch 2025-05-07 14:05:43 +01: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
swift-ci
537c86f009 Merge remote-tracking branch 'origin/main' into rebranch 2025-05-01 16:13:50 -07: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
swift-ci
51c93c1134 Merge remote-tracking branch 'origin/main' into rebranch 2025-05-01 07:35:16 -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
swift-ci
de2091f2d3 Merge remote-tracking branch 'origin/main' into rebranch 2025-04-30 15:53:34 -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
Anthony Latsis
442825d9de [rebranch] IRGen: Fix omission in hash computation after switching API
Issue introduced by 0d2d6cb8a0.
`llvm::getPointerAuthStableSipHash` produces the combined result of
the obsoleted `clang::CodeGen::computeStableStringHash` and
our `getDiscriminatorForHash`, so we no longer need to call both.
2025-04-30 21:45:46 +01: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
swift-ci
a546b80a0d Merge remote-tracking branch 'origin/main' into rebranch 2025-04-29 23:53:41 -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
swift-ci
0734f25612 Merge remote-tracking branch 'origin/main' into rebranch 2025-04-29 14:58:07 -07: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
swift-ci
dd8c99e095 Merge remote-tracking branch 'origin/main' into rebranch 2025-04-25 10:17:16 -07:00
Anthony Latsis
3596104550 Merge pull request #80987 from AnthonyLatsis/rebranch-fix
[rebranch] Get rebranch building with new LLVM stable branch
2025-04-25 13:08:24 +01: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
Anthony Latsis
c950146889 IRGen: Adjust use of llvm::PassBuilder::buildO0DefaultPipeline (parameter type changed)
Per 5445edb5d6667333f829f03932c2fc6a607e8306 (llvm-project).
2025-04-24 01:52:48 +01:00