Commit Graph

588 Commits

Author SHA1 Message Date
Alejandro Alonso
c20ab10cef Use an i32 argument instead of size
more int32

zzz
2023-08-15 19:49:44 -07: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
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
Slava Pestov
66ed09e72b Runtime: Variadic generic type fixes 2023-03-03 02:24:01 -05:00
Slava Pestov
32caa17b11 Runtime: Finish removing the 'extra argument' notion 2023-03-03 02:21:08 -05:00
Slava Pestov
01acda7730 Runtime: Remove linear order on metadata cache keys 2023-03-02 10:22:11 -05:00
Slava Pestov
d764167783 Runtime: Fix Windows build 2023-02-28 02:12:32 -05:00
Slava Pestov
560aad797e Runtime: Wrap pack pointers in a fancy TargetPackPointer template instead of twiddling the LSB by hand
This is more type safe in theory, but in practice it's just catnip for C++ fans.
2023-02-28 02:12:32 -05:00
Slava Pestov
5663910827 Runtime: Add swift_allocateMetadataPack() and swift_allocateWitnessTablePack()
Both return the pack immediately if its already heap allocated, by
checking the least significant bit of the pack pointer.

Then,

- swift_allocateMetadataPack() uniques the metadata pack by the
  pointer equality of elements.

- swift_allocateWitnessTablePack() does not unique the pack.

Both return a pack pointer with the least significant bit set,
indicating heap allocation.
2023-02-28 02:12:32 -05:00
Dario Rexin
96d988a431 [Runtime] Move bytecode layout handling into runtime (#63901)
rdar://105904548
2023-02-25 10:18:45 -08:00
Dario Rexin
a8d4d57f11 [IRGen] Generate compressed representation of value witnesses (#63813)
rdar://105837040

* WIP: Store layout string in type metadata

* WIP: More cases working

* WIP: Layout strings almost working

* Add layout string pointer to struct metadata

* Fetch bytecode layout strings from metadata in runtime

* More efficient bytecode layout

* Add support for interpreted generics in layout strings

* Layout string instantiation, take and more

* Remove duplicate information from layout strings

* Include size of previous object in next objects offset to reduce number of increments at runtime

* Add support for existentials

* Build type layout strings with StructBuilder to support target sizes and metadata pointers

* Add support for resilient types

* Properly cache layout strings in compiler

* Generic resilient types working

* Non-generic resilient types working

* Instantiate resilient type in layout when possible

* Fix a few issues around alignment and signing

* Disable generics, fix static alignment

* Fix MultiPayloadEnum size when no extra tag is necessary

* Fixes after rebase

* Cleanup

* Fix most tests

* Fix objcImplementattion and non-Darwin builds

* Fix BytecodeLayouts on non-Darwin

* Fix Linux build

* Fix sizes in linux tests

* Sign layout string pointers

* Use nullptr instead of debug value
2023-02-24 15:40:28 -08:00
Arnold Schwaighofer
1fa68ff82b Sign relative protocol witness tables
rdar://98583748
2023-02-20 12:29:13 -08:00
Arnold Schwaighofer
9e2308295d runtime: conditionally generate relative protocol witness tables entry points 2023-02-03 08:54:58 -08:00
Arnold Schwaighofer
0f9bfac94b Remove undefined behavior in RelativeWitnessTable::getDescription() 2023-02-02 07:02:21 -08:00
Arnold Schwaighofer
770648f161 Initial runtime changes to support relative protocol witness tables 2023-01-31 10:59:37 -08:00
Erik Eckstein
77fd3a7004 runtime: fix a wrong fall-through caused by an assert(false)
Replace the `assert(false)` with `swift_unreachable`.
This is more robust in release builds where the `assert(false)` is a no-op and would result in a wrong fall-though to the next switch case.
Fixes a warning in release builds.
2022-11-14 20:40:56 +01:00
Anthony Latsis
c731089068 Gardening: Migrate stdlib sources to GH issues 2022-09-26 06:30:49 +03:00
Anton Korobeynikov
c89e270b7d Implement value witness table for @differentiable functions (#60875)
@differentiable function is actually a triple (function, jvp, vjp). Previously normal thick function value witness table was used. As a result, for example,  only function was copied, but none of differential components.

This was the cause of uninitialized memory accesses and subsequent segfaults.

Should fix now unavailable TF-1122
2022-09-01 03:09:39 -07:00
Mike Ash
91b86912e6 [Runtime] Fix rare crash when fixing up dynamic subclasses.
Swift vtables can contain NULL entries. This happens when the compiler is able to prove that a method is never called.

When ptrauth is enabled, those NULL entries are still signed. However, there's an inconsistency in the runtime. Most places where we copy a vtable with swift_ptrauth_copy_code_or_data, we accept an unsigned NULL value. But when fixing up a dynamic ObjC subclass with swift_objc_classCopyFixupHandler, we don't.

Since the compiler seems to always sign these NULL values, this still works, except in the case where a signed NULL value coincidentally has a ptrauth signature of all zeroes. When that happens, the code to accept an unsigned NULL value sees this NULL with an all-zero signature as an unsigned NULL, and copies it verbatim. Then we really do have an unsigned NULL in the destination.

If that class is then dynamically subclassed, we'll call swift_objc_classCopyFixupHandler which does not accept unsigned NULL values, and fail ptrauth.

Adjust swift_objc_classCopyFixupHandler to accept unsigned NULL like the rest. These entries should never be called, and any attempt to call them will crash regardless, so it makes little difference.

rdar://92800322
2022-07-25 22:38:55 -04:00