diff --git a/doc/langref.html.in b/doc/langref.html.in index 567c12cd0a..28577560e2 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -5056,7 +5056,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val {#header_close#} {#header_open|@wasmMemorySize#} -
{#syntax#}@wasmMemorySize(index: u32) u32{#endsyntax#}
+
{#syntax#}@wasmMemorySize(index: u32) usize{#endsyntax#}

This function returns the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} as an unsigned value in units of Wasm pages. Note that each Wasm page is 64KB in size. @@ -5070,7 +5070,7 @@ fn cmpxchgWeakButNotAtomic(comptime T: type, ptr: *T, expected_value: T, new_val {#header_close#} {#header_open|@wasmMemoryGrow#} -

{#syntax#}@wasmMemoryGrow(index: u32, delta: u32) i32{#endsyntax#}
+
{#syntax#}@wasmMemoryGrow(index: u32, delta: usize) isize{#endsyntax#}

This function increases the size of the Wasm memory identified by {#syntax#}index{#endsyntax#} by {#syntax#}delta{#endsyntax#} in units of unsigned number of Wasm pages. Note that each Wasm page diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 905fa4bdc2..ee14d7dee4 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -9461,7 +9461,7 @@ fn builtinCall( }, .wasm_memory_grow => { const index_arg = try comptimeExpr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[0]); - const delta_arg = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .u32_type } }, params[1]); + const delta_arg = try expr(gz, scope, .{ .rl = .{ .coerced_ty = .usize_type } }, params[1]); const result = try gz.addExtendedPayload(.wasm_memory_grow, Zir.Inst.BinNode{ .node = gz.nodeIndexToRelative(node), .lhs = index_arg, diff --git a/src/Air.zig b/src/Air.zig index 16c20f5a18..9d7016155e 100644 --- a/src/Air.zig +++ b/src/Air.zig @@ -782,13 +782,13 @@ pub const Inst = struct { field_parent_ptr, /// Implements @wasmMemorySize builtin. - /// Result type is always `u32`, + /// Result type is always `usize`, /// Uses the `pl_op` field, payload represents the index of the target memory. /// The operand is unused and always set to `Ref.none`. wasm_memory_size, /// Implements @wasmMemoryGrow builtin. - /// Result type is always `i32`, + /// Result type is always `isize`, /// Uses the `pl_op` field, payload represents the index of the target memory. wasm_memory_grow, @@ -1471,8 +1471,8 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool) .save_err_return_trace_index, => return Type.usize, - .wasm_memory_grow => return Type.i32, - .wasm_memory_size => return Type.u32, + .wasm_memory_grow => return Type.isize, + .wasm_memory_size => return Type.usize, .int_from_bool => return Type.u1, diff --git a/src/Sema.zig b/src/Sema.zig index 7a1885d652..ca6d562eef 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -26253,7 +26253,7 @@ fn zirWasmMemoryGrow( const index: u32 = @intCast(try sema.resolveInt(block, index_src, extra.lhs, Type.u32, .{ .needed_comptime_reason = "wasm memory size index must be comptime-known", })); - const delta = try sema.coerce(block, Type.u32, try sema.resolveInst(extra.rhs), delta_src); + const delta = try sema.coerce(block, Type.usize, try sema.resolveInst(extra.rhs), delta_src); try sema.requireRuntimeBlock(block, builtin_src, null); return block.addInst(.{ diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index 4502fe1c30..9e51417ab6 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -7625,7 +7625,8 @@ pub const FuncGen = struct { const o = self.dg.object; const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; const index = pl_op.payload; - return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{.i32}, &.{ + const llvm_usize = try o.lowerType(Type.usize); + return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.size", &.{llvm_usize}, &.{ try o.builder.intValue(.i32, index), }, ""); } @@ -7634,7 +7635,8 @@ pub const FuncGen = struct { const o = self.dg.object; const pl_op = self.air.instructions.items(.data)[@intFromEnum(inst)].pl_op; const index = pl_op.payload; - return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{.i32}, &.{ + const llvm_isize = try o.lowerType(Type.isize); + return self.wip.callIntrinsic(.normal, .none, .@"wasm.memory.grow", &.{llvm_isize}, &.{ try o.builder.intValue(.i32, index), try self.resolveInst(pl_op.operand), }, ""); }