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...@@ -475,7 +475,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
475 .unwrap_optional => {475 .unwrap_optional => {
476 const src_token = tree.firstToken(node);476 const src_token = tree.firstToken(node);
477477
478 const src = token_starts[main_tokens[node]];
479 switch (rl) {478 switch (rl) {
480 .ref => return gz.addUnTok(479 .ref => return gz.addUnTok(
481 .optional_payload_safe_ptr,480 .optional_payload_safe_ptr,
...@@ -518,7 +517,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In...@@ -518,7 +517,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
518 if (true) @panic("TODO update for zir-memory-layout");517 if (true) @panic("TODO update for zir-memory-layout");
519 const ident_token = node_datas[node].rhs;518 const ident_token = node_datas[node].rhs;
520 const name = try mod.identifierTokenString(scope, ident_token);519 const name = try mod.identifierTokenString(scope, ident_token);
521 const src = token_starts[ident_token];
522 const result = try addZirInstTag(mod, scope, src, .error_value, .{ .name = name });520 const result = try addZirInstTag(mod, scope, src, .error_value, .{ .name = name });
523 return rvalue(mod, scope, rl, result);521 return rvalue(mod, scope, rl, result);
524 },522 },
...@@ -526,7 +524,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In...@@ -526,7 +524,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
526 if (true) @panic("TODO update for zir-memory-layout");524 if (true) @panic("TODO update for zir-memory-layout");
527 const error_set = try typeExpr(mod, scope, node_datas[node].lhs);525 const error_set = try typeExpr(mod, scope, node_datas[node].lhs);
528 const payload = try typeExpr(mod, scope, node_datas[node].rhs);526 const payload = try typeExpr(mod, scope, node_datas[node].rhs);
529 const src = token_starts[main_tokens[node]];
530 const result = try addZIRBinOp(mod, scope, src, .error_union_type, error_set, payload);527 const result = try addZIRBinOp(mod, scope, src, .error_union_type, error_set, payload);
531 return rvalue(mod, scope, rl, result);528 return rvalue(mod, scope, rl, result);
532 },529 },
...@@ -534,14 +531,12 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In...@@ -534,14 +531,12 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
534 if (true) @panic("TODO update for zir-memory-layout");531 if (true) @panic("TODO update for zir-memory-layout");
535 const lhs = try typeExpr(mod, scope, node_datas[node].lhs);532 const lhs = try typeExpr(mod, scope, node_datas[node].lhs);
536 const rhs = try typeExpr(mod, scope, node_datas[node].rhs);533 const rhs = try typeExpr(mod, scope, node_datas[node].rhs);
537 const src = token_starts[main_tokens[node]];
538 const result = try addZIRBinOp(mod, scope, src, .merge_error_sets, lhs, rhs);534 const result = try addZIRBinOp(mod, scope, src, .merge_error_sets, lhs, rhs);
539 return rvalue(mod, scope, rl, result);535 return rvalue(mod, scope, rl, result);
540 },536 },
541 .anyframe_literal => {537 .anyframe_literal => {
542 if (true) @panic("TODO update for zir-memory-layout");538 if (true) @panic("TODO update for zir-memory-layout");
543 const main_token = main_tokens[node];539 const main_token = main_tokens[node];
544 const src = token_starts[main_token];
545 const result = try addZIRInstConst(mod, scope, src, .{540 const result = try addZIRInstConst(mod, scope, src, .{
546 .ty = Type.initTag(.type),541 .ty = Type.initTag(.type),
547 .val = Value.initTag(.anyframe_type),542 .val = Value.initTag(.anyframe_type),
...@@ -550,7 +545,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In...@@ -550,7 +545,6 @@ pub fn expr(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) In
550 },545 },
551 .anyframe_type => {546 .anyframe_type => {
552 if (true) @panic("TODO update for zir-memory-layout");547 if (true) @panic("TODO update for zir-memory-layout");
553 const src = token_starts[node_datas[node].lhs];
554 const return_type = try typeExpr(mod, scope, node_datas[node].rhs);548 const return_type = try typeExpr(mod, scope, node_datas[node].rhs);
555 const result = try addZIRUnOp(mod, scope, src, .anyframe_type, return_type);549 const result = try addZIRUnOp(mod, scope, src, .anyframe_type, return_type);
556 return rvalue(mod, scope, rl, result);550 return rvalue(mod, scope, rl, result);
...@@ -724,7 +718,6 @@ pub fn comptimeExpr(...@@ -724,7 +718,6 @@ pub fn comptimeExpr(
724 // instruction is the block's result value.718 // instruction is the block's result value.
725 _ = try expr(mod, &block_scope.base, rl, node);719 _ = try expr(mod, &block_scope.base, rl, node);
726720
727 const src = token_starts[tree.firstToken(node)];
728 const block = try addZIRInstBlock(mod, parent_scope, src, .block_comptime_flat, .{721 const block = try addZIRInstBlock(mod, parent_scope, src, .block_comptime_flat, .{
729 .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items),722 .instructions = try block_scope.arena.dupe(zir.Inst.Ref, block_scope.instructions.items),
730 });723 });
...@@ -744,7 +737,6 @@ fn breakExpr(...@@ -744,7 +737,6 @@ fn breakExpr(
744 const main_tokens = tree.nodes.items(.main_token);737 const main_tokens = tree.nodes.items(.main_token);
745 const token_starts = tree.tokens.items(.start);738 const token_starts = tree.tokens.items(.start);
746739
747 const src = token_starts[main_tokens[node]];
748 const break_label = node_datas[node].lhs;740 const break_label = node_datas[node].lhs;
749 const rhs = node_datas[node].rhs;741 const rhs = node_datas[node].rhs;
750742
...@@ -823,7 +815,6 @@ fn continueExpr(...@@ -823,7 +815,6 @@ fn continueExpr(
823 const main_tokens = tree.nodes.items(.main_token);815 const main_tokens = tree.nodes.items(.main_token);
824 const token_starts = tree.tokens.items(.start);816 const token_starts = tree.tokens.items(.start);
825817
826 const src = token_starts[main_tokens[node]];
827 const break_label = node_datas[node].lhs;818 const break_label = node_datas[node].lhs;
828819
829 // Look for the label in the scope.820 // Look for the label in the scope.
...@@ -958,7 +949,6 @@ fn labeledBlockExpr(...@@ -958,7 +949,6 @@ fn labeledBlockExpr(
958 const lbrace = main_tokens[block_node];949 const lbrace = main_tokens[block_node];
959 const label_token = lbrace - 2;950 const label_token = lbrace - 2;
960 assert(token_tags[label_token] == .identifier);951 assert(token_tags[label_token] == .identifier);
961 const src = token_starts[lbrace];
962952
963 try checkLabelRedefinition(mod, parent_scope, label_token);953 try checkLabelRedefinition(mod, parent_scope, label_token);
964954
...@@ -1321,7 +1311,6 @@ fn assignOp(...@@ -1321,7 +1311,6 @@ fn assignOp(
1321 const lhs = try addZIRUnOp(mod, scope, lhs_ptr.src, .deref, lhs_ptr);1311 const lhs = try addZIRUnOp(mod, scope, lhs_ptr.src, .deref, lhs_ptr);
1322 const lhs_type = try addZIRUnOp(mod, scope, lhs_ptr.src, .typeof, lhs);1312 const lhs_type = try addZIRUnOp(mod, scope, lhs_ptr.src, .typeof, lhs);
1323 const rhs = try expr(mod, scope, .{ .ty = lhs_type }, node_datas[infix_node].rhs);1313 const rhs = try expr(mod, scope, .{ .ty = lhs_type }, node_datas[infix_node].rhs);
1324 const src = token_starts[main_tokens[infix_node]];
1325 const result = try addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs);1314 const result = try addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs);
1326 _ = try addZIRBinOp(mod, scope, src, .store, lhs_ptr, result);1315 _ = try addZIRBinOp(mod, scope, src, .store, lhs_ptr, result);
1327}1316}
...@@ -1360,7 +1349,6 @@ fn negation(...@@ -1360,7 +1349,6 @@ fn negation(
1360 const main_tokens = tree.nodes.items(.main_token);1349 const main_tokens = tree.nodes.items(.main_token);
1361 const token_starts = tree.tokens.items(.start);1350 const token_starts = tree.tokens.items(.start);
13621351
1363 const src = token_starts[main_tokens[node]];
1364 const lhs = try addZIRInstConst(mod, scope, src, .{1352 const lhs = try addZIRInstConst(mod, scope, src, .{
1365 .ty = Type.initTag(.comptime_int),1353 .ty = Type.initTag(.comptime_int),
1366 .val = Value.initTag(.zero),1354 .val = Value.initTag(.zero),
...@@ -1379,8 +1367,6 @@ fn ptrType(...@@ -1379,8 +1367,6 @@ fn ptrType(
1379 const tree = scope.tree();1367 const tree = scope.tree();
1380 const token_starts = tree.tokens.items(.start);1368 const token_starts = tree.tokens.items(.start);
13811369
1382 const src = token_starts[ptr_info.ast.main_token];
1383
1384 const simple = ptr_info.allowzero_token == null and1370 const simple = ptr_info.allowzero_token == null and
1385 ptr_info.ast.align_node == 0 and1371 ptr_info.ast.align_node == 0 and
1386 ptr_info.volatile_token == null and1372 ptr_info.volatile_token == null and
...@@ -1426,7 +1412,6 @@ fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !...@@ -1426,7 +1412,6 @@ fn arrayType(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) !
1426 const node_datas = tree.nodes.items(.data);1412 const node_datas = tree.nodes.items(.data);
1427 const token_starts = tree.tokens.items(.start);1413 const token_starts = tree.tokens.items(.start);
14281414
1429 const src = token_starts[main_tokens[node]];
1430 const usize_type = try addZIRInstConst(mod, scope, src, .{1415 const usize_type = try addZIRInstConst(mod, scope, src, .{
1431 .ty = Type.initTag(.type),1416 .ty = Type.initTag(.type),
1432 .val = Value.initTag(.usize_type),1417 .val = Value.initTag(.usize_type),
...@@ -1456,7 +1441,6 @@ fn arrayTypeSentinel(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node....@@ -1456,7 +1441,6 @@ fn arrayTypeSentinel(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.
14561441
1457 const len_node = node_datas[node].lhs;1442 const len_node = node_datas[node].lhs;
1458 const extra = tree.extraData(node_datas[node].rhs, ast.Node.ArrayTypeSentinel);1443 const extra = tree.extraData(node_datas[node].rhs, ast.Node.ArrayTypeSentinel);
1459 const src = token_starts[main_tokens[node]];
1460 const usize_type = try addZIRInstConst(mod, scope, src, .{1444 const usize_type = try addZIRInstConst(mod, scope, src, .{
1461 .ty = Type.initTag(.type),1445 .ty = Type.initTag(.type),
1462 .val = Value.initTag(.usize_type),1446 .val = Value.initTag(.usize_type),
...@@ -1529,7 +1513,6 @@ fn errorSetDecl(...@@ -1529,7 +1513,6 @@ fn errorSetDecl(
1529 }1513 }
1530 }1514 }
1531 }1515 }
1532 const src = token_starts[error_token];
1533 const result = try addZIRInst(mod, scope, src, zir.Inst.ErrorSet, .{ .fields = fields }, .{});1516 const result = try addZIRInst(mod, scope, src, zir.Inst.ErrorSet, .{ .fields = fields }, .{});
1534 return rvalue(mod, scope, rl, result);1517 return rvalue(mod, scope, rl, result);
1535}1518}
...@@ -1551,8 +1534,6 @@ fn orelseCatchExpr(...@@ -1551,8 +1534,6 @@ fn orelseCatchExpr(
1551 const tree = scope.tree();1534 const tree = scope.tree();
1552 const token_starts = tree.tokens.items(.start);1535 const token_starts = tree.tokens.items(.start);
15531536
1554 const src = token_starts[op_token];
1555
1556 var block_scope: Scope.GenZir = .{1537 var block_scope: Scope.GenZir = .{
1557 .parent = scope,1538 .parent = scope,
1558 .decl = scope.ownerDecl().?,1539 .decl = scope.ownerDecl().?,
...@@ -1738,7 +1719,6 @@ pub fn fieldAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.In...@@ -1738,7 +1719,6 @@ pub fn fieldAccess(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.In
1738 const node_datas = tree.nodes.items(.data);1719 const node_datas = tree.nodes.items(.data);
17391720
1740 const dot_token = main_tokens[node];1721 const dot_token = main_tokens[node];
1741 const src = token_starts[dot_token];
1742 const field_ident = dot_token + 1;1722 const field_ident = dot_token + 1;
1743 const field_name = try mod.identifierTokenString(scope, field_ident);1723 const field_name = try mod.identifierTokenString(scope, field_ident);
1744 if (rl == .ref) {1724 if (rl == .ref) {
...@@ -1766,7 +1746,6 @@ fn arrayAccess(...@@ -1766,7 +1746,6 @@ fn arrayAccess(
1766 const token_starts = tree.tokens.items(.start);1746 const token_starts = tree.tokens.items(.start);
1767 const node_datas = tree.nodes.items(.data);1747 const node_datas = tree.nodes.items(.data);
17681748
1769 const src = token_starts[main_tokens[node]];
1770 const usize_type = try addZIRInstConst(mod, scope, src, .{1749 const usize_type = try addZIRInstConst(mod, scope, src, .{
1771 .ty = Type.initTag(.type),1750 .ty = Type.initTag(.type),
1772 .val = Value.initTag(.usize_type),1751 .val = Value.initTag(.usize_type),
...@@ -1794,8 +1773,6 @@ fn sliceExpr(...@@ -1794,8 +1773,6 @@ fn sliceExpr(
1794 const tree = scope.tree();1773 const tree = scope.tree();
1795 const token_starts = tree.tokens.items(.start);1774 const token_starts = tree.tokens.items(.start);
17961775
1797 const src = token_starts[slice.ast.lbracket];
1798
1799 const usize_type = try addZIRInstConst(mod, scope, src, .{1776 const usize_type = try addZIRInstConst(mod, scope, src, .{
1800 .ty = Type.initTag(.type),1777 .ty = Type.initTag(.type),
1801 .val = Value.initTag(.usize_type),1778 .val = Value.initTag(.usize_type),
...@@ -1848,7 +1825,6 @@ fn simpleBinOp(...@@ -1848,7 +1825,6 @@ fn simpleBinOp(
18481825
1849 const lhs = try expr(mod, scope, .none, node_datas[infix_node].lhs);1826 const lhs = try expr(mod, scope, .none, node_datas[infix_node].lhs);
1850 const rhs = try expr(mod, scope, .none, node_datas[infix_node].rhs);1827 const rhs = try expr(mod, scope, .none, node_datas[infix_node].rhs);
1851 const src = token_starts[main_tokens[infix_node]];
1852 const result = try addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs);1828 const result = try addZIRBinOp(mod, scope, src, op_inst_tag, lhs, rhs);
1853 return rvalue(mod, scope, rl, result);1829 return rvalue(mod, scope, rl, result);
1854}1830}
...@@ -1866,7 +1842,6 @@ fn boolBinOp(...@@ -1866,7 +1842,6 @@ fn boolBinOp(
1866 const main_tokens = tree.nodes.items(.main_token);1842 const main_tokens = tree.nodes.items(.main_token);
1867 const token_starts = tree.tokens.items(.start);1843 const token_starts = tree.tokens.items(.start);
18681844
1869 const src = token_starts[main_tokens[infix_node]];
1870 const bool_type = try addZIRInstConst(mod, scope, src, .{1845 const bool_type = try addZIRInstConst(mod, scope, src, .{
1871 .ty = Type.initTag(.type),1846 .ty = Type.initTag(.type),
1872 .val = Value.initTag(.bool_type),1847 .val = Value.initTag(.bool_type),
...@@ -2880,7 +2855,6 @@ fn parseStringLiteral(mod: *Module, scope: *Scope, token: ast.TokenIndex) ![]u8...@@ -2880,7 +2855,6 @@ fn parseStringLiteral(mod: *Module, scope: *Scope, token: ast.TokenIndex) ![]u8
2880 const bytes = std.zig.parseStringLiteral(arena, unparsed, &bad_index) catch |err| switch (err) {2855 const bytes = std.zig.parseStringLiteral(arena, unparsed, &bad_index) catch |err| switch (err) {
2881 error.InvalidCharacter => {2856 error.InvalidCharacter => {
2882 const bad_byte = unparsed[bad_index];2857 const bad_byte = unparsed[bad_index];
2883 const src = token_starts[token];
2884 return mod.fail(scope, src + bad_index, "invalid string literal character: '{c}'", .{2858 return mod.fail(scope, src + bad_index, "invalid string literal character: '{c}'", .{
2885 bad_byte,2859 bad_byte,
2886 });2860 });
...@@ -2903,7 +2877,6 @@ fn stringLiteral(...@@ -2903,7 +2877,6 @@ fn stringLiteral(
29032877
2904 const str_lit_token = main_tokens[str_lit];2878 const str_lit_token = main_tokens[str_lit];
2905 const bytes = try parseStringLiteral(mod, scope, str_lit_token);2879 const bytes = try parseStringLiteral(mod, scope, str_lit_token);
2906 const src = token_starts[str_lit_token];
2907 const str_inst = try addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{});2880 const str_inst = try addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{});
2908 return rvalue(mod, scope, rl, str_inst);2881 return rvalue(mod, scope, rl, str_inst);
2909}2882}
...@@ -2953,7 +2926,6 @@ fn multilineStringLiteral(...@@ -2953,7 +2926,6 @@ fn multilineStringLiteral(
2953 mem.copy(u8, bytes[byte_i..], line_bytes);2926 mem.copy(u8, bytes[byte_i..], line_bytes);
2954 byte_i += line_bytes.len;2927 byte_i += line_bytes.len;
2955 }2928 }
2956 const src = token_starts[start];
2957 const str_inst = try addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{});2929 const str_inst = try addZIRInst(mod, scope, src, zir.Inst.Str, .{ .bytes = bytes }, .{});
2958 return rvalue(mod, scope, rl, str_inst);2930 return rvalue(mod, scope, rl, str_inst);
2959}2931}
...@@ -2965,7 +2937,6 @@ fn charLiteral(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index)...@@ -2965,7 +2937,6 @@ fn charLiteral(mod: *Module, scope: *Scope, rl: ResultLoc, node: ast.Node.Index)
2965 const main_token = main_tokens[node];2937 const main_token = main_tokens[node];
2966 const token_starts = tree.tokens.items(.start);2938 const token_starts = tree.tokens.items(.start);
29672939
2968 const src = token_starts[main_token];
2969 const slice = tree.tokenSlice(main_token);2940 const slice = tree.tokenSlice(main_token);
29702941
2971 var bad_index: usize = undefined;2942 var bad_index: usize = undefined;
...@@ -3025,7 +2996,6 @@ fn floatLiteral(...@@ -3025,7 +2996,6 @@ fn floatLiteral(
3025 const float_number = std.fmt.parseFloat(f128, bytes) catch |e| switch (e) {2996 const float_number = std.fmt.parseFloat(f128, bytes) catch |e| switch (e) {
3026 error.InvalidCharacter => unreachable, // validated by tokenizer2997 error.InvalidCharacter => unreachable, // validated by tokenizer
3027 };2998 };
3028 const src = token_starts[main_token];
3029 const result = try addZIRInstConst(mod, scope, src, .{2999 const result = try addZIRInstConst(mod, scope, src, .{
3030 .ty = Type.initTag(.comptime_float),3000 .ty = Type.initTag(.comptime_float),
3031 .val = try Value.Tag.float_128.create(arena, float_number),3001 .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...@@ -3048,7 +3018,6 @@ fn asmExpr(mod: *Module, scope: *Scope, rl: ResultLoc, full: ast.full.Asm) Inner
3048 const inputs = try arena.alloc([]const u8, full.inputs.len);3018 const inputs = try arena.alloc([]const u8, full.inputs.len);
3049 const args = try arena.alloc(zir.Inst.Ref, full.inputs.len);3019 const args = try arena.alloc(zir.Inst.Ref, full.inputs.len);
30503020
3051 const src = token_starts[full.ast.asm_token];
3052 const str_type = try addZIRInstConst(mod, scope, src, .{3021 const str_type = try addZIRInstConst(mod, scope, src, .{
3053 .ty = Type.initTag(.type),3022 .ty = Type.initTag(.type),
3054 .val = Value.initTag(.const_slice_u8_type),3023 .val = Value.initTag(.const_slice_u8_type),
...@@ -3258,7 +3227,6 @@ fn builtinCall(...@@ -3258,7 +3227,6 @@ fn builtinCall(
3258 });3227 });
3259 }3228 }
3260 }3229 }
3261 const src = token_starts[builtin_token];
32623230
3263 switch (info.tag) {3231 switch (info.tag) {
3264 .ptr_to_int => {3232 .ptr_to_int => {