Commit Graph

2885 Commits

Author SHA1 Message Date
Alastair Houghton
2aba85f12f Merge pull request #71056 from al45tair/eng/PR-120952971
[Runtime][IRGen] Trap C++ exceptions on *throw*, not catch.
2024-02-08 15:00:35 +00:00
Alastair Houghton
9d2dcb5c4e Merge pull request #71386 from al45tair/eng/PR-122302117
[Runtime] Add an option to produce non-symbolicated backtraces.
2024-02-08 11:14:26 +00:00
Alastair Houghton
dd0b826235 [Runtime] Improved symbolication option for backtracing.
Rather than just on or off, I've changed it to allow "off", "fast",
or "full".  "fast" means that we'll do symbol lookup, but we won't
try to find inline frames and we won't run line number programs
(those are the things that are taking considerable time in some
cases).

rdar://122302117
2024-02-06 17:38:20 +00:00
Alastair Houghton
25e9ca02b0 [Runtime][Test] Add a leading underscore to swift_exceptionPersonality.
The other new runtime functions appear to have a leading underscore.
It makes sense in this case because we don't expect anything to call
this directly (other than the unwinder).

rdar://120952971
2024-02-06 16:21:09 +00:00
Alastair Houghton
143a473aa4 [Runtime][IRGen] Trap C++ exceptions on *throw*, not catch.
The previous approach was effectively to catch the exception and then
run a trap instruction.  That has the unfortunate feature that we end
up with a crash at the catch site, not at the throw site, which leaves
us with very little information about which exception was thrown or
where from.

