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 {...@@ -1464,12 +1464,8 @@ pub const Fn = struct {
1464 /// These never have .generic_poison for the Type1464 /// These never have .generic_poison for the Type
1465 /// because the Type is needed to pass to `Type.eql` and for inserting comptime arguments1465 /// because the Type is needed to pass to `Type.eql` and for inserting comptime arguments
1466 /// into the inst_map when analyzing the body of a generic function instantiation.1466 /// 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`.
1468 comptime_args: ?[*]TypedValue,1468 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
1474 /// Precomputed hash for monomorphed_funcs.1470 /// Precomputed hash for monomorphed_funcs.
1475 /// This is important because it may be accessed when resizing monomorphed_funcs1471 /// This is important because it may be accessed when resizing monomorphed_funcs
...@@ -1584,6 +1580,21 @@ pub const Fn = struct {...@@ -1584,6 +1580,21 @@ pub const Fn = struct {
1584 }1580 }
1585 }1581 }
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
1587 pub fn getParamName(func: Fn, mod: *Module, index: u32) [:0]const u8 {1598 pub fn getParamName(func: Fn, mod: *Module, index: u32) [:0]const u8 {
1588 const file = mod.declPtr(func.owner_decl).getFileScope();1599 const file = mod.declPtr(func.owner_decl).getFileScope();
15891600
src/Sema.zig+2-9
...@@ -5498,7 +5498,7 @@ const GenericCallAdapter = struct {...@@ -5498,7 +5498,7 @@ const GenericCallAdapter = struct {
5498 const this_is_comptime = this_arg.val.tag() != .generic_poison;5498 const this_is_comptime = this_arg.val.tag() != .generic_poison;
5499 const other_is_comptime = other_arg.val.tag() != .generic_poison;5499 const other_is_comptime = other_arg.val.tag() != .generic_poison;
5500 const this_is_anytype = this_arg.ty.tag() != .generic_poison;5500 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
5503 if (other_is_anytype != this_is_anytype) return false;5503 if (other_is_anytype != this_is_anytype) return false;
5504 if (other_is_comptime != this_is_comptime) return false;5504 if (other_is_comptime != this_is_comptime) return false;
...@@ -6379,12 +6379,9 @@ fn instantiateGenericCall(...@@ -6379,12 +6379,9 @@ fn instantiateGenericCall(
6379 errdefer new_func.deinit(gpa);6379 errdefer new_func.deinit(gpa);
6380 assert(new_func == new_module_func);6380 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;
6384 arg_i = 0;6382 arg_i = 0;
6385 for (fn_info.param_body) |inst| {6383 for (fn_info.param_body) |inst| {
6386 var is_comptime = false;6384 var is_comptime = false;
6387 var is_anytype = false;
6388 switch (zir_tags[inst]) {6385 switch (zir_tags[inst]) {
6389 .param => {6386 .param => {
6390 is_comptime = func_ty_info.paramIsComptime(arg_i);6387 is_comptime = func_ty_info.paramIsComptime(arg_i);
...@@ -6393,11 +6390,9 @@ fn instantiateGenericCall(...@@ -6393,11 +6390,9 @@ fn instantiateGenericCall(
6393 is_comptime = true;6390 is_comptime = true;
6394 },6391 },
6395 .param_anytype => {6392 .param_anytype => {
6396 is_anytype = true;
6397 is_comptime = func_ty_info.paramIsComptime(arg_i);6393 is_comptime = func_ty_info.paramIsComptime(arg_i);
6398 },6394 },
6399 .param_anytype_comptime => {6395 .param_anytype_comptime => {
6400 is_anytype = true;
6401 is_comptime = true;6396 is_comptime = true;
6402 },6397 },
6403 else => continue,6398 else => continue,
...@@ -6405,10 +6400,9 @@ fn instantiateGenericCall(...@@ -6405,10 +6400,9 @@ fn instantiateGenericCall(
64056400
6406 // We populate the Type here regardless because it is needed by6401 // We populate the Type here regardless because it is needed by
6407 // `GenericCallAdapter.eql` as well as function body analysis.6402 // `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`.
6409 const arg = child_sema.inst_map.get(inst).?;6404 const arg = child_sema.inst_map.get(inst).?;
6410 const copied_arg_ty = try child_sema.typeOf(arg).copy(new_decl_arena_allocator);6405 const copied_arg_ty = try child_sema.typeOf(arg).copy(new_decl_arena_allocator);
6411 anytype_args[arg_i] = is_anytype;
64126406
6413 if (try sema.typeRequiresComptime(block, .unneeded, copied_arg_ty)) {6407 if (try sema.typeRequiresComptime(block, .unneeded, copied_arg_ty)) {
6414 is_comptime = true;6408 is_comptime = true;
...@@ -7760,7 +7754,6 @@ fn funcCommon(...@@ -7760,7 +7754,6 @@ fn funcCommon(
7760 .zir_body_inst = func_inst,7754 .zir_body_inst = func_inst,
7761 .owner_decl = sema.owner_decl_index,7755 .owner_decl = sema.owner_decl_index,
7762 .comptime_args = comptime_args,7756 .comptime_args = comptime_args,
7763 .anytype_args = undefined,
7764 .hash = hash,7757 .hash = hash,
7765 .lbrace_line = src_locs.lbrace_line,7758 .lbrace_line = src_locs.lbrace_line,
7766 .rbrace_line = src_locs.rbrace_line,7759 .rbrace_line = src_locs.rbrace_line,