Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot restrict vm:entry-point pragma for a getter #59920

Open
iinozemtsev opened this issue Jan 16, 2025 · 1 comment
Open

Cannot restrict vm:entry-point pragma for a getter #59920

iinozemtsev opened this issue Jan 16, 2025 · 1 comment
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.

Comments

@iinozemtsev
Copy link
Member

In https://dart-review.googlesource.com/c/sdk/+/402860 I have a getter I am trying to call from the native code.

In Dart code, the getter is called like this:

int _tickCount = 0;
@pragma('vm:entry-point')
int get ticks => _tickCount;

And in native code, I am trying to call it like this:

Dart_GetField(Dart_RootLibrary(), Dart_NewStringFromCString("ticks"))

When I change pragma to @pragma('vm:entry-point', 'call'), I get the following error (both in AOT and Kernel mode):

ERROR: To retrieve the value of 'file:///usr/local/google/home/iinozemtsev/work/dart-sdk/sdk/samples/embedder/timer.dart::ticks (kind GetterFunction)' from native code, it must be annotated.
ERROR: See https://github.com/dart-lang/sdk/blob/master/runtime/docs/compiler/aot/entry_point_pragma.md

When I change pragma to @pragma('vm:entry-point', 'get'), then it works fine in Kernel mode, but in AOT mode it fails with the following error:

../../runtime/vm/dart_entry.cc: 145: error: expected: function.HasCode()
version=3.7.0-edge.193a852639ed45c9314d9e6f72f763338fba86e3 (main) (Thu Jan 16 13:45:19 2025 +0100) on "linux_x64"
pid=1218004, thread=1218004, isolate_group=file://out/DebugX64/timer_aot.snapshot(0x55597b637410), isolate=file://out/DebugX64/timer_aot.snapshot(0x55597b63ebe0)
os=linux, arch=x64, comp=no, sim=no
isolate_instructions=7f85cdb36f40, vm_instructions=7f85cdb2f000
fp=7ffe8fdb0b40, sp=7ffe8fdb0a10, pc=7f85cf1749ac
  pc 0x00007f85cf1749ac fp 0x00007ffe8fdb0b40 /usr/local/google/home/iinozemtsev/work/dart-sdk/sdk/out/DebugX64/libeasy_embedder_aot_shared.so+0x5749ac
  pc 0x00007f85cef920a4 fp 0x00007ffe8fdb0c20 /usr/local/google/home/iinozemtsev/work/dart-sdk/sdk/out/DebugX64/libeasy_embedder_aot_shared.so+0x3920a4
  pc 0x00007f85cf025122 fp 0x00007ffe8fdb0c90 /usr/local/google/home/iinozemtsev/work/dart-sdk/sdk/out/DebugX64/libeasy_embedder_aot_shared.so+0x425122
  pc 0x00007f85cf6f3285 fp 0x00007ffe8fdb0d70 Dart_GetField+0x475
  pc 0x000055594517db9a fp 0x00007ffe8fdb0e00 out/DebugX64/run_timer_aot+0x39b9a
-- End of DumpStackTrace
@iinozemtsev iinozemtsev added the area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. label Jan 16, 2025
@sstrickl sstrickl self-assigned this Jan 16, 2025
@sstrickl
Copy link
Contributor

sstrickl commented Jan 16, 2025

The issue here is that VerifyEntryPoint, used by the various Invoke/InvokeGetter/InvokeSetter functions, is out of sync with the precompiler.

If a non-true or null pragma argument is provided, then VerifyEntryPoint requires that

  • getters are annotated with "get" ("call" makes no sense with them, even when used with Dart_Invoke, because Dart_Invoke on a getter is the equivalent of Dart_GetField and then Dart_InvokeClosure on the retrieved value), and
  • setters are annotated with "set" (as they can only be used with Dart_SetField).

This matches how Invoke/InvokeGetter/InvokeSetter have traditionally treated getters and setters.

However, the precompiler and the pragma checks in native_code.dart do not treat getters and setters differently from other procedures (other than disallowing "get" for setters). They treat "get" on a getter as if it would closurize the getter instead of calling it to retrieve the value, and they treat "call" on both getters and setters as if they were invoked by Dart_Invoke.

I'm currently working on a CL to align all the various parts and also update the entry point pragma documentation appropriately, which should fix the issue here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
Projects
None yet
Development

No branches or pull requests

2 participants