| ... | ... | @@ -5470,6 +5470,10 @@ fn addStrLitNoAlias(sema: *Sema, bytes: []const u8) CompileError!Air.Inst.Ref { |
| 5470 | 5470 | } |
| 5471 | 5471 | |
| 5472 | 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 { |
| 5473 | 5477 | const mod = sema.mod; |
| 5474 | 5478 | const ptr_ty = (try sema.ptrType(.{ |
| 5475 | 5479 | .child = mod.intern_pool.typeOf(val), |
| ... | ... | @@ -5479,13 +5483,13 @@ fn anonDeclRef(sema: *Sema, val: InternPool.Index) CompileError!Air.Inst.Ref { |
| 5479 | 5483 | .address_space = .generic, |
| 5480 | 5484 | }, |
| 5481 | 5485 | })).toIntern(); |
| 5482 | | return Air.internedToRef(try mod.intern(.{ .ptr = .{ |
| 5486 | return mod.intern(.{ .ptr = .{ |
| 5483 | 5487 | .ty = ptr_ty, |
| 5484 | 5488 | .addr = .{ .anon_decl = .{ |
| 5485 | 5489 | .val = val, |
| 5486 | 5490 | .orig_ty = ptr_ty, |
| 5487 | 5491 | } }, |
| 5488 | | } })); |
| 5492 | } }); |
| 5489 | 5493 | } |
| 5490 | 5494 | |
| 5491 | 5495 | fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -17031,7 +17035,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17031 | 17035 | // is_allowzero: bool, |
| 17032 | 17036 | Value.makeBool(info.flags.is_allowzero).toIntern(), |
| 17033 | 17037 | // sentinel: ?*const anyopaque, |
| 17034 | | (try sema.optRefValue(block, info.child.toType(), switch (info.sentinel) { |
| 17038 | (try sema.optRefValue(switch (info.sentinel) { |
| 17035 | 17039 | .none => null, |
| 17036 | 17040 | else => info.sentinel.toValue(), |
| 17037 | 17041 | })).toIntern(), |
| ... | ... | @@ -17066,7 +17070,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17066 | 17070 | // child: type, |
| 17067 | 17071 | info.elem_type.toIntern(), |
| 17068 | 17072 | // sentinel: ?*const anyopaque, |
| 17069 | | (try sema.optRefValue(block, info.elem_type, info.sentinel)).toIntern(), |
| 17073 | (try sema.optRefValue(info.sentinel)).toIntern(), |
| 17070 | 17074 | }; |
| 17071 | 17075 | return Air.internedToRef((try mod.intern(.{ .un = .{ |
| 17072 | 17076 | .ty = type_info_ty.toIntern(), |
| ... | ... | @@ -17593,7 +17597,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17593 | 17597 | |
| 17594 | 17598 | const is_comptime = field_val != .none; |
| 17595 | 17599 | const opt_default_val = if (is_comptime) field_val.toValue() else null; |
| 17596 | | 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); |
| 17597 | 17601 | const struct_field_fields = .{ |
| 17598 | 17602 | // name: []const u8, |
| 17599 | 17603 | name_val, |
| ... | ... | @@ -17647,7 +17651,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 17647 | 17651 | }; |
| 17648 | 17652 | |
| 17649 | 17653 | const opt_default_val = if (field_init == .none) null else field_init.toValue(); |
| 17650 | | const default_val_ptr = try sema.optRefValue(block, field_ty, opt_default_val); |
| 17654 | const default_val_ptr = try sema.optRefValue(opt_default_val); |
| 17651 | 17655 | const alignment = switch (struct_type.layout) { |
| 17652 | 17656 | .Packed => .none, |
| 17653 | 17657 | else => try sema.structFieldAlignment( |
| ... | ... | @@ -21367,28 +21371,9 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai |
| 21367 | 21371 | const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node }; |
| 21368 | 21372 | const ty = try sema.resolveType(block, ty_src, inst_data.operand); |
| 21369 | 21373 | |
| 21370 | | var anon_decl = try block.startAnonDecl(); |
| 21371 | | defer anon_decl.deinit(); |
| 21372 | | |
| 21373 | 21374 | var bytes = std.ArrayList(u8).init(sema.arena); |
| 21374 | | defer bytes.deinit(); |
| 21375 | 21375 | try ty.print(bytes.writer(), mod); |
| 21376 | | |
| 21377 | | const decl_ty = try mod.arrayType(.{ |
| 21378 | | .len = bytes.items.len, |
| 21379 | | .sentinel = .zero_u8, |
| 21380 | | .child = .u8_type, |
| 21381 | | }); |
| 21382 | | const new_decl = try anon_decl.finish( |
| 21383 | | decl_ty, |
| 21384 | | (try mod.intern(.{ .aggregate = .{ |
| 21385 | | .ty = decl_ty.toIntern(), |
| 21386 | | .storage = .{ .bytes = bytes.items }, |
| 21387 | | } })).toValue(), |
| 21388 | | .none, // default alignment |
| 21389 | | ); |
| 21390 | | |
| 21391 | | return sema.analyzeDeclRef(new_decl); |
| 21376 | return addStrLitNoAlias(sema, bytes.items); |
| 21392 | 21377 | } |
| 21393 | 21378 | |
| 21394 | 21379 | fn zirFrameType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref { |
| ... | ... | @@ -26271,13 +26256,8 @@ fn fieldPtr( |
| 26271 | 26256 | switch (inner_ty.zigTypeTag(mod)) { |
| 26272 | 26257 | .Array => { |
| 26273 | 26258 | if (ip.stringEqlSlice(field_name, "len")) { |
| 26274 | | var anon_decl = try block.startAnonDecl(); |
| 26275 | | defer anon_decl.deinit(); |
| 26276 | | return sema.analyzeDeclRef(try anon_decl.finish( |
| 26277 | | Type.usize, |
| 26278 | | try mod.intValue(Type.usize, inner_ty.arrayLen(mod)), |
| 26279 | | .none, // default alignment |
| 26280 | | )); |
| 26259 | const int_val = try mod.intValue(Type.usize, inner_ty.arrayLen(mod)); |
| 26260 | return anonDeclRef(sema, int_val.toIntern()); |
| 26281 | 26261 | } else { |
| 26282 | 26262 | return sema.fail( |
| 26283 | 26263 | block, |
| ... | ... | @@ -26386,20 +26366,14 @@ fn fieldPtr( |
| 26386 | 26366 | else => unreachable, |
| 26387 | 26367 | } |
| 26388 | 26368 | |
| 26389 | | var anon_decl = try block.startAnonDecl(); |
| 26390 | | defer anon_decl.deinit(); |
| 26391 | 26369 | const error_set_type = if (!child_type.isAnyError(mod)) |
| 26392 | 26370 | child_type |
| 26393 | 26371 | else |
| 26394 | 26372 | try mod.singleErrorSetType(field_name); |
| 26395 | | return sema.analyzeDeclRef(try anon_decl.finish( |
| 26396 | | error_set_type, |
| 26397 | | (try mod.intern(.{ .err = .{ |
| 26398 | | .ty = error_set_type.toIntern(), |
| 26399 | | .name = field_name, |
| 26400 | | } })).toValue(), |
| 26401 | | .none, // default alignment |
| 26402 | | )); |
| 26373 | return anonDeclRef(sema, try mod.intern(.{ .err = .{ |
| 26374 | .ty = error_set_type.toIntern(), |
| 26375 | .name = field_name, |
| 26376 | } })); |
| 26403 | 26377 | }, |
| 26404 | 26378 | .Union => { |
| 26405 | 26379 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| ... | ... | @@ -26411,13 +26385,8 @@ fn fieldPtr( |
| 26411 | 26385 | if (child_type.unionTagType(mod)) |enum_ty| { |
| 26412 | 26386 | if (enum_ty.enumFieldIndex(field_name, mod)) |field_index| { |
| 26413 | 26387 | const field_index_u32: u32 = @intCast(field_index); |
| 26414 | | var anon_decl = try block.startAnonDecl(); |
| 26415 | | defer anon_decl.deinit(); |
| 26416 | | return sema.analyzeDeclRef(try anon_decl.finish( |
| 26417 | | enum_ty, |
| 26418 | | try mod.enumValueFieldIndex(enum_ty, field_index_u32), |
| 26419 | | .none, // default alignment |
| 26420 | | )); |
| 26388 | const idx_val = try mod.enumValueFieldIndex(enum_ty, field_index_u32); |
| 26389 | return anonDeclRef(sema, idx_val.toIntern()); |
| 26421 | 26390 | } |
| 26422 | 26391 | } |
| 26423 | 26392 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| ... | ... | @@ -26432,13 +26401,8 @@ fn fieldPtr( |
| 26432 | 26401 | return sema.failWithBadMemberAccess(block, child_type, field_name_src, field_name); |
| 26433 | 26402 | }; |
| 26434 | 26403 | const field_index_u32: u32 = @intCast(field_index); |
| 26435 | | var anon_decl = try block.startAnonDecl(); |
| 26436 | | defer anon_decl.deinit(); |
| 26437 | | return sema.analyzeDeclRef(try anon_decl.finish( |
| 26438 | | child_type, |
| 26439 | | try mod.enumValueFieldIndex(child_type, field_index_u32), |
| 26440 | | .none, // default alignment |
| 26441 | | )); |
| 26404 | const idx_val = try mod.enumValueFieldIndex(child_type, field_index_u32); |
| 26405 | return anonDeclRef(sema, idx_val.toIntern()); |
| 26442 | 26406 | }, |
| 26443 | 26407 | .Struct, .Opaque => { |
| 26444 | 26408 | if (child_type.getNamespaceIndex(mod).unwrap()) |namespace| { |
| ... | ... | @@ -31607,31 +31571,13 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: InternPool.Index) CompileError!void |
| 31607 | 31571 | }; |
| 31608 | 31572 | } |
| 31609 | 31573 | |
| 31610 | | fn refValue(sema: *Sema, block: *Block, ty: Type, val: Value) !Value { |
| 31611 | | const mod = sema.mod; |
| 31612 | | var anon_decl = try block.startAnonDecl(); |
| 31613 | | defer anon_decl.deinit(); |
| 31614 | | const decl = try anon_decl.finish( |
| 31615 | | ty, |
| 31616 | | val, |
| 31617 | | .none, // default alignment |
| 31618 | | ); |
| 31619 | | try sema.maybeQueueFuncBodyAnalysis(decl); |
| 31620 | | try mod.declareDeclDependency(sema.owner_decl_index, decl); |
| 31621 | | const result = try mod.intern(.{ .ptr = .{ |
| 31622 | | .ty = (try mod.singleConstPtrType(ty)).toIntern(), |
| 31623 | | .addr = .{ .decl = decl }, |
| 31624 | | } }); |
| 31625 | | return result.toValue(); |
| 31626 | | } |
| 31627 | | |
| 31628 | | fn optRefValue(sema: *Sema, block: *Block, ty: Type, opt_val: ?Value) !Value { |
| 31574 | fn optRefValue(sema: *Sema, opt_val: ?Value) !Value { |
| 31629 | 31575 | const mod = sema.mod; |
| 31630 | 31576 | const ptr_anyopaque_ty = try mod.singleConstPtrType(Type.anyopaque); |
| 31631 | 31577 | return (try mod.intern(.{ .opt = .{ |
| 31632 | 31578 | .ty = (try mod.optionalType(ptr_anyopaque_ty.toIntern())).toIntern(), |
| 31633 | 31579 | .val = if (opt_val) |val| (try mod.getCoerced( |
| 31634 | | try sema.refValue(block, ty, val), |
| 31580 | (try sema.refValue(val.toIntern())).toValue(), |
| 31635 | 31581 | ptr_anyopaque_ty, |
| 31636 | 31582 | )).toIntern() else .none, |
| 31637 | 31583 | } })).toValue(); |
| ... | ... | @@ -31693,15 +31639,8 @@ fn analyzeRef( |
| 31693 | 31639 | switch (mod.intern_pool.indexToKey(val.toIntern())) { |
| 31694 | 31640 | .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl), |
| 31695 | 31641 | .func => |func| return sema.analyzeDeclRef(func.owner_decl), |
| 31696 | | else => {}, |
| 31642 | else => return anonDeclRef(sema, val.toIntern()), |
| 31697 | 31643 | } |
| 31698 | | var anon_decl = try block.startAnonDecl(); |
| 31699 | | defer anon_decl.deinit(); |
| 31700 | | return sema.analyzeDeclRef(try anon_decl.finish( |
| 31701 | | operand_ty, |
| 31702 | | val, |
| 31703 | | .none, // default alignment |
| 31704 | | )); |
| 31705 | 31644 | } |
| 31706 | 31645 | |
| 31707 | 31646 | try sema.requireRuntimeBlock(block, src, null); |
| ... | ... | @@ -36786,7 +36725,7 @@ fn analyzeComptimeAlloc( |
| 36786 | 36725 | }, |
| 36787 | 36726 | }); |
| 36788 | 36727 | |
| 36789 | | var anon_decl = try block.startAnonDecl(); |
| 36728 | var anon_decl = try block.startAnonDecl(); // TODO: comptime value mutation without Decl |
| 36790 | 36729 | defer anon_decl.deinit(); |
| 36791 | 36730 | |
| 36792 | 36731 | const decl_index = try anon_decl.finish( |