authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-03-20 18:54:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-20 15:56:59-07:00
log907142a03627f170ef1e721e996a8759952fb58f
tree93868f711b3d81e241d05976ae494ede0374b862
parent12eeb18a263f0b1498c9bedc11e9970bc47ffa8f

zir-memory-layout: remove all absolute src consts

this is to prevent future bugs

1 files changed, 0 insertions(+), 32 deletions(-)

src/astgen.zig-32
......@@ -475,7 +475,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
475475 .unwrap_optional => {
476476 const src_token = tree.firstToken(node);
477477
478 const src = token_starts[main_tokens[node]];
479478 switch (rl) {
480479 .ref => return gz.addUnTok(
481480 .optional_payload_safe_ptr,
......@@ -518,7 +517,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
518517 if (true) @panic("TODO update for zir-memory-layout");
519518 const ident_token = node_datas[node].rhs;
520519 const name = try mod.identifierTokenString(scope, ident_token);
521 const src = token_starts[ident_token];
522520 const result = try addZirInstTag(mod, scope, src, .error_value, .{ .name = name });
523521 return rvalue(mod, scope, rl, result);
524522 },
......@@ -526,7 +524,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
526524 if (true) @panic("TODO update for zir-memory-layout");
527525 const error_set = try typeExpr(mod, scope, node_datas[node].lhs);
528526 const payload = try typeExpr(mod, scope, node_datas[node].rhs);
529 const src = token_starts[main_tokens[node]];
530527 const result = try addZIRBinOp(mod, scope, src, .error_union_type, error_set, payload);
531528 return rvalue(mod, scope, rl, result);
532529 },
......@@ -534,14 +531,12 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
534531 if (true) @panic("TODO update for zir-memory-layout");
535532 const lhs = try typeExpr(mod, scope, node_datas[node].lhs);
536533 const rhs = try typeExpr(mod, scope, node_datas[node].rhs);
537 const src = token_starts[main_tokens[node]];
538534 const result = try addZIRBinOp(mod, scope, src, .merge_error_sets, lhs, rhs);
539535 return rvalue(mod, scope, rl, result);
540536 },
541537 .anyframe_literal => {
542538 if (true) @panic("TODO update for zir-memory-layout");
543539 const main_token = main_tokens[node];
544 const src = token_starts[main_token];
545540 const result = try addZIRInstConst(mod, scope, src, .{
546541 .ty = Type.initTag(.type),
547542 .val = Value.initTag(.anyframe_type),
......@@ -550,7 +545,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
550545 },
551546 .anyframe_type => {
552547 if (true) @panic("TODO update for zir-memory-layout");
553 const src = token_starts[node_datas[node].lhs];
554548 const return_type = try typeExpr(mod, scope, node_datas[node].rhs);
555549 const result = try addZIRUnOp(mod, scope, src, .anyframe_type, return_type);
556550 return rvalue(mod, scope, rl, result);
......@@ -724,7 +718,6 @@ pub fn comptimeExpr(
724718 // instruction is the block's result value.
725719 _ = try expr(mod, &block_scope.base, rl, node);
726720
727 const src = token_starts[tree.firstToken(node)];
728721 const block = try addZIRInstBlock(mod, parent_scope, src, .block_comptime_flat, .{
729722 .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items),
730723 });
......@@ -744,7 +737,6 @@ fn breakExpr(
744737 const main_tokens = tree.nodes.items(.main_token);
745738 const token_starts = tree.tokens.items(.start);
746739
747 const src = token_starts[main_tokens[node]];
748740 const break_label = node_datas[node].lhs;
749741 const rhs = node_datas[node].rhs;
750742
......@@ -823,7 +815,6 @@ fn continueExpr(
823815 const main_tokens = tree.nodes.items(.main_token);
824816 const token_starts = tree.tokens.items(.start);
825817
826 const src = token_starts[main_tokens[node]];
827818 const break_label = node_datas[node].lhs;
828819
829820 // Look for the label in the scope.
......@@ -958,7 +949,6 @@ fn labeledBlockExpr(
958949 const lbrace = main_tokens[block_node];
959950 const label_token = lbrace - 2;
960951 assert(token_tags[label_token] == .identifier);
961 const src = token_starts[lbrace];
962952
963953 try checkLabelRedefinition(mod, parent_scope, label_token);
964954
......@@ -1321,7 +1311,6 @@ fn assignOp(
13211311 const lhs = try addZIRUnOp(mod, scope, lhs_ptr.src, .deref, lhs_ptr);
13221312 const lhs_type = try addZIRUnOp(mod, scope, lhs_ptr.src, .typeof, lhs);
13231313 const rhs = try expr(mod, scope, .{ .ty = lhs_type }, node_datas[infix_node].rhs);
1324 const src = token_starts[main_tokens[infix_node]];
13251314 const result = try addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs);
13261315 _ = try addZIRBinOp(mod, scope, src, .store, lhs_ptr, result);
13271316}
......@@ -1360,7 +1349,6 @@ fn negation(
13601349 const main_tokens = tree.nodes.items(.main_token);
13611350 const token_starts = tree.tokens.items(.start);
13621351
1363 const src = token_starts[main_tokens[node]];
13641352 const lhs = try addZIRInstConst(mod, scope, src, .{
13651353 .ty = Type.initTag(.comptime_int),
13661354 .val = Value.initTag(.zero),
......@@ -1379,8 +1367,6 @@ fn ptrType(
13791367 const tree = scope.tree();
13801368 const token_starts = tree.tokens.items(.start);
13811369
1382 const src = token_starts[ptr_info.ast.main_token];
1383
13841370 const simple = ptr_info.allowzero_token == null and
13851371 ptr_info.ast.align_node == 0 and
13861372 ptr_info.volatile_token == null and
......@@ -1426,7 +1412,6 @@ fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !
14261412 const node_datas = tree.nodes.items(.data);
14271413 const token_starts = tree.tokens.items(.start);
14281414
1429 const src = token_starts[main_tokens[node]];
14301415 const usize_type = try addZIRInstConst(mod, scope, src, .{
14311416 .ty = Type.initTag(.type),
14321417 .val = Value.initTag(.usize_type),
......@@ -1456,7 +1441,6 @@ fn arrayTypeSentinel(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.
14561441
14571442 const len_node = node_datas[node].lhs;
14581443 const extra = tree.extraData(node_datas[node].rhs, ast.Node.ArrayTypeSentinel);
1459 const src = token_starts[main_tokens[node]];
14601444 const usize_type = try addZIRInstConst(mod, scope, src, .{
14611445 .ty = Type.initTag(.type),
14621446 .val = Value.initTag(.usize_type),
......@@ -1529,7 +1513,6 @@ fn errorSetDecl(
15291513 }
15301514 }
15311515 }
1532 const src = token_starts[error_token];
15331516 const result = try addZIRInst(mod, scope, src, zir.Inst.ErrorSet, .{ .fields = fields }, .{});
15341517 return rvalue(mod, scope, rl, result);
15351518}
......@@ -1551,8 +1534,6 @@ fn orelseCatchExpr(
15511534 const tree = scope.tree();
15521535 const token_starts = tree.tokens.items(.start);
15531536
1554 const src = token_starts[op_token];
1555
15561537 var block_scope: Scope.GenZir = .{
15571538 .parent = scope,
15581539 .decl = scope.ownerDecl().?,
......@@ -1738,7 +1719,6 @@ pub fn fieldAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.In
17381719 const node_datas = tree.nodes.items(.data);
17391720
17401721 const dot_token = main_tokens[node];
1741 const src = token_starts[dot_token];
17421722 const field_ident = dot_token + 1;
17431723 const field_name = try mod.identifierTokenString(scope, field_ident);
17441724 if (rl == .ref) {
......@@ -1766,7 +1746,6 @@ fn arrayAccess(
17661746 const token_starts = tree.tokens.items(.start);
17671747 const node_datas = tree.nodes.items(.data);
17681748
1769 const src = token_starts[main_tokens[node]];
17701749 const usize_type = try addZIRInstConst(mod, scope, src, .{
17711750 .ty = Type.initTag(.type),
17721751 .val = Value.initTag(.usize_type),
......@@ -1794,8 +1773,6 @@ fn sliceExpr(
17941773 const tree = scope.tree();
17951774 const token_starts = tree.tokens.items(.start);
17961775
1797 const src = token_starts[slice.ast.lbracket];
1798
17991776 const usize_type = try addZIRInstConst(mod, scope, src, .{
18001777 .ty = Type.initTag(.type),
18011778 .val = Value.initTag(.usize_type),
......@@ -1848,7 +1825,6 @@ fn simpleBinOp(
18481825
18491826 const lhs = try expr(mod, scope, .none, node_datas[infix_node].lhs);
18501827 const rhs = try expr(mod, scope, .none, node_datas[infix_node].rhs);
1851 const src = token_starts[main_tokens[infix_node]];
18521828 const result = try addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs);
18531829 return rvalue(mod, scope, rl, result);
18541830}
......@@ -1866,7 +1842,6 @@ fn boolBinOp(
18661842 const main_tokens = tree.nodes.items(.main_token);
18671843 const token_starts = tree.tokens.items(.start);
18681844
1869 const src = token_starts[main_tokens[infix_node]];
18701845 const bool_type = try addZIRInstConst(mod, scope, src, .{
18711846 .ty = Type.initTag(.type),
18721847 .val = Value.initTag(.bool_type),
......@@ -2880,7 +2855,6 @@ fn parseStringLiteral(mod: *Module, scope: *Scope, token: ast.TokenIndex) ![]u8
28802855 const bytes = std.zig.parseStringLiteral(arena, unparsed, &bad_index) catch |err| switch (err) {
28812856 error.InvalidCharacter => {
28822857 const bad_byte = unparsed[bad_index];
2883 const src = token_starts[token];
28842858 return mod.fail(scope, src + bad_index, "invalid string literal character: '{c}'", .{
28852859 bad_byte,
28862860 });
......@@ -2903,7 +2877,6 @@ fn stringLiteral(
29032877
29042878 const str_lit_token = main_tokens[str_lit];
29052879 const bytes = try parseStringLiteral(mod, scope, str_lit_token);
2906 const src = token_starts[str_lit_token];
29072880 const str_inst = try addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{});
29082881 return rvalue(mod, scope, rl, str_inst);
29092882}
......@@ -2953,7 +2926,6 @@ fn multilineStringLiteral(
29532926 mem.copy(u8, bytes[byte_i..], line_bytes);
29542927 byte_i += line_bytes.len;
29552928 }
2956 const src = token_starts[start];
29572929 const str_inst = try addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{});
29582930 return rvalue(mod, scope, rl, str_inst);
29592931}
......@@ -2965,7 +2937,6 @@ fn charLiteral(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index)
29652937 const main_token = main_tokens[node];
29662938 const token_starts = tree.tokens.items(.start);
29672939
2968 const src = token_starts[main_token];
29692940 const slice = tree.tokenSlice(main_token);
29702941
29712942 var bad_index: usize = undefined;
......@@ -3025,7 +2996,6 @@ fn floatLiteral(
30252996 const float_number = std.fmt.parseFloat(f128, bytes) catch |e| switch (e) {
30262997 error.InvalidCharacter => unreachable, // validated by tokenizer
30272998 };
3028 const src = token_starts[main_token];
30292999 const result = try addZIRInstConst(mod, scope, src, .{
30303000 .ty = Type.initTag(.comptime_float),
30313001 .val = try Value.Tag.float_128.create(arena, float_number),
......@@ -3048,7 +3018,6 @@ fn asmExpr(mod: *Module, scope: *Scope, rl: ResultLoc, full: ast.full.Asm) Inner
30483018 const inputs = try arena.alloc([]const u8, full.inputs.len);
30493019 const args = try arena.alloc(zir.Inst.Ref, full.inputs.len);
30503020
3051 const src = token_starts[full.ast.asm_token];
30523021 const str_type = try addZIRInstConst(mod, scope, src, .{
30533022 .ty = Type.initTag(.type),
30543023 .val = Value.initTag(.const_slice_u8_type),
......@@ -3258,7 +3227,6 @@ fn builtinCall(
32583227 });
32593228 }
32603229 }
3261 const src = token_starts[builtin_token];
32623230
32633231 switch (info.tag) {
32643232 .ptr_to_int => {