Skip to content

Commit

Permalink
Attempt to fix web-lib build.
Browse files Browse the repository at this point in the history
  • Loading branch information
fubark committed Aug 26, 2024
1 parent 88e9e50 commit 0232637
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/bc_gen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/cte.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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()" {
Expand Down
4 changes: 2 additions & 2 deletions src/module.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down
35 changes: 21 additions & 14 deletions src/sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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];
Expand Down Expand Up @@ -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.* = .{
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/std/os_ffi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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});
Expand Down

0 comments on commit 0232637

Please sign in to comment.