authorgravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2022-07-30 18:43:15+02:00
committergravatar for liljaanton2001@gmail.comantlilja <liljaanton2001@gmail.com> 2022-08-01 14:51:54+02:00
logab3b614a335ffac9eac4f824ee18fba262ad988e
tree4851f9b4df1bbd93db44377625b78179dc2549eb
parentcd8070f94f6865959949dbcec6e0e32cd88bb544
signaturelock-open Commit is signed but in an unrecognized format.

Removed anytype_args field from Fn

anytype_args field was replaced with isAnytypeParam function.

2 files changed, 18 insertions(+), 14 deletions(-)

src/Module.zig+16-5
......@@ -1464,12 +1464,8 @@ pub const Fn = struct {
14641464 /// These never have .generic_poison for the Type
14651465 /// because the Type is needed to pass to `Type.eql` and for inserting comptime arguments
14661466 /// into the inst_map when analyzing the body of a generic function instantiation.
1467 /// Instead, the is_anytype knowledge is communicated via `anytype_args`.
1467 /// Instead, the is_anytype knowledge is communicated via `isAnytypeParam`.
14681468 comptime_args: ?[*]TypedValue,
1469 /// When comptime_args is null, this is undefined. Otherwise, this flags each
1470 /// parameter and tells whether it is anytype.
1471 /// TODO apply the same enhancement for param_names below to this field.
1472 anytype_args: [*]bool,
14731469
14741470 /// Precomputed hash for monomorphed_funcs.
14751471 /// This is important because it may be accessed when resizing monomorphed_funcs
......@@ -1584,6 +1580,21 @@ pub const Fn = struct {
15841580 }
15851581 }
15861582
1583 pub fn isAnytypeParam(func: Fn, mod: *Module, index: u32) bool {
1584 const file = mod.declPtr(func.owner_decl).getFileScope();
1585
1586 const tags = file.zir.instructions.items(.tag);
1587
1588 const param_body = file.zir.getParamBody(func.zir_body_inst);
1589 const param = param_body[index];
1590
1591 return switch (tags[param]) {
1592 .param, .param_comptime => false,
1593 .param_anytype, .param_anytype_comptime => true,
1594 else => unreachable,
1595 };
1596 }
1597
15871598 pub fn getParamName(func: Fn, mod: *Module, index: u32) [:0]const u8 {
15881599 const file = mod.declPtr(func.owner_decl).getFileScope();
15891600
src/Sema.zig+2-9
......@@ -5498,7 +5498,7 @@ const GenericCallAdapter = struct {
54985498 const this_is_comptime = this_arg.val.tag() != .generic_poison;
54995499 const other_is_comptime = other_arg.val.tag() != .generic_poison;
55005500 const this_is_anytype = this_arg.ty.tag() != .generic_poison;
5501 const other_is_anytype = other_key.anytype_args[i];
5501 const other_is_anytype = other_key.isAnytypeParam(ctx.module, @intCast(u32, i));
55025502
55035503 if (other_is_anytype != this_is_anytype) return false;
55045504 if (other_is_comptime != this_is_comptime) return false;
......@@ -6379,12 +6379,9 @@ fn instantiateGenericCall(
63796379 errdefer new_func.deinit(gpa);
63806380 assert(new_func == new_module_func);
63816381
6382 const anytype_args = try new_decl_arena_allocator.alloc(bool, func_ty_info.param_types.len);
6383 new_func.anytype_args = anytype_args.ptr;
63846382 arg_i = 0;
63856383 for (fn_info.param_body) |inst| {
63866384 var is_comptime = false;
6387 var is_anytype = false;
63886385 switch (zir_tags[inst]) {
63896386 .param => {
63906387 is_comptime = func_ty_info.paramIsComptime(arg_i);
......@@ -6393,11 +6390,9 @@ fn instantiateGenericCall(
63936390 is_comptime = true;
63946391 },
63956392 .param_anytype => {
6396 is_anytype = true;
63976393 is_comptime = func_ty_info.paramIsComptime(arg_i);
63986394 },
63996395 .param_anytype_comptime => {
6400 is_anytype = true;
64016396 is_comptime = true;
64026397 },
64036398 else => continue,
......@@ -6405,10 +6400,9 @@ fn instantiateGenericCall(
64056400
64066401 // We populate the Type here regardless because it is needed by
64076402 // `GenericCallAdapter.eql` as well as function body analysis.
6408 // Whether it is anytype is communicated by `anytype_args`.
6403 // Whether it is anytype is communicated by `isAnytypeParam`.
64096404 const arg = child_sema.inst_map.get(inst).?;
64106405 const copied_arg_ty = try child_sema.typeOf(arg).copy(new_decl_arena_allocator);
6411 anytype_args[arg_i] = is_anytype;
64126406
64136407 if (try sema.typeRequiresComptime(block, .unneeded, copied_arg_ty)) {
64146408 is_comptime = true;
......@@ -7760,7 +7754,6 @@ fn funcCommon(
77607754 .zir_body_inst = func_inst,
77617755 .owner_decl = sema.owner_decl_index,
77627756 .comptime_args = comptime_args,
7763 .anytype_args = undefined,
77647757 .hash = hash,
77657758 .lbrace_line = src_locs.lbrace_line,
77667759 .rbrace_line = src_locs.rbrace_line,