Commit Graph

381 Commits

Author SHA1 Message Date
Mike Ash
2d238bcea5 Merge pull request #67168 from mikeash/ptrauth-struct-context-descriptors
[Runtime][IRGen] Sign type context descriptor pointers.
2023-07-11 17:03:53 -04:00
Mike Ash
fe7e13bba5 [Runtime][IRGen] Sign type context descriptor pointers.
Ensure that context descriptor pointers are signed in the runtime by putting the ptrauth_struct attribute on the types.

We use the new __builtin_ptrauth_struct_key/disc to conditionally apply ptrauth_struct to TrailingObjects based on the signing of the base type, so that pointers to TrailingObjects get signed when used with a context descriptor pointer.

We add new runtime entrypoints that take signed pointers where appropriate, and have the compiler emit calls to the new entrypoints when targeting a sufficiently new OS.

rdar://111480914
2023-07-07 18:10:35 -04:00
Slava Pestov
b471cd308f TypeDecoder: Don't demangle freestanding PackExpansionTypes 2023-07-05 16:35:17 -04:00
Slava Pestov
da145aa43a Runtime: Relax prohibition on packs in SubstGenericParameterFn implementations 2023-07-05 16:35:16 -04:00
Slava Pestov
f40a447980 TypeDecoder: Implement lane-wise pack expansion 2023-07-05 16:35:16 -04:00
Slava Pestov
338cb7ccb9 TypeDecoder: Change createTupleType() to take labels as ArrayRef<StringRef> instead of std::string 2023-07-05 16:33:43 -04:00
Mike Ash
516c21a790 [Runtime] Fast-path lookup of protocol descriptors with standard manglings.
We weren't taking advantage of standard manglings in _findProtocolDescriptor like wo do in _findContextDescriptor. Extract out the "standard mangling" code and call it from both to speed up those searches.

rdar://111235115
2023-06-27 14:15:15 -04:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Slava Pestov
3052e36f7e Runtime: Fix dynamic casts of variadic types that conditionally conform 2023-06-21 13:42:57 -04:00
Slava Pestov
d1cb9307c9 Runtime: Support for conditional conformances with pack conformance requirements 2023-06-21 13:42:57 -04:00
Mike Ash
110f428780 [Runtime] Add tracing for section scans.
Section scans (for metadata, protocols, etc.) can be costly. This change adds tracing calls to those scans so we can more easily see how much time is spent in these scans and where they're initiated.

This adds an os_signpost implementation controlled by SWIFT_STDLIB_TRACING, and a default empty implementation for when that's disabled.

rdar://110266743
2023-06-14 12:07:44 -04:00
Mike Ash
8f9a4cbdae Merge pull request #66109 from mikeash/dont-scan-objc-classes
[Runtime] Skip metadata records search for classes in the __C module.
2023-05-25 11:15:14 -04:00
Mike Ash
f9599ddcb1 [Runtime] Skip metadata records search for classes in the __C module.
ObjC classes won't be found, so don't spend lots of time searching for them.

rdar://109783948
2023-05-24 16:23:51 -04:00
Mike Ash
dfd313cd6c [Runtime] Fast lookups of Concurrency types with standard manglings.
Have the Concurrency runtime register a struct containing pointers to all of its type descriptors with standard manglings. Then have the runtime use that struct to quickly look up those types, instead of using the standard, slower type lookup code.

rdar://109783861
2023-05-24 16:08:23 -04:00
Slava Pestov
f12be70da5 Runtime: Demangling DependentMemberType whose base type is a pack type 2023-03-17 22:19:18 -04:00
Slava Pestov
d776f71b4f Runtime: Teach checkGenericRequirements() to check same-shape and conformance pack requirements 2023-03-09 09:42:00 -05:00
Slava Pestov
17086962c3 Runtime: Add swift_getTypePackByMangledName() entry point
For now this has SWIFT_RUNTIME_LIBRARY_VISIBILITY, but in the
future we might want to make it public so that IRGen can use it
to build packs out of concrete types.
2023-03-09 01:54:51 -05:00
Slava Pestov
cdd1c6da57 Runtime: Move MetadataOrPack to Private.h 2023-03-09 01:54:51 -05:00
Slava Pestov
2b68ee1065 Runtime: Teach _gatherWrittenGenericArgs() about metadata packs 2023-03-09 01:54:51 -05:00
Slava Pestov
bcf6f26579 Runtime: Make SubstGenericParametersFromWrittenArgs and _gatherWrittenGenericArgs() completely private to MetadataLoookup.cpp 2023-03-09 01:54:51 -05:00
Slava Pestov
39aa4d4001 Runtime: Preliminary refactoring for demangling variadic generic types to metadata 2023-03-09 01:54:51 -05:00
Slava Pestov
affd1bf8fd AST: Fold RequirementBase into it's three subclasses
It's a very simple algebraic data type, and factoring it out into
a template doesn't carry its weight.
2023-03-09 01:54:51 -05:00
Slava Pestov
8731eb4394 Runtime: On-heap packs know their own length 2023-03-09 01:54:51 -05:00
Slava Pestov
1fe96205b1 Runtime: Put DecodedMetadataBuilder in anonymous namespace 2023-03-08 14:42:37 -05:00
Slava Pestov
b3cb845ea3 Runtime: support metadata packs in _buildDemanglingForNominalType()
This adds a bunch of new code but once I finish refactoring the other
demangling stuff, I should be able to remove

- gatherWrittenGenericArgs()
- _gatherGenericParameters()
- SubstGenericParametersFromWrittenArgs
2023-03-03 14:16:53 -05:00
Slava Pestov
32caa17b11 Runtime: Finish removing the 'extra argument' notion 2023-03-03 02:21:08 -05:00
Slava Pestov
d8f7959adf ASTDemangler: Support PackType, SILPackType, and PackExpansionType
Also stub out the corresponding entry points in the runtime's
MetadataBuilder and the Remote Mirrors TypeRefBuilder.
2023-02-21 15:33:19 -05:00
Arnold Schwaighofer
770648f161 Initial runtime changes to support relative protocol witness tables 2023-01-31 10:59:37 -08:00
Mike Ash
df48847c4a Merge pull request #62997 from mikeash/null-symbolic-reference-fatal-error
[Runtime] Fatal error when resolving a symbolic reference to NULL.
2023-01-13 09:14:14 -05:00
Alastair Houghton
6ca5716ef4 Merge pull request #62879 from al45tair/eng/PR-103950409
[Runtime] Make the swift_getTypeByMangled... functions emit error messages.
2023-01-12 20:32:41 +00:00
Mike Ash
7b33d2c0af [Runtime] Fatal error when resolving a symbolic reference to NULL.
We crash in ResolveAsSymbolicReference::operator() when a symbolic reference targets a missing symbol. We usually have very little information about what was missing when this happens. Instead of crashing, explicitly check for NULL and fatal error in that case, including information about the location of the symbolic reference that it came from.
2023-01-12 11:46:57 -05:00
Alejandro Alonso
382510fa50 Rename Reflection library to RemoteInspection (#62846) 2023-01-06 13:21:32 -05:00
Alastair Houghton
f0200bc0d8 Conditionalise the warnings on an environment variable.
We'll only generate warnings if SWIFT_DEBUG_FAILED_TYPE_LOOKUP is
enabled.

rdar://103950409
2023-01-06 14:42:27 +00:00
Alastair Houghton
d9db40d356 Make the swift_getTypeByMangled... functions emit error messages.
When type lookups fail, these functions should at least generate a warning.

rdar://103950409
2023-01-06 13:04:38 +00:00
Arnold Schwaighofer
1e82ef8df7 Fix dynamic replacement of weakly linked symbols
If the replaced symbol goes away in the original library, the
replacement key in the replacement descriptor will be null. Handle this
by ignoring the replacement entry rather than crashing.

rdar://103307821
2022-12-15 13:19:34 -08:00
Jonathan Grynspan
c889270a38 Remove lookupSymbol() and have all callers use SymbolInfo::lookup() instead (#62552) 2022-12-14 08:33:32 -05:00
Jonathan Grynspan
26fc627ad0 Fix a use-after-free bug on Win32 when calling lookupSymbol() (#62484) 2022-12-13 09:04:34 -05:00
John McCall
caa57f5f0d Fix extended existential symbolic demangling on arm64e.
Fixes rdar://96367576 and rdar://96367737.
2022-07-05 18:18:11 -04:00
Kuba (Brecka) Mracek
f13a5213c8 Explicitly #include <cctype> to avoid relying on isdigit being available through unrelated headers (#59745) 2022-07-05 17:30:12 +02:00
John McCall
175f74d38f Implement symbolic demangling for extended existential metadata
Fixes rdar://96268090.
2022-07-01 11:21:53 -04:00
John McCall
396121c231 Fix the build on 32-bit targets. 2022-07-01 11:21:53 -04:00
Robert Widmann
dde0d8f609 Generalize the Mangling of Constrained Existential Types
Upgrade the old mangling from a list of argument types to a
list of requiremnets. For now, only same-type requirements
may actually be mangled since those are all that are available
to the surface language.

Reconstruction of existential types now consists of demangling (a list of)
base protocol(s), decoding the constraints, and converting the same-type
constraints back into a list of arguments.

rdar://96088707
2022-06-30 15:32:37 -07:00
Robert Widmann
9e4670a605 Implement Casting For Extended Existentials
Implement casting to and from extended existentials. This is done by slightly generalizing the conditional conformances checking infrastructure.

Unfortunately, casts for reference types and metatypes are unsound because IRGen is peepholing all non-opaque existential conversions with a helper. I’ll disable that in a follow-up.

rdar://92197049
2022-06-15 21:35:15 -06:00
Robert Widmann
14edd57e3e Generalize Metadata Lookup for Shapes 2022-06-15 18:19:33 -06:00
Alastair Houghton
0e9318cec5 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
f5bdb858e0 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alex Hoppen
4aa2bbbf06 Revert "Merge pull request #42447 from al45tair/eng/PR-90776105"
This reverts commit 8bcb71140f, reversing
changes made to c4dd271d36.
2022-06-02 18:03:23 +02:00
Alastair Houghton
8bcb71140f Merge pull request #42447 from al45tair/eng/PR-90776105
[Build][Runtime] Add a new threading library.
2022-06-01 12:57:23 -07:00
Mike Ash
8f072d1c29 [Runtime] Don't try to demangle unprefixed untrusted names. Remove operator new/delete hackery.
The operator new/delete overrides aren't working out due to inconsistent inlining of std::string creation/deletion. We can end up creating one with the global new but destroying it with our local delete. If they aren't compatible, this crashes.

Instead, avoid problematic new/delete activity coming from lookup of ObjC class names. Names passed to getObjCClassByMangledName must either have a standard mangled name prefix, start with a digit (for unprefixed mangled names) or use the convenience dot syntax. Check for those up front and immediately reject anything else. This has the added bonus of failing more quickly for non-Swift names.

rdar://93863030
2022-05-25 22:40:33 -04:00