Commit Graph

3149 Commits

Author SHA1 Message Date
Alastair Houghton
e2c7ec6ee7 Merge pull request #75108 from al45tair/eng/PR-130992923
[Runtime][Win32] Fix fatalError() backtraces.
2024-07-11 14:49:19 +01:00
Alastair Houghton
a72c167af5 [Runtime][Win32] Further tweaks to SymbolInfo.cpp and Errors.cpp.
Fix an unused variable warning in `Errors.cpp`.

Use brace initialization syntax in `SymbolInfo.cpp` rather than using
a constructor call.

rdar://130992923
2024-07-11 11:51:59 +01:00
Tim Kientzle
fac8c972a5 Tailored error reporting when dynamic casts have nonsensical type args
This inserts a suitably named function into the stack trace whenever
a dynamic cast failure involves a NULL source or target type.
Very often, crash logs include backtraces with function names but
no log output; with this change, such a backtrace might look like
the following -- note `TARGET_TYPE_NULL` in the function name
here to mark the missing type information:

```
 frame #0: __pthread_kill + 8
 frame #1: pthread_kill + 288
 frame #2: abort + 128
 frame #3: swift::fatalErrorv()
 frame #4: swift::fatalError()
 frame #5: swift_dynamicCastFailure_TARGET_TYPE_NULL()
 frame #6: swift::swift_dynamicCastFailure()
 frame #7: ::swift_dynamicCast()
```

Resolves rdar://130630157
2024-07-10 15:57:36 -07:00
Alastair Houghton
418a240e80 [Runtime][Win32] Tweak SymbolInfo slightly based on review comments.
Prefer `ZeroMemory()` to `::memset()` here.

Use `sizeof(*wszBuffer)` instead of `sizeof(WCHAR)`, just in case.

Don't use `*this=other`, because that motivates tests around `::free()`,
but instead pull the shared code out into some private functions.

Also, fix `SymbolInfo()` to initialize the pointer members.

rdar://130992923
2024-07-10 12:22:35 +01:00
Tim Kientzle
0ab1b1631d Upstream some binary-compatibility logic 2024-07-09 13:30:13 -07:00
Alastair Houghton
8ad89c08e2 [Runtime][Win32] Fix fatalError() backtraces.
We were calling `SymInitialize()` multiple times, which is wrong, which
was making the `SymbolInfo::lookup()` call fail.  Also, we weren't
fetching the module names, so we should do that too.

rdar://130992923
2024-07-09 18:50:20 +01:00
Joe Groff
dfc5321ca6 Merge pull request #74997 from jckarter/protocol-extension-self-same-type-runtime-resolution
Runtime: Fix runtime type resolution when mangled names refer to protocol extensions with Self same type constraints.
2024-07-09 09:10:19 -07:00
Joe Groff
e0df8ffdb5 Runtime: Fix runtime type resolution when mangled names refer to protocol extensions with Self same type constraints.
If a type or opaque type descriptor appears inside of a protocol extension of the form:

```
extension P where Self == Nominal { ... }
```

then the runtime representation of the extension context was interpreted by the runtime
demangler as a nominal type extension, even though the parameterization is on the
`<Self>` generic signature of the protocol extension and not the generic signature of
the nominal type. This would cause spurious rejection of mangled names referencing the
extension context because we mistakenly thought that the type arguments mismatched with
the nominal type signature rather than matching them to the extension context.

Add some code to `_findExtendedTypeContextDescriptor` to detect when an extension is
a protocol extension with a `Self == SameType` constraint, and pass the extension along
rather than treating it as a nominal type extension. Fixes rdar://130168101.
2024-07-08 07:41:24 -07:00
Alastair Houghton
565a9b9208 Merge pull request #75051 from al45tair/eng/PR-131294724
[Runtime] Add missing cast.
2024-07-08 13:27:08 +01:00
Alastair Houghton
64b891d5fe [Runtime] Add missing cast.
Apparently we're missing a cast in `_swift_initRuntimePath()`.  Previously
this code was accidentally not being used, which is why we hadn't noticed
it.

rdar://131294724
2024-07-08 10:29:31 +01:00
Alexander Cyon
c21b1e68fd [stdlib] Fix typos 2024-07-06 13:09:57 +02:00
Alastair Houghton
fc012fd258 Merge pull request #74891 from al45tair/eng/PR-130954606
[Runtime] Use dyld to find the image path when possible.
2024-07-04 15:10:06 +01:00
Mike Ash
9bbcef3bc5 [Runtime] Fix missing return in getMetadataFromPointerKeyedMap.
When DYLD_FIND_POINTER_HASH_TABLE_ENTRY_DEFINED is set but the function is not found at runtime, we're missing a return statement.
2024-07-03 15:26:11 -04:00
Alastair Houghton
d846689695 [Runtime] Use dyld to find the image path when possible.
For performance reasons, we want to avoid `dladdr()` when possible.

