From 133da8692e80532797dd91b32539cf2175280a95 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 30 Dec 2020 19:57:11 -0700 Subject: stage2: rework Type Payload layout Add `Type.castTag` and note that it is preferable to call than `Type.cast`. This matches other abstractions in the codebase. Added a convenience function `Type.Tag.create` which really cleans up the callsites of creating `Type` objects. `Type` payloads can now share types. This is in preparation for another improvement that I want to do. --- src/Compilation.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index 8a0a6ee58d..11c8303fac 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -825,9 +825,11 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { const root_scope = rs: { if (mem.endsWith(u8, root_pkg.root_src_path, ".zig")) { - const struct_payload = try gpa.create(Type.Payload.EmptyStruct); const root_scope = try gpa.create(Module.Scope.File); - struct_payload.* = .{ .scope = &root_scope.root_container }; + const struct_ty = try Type.Tag.empty_struct.create( + gpa, + &root_scope.root_container, + ); root_scope.* = .{ // TODO this is duped so it can be freed in Container.deinit .sub_file_path = try gpa.dupe(u8, root_pkg.root_src_path), @@ -838,7 +840,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { .root_container = .{ .file_scope = root_scope, .decls = .{}, - .ty = Type.initPayload(&struct_payload.base), + .ty = struct_ty, }, }; break :rs &root_scope.base; -- cgit v1.2.3