(Strictly we do have the exception pointer and could obtain exception
information, but it still won't tell us what threw it.)

Instead of that, set a personality function for Swift functions that
call potentially throwing code, and have that personality function
trap the exception during phase 1 (i.e. *before* the original stack
has been unwound).

rdar://120952971
2024-02-06 16:19:17 +00:00
Doug Gregor
e4d6bee153 Merge pull request #71400 from DougGregor/will-throw-typed
Implement `swift_willThrow` variant for typed throws.
2024-02-06 03:22:22 -08:00
Doug Gregor
3fa07a0e7a Implement swift_willThrow variant for typed throws.
`swift_willThrow` is called with an error right before it is thrown.
This existing entrypoint requires an already-boxed error existential;
with typed errors, we don't have the error existential on hand, so we
would need to allocate the box to throw a typed error. That's not okay.

Introduce a new `swift_willThrowTypedImpl` entry point into the runtime
that will first check for the presence of an error handler and, if one
is present, box the error to provide to the error handler. This
maintains the no-allocations path for typed errors while still
allowing existing error handlers to work.

This new entrypoint isn't available on older Swift runtimes, so create
a back-deployable shim called by the compiler. On new-enough platforms,
this will call through to `swift_willThrowTypedImpl`. On older
platforms, we drop the error and don't call the registered will-throw
handler at all. This is a compromise that avoids boxing when throwing
typed errors, at the cost of a slightly different experience for this
new feature on older runtimes.

Fixes rdar://119828459.
2024-02-05 15:06:55 -08:00
Alastair Houghton
8269bf72eb [Runtime] Add an option to produce non-symbolicated backtraces.
Symbolication can take some time, depending on the binaries involved.
In certain contexts it's better for the backtrace to finish quickly,
and then symbolication could be done offline.

rdar://122302117
2024-02-05 12:56:47 +00:00
Tim Kientzle
ccc6ef8e68 Merge pull request #70978 from tbkka/tbkka-revert-PR68952
Revert #68952 [Casting] Make more casts look inside __SwiftValue
2024-02-02 11:03:04 -08:00
Guillaume Lessard
114f235d17 Merge pull request #71167 from vanvoorden/vanvoorden/inclusive-language
[Inclusive Language][Comments][Documentation] migrate "sanity" checks to "soundness" checks
2024-02-02 10:27:34 -08:00
Dario Rexin
55e565d838 [Runtime] Handle different types for src and dest in existentialAssignWithCopy (#71323)
rdar://117083470

An existential can contain a different type than the one that is being assigned, so we have to check the types and handle the values accordingly.
2024-02-02 08:34:37 -08:00
Mike Ash
b8b59c4bac [ExternalGenericMetadataBuilder] Add a test that validates built metadata against the runtime.
We run the builder, then use a small program that converts the JSON output into C code that generates the data. Compile that into a bundle, then load it as the prespecializations library. Then scan all the entries in the table and compare them with what the runtime builds dynamically.
2024-01-31 17:03:27 -05:00
Mike Ash
46ddceb7d4 Merge pull request #71184 from mikeash/libprespecialize-metadata-name-lookup
[Runtime] Do a proper hash table lookup in the prespecializations library.
2024-01-29 12:10:35 -05:00
Mike Ash
ade4b8e989 [Runtime] Fix dyld call for Swift prespecialized data.
Make our variables const to match the call signature, and do a weak check of the symbol before calling it.
2024-01-27 12:53:23 -05:00
Mike Ash
edb292dda5 [Runtime] Do a proper hash table lookup in the prespecializations library.
We were doing a linear scan of the table contents as a stopgap. Stop doing that, and compute the proper key for the lookup, matching the one used in the builder.
2024-01-26 12:04:02 -05:00
Mike Ash
4bc7726d43 Merge pull request #70900 from mikeash/swift-generic-metadata-builder-out-of-process
[Tools] Add a library to build specialized generic metadata out of process.
2024-01-26 10:50:34 -05:00
John McCall
b0fb03d8c7 Create a uniform representation for function type isolation.
Not quite NFC because apparently the representation bleeds into what's
accepted in some situations where we're supposed to be warning about
conflicts and then making an arbitrary choice.  But what we're doing
is nonsense, so we definitely need to break behavior here.

This is setting up for isolated(any) and isolated(caller).  I tried
to keep that out of the patch as much as possible, though.
2024-01-25 22:11:01 -05:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Mike Ash
4341102c92 [Tools] Add a library to build specialized generic metadata out of process.
This library uses GenericMetadataBuilder with a ReaderWriter that can read data and resolve pointers from MachO files, and emit a JSON representation of a dylib containing the built metadata.

We use LLVM's binary file readers to parse the MachO files and resolve fixups so we can follow pointers. This code is somewhat MachO specific, but could be generalized to other formats that LLVM supports.

rdar://116592577
2024-01-24 20:45:50 -05:00
Tim Kientzle
62f8780bb0 Revert "Obj-C class metatypes should never satisfy Obj-C existentials"
This reverts commit aed05b9a36.

This needs some additional work.  Reverting out until it can be fixed.
2024-01-22 11:27:42 -08:00
Tim Kientzle
4ea5ed1309 Revert #68952 [Casting] Make more casts look inside __SwiftValue
Turns out that our Obj-C bridging relies on this inconsistent behavior,
so it can quite likely never be actually fixed.
2024-01-17 18:14:57 -08:00
Allan Shortlidge
79d0ecafaa NFC: Ignore deprecation of asl_log in the runtime and demangling library.
ASL is deprecated in macOS 10.12. It may be time to transition to os_log now
that deployment targets have been raised to 10.12, but until that project
starts these warnings are just pollution.

Filed rdar://121066531 to track adoption of `os_log()` if appropriate.
2024-01-16 13:27:55 -08:00
Allan Shortlidge
d3305af80a NFC: Ignore -Wreceiver-forward-class warning in SwiftObject.mm. 2024-01-16 13:27:55 -08:00
Allan Shortlidge
5add794b82 NFC: Ignore -Wobjc-root-class warning in SwiftObject.h.
SwiftObject intentionally does not inherit from `NSObject`.
2024-01-16 13:27:55 -08:00
Allan Shortlidge
3a3a2460df NFC: Resolve -Wformat warning in ProtocolConformance.cpp. 2024-01-12 17:41:50 -08:00
Allan Shortlidge
272a1a4b18 NFC: Resolve -Wauto-var-id warning in ErrorObject.mm. 2024-01-12 17:40:46 -08:00
Allan Shortlidge
333b7b6a46 NFC: Resolve unused variable warnings in BytecodeLayouts.cpp. 2024-01-12 17:39:00 -08:00
Mike Ash
29c350e813 [Runtime] Create an external generic metadata builder.
Create a version of the metadata specialization code which is abstracted so that it can work in different contexts, such as building specialized metadata from dylibs on disk rather than from inside a running process.

The GenericMetadataBuilder class is templatized on a ReaderWriter. The ReaderWriter abstracts out everything that's different between in-process and external construction of this data. Instead of reading and writing pointers directly, the builder calls the ReaderWriter to resolve and write pointers. The ReaderWriter also handles symbol lookups and looking up other Swift types by name.

This is accompanied by a simple implementation of the ReaderWriter which works in-process. The abstracted calls to resolve and write pointers are implemented using standard pointer dereferencing.

A new SWIFT_DEBUG_VALIDATE_EXTERNAL_GENERIC_METADATA_BUILDER environment variable uses the in-process ReaderWriter to validate the builder by running it in parallel with the existing metadata builder code in the runtime. When enabled, the GenericMetadataBuilder is used to build a second copy of metadata built by the runtime, and the two are compared to ensure that they match. When this environment variable is not set, the new builder code is inactive.

The builder is incomplete, and this initial version only works on structs. Any unsupported type produces an error, and skips the validation.

rdar://116592420
2024-01-11 09:15:02 -05:00
Rose
873a423da6 Some methods swap the number of elements and the size arguments
For calloc, the variable denoting the of elements comes first,
then the variable denoting the size of each element. However, both
arguments are swapped when calling this function in many places in this codebase.
2023-12-23 11:00:31 -05:00
Alastair Houghton
7689c29e08 [Runtime] Fix call site for malloc_type_posix_memalign.
Seems I missed off the type ID.  Oops.

rdar://119137861
2023-12-13 20:52:51 +00:00
Alastair Houghton
9fc61ddb8b [Runtime] Use malloc_type_posix_memalign().
We can't use `malloc_type_aligned_alloc()` because `aligned_alloc()` requires
that `size` be a multiple of `alignment`, which isn't something we expect here.

rdar://119137861
2023-12-11 12:21:02 +00:00
Alastair Houghton
c9abb0bc61 [Backtracing] Improve warning message about thread suspension failure.
In the event that the backtracer fails to suspend a thread, it emits a
warning message.  Unfortunately the exact meaning of this message isn't
obvious and it doesn't make clear that it's a secondary problem (that is,
you've already crashed at this point).

Update the message to make things clearer.

rdar://116593541
2023-12-08 13:53:38 +00:00
Mike Ash
3716df4ca5 [Runtime] Fix findBridgeWitness when building for the shared cache.
The static bridgeableProtocol inherits the ptrauth_struct attribute which uses the B key, and that's not allowed on global data in the shared cache. Pass the value directly as a parameter instead.
2023-12-01 09:40:25 -05:00
nate-chandler
1c0971e719 Merge pull request #70099 from nate-chandler/gardening/20231129/1
[Gardening] Fix typo.
2023-11-29 16:59:09 -08:00
Nate Chandler
3817af3067 [Gardening] Fix typo.
Replaced homophone of presence ("presents", i.e. 🎁🎁, 🖥️, etc.) with
the word itself.
2023-11-29 12:52:35 -08:00
Alastair Houghton
dfea14af45 Merge pull request #69913 from finagolfin/arm
[Backtracing][Android] Fix armv7 build
2023-11-29 14:07:26 +00:00
Dario Rexin
011fce8212 [Runtime] Fix leak of bridge objects in swift_generic_initWithTake (#69977)
rdar://118606044

The initWithTakeTable accidentally referenced bridgeRetain instead of copyingInitWithTake, which caused a leak when an object containing a bridge reference was also not bitwise takable.
2023-11-27 08:04:10 -08:00
Dario Rexin
506fbb3c91 [Runtime] Fix alignment of tuples in runtime layout string instantiation (#69975)
rdar://118366415

If a tuple was not already aligned, this would cause a wrong offset to be used in the layout string.
2023-11-27 08:03:38 -08:00
Finagolfin
d9d6356f3b [Backtracing][Android] Fix armv7 build 2023-11-16 20:26:09 +05:30
Alastair Houghton
b693cce3b8 Merge pull request #69859 from al45tair/eng/PR-118402226
[Backtracing] Fix ARM64e build failure.
2023-11-15 11:14:13 +00:00
Alastair Houghton
5c427124ae [Backtracing] Fix ARM64e build failure.
Accessing the thread context structures is complicated because their
member variables change name depending on various macros.  This caused
a build failure for ARM64e.

rdar://118402226
2023-11-14 17:37:00 +00:00
Alastair Houghton
1667378e73 [Backtracing] Make sure we print the program counter on ARM64 linux.
On Linux, the right macro for detecting ARM64 is `__aarch64__`, not
`__arm64__`.

rdar://118379429
2023-11-14 08:27:24 +00:00
Alastair Houghton
2c8bd79bf0 Merge pull request #69697 from al45tair/eng/PR-118055527
[Backtracing] Add an indication that we're working on a backtrace.
2023-11-13 17:54:43 +00:00
Tim Kientzle
4e821f65ec Merge pull request #69464 from tbkka/tbkka-objc-equatable-hashable
Use Swift Equatable and Hashable conformances from ObjC
2023-11-10 13:46:19 -08:00
Dario Rexin
36f3367275 [Runtime] Use threaded code in compact value witness runtime (#69756)
* [Runtime] Use threaded code in compact value witness runtime

These changed reduce branching and yield performance improvements of up to 10% for some cases.

* Fix offset in handleRefCountsInitWithTake
2023-11-09 19:12:29 -08:00
Alastair Houghton
9ca81c63b1 [Backtracing] Massage the output a little in various cases.
We shouldn't try to erase the message when in non-color mode; mostly
that's intended for redirected output scenarios anyway, and in that case
we don't really want garbage in the output.

Also, improve the failure messages when the backtracer itself goes
wrong or can't be executed.

Finally, change the behaviour slightly so that *if* we're explicitly
enabled, *and* the backtracer path wasn't explicitly specified, *and*
we can't find the backtracer, we print a warning on start-up.  We
don't do that in any other case because we don't want spurious warnings
everywhere.

rdar://118055527
2023-11-09 18:12:18 +00:00
Alastair Houghton
9d462a7b69 [Backtracing] Add an indication that we're working on a backtrace.
When we crash, emit a message straight away that says we're working
on a backtrace.  If starting the backtracer fails, report that also.

Finally, add a duration to the messages output by the backtracer, so
that we can see how long it took.

rdar://118055527
2023-11-09 18:12:18 +00:00
Alastair Houghton
3d9533de0d Merge pull request #69570 from al45tair/eng/PR-117470489
[Linux] Disable fatalError() backtraces when the runtime backtracer is active.
2023-11-09 17:53:53 +00:00
Mike Ash
967c5c6a75 Merge pull request #69542 from mikeash/retain-release-override-optional
[Runtime] Add option to remove override point for retain/release.
2023-11-08 19:51:29 -05:00
Mike Ash
5e0125b53d Merge pull request #69334 from mikeash/metadata-cache-key-equality-memcmp
[Runtime] Have MetadataCacheKey::operator== try memcmp before deeper comparison.
2023-11-08 19:36:48 -05:00