| ... | ... | @@ -5466,21 +5466,30 @@ fn addStrLitNoAlias(sema: *Sema, bytes: []const u8) CompileError!Air.Inst.Ref { |
| 5466 | 5466 | .ty = array_ty.toIntern(), |
| 5467 | 5467 | .storage = .{ .bytes = bytes }, |
| 5468 | 5468 | } }); |
| 5469 | | const ptr_ty = try sema.ptrType(.{ |
| 5470 | | .child = array_ty.toIntern(), |
| 5469 | return anonDeclRef(sema, val); |
| 5470 | } |
| 5471 | |
| 5472 | fn anonDeclRef(sema: *Sema, val: InternPool.Index) CompileError!Air.Inst.Ref { |
| 5473 | return Air.internedToRef(try refValue(sema, val)); |
| 5474 | } |
| 5475 | |
| 5476 | fn refValue(sema: *Sema, val: InternPool.Index) CompileError!InternPool.Index { |
| 5477 | const mod = sema.mod; |
| 5478 | const ptr_ty = (try sema.ptrType(.{ |
| 5479 | .child = mod.intern_pool.typeOf(val), |
| 5471 | 5480 | .flags = .{ |
| 5472 | 5481 | .alignment = .none, |
| 5473 | 5482 | .is_const = true, |
| 5474 | 5483 | .address_space = .generic, |
| 5475 | 5484 | }, |
| 5476 | | }); |
| 5477 | | return Air.internedToRef((try mod.intern(.{ .ptr = .{ |
| 5478 | | .ty = ptr_ty.toIntern(), |
| 5485 | })).toIntern(); |
| 5486 | return mod.intern(.{ .ptr = .{ |
| 5487 | .ty = ptr_ty, |
| 5479 | 5488 | .addr = .{ .anon_decl = .{ |
| 5480 | 5489 | .val = val, |
| 5481 | | .orig_ty = ptr_ty.toIntern(), |
| 5490 | .orig_ty = ptr_ty, |
| 5482 | 5491 | } }, |
| 5483 | | } }))); |
| 5492 | } }); |
| 5484 | 5493 | } |
| 5485 | 5494 | |
| 5486 | 5495 | fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -10740,7 +10749,7 @@ const SwitchProngAnalysis = struct { |
| 10740 | 10749 | return block.addStructFieldVal(spa.operand, field_index, field_ty); |
| 10741 | 10750 | } |
| 10742 | 10751 | } else if (capture_byref) { |
| 10743 | | return sema.addConstantMaybeRef(block, operand_ty, item_val, true); |
| 10752 | return anonDeclRef(sema, item_val.toIntern()); |
| 10744 | 10753 | } else { |
| 10745 | 10754 | return inline_case_capture; |
| 10746 | 10755 | } |
| ... | ... | @@ -13765,10 +13774,10 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 13765 | 13774 | const coerced_elem_val = try sema.resolveConstValue(block, .unneeded, coerced_elem_val_inst, undefined); |
| 13766 | 13775 | element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod); |
| 13767 | 13776 | } |
| 13768 | | return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{ |
| 13777 | return sema.addConstantMaybeRef(try mod.intern(.{ .aggregate = .{ |
| 13769 | 13778 | .ty = result_ty.toIntern(), |
| 13770 | 13779 | .storage = .{ .elems = element_vals }, |
| 13771 | | } })).toValue(), ptr_addrspace != null); |
| 13780 | } }), ptr_addrspace != null); |
| 13772 | 13781 | } else break :rs rhs_src; |
| 13773 | 13782 | } else lhs_src; |
| 13774 | 13783 | |
| ... | ... | @@ -14034,7 +14043,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 14034 | 14043 | .storage = .{ .elems = element_vals }, |
| 14035 | 14044 | } }); |
| 14036 | 14045 | }; |
| 14037 | | return sema.addConstantMaybeRef(block, result_ty, val.toValue(), ptr_addrspace != null); |
| 14046 | return sema.addConstantMaybeRef(val, ptr_addrspace != null); |
| 14038 | 14047 | } |
| 14039 | 14048 | |
| 14040 | 14049 | try sema.requireRuntimeBlock(block, src, lhs_src); |
| ... | ... | @@ -16724,54 +16733,49 @@ fn zirBuiltinSrc( |
| 16724 | 16733 | const src = LazySrcLoc.nodeOffset(extra.node); |
| 16725 | 16734 | if (sema.func_index == .none) return sema.fail(block, src, "@src outside function", .{}); |
| 16726 | 16735 | const fn_owner_decl = mod.funcOwnerDeclPtr(sema.func_index); |
| 16736 | const ip = &mod.intern_pool; |
| 16737 | const gpa = sema.gpa; |
| 16727 | 16738 | |
| 16728 | | const func_name_val = blk: { |
| 16729 | | var anon_decl = try block.startAnonDecl(); |
| 16730 | | defer anon_decl.deinit(); |
| 16731 | | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 16732 | | const name = try sema.arena.dupe(u8, mod.intern_pool.stringToSlice(fn_owner_decl.name)); |
| 16733 | | const new_decl_ty = try mod.arrayType(.{ |
| 16734 | | .len = name.len, |
| 16739 | const func_name_val = v: { |
| 16740 | // This dupe prevents InternPool string pool memory from being reallocated |
| 16741 | // while a reference exists. |
| 16742 | const bytes = try sema.arena.dupe(u8, ip.stringToSlice(fn_owner_decl.name)); |
| 16743 | const array_ty = try ip.get(gpa, .{ .array_type = .{ |
| 16744 | .len = bytes.len, |
| 16735 | 16745 | .sentinel = .zero_u8, |
| 16736 | 16746 | .child = .u8_type, |
| 16737 | | }); |
| 16738 | | const new_decl = try anon_decl.finish( |
| 16739 | | new_decl_ty, |
| 16740 | | (try mod.intern(.{ .aggregate = .{ |
| 16741 | | .ty = new_decl_ty.toIntern(), |
| 16742 | | .storage = .{ .bytes = name }, |
| 16743 | | } })).toValue(), |
| 16744 | | .none, // default alignment |
| 16745 | | ); |
| 16746 | | break :blk try mod.intern(.{ .ptr = .{ |
| 16747 | } }); |
| 16748 | break :v try ip.get(gpa, .{ .ptr = .{ |
| 16747 | 16749 | .ty = .slice_const_u8_sentinel_0_type, |
| 16748 | | .addr = .{ .decl = new_decl }, |
| 16749 | | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), |
| 16750 | .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(), |
| 16751 | .addr = .{ .anon_decl = .{ |
| 16752 | .orig_ty = .slice_const_u8_sentinel_0_type, |
| 16753 | .val = try ip.get(gpa, .{ .aggregate = .{ |
| 16754 | .ty = array_ty, |
| 16755 | .storage = .{ .bytes = bytes }, |
| 16756 | } }), |
| 16757 | } }, |
| 16750 | 16758 | } }); |
| 16751 | 16759 | }; |
| 16752 | 16760 | |
| 16753 | | const file_name_val = blk: { |
| 16754 | | var anon_decl = try block.startAnonDecl(); |
| 16755 | | defer anon_decl.deinit(); |
| 16761 | const file_name_val = v: { |
| 16756 | 16762 | // The compiler must not call realpath anywhere. |
| 16757 | | const name = try fn_owner_decl.getFileScope(mod).fullPathZ(sema.arena); |
| 16758 | | const new_decl_ty = try mod.arrayType(.{ |
| 16759 | | .len = name.len, |
| 16763 | const bytes = try fn_owner_decl.getFileScope(mod).fullPathZ(sema.arena); |
| 16764 | const array_ty = try ip.get(gpa, .{ .array_type = .{ |
| 16765 | .len = bytes.len, |
| 16760 | 16766 | .sentinel = .zero_u8, |
| 16761 | 16767 | .child = .u8_type, |
| 16762 | | }); |
| 16763 | | const new_decl = try anon_decl.finish( |
| 16764 | | new_decl_ty, |
| 16765 | | (try mod.intern(.{ .aggregate = .{ |
| 16766 | | .ty = new_decl_ty.toIntern(), |
| 16767 | | .storage = .{ .bytes = name }, |
| 16768 | | } })).toValue(), |
| 16769 | | .none, // default alignment |
| 16770 | | ); |
| 16771 | | break :blk try mod.intern(.{ .ptr = .{ |
| 16768 | } }); |
| 16769 | break :v try ip.get(gpa, .{ .ptr = .{ |
| 16772 | 16770 | .ty = .slice_const_u8_sentinel_0_type, |
| 16773 | | .addr = .{ .decl = new_decl }, |
| 16774 | | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), |
| 16771 | .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(), |
| 16772 | .addr = .{ .anon_decl = .{ |
| 16773 | .orig_ty = .slice_const_u8_sentinel_0_type, |
| 16774 | .val = try ip.get(gpa, .{ .aggregate = .{ |
| 16775 | .ty = array_ty, |
| 16776 | .storage = .{ .bytes = bytes }, |
| 16777 | } }), |
| 16778 | } }, |
| 16775 | 16779 | } }); |
| 16776 | 16780 | }; |
| 16777 | 16781 | |
| ... | ... | @@ -16818,10 +16822,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16818 | 16822 | .val = .void_value, |
| 16819 | 16823 | } }))), |
| 16820 | 16824 | .Fn => { |
| 16821 | | // TODO: look into memoizing this result. |
| 16822 | | var params_anon_decl = try block.startAnonDecl(); |
| 16823 | | defer params_anon_decl.deinit(); |
| 16824 | | |
| 16825 | 16825 | const fn_info_decl_index = (try sema.namespaceLookup( |
| 16826 | 16826 | block, |
| 16827 | 16827 | src, |
| ... | ... | @@ -16878,23 +16878,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 16878 | 16878 | .len = param_vals.len, |
| 16879 | 16879 | .child = param_info_ty.toIntern(), |
| 16880 | 16880 | }); |
| 16881 | | const new_decl = try params_anon_decl.finish( |
| 16882 | | new_decl_ty, |
| 16883 | | (try mod.intern(.{ .aggregate = .{ |
| 16884 | | .ty = new_decl_ty.toIntern(), |
| 16885 | | .storage = .{ .elems = param_vals }, |
| 16886 | | } })).toValue(), |
| 16887 | | .none, // default alignment |
| 16888 | | ); |
| 16881 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 16882 | .ty = new_decl_ty.toIntern(), |
| 16883 | .storage = .{ .elems = param_vals }, |
| 16884 | } }); |
| 16885 | const ptr_ty = (try sema.ptrType(.{ |
| 16886 | .child = param_info_ty.toIntern(), |
| 16887 | .flags = .{ |
| 16888 | .size = .Slice, |
| 16889 | .is_const = true, |
| 16890 | }, |
| 16891 | })).toIntern(); |
| 16889 | 16892 | break :v try mod.intern(.{ .ptr = .{ |
| 16890 | | .ty = (try sema.ptrType(.{ |
| 16891 | | .child = param_info_ty.toIntern(), |
| 16892 | | .flags = .{ |
| 16893 | | .size = .Slice, |
| 16894 | | .is_const = true, |
| 16895 | | }, |
| 16896 | | })).toIntern(), |
| 16897 | | .addr = .{ .decl = new_decl }, |
| 16893 | .ty = ptr_ty, |
| 16894 | .addr = .{ .anon_decl = .{ |
| 16895 | .orig_ty = ptr_ty, |
| 16896 | .val = new_decl_val, |
| 16897 | } }, |
| 16898 | 16898 | .len = (try mod.intValue(Type.usize, param_vals.len)).toIntern(), |
| 16899 | 16899 | } }); |
| 16900 | 16900 | }; |
| ... | ... | @@ -17035,7 +17035,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17035 | 17035 | // is_allowzero: bool, |
| 17036 | 17036 | Value.makeBool(info.flags.is_allowzero).toIntern(), |
| 17037 | 17037 | // sentinel: ?*const anyopaque, |
| 17038 | | (try sema.optRefValue(block, info.child.toType(), switch (info.sentinel) { |
| 17038 | (try sema.optRefValue(switch (info.sentinel) { |
| 17039 | 17039 | .none => null, |
| 17040 | 17040 | else => info.sentinel.toValue(), |
| 17041 | 17041 | })).toIntern(), |
| ... | ... | @@ -17070,7 +17070,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17070 | 17070 | // child: type, |
| 17071 | 17071 | info.elem_type.toIntern(), |
| 17072 | 17072 | // sentinel: ?*const anyopaque, |
| 17073 | | (try sema.optRefValue(block, info.elem_type, info.sentinel)).toIntern(), |
| 17073 | (try sema.optRefValue(info.sentinel)).toIntern(), |
| 17074 | 17074 | }; |
| 17075 | 17075 | return Air.internedToRef((try mod.intern(.{ .un = .{ |
| 17076 | 17076 | .ty = type_info_ty.toIntern(), |
| ... | ... | @@ -17139,9 +17139,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17139 | 17139 | } }))); |
| 17140 | 17140 | }, |
| 17141 | 17141 | .ErrorSet => { |
| 17142 | | var fields_anon_decl = try block.startAnonDecl(); |
| 17143 | | defer fields_anon_decl.deinit(); |
| 17144 | | |
| 17145 | 17142 | // Get the Error type |
| 17146 | 17143 | const error_field_ty = t: { |
| 17147 | 17144 | const set_field_ty_decl_index = (try sema.namespaceLookup( |
| ... | ... | @@ -17170,23 +17167,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17170 | 17167 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 17171 | 17168 | const name = try sema.arena.dupe(u8, ip.stringToSlice(names.get(ip)[i])); |
| 17172 | 17169 | const name_val = v: { |
| 17173 | | var anon_decl = try block.startAnonDecl(); |
| 17174 | | defer anon_decl.deinit(); |
| 17175 | 17170 | const new_decl_ty = try mod.arrayType(.{ |
| 17176 | 17171 | .len = name.len, |
| 17177 | 17172 | .child = .u8_type, |
| 17178 | 17173 | }); |
| 17179 | | const new_decl = try anon_decl.finish( |
| 17180 | | new_decl_ty, |
| 17181 | | (try mod.intern(.{ .aggregate = .{ |
| 17182 | | .ty = new_decl_ty.toIntern(), |
| 17183 | | .storage = .{ .bytes = name }, |
| 17184 | | } })).toValue(), |
| 17185 | | .none, // default alignment |
| 17186 | | ); |
| 17174 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17175 | .ty = new_decl_ty.toIntern(), |
| 17176 | .storage = .{ .bytes = name }, |
| 17177 | } }); |
| 17187 | 17178 | break :v try mod.intern(.{ .ptr = .{ |
| 17188 | 17179 | .ty = .slice_const_u8_type, |
| 17189 | | .addr = .{ .decl = new_decl }, |
| 17180 | .addr = .{ .anon_decl = .{ |
| 17181 | .val = new_decl_val, |
| 17182 | .orig_ty = .slice_const_u8_type, |
| 17183 | } }, |
| 17190 | 17184 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), |
| 17191 | 17185 | } }); |
| 17192 | 17186 | }; |
| ... | ... | @@ -17219,17 +17213,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17219 | 17213 | .len = vals.len, |
| 17220 | 17214 | .child = error_field_ty.toIntern(), |
| 17221 | 17215 | }); |
| 17222 | | const new_decl = try fields_anon_decl.finish( |
| 17223 | | array_errors_ty, |
| 17224 | | (try mod.intern(.{ .aggregate = .{ |
| 17225 | | .ty = array_errors_ty.toIntern(), |
| 17226 | | .storage = .{ .elems = vals }, |
| 17227 | | } })).toValue(), |
| 17228 | | .none, // default alignment |
| 17229 | | ); |
| 17216 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17217 | .ty = array_errors_ty.toIntern(), |
| 17218 | .storage = .{ .elems = vals }, |
| 17219 | } }); |
| 17230 | 17220 | break :v try mod.intern(.{ .ptr = .{ |
| 17231 | 17221 | .ty = slice_errors_ty.toIntern(), |
| 17232 | | .addr = .{ .decl = new_decl }, |
| 17222 | .addr = .{ .anon_decl = .{ |
| 17223 | .orig_ty = slice_errors_ty.toIntern(), |
| 17224 | .val = new_decl_val, |
| 17225 | } }, |
| 17233 | 17226 | .len = (try mod.intValue(Type.usize, vals.len)).toIntern(), |
| 17234 | 17227 | } }); |
| 17235 | 17228 | } else .none; |
| ... | ... | @@ -17275,12 +17268,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17275 | 17268 | } }))); |
| 17276 | 17269 | }, |
| 17277 | 17270 | .Enum => { |
| 17278 | | // TODO: look into memoizing this result. |
| 17279 | 17271 | const is_exhaustive = Value.makeBool(ip.indexToKey(ty.toIntern()).enum_type.tag_mode != .nonexhaustive); |
| 17280 | 17272 | |
| 17281 | | var fields_anon_decl = try block.startAnonDecl(); |
| 17282 | | defer fields_anon_decl.deinit(); |
| 17283 | | |
| 17284 | 17273 | const enum_field_ty = t: { |
| 17285 | 17274 | const enum_field_ty_decl_index = (try sema.namespaceLookup( |
| 17286 | 17275 | block, |
| ... | ... | @@ -17308,23 +17297,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17308 | 17297 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 17309 | 17298 | const name = try sema.arena.dupe(u8, ip.stringToSlice(enum_type.names.get(ip)[i])); |
| 17310 | 17299 | const name_val = v: { |
| 17311 | | var anon_decl = try block.startAnonDecl(); |
| 17312 | | defer anon_decl.deinit(); |
| 17313 | 17300 | const new_decl_ty = try mod.arrayType(.{ |
| 17314 | 17301 | .len = name.len, |
| 17315 | 17302 | .child = .u8_type, |
| 17316 | 17303 | }); |
| 17317 | | const new_decl = try anon_decl.finish( |
| 17318 | | new_decl_ty, |
| 17319 | | (try mod.intern(.{ .aggregate = .{ |
| 17320 | | .ty = new_decl_ty.toIntern(), |
| 17321 | | .storage = .{ .bytes = name }, |
| 17322 | | } })).toValue(), |
| 17323 | | .none, // default alignment |
| 17324 | | ); |
| 17304 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17305 | .ty = new_decl_ty.toIntern(), |
| 17306 | .storage = .{ .bytes = name }, |
| 17307 | } }); |
| 17325 | 17308 | break :v try mod.intern(.{ .ptr = .{ |
| 17326 | 17309 | .ty = .slice_const_u8_type, |
| 17327 | | .addr = .{ .decl = new_decl }, |
| 17310 | .addr = .{ .anon_decl = .{ |
| 17311 | .val = new_decl_val, |
| 17312 | .orig_ty = .slice_const_u8_type, |
| 17313 | } }, |
| 17328 | 17314 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), |
| 17329 | 17315 | } }); |
| 17330 | 17316 | }; |
| ... | ... | @@ -17346,23 +17332,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17346 | 17332 | .len = enum_field_vals.len, |
| 17347 | 17333 | .child = enum_field_ty.toIntern(), |
| 17348 | 17334 | }); |
| 17349 | | const new_decl = try fields_anon_decl.finish( |
| 17350 | | fields_array_ty, |
| 17351 | | (try mod.intern(.{ .aggregate = .{ |
| 17352 | | .ty = fields_array_ty.toIntern(), |
| 17353 | | .storage = .{ .elems = enum_field_vals }, |
| 17354 | | } })).toValue(), |
| 17355 | | .none, // default alignment |
| 17356 | | ); |
| 17335 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17336 | .ty = fields_array_ty.toIntern(), |
| 17337 | .storage = .{ .elems = enum_field_vals }, |
| 17338 | } }); |
| 17339 | const ptr_ty = (try sema.ptrType(.{ |
| 17340 | .child = enum_field_ty.toIntern(), |
| 17341 | .flags = .{ |
| 17342 | .size = .Slice, |
| 17343 | .is_const = true, |
| 17344 | }, |
| 17345 | })).toIntern(); |
| 17357 | 17346 | break :v try mod.intern(.{ .ptr = .{ |
| 17358 | | .ty = (try sema.ptrType(.{ |
| 17359 | | .child = enum_field_ty.toIntern(), |
| 17360 | | .flags = .{ |
| 17361 | | .size = .Slice, |
| 17362 | | .is_const = true, |
| 17363 | | }, |
| 17364 | | })).toIntern(), |
| 17365 | | .addr = .{ .decl = new_decl }, |
| 17347 | .ty = ptr_ty, |
| 17348 | .addr = .{ .anon_decl = .{ |
| 17349 | .val = new_decl_val, |
| 17350 | .orig_ty = ptr_ty, |
| 17351 | } }, |
| 17366 | 17352 | .len = (try mod.intValue(Type.usize, enum_field_vals.len)).toIntern(), |
| 17367 | 17353 | } }); |
| 17368 | 17354 | }; |
| ... | ... | @@ -17402,11 +17388,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17402 | 17388 | } }))); |
| 17403 | 17389 | }, |
| 17404 | 17390 | .Union => { |
| 17405 | | // TODO: look into memoizing this result. |
| 17406 | | |
| 17407 | | var fields_anon_decl = try block.startAnonDecl(); |
| 17408 | | defer fields_anon_decl.deinit(); |
| 17409 | | |
| 17410 | 17391 | const type_union_ty = t: { |
| 17411 | 17392 | const type_union_ty_decl_index = (try sema.namespaceLookup( |
| 17412 | 17393 | block, |
| ... | ... | @@ -17444,23 +17425,20 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17444 | 17425 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 17445 | 17426 | const name = try sema.arena.dupe(u8, ip.stringToSlice(union_obj.field_names.get(ip)[i])); |
| 17446 | 17427 | const name_val = v: { |
| 17447 | | var anon_decl = try block.startAnonDecl(); |
| 17448 | | defer anon_decl.deinit(); |
| 17449 | 17428 | const new_decl_ty = try mod.arrayType(.{ |
| 17450 | 17429 | .len = name.len, |
| 17451 | 17430 | .child = .u8_type, |
| 17452 | 17431 | }); |
| 17453 | | const new_decl = try anon_decl.finish( |
| 17454 | | new_decl_ty, |
| 17455 | | (try mod.intern(.{ .aggregate = .{ |
| 17456 | | .ty = new_decl_ty.toIntern(), |
| 17457 | | .storage = .{ .bytes = name }, |
| 17458 | | } })).toValue(), |
| 17459 | | .none, // default alignment |
| 17460 | | ); |
| 17432 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17433 | .ty = new_decl_ty.toIntern(), |
| 17434 | .storage = .{ .bytes = name }, |
| 17435 | } }); |
| 17461 | 17436 | break :v try mod.intern(.{ .ptr = .{ |
| 17462 | 17437 | .ty = .slice_const_u8_type, |
| 17463 | | .addr = .{ .decl = new_decl }, |
| 17438 | .addr = .{ .anon_decl = .{ |
| 17439 | .val = new_decl_val, |
| 17440 | .orig_ty = .slice_const_u8_type, |
| 17441 | } }, |
| 17464 | 17442 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), |
| 17465 | 17443 | } }); |
| 17466 | 17444 | }; |
| ... | ... | @@ -17490,23 +17468,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17490 | 17468 | .len = union_field_vals.len, |
| 17491 | 17469 | .child = union_field_ty.toIntern(), |
| 17492 | 17470 | }); |
| 17493 | | const new_decl = try fields_anon_decl.finish( |
| 17494 | | array_fields_ty, |
| 17495 | | (try mod.intern(.{ .aggregate = .{ |
| 17496 | | .ty = array_fields_ty.toIntern(), |
| 17497 | | .storage = .{ .elems = union_field_vals }, |
| 17498 | | } })).toValue(), |
| 17499 | | .none, // default alignment |
| 17500 | | ); |
| 17471 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17472 | .ty = array_fields_ty.toIntern(), |
| 17473 | .storage = .{ .elems = union_field_vals }, |
| 17474 | } }); |
| 17475 | const ptr_ty = (try sema.ptrType(.{ |
| 17476 | .child = union_field_ty.toIntern(), |
| 17477 | .flags = .{ |
| 17478 | .size = .Slice, |
| 17479 | .is_const = true, |
| 17480 | }, |
| 17481 | })).toIntern(); |
| 17501 | 17482 | break :v try mod.intern(.{ .ptr = .{ |
| 17502 | | .ty = (try sema.ptrType(.{ |
| 17503 | | .child = union_field_ty.toIntern(), |
| 17504 | | .flags = .{ |
| 17505 | | .size = .Slice, |
| 17506 | | .is_const = true, |
| 17507 | | }, |
| 17508 | | })).toIntern(), |
| 17509 | | .addr = .{ .decl = new_decl }, |
| 17483 | .ty = ptr_ty, |
| 17484 | .addr = .{ .anon_decl = .{ |
| 17485 | .orig_ty = ptr_ty, |
| 17486 | .val = new_decl_val, |
| 17487 | } }, |
| 17510 | 17488 | .len = (try mod.intValue(Type.usize, union_field_vals.len)).toIntern(), |
| 17511 | 17489 | } }); |
| 17512 | 17490 | }; |
| ... | ... | @@ -17552,11 +17530,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17552 | 17530 | } }))); |
| 17553 | 17531 | }, |
| 17554 | 17532 | .Struct => { |
| 17555 | | // TODO: look into memoizing this result. |
| 17556 | | |
| 17557 | | var fields_anon_decl = try block.startAnonDecl(); |
| 17558 | | defer fields_anon_decl.deinit(); |
| 17559 | | |
| 17560 | 17533 | const type_struct_ty = t: { |
| 17561 | 17534 | const type_struct_ty_decl_index = (try sema.namespaceLookup( |
| 17562 | 17535 | block, |
| ... | ... | @@ -17596,8 +17569,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17596 | 17569 | const field_ty = anon_struct_type.types.get(ip)[i]; |
| 17597 | 17570 | const field_val = anon_struct_type.values.get(ip)[i]; |
| 17598 | 17571 | const name_val = v: { |
| 17599 | | var anon_decl = try block.startAnonDecl(); |
| 17600 | | defer anon_decl.deinit(); |
| 17601 | 17572 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 17602 | 17573 | const bytes = if (tuple.names.len != 0) |
| 17603 | 17574 | // https://github.com/ziglang/zig/issues/15709 |
| ... | ... | @@ -17608,17 +17579,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17608 | 17579 | .len = bytes.len, |
| 17609 | 17580 | .child = .u8_type, |
| 17610 | 17581 | }); |
| 17611 | | const new_decl = try anon_decl.finish( |
| 17612 | | new_decl_ty, |
| 17613 | | (try mod.intern(.{ .aggregate = .{ |
| 17614 | | .ty = new_decl_ty.toIntern(), |
| 17615 | | .storage = .{ .bytes = bytes }, |
| 17616 | | } })).toValue(), |
| 17617 | | .none, // default alignment |
| 17618 | | ); |
| 17582 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17583 | .ty = new_decl_ty.toIntern(), |
| 17584 | .storage = .{ .bytes = bytes }, |
| 17585 | } }); |
| 17619 | 17586 | break :v try mod.intern(.{ .ptr = .{ |
| 17620 | 17587 | .ty = .slice_const_u8_type, |
| 17621 | | .addr = .{ .decl = new_decl }, |
| 17588 | .addr = .{ .anon_decl = .{ |
| 17589 | .val = new_decl_val, |
| 17590 | .orig_ty = .slice_const_u8_type, |
| 17591 | } }, |
| 17622 | 17592 | .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(), |
| 17623 | 17593 | } }); |
| 17624 | 17594 | }; |
| ... | ... | @@ -17627,7 +17597,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17627 | 17597 | |
| 17628 | 17598 | const is_comptime = field_val != .none; |
| 17629 | 17599 | const opt_default_val = if (is_comptime) field_val.toValue() else null; |
| 17630 | | const default_val_ptr = try sema.optRefValue(block, field_ty.toType(), opt_default_val); |
| 17600 | const default_val_ptr = try sema.optRefValue(opt_default_val); |
| 17631 | 17601 | const struct_field_fields = .{ |
| 17632 | 17602 | // name: []const u8, |
| 17633 | 17603 | name_val, |
| ... | ... | @@ -17662,29 +17632,26 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17662 | 17632 | const field_init = struct_type.fieldInit(ip, i); |
| 17663 | 17633 | const field_is_comptime = struct_type.fieldIsComptime(ip, i); |
| 17664 | 17634 | const name_val = v: { |
| 17665 | | var anon_decl = try block.startAnonDecl(); |
| 17666 | | defer anon_decl.deinit(); |
| 17667 | 17635 | const new_decl_ty = try mod.arrayType(.{ |
| 17668 | 17636 | .len = name.len, |
| 17669 | 17637 | .child = .u8_type, |
| 17670 | 17638 | }); |
| 17671 | | const new_decl = try anon_decl.finish( |
| 17672 | | new_decl_ty, |
| 17673 | | (try mod.intern(.{ .aggregate = .{ |
| 17674 | | .ty = new_decl_ty.toIntern(), |
| 17675 | | .storage = .{ .bytes = name }, |
| 17676 | | } })).toValue(), |
| 17677 | | .none, // default alignment |
| 17678 | | ); |
| 17639 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17640 | .ty = new_decl_ty.toIntern(), |
| 17641 | .storage = .{ .bytes = name }, |
| 17642 | } }); |
| 17679 | 17643 | break :v try mod.intern(.{ .ptr = .{ |
| 17680 | 17644 | .ty = .slice_const_u8_type, |
| 17681 | | .addr = .{ .decl = new_decl }, |
| 17645 | .addr = .{ .anon_decl = .{ |
| 17646 | .val = new_decl_val, |
| 17647 | .orig_ty = .slice_const_u8_type, |
| 17648 | } }, |
| 17682 | 17649 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), |
| 17683 | 17650 | } }); |
| 17684 | 17651 | }; |
| 17685 | 17652 | |
| 17686 | 17653 | const opt_default_val = if (field_init == .none) null else field_init.toValue(); |
| 17687 | | const default_val_ptr = try sema.optRefValue(block, field_ty, opt_default_val); |
| 17654 | const default_val_ptr = try sema.optRefValue(opt_default_val); |
| 17688 | 17655 | const alignment = switch (struct_type.layout) { |
| 17689 | 17656 | .Packed => .none, |
| 17690 | 17657 | else => try sema.structFieldAlignment( |
| ... | ... | @@ -17718,23 +17685,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17718 | 17685 | .len = struct_field_vals.len, |
| 17719 | 17686 | .child = struct_field_ty.toIntern(), |
| 17720 | 17687 | }); |
| 17721 | | const new_decl = try fields_anon_decl.finish( |
| 17722 | | array_fields_ty, |
| 17723 | | (try mod.intern(.{ .aggregate = .{ |
| 17724 | | .ty = array_fields_ty.toIntern(), |
| 17725 | | .storage = .{ .elems = struct_field_vals }, |
| 17726 | | } })).toValue(), |
| 17727 | | .none, // default alignment |
| 17728 | | ); |
| 17688 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17689 | .ty = array_fields_ty.toIntern(), |
| 17690 | .storage = .{ .elems = struct_field_vals }, |
| 17691 | } }); |
| 17692 | const ptr_ty = (try sema.ptrType(.{ |
| 17693 | .child = struct_field_ty.toIntern(), |
| 17694 | .flags = .{ |
| 17695 | .size = .Slice, |
| 17696 | .is_const = true, |
| 17697 | }, |
| 17698 | })).toIntern(); |
| 17729 | 17699 | break :v try mod.intern(.{ .ptr = .{ |
| 17730 | | .ty = (try sema.ptrType(.{ |
| 17731 | | .child = struct_field_ty.toIntern(), |
| 17732 | | .flags = .{ |
| 17733 | | .size = .Slice, |
| 17734 | | .is_const = true, |
| 17735 | | }, |
| 17736 | | })).toIntern(), |
| 17737 | | .addr = .{ .decl = new_decl }, |
| 17700 | .ty = ptr_ty, |
| 17701 | .addr = .{ .anon_decl = .{ |
| 17702 | .orig_ty = ptr_ty, |
| 17703 | .val = new_decl_val, |
| 17704 | } }, |
| 17738 | 17705 | .len = (try mod.intValue(Type.usize, struct_field_vals.len)).toIntern(), |
| 17739 | 17706 | } }); |
| 17740 | 17707 | }; |
| ... | ... | @@ -17786,8 +17753,6 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17786 | 17753 | } }))); |
| 17787 | 17754 | }, |
| 17788 | 17755 | .Opaque => { |
| 17789 | | // TODO: look into memoizing this result. |
| 17790 | | |
| 17791 | 17756 | const type_opaque_ty = t: { |
| 17792 | 17757 | const type_opaque_ty_decl_index = (try sema.namespaceLookup( |
| 17793 | 17758 | block, |
| ... | ... | @@ -17832,9 +17797,6 @@ fn typeInfoDecls( |
| 17832 | 17797 | const mod = sema.mod; |
| 17833 | 17798 | const gpa = sema.gpa; |
| 17834 | 17799 | |
| 17835 | | var decls_anon_decl = try block.startAnonDecl(); |
| 17836 | | defer decls_anon_decl.deinit(); |
| 17837 | | |
| 17838 | 17800 | const declaration_ty = t: { |
| 17839 | 17801 | const declaration_ty_decl_index = (try sema.namespaceLookup( |
| 17840 | 17802 | block, |
| ... | ... | @@ -17864,23 +17826,23 @@ fn typeInfoDecls( |
| 17864 | 17826 | .len = decl_vals.items.len, |
| 17865 | 17827 | .child = declaration_ty.toIntern(), |
| 17866 | 17828 | }); |
| 17867 | | const new_decl = try decls_anon_decl.finish( |
| 17868 | | array_decl_ty, |
| 17869 | | (try mod.intern(.{ .aggregate = .{ |
| 17870 | | .ty = array_decl_ty.toIntern(), |
| 17871 | | .storage = .{ .elems = decl_vals.items }, |
| 17872 | | } })).toValue(), |
| 17873 | | .none, // default alignment |
| 17874 | | ); |
| 17829 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17830 | .ty = array_decl_ty.toIntern(), |
| 17831 | .storage = .{ .elems = decl_vals.items }, |
| 17832 | } }); |
| 17833 | const ptr_ty = (try sema.ptrType(.{ |
| 17834 | .child = declaration_ty.toIntern(), |
| 17835 | .flags = .{ |
| 17836 | .size = .Slice, |
| 17837 | .is_const = true, |
| 17838 | }, |
| 17839 | })).toIntern(); |
| 17875 | 17840 | return try mod.intern(.{ .ptr = .{ |
| 17876 | | .ty = (try sema.ptrType(.{ |
| 17877 | | .child = declaration_ty.toIntern(), |
| 17878 | | .flags = .{ |
| 17879 | | .size = .Slice, |
| 17880 | | .is_const = true, |
| 17881 | | }, |
| 17882 | | })).toIntern(), |
| 17883 | | .addr = .{ .decl = new_decl }, |
| 17841 | .ty = ptr_ty, |
| 17842 | .addr = .{ .anon_decl = .{ |
| 17843 | .orig_ty = ptr_ty, |
| 17844 | .val = new_decl_val, |
| 17845 | } }, |
| 17884 | 17846 | .len = (try mod.intValue(Type.usize, decl_vals.items.len)).toIntern(), |
| 17885 | 17847 | } }); |
| 17886 | 17848 | } |
| ... | ... | @@ -17909,25 +17871,22 @@ fn typeInfoNamespaceDecls( |
| 17909 | 17871 | } |
| 17910 | 17872 | if (decl.kind != .named or !decl.is_pub) continue; |
| 17911 | 17873 | const name_val = v: { |
| 17912 | | var anon_decl = try block.startAnonDecl(); |
| 17913 | | defer anon_decl.deinit(); |
| 17914 | 17874 | // TODO: write something like getCoercedInts to avoid needing to dupe |
| 17915 | 17875 | const name = try sema.arena.dupe(u8, ip.stringToSlice(decl.name)); |
| 17916 | 17876 | const new_decl_ty = try mod.arrayType(.{ |
| 17917 | 17877 | .len = name.len, |
| 17918 | 17878 | .child = .u8_type, |
| 17919 | 17879 | }); |
| 17920 | | const new_decl = try anon_decl.finish( |
| 17921 | | new_decl_ty, |
| 17922 | | (try mod.intern(.{ .aggregate = .{ |
| 17923 | | .ty = new_decl_ty.toIntern(), |
| 17924 | | .storage = .{ .bytes = name }, |
| 17925 | | } })).toValue(), |
| 17926 | | .none, // default alignment |
| 17927 | | ); |
| 17880 | const new_decl_val = try mod.intern(.{ .aggregate = .{ |
| 17881 | .ty = new_decl_ty.toIntern(), |
| 17882 | .storage = .{ .bytes = name }, |
| 17883 | } }); |
| 17928 | 17884 | break :v try mod.intern(.{ .ptr = .{ |
| 17929 | 17885 | .ty = .slice_const_u8_type, |
| 17930 | | .addr = .{ .decl = new_decl }, |
| 17886 | .addr = .{ .anon_decl = .{ |
| 17887 | .orig_ty = .slice_const_u8_type, |
| 17888 | .val = new_decl_val, |
| 17889 | } }, |
| 17931 | 17890 | .len = (try mod.intValue(Type.usize, name.len)).toIntern(), |
| 17932 | 17891 | } }); |
| 17933 | 17892 | }; |
| ... | ... | @@ -19072,10 +19031,7 @@ fn zirStructInitEmptyResult(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is |
| 19072 | 19031 | |
| 19073 | 19032 | if (is_byref) { |
| 19074 | 19033 | const init_val = (try sema.resolveValue(init_ref)).?; |
| 19075 | | var anon_decl = try block.startAnonDecl(); |
| 19076 | | defer anon_decl.deinit(); |
| 19077 | | const decl = try anon_decl.finish(init_ty, init_val, .none); |
| 19078 | | return sema.analyzeDeclRef(decl); |
| 19034 | return anonDeclRef(sema, init_val.toIntern()); |
| 19079 | 19035 | } else { |
| 19080 | 19036 | return init_ref; |
| 19081 | 19037 | } |
| ... | ... | @@ -19298,7 +19254,7 @@ fn zirStructInit( |
| 19298 | 19254 | } })).toValue(); |
| 19299 | 19255 | const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src); |
| 19300 | 19256 | const final_val = (try sema.resolveValue(final_val_inst)).?; |
| 19301 | | return sema.addConstantMaybeRef(block, resolved_ty, final_val, is_ref); |
| 19257 | return sema.addConstantMaybeRef(final_val.toIntern(), is_ref); |
| 19302 | 19258 | } |
| 19303 | 19259 | |
| 19304 | 19260 | if (try sema.typeRequiresComptime(resolved_ty)) { |
| ... | ... | @@ -19458,7 +19414,7 @@ fn finishStructInit( |
| 19458 | 19414 | } }); |
| 19459 | 19415 | const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val), init_src); |
| 19460 | 19416 | const final_val = (try sema.resolveValue(final_val_inst)).?; |
| 19461 | | return sema.addConstantMaybeRef(block, result_ty, final_val, is_ref); |
| 19417 | return sema.addConstantMaybeRef(final_val.toIntern(), is_ref); |
| 19462 | 19418 | }; |
| 19463 | 19419 | |
| 19464 | 19420 | if (try sema.typeRequiresComptime(struct_ty)) { |
| ... | ... | @@ -19611,7 +19567,7 @@ fn structInitAnon( |
| 19611 | 19567 | .ty = tuple_ty, |
| 19612 | 19568 | .storage = .{ .elems = values }, |
| 19613 | 19569 | } }); |
| 19614 | | return sema.addConstantMaybeRef(block, tuple_ty.toType(), tuple_val.toValue(), is_ref); |
| 19570 | return sema.addConstantMaybeRef(tuple_val, is_ref); |
| 19615 | 19571 | }; |
| 19616 | 19572 | |
| 19617 | 19573 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| ... | ... | @@ -19777,7 +19733,8 @@ fn zirArrayInit( |
| 19777 | 19733 | .storage = .{ .elems = elem_vals }, |
| 19778 | 19734 | } }); |
| 19779 | 19735 | const result_ref = try sema.coerce(block, result_ty, Air.internedToRef(arr_val), src); |
| 19780 | | return sema.addConstantMaybeRef(block, result_ty, (try sema.resolveValue(result_ref)).?, is_ref); |
| 19736 | const result_val = (try sema.resolveValue(result_ref)).?; |
| 19737 | return sema.addConstantMaybeRef(result_val.toIntern(), is_ref); |
| 19781 | 19738 | }; |
| 19782 | 19739 | |
| 19783 | 19740 | sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) { |
| ... | ... | @@ -19896,7 +19853,7 @@ fn arrayInitAnon( |
| 19896 | 19853 | .ty = tuple_ty, |
| 19897 | 19854 | .storage = .{ .elems = values }, |
| 19898 | 19855 | } }); |
| 19899 | | return sema.addConstantMaybeRef(block, tuple_ty.toType(), tuple_val.toValue(), is_ref); |
| 19856 | return sema.addConstantMaybeRef(tuple_val, is_ref); |
| 19900 | 19857 | }; |
| 19901 | 19858 | |
| 19902 | 19859 | try sema.requireRuntimeBlock(block, src, runtime_src); |
| ... | ... | @@ -19931,23 +19888,8 @@ fn arrayInitAnon( |
| 19931 | 19888 | return block.addAggregateInit(tuple_ty.toType(), element_refs); |
| 19932 | 19889 | } |
| 19933 | 19890 | |
| 19934 | | fn addConstantMaybeRef( |
| 19935 | | sema: *Sema, |
| 19936 | | block: *Block, |
| 19937 | | ty: Type, |
| 19938 | | val: Value, |
| 19939 | | is_ref: bool, |
| 19940 | | ) !Air.Inst.Ref { |
| 19941 | | if (!is_ref) return Air.internedToRef(val.toIntern()); |
| 19942 | | |
| 19943 | | var anon_decl = try block.startAnonDecl(); |
| 19944 | | defer anon_decl.deinit(); |
| 19945 | | const decl = try anon_decl.finish( |
| 19946 | | ty, |
| 19947 | | val, |
| 19948 | | .none, // default alignment |
| 19949 | | ); |
| 19950 | | return sema.analyzeDeclRef(decl); |
| 19891 | fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.Inst.Ref { |
| 19892 | return if (is_ref) anonDeclRef(sema, val) else Air.internedToRef(val); |
| 19951 | 19893 | } |
| 19952 | 19894 | |
| 19953 | 19895 | fn zirFieldTypeRef(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -21429,28 +21371,9 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21429 | 21371 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 21430 | 21372 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 21431 | 21373 | |
| 21432 | | var anon_decl = try block.startAnonDecl(); |
| 21433 | | defer anon_decl.deinit(); |
| 21434 | | |
| 21435 | 21374 | var bytes = std.ArrayList(u8).init(sema.arena); |
| 21436 | | defer bytes.deinit(); |
| 21437 | 21375 | try ty.print(bytes.writer(), mod); |
| 21438 | | |
| 21439 | | const decl_ty = try mod.arrayType(.{ |
| 21440 | | .len = bytes.items.len, |
| 21441 | | .sentinel = .zero_u8, |
| 21442 | | .child = .u8_type, |
| 21443 | | }); |
| 21444 | | const new_decl = try anon_decl.finish( |
| 21445 | | decl_ty, |
| 21446 | | (try mod.intern(.{ .aggregate = .{ |
| 21447 | | .ty = decl_ty.toIntern(), |
| 21448 | | .storage = .{ .bytes = bytes.items }, |
| 21449 | | } })).toValue(), |
| 21450 | | .none, // default alignment |
| 21451 | | ); |
| 21452 | | |
| 21453 | | return sema.analyzeDeclRef(new_decl); |
| 21376 | return addStrLitNoAlias(sema, bytes.items); |
| 21454 | 21377 | } |
| 21455 | 21378 | |
| 21456 | 21379 | fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -26333,13 +26256,8 @@ fn fieldPtr( |
| 26333 | 26256 | switch (inner_ty.zigTypeTag(mod)) { |
| 26334 | 26257 | .Array => { |
| 26335 | 26258 | if (ip.stringEqlSlice(field_name, "len")) { |
| 26336 | | var anon_decl = try block.startAnonDecl(); |
| 26337 | | defer anon_decl.deinit(); |
| 26338 | | return sema.analyzeDeclRef(try anon_decl.finish( |
| 26339 | | Type.usize, |
| 26340 | | try mod.intValue(Type.usize, inner_ty.arrayLen(mod)), |
| 26341 | | .none, // default alignment |
| 26342 | | )); |
| 26259 | const int_val = try mod.intValue(Type.usize, inner_ty.arrayLen(mod)); |
| 26260 | return anonDeclRef(sema, int_val.toIntern()); |
| 26343 | 26261 | } else { |
| 26344 | 26262 | return sema.fail( |
| 26345 | 26263 | block, |
| ... | ... | @@ -26448,20 +26366,14 @@ fn fieldPtr( |
| 26448 | 26366 | else => unreachable, |
| 26449 | 26367 | } |
| 26450 | 26368 | |
| 26451 | | var anon_decl = try block.startAnonDecl(); |
| 26452 | | defer anon_decl.deinit(); |
| 26453 | 26369 | const error_set_type = if (!child_type.isAnyError(mod)) |
| 26454 | 26370 | child_type |
| 26455 | 26371 | else |
| 26456 | 26372 | try mod.singleErrorSetType(field_name); |
| 26457 | | return sema.analyzeDeclRef(try anon_decl.finish( |
| 26458 | | error_set_type, |
| 26459 | | (try mod.intern(.{ .err = .{ |
| 26460 | | .ty = error_set_type.toIntern(), |
| 26461 | | .name = field_name, |
| 26462 | | } })).toValue(), |
| 26463 | | .none, // default alignment |
| 26464 | | )); |
| 26373 | return anonDeclRef(sema, try mod.intern(.{ .err = .{ |
| 26374 | .ty = error_set_type.toIntern(), |
| 26375 | .name = field_name, |
| 26376 | } })); |
| 26465 | 26377 | }, |
| 26466 | 26378 | .Union => { |
| 26467 | 26379 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| ... | ... | @@ -26473,13 +26385,8 @@ fn fieldPtr( |
| 26473 | 26385 | if (child_type.unionTagType(mod)) |enum_ty| { |
| 26474 | 26386 | if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| { |
| 26475 | 26387 | const field_index_u32: u32 = @intCast(field_index); |
| 26476 | | var anon_decl = try block.startAnonDecl(); |
| 26477 | | defer anon_decl.deinit(); |
| 26478 | | return sema.analyzeDeclRef(try anon_decl.finish( |
| 26479 | | enum_ty, |
| 26480 | | try mod.enumValueFieldIndex(enum_ty, field_index_u32), |
| 26481 | | .none, // default alignment |
| 26482 | | )); |
| 26388 | const idx_val = try mod.enumValueFieldIndex(enum_ty, field_index_u32); |
| 26389 | return anonDeclRef(sema, idx_val.toIntern()); |
| 26483 | 26390 | } |
| 26484 | 26391 | } |
| 26485 | 26392 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| ... | ... | @@ -26494,13 +26401,8 @@ fn fieldPtr( |
| 26494 | 26401 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 26495 | 26402 | }; |
| 26496 | 26403 | const field_index_u32: u32 = @intCast(field_index); |
| 26497 | | var anon_decl = try block.startAnonDecl(); |
| 26498 | | defer anon_decl.deinit(); |
| 26499 | | return sema.analyzeDeclRef(try anon_decl.finish( |
| 26500 | | child_type, |
| 26501 | | try mod.enumValueFieldIndex(child_type, field_index_u32), |
| 26502 | | .none, // default alignment |
| 26503 | | )); |
| 26404 | const idx_val = try mod.enumValueFieldIndex(child_type, field_index_u32); |
| 26405 | return anonDeclRef(sema, idx_val.toIntern()); |
| 26504 | 26406 | }, |
| 26505 | 26407 | .Struct, .Opaque => { |
| 26506 | 26408 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| ... | ... | @@ -31669,31 +31571,13 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: InternPool.Index) CompileError!void |
| 31669 | 31571 | }; |
| 31670 | 31572 | } |
| 31671 | 31573 | |
| 31672 | | fn refValue(sema: *Sema, block: *Block, ty: Type, val: Value) !Value { |
| 31673 | | const mod = sema.mod; |
| 31674 | | var anon_decl = try block.startAnonDecl(); |
| 31675 | | defer anon_decl.deinit(); |
| 31676 | | const decl = try anon_decl.finish( |
| 31677 | | ty, |
| 31678 | | val, |
| 31679 | | .none, // default alignment |
| 31680 | | ); |
| 31681 | | try sema.maybeQueueFuncBodyAnalysis(decl); |
| 31682 | | try mod.declareDeclDependency(sema.owner_decl_index, decl); |
| 31683 | | const result = try mod.intern(.{ .ptr = .{ |
| 31684 | | .ty = (try mod.singleConstPtrType(ty)).toIntern(), |
| 31685 | | .addr = .{ .decl = decl }, |
| 31686 | | } }); |
| 31687 | | return result.toValue(); |
| 31688 | | } |
| 31689 | | |
| 31690 | | fn optRefValue(sema: *Sema, block: *Block, ty: Type, opt_val: ?Value) !Value { |
| 31574 | fn optRefValue(sema: *Sema, opt_val: ?Value) !Value { |
| 31691 | 31575 | const mod = sema.mod; |
| 31692 | 31576 | const ptr_anyopaque_ty = try mod.singleConstPtrType(Type.anyopaque); |
| 31693 | 31577 | return (try mod.intern(.{ .opt = .{ |
| 31694 | 31578 | .ty = (try mod.optionalType(ptr_anyopaque_ty.toIntern())).toIntern(), |
| 31695 | 31579 | .val = if (opt_val) |val| (try mod.getCoerced( |
| 31696 | | try sema.refValue(block, ty, val), |
| 31580 | (try sema.refValue(val.toIntern())).toValue(), |
| 31697 | 31581 | ptr_anyopaque_ty, |
| 31698 | 31582 | )).toIntern() else .none, |
| 31699 | 31583 | } })).toValue(); |
| ... | ... | @@ -31755,15 +31639,8 @@ fn analyzeRef( |
| 31755 | 31639 | switch (mod.intern_pool.indexToKey(val.toIntern())) { |
| 31756 | 31640 | .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl), |
| 31757 | 31641 | .func => |func| return sema.analyzeDeclRef(func.owner_decl), |
| 31758 | | else => {}, |
| 31642 | else => return anonDeclRef(sema, val.toIntern()), |
| 31759 | 31643 | } |
| 31760 | | var anon_decl = try block.startAnonDecl(); |
| 31761 | | defer anon_decl.deinit(); |
| 31762 | | return sema.analyzeDeclRef(try anon_decl.finish( |
| 31763 | | operand_ty, |
| 31764 | | val, |
| 31765 | | .none, // default alignment |
| 31766 | | )); |
| 31767 | 31644 | } |
| 31768 | 31645 | |
| 31769 | 31646 | try sema.requireRuntimeBlock(block, src, null); |
| ... | ... | @@ -36848,7 +36725,7 @@ fn analyzeComptimeAlloc( |
| 36848 | 36725 | }, |
| 36849 | 36726 | }); |
| 36850 | 36727 | |
| 36851 | | var anon_decl = try block.startAnonDecl(); |
| 36728 | var anon_decl = try block.startAnonDecl(); // TODO: comptime value mutation without Decl |
| 36852 | 36729 | defer anon_decl.deinit(); |
| 36853 | 36730 | |
| 36854 | 36731 | const decl_index = try anon_decl.finish( |