[XL] Change in dart/sdk[main]: [vm/service]: Add _getFfiStructLayout RPC for FFI struct field layout

0 views
Skip to first unread message

Daco Harkes (Gerrit)

unread,
5:28 AM (14 hours ago) 5:28 AM
to Nourhan Hasan, Ryan Macnak, Ben Konyi, dart-...@luci-project-accounts.iam.gserviceaccount.com, Alexander Markov, dart-vm-compil...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Ben Konyi, Nourhan Hasan and Ryan Macnak

Daco Harkes added 5 comments

Patchset-level comments
File-level comment, Patchset 5 (Latest):
Daco Harkes . unresolved

@rma...@google.com Since you've made the most changes to `NativeType` in the last years. What do you think of the architectural options here?

Background: We need some display information to show to users for structs and their fields. And the VM service relies on the `NativeType` hierarchy calculations to figure out the field offsets and sizes. Which of the options listed in the comments below do you prefer? Or do you have another idea?

File pkg/vm/lib/modular/transformations/ffi/definitions.dart
Line 805, Patchset 5 (Latest): .map((f) => f.field?.name.text ?? f.getter!.name.text)
Daco Harkes . unresolved

Maybe add the fallback on `class CompoundField` instead. `String get name =>`

Line 806, Patchset 5 (Latest): .toList(),
Daco Harkes . unresolved

Nit you can use `[for (final f` instead of `map` and `toList`.

Line 994, Patchset 5 (Latest):
Daco Harkes . unresolved

nit: no newline needed.

File runtime/vm/compiler/ffi/native_type.cc
Line 443, Patchset 5 (Latest):static const NativeType* CompoundFromPragma(
Daco Harkes . unresolved

Let me think about the approach here architecturally:

Before this change, the NativeType _only_ has information needed for computing the calling convention. And this method only produces a NativeType.

With this change this method has two side effects, member names and user-readable dart types.

This feels kind of weird.

Some ideas on how to make the architecture better.

Option 1:

  • Add the field names to `NativeCompoundType` changing `const NativeTypes& members_;` to a new class that holds both a native type and a name per member entry.
  • And _only_ return the `NativeType`.
  • And make the VM service interact with the `NativeType`.
  • And have a mapping function from `NativeType` to some display name in the VM service.
  • We might then also need to add a name `NativeCompoundType` itself, so that you can display the name of structs and unions.
  • And then we should add such info to the `PrintTo` methods as well.

=> This ensures that we have a proper abstraction. The VM service only interacts with `NativeType` and it contains all the needed info also for debugging.
=> It also slightly slows down the compiler, because we're always parsing those names. (We're doing that already by embedding the names in the ffi struct fields pragma anyways. So it would be consistent.)
=> We might be able to use those names in the existing code to give more useful error messages.

Option 2: Scope the debugger-useful names only to the VM service.

  • Write a `DebuggerCompoundFromPragma` that calls `CompoundFromPragma` and then also parses the pragma again and constructs a new data structure that copies out all the relevant data into a new consistent data structure.

Pros:

  • Separation of concerns.

Cons:

  • Parsing the pragma twice. And some code duplication for that. Maybe some of the code duplication can be avoided.

Option 3:
Introduce a `DebuggableNativeStructType : public NativeStructType` that holds on to the names and return that from `CompoundFromPragma` if `bool debug_info=true` as a param.

Cons:

  • Complicates the type hierarchy.

I think I'm leaning towards option 1.

WDYT @bkony and @rmacnak?

Open in Gerrit

Related details

Attention is currently required from:
  • Ben Konyi
  • Nourhan Hasan
  • Ryan Macnak
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I7b9d524b2a11b488beeb975c34ca38ac9e7c552d
Gerrit-Change-Number: 530181
Gerrit-PatchSet: 5
Gerrit-Owner: Nourhan Hasan <nourhan...@gmail.com>
Gerrit-Reviewer: Ben Konyi <bko...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Ryan Macnak <rma...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-Attention: Nourhan Hasan <nourhan...@gmail.com>
Gerrit-Attention: Ben Konyi <bko...@google.com>
Gerrit-Attention: Ryan Macnak <rma...@google.com>
Gerrit-Comment-Date: Wed, 05 Aug 2026 09:28:20 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Ryan Macnak (Gerrit)

unread,
2:21 PM (5 hours ago) 2:21 PM
to Nourhan Hasan, Ben Konyi, Daco Harkes, dart-...@luci-project-accounts.iam.gserviceaccount.com, Alexander Markov, dart-vm-compil...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Ben Konyi and Nourhan Hasan

Ryan Macnak added 1 comment

Patchset-level comments
Daco Harkes . unresolved

@rma...@google.com Since you've made the most changes to `NativeType` in the last years. What do you think of the architectural options here?

Background: We need some display information to show to users for structs and their fields. And the VM service relies on the `NativeType` hierarchy calculations to figure out the field offsets and sizes. Which of the options listed in the comments below do you prefer? Or do you have another idea?

Ryan Macnak

Maybe I'm not understanding the usage, but I would have expected changes to the output of getObject, not a new RPC, to be able to show the state of FFI objects.

(Compare "Records and the VM Service".)

Open in Gerrit

Related details

Attention is currently required from:
  • Ben Konyi
  • Nourhan Hasan
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I7b9d524b2a11b488beeb975c34ca38ac9e7c552d
Gerrit-Change-Number: 530181
Gerrit-PatchSet: 5
Gerrit-Owner: Nourhan Hasan <nourhan...@gmail.com>
Gerrit-Reviewer: Ben Konyi <bko...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Ryan Macnak <rma...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-Attention: Nourhan Hasan <nourhan...@gmail.com>
Gerrit-Attention: Ben Konyi <bko...@google.com>
Gerrit-Comment-Date: Wed, 05 Aug 2026 18:21:37 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Daco Harkes <dacoh...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages