diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-04-26 20:41:07 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-04-26 20:41:07 -0700 |
| commit | bfded492f0c12be2778c566bad0c82dea6ee76cb (patch) | |
| tree | 0942c1ca40f40fe371504fd4818535a9b73f90e5 /src/AstGen.zig | |
| parent | 91c317bb9aa906684104db3d73442ab1198a83f4 (diff) | |
| download | zig-bfded492f0c12be2778c566bad0c82dea6ee76cb.tar.gz zig-bfded492f0c12be2778c566bad0c82dea6ee76cb.zip | |
stage2: rewire the frontend driver to whole-file-zir
* Remove some unused imports in AstGen.zig. I think it would make sense
to start decoupling AstGen from the rest of the compiler code,
similar to how the tokenizer and parser are decoupled.
* AstGen: For decls, move the block_inline instructions to the top of
the function so that they get lower ZIR instruction indexes. With
this, the block_inline instruction index combined with its corresponding
break_inline instruction index can be used to form a ZIR instruction
range. This is useful for allocating an array to map ZIR instructions
to semantically analyzed instructions.
* Module: extract emit-h functionality into a struct, and only allocate
it when emit-h is activated.
* Module: remove the `decl_table` field. This previously was a table of
all Decls in the entire Module. A "name hash" strategy was used to
find decls within a given namespace, using this global table. Now,
each Namespace has its own map of name to children Decls.
- Additionally, there were 3 places that relied on iterating over
decl_table in order to function:
- C backend and SPIR-V backend. These now have their own decl_table
that they keep populated when `updateDecl` and `removeDecl` are
called.
- emit-h. A `decl_table` field has been added to the new GlobalEmitH
struct which is only allocated when emit-h is activated.
* Module: fix ZIR serialization/deserialization bug in debug mode having
to do with the secret safety tag for untagged unions. There is still an
open TODO to investigate a friendlier solution to this problem with
the language.
* Module: improve deserialization of ZIR to allocate only exactly as
much capacity as length in the instructions array so as to not waste
space.
* Module: move `srcHashEql` to `std.zig` to live next to the definition
of `SrcHash` itself.
* Module: re-introduce the logic for scanning top level declarations
within a namespace.
* Compilation: add an `analyze_pkg` Job which is used to kick off the
start of semantic analysis by doing the equivalent of
`_ = @import("std");`. The `analyze_pkg` job is unconditionally added
to the work queue on every update(), with pkg set to the std lib pkg.
* Rename TZIR to AIR in a few places. A more comprehensive rename will
come later.
Diffstat (limited to 'src/AstGen.zig')
| -rw-r--r-- | src/AstGen.zig | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig index 25f24e4039..3fe7ced0d1 100644 --- a/src/AstGen.zig +++ b/src/AstGen.zig @@ -12,9 +12,6 @@ const Allocator = std.mem.Allocator; const assert = std.debug.assert; const ArrayListUnmanaged = std.ArrayListUnmanaged; -const Value = @import("value.zig").Value; -const Type = @import("type.zig").Type; -const TypedValue = @import("TypedValue.zig"); const Zir = @import("Zir.zig"); const Module = @import("Module.zig"); const trace = @import("tracy.zig").trace; @@ -2648,6 +2645,10 @@ fn fnDecl( const tree = &astgen.file.tree; const token_tags = tree.tokens.items(.tag); + // We insert this at the beginning so that its instruction index marks the + // start of the top level declaration. + const block_inst = try gz.addBlock(.block_inline, fn_proto.ast.proto_node); + var decl_gz: GenZir = .{ .force_comptime = true, .decl_node_index = fn_proto.ast.proto_node, @@ -2843,7 +2844,8 @@ fn fnDecl( }; const fn_name_str_index = try decl_gz.identAsString(fn_name_token); - const block_inst = try gz.addBlock(.block_inline, fn_proto.ast.proto_node); + // We add this at the end so that its instruction index marks the end range + // of the top level declaration. _ = try decl_gz.addBreak(.break_inline, block_inst, func_inst); try decl_gz.setBlockBody(block_inst); @@ -2875,6 +2877,12 @@ fn globalVarDecl( const tree = &astgen.file.tree; const token_tags = tree.tokens.items(.tag); + const is_mutable = token_tags[var_decl.ast.mut_token] == .keyword_var; + const tag: Zir.Inst.Tag = if (is_mutable) .block_inline_var else .block_inline; + // We do this at the beginning so that the instruction index marks the range start + // of the top level declaration. + const block_inst = try gz.addBlock(tag, node); + var block_scope: GenZir = .{ .parent = scope, .decl_node_index = node, @@ -2900,7 +2908,6 @@ fn globalVarDecl( }; try wip_decls.next(gpa, is_pub, is_export, align_inst != .none, section_inst != .none); - const is_mutable = token_tags[var_decl.ast.mut_token] == .keyword_var; const is_threadlocal = if (var_decl.threadlocal_token) |tok| blk: { if (!is_mutable) { return astgen.failTok(tok, "threadlocal variable cannot be constant", .{}); @@ -2940,8 +2947,8 @@ fn globalVarDecl( var_decl.ast.init_node, ); - const tag: Zir.Inst.Tag = if (is_mutable) .block_inline_var else .block_inline; - const block_inst = try gz.addBlock(tag, node); + // We do this at the end so that the instruction index marks the end + // range of a top level declaration. _ = try block_scope.addBreak(.break_inline, block_inst, init_inst); try block_scope.setBlockBody(block_inst); break :vi block_inst; |
