aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-05-23 19:10:36 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:54 -0700
commit01ca841f1227cc3e17169c45318c8d4757a5c0d2 (patch)
tree431768f9bac787fd2568de48fa1d178e98df51df /src/Sema.zig
parent1b64eed107f54220f85a5158699225b59899a20a (diff)
downloadzig-01ca841f1227cc3e17169c45318c8d4757a5c0d2.tar.gz
zig-01ca841f1227cc3e17169c45318c8d4757a5c0d2.zip
Sema: improve the types_to_resolve mechanism
Store `InternPool.Index` as the key instead which means that an AIR instruction no longer needs to be burned to store the type, and also that we can use AutoArrayHashMap instead of an ArrayList, which avoids storing duplicates into the set, potentially saving CPU time.
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 13a1c1cb3d..866c242f15 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -66,11 +66,14 @@ comptime_args_fn_inst: Zir.Inst.Index = 0,
/// extra hash table lookup in the `monomorphed_funcs` set.
/// Sema will set this to null when it takes ownership.
preallocated_new_func: ?*Module.Fn = null,
-/// The key is `constant` AIR instructions to types that must be fully resolved
-/// after the current function body analysis is done.
-/// TODO: after upgrading to use InternPool change the key here to be an
-/// InternPool value index.
-types_to_resolve: std.ArrayListUnmanaged(Air.Inst.Ref) = .{},
+/// The key is types that must be fully resolved prior to machine code
+/// generation pass. Types are added to this set when resolving them
+/// immediately could cause a dependency loop, but they do need to be resolved
+/// before machine code generation passes process the AIR.
+/// It would work fine if this were an array list instead of an array hash map.
+/// I chose array hash map with the intention to save time by omitting
+/// duplicates.
+types_to_resolve: std.AutoArrayHashMapUnmanaged(InternPool.Index, void) = .{},
/// These are lazily created runtime blocks from block_inline instructions.
/// They are created when an break_inline passes through a runtime condition, because
/// Sema must convert comptime control flow to runtime control flow, which means
@@ -34085,8 +34088,7 @@ fn anonStructFieldIndex(
}
fn queueFullTypeResolution(sema: *Sema, ty: Type) !void {
- const inst_ref = try sema.addType(ty);
- try sema.types_to_resolve.append(sema.gpa, inst_ref);
+ try sema.types_to_resolve.put(sema.gpa, ty.toIntern(), {});
}
fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {