Skip to content

Commit 18362eb

Browse files
committed
Zir: refactor declaration instruction representation
The new representation is often more compact. It is also more straightforward to understand: for instance, `extern` is represented on the `declaration` instruction itself rather than using a special instruction. The same applies to `var`, making both of these far more compact. This commit also separates the type and value bodies of a `declaration` instruction. This is a prerequisite for ziglang#131. In general, `declaration` now directly encodes details of the syntax form used, and the embedded ZIR bodies are for actual expressions. The only exception to this is functions, where ZIR is effectively designed as if we had ziglang#1717. `extern fn` declarations are modeled as `extern const` with a function type, and normal `fn` definitions are modeled as `const` with a `func{,_fancy,_inferred}` instruction. This may change in the future, but improving on this was out of scope for this commit.
1 parent af5e731 commit 18362eb

14 files changed

+1248
-1119
lines changed

lib/std/zig/AstGen.zig

+582-536
Large diffs are not rendered by default.

lib/std/zig/Zir.zig

+392-95
Large diffs are not rendered by default.

src/InternPool.zig

-7
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,6 @@ pub const Key = union(enum) {
20182018
ty: Index,
20192019
init: Index,
20202020
owner_nav: Nav.Index,
2021-
lib_name: OptionalNullTerminatedString,
20222021
is_threadlocal: bool,
20232022
is_weak_linkage: bool,
20242023
};
@@ -2741,7 +2740,6 @@ pub const Key = union(enum) {
27412740
return a_info.owner_nav == b_info.owner_nav and
27422741
a_info.ty == b_info.ty and
27432742
a_info.init == b_info.init and
2744-
a_info.lib_name == b_info.lib_name and
27452743
a_info.is_threadlocal == b_info.is_threadlocal and
27462744
a_info.is_weak_linkage == b_info.is_weak_linkage;
27472745
},
@@ -5573,9 +5571,6 @@ pub const Tag = enum(u8) {
55735571
/// May be `none`.
55745572
init: Index,
55755573
owner_nav: Nav.Index,
5576-
/// Library name if specified.
5577-
/// For example `extern "c" var stderrp = ...` would have 'c' as library name.
5578-
lib_name: OptionalNullTerminatedString,
55795574
flags: Flags,
55805575

55815576
pub const Flags = packed struct(u32) {
@@ -6928,7 +6923,6 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
69286923
.ty = extra.ty,
69296924
.init = extra.init,
69306925
.owner_nav = extra.owner_nav,
6931-
.lib_name = extra.lib_name,
69326926
.is_threadlocal = extra.flags.is_threadlocal,
69336927
.is_weak_linkage = extra.flags.is_weak_linkage,
69346928
} };
@@ -7575,7 +7569,6 @@ pub fn get(ip: *InternPool, gpa: Allocator, tid: Zcu.PerThread.Id, key: Key) All
75757569
.ty = variable.ty,
75767570
.init = variable.init,
75777571
.owner_nav = variable.owner_nav,
7578-
.lib_name = variable.lib_name,
75797572
.flags = .{
75807573
.is_const = false,
75817574
.is_threadlocal = variable.is_threadlocal,

0 commit comments

Comments
 (0)