Skip to content

Commit ec6d9c0

Browse files
osa1Commit Queue
authored andcommitted
[dart2wasm] Inline Pointer constructor
Currently none of dart2wasm or wasm-opt inline `Pointer._`, resulting in bad code generation when the allocated pointers are directly unboxed. Example: ``` import 'dart:ffi'; @Native<Pointer<Int64> Function()>() external Pointer<Int64> intPtr(); @Native<Int64 Function(Pointer<Int64>)>() external int derefIntPtr(Pointer<Int64> ptr); void main() { Pointer<Int64> ptr = intPtr(); ptr += 1; int i = derefIntPtr(ptr); print(i); } ``` Current output: ``` (func $main (;299;) i32.const 83 call $ffi.intPtr (import) call $Pointer._ struct.get $_Type $field2 i32.const 8 i32.add call $Pointer._ struct.get $_Type $field2 call $ffi.derefIntPtr (import) struct.new $BoxedInt call $print) ``` With this CL the `Pointer` allocation disappears: ``` (func $main (;299;) i32.const 83 call $ffi.intPtr (import) i32.const 8 i32.add call $ffi.derefIntPtr (import) struct.new $BoxedInt call $print) ``` Change-Id: I54a2fd37bc9e8ab26c6394e0b8175d65ecf64cb4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399561 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Ömer Ağacan <[email protected]>
1 parent 0c527e1 commit ec6d9c0

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

sdk/lib/_internal/wasm/lib/ffi_patch.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ final class Pointer<T extends NativeType> {
1010
@pragma("wasm:entry-point")
1111
WasmI32 _address;
1212

13+
@pragma("wasm:prefer-inline")
1314
Pointer._(this._address);
1415

1516
@patch

0 commit comments

Comments
 (0)