Commit Graph

604 Commits

Author SHA1 Message Date
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
Doug Gregor
e82854d860 Reimplement TargetFunctionTypeMetadata using TrailingObjects
The layout is the same, but this eliminates the handwritten address
computations.
2023-10-29 09:12:32 -07:00
Tony Allevato
5f5b24f96e [C++20] Make operator{==,!=}s const.
In C++20, the compiler will synthesize a version of the operator
with its arguments reversed to ease commutativity. This reversed
version is ambiguous with the hand-written operator when the
argument is const but `this` isn't.
2023-10-03 17:10:57 -04:00
Mike Ash
e2b4d2f465 [Runtime] Fix lazy ivar list copying.
The `ivar` reference still pointed to the original list, so the first modification went to the wrong place. Change `ivar` to a pointer, and re-point it when we copy the list.

rdar://116339597
2023-10-02 16:06:01 -04:00
Mike Ash
641870a205 [Runtime] Lazily copy ivar list in initObjCClass.
There's often nothing that needs to be fixed up in the ivar list. In that case, we can avoid copying it. This saves time and memory, and allows the class rodata to be in immutable memory.

rdar://116189946
2023-09-28 14:19:04 -04:00
Dario Rexin
75f6103898 [IRGen+Runtime] Remove unnecessary null terminator in layout strings
The last offset also signals the end of the layout string, so the null terminator is unnecessary
2023-09-21 10:46:19 -07:00
Alejandro Alonso
ab143ee3ee Some fixes for raw layout types and noncopyable types in the stdlib 2023-09-11 20:45:09 -07:00
Evan Wilde
176bf3417e Merge pull request #65076 from etcwilde/ewilde/metadata-cleanup
Replace mismatched `delete` with `swift_cxx_deleteObject`
2023-09-01 20:31:29 -07:00
Dario Rexin
fd967fd9e3 [Runtime] Properly handle boxed references in layout string instantiation 2023-08-21 10:58:25 -07:00
Dario Rexin
7e3f56de24 [Runtime] Fix generic existentials in layout strings 2023-08-21 10:57:33 -07:00
Dario Rexin
8ab845fdca [Runtime+IRGen] Fix offsets of existentials in layout strings 2023-08-21 10:55:51 -07:00
Dario Rexin
30d628270b [IRGen+Runtime] Make more fine grained copies in layout string runtime functions 2023-08-21 10:55:02 -07:00
Dario Rexin
4a395cb8d3 [Runtime+IRGen] Some fixes and optimizations for layout strings 2023-08-21 10:53:44 -07:00
Alejandro Alonso
44198d16a4 Merge pull request #67611 from Azoy/raw-types-are-cool!
[WIP] Implement dependent layouts for raw types
2023-08-16 06:55:42 -07:00
Alejandro Alonso
c20ab10cef Use an i32 argument instead of size
more int32

zzz
2023-08-15 19:49:44 -07:00
Mike Ash
dbd2f82739 [Runtime] Fix up the heap destroyer in objc_setClassCopyFixupHandler.
We fix up the VWT pointer, but not the heap destroyer. This doesn't matter for classes which use ObjC refcounting, which is the common case for dynamic subclasses, because that doesn't use the heap destroyer pointer. But it does matter for classes that use native Swift refcounting, such as classes that don't inherit from NSObject, or actors.

rdar://113657917
2023-08-10 15:19:18 -04:00
Alejandro Alonso
df17f7be90 Implement dependent layouts for raw types
Update raw_layout.swift

Allow for concrete specializations of raw layout

Make test platform agnostic
2023-08-01 14:09:23 -07:00
Dario Rexin
f257b3bbab [Runtime] Fix _swift_refCountBytesForMetatype for reference types
_swift_addRefCountStringForMetatype and _swift_refCountBytesForMetatype diverged in the code that determines whether a type is a reference, causing the size number of ref count bytes to differ from the actually used bytes. This can cause early termination of the runtime interpreter functions, which in turn causes unbalanced reference counts.

rdar://112474091
2023-07-28 11:55:53 -07:00
Dario Rexin
620d516fe7 [Runtime] Fix MultiPayloadEnumFN case in swift_resolve_resilientAccessors
rdar://112825968

Offsets were wrong, causing invalid memory accesses
2023-07-25 13:50:17 -07:00
Dario Rexin
10685367ce [Runtime] Use the properly resolved tag when adding offset after resolving relative pointers in layout strings
The tag was overwritten after resolve when a prior field caused a non-zero offset. This then caused the runtime to treat is a relative instead of an absolute pointer, causing invalid pointers to be dereferenced.
2023-07-24 09:36:26 -07:00
Slava Pestov
da145aa43a Runtime: Relax prohibition on packs in SubstGenericParameterFn implementations 2023-07-05 16:35:16 -04:00
Dario Rexin
fd369cd050 [Runtime] Refactor layout string code (#66831)
Made the code a bit more readable by adding a reader and writer type that encapsulate
the layout string and offset.
2023-06-21 19:46:22 -07:00
Slava Pestov
3676379302 Merge pull request #66814 from slavapestov/variadic-type-conditional-conformance
Conditional conformances for variadic generic types
2023-06-21 17:52:28 -04:00
Slava Pestov
d1cb9307c9 Runtime: Support for conditional conformances with pack conformance requirements 2023-06-21 13:42:57 -04:00
Dario Rexin
493a25faae [IRGen+Runtime] Add layout string support for generic single payload enums (#66791) 2023-06-20 20:46:54 -07:00
Dario Rexin
d74c085fe8 [Runtime+IRGen] Add layout string support for generic singleton enums (#66647) 2023-06-14 20:13:15 -07:00
Saleem Abdulrasool
df71ee08ba Merge pull request #66524 from hjyamauchi/dump-generic-metadata
Fix the swift-inspect dump-generic-metadata operation.
2023-06-14 14:48:07 -07:00
Dario Rexin
58ff42af16 [Runtime] Properly handle tuple types in layout string instantiation (#66603)
Tuple types contain metadata entries for each element, so we can handle them individually to avoid unnecessary indirection.
2023-06-13 13:48:05 -07:00
Hiroshi Yamauchi
50ef384f88 Fix the swift-inspect dump-generic-metadata operation.
ReflectionContext::allocationMetadataPointer() was reading the
metadata pointer from a wrong offset because of the out-of-sync struct
layouts and dump-generic-metadata was not working correctly.

This change resync's the layouts and adds a static_assert to verify
that the offsets match between GenericMetadataCacheEntry and
GenericCacheEntry.
2023-06-09 18:33:06 -07:00
Dario Rexin
fe6f8f5404 [IRGen] Implement support for multi payload enums in layout strings (#66354)
* [IRGen] Implement support for multi payload enums in layout strings

rdar://105837114

* Implement multi payload enum cases in swift_resolve_resilientAccessors

* Add missing const
2023-06-06 23:51:57 -07:00
Dario Rexin
ca004c2316 [Runtime] Fix UB in layout string runtime functions (#66112)
rdar://109790722

Layout strings are not guaranteed to be properly aligned, so we can't directly read from and write to it, but have to use memcpy instead.
2023-05-25 08:33:53 -07:00
Dario Rexin
cae740d902 [Runtime] Use MetadataAllocator to allocate runtime instantiated layout strings (#66055)
rdar://109660582

This will create more visibility into layout string allocations when using swift-inspect.
2023-05-22 12:55:09 -07:00
Alastair Houghton
2e36235451 Merge pull request #65140 from al45tair/eng/PR-107718586
[Runtime] Ensure we *always* generate names for ObjC classes.
2023-04-27 13:53:46 +01:00
Dario Rexin
022311e438 [IRGen] Fix layout string generation for pre-specialized metadata (#65162)
* [IRGen] Fix layout string generation for pre-specialized metadata

rdar://108012057

Pre-specialized metadata has to be specifically handled by using the bound generic type instead of the unbound one. All the necessary information is already being passed down as BoundGenericTypeCharacteristics, we just need to apply them when present.

* Add tests and a few fixes

* Fixes after rebase

* Attempt to fix Windows linker issue in test
2023-04-20 13:26:41 -07:00
Alastair Houghton
2f6baac55e [Runtime] Ensure we *always* generate names for ObjC classes.
If something fails while trying to generate a name for an ObjC class,
we fall back to a generated name based on the metadata pointer.  This
ensures that we won't crash, and if the name turns up in the debugger
or somewhere it should be obvious that something went wrong.

rdar://107718586
2023-04-13 15:34:03 +01:00
Evan Wilde
f47d56336e Replace mismatched delete with swift_cxx_deleteObject
The `allocatedEntry` is allocated with `swift_cxx_newObject` so it
should be deallocated with the `swift_cxx_deleteObject`.
2023-04-11 14:15:24 -07:00
Konrad `ktoso` Malawski
0586c14b60 [Concurrency] SerialExecutor.isSameExclusiveExecutionContext (#64604) 2023-03-28 15:56:28 +09:00
Slava Pestov
5f0d7320df Runtime: Fix MetadataCacheKey::installInto() for variadic generics 2023-03-22 16:53:25 -04:00
Dario Rexin
2f8c1a402c [IRGen] Make pointers to accessor functions in layout strings relative (#64155)
* [IRGen] Make pointers to accessor functions in layout strings relative

rdar://106319336

Pointers embedded in static layout strings should always be relative, so layout strings can reside in read-only memory.

* Properly handle reference storage ownership

* Pass layout tag and metadata / type layout ppointers separately

* Layout string instantiation fully working

* Fix cases where hasLayoutString flag was not set when it should have

* Update include/swift/ABI/Metadata.h
2023-03-17 09:02:51 -07:00
Kuba (Brecka) Mracek
78a406a75d In Metadata.h/.cpp, start building the relative wtable support even on platforms that don't use it yet (#64354) 2023-03-15 09:41:40 -07:00
Arnold Schwaighofer
7afab4735d Runtime: Fix swift_getAssociatedTypeWitnessRelativeSlowImpl for MetadataOrPack change 2023-03-14 07:58:12 -07:00
Mike Ash
1dfd1ede9e Merge pull request #64327 from mikeash/fewer-news
[Runtime] Remove a few uses of operator new/delete.
2023-03-14 08:57:44 -04:00
Joe Groff
730c5cf632 Merge pull request #64295 from jckarter/noncopyable-hide-field-types
Don't let reflection handle noncopyable types yet.
2023-03-13 17:01:25 -07:00
Mike Ash
69d0905e80 [Runtime] Remove a few uses of operator new/delete.
Replace them with swift_cxx_newObject/swift_cxx_deleteObject to avoid calling overridden global operators. Overridden global operators can sometimes fail when called from places the authors didn't expect.

The particular uses being changed here are:

1. Creation of new SingletonMetadataCacheEntry objects.
2. Allocation of the _globalIvarOffsets array in initGenericObjCClass.
3. Creation/destruction of SwiftTLSContext objects.

rdar://106238547
2023-03-13 16:05:37 -04:00
Joe Groff
4d6d7657fa Don't let reflection handle noncopyable types yet.
We don't have any language or runtime support for noncopyable types as generic
or dynamic types yet, and existing reflection code almost certainly assumes it
can copy the values it's working with, and will trap or corrupt state if it does
so with noncopyable types. But a class can have noncopyable fields while the
type itself is copyable, and existing code assumes that it can use `Mirror` or
other reflection mechanisms to safely traverse the contents of an arbitrary
class.

Allow this sort of code to continue working, while still preparing for forward
compatibility with future runtimes that do support noncopyable generics, by
emitting the type references for fields using a function that probes the
address of a new symbol in the Swift runtime. The symbol will either be missing
or defined with an absolute address of zero in current or previous runtime
versions, but can be changed to a non-null address in the future.
2023-03-13 11:50:24 -07: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
8731eb4394 Runtime: On-heap packs know their own length 2023-03-09 01:54:51 -05:00
Slava Pestov
e7ef0d3a97 Runtime: Also unique witness table packs
While we can't assume that pointer equality implies semantic equality
with witness table packs, it still makes sense to unique their storage
opportunistically.
2023-03-08 14:37:17 -05:00
Slava Pestov
5a52fdba10 Runtime: Fix SWIFT_STDLIB_USE_RELATIVE_PROTOCOL_WITNESS_TABLES build
Fixes rdar://106433355.
2023-03-08 14:10:34 -05:00
Dario Rexin
5fe716577b [IRGen] Add layout strings for generic and resilient types (#64023)
* [IRGen] Add layout strings for generic and resilient types

rdar://105837048

* Add some corner cases

* Add flag to enable generic instantiation and some fixes

* Fix resilient types

* Fix metadata accessor function pointers in combined layout strings
2023-03-05 15:26:45 -08:00