| ... | ... | @@ -1610,8 +1610,7 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerE |
| 1610 | 1610 | .body = undefined, |
| 1611 | 1611 | }; |
| 1612 | 1612 | |
| 1613 | | var child_block = parent_block.makeSubBlock(); |
| 1614 | | child_block.label = Scope.Block.Label{ |
| 1613 | var label: Scope.Block.Label = .{ |
| 1615 | 1614 | .zir_block = inst, |
| 1616 | 1615 | .merges = .{ |
| 1617 | 1616 | .results = .{}, |
| ... | ... | @@ -1619,6 +1618,8 @@ fn zirLoop(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) InnerE |
| 1619 | 1618 | .block_inst = block_inst, |
| 1620 | 1619 | }, |
| 1621 | 1620 | }; |
| 1621 | var child_block = parent_block.makeSubBlock(); |
| 1622 | child_block.label = &label; |
| 1622 | 1623 | const merges = &child_block.label.?.merges; |
| 1623 | 1624 | |
| 1624 | 1625 | defer child_block.instructions.deinit(sema.gpa); |
| ... | ... | @@ -1689,20 +1690,21 @@ fn zirBlock(sema: *Sema, parent_block: *Scope.Block, inst: Zir.Inst.Index) Inner |
| 1689 | 1690 | .body = undefined, |
| 1690 | 1691 | }; |
| 1691 | 1692 | |
| 1693 | var label: Scope.Block.Label = .{ |
| 1694 | .zir_block = inst, |
| 1695 | .merges = .{ |
| 1696 | .results = .{}, |
| 1697 | .br_list = .{}, |
| 1698 | .block_inst = block_inst, |
| 1699 | }, |
| 1700 | }; |
| 1701 | |
| 1692 | 1702 | var child_block: Scope.Block = .{ |
| 1693 | 1703 | .parent = parent_block, |
| 1694 | 1704 | .sema = sema, |
| 1695 | 1705 | .src_decl = parent_block.src_decl, |
| 1696 | 1706 | .instructions = .{}, |
| 1697 | | // TODO @as here is working around a stage1 miscompilation bug :( |
| 1698 | | .label = @as(?Scope.Block.Label, Scope.Block.Label{ |
| 1699 | | .zir_block = inst, |
| 1700 | | .merges = .{ |
| 1701 | | .results = .{}, |
| 1702 | | .br_list = .{}, |
| 1703 | | .block_inst = block_inst, |
| 1704 | | }, |
| 1705 | | }), |
| 1707 | .label = &label, |
| 1706 | 1708 | .inlining = parent_block.inlining, |
| 1707 | 1709 | .is_comptime = parent_block.is_comptime, |
| 1708 | 1710 | }; |
| ... | ... | @@ -1895,7 +1897,7 @@ fn zirBreak(sema: *Sema, start_block: *Scope.Block, inst: Zir.Inst.Index) InnerE |
| 1895 | 1897 | |
| 1896 | 1898 | var block = start_block; |
| 1897 | 1899 | while (true) { |
| 1898 | | if (block.label) |*label| { |
| 1900 | if (block.label) |label| { |
| 1899 | 1901 | if (label.zir_block == zir_block) { |
| 1900 | 1902 | // Here we add a br instruction, but we over-allocate a little bit |
| 1901 | 1903 | // (if necessary) to make it possible to convert the instruction into |
| ... | ... | @@ -2084,26 +2086,38 @@ fn analyzeCall( |
| 2084 | 2086 | .block_inst = block_inst, |
| 2085 | 2087 | }, |
| 2086 | 2088 | }; |
| 2087 | | const callee_zir = module_fn.owner_decl.namespace.file_scope.zir; |
| 2088 | | var inline_sema: Sema = .{ |
| 2089 | | .mod = sema.mod, |
| 2090 | | .gpa = sema.mod.gpa, |
| 2091 | | .arena = sema.arena, |
| 2092 | | .code = callee_zir, |
| 2093 | | .inst_map = try sema.gpa.alloc(*ir.Inst, callee_zir.instructions.len), |
| 2094 | | .owner_decl = sema.owner_decl, |
| 2095 | | .namespace = sema.owner_decl.namespace, |
| 2096 | | .owner_func = sema.owner_func, |
| 2097 | | .func = module_fn, |
| 2098 | | .param_inst_list = casted_args, |
| 2099 | | .branch_quota = sema.branch_quota, |
| 2100 | | .branch_count = sema.branch_count, |
| 2101 | | }; |
| 2102 | | defer sema.gpa.free(inline_sema.inst_map); |
| 2089 | // In order to save a bit of stack space, directly modify Sema rather |
| 2090 | // than create a child one. |
| 2091 | const parent_zir = sema.code; |
| 2092 | sema.code = module_fn.owner_decl.namespace.file_scope.zir; |
| 2093 | defer sema.code = parent_zir; |
| 2094 | |
| 2095 | const parent_inst_map = sema.inst_map; |
| 2096 | sema.inst_map = try sema.gpa.alloc(*ir.Inst, sema.code.instructions.len); |
| 2097 | defer { |
| 2098 | sema.gpa.free(sema.inst_map); |
| 2099 | sema.inst_map = parent_inst_map; |
| 2100 | } |
| 2101 | |
| 2102 | const parent_namespace = sema.namespace; |
| 2103 | sema.namespace = module_fn.owner_decl.namespace; |
| 2104 | defer sema.namespace = parent_namespace; |
| 2105 | |
| 2106 | const parent_func = sema.func; |
| 2107 | sema.func = module_fn; |
| 2108 | defer sema.func = parent_func; |
| 2109 | |
| 2110 | const parent_param_inst_list = sema.param_inst_list; |
| 2111 | sema.param_inst_list = casted_args; |
| 2112 | defer sema.param_inst_list = parent_param_inst_list; |
| 2113 | |
| 2114 | const parent_next_arg_index = sema.next_arg_index; |
| 2115 | sema.next_arg_index = 0; |
| 2116 | defer sema.next_arg_index = parent_next_arg_index; |
| 2103 | 2117 | |
| 2104 | 2118 | var child_block: Scope.Block = .{ |
| 2105 | 2119 | .parent = null, |
| 2106 | | .sema = &inline_sema, |
| 2120 | .sema = sema, |
| 2107 | 2121 | .src_decl = module_fn.owner_decl, |
| 2108 | 2122 | .instructions = .{}, |
| 2109 | 2123 | .label = null, |
| ... | ... | @@ -2117,16 +2131,13 @@ fn analyzeCall( |
| 2117 | 2131 | defer merges.results.deinit(sema.gpa); |
| 2118 | 2132 | defer merges.br_list.deinit(sema.gpa); |
| 2119 | 2133 | |
| 2120 | | try inline_sema.emitBackwardBranch(&child_block, call_src); |
| 2134 | try sema.emitBackwardBranch(&child_block, call_src); |
| 2121 | 2135 | |
| 2122 | 2136 | // This will have return instructions analyzed as break instructions to |
| 2123 | 2137 | // the block_inst above. |
| 2124 | | try inline_sema.analyzeFnBody(&child_block, module_fn.zir_body_inst); |
| 2138 | try sema.analyzeFnBody(&child_block, module_fn.zir_body_inst); |
| 2125 | 2139 | |
| 2126 | | const result = try inline_sema.analyzeBlockBody(block, call_src, &child_block, merges); |
| 2127 | | |
| 2128 | | sema.branch_quota = inline_sema.branch_quota; |
| 2129 | | sema.branch_count = inline_sema.branch_count; |
| 2140 | const result = try sema.analyzeBlockBody(block, call_src, &child_block, merges); |
| 2130 | 2141 | |
| 2131 | 2142 | break :res result; |
| 2132 | 2143 | } else res: { |
| ... | ... | @@ -3797,20 +3808,21 @@ fn analyzeSwitch( |
| 3797 | 3808 | .body = undefined, |
| 3798 | 3809 | }; |
| 3799 | 3810 | |
| 3811 | var label: Scope.Block.Label = .{ |
| 3812 | .zir_block = switch_inst, |
| 3813 | .merges = .{ |
| 3814 | .results = .{}, |
| 3815 | .br_list = .{}, |
| 3816 | .block_inst = block_inst, |
| 3817 | }, |
| 3818 | }; |
| 3819 | |
| 3800 | 3820 | var child_block: Scope.Block = .{ |
| 3801 | 3821 | .parent = block, |
| 3802 | 3822 | .sema = sema, |
| 3803 | 3823 | .src_decl = block.src_decl, |
| 3804 | 3824 | .instructions = .{}, |
| 3805 | | // TODO @as here is working around a stage1 miscompilation bug :( |
| 3806 | | .label = @as(?Scope.Block.Label, Scope.Block.Label{ |
| 3807 | | .zir_block = switch_inst, |
| 3808 | | .merges = .{ |
| 3809 | | .results = .{}, |
| 3810 | | .br_list = .{}, |
| 3811 | | .block_inst = block_inst, |
| 3812 | | }, |
| 3813 | | }), |
| 3825 | .label = &label, |
| 3814 | 3826 | .inlining = block.inlining, |
| 3815 | 3827 | .is_comptime = block.is_comptime, |
| 3816 | 3828 | }; |