| ... | ... | @@ -984,17 +984,17 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr |
| 984 | 984 | |
| 985 | 985 | .fn_proto_simple => { |
| 986 | 986 | var params: [1]Ast.Node.Index = undefined; |
| 987 | | return fnProtoExpr(gz, scope, rl, tree.fnProtoSimple(&params, node)); |
| 987 | return fnProtoExpr(gz, scope, rl, node, tree.fnProtoSimple(&params, node)); |
| 988 | 988 | }, |
| 989 | 989 | .fn_proto_multi => { |
| 990 | | return fnProtoExpr(gz, scope, rl, tree.fnProtoMulti(node)); |
| 990 | return fnProtoExpr(gz, scope, rl, node, tree.fnProtoMulti(node)); |
| 991 | 991 | }, |
| 992 | 992 | .fn_proto_one => { |
| 993 | 993 | var params: [1]Ast.Node.Index = undefined; |
| 994 | | return fnProtoExpr(gz, scope, rl, tree.fnProtoOne(&params, node)); |
| 994 | return fnProtoExpr(gz, scope, rl, node, tree.fnProtoOne(&params, node)); |
| 995 | 995 | }, |
| 996 | 996 | .fn_proto => { |
| 997 | | return fnProtoExpr(gz, scope, rl, tree.fnProto(node)); |
| 997 | return fnProtoExpr(gz, scope, rl, node, tree.fnProto(node)); |
| 998 | 998 | }, |
| 999 | 999 | } |
| 1000 | 1000 | } |
| ... | ... | @@ -1101,6 +1101,7 @@ fn fnProtoExpr( |
| 1101 | 1101 | gz: *GenZir, |
| 1102 | 1102 | scope: *Scope, |
| 1103 | 1103 | rl: ResultLoc, |
| 1104 | node: Ast.Node.Index, |
| 1104 | 1105 | fn_proto: Ast.full.FnProto, |
| 1105 | 1106 | ) InnerError!Zir.Inst.Ref { |
| 1106 | 1107 | const astgen = gz.astgen; |
| ... | ... | @@ -1113,6 +1114,11 @@ fn fnProtoExpr( |
| 1113 | 1114 | }; |
| 1114 | 1115 | assert(!is_extern); |
| 1115 | 1116 | |
| 1117 | var block_scope = gz.makeSubBlock(scope); |
| 1118 | defer block_scope.unstack(); |
| 1119 | |
| 1120 | const block_inst = try gz.makeBlockInst(.block_inline, node); |
| 1121 | |
| 1116 | 1122 | const is_var_args = is_var_args: { |
| 1117 | 1123 | var param_type_i: usize = 0; |
| 1118 | 1124 | var it = fn_proto.iterate(tree.*); |
| ... | ... | @@ -1144,11 +1150,11 @@ fn fnProtoExpr( |
| 1144 | 1150 | .param_anytype_comptime |
| 1145 | 1151 | else |
| 1146 | 1152 | .param_anytype; |
| 1147 | | _ = try gz.addStrTok(tag, param_name, name_token); |
| 1153 | _ = try block_scope.addStrTok(tag, param_name, name_token); |
| 1148 | 1154 | } else { |
| 1149 | 1155 | const param_type_node = param.type_expr; |
| 1150 | 1156 | assert(param_type_node != 0); |
| 1151 | | var param_gz = gz.makeSubBlock(scope); |
| 1157 | var param_gz = block_scope.makeSubBlock(scope); |
| 1152 | 1158 | defer param_gz.unstack(); |
| 1153 | 1159 | const param_type = try expr(&param_gz, scope, coerced_type_rl, param_type_node); |
| 1154 | 1160 | const param_inst_expected = @intCast(u32, astgen.instructions.len + 1); |
| ... | ... | @@ -1156,7 +1162,7 @@ fn fnProtoExpr( |
| 1156 | 1162 | const main_tokens = tree.nodes.items(.main_token); |
| 1157 | 1163 | const name_token = param.name_token orelse main_tokens[param_type_node]; |
| 1158 | 1164 | const tag: Zir.Inst.Tag = if (is_comptime) .param_comptime else .param; |
| 1159 | | const param_inst = try gz.addParam(&param_gz, tag, name_token, param_name); |
| 1165 | const param_inst = try block_scope.addParam(&param_gz, tag, name_token, param_name); |
| 1160 | 1166 | assert(param_inst_expected == param_inst); |
| 1161 | 1167 | } |
| 1162 | 1168 | } |
| ... | ... | @@ -1164,7 +1170,7 @@ fn fnProtoExpr( |
| 1164 | 1170 | }; |
| 1165 | 1171 | |
| 1166 | 1172 | const align_inst: Zir.Inst.Ref = if (fn_proto.ast.align_expr == 0) .none else inst: { |
| 1167 | | break :inst try expr(gz, scope, align_rl, fn_proto.ast.align_expr); |
| 1173 | break :inst try expr(&block_scope, scope, align_rl, fn_proto.ast.align_expr); |
| 1168 | 1174 | }; |
| 1169 | 1175 | |
| 1170 | 1176 | if (fn_proto.ast.addrspace_expr != 0) { |
| ... | ... | @@ -1177,7 +1183,7 @@ fn fnProtoExpr( |
| 1177 | 1183 | |
| 1178 | 1184 | const cc: Zir.Inst.Ref = if (fn_proto.ast.callconv_expr != 0) |
| 1179 | 1185 | try expr( |
| 1180 | | gz, |
| 1186 | &block_scope, |
| 1181 | 1187 | scope, |
| 1182 | 1188 | .{ .ty = .calling_convention_type }, |
| 1183 | 1189 | fn_proto.ast.callconv_expr, |
| ... | ... | @@ -1190,14 +1196,14 @@ fn fnProtoExpr( |
| 1190 | 1196 | if (is_inferred_error) { |
| 1191 | 1197 | return astgen.failTok(maybe_bang, "function prototype may not have inferred error set", .{}); |
| 1192 | 1198 | } |
| 1193 | | var ret_gz = gz.makeSubBlock(scope); |
| 1199 | var ret_gz = block_scope.makeSubBlock(scope); |
| 1194 | 1200 | defer ret_gz.unstack(); |
| 1195 | 1201 | const ret_ty = try expr(&ret_gz, scope, coerced_type_rl, fn_proto.ast.return_type); |
| 1196 | 1202 | const ret_br = try ret_gz.addBreak(.break_inline, 0, ret_ty); |
| 1197 | 1203 | |
| 1198 | | const result = try gz.addFunc(.{ |
| 1204 | const result = try block_scope.addFunc(.{ |
| 1199 | 1205 | .src_node = fn_proto.ast.proto_node, |
| 1200 | | .param_block = 0, |
| 1206 | .param_block = block_inst, |
| 1201 | 1207 | .ret_gz = &ret_gz, |
| 1202 | 1208 | .ret_br = ret_br, |
| 1203 | 1209 | .body_gz = null, |
| ... | ... | @@ -1209,7 +1215,12 @@ fn fnProtoExpr( |
| 1209 | 1215 | .is_test = false, |
| 1210 | 1216 | .is_extern = false, |
| 1211 | 1217 | }); |
| 1212 | | return rvalue(gz, rl, result, fn_proto.ast.proto_node); |
| 1218 | |
| 1219 | _ = try block_scope.addBreak(.break_inline, block_inst, result); |
| 1220 | try block_scope.setBlockBody(block_inst); |
| 1221 | try gz.instructions.append(astgen.gpa, block_inst); |
| 1222 | |
| 1223 | return rvalue(gz, rl, indexToRef(block_inst), fn_proto.ast.proto_node); |
| 1213 | 1224 | } |
| 1214 | 1225 | |
| 1215 | 1226 | fn arrayInitExpr( |