OpenSwiftUIProject / OpenSwiftUI

[WIP] Open source implementation of Apple's SwiftUI.
https://swiftpackageindex.com/OpenSwiftUIProject/OpenSwiftUI/main/documentation/openswiftui
MIT License
912 stars 27 forks source link

BodyAccessor crash for non empty View instance #81

Closed Kyle-Ye closed 4 months ago

Kyle-Ye commented 4 months ago

Add any property (>=1) to our ContentView in HostingExample and it will crash.

image
Kyle-Ye commented 4 months ago

Compare the crash stack between SwiftUI and OpenSwiftUI for AG::Graph::UpdateStack::update()

+0
...
+120
->
+156
...
+164
->
+416
->
+432
...
+440
->
+452
...
0x1ad4cd178 <+532>:  ldr    w8, [x27]
0x1ad4cd17c <+536>:  tbz    w8, #0x4, 0x1ad4cd3c8
; For SwiftUI, w8 = 0x00000673
0x1ad4cd17c <+536>:  tbz    w8, #0x4, 0x1ad4cd3c8
->
0x1ad4cd180 <+540>:  ldr    x8, [x22]
...

; For OpenSwiftUI, w8 = 0x00000663
0x1ad4cd17c <+536>:  tbz    w8, #0x4, 0x1ad4cd3c8
->
0x1ad4cd3c8 <+1124>: ldr    x1, [x23, #0x8]
0x1ad4cd3cc <+1128>: ldur   x9, [x1, #-0x8]
0x1ad4cd3d0 <+1132>: ldr    x9, [x9, #0x40]
0x1ad4cd3d4 <+1136>: cbnz   x9, 0x1ad4cd508
->
0x1ad4cd508 <+1444>: ldr    x9, [x19]
...
; precondition_failure

Using some background knowledge of OG/AG, we know +536 is checking attribute_info.has_value.

SwiftUI code can pass it as true while OpenSwiftUI will not.

Then it will check the VWT of the current view and will emit a precondition_failure if size is not zero.

I believe we should fix it by setting the value of the view/container attribute in advance at some point.