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

[vm/ffi] @Constant for compile-time null terminated strings #52342

Open
ds84182 opened this issue May 10, 2023 · 2 comments
Open

[vm/ffi] @Constant for compile-time null terminated strings #52342

ds84182 opened this issue May 10, 2023 · 2 comments
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi P3 A lower priority bug or feature request triaged Issue has been triaged by sub team type-enhancement A request for a change that isn't a bug

Comments

@ds84182
Copy link
Contributor

ds84182 commented May 10, 2023

Would be nice to have to avoid managing allocations for C strings, and in AOT it could be part of the .rodata section of the executable.

Would support UTF-8 (Uint8) and UTF-16 (Uint16). Could be extended for value and struct constants behind a pointer as well.

@Constant('Hello, World!\n')
external Pointer<Uint8> get greeting;

puts(greeting);

// Or maybe...?
const greeting = Constant<Pointer<Uint8>>('Hello, World!\n');

puts(greeting.ptr);

cc @dcharkes

@dcharkes
Copy link
Contributor

That's an interesting idea.

When addressing #47718, we should get the right infrastructure to do this.

Though, how do we provide an API for JIT in this case? Do we in JIT allocate at runtime and leak?

And maybe we can try to align the syntax with #50551.

// Global var in native asset, similar to `@Native external` function.
@NativeSymbol(/* optional symbol and asset */); // No type argument, as the Pointer already has it.
external Pointer<Uint8> get greeting;

// Global var in Dart.
@Constant('Hello, World!\n')
external Pointer<Uint8> get greeting;

Maybe if we address #50565 and #50551, we can just put them in a src/constants.c instead. Is there a strong preference for having them in Dart?

@ds84182
Copy link
Contributor Author

ds84182 commented May 11, 2023

My preference for having them in Dart is mostly reducing the need to alloc & copy strings to the heap. It's a pain to manage temporary allocations for string-heavy APIs. A good example is Vulkan, where you have to look up all your functions using an instance-provided lookup function.

For JIT, the strings could live as long as the VM. Might require interning with a string cache of some kind.

@lrhn lrhn added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi labels May 11, 2023
@a-siva a-siva added type-enhancement A request for a change that isn't a bug P3 A lower priority bug or feature request triaged Issue has been triaged by sub team labels Dec 7, 2023
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. library-ffi P3 A lower priority bug or feature request triaged Issue has been triaged by sub team type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants