Commit Graph

257 Commits

Author SHA1 Message Date
Mike Ash
292762d4eb [Test] Add codesign command to protocol-conformance-cache tests.
rdar://162423302
2025-10-15 12:56:23 -04:00
Mike Ash
0807294ee3 [Test] Use %env in protocol-conformance-cache tests.
rdar://161370009
2025-09-26 12:52:31 -04:00
Dmitrii Galimzianov
091b005a60 Protocol conformance cache for generic types
This change adds a new type of cache (cache by type descriptor) to the protocol conformance lookup system. This optimization is beneficial for generic types, where the
same conformance can be reused across different instantiations of the generic type.

Key changes:
- Add a `GetOrInsertManyScope` class to `ConcurrentReadableHashMap` for performing
  multiple insertions under a single lock
- Add type descriptor-based caching for protocol conformances
- Add environment variables for controlling and debugging the conformance cache
- Add tests to verify the behavior of the conformance cache
- Fix for https://github.com/swiftlang/swift/issues/82889

The implementation is controlled by the `SWIFT_DEBUG_ENABLE_CACHE_PROTOCOL_CONFORMANCES_BY_TYPE_DESCRIPTOR`
environment variable, which is enabled by default.

This reapplies https://github.com/swiftlang/swift/pull/82818 after it's been reverted in https://github.com/swiftlang/swift/pull/83770.
2025-08-30 00:12:52 +02:00
Mike Ash
6d96d8fa87 [Test] Disable nested private generic types test on old runtimes.
This test tests a fix in Swift 5.1+. When running on 5.0, it uses expectCrashLater since 5.0 doesn't have the fix. This breaks if we're ever testing a newer runtime on an old OS. We don't need to test if old runtimes are broken (we know they are), just that new runtimes remain fixed. Don't run the test at all unless on 5.1+.

rdar://159026050
2025-08-26 15:43:04 -04:00
Dmitrii Galimzianov
4509b22415 Revert "Protocol conformance cache for generic types"
This reverts commit 7989dbe24e merged in https://github.com/swiftlang/swift/pull/82818
2025-08-16 01:39:16 +02:00
Mike Ash
030f3c889d [Test] Disable protocol-conformance-cache tests when tests are optimized.
These tests need to perform various conformance checks that can be statically known, and the optimizer removes them.

rdar://155924190
2025-07-22 11:55:10 -04:00
Dmitrii Galimzianov
7989dbe24e Protocol conformance cache for generic types
This change adds a new type of cache (cache by type descriptor) to the protocol conformance lookup system. This optimization is beneficial for generic types, where the
same conformance can be reused across different instantiations of the generic type.

Key changes:
- Add a `GetOrInsertManyScope` class to `ConcurrentReadableHashMap` for performing
  multiple insertions under a single lock
- Add type descriptor-based caching for protocol conformances
- Add environment variables for controlling and debugging the conformance cache
- Add tests to verify the behavior of the conformance cache
- Fix for https://github.com/swiftlang/swift/issues/82889

The implementation is controlled by the `SWIFT_DEBUG_ENABLE_CACHE_PROTOCOL_CONFORMANCES_BY_TYPE_DESCRIPTOR`
environment variable, which is enabled by default.
2025-07-11 03:54:42 +02:00
Alastair Houghton
9e65b84099 [Runtime][Tests] Disable Runtime/backtrace test on Android.
This should be disabled for Android.

Fixes #44446.

rdar://153615567
2025-06-18 10:03:24 +01:00
Andrew Trick
64a48d08e1 Update tests for strict @lifetime type checking 2025-03-19 11:59:04 -07:00
Mike Ash
f1070f7f1e Merge pull request #80000 from swiftlang/jgrynspan/145945680-mangledtypename-nonescapable
[Runtime] Allow ~Escapable types in _getMangledTypeName.
2025-03-14 11:53:12 -04:00
Jonathan Grynspan
9489564e07 Just like #76041, but for ~Escapable instead of ~Copyable.
Resolves rdar://145945680.
2025-03-03 14:06:30 -05:00
Alejandro Alonso
c1bb143648 Make ValueGenerics feature always available 2025-02-27 10:03:37 -08:00
John McCall
623d063ad7 Fix remangling isolated(any) function types from type metadata. 2025-01-22 21:41:14 -05:00
Augusto Noronha
72b0120b43 [DebugInfo] Fix handling of @_originallyDefinedIn types
Emit an imported declaration for @_originallyDefinedIn under the
real module that these types live in.

This patch also changes the mangling for the debugger to respect
@_originallyDefinedIn, and fixes a bug where @_originallyDefinedIn
that should be ignored was still being used when mangling.

rdar://137146961
2024-12-16 10:28:18 -08:00
Joe Groff
5970f0ef0e Merge pull request #77439 from jckarter/disable-test-on-arm64e
Disable test/Runtime/bitwise-borrowable-generics.swift on arm64e.
2024-11-07 08:21:16 -08:00
Mike Ash
9ae3f881a8 [Test] Fix assertion failure building demangleToMetadata.swift.
The direct call to _getTypeByMangledName made the compiler angry when doing an optimizd simulator build. Instead, use _typeByName with a string that has an embedded NUL to achieve the same effect.

rdar://139264622
2024-11-06 20:49:38 -05:00
Joe Groff
7a4637d18a Disable test/Runtime/bitwise-borrowable-generics.swift on arm64e. 2024-11-06 16:59:59 -08:00
Mike Ash
794165ad6e Merge pull request #77346 from mikeash/demangler-nul-terminator
[Demangler] Accept overly short type names if they are NUL terminated
2024-11-04 20:17:46 -05:00
Mike Ash
4a5dc2a6a9 [Demangler] Accept overly short type names if they are NUL terminated
swift_getTypeByMangledNameInContext takes a pointer and a length, but some programs pass a pointer to a NUL-terminated C string and an excessive length, implicitly relying on the terminator to end the string early. This worked previously, but commit 7fe2befd31 made the demangler more strict about bad data. This changes the demangler to successfully parse a name by terminating the name string at a 0 byte encountered where it expects to find an operator. All other cases of bad data continue to be rejected.

rdar://137430048
2024-11-04 11:21:54 -05:00
Daniel Rodríguez Troitiño
ba68faaed5 [test] Mark tests that use experimental/upcoming features as such
Find all the usages of `--enable-experimental-feature` or
`--enable-upcoming-feature` in the tests and replace some of the
`REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which
should correctly apply to depending on the asserts/noasserts mode of the
toolchain for each feature.

Remove some comments that talked about enabling asserts since they don't
apply anymore (but I might had miss some).

All this was done with an automated script, so some formatting weirdness
might happen, but I hope I fixed most of those.

There might be some tests that were `REQUIRES: asserts` that might run
in `noasserts` toolchains now. This will normally be because their
feature went from experimental to upcoming/base and the tests were not
updated.
2024-11-02 11:46:46 -07:00
Allan Shortlidge
cb578172ea Tests: Remove -disable-availability-checking in more tests that use concurrency.
Use the `%target-swift-5.1-abi-triple` substitution to compile the tests for
deployment to the minimum OS versions required for use of _Concurrency APIs,
instead of disabling availability checking.
2024-10-19 12:35:20 -07:00
Joe Groff
4b3931c8ce Merge pull request #76734 from jckarter/atomic-layout-runtime
Runtime: Set 'is not bitwise borrowable' bit for raw layout types.
2024-09-30 05:53:43 -10:00
Joe Groff
6e565b52ba Runtime: Set 'is not bitwise borrowable' bit for raw layout types.
When initializing metadata for layout-dependent raw layout types, set the
"is not bitwise borrowable" bit.
2024-09-27 11:27:47 -07:00
Jonathan Grynspan
db7a030a71 Extend internal _mangledTypeName() function to take non-copyable types. (#76041)
`_mangledTypeName()` returns the Swift-mangled typename of a given type. This PR extends it to take non-copyable types as well.

Related to our use case in Swift Testing, but not to the PR directly: #69146 #69147 #71112

Resolves rdar://134278607.
2024-09-11 16:11:58 -04:00
Alejandro Alonso
3d8a9d4554 Implement same type checking at runtime 2024-09-04 15:13:51 -07: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
Erik Eckstein
7fe2befd31 Demangler: handle errors in demangleType
Makes sure that invalid runtime type strings result in errors and not fail silently.
In worst case this could lead to wrong reconstructed metatypes which can result in all kind of memory corruption.

relates to rdar://129861211
2024-07-05 11:37:15 +02:00
Michael Gottesman
112071e57d [sending] Remove transferring.
Out of an abundance of caution, we:

1. Left in parsing support for transferring but internally made it rely on the
internals of sending.

2. Added a warning to tell people that transferring was going to
be removed very soon.

Now that we have given people some time, remove support for parsing
transferring.

rdar://130253724
2024-06-21 16:03:21 -07:00
Michael Gottesman
88729b9e34 [sending] Make {Transferring,Sending}ArgsAndResults a LANGUAGE_FEATURE instead of an UPCOMING_FEATURE.
TLDR: This makes it so that we always can parse sending/transferring but changes
the semantic language effects to be keyed on RegionBasedIsolation instead.

----

The key thing that makes this all work is that I changed all of the "special"
semantic changes originally triggered on *ArgsAndResults to now be triggered
based on RegionBasedIsolation being enabled. This makes a lot of sense since we
want these semantic changes specifically to be combined with the checkers that
RegionBasedIsolation turns on. As a result, even though this causes these two
features to always be enabled, we just parse it but we do not use it for
anything semantically.

rdar://128961672
2024-06-01 23:25:16 -07:00
Artem Chikin
1f14158a1d Introduce VisionOS Platform
This change introduces a new compilation target platform to the Swift compiler - visionOS.

- Changes to the compiler build infrastrucuture to support building compiler-adjacent artifacts and test suites for the new target.
- Addition of the new platform kind definition.
- Support for the new platform in language constructs such as compile-time availability annotations or runtime OS version queries.
- Utilities to read out Darwin platform SDK info containing platform mapping data.
- Utilities to support re-mapping availability annotations from iOS to visionOS (e.g. 'updateIntroducedPlatformForFallback', 'updateDeprecatedPlatformForFallback', 'updateObsoletedPlatformForFallback').
- Additional tests exercising platform-specific availability handling and availability re-mapping fallback code-path.
- Changes to existing test suite to accomodate the new platform.
2024-04-10 09:38:02 -07:00
Mike Ash
0491192337 [Runtime] Remove ExternalGenericMetadataBuilder. 2024-03-21 17:56:17 -04:00
Michael Gottesman
99e3f7fb13 [region-isolation] Make RegionBasedIsolation an upcoming feature for swift 6.
To make the tests pass, I had to teach sil-opt how to setup upcoming features
since it did not know how to parse them.

rdar://124100266
2024-03-05 15:15:14 -08:00
Mike Ash
a71eaf15db [Runtime] Don't shrink class InstanceStart when initing field offset vectors.
When ObjC interop is enabled, we emit what we think will be the class's InstanceStart and InstanceSize based on what we know about the superclass. We then fix up those values at runtime if they don't match. The compiler will emit this data into read-only memory if it knows they will always match, and then the runtime avoids writing to these fields if they already contain the correct value.

However, the compiler aligns the InstanceStart, but instance size is not aligned. For example:

class Super<T> { var bool = true }
class Sub: Super<Int> { var obj: AnyObject? }

Super's InstanceSize is 17 (on 64-bit) but Sub's InstanceStart is 24. The compiler sees a fixed layout and emits Sub's rodata into constant memory. The runtime sees that 24 does not equal 17 and tries to update it, but we don't want it to.

Instead, only update InstanceStart if it's too small to accommodate the superclass's InstanceSize. If it's overlay large then we'll just leave it alone. The compiler underestimates InstanceStart when it doesn't know the superclass's size so this should only happen due to alignment.

rdar://123695998
2024-02-28 10:49:42 -05:00
Mishal Shah
6c306e3d43 Update the SwiftStdlib version to 6.0 and fix Frontend/crash.swift test 2024-02-21 15:20:24 -08:00
Mishal Shah
b488702cc9 Merge remote-tracking branch 'origin/main' into bump-swift-version-to-6 2024-02-20 21:04:47 -08:00
Mishal Shah
af112c1591 Update the Swift version to 6.0 from 5.11 2024-02-19 17:47:16 -08:00
Michael Gottesman
f4efcec55c [transferring] Add mangling support for transferring.
This includes runtime support for instantiating transferring param/result in
function types. This is especially important since that is how we instantiate
function types like: typealias Fn = (transferring X) -> ().

rdar://123118061
2024-02-19 12:11:57 -08:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Mike Ash
f2a0dbb471 [Test] Temporarily disable genericMetadataBuilder.swift on ARM64e.
The validation is getting confused by ptrauth. Disable the test there while we fix it.

rdar://121029024
2024-01-16 10:33:37 -05:00
Mike Ash
f5b25776a0 [Test] Fix genericMetadataBuilder.swift requirements.
It requires executable_test and a just-built stdlib.

rdar://120908563
2024-01-12 12:38:39 -05: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
Doug Gregor
b9c5aca15f Enable SE-0413 "Typed Throws" by default 2024-01-02 15:34:07 -08: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
Alejandro Alonso
8ac7f0b10f Merge pull request #69138 from Azoy/generics-are-hard
[Runtime] Refactor _gatherWrittenGenericParameters
2023-11-06 19:27:54 -08:00
Alejandro Alonso
d73c812a2d Simplify _gatherWrittenGenericParameters 2023-11-06 12:51:06 -08:00
Alejandro Alonso
a0c8465f0c Refactor _gatherWrittenGenericParameters
Fix some bugs
2023-11-06 10:31:20 -08:00
Alastair Houghton
d84c47121a [Backtracing] Disable backtracer for Runtime/backtrace test.
The Runtime/backtrace test is a test of the fatalError() backtracer,
which gets turned off when we have the new backtracer enabled.  So,
to make this test work, we need to turn off the new backtracer.

rdar://117470489
2023-11-01 13:45:17 +00:00
Doug Gregor
1b42ca3673 Handle any Error and Never thrown error types during runtime uniquing.
When forming runtime metadata for a function type that has either `any
Error` or `Never` as the specified thrown error type, drop the thrown
error type and normalize down to (untyped) `throws` or non-throwing,
as appropriate.
2023-10-29 19:29:09 -07:00
Doug Gregor
40e07cf900 [Typed throws] IR generation and runtime support for function type metadata
Extend function type metadata with an entry for the thrown error type,
so that thrown error types are represented at runtime as well. Note
that this required the introduction of "extended" function type
flags into function type metadata, because we would have used the last
bit. Do so, and define one extended flag bit as representing typed
throws.

Add `swift_getExtendedFunctionTypeMetadata` to the runtime to build
function types that have the extended flags and a thrown error type.
Teach IR generation to call this function to form the metadata, when
appropriate.

Introduce all of the runtime mangling/demangling support needed for
thrown error types.
2023-10-29 09:12:32 -07:00