Commit Graph

65 Commits

Author SHA1 Message Date
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
Dario Rexin
4e7ce5a058 [IRGen+Runtime] Differentiate between pure Swift and regular ObjC references in CVW
rdar://139106139

Regular ObjC references do not have unused bits or extra inhabitants for storing enum tags, because they may be tagged pointers. However, ObjC classes that are implemented in Swift do, so we must differentiate between the two.
2024-11-04 18:52:26 -08: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
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
b97fbac9a6 [Runtime] Fix CVW for genreic single payload enums with no extra inha… (#73186)
* [Runtime] Fix CVW for genreic single payload enums with no extra inhabitants

rdar://126728925

When the payload of a generic SPE did not have any extra inhabitants, we erroneously always treated it as the no payload case.
Additionally the offset and skip values were improperly computed.

* Fixed FileCheck string
2024-04-22 22:56:57 -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
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
Allan Shortlidge
333b7b6a46 NFC: Resolve unused variable warnings in BytecodeLayouts.cpp. 2024-01-12 17:39:00 -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
Dario Rexin
0c36e44f2e [Runtime] Cleanup function names in BytecodeLayouts.cpp 2023-10-13 10:22:02 -07:00
Dario Rexin
56d0975668 [Runtime] Add layout string handling in swift_arrayAssignWithCopyFrontToBack
By using a specialize function, we only call through the witness table and fetch the layout string once for the whoe buffer, instead of once per element.
2023-09-21 09:52:46 -07:00
Dario Rexin
ee28da2bf2 [Runtime] Use handleRefCountsAssignWithCopy in swift_generic_assignWithCopy
rdar://114840977

This was accidentally committed after debugging an issue
2023-09-01 14:53:52 -07:00
Dario Rexin
6e3d1ae726 [Runtime] Check if objc pointers are tagged before masking
In layout string value witnesses runtime functions, if an objc pointer is tagged, there is no ref counting necessary.
2023-08-30 18:50:38 -07:00
Dario Rexin
8fe4c77b3e [Runtime] Properly mask pointers before ref counting and other fixes
The fixes are all around enum support. Some tag comparisons and pointer masking were incorrect and led to crashes.

rdar://114575149
2023-08-30 17:54:47 -07:00
Dario Rexin
e3a1bac859 [Runtime] Use copy of addrOffset in single payload assign with copy 2023-08-24 11:01:14 -07:00
Dario Rexin
21f4064380 [Runtime] Fix singlePayloadEnumSimpleAssignWithCopy 2023-08-21 10:59:15 -07:00
Dario Rexin
56048ac19f [Runtime+IRGen] Fix existential offset for multiple protocol witnesses 2023-08-21 10:57:06 -07:00
Dario Rexin
8b3aaf5423 [Runtime] Compute end before looping over single payload ref count 2023-08-21 10:56:42 -07:00
Dario Rexin
7c0203dd55 [Runtime] Combine copy and destroy in assignWithCopy 2023-08-21 10:56:19 -07:00
Dario Rexin
8ab845fdca [Runtime+IRGen] Fix offsets of existentials in layout strings 2023-08-21 10:55:51 -07:00
Dario Rexin
4f6e69b35f [Runtime] Reduce instruction count in simple layout string operations 2023-08-21 10:55:25 -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
27b1764d13 [Runtime+IRGen] Fix layout string flag in type layout and add array functions 2023-08-21 10:54:35 -07:00
Dario Rexin
31de67c713 [IRGen+Runtime] Further fixes for layout strings 2023-08-21 10:54:14 -07:00
Dario Rexin
4a395cb8d3 [Runtime+IRGen] Some fixes and optimizations for layout strings 2023-08-21 10:53:44 -07:00
Dario Rexin
2f61e2a9c9 [Runtime] Further abstract shared functionality in BytecodeLayouts 2023-08-21 10:53:14 -07:00
Dario Rexin
ec3a2dc370 [Runtime] Templatize shared functionality in BytecodeLayouts 2023-08-21 10:52:39 -07:00
Dario Rexin
c25b3b43a2 [Runtime] Restructure BytecodeLayouts 2023-08-21 10:52:24 -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
6fb232510b [Runtime] Fix SinglePayloadEnumSimple read offset in swift_resolve_resilientAccessors
The offset was off by 1, causing subsequent tags to not be resolved properly.
2023-07-24 09:47:42 -07:00
Dario Rexin
b3cdcda6c7 Merge pull request #67173 from drexin/wip-singleton-inject
Support destructiveInjectEnumTag in singleton enums with layout strings
2023-07-06 19:33:05 -07:00
Dario Rexin
de177dc2ec [Runtime] Add destructiveEnumInject support for singleton enums with layout strings 2023-07-06 15:46:59 -07:00
Dario Rexin
81153489f6 [Runtime] Add destructiveEnumInject support for simple single payload enums in layout strings 2023-07-06 15:23:38 -07:00
Dario Rexin
fd4ef74266 Merge pull request #67067 from drexin/wip-refactor-simple-enum-tag
[Runtime] Abstract handling of simple single payload enum handling
2023-06-30 17:03:02 -07:00
Dario Rexin
13930c9347 [Runtime] Abstract handling of simple single payload enum handling
We can re-use some of this in destructiveInjectEnumTag, so adding the abstraction in preparation of that.
2023-06-30 13:51:47 -07:00
Dario Rexin
e2b8366fdb [Runtime] Remove incorrect skip in handleSinglePayloadEnumGenericTag 2023-06-30 13:05:32 -07:00
Dario Rexin
8114ecc3e0 [Runtime] Add destructiveInjectEnumTag support for generic multi payload enums with layout strings 2023-06-29 16:34:10 -07:00
Dario Rexin
89d37da9ee [Runtime] Add destructiveInjectEnumTag support for generic single payload enums with layout strings 2023-06-29 10:37:51 -07:00
Dario Rexin
964a51f4e9 [Runtime] Abstract tag handling for generic single payload enums (#67002)
* [Runtime] Abstract tag handling for generic single payload enums

This functionality will be shared across multiple functions, so adding the abstraction in preparation of that.

* Update BytecodeLayouts.cpp
2023-06-28 22:13:58 -07:00
Dario Rexin
8733969222 [Runtime] Fix sign-compare warning in BytecodeLayouts (#67001) 2023-06-28 19:14:37 -07:00
Dario Rexin
3524945cd4 [IRGen+Runtime] Implement getEnumTag for singleton enums in layout strings (#66985) 2023-06-28 14:25:34 -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
fc6834daf6 [IRGen+Runtime] Add getEnumTag for layout strings on simple single payload enums (#66941) 2023-06-26 19:32:51 -07:00
Dario Rexin
253d8fbf33 [IRGen+Runtime] Add getEnumTag for layout strings on generic single payload enum (#66911) 2023-06-23 20:43:28 -07:00
Dario Rexin
270089f297 [IRGen+Runtime] Layout string getEnumTag for fixed size enums subset (#66899)
* [IRGen+Runtime] Layout string getEnumTag for fixed size enums subset

getEnumTag impl for layout strings of fixed sized enums that use a function to fetch the enum tag

* Fix potential UB in IRGen
2023-06-23 18:10:55 -07:00
Dario Rexin
36ddb77fcd [IRGen+Runtime] Layout string getEnumTag for generic multi payload enums (#66872)
We already store all necessary information to extract the tag in the layout string, so we should utilize it for the getEnumTag witness
2023-06-22 19:07:50 -07:00
Dario Rexin
37220ed37f [Runtime] Handle generic multi payload enums in resilient resolve (#66848)
* [Runtime] Handle generic multi payload enums in resilient resolve

* Update BytecodeLayouts.cpp

* Update BytecodeLayouts.cpp
2023-06-22 12:02:46 -07:00
Dario Rexin
806fd1b58b [Runtime] Handle generic single payload enums in resilient resolve (#66849) 2023-06-22 10:53:55 -07:00