Commit Graph

31 Commits

Author SHA1 Message Date
Dario Rexin
c0c31c0613 [IRGen] Set minimum runtime availability version for CVW
rdar://139375022

CVW should not be generated when the deployment target does not have the necessary runtime functions.
2024-11-13 22:36:15 -08:00
Dario Rexin
3c7b556cf1 [IRGen+Runtime] Fix tag bit mask handling for objc, unknown objects and blocks
rdar://138487964

On platforms that don't have reserved bits in objc (including unknown) pointers, we use the spare bits for Swift enums, so they have to be masked out. Blocks don't have reserved bits on any platform.
2024-11-07 09:55:40 -08: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
Dario Rexin
edd9955673 [Runtime] Fix SwiftError handling in CVW runtime
rdar://138085348

Even though errors are ObjC boxes, they can't be tagged pointers and in fact may use that bit to store enum tags, so treating them like regular ObjC references here can cause ref count issues.
2024-10-23 17:31:11 -07:00
Dario Rexin
90a9ffdf02 [IRGen] Properly compute bit mask for extra tag bits in CVW
rdar://132501359

PowerOf2Ceil is not the correct function to use, because we end up with an empty mask if there is only one value stored in the extra tag bits
2024-07-26 14:50:54 -07:00
Dario Rexin
e3e06a79e4 [IRGen] Fix emitPrimitiveLoadPayloadAndExtraTag for CVW
rdar://129627898

When casting the projectedBits to Int8, we accidetnally passed the base addr instead of the projectedBits. This was causing the wrong bits to be read.
2024-07-16 10:35:01 -07:00
Dario Rexin
5dcd163c42 [IRGen] Always load extra tag bits as full bytes in CVW to avoid elemination of masking
rdar://129627898

LLVM expects integer types of fractional byte sizes to have been written as those types as well, so it expects all unused bytes to be 0.
Since we are using the unused extra tag bits to store tags of outer enums, that assumption does not hold here. In regular witnesses,
the outer enum would mask out those bytes before checking the tag of the inner enum. In CVW we can't do that, so we have to apply the
mask ourselves. To guarantee the mask does not get optimized out, we have to use full bytes instead of fractionals.
2024-07-03 12:32:07 -07: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
Dario Rexin
c1d732a9cb [IRGen] Fix alignment for imported C types in CVW
rdar://127279770

When an imported C type is over or under aligned, we did not use the alignment of the type, but computed the maximum alignment of its components, causing alignment issues in compact value witnesses.
2024-05-02 17:05:38 -07:00
Dario Rexin
09cd036d15 [IRGen] Fix size computation for imported C types in type layouts (#73271)
rdar://126954341

C types don't have separate size and stride, but in type layouts we always computed the size as if they did. This could cause wrong offsets in compact value witnesses
2024-04-25 19:58:14 -07:00
Dario Rexin
7a4fcc6841 [Runtime] Mask out reserved bits for SwiftError in BytecodeLayouts.cpp (#71669)
rdar://122911427

These bits can be used for storing multi payload enum tags and not masking them out can cause crashes an other unexpected behavior.
2024-02-16 08:59:22 -08:00
Dario Rexin
747cbfcc24 [IRGen] Mask extra tag bits in getEnumTag function for CVW (#71421)
rdar://121868127

In compact value witnesses we need to mask the extra tag bits in case they are used to store tag bits of outer enums, so we only read the ones we are interested in.
2024-02-07 08:58:07 -08:00
Dario Rexin
55e565d838 [Runtime] Handle different types for src and dest in existentialAssignWithCopy (#71323)
rdar://117083470

An existential can contain a different type than the one that is being assigned, so we have to check the types and handle the values accordingly.
2024-02-02 08:34:37 -08:00
Dario Rexin
011fce8212 [Runtime] Fix leak of bridge objects in swift_generic_initWithTake (#69977)
rdar://118606044

The initWithTakeTable accidentally referenced bridgeRetain instead of copyingInitWithTake, which caused a leak when an object containing a bridge reference was also not bitwise takable.
2023-11-27 08:04:10 -08:00
Dario Rexin
36f3367275 [Runtime] Use threaded code in compact value witness runtime (#69756)
* [Runtime] Use threaded code in compact value witness runtime

These changed reduce branching and yield performance improvements of up to 10% for some cases.

* Fix offset in handleRefCountsInitWithTake
2023-11-09 19:12:29 -08:00
Dario Rexin
40b8079018 [Runtime] Fix missing memcpy in handleSingleRefCountInitWithCopy
rdar://117755666

Missing memcpy in handleSingleRefCountInitWithCopy caused wrong enum cases, crashes etc.
2023-11-03 00:27:45 -07:00
Nate Chandler
2d2e68aa18 [Test] Mark 3 tests unsupported on use_os_stdlib.
These tests require an OS with Swift 5.9, and that can't be expressed as
a REQUIRES: line.

rdar://114564735
2023-08-29 17:21:01 -07:00
Dario Rexin
7e3f56de24 [Runtime] Fix generic existentials in layout strings 2023-08-21 10:57:33 -07:00
Dario Rexin
56048ac19f [Runtime+IRGen] Fix existential offset for multiple protocol witnesses 2023-08-21 10:57:06 -07:00
Dario Rexin
69c8ae6ff3 [IRGen] Fix extra inhabitant offset for simple single payload enums with layout strings 2023-07-19 16:03:52 -07:00
Dario Rexin
ca664141cc [IRGen+Runtime] Add support for initializeBufferWithCopyOfBuffer to layout strings (#66965) 2023-06-27 18:05:30 -07:00
Dario Rexin
874b577280 [IRGen] Use EnumImplStrategy to generate getEnumTag function for layo… (#66707)
* [IRGen] Use EnumImplStrategy to generate getEnumTag function for layout strings

rdar://110794898

The implementation in TypeLayout seems to have a bug causing wrong tags to be returned on 32 bit systems.

* Don't use unsupported types in tests
2023-06-16 18:14:48 -07:00
Dario Rexin
5cbf9f9641 [IRGen] Handle complex single payload enum cases (#66289)
* [IRGen] Handle complex single payload enum cases

rdar://110138498

Handles single payload enum cases with more complex bit patterns (e.g. >64 bits or scattered) by storing a relative pointer to a function that reads the tag.

* Use proper symbol for enum tag helper
2023-06-02 11:49:57 -07:00
Dario Rexin
e6fe6befe7 [IRGen] Include extra tag bytes in offset in layout strings (#66259)
rdar://110088270

When extra tag bytes are used in single payload enums, the generated layout string does not include the tag bytes in its offset after the enum payload. This causes subsequent ref count operations to use the wrong memory location.
2023-05-31 20:54:47 -07:00
Dario Rexin
97381e6411 [IRGen] Support additional single payload enum cases in layout strings (#66042)
* [IRGen] Support additional single payload enum cases in layout strings

rdar://105837101

Adds layout string support for single payload enums with simple (non-scattered) extra inhabitant patterns

* Add more test cases
2023-05-23 13:17:51 -07: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
Dario Rexin
883750e908 [IRGen] Reject enums with inaccessible tpye metadata in layout string… (#65016)
* [IRGen] Reject enums with inaccessible tpye metadata in layout string generation

rdar://107679697

Because we are currently handling most enums in layout strings by going through the metadata, we have to ensure that the metadata is accessible from the current module and reject the enum otherwise.

* Use proper mechanism to create and reference dylib in test

* Fix linking

* Add rpath to test dylib
2023-04-13 17:19:31 -07:00
Dario Rexin
38decb8ab3 [Test] Disable layout string tests on back deployment runtime (#64002)
rdar://106085766
2023-03-01 21:23:28 -08:00
Dario Rexin
a0e1810f62 [IRGen] Generate layout strings for subset of enums (#63930)
rdar://105959425
2023-02-27 07:33:34 -08: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