diff --git a/src/bc_gen.zig b/src/bc_gen.zig index 728a47c54..b81e163bd 100644 --- a/src/bc_gen.zig +++ b/src/bc_gen.zig @@ -253,7 +253,7 @@ pub fn prepareFunc(c: *cy.Compiler, opt_group: ?rt.FuncGroupId, func: *cy.Func) log.tracev("prep func: {s}", .{symPath}); } const funcSig = c.sema.getFuncSig(func.funcSigId); - const rtFunc = rt.FuncSymbol.initHostFunc(@ptrCast(func.data.hostFunc.ptr), funcSig.reqCallTypeCheck, func.isMethod(), funcSig.numParams(), func.funcSigId); + const rtFunc = rt.FuncSymbol.initHostFunc(@ptrCast(func.data.hostFunc.ptr), funcSig.info.reqCallTypeCheck, func.isMethod(), funcSig.numParams(), func.funcSigId); if (opt_group) |group| { _ = try addGroupFunc(c, group, func, rtFunc); } else { diff --git a/src/cte.zig b/src/cte.zig index 30859aa71..4e8992ec6 100644 --- a/src/cte.zig +++ b/src/cte.zig @@ -350,7 +350,7 @@ pub fn expandValueTemplate(c: *cy.Chunk, template: *cy.sym.Template, args: []con const func_sig = c.sema.getFuncSig(sig); func.funcSigId = sig; func.retType = func_sig.getRetType(); - func.reqCallTypeCheck = func_sig.reqCallTypeCheck; + func.reqCallTypeCheck = func_sig.info.reqCallTypeCheck; func.numParams = @intCast(func_sig.params_len); func.variant = variant; @@ -402,8 +402,8 @@ pub fn expandTemplate(c: *cy.Chunk, template: *cy.sym.Template, args: []const cy ct_dep = ct_dep or type_e.info.ct_ref; } else if (arg.getTypeId() == bt.FuncSig) { const sig = c.sema.getFuncSig(@intCast(arg.asHeapObject().integer.val)); - ct_infer = ct_infer or sig.ct_infer; - ct_dep = ct_dep or sig.ct_dep; + ct_infer = ct_infer or sig.info.ct_infer; + ct_dep = ct_dep or sig.info.ct_dep; } } diff --git a/src/lib.zig b/src/lib.zig index 4767ddd4e..104037b97 100644 --- a/src/lib.zig +++ b/src/lib.zig @@ -588,7 +588,7 @@ export fn clNewFuncDyn(vm: *cy.VM, numParams: u32, func: c.FuncFn) Value { export fn clNewFunc(vm: *cy.VM, params: [*]const cy.TypeId, numParams: u32, retType: cy.TypeId, func: c.FuncFn) Value { const funcSigId = vm.sema.ensureFuncSig(@ptrCast(params[0..numParams]), retType) catch fatal(); const funcSig = vm.sema.funcSigs.items[funcSigId]; - return vm.allocHostFuncUnion(bt.Func, @ptrCast(func), numParams, funcSigId, null, funcSig.reqCallTypeCheck) catch fatal(); + return vm.allocHostFuncUnion(bt.Func, @ptrCast(func), numParams, funcSigId, null, funcSig.info.reqCallTypeCheck) catch fatal(); } test "clNewFunc()" { diff --git a/src/module.zig b/src/module.zig index c062c9471..5d0bff74c 100644 --- a/src/module.zig +++ b/src/module.zig @@ -351,7 +351,7 @@ pub const ChunkExt = struct { const func_sig = c.compiler.sema.getFuncSig(sig); func.funcSigId = sig; func.retType = func_sig.getRetType(); - func.reqCallTypeCheck = func_sig.reqCallTypeCheck; + func.reqCallTypeCheck = func_sig.info.reqCallTypeCheck; func.numParams = @intCast(func_sig.params_len); } @@ -447,7 +447,7 @@ pub const ChunkExt = struct { const func_sig = c.compiler.sema.getFuncSig(func_sig_id); func.funcSigId = func_sig_id; func.retType = func_sig.getRetType(); - func.reqCallTypeCheck = func_sig.reqCallTypeCheck; + func.reqCallTypeCheck = func_sig.info.reqCallTypeCheck; func.numParams = @intCast(func_sig.params_len); } diff --git a/src/sema.zig b/src/sema.zig index 9356701fd..c775fe572 100644 --- a/src/sema.zig +++ b/src/sema.zig @@ -2418,7 +2418,7 @@ pub fn resolveFunc2(c: *cy.Chunk, func: *cy.Func, has_parent_ctx: bool) !void { const sig_id = try resolveFuncSig(c, func, false); const sig = c.sema.getFuncSig(sig_id); - if (sig.is_template) { + if (sig.info.is_template) { const ct_params = getResolveContext(c).ct_params; try resolveToFuncTemplate(c, func, sig_id, ct_params); return; @@ -6982,7 +6982,10 @@ pub const FuncParam = packed struct { }; pub const FuncSigId = u32; -pub const FuncSig = packed struct { + +/// Turning this into to packed struct fails web-lib ReleaseFast strip=true, +/// however, it seems an inner packed struct `info` works. +pub const FuncSig = struct { /// Last elem is the return type sym. params_ptr: [*]const FuncParam, ret: cy.TypeId, @@ -6994,16 +6997,18 @@ pub const FuncSig = packed struct { /// If a param is not the any type. // isParamsTyped: bool, - /// Requires type checking if any param is not `dynamic` or `any`. - reqCallTypeCheck: bool, + info: packed struct { + /// Requires type checking if any param is not `dynamic` or `any`. + reqCallTypeCheck: bool, - is_template: bool, + is_template: bool, - /// Contains a param or return type that is dependent on a compile-time param. - ct_dep: bool, + /// Contains a param or return type that is dependent on a compile-time param. + ct_dep: bool, - /// Contains a param that infers a compile-time param. - ct_infer: bool, + /// Contains a param that infers a compile-time param. + ct_infer: bool, + }, pub inline fn params(self: FuncSig) []const FuncParam { return self.params_ptr[0..self.params_len]; @@ -7213,10 +7218,12 @@ pub const Sema = struct { .params_ptr = new.ptr, .params_len = @intCast(new.len), .ret = ret, - .reqCallTypeCheck = reqCallTypeCheck, - .is_template = is_template, - .ct_dep = ct_dep, - .ct_infer = ct_infer, + .info = .{ + .reqCallTypeCheck = reqCallTypeCheck, + .is_template = is_template, + .ct_dep = ct_dep, + .ct_infer = ct_infer, + }, }); res.value_ptr.* = id; res.key_ptr.* = .{ @@ -7475,7 +7482,7 @@ test "sema internals." { } if (cy.is32Bit) { - try t.eq(@sizeOf(FuncSig), 16); + try t.eq(@sizeOf(FuncSig), 12); } else { try t.eq(@sizeOf(FuncSig), 16); } diff --git a/src/std/os_ffi.zig b/src/std/os_ffi.zig index 4f3971fae..73ab15f6f 100644 --- a/src/std/os_ffi.zig +++ b/src/std/os_ffi.zig @@ -986,7 +986,7 @@ pub fn ffiBindLib(vm: *cy.VM, config: BindLibConfig) !Value { const ptr_t = try cy.vm.getFuncPtrType(vm, cfunc.funcSigId); const funcVal = try cy.heap.allocHostFuncPtr(vm, ptr_t, func, @intCast(cfunc.params.len), - cfunc.funcSigId, cyState, funcSig.reqCallTypeCheck); + cfunc.funcSigId, cyState, funcSig.info.reqCallTypeCheck); try table.asHeapObject().table.set(vm, symKey, funcVal); vm.release(symKey); vm.release(funcVal); @@ -1033,7 +1033,7 @@ pub fn ffiBindLib(vm: *cy.VM, config: BindLibConfig) !Value { const func = cy.ptrAlignCast(cy.ZHostFuncFn, funcPtr); const func_sig = vm.compiler.sema.getFuncSig(cfunc.funcSigId); - const func_sym = rt.FuncSymbol.initHostFunc(@ptrCast(func), func_sig.reqCallTypeCheck, true, func_sig.numParams(), cfunc.funcSigId); + const func_sym = rt.FuncSymbol.initHostFunc(@ptrCast(func), func_sig.info.reqCallTypeCheck, true, func_sig.numParams(), cfunc.funcSigId); const group = try vm.addFuncGroup(); _ = try vm.addGroupFunc(group, cfunc.namez, cfunc.funcSigId, func_sym); try @call(.never_inline, cy.VM.setMethodGroup, .{vm, sid, cfunc.namez, group});