| ... | @@ -1613,10 +1613,15 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE | ... | @@ -1613,10 +1613,15 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE |
| 1613 | //} | 1613 | //} |
| 1614 | | 1614 | |
| 1615 | // The last one is always `store`. | 1615 | // The last one is always `store`. |
| 1616 | const trash_inst = trash_block.instructions.pop(); | 1616 | const trash_inst = trash_block.instructions.items[trash_block.instructions.items.len - 1]; |
| 1617 | assert(air_tags[trash_inst] == .store); | 1617 | if (air_tags[trash_inst] != .store) { |
| 1618 | assert(trash_inst == sema.air_instructions.len - 1); | 1618 | // no store instruction is generated for zero sized types |
| 1619 | sema.air_instructions.len -= 1; | 1619 | assert((try sema.typeHasOnePossibleValue(block, src, pointee_ty)) != null); |
| | 1620 | } else { |
| | 1621 | trash_block.instructions.items.len -= 1; |
| | 1622 | assert(trash_inst == sema.air_instructions.len - 1); |
| | 1623 | sema.air_instructions.len -= 1; |
| | 1624 | } |
| 1620 | } | 1625 | } |
| 1621 | | 1626 | |
| 1622 | const ptr_ty = try Type.ptr(sema.arena, .{ | 1627 | const ptr_ty = try Type.ptr(sema.arena, .{ |
| ... | @@ -5236,6 +5241,22 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5236,6 +5241,22 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5236 | if (lhs_ty.tag() == .anyerror or rhs_ty.tag() == .anyerror) { | 5241 | if (lhs_ty.tag() == .anyerror or rhs_ty.tag() == .anyerror) { |
| 5237 | return Air.Inst.Ref.anyerror_type; | 5242 | return Air.Inst.Ref.anyerror_type; |
| 5238 | } | 5243 | } |
| | 5244 | |
| | 5245 | if (lhs_ty.castTag(.error_set_inferred)) |payload| { |
| | 5246 | try sema.resolveInferredErrorSet(payload.data); |
| | 5247 | // isAnyError might have changed from a false negative to a true positive after resolution. |
| | 5248 | if (lhs_ty.isAnyError()) { |
| | 5249 | return Air.Inst.Ref.anyerror_type; |
| | 5250 | } |
| | 5251 | } |
| | 5252 | if (rhs_ty.castTag(.error_set_inferred)) |payload| { |
| | 5253 | try sema.resolveInferredErrorSet(payload.data); |
| | 5254 | // isAnyError might have changed from a false negative to a true positive after resolution. |
| | 5255 | if (rhs_ty.isAnyError()) { |
| | 5256 | return Air.Inst.Ref.anyerror_type; |
| | 5257 | } |
| | 5258 | } |
| | 5259 | |
| 5239 | // Resolve both error sets now. | 5260 | // Resolve both error sets now. |
| 5240 | const lhs_names = lhs_ty.errorSetNames(); | 5261 | const lhs_names = lhs_ty.errorSetNames(); |
| 5241 | const rhs_names = rhs_ty.errorSetNames(); | 5262 | const rhs_names = rhs_ty.errorSetNames(); |
| ... | @@ -6809,6 +6830,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError | ... | @@ -6809,6 +6830,10 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError |
| 6809 | } | 6830 | } |
| 6810 | } | 6831 | } |
| 6811 | | 6832 | |
| | 6833 | if (operand_ty.castTag(.error_set_inferred)) |inferred| { |
| | 6834 | try sema.resolveInferredErrorSet(inferred.data); |
| | 6835 | } |
| | 6836 | |
| 6812 | if (operand_ty.isAnyError()) { | 6837 | if (operand_ty.isAnyError()) { |
| 6813 | if (special_prong != .@"else") { | 6838 | if (special_prong != .@"else") { |
| 6814 | return sema.fail( | 6839 | return sema.fail( |
| ... | @@ -14597,6 +14622,12 @@ fn elemPtr( | ... | @@ -14597,6 +14622,12 @@ fn elemPtr( |
| 14597 | }, | 14622 | }, |
| 14598 | .Array => return sema.elemPtrArray(block, array_ptr_src, array_ptr, elem_index, elem_index_src), | 14623 | .Array => return sema.elemPtrArray(block, array_ptr_src, array_ptr, elem_index, elem_index_src), |
| 14599 | .Vector => return sema.fail(block, src, "TODO implement Sema for elemPtr for vector", .{}), | 14624 | .Vector => return sema.fail(block, src, "TODO implement Sema for elemPtr for vector", .{}), |
| | 14625 | .Struct => { |
| | 14626 | // Tuple field access. |
| | 14627 | const index_val = try sema.resolveConstValue(block, elem_index_src, elem_index); |
| | 14628 | const index = @intCast(u32, index_val.toUnsignedInt()); |
| | 14629 | return sema.tupleFieldPtr(block, array_ptr, index, src, elem_index_src); |
| | 14630 | }, |
| 14600 | else => unreachable, | 14631 | else => unreachable, |
| 14601 | } | 14632 | } |
| 14602 | } | 14633 | } |
| ... | @@ -14673,6 +14704,45 @@ fn elemVal( | ... | @@ -14673,6 +14704,45 @@ fn elemVal( |
| 14673 | } | 14704 | } |
| 14674 | } | 14705 | } |
| 14675 | | 14706 | |
| | 14707 | fn tupleFieldPtr( |
| | 14708 | sema: *Sema, |
| | 14709 | block: *Block, |
| | 14710 | tuple_ptr: Air.Inst.Ref, |
| | 14711 | field_index: u32, |
| | 14712 | tuple_src: LazySrcLoc, |
| | 14713 | field_index_src: LazySrcLoc, |
| | 14714 | ) CompileError!Air.Inst.Ref { |
| | 14715 | const tuple_ptr_ty = sema.typeOf(tuple_ptr); |
| | 14716 | const tuple_ty = tuple_ptr_ty.childType(); |
| | 14717 | const tuple_info = tuple_ty.castTag(.tuple).?.data; |
| | 14718 | |
| | 14719 | if (field_index > tuple_info.types.len) { |
| | 14720 | return sema.fail(block, field_index_src, "index {d} outside tuple of length {d}", .{ |
| | 14721 | field_index, tuple_info.types.len, |
| | 14722 | }); |
| | 14723 | } |
| | 14724 | |
| | 14725 | const field_ty = tuple_info.types[field_index]; |
| | 14726 | const ptr_field_ty = try Type.ptr(sema.arena, .{ |
| | 14727 | .pointee_type = field_ty, |
| | 14728 | .mutable = tuple_ptr_ty.ptrIsMutable(), |
| | 14729 | .@"addrspace" = tuple_ptr_ty.ptrAddressSpace(), |
| | 14730 | }); |
| | 14731 | |
| | 14732 | if (try sema.resolveMaybeUndefVal(block, tuple_src, tuple_ptr)) |tuple_ptr_val| { |
| | 14733 | return sema.addConstant( |
| | 14734 | ptr_field_ty, |
| | 14735 | try Value.Tag.field_ptr.create(sema.arena, .{ |
| | 14736 | .container_ptr = tuple_ptr_val, |
| | 14737 | .field_index = field_index, |
| | 14738 | }), |
| | 14739 | ); |
| | 14740 | } |
| | 14741 | |
| | 14742 | try sema.requireRuntimeBlock(block, tuple_src); |
| | 14743 | return block.addStructFieldPtr(tuple_ptr, field_index, ptr_field_ty); |
| | 14744 | } |
| | 14745 | |
| 14676 | fn tupleField( | 14746 | fn tupleField( |
| 14677 | sema: *Sema, | 14747 | sema: *Sema, |
| 14678 | block: *Block, | 14748 | block: *Block, |
| ... | @@ -15273,9 +15343,8 @@ fn coerceInMemoryAllowedErrorSets( | ... | @@ -15273,9 +15343,8 @@ fn coerceInMemoryAllowedErrorSets( |
| 15273 | return .no_match; | 15343 | return .no_match; |
| 15274 | } | 15344 | } |
| 15275 | | 15345 | |
| 15276 | var it = src_data.errors.keyIterator(); | 15346 | for (src_data.errors.keys()) |key| { |
| 15277 | while (it.next()) |name_ptr| { | 15347 | if (!dest_ty.errorSetHasField(key)) { |
| 15278 | if (!dest_ty.errorSetHasField(name_ptr.*)) { | | |
| 15279 | return .no_match; | 15348 | return .no_match; |
| 15280 | } | 15349 | } |
| 15281 | } | 15350 | } |
| ... | @@ -17525,9 +17594,8 @@ fn resolveInferredErrorSet(sema: *Sema, inferred_error_set: *Module.Fn.InferredE | ... | @@ -17525,9 +17594,8 @@ fn resolveInferredErrorSet(sema: *Sema, inferred_error_set: *Module.Fn.InferredE |
| 17525 | try sema.ensureDeclAnalyzed(decl); // To ensure that all dependencies are properly added to the set. | 17594 | try sema.ensureDeclAnalyzed(decl); // To ensure that all dependencies are properly added to the set. |
| 17526 | try sema.resolveInferredErrorSet(other_error_set_ptr.*); | 17595 | try sema.resolveInferredErrorSet(other_error_set_ptr.*); |
| 17527 | | 17596 | |
| 17528 | var error_it = other_error_set_ptr.*.errors.keyIterator(); | 17597 | for (other_error_set_ptr.*.errors.keys()) |key| { |
| 17529 | while (error_it.next()) |entry| { | 17598 | try inferred_error_set.errors.put(sema.gpa, key, {}); |
| 17530 | try inferred_error_set.errors.put(sema.gpa, entry.*, {}); | | |
| 17531 | } | 17599 | } |
| 17532 | if (other_error_set_ptr.*.is_anyerror) | 17600 | if (other_error_set_ptr.*.is_anyerror) |
| 17533 | inferred_error_set.is_anyerror = true; | 17601 | inferred_error_set.is_anyerror = true; |