rdar://130954606
2024-07-02 14:11:10 +01:00
Ben Barham
d72f5b12c4 Update StringRef::equals references to operator==
`equals` has been deprecated upstream, use `operator==` instead.
2024-06-27 19:14:06 -07:00
Tim Kientzle
05c74e0d90 Revert "Merge pull request #74394 from tbkka/tbkka-remotemirror-no-more-mpe-metadata-partial"
This reverts commit a1708ef8b1, reversing
changes made to b5930625be.
2024-06-14 15:32:39 -07:00
Tim Kientzle
a1708ef8b1 Merge pull request #74394 from tbkka/tbkka-remotemirror-no-more-mpe-metadata-partial
Remove RemoteInspection code to fetch no-longer-used reflection metadata
2024-06-13 16:40:04 -07:00
Tim Kientzle
c20ef6de2a Remove RemoteInspection code to fetch no-longer-used reflection metadata
without relying on spare bit information in the reflection metadata
(which was added in #40906).  As a result, we can remove the
code from #40906.

This is the first step in such removal.  It removes the RemoteMirror
code for looking up such metadata.  It leaves behind:

* Sufficient stubs for LLDB to continue to build.  Once LLDB is updated, these stubs can be removed as well.

* The compiler code to emit such metadata.  This allows new binaries to still reflect MPEs on older runtimes.  This will need to be kept for a transitional period.
2024-06-13 09:34:43 -07:00
Mike Ash
b86fe88c43 [Runtime] Fix key argument indexing when checking invertible protocols.
Track the key argument index separately from the generic parameter index when performing the invertible protocol checking in _checkGenericRequirements. This keeps the indexing correct when a non-key argument is followed by a key argument.

rdar://128774651
2024-06-11 12:39:23 -04:00
Konrad `ktoso` Malawski
0c44645832 [Concurrency] Implement defensive copying in task groups, rather than crashing (#73978) 2024-05-31 11:27:03 -07:00
Mike Ash
7427aa5f48 [Concurrency] Remove SWIFT_ENABLE_ASYNC_JOB_DISPATCH_INTEGRATION environment variable.
This option serves no purpose anymore and this dispatch integration should always be enabled.
2024-05-30 12:43:19 -04:00
Konrad `ktoso` Malawski
7790609fc8 [Concurrency] Futher prevent crashes in legacy mode of isCurrentExecutor 2024-05-27 17:02:26 +09:00
Mike Ash
ae71658c6a [Runtime] Add weak check to use of _dyld_find_pointer_hash_table_entry.
Needed to avoid availability errors in some configurations.

rdar://127621414
2024-05-21 10:59:15 -04:00
Michael Gottesman
d759ec97ea Merge pull request #73696 from gottesmm/rdar128216574
[sending] Add support for 'sending'
2024-05-18 05:42:41 -04:00
Mike Ash
011c46eb45 Merge pull request #73650 from mikeash/prespecializations-dyld-hash-table
[Runtime] Add pointer-based lookup of prespecialized metadata.
2024-05-17 21:22:57 -04:00
Mike Ash
96555ba51c [Runtime] Add pointer-based lookup of prespecialized metadata.
The existing lookup uses a hash table with the type's mangled name as the key. Building that key is costly. Add a new table that uses pointer keys, so that we can use the descriptor and arguments directly as the key.

rdar://127621414
2024-05-17 16:17:03 -04:00
Michael Gottesman
e3e78ad6bb [sending] Change the internals of sending to be based around 'sending' instead of 'transferring'.
We still only parse transferring... but this sets us up for adding the new
'sending' syntax by first validating that this internal change does not mess up
the current transferring impl since we want both to keep working for now.

rdar://128216574
2024-05-16 12:20:45 -07:00
Mike Ash
dd24d8e71f [Runtime] Don't emit signposts until the system is ready.
Emitting a signpost for the first time can trigger lazy setup of the logging system, and doing this in the wrong context can cause deadlocks. Check to see if the logging system is already set up, and only emit signposts if it has been to avoid triggering this.

As it's hard to determine if the "is it set up?" function is available in the SDK we're building against, only do this in OS builds, as it's not particularly useful in local builds.

rdar://124620772
2024-05-15 11:02:23 -04:00
Tim Kientzle
54a2007903 Merge pull request #73552 from tbkka/tbkka-127839540
Make SwiftValue == support unconditional
2024-05-10 22:47:30 -07:00
Alex Lorenz
340bfcddc0 Merge pull request #73534 from hyp/eng/fix-readlink
stdlib: fix android build
2024-05-09 20:29:59 -07:00
Tim Kientzle
cb03a459fe Make SwiftValue == support unconditional
PR #71620 made this behavior conditional as a way to help
provide binary compatibility for legacy software that might
be relying on the old behavior.

So far, it appears the only such problems arose from the
SwiftObject behavior changes, not from SwiftValue behavior.
So let's optimistically back this out and make the new behavior
unconditional.

Resolves rdar://127839540
2024-05-09 14:38:36 -07:00
Konrad `ktoso` Malawski
b2bd17635f [Concurrency] Fix too eager early return in checkIsolation mode detecting (#73495) 2024-05-09 03:12:37 -07:00
Alex Lorenz
94b1348183 stdlib: fix android build
the readlink addition in f4bf278 was introduced without a corresponding include.
2024-05-08 20:20:51 -07:00
Alastair Houghton
f4bf27852f [Backtracing] Make the backtracer work for fully-static Linux.
The backtracer and its build system need a couple of changes to make
them work with the new fully-static Linux support.

rdar://123507656
2024-05-07 16:51:34 +01:00
Alastair Houghton
a2c33ad22c [Runtime] Fix generation of .lnk files for static linking.
Use the new `SWIFT_SDK_<sdk>_STATIC_LINKING_SUPPORTED` and
`_STATIC_ONLY` flags instead of hardcoding support for Linux
and WASI.

Also, use the `_LIB_SUBDIR` variable rather than lowercasing
the SDK.

rdar://123504757
2024-05-07 16:45:16 +01:00
Dario Rexin
db7580f842 Merge pull request #73426 from drexin/wip-127379960
[Runtime] Mask out spare bits after copying for Error in CVW
2024-05-06 13:59:37 -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
Dario Rexin
101f8a4760 [Runtime] Mask out spare bits after copying for Error in CVW
rdar://127379960

When the spare bits of an Error objects are used to store tag bits, this caused the enum tag to be lost, which caused the wrong enum cases to be matched.
2024-05-03 12:26:43 -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
4578be2810 Set a minimum deployment target for objcImpl
We’re not committing to @objc @implementation back-deploying to pre-stable Apple platforms.
2024-04-30 12:03:46 -07:00
Becca Royal-Gordon
915a49a1c0 [NFC] Refactor swift_updatePureObjCClassMetadata()
Merge the three-stage operation originally designed for field vectors into a single unified loop that acts directly on the ivar offsets instead of using a faux field offset vector.
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
Alastair Houghton
7df249b67c [Runtime] Tidy up a couple of minor nits.
This doesn't change any code, just makes things look slightly
neater.

rdar://123504095
2024-04-29 10:48:23 +01:00
Alastair Houghton
554c402f11 [Runtime] Add the retain attribute to make the backtracer work.
Without `retain` here, we might remove the reference that pulls in
the backtracing support code.

rdar://123504095
2024-04-29 10:48:23 +01:00
Alastair Houghton
b7557247a7 [Runtime] Tidy up section declarations slightly.
This also calls out the reflection sections, even though we don't
actually need to do anything special for them (as it turns out).

rdar://123504095
2024-04-29 10:48:22 +01:00
Mike Ash
4d62c521bd [Runtime] Avoid dlsym of objc_isUniquelyReferenced.
We attempted to use the declaration if it exists, and fall back to dlsym. This didn't actually work and we always call dlsym. Include the right header (when available) and add a weak check to the direct call.

rdar://127116080
2024-04-26 11:44:28 -04:00
Mike Ash
717b03b5a5 [Runtime] Use StackAllocatedDemangler in getLibPrespecializedMetadata.
Reduce the amount of time spent freeing demangler slabs by starting out with a stack allocation that doesn't need to be freed.

rdar://126932780
2024-04-23 14:44:40 -04:00
Dario Rexin
b97fbac9a6 [Runtime] Fix CVW for genreic single payload enums with no extra inha… (#73186)
* [Runtime] Fix CVW for genreic single payload enums with no extra inhabitants

rdar://126728925

When the payload of a generic SPE did not have any extra inhabitants, we erroneously always treated it as the no payload case.
Additionally the offset and skip values were improperly computed.

* Fixed FileCheck string
2024-04-22 22:56:57 -07:00
Mike Ash
84983353d3 [Runtime] Add the pointer location to the "failed to look up symbolic reference" error.
The pointer location can be computed from the symbolic reference location and offset, which we already provide, but it's not clear that you should add them together, nor is it clear why this failure would occur. Add the location of the NULL pointer itself to the error message, and also mention that it's probably caused by a missing weak symbol.
2024-04-19 10:48:44 -04:00