| ... | @@ -8050,6 +8050,10 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8050,6 +8050,10 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8050 | const tracy = trace(@src()); | 8050 | const tracy = trace(@src()); |
| 8051 | defer tracy.end(); | 8051 | defer tracy.end(); |
| 8052 | | 8052 | |
| | 8053 | const pt = sema.pt; |
| | 8054 | const zcu = pt.zcu; |
| | 8055 | const ip = &zcu.intern_pool; |
| | 8056 | |
| 8053 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 8057 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 8054 | const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; | 8058 | const extra = sema.code.extraData(Zir.Inst.ArrayTypeSentinel, inst_data.payload_index).data; |
| 8055 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); | 8059 | const len_src = block.src(.{ .node_offset_array_type_len = inst_data.src_node }); |
| ... | @@ -8061,7 +8065,11 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil | ... | @@ -8061,7 +8065,11 @@ fn zirArrayTypeSentinel(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compil |
| 8061 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); | 8065 | const uncasted_sentinel = try sema.resolveInst(extra.sentinel); |
| 8062 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); | 8066 | const sentinel = try sema.coerce(block, elem_type, uncasted_sentinel, sentinel_src); |
| 8063 | const sentinel_val = try sema.resolveConstDefinedValue(block, sentinel_src, sentinel, .{ .simple = .array_sentinel }); | 8067 | const sentinel_val = try sema.resolveConstDefinedValue(block, sentinel_src, sentinel, .{ .simple = .array_sentinel }); |
| 8064 | const array_ty = try sema.pt.arrayType(.{ | 8068 | if (sentinel_val.canMutateComptimeVarState(zcu)) { |
| | 8069 | const sentinel_name = try ip.getOrPutString(sema.gpa, pt.tid, "sentinel", .no_embedded_nulls); |
| | 8070 | return sema.failWithContainsReferenceToComptimeVar(block, sentinel_src, sentinel_name, "sentinel", sentinel_val); |
| | 8071 | } |
| | 8072 | const array_ty = try pt.arrayType(.{ |
| 8065 | .len = len, | 8073 | .len = len, |
| 8066 | .sentinel = sentinel_val.toIntern(), | 8074 | .sentinel = sentinel_val.toIntern(), |
| 8067 | .child = elem_type.toIntern(), | 8075 | .child = elem_type.toIntern(), |
| ... | @@ -19021,6 +19029,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19021,6 +19029,8 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19021 | | 19029 | |
| 19022 | const pt = sema.pt; | 19030 | const pt = sema.pt; |
| 19023 | const zcu = pt.zcu; | 19031 | const zcu = pt.zcu; |
| | 19032 | const ip = &zcu.intern_pool; |
| | 19033 | |
| 19024 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type; | 19034 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].ptr_type; |
| 19025 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); | 19035 | const extra = sema.code.extraData(Zir.Inst.PtrType, inst_data.payload_index); |
| 19026 | const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node }); | 19036 | const elem_ty_src = block.src(.{ .node_offset_ptr_elem = extra.data.src_node }); |
| ... | @@ -19055,6 +19065,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air | ... | @@ -19055,6 +19065,10 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air |
| 19055 | const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src); | 19065 | const coerced = try sema.coerce(block, elem_ty, try sema.resolveInst(ref), sentinel_src); |
| 19056 | const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{ .simple = .pointer_sentinel }); | 19066 | const val = try sema.resolveConstDefinedValue(block, sentinel_src, coerced, .{ .simple = .pointer_sentinel }); |
| 19057 | try checkSentinelType(sema, block, sentinel_src, elem_ty); | 19067 | try checkSentinelType(sema, block, sentinel_src, elem_ty); |
| | 19068 | if (val.canMutateComptimeVarState(zcu)) { |
| | 19069 | const sentinel_name = try ip.getOrPutString(sema.gpa, pt.tid, "sentinel", .no_embedded_nulls); |
| | 19070 | return sema.failWithContainsReferenceToComptimeVar(block, sentinel_src, sentinel_name, "sentinel", val); |
| | 19071 | } |
| 19058 | break :blk val.toIntern(); | 19072 | break :blk val.toIntern(); |
| 19059 | } else .none; | 19073 | } else .none; |
| 19060 | | 19074 | |
| ... | @@ -20580,6 +20594,10 @@ fn zirReify( | ... | @@ -20580,6 +20594,10 @@ fn zirReify( |
| 20580 | const ptr_ty = try pt.singleMutPtrType(elem_ty); | 20594 | const ptr_ty = try pt.singleMutPtrType(elem_ty); |
| 20581 | const sent_val = (try sema.pointerDeref(block, src, sentinel_ptr_val, ptr_ty)).?; | 20595 | const sent_val = (try sema.pointerDeref(block, src, sentinel_ptr_val, ptr_ty)).?; |
| 20582 | try sema.checkSentinelType(block, src, elem_ty); | 20596 | try sema.checkSentinelType(block, src, elem_ty); |
| | 20597 | if (sent_val.canMutateComptimeVarState(zcu)) { |
| | 20598 | const sentinel_name = try ip.getOrPutString(gpa, pt.tid, "sentinel_ptr", .no_embedded_nulls); |
| | 20599 | return sema.failWithContainsReferenceToComptimeVar(block, src, sentinel_name, "sentinel", sent_val); |
| | 20600 | } |
| 20583 | break :s sent_val.toIntern(); | 20601 | break :s sent_val.toIntern(); |
| 20584 | } | 20602 | } |
| 20585 | break :s .none; | 20603 | break :s .none; |
| ... | @@ -20645,7 +20663,12 @@ fn zirReify( | ... | @@ -20645,7 +20663,12 @@ fn zirReify( |
| 20645 | const sentinel = if (sentinel_val.optionalValue(zcu)) |p| blk: { | 20663 | const sentinel = if (sentinel_val.optionalValue(zcu)) |p| blk: { |
| 20646 | const ptr_ty = try pt.singleMutPtrType(child_ty); | 20664 | const ptr_ty = try pt.singleMutPtrType(child_ty); |
| 20647 | try sema.checkSentinelType(block, src, child_ty); | 20665 | try sema.checkSentinelType(block, src, child_ty); |
| 20648 | break :blk (try sema.pointerDeref(block, src, p, ptr_ty)).?; | 20666 | const sentinel = (try sema.pointerDeref(block, src, p, ptr_ty)).?; |
| | 20667 | if (sentinel.canMutateComptimeVarState(zcu)) { |
| | 20668 | const sentinel_name = try ip.getOrPutString(gpa, pt.tid, "sentinel_ptr", .no_embedded_nulls); |
| | 20669 | return sema.failWithContainsReferenceToComptimeVar(block, src, sentinel_name, "sentinel", sentinel); |
| | 20670 | } |
| | 20671 | break :blk sentinel; |
| 20649 | } else null; | 20672 | } else null; |
| 20650 | | 20673 | |
| 20651 | const ty = try pt.arrayType(.{ | 20674 | const ty = try pt.arrayType(.{ |
| ... | @@ -21387,6 +21410,9 @@ fn reifyTuple( | ... | @@ -21387,6 +21410,9 @@ fn reifyTuple( |
| 21387 | src, | 21410 | src, |
| 21388 | .{ .simple = .tuple_field_default_value }, | 21411 | .{ .simple = .tuple_field_default_value }, |
| 21389 | ); | 21412 | ); |
| | 21413 | if (val.canMutateComptimeVarState(zcu)) { |
| | 21414 | return sema.failWithContainsReferenceToComptimeVar(block, src, field_name, "field default value", val); |
| | 21415 | } |
| 21390 | // Resolve the value so that lazy values do not create distinct types. | 21416 | // Resolve the value so that lazy values do not create distinct types. |
| 21391 | break :d (try sema.resolveLazyValue(val)).toIntern(); | 21417 | break :d (try sema.resolveLazyValue(val)).toIntern(); |
| 21392 | } else .none; | 21418 | } else .none; |
| ... | @@ -21500,6 +21526,9 @@ fn reifyStruct( | ... | @@ -21500,6 +21526,9 @@ fn reifyStruct( |
| 21500 | src, | 21526 | src, |
| 21501 | .{ .simple = .struct_field_default_value }, | 21527 | .{ .simple = .struct_field_default_value }, |
| 21502 | ); | 21528 | ); |
| | 21529 | if (val.canMutateComptimeVarState(zcu)) { |
| | 21530 | return sema.failWithContainsReferenceToComptimeVar(block, src, field_name, "field default value", val); |
| | 21531 | } |
| 21503 | // Resolve the value so that lazy values do not create distinct types. | 21532 | // Resolve the value so that lazy values do not create distinct types. |
| 21504 | break :d (try sema.resolveLazyValue(val)).toIntern(); | 21533 | break :d (try sema.resolveLazyValue(val)).toIntern(); |
| 21505 | } else .none; | 21534 | } else .none; |