| ... | @@ -844,7 +844,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr | ... | @@ -844,7 +844,7 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: ast.Node.Index) InnerEr |
| 844 | .@"switch", .switch_comma => return switchExpr(gz, scope, rl, node), | 844 | .@"switch", .switch_comma => return switchExpr(gz, scope, rl, node), |
| 845 | | 845 | |
| 846 | .@"nosuspend" => return nosuspendExpr(gz, scope, rl, node), | 846 | .@"nosuspend" => return nosuspendExpr(gz, scope, rl, node), |
| 847 | .@"suspend" => return suspendExpr(gz, scope, rl, node), | 847 | .@"suspend" => return suspendExpr(gz, scope, node), |
| 848 | .@"await" => return awaitExpr(gz, scope, rl, node), | 848 | .@"await" => return awaitExpr(gz, scope, rl, node), |
| 849 | .@"resume" => return resumeExpr(gz, scope, rl, node), | 849 | .@"resume" => return resumeExpr(gz, scope, rl, node), |
| 850 | | 850 | |
| ... | @@ -922,10 +922,8 @@ fn nosuspendExpr( | ... | @@ -922,10 +922,8 @@ fn nosuspendExpr( |
| 922 | fn suspendExpr( | 922 | fn suspendExpr( |
| 923 | gz: *GenZir, | 923 | gz: *GenZir, |
| 924 | scope: *Scope, | 924 | scope: *Scope, |
| 925 | rl: ResultLoc, | | |
| 926 | node: ast.Node.Index, | 925 | node: ast.Node.Index, |
| 927 | ) InnerError!Zir.Inst.Ref { | 926 | ) InnerError!Zir.Inst.Ref { |
| 928 | _ = rl; | | |
| 929 | const astgen = gz.astgen; | 927 | const astgen = gz.astgen; |
| 930 | const gpa = astgen.gpa; | 928 | const gpa = astgen.gpa; |
| 931 | const tree = astgen.tree; | 929 | const tree = astgen.tree; |
| ... | @@ -1171,32 +1169,32 @@ fn arrayInitExpr( | ... | @@ -1171,32 +1169,32 @@ fn arrayInitExpr( |
| 1171 | }, | 1169 | }, |
| 1172 | .ref => { | 1170 | .ref => { |
| 1173 | if (types.array != .none) { | 1171 | if (types.array != .none) { |
| 1174 | return arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, types.array, types.elem, .array_init_ref); | 1172 | return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, .array_init_ref); |
| 1175 | } else { | 1173 | } else { |
| 1176 | return arrayInitExprRlNone(gz, scope, rl, node, array_init.ast.elements, .array_init_anon_ref); | 1174 | return arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon_ref); |
| 1177 | } | 1175 | } |
| 1178 | }, | 1176 | }, |
| 1179 | .none, .none_or_ref => { | 1177 | .none, .none_or_ref => { |
| 1180 | if (types.array != .none) { | 1178 | if (types.array != .none) { |
| 1181 | return arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, types.array, types.elem, .array_init); | 1179 | return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, .array_init); |
| 1182 | } else { | 1180 | } else { |
| 1183 | return arrayInitExprRlNone(gz, scope, rl, node, array_init.ast.elements, .array_init_anon); | 1181 | return arrayInitExprRlNone(gz, scope, node, array_init.ast.elements, .array_init_anon); |
| 1184 | } | 1182 | } |
| 1185 | }, | 1183 | }, |
| 1186 | .ty => |ty_inst| { | 1184 | .ty => |ty_inst| { |
| 1187 | if (types.array != .none) { | 1185 | if (types.array != .none) { |
| 1188 | const result = try arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, types.array, types.elem, .array_init); | 1186 | const result = try arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, types.elem, .array_init); |
| 1189 | return rvalue(gz, scope, rl, result, node); | 1187 | return rvalue(gz, scope, rl, result, node); |
| 1190 | } else { | 1188 | } else { |
| 1191 | const elem_type = try gz.addUnNode(.elem_type, ty_inst, node); | 1189 | const elem_type = try gz.addUnNode(.elem_type, ty_inst, node); |
| 1192 | return arrayInitExprRlTy(gz, scope, rl, node, array_init.ast.elements, ty_inst, elem_type, .array_init); | 1190 | return arrayInitExprRlTy(gz, scope, node, array_init.ast.elements, elem_type, .array_init); |
| 1193 | } | 1191 | } |
| 1194 | }, | 1192 | }, |
| 1195 | .ptr, .inferred_ptr => |ptr_inst| { | 1193 | .ptr, .inferred_ptr => |ptr_inst| { |
| 1196 | return arrayInitExprRlPtr(gz, scope, rl, node, array_init.ast.elements, ptr_inst); | 1194 | return arrayInitExprRlPtr(gz, scope, node, array_init.ast.elements, ptr_inst); |
| 1197 | }, | 1195 | }, |
| 1198 | .block_ptr => |block_gz| { | 1196 | .block_ptr => |block_gz| { |
| 1199 | return arrayInitExprRlPtr(gz, scope, rl, node, array_init.ast.elements, block_gz.rl_ptr); | 1197 | return arrayInitExprRlPtr(gz, scope, node, array_init.ast.elements, block_gz.rl_ptr); |
| 1200 | }, | 1198 | }, |
| 1201 | } | 1199 | } |
| 1202 | } | 1200 | } |
| ... | @@ -1204,12 +1202,10 @@ fn arrayInitExpr( | ... | @@ -1204,12 +1202,10 @@ fn arrayInitExpr( |
| 1204 | fn arrayInitExprRlNone( | 1202 | fn arrayInitExprRlNone( |
| 1205 | gz: *GenZir, | 1203 | gz: *GenZir, |
| 1206 | scope: *Scope, | 1204 | scope: *Scope, |
| 1207 | rl: ResultLoc, | | |
| 1208 | node: ast.Node.Index, | 1205 | node: ast.Node.Index, |
| 1209 | elements: []const ast.Node.Index, | 1206 | elements: []const ast.Node.Index, |
| 1210 | tag: Zir.Inst.Tag, | 1207 | tag: Zir.Inst.Tag, |
| 1211 | ) InnerError!Zir.Inst.Ref { | 1208 | ) InnerError!Zir.Inst.Ref { |
| 1212 | _ = rl; | | |
| 1213 | const astgen = gz.astgen; | 1209 | const astgen = gz.astgen; |
| 1214 | const gpa = astgen.gpa; | 1210 | const gpa = astgen.gpa; |
| 1215 | const elem_list = try gpa.alloc(Zir.Inst.Ref, elements.len); | 1211 | const elem_list = try gpa.alloc(Zir.Inst.Ref, elements.len); |
| ... | @@ -1228,16 +1224,11 @@ fn arrayInitExprRlNone( | ... | @@ -1228,16 +1224,11 @@ fn arrayInitExprRlNone( |
| 1228 | fn arrayInitExprRlTy( | 1224 | fn arrayInitExprRlTy( |
| 1229 | gz: *GenZir, | 1225 | gz: *GenZir, |
| 1230 | scope: *Scope, | 1226 | scope: *Scope, |
| 1231 | rl: ResultLoc, | | |
| 1232 | node: ast.Node.Index, | 1227 | node: ast.Node.Index, |
| 1233 | elements: []const ast.Node.Index, | 1228 | elements: []const ast.Node.Index, |
| 1234 | array_ty_inst: Zir.Inst.Ref, | | |
| 1235 | elem_ty_inst: Zir.Inst.Ref, | 1229 | elem_ty_inst: Zir.Inst.Ref, |
| 1236 | tag: Zir.Inst.Tag, | 1230 | tag: Zir.Inst.Tag, |
| 1237 | ) InnerError!Zir.Inst.Ref { | 1231 | ) InnerError!Zir.Inst.Ref { |
| 1238 | _ = rl; | | |
| 1239 | _ = array_ty_inst; | | |
| 1240 | _ = elem_ty_inst; | | |
| 1241 | const astgen = gz.astgen; | 1232 | const astgen = gz.astgen; |
| 1242 | const gpa = astgen.gpa; | 1233 | const gpa = astgen.gpa; |
| 1243 | | 1234 | |
| ... | @@ -1259,12 +1250,10 @@ fn arrayInitExprRlTy( | ... | @@ -1259,12 +1250,10 @@ fn arrayInitExprRlTy( |
| 1259 | fn arrayInitExprRlPtr( | 1250 | fn arrayInitExprRlPtr( |
| 1260 | gz: *GenZir, | 1251 | gz: *GenZir, |
| 1261 | scope: *Scope, | 1252 | scope: *Scope, |
| 1262 | rl: ResultLoc, | | |
| 1263 | node: ast.Node.Index, | 1253 | node: ast.Node.Index, |
| 1264 | elements: []const ast.Node.Index, | 1254 | elements: []const ast.Node.Index, |
| 1265 | result_ptr: Zir.Inst.Ref, | 1255 | result_ptr: Zir.Inst.Ref, |
| 1266 | ) InnerError!Zir.Inst.Ref { | 1256 | ) InnerError!Zir.Inst.Ref { |
| 1267 | _ = rl; | | |
| 1268 | const astgen = gz.astgen; | 1257 | const astgen = gz.astgen; |
| 1269 | const gpa = astgen.gpa; | 1258 | const gpa = astgen.gpa; |
| 1270 | | 1259 | |
| ... | @@ -1340,41 +1329,39 @@ fn structInitExpr( | ... | @@ -1340,41 +1329,39 @@ fn structInitExpr( |
| 1340 | .ref => { | 1329 | .ref => { |
| 1341 | if (struct_init.ast.type_expr != 0) { | 1330 | if (struct_init.ast.type_expr != 0) { |
| 1342 | const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr); | 1331 | const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr); |
| 1343 | return structInitExprRlTy(gz, scope, rl, node, struct_init, ty_inst, .struct_init_ref); | 1332 | return structInitExprRlTy(gz, scope, node, struct_init, ty_inst, .struct_init_ref); |
| 1344 | } else { | 1333 | } else { |
| 1345 | return structInitExprRlNone(gz, scope, rl, node, struct_init, .struct_init_anon_ref); | 1334 | return structInitExprRlNone(gz, scope, node, struct_init, .struct_init_anon_ref); |
| 1346 | } | 1335 | } |
| 1347 | }, | 1336 | }, |
| 1348 | .none, .none_or_ref => { | 1337 | .none, .none_or_ref => { |
| 1349 | if (struct_init.ast.type_expr != 0) { | 1338 | if (struct_init.ast.type_expr != 0) { |
| 1350 | const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr); | 1339 | const ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr); |
| 1351 | return structInitExprRlTy(gz, scope, rl, node, struct_init, ty_inst, .struct_init); | 1340 | return structInitExprRlTy(gz, scope, node, struct_init, ty_inst, .struct_init); |
| 1352 | } else { | 1341 | } else { |
| 1353 | return structInitExprRlNone(gz, scope, rl, node, struct_init, .struct_init_anon); | 1342 | return structInitExprRlNone(gz, scope, node, struct_init, .struct_init_anon); |
| 1354 | } | 1343 | } |
| 1355 | }, | 1344 | }, |
| 1356 | .ty => |ty_inst| { | 1345 | .ty => |ty_inst| { |
| 1357 | if (struct_init.ast.type_expr == 0) { | 1346 | if (struct_init.ast.type_expr == 0) { |
| 1358 | return structInitExprRlTy(gz, scope, rl, node, struct_init, ty_inst, .struct_init); | 1347 | return structInitExprRlTy(gz, scope, node, struct_init, ty_inst, .struct_init); |
| 1359 | } | 1348 | } |
| 1360 | const inner_ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr); | 1349 | const inner_ty_inst = try typeExpr(gz, scope, struct_init.ast.type_expr); |
| 1361 | const result = try structInitExprRlTy(gz, scope, rl, node, struct_init, inner_ty_inst, .struct_init); | 1350 | const result = try structInitExprRlTy(gz, scope, node, struct_init, inner_ty_inst, .struct_init); |
| 1362 | return rvalue(gz, scope, rl, result, node); | 1351 | return rvalue(gz, scope, rl, result, node); |
| 1363 | }, | 1352 | }, |
| 1364 | .ptr, .inferred_ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, rl, node, struct_init, ptr_inst), | 1353 | .ptr, .inferred_ptr => |ptr_inst| return structInitExprRlPtr(gz, scope, node, struct_init, ptr_inst), |
| 1365 | .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, rl, node, struct_init, block_gz.rl_ptr), | 1354 | .block_ptr => |block_gz| return structInitExprRlPtr(gz, scope, node, struct_init, block_gz.rl_ptr), |
| 1366 | } | 1355 | } |
| 1367 | } | 1356 | } |
| 1368 | | 1357 | |
| 1369 | fn structInitExprRlNone( | 1358 | fn structInitExprRlNone( |
| 1370 | gz: *GenZir, | 1359 | gz: *GenZir, |
| 1371 | scope: *Scope, | 1360 | scope: *Scope, |
| 1372 | rl: ResultLoc, | | |
| 1373 | node: ast.Node.Index, | 1361 | node: ast.Node.Index, |
| 1374 | struct_init: ast.full.StructInit, | 1362 | struct_init: ast.full.StructInit, |
| 1375 | tag: Zir.Inst.Tag, | 1363 | tag: Zir.Inst.Tag, |
| 1376 | ) InnerError!Zir.Inst.Ref { | 1364 | ) InnerError!Zir.Inst.Ref { |
| 1377 | _ = rl; | | |
| 1378 | const astgen = gz.astgen; | 1365 | const astgen = gz.astgen; |
| 1379 | const gpa = astgen.gpa; | 1366 | const gpa = astgen.gpa; |
| 1380 | const tree = astgen.tree; | 1367 | const tree = astgen.tree; |
| ... | @@ -1405,12 +1392,10 @@ fn structInitExprRlNone( | ... | @@ -1405,12 +1392,10 @@ fn structInitExprRlNone( |
| 1405 | fn structInitExprRlPtr( | 1392 | fn structInitExprRlPtr( |
| 1406 | gz: *GenZir, | 1393 | gz: *GenZir, |
| 1407 | scope: *Scope, | 1394 | scope: *Scope, |
| 1408 | rl: ResultLoc, | | |
| 1409 | node: ast.Node.Index, | 1395 | node: ast.Node.Index, |
| 1410 | struct_init: ast.full.StructInit, | 1396 | struct_init: ast.full.StructInit, |
| 1411 | result_ptr: Zir.Inst.Ref, | 1397 | result_ptr: Zir.Inst.Ref, |
| 1412 | ) InnerError!Zir.Inst.Ref { | 1398 | ) InnerError!Zir.Inst.Ref { |
| 1413 | _ = rl; | | |
| 1414 | const astgen = gz.astgen; | 1399 | const astgen = gz.astgen; |
| 1415 | const gpa = astgen.gpa; | 1400 | const gpa = astgen.gpa; |
| 1416 | const tree = astgen.tree; | 1401 | const tree = astgen.tree; |
| ... | @@ -1441,13 +1426,11 @@ fn structInitExprRlPtr( | ... | @@ -1441,13 +1426,11 @@ fn structInitExprRlPtr( |
| 1441 | fn structInitExprRlTy( | 1426 | fn structInitExprRlTy( |
| 1442 | gz: *GenZir, | 1427 | gz: *GenZir, |
| 1443 | scope: *Scope, | 1428 | scope: *Scope, |
| 1444 | rl: ResultLoc, | | |
| 1445 | node: ast.Node.Index, | 1429 | node: ast.Node.Index, |
| 1446 | struct_init: ast.full.StructInit, | 1430 | struct_init: ast.full.StructInit, |
| 1447 | ty_inst: Zir.Inst.Ref, | 1431 | ty_inst: Zir.Inst.Ref, |
| 1448 | tag: Zir.Inst.Tag, | 1432 | tag: Zir.Inst.Tag, |
| 1449 | ) InnerError!Zir.Inst.Ref { | 1433 | ) InnerError!Zir.Inst.Ref { |
| 1450 | _ = rl; | | |
| 1451 | const astgen = gz.astgen; | 1434 | const astgen = gz.astgen; |
| 1452 | const gpa = astgen.gpa; | 1435 | const gpa = astgen.gpa; |
| 1453 | const tree = astgen.tree; | 1436 | const tree = astgen.tree; |
| ... | @@ -1667,7 +1650,7 @@ fn blockExpr( | ... | @@ -1667,7 +1650,7 @@ fn blockExpr( |
| 1667 | return labeledBlockExpr(gz, scope, rl, block_node, statements, .block); | 1650 | return labeledBlockExpr(gz, scope, rl, block_node, statements, .block); |
| 1668 | } | 1651 | } |
| 1669 | | 1652 | |
| 1670 | try blockExprStmts(gz, scope, block_node, statements); | 1653 | try blockExprStmts(gz, scope, statements); |
| 1671 | return rvalue(gz, scope, rl, .void_value, block_node); | 1654 | return rvalue(gz, scope, rl, .void_value, block_node); |
| 1672 | } | 1655 | } |
| 1673 | | 1656 | |
| ... | @@ -1742,7 +1725,7 @@ fn labeledBlockExpr( | ... | @@ -1742,7 +1725,7 @@ fn labeledBlockExpr( |
| 1742 | defer block_scope.labeled_breaks.deinit(astgen.gpa); | 1725 | defer block_scope.labeled_breaks.deinit(astgen.gpa); |
| 1743 | defer block_scope.labeled_store_to_block_ptr_list.deinit(astgen.gpa); | 1726 | defer block_scope.labeled_store_to_block_ptr_list.deinit(astgen.gpa); |
| 1744 | | 1727 | |
| 1745 | try blockExprStmts(&block_scope, &block_scope.base, block_node, statements); | 1728 | try blockExprStmts(&block_scope, &block_scope.base, statements); |
| 1746 | | 1729 | |
| 1747 | if (!block_scope.label.?.used) { | 1730 | if (!block_scope.label.?.used) { |
| 1748 | return astgen.failTok(label_token, "unused block label", .{}); | 1731 | return astgen.failTok(label_token, "unused block label", .{}); |
| ... | @@ -1784,13 +1767,7 @@ fn labeledBlockExpr( | ... | @@ -1784,13 +1767,7 @@ fn labeledBlockExpr( |
| 1784 | } | 1767 | } |
| 1785 | } | 1768 | } |
| 1786 | | 1769 | |
| 1787 | fn blockExprStmts( | 1770 | fn blockExprStmts(gz: *GenZir, parent_scope: *Scope, statements: []const ast.Node.Index) !void { |
| 1788 | gz: *GenZir, | | |
| 1789 | parent_scope: *Scope, | | |
| 1790 | node: ast.Node.Index, | | |
| 1791 | statements: []const ast.Node.Index, | | |
| 1792 | ) !void { | | |
| 1793 | _ = node; | | |
| 1794 | const astgen = gz.astgen; | 1771 | const astgen = gz.astgen; |
| 1795 | const tree = astgen.tree; | 1772 | const tree = astgen.tree; |
| 1796 | const node_tags = tree.nodes.items(.tag); | 1773 | const node_tags = tree.nodes.items(.tag); |
| ... | @@ -1807,8 +1784,8 @@ fn blockExprStmts( | ... | @@ -1807,8 +1784,8 @@ fn blockExprStmts( |
| 1807 | .simple_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.simpleVarDecl(statement)), | 1784 | .simple_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.simpleVarDecl(statement)), |
| 1808 | .aligned_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.alignedVarDecl(statement)), | 1785 | .aligned_var_decl => scope = try varDecl(gz, scope, statement, &block_arena.allocator, tree.alignedVarDecl(statement)), |
| 1809 | | 1786 | |
| 1810 | .@"defer" => scope = try deferStmt(gz, scope, statement, &block_arena.allocator, .defer_normal), | 1787 | .@"defer" => scope = try makeDeferScope(scope, statement, &block_arena.allocator, .defer_normal), |
| 1811 | .@"errdefer" => scope = try deferStmt(gz, scope, statement, &block_arena.allocator, .defer_error), | 1788 | .@"errdefer" => scope = try makeDeferScope(scope, statement, &block_arena.allocator, .defer_error), |
| 1812 | | 1789 | |
| 1813 | .assign => try assign(gz, scope, statement), | 1790 | .assign => try assign(gz, scope, statement), |
| 1814 | | 1791 | |
| ... | @@ -2205,14 +2182,12 @@ fn checkUsed( | ... | @@ -2205,14 +2182,12 @@ fn checkUsed( |
| 2205 | } | 2182 | } |
| 2206 | } | 2183 | } |
| 2207 | | 2184 | |
| 2208 | fn deferStmt( | 2185 | fn makeDeferScope( |
| 2209 | gz: *GenZir, | | |
| 2210 | scope: *Scope, | 2186 | scope: *Scope, |
| 2211 | node: ast.Node.Index, | 2187 | node: ast.Node.Index, |
| 2212 | block_arena: *Allocator, | 2188 | block_arena: *Allocator, |
| 2213 | scope_tag: Scope.Tag, | 2189 | scope_tag: Scope.Tag, |
| 2214 | ) InnerError!*Scope { | 2190 | ) InnerError!*Scope { |
| 2215 | _ = gz; | | |
| 2216 | const defer_scope = try block_arena.create(Scope.Defer); | 2191 | const defer_scope = try block_arena.create(Scope.Defer); |
| 2217 | defer_scope.* = .{ | 2192 | defer_scope.* = .{ |
| 2218 | .base = .{ .tag = scope_tag }, | 2193 | .base = .{ .tag = scope_tag }, |