aboutsummaryrefslogtreecommitdiff
path: root/src/AstGen.zig
diff options
context:
space:
mode:
authorMartin Wickham <spexguy070@gmail.com>2021-06-03 15:39:26 -0500
committerMartin Wickham <spexguy070@gmail.com>2021-06-03 17:02:16 -0500
commitfc9430f56798a53f9393a697f4ccd6bf9981b970 (patch)
tree69a1a3b359e970349f9466f85a370918d78b7217 /src/AstGen.zig
parent87dae0ce98fde1957a9290c22866b3101ce419d8 (diff)
downloadzig-fc9430f56798a53f9393a697f4ccd6bf9981b970.tar.gz
zig-fc9430f56798a53f9393a697f4ccd6bf9981b970.zip
Breaking hash map changes for 0.8.0
- hash/eql functions moved into a Context object - *Context functions pass an explicit context - *Adapted functions pass specialized keys and contexts - new getPtr() function returns a pointer to value - remove functions renamed to fetchRemove - new remove functions return bool - removeAssertDiscard deleted, use assert(remove(...)) instead - Keys and values are stored in separate arrays - Entry is now {*K, *V}, the new KV is {K, V} - BufSet/BufMap functions renamed to match other set/map types - fixed iterating-while-modifying bug in src/link/C.zig
Diffstat (limited to 'src/AstGen.zig')
-rw-r--r--src/AstGen.zig20
1 files changed, 9 insertions, 11 deletions
diff --git a/src/AstGen.zig b/src/AstGen.zig
index 790984dc8f..564813f9e3 100644
--- a/src/AstGen.zig
+++ b/src/AstGen.zig
@@ -144,9 +144,7 @@ pub fn generate(gpa: *Allocator, tree: ast.Tree) InnerError!Zir {
astgen.extra.items[imports_index] = astgen.addExtraAssumeCapacity(Zir.Inst.Imports{
.imports_len = @intCast(u32, astgen.imports.count()),
});
- for (astgen.imports.items()) |entry| {
- astgen.extra.appendAssumeCapacity(entry.key);
- }
+ astgen.extra.appendSliceAssumeCapacity(astgen.imports.keys());
}
return Zir{
@@ -7932,13 +7930,13 @@ fn identAsString(astgen: *AstGen, ident_token: ast.TokenIndex) !u32 {
const gop = try astgen.string_table.getOrPut(gpa, key);
if (gop.found_existing) {
string_bytes.shrinkRetainingCapacity(str_index);
- return gop.entry.value;
+ return gop.value_ptr.*;
} else {
// We have to dupe the key into the arena, otherwise the memory
// becomes invalidated when string_bytes gets data appended.
// TODO https://github.com/ziglang/zig/issues/8528
- gop.entry.key = try astgen.arena.dupe(u8, key);
- gop.entry.value = str_index;
+ gop.key_ptr.* = try astgen.arena.dupe(u8, key);
+ gop.value_ptr.* = str_index;
try string_bytes.append(gpa, 0);
return str_index;
}
@@ -7957,15 +7955,15 @@ fn strLitAsString(astgen: *AstGen, str_lit_token: ast.TokenIndex) !IndexSlice {
if (gop.found_existing) {
string_bytes.shrinkRetainingCapacity(str_index);
return IndexSlice{
- .index = gop.entry.value,
+ .index = gop.value_ptr.*,
.len = @intCast(u32, key.len),
};
} else {
// We have to dupe the key into the arena, otherwise the memory
// becomes invalidated when string_bytes gets data appended.
// TODO https://github.com/ziglang/zig/issues/8528
- gop.entry.key = try astgen.arena.dupe(u8, key);
- gop.entry.value = str_index;
+ gop.key_ptr.* = try astgen.arena.dupe(u8, key);
+ gop.value_ptr.* = str_index;
// Still need a null byte because we are using the same table
// to lookup null terminated strings, so if we get a match, it has to
// be null terminated for that to work.
@@ -9122,10 +9120,10 @@ fn declareNewName(
return astgen.failNodeNotes(node, "redeclaration of '{s}'", .{
name,
}, &[_]u32{
- try astgen.errNoteNode(gop.entry.value, "other declaration here", .{}),
+ try astgen.errNoteNode(gop.value_ptr.*, "other declaration here", .{}),
});
}
- gop.entry.value = node;
+ gop.value_ptr.* = node;
break;
},
.top => break,