aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-07-03 22:09:30 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-07-18 19:02:05 -0700
commitdb33ee45b7261c9ec62a1087cfc9377bc4e7aa8f (patch)
tree81e1f629c296a8a9c9573879382586dac3784737 /src/Compilation.zig
parent70c71935c7c9f20353dc2a50b497b752d70d3452 (diff)
downloadzig-db33ee45b7261c9ec62a1087cfc9377bc4e7aa8f.tar.gz
zig-db33ee45b7261c9ec62a1087cfc9377bc4e7aa8f.zip
rework generic function calls
Abridged summary: * Move `Module.Fn` into `InternPool`. * Delete a lot of confusing and problematic `Sema` logic related to generic function calls. This commit removes `Module.Fn` and replaces it with two new `InternPool.Tag` values: * `func_decl` - corresponding to a function declared in the source code. This one contains line/column numbers, zir_body_inst, etc. * `func_instance` - one for each monomorphization of a generic function. Contains a reference to the `func_decl` from whence the instantiation came, along with the `comptime` parameter values (or types in the case of `anytype`) Since `InternPool` provides deduplication on these values, these fields are now deleted from `Module`: * `monomorphed_func_keys` * `monomorphed_funcs` * `align_stack_fns` Instead of these, Sema logic for generic function instantiation now unconditionally evaluates the function prototype expression for every generic callsite. This is technically required in order for type coercions to work. The previous code had some dubious, probably wrong hacks to make things work, such as `hashUncoerced`. I'm not 100% sure how we were able to eliminate that function and still pass all the behavior tests, but I'm pretty sure things were still broken without doing type coercion for every generic function call argument. After the function prototype is evaluated, it produces a deduplicated `func_instance` `InternPool.Index` which can then be used for the generic function call. Some other nice things made by this simplification are the removal of `comptime_args_fn_inst` and `preallocated_new_func` from `Sema`, and the messy logic associated with them. I have not yet been able to measure the perf of this against master branch. On one hand, it reduces memory usage and pointer chasing of the most heavily used `InternPool` Tag - function bodies - but on the other hand, it does evaluate function prototype expressions more than before. We will soon find out.
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig7
1 files changed, 4 insertions, 3 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 91747e8b01..bc47d9c636 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -29,6 +29,7 @@ const wasi_libc = @import("wasi_libc.zig");
const fatal = @import("main.zig").fatal;
const clangMain = @import("main.zig").clangMain;
const Module = @import("Module.zig");
+const InternPool = @import("InternPool.zig");
const BuildId = std.Build.CompileStep.BuildId;
const Cache = std.Build.Cache;
const translate_c = @import("translate_c.zig");
@@ -227,7 +228,8 @@ const Job = union(enum) {
/// Write the constant value for a Decl to the output file.
codegen_decl: Module.Decl.Index,
/// Write the machine code for a function to the output file.
- codegen_func: Module.Fn.Index,
+ /// This will either be a non-generic `func_decl` or a `func_instance`.
+ codegen_func: InternPool.Index,
/// Render the .h file snippet for the Decl.
emit_h_decl: Module.Decl.Index,
/// The Decl needs to be analyzed and possibly export itself.
@@ -3216,8 +3218,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v
// Tests are always emitted in test binaries. The decl_refs are created by
// Module.populateTestFunctions, but this will not queue body analysis, so do
// that now.
- const func_index = module.intern_pool.indexToFunc(decl.val.ip_index).unwrap().?;
- try module.ensureFuncBodyAnalysisQueued(func_index);
+ try module.ensureFuncBodyAnalysisQueued(decl.val.toIntern());
}
},
.update_embed_file => |embed_file| {