| author | |
| committer | |
| log | 95e83afa98c5af89c6e5f40d559eb54c6c31a54e |
| tree | f1616f0a6a546a0ff7434b56b6efd1d0a3213c0f |
| parent | 5a142dfa5651ec21792de211a6e9341c31ab4dbb |
This is a property which solely belongs to pointers to functions,
not to the functions themselves. This cannot be properly represented by
stage 2 at the moment, as type with zigTypeTag() == .Fn is overloaded for
for function pointers and function prototypes.10 files changed, 179 insertions(+), 208 deletions(-)
lib/std/builtin.zig-1| ... | ... | @@ -365,7 +365,6 @@ pub const TypeInfo = union(enum) { |
| 365 | 365 | pub const Fn = struct { |
| 366 | 366 | calling_convention: CallingConvention, |
| 367 | 367 | alignment: comptime_int, |
| 368 | address_space: AddressSpace, | |
| 369 | 368 | is_generic: bool, |
| 370 | 369 | is_var_args: bool, |
| 371 | 370 | return_type: ?type, |
src/AstGen.zig+4-14| ... | ... | @@ -1117,9 +1117,9 @@ fn fnProtoExpr( |
| 1117 | 1117 | break :inst try expr(gz, scope, align_rl, fn_proto.ast.align_expr); |
| 1118 | 1118 | }; |
| 1119 | 1119 | |
| 1120 | const addrspace_inst: Zir.Inst.Ref = if (fn_proto.ast.addrspace_expr == 0) .none else inst: { | |
| 1121 | break :inst try expr(gz, scope, .{ .ty = .address_space_type }, fn_proto.ast.addrspace_expr); | |
| 1122 | }; | |
| 1120 | if (fn_proto.ast.addrspace_expr != 0) { | |
| 1121 | return astgen.failNode(fn_proto.ast.addrspace_expr, "addrspace not allowed on function prototypes", .{}); | |
| 1122 | } | |
| 1123 | 1123 | |
| 1124 | 1124 | if (fn_proto.ast.section_expr != 0) { |
| 1125 | 1125 | return astgen.failNode(fn_proto.ast.section_expr, "linksection not allowed on function prototypes", .{}); |
| ... | ... | @@ -1153,7 +1153,6 @@ fn fnProtoExpr( |
| 1153 | 1153 | .body = &[0]Zir.Inst.Index{}, |
| 1154 | 1154 | .cc = cc, |
| 1155 | 1155 | .align_inst = align_inst, |
| 1156 | .addrspace_inst = addrspace_inst, | |
| 1157 | 1156 | .lib_name = 0, |
| 1158 | 1157 | .is_var_args = is_var_args, |
| 1159 | 1158 | .is_inferred_error = false, |
| ... | ... | @@ -3089,7 +3088,6 @@ fn fnDecl( |
| 3089 | 3088 | .body = &[0]Zir.Inst.Index{}, |
| 3090 | 3089 | .cc = cc, |
| 3091 | 3090 | .align_inst = .none, // passed in the per-decl data |
| 3092 | .addrspace_inst = .none, // passed in the per-decl data | |
| 3093 | 3091 | .lib_name = lib_name, |
| 3094 | 3092 | .is_var_args = is_var_args, |
| 3095 | 3093 | .is_inferred_error = false, |
| ... | ... | @@ -3129,7 +3127,6 @@ fn fnDecl( |
| 3129 | 3127 | .body = fn_gz.instructions.items, |
| 3130 | 3128 | .cc = cc, |
| 3131 | 3129 | .align_inst = .none, // passed in the per-decl data |
| 3132 | .addrspace_inst = .none, // passed in the per-decl data | |
| 3133 | 3130 | .lib_name = lib_name, |
| 3134 | 3131 | .is_var_args = is_var_args, |
| 3135 | 3132 | .is_inferred_error = is_inferred_error, |
| ... | ... | @@ -3481,7 +3478,6 @@ fn testDecl( |
| 3481 | 3478 | .body = fn_block.instructions.items, |
| 3482 | 3479 | .cc = .none, |
| 3483 | 3480 | .align_inst = .none, |
| 3484 | .addrspace_inst = .none, | |
| 3485 | 3481 | .lib_name = 0, |
| 3486 | 3482 | .is_var_args = false, |
| 3487 | 3483 | .is_inferred_error = true, |
| ... | ... | @@ -9217,7 +9213,6 @@ const GenZir = struct { |
| 9217 | 9213 | ret_br: Zir.Inst.Index, |
| 9218 | 9214 | cc: Zir.Inst.Ref, |
| 9219 | 9215 | align_inst: Zir.Inst.Ref, |
| 9220 | addrspace_inst: Zir.Inst.Ref, | |
| 9221 | 9216 | lib_name: u32, |
| 9222 | 9217 | is_var_args: bool, |
| 9223 | 9218 | is_inferred_error: bool, |
| ... | ... | @@ -9261,7 +9256,7 @@ const GenZir = struct { |
| 9261 | 9256 | |
| 9262 | 9257 | if (args.cc != .none or args.lib_name != 0 or |
| 9263 | 9258 | args.is_var_args or args.is_test or args.align_inst != .none or |
| 9264 | args.addrspace_inst != .none or args.is_extern) | |
| 9259 | args.is_extern) | |
| 9265 | 9260 | { |
| 9266 | 9261 | try astgen.extra.ensureUnusedCapacity( |
| 9267 | 9262 | gpa, |
| ... | ... | @@ -9269,7 +9264,6 @@ const GenZir = struct { |
| 9269 | 9264 | args.ret_ty.len + args.body.len + src_locs.len + |
| 9270 | 9265 | @boolToInt(args.lib_name != 0) + |
| 9271 | 9266 | @boolToInt(args.align_inst != .none) + |
| 9272 | @boolToInt(args.addrspace_inst != .none) + | |
| 9273 | 9267 | @boolToInt(args.cc != .none), |
| 9274 | 9268 | ); |
| 9275 | 9269 | const payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.ExtendedFunc{ |
| ... | ... | @@ -9287,9 +9281,6 @@ const GenZir = struct { |
| 9287 | 9281 | if (args.align_inst != .none) { |
| 9288 | 9282 | astgen.extra.appendAssumeCapacity(@enumToInt(args.align_inst)); |
| 9289 | 9283 | } |
| 9290 | if (args.addrspace_inst != .none) { | |
| 9291 | astgen.extra.appendAssumeCapacity(@enumToInt(args.addrspace_inst)); | |
| 9292 | } | |
| 9293 | 9284 | astgen.extra.appendSliceAssumeCapacity(args.ret_ty); |
| 9294 | 9285 | astgen.extra.appendSliceAssumeCapacity(args.body); |
| 9295 | 9286 | astgen.extra.appendSliceAssumeCapacity(src_locs); |
| ... | ... | @@ -9308,7 +9299,6 @@ const GenZir = struct { |
| 9308 | 9299 | .has_lib_name = args.lib_name != 0, |
| 9309 | 9300 | .has_cc = args.cc != .none, |
| 9310 | 9301 | .has_align = args.align_inst != .none, |
| 9311 | .has_addrspace = args.addrspace_inst != .none, | |
| 9312 | 9302 | .is_test = args.is_test, |
| 9313 | 9303 | .is_extern = args.is_extern, |
| 9314 | 9304 | }), |
src/Module.zig+55-59| ... | ... | @@ -3220,7 +3220,12 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { |
| 3220 | 3220 | }; |
| 3221 | 3221 | |
| 3222 | 3222 | break :blk switch (decl.zirAddrspaceRef()) { |
| 3223 | .none => .generic, | |
| 3223 | .none => switch (addrspace_ctx) { | |
| 3224 | .function => target_util.defaultAddressSpace(sema.mod.getTarget(), .function), | |
| 3225 | .variable => target_util.defaultAddressSpace(sema.mod.getTarget(), .global_mutable), | |
| 3226 | .constant => target_util.defaultAddressSpace(sema.mod.getTarget(), .global_constant), | |
| 3227 | else => unreachable, | |
| 3228 | }, | |
| 3224 | 3229 | else => |addrspace_ref| try sema.analyzeAddrspace(&block_scope, src, addrspace_ref, addrspace_ctx), |
| 3225 | 3230 | }; |
| 3226 | 3231 | }; |
| ... | ... | @@ -4359,26 +4364,21 @@ pub fn simplePtrType( |
| 4359 | 4364 | elem_ty: Type, |
| 4360 | 4365 | mutable: bool, |
| 4361 | 4366 | size: std.builtin.TypeInfo.Pointer.Size, |
| 4367 | @"addrspace": std.builtin.AddressSpace, | |
| 4362 | 4368 | ) Allocator.Error!Type { |
| 4363 | if (!mutable and size == .Slice and elem_ty.eql(Type.initTag(.u8))) { | |
| 4364 | return Type.initTag(.const_slice_u8); | |
| 4365 | } | |
| 4366 | // TODO stage1 type inference bug | |
| 4367 | const T = Type.Tag; | |
| 4368 | ||
| 4369 | const type_payload = try arena.create(Type.Payload.ElemType); | |
| 4370 | type_payload.* = .{ | |
| 4371 | .base = .{ | |
| 4372 | .tag = switch (size) { | |
| 4373 | .One => if (mutable) T.single_mut_pointer else T.single_const_pointer, | |
| 4374 | .Many => if (mutable) T.many_mut_pointer else T.many_const_pointer, | |
| 4375 | .C => if (mutable) T.c_mut_pointer else T.c_const_pointer, | |
| 4376 | .Slice => if (mutable) T.mut_slice else T.const_slice, | |
| 4377 | }, | |
| 4378 | }, | |
| 4379 | .data = elem_ty, | |
| 4380 | }; | |
| 4381 | return Type.initPayload(&type_payload.base); | |
| 4369 | return ptrType( | |
| 4370 | arena, | |
| 4371 | elem_ty, | |
| 4372 | null, | |
| 4373 | 0, | |
| 4374 | @"addrspace", | |
| 4375 | 0, | |
| 4376 | 0, | |
| 4377 | mutable, | |
| 4378 | false, | |
| 4379 | false, | |
| 4380 | size, | |
| 4381 | ); | |
| 4382 | 4382 | } |
| 4383 | 4383 | |
| 4384 | 4384 | pub fn ptrType( |
| ... | ... | @@ -4396,47 +4396,43 @@ pub fn ptrType( |
| 4396 | 4396 | ) Allocator.Error!Type { |
| 4397 | 4397 | assert(host_size == 0 or bit_offset < host_size * 8); |
| 4398 | 4398 | |
| 4399 | // TODO check if type can be represented by simplePtrType | |
| 4400 | return Type.Tag.pointer.create(arena, .{ | |
| 4401 | .pointee_type = elem_ty, | |
| 4402 | .sentinel = sentinel, | |
| 4403 | .@"align" = @"align", | |
| 4404 | .@"addrspace" = @"addrspace", | |
| 4405 | .bit_offset = bit_offset, | |
| 4406 | .host_size = host_size, | |
| 4407 | .@"allowzero" = @"allowzero", | |
| 4408 | .mutable = mutable, | |
| 4409 | .@"volatile" = @"volatile", | |
| 4410 | .size = size, | |
| 4411 | }); | |
| 4412 | } | |
| 4399 | if (sentinel != null or @"align" != 0 or @"addrspace" != .generic or | |
| 4400 | bit_offset != 0 or host_size != 0 or @"allowzero" or @"volatile") | |
| 4401 | { | |
| 4402 | return Type.Tag.pointer.create(arena, .{ | |
| 4403 | .pointee_type = elem_ty, | |
| 4404 | .sentinel = sentinel, | |
| 4405 | .@"align" = @"align", | |
| 4406 | .@"addrspace" = @"addrspace", | |
| 4407 | .bit_offset = bit_offset, | |
| 4408 | .host_size = host_size, | |
| 4409 | .@"allowzero" = @"allowzero", | |
| 4410 | .mutable = mutable, | |
| 4411 | .@"volatile" = @"volatile", | |
| 4412 | .size = size, | |
| 4413 | }); | |
| 4414 | } | |
| 4413 | 4415 | |
| 4414 | /// Create a pointer type with an explicit address space. This function might return results | |
| 4415 | /// of either simplePtrType or ptrType, depending on the address space. | |
| 4416 | /// TODO(Snektron) unify ptrType functions. | |
| 4417 | pub fn simplePtrTypeWithAddressSpace( | |
| 4418 | arena: *Allocator, | |
| 4419 | elem_ty: Type, | |
| 4420 | mutable: bool, | |
| 4421 | size: std.builtin.TypeInfo.Pointer.Size, | |
| 4422 | address_space: std.builtin.AddressSpace, | |
| 4423 | ) Allocator.Error!Type { | |
| 4424 | switch (address_space) { | |
| 4425 | .generic => return simplePtrType(arena, elem_ty, mutable, size), | |
| 4426 | else => return ptrType( | |
| 4427 | arena, | |
| 4428 | elem_ty, | |
| 4429 | null, | |
| 4430 | 0, | |
| 4431 | address_space, | |
| 4432 | 0, | |
| 4433 | 0, | |
| 4434 | mutable, | |
| 4435 | false, | |
| 4436 | false, | |
| 4437 | size, | |
| 4438 | ), | |
| 4416 | if (!mutable and size == .Slice and elem_ty.eql(Type.initTag(.u8))) { | |
| 4417 | return Type.initTag(.const_slice_u8); | |
| 4439 | 4418 | } |
| 4419 | ||
| 4420 | // TODO stage1 type inference bug | |
| 4421 | const T = Type.Tag; | |
| 4422 | ||
| 4423 | const type_payload = try arena.create(Type.Payload.ElemType); | |
| 4424 | type_payload.* = .{ | |
| 4425 | .base = .{ | |
| 4426 | .tag = switch (size) { | |
| 4427 | .One => if (mutable) T.single_mut_pointer else T.single_const_pointer, | |
| 4428 | .Many => if (mutable) T.many_mut_pointer else T.many_const_pointer, | |
| 4429 | .C => if (mutable) T.c_mut_pointer else T.c_const_pointer, | |
| 4430 | .Slice => if (mutable) T.mut_slice else T.const_slice, | |
| 4431 | }, | |
| 4432 | }, | |
| 4433 | .data = elem_ty, | |
| 4434 | }; | |
| 4435 | return Type.initPayload(&type_payload.base); | |
| 4440 | 4436 | } |
| 4441 | 4437 | |
| 4442 | 4438 | pub fn optionalType(arena: *Allocator, child_type: Type) Allocator.Error!Type { |
src/Sema.zig+81-40| ... | ... | @@ -1373,7 +1373,13 @@ fn zirRetPtr( |
| 1373 | 1373 | return sema.analyzeComptimeAlloc(block, sema.fn_ret_ty); |
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | const ptr_type = try Module.simplePtrType(sema.arena, sema.fn_ret_ty, true, .One); | |
| 1376 | const ptr_type = try Module.simplePtrType( | |
| 1377 | sema.arena, | |
| 1378 | sema.fn_ret_ty, | |
| 1379 | true, | |
| 1380 | .One, | |
| 1381 | target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | |
| 1382 | ); | |
| 1377 | 1383 | return block.addTy(.alloc, ptr_type); |
| 1378 | 1384 | } |
| 1379 | 1385 | |
| ... | ... | @@ -1521,7 +1527,13 @@ fn zirAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileError |
| 1521 | 1527 | const ty_src: LazySrcLoc = .{ .node_offset_var_decl_ty = inst_data.src_node }; |
| 1522 | 1528 | const var_decl_src = inst_data.src(); |
| 1523 | 1529 | const var_type = try sema.resolveType(block, ty_src, inst_data.operand); |
| 1524 | const ptr_type = try Module.simplePtrType(sema.arena, var_type, true, .One); | |
| 1530 | const ptr_type = try Module.simplePtrType( | |
| 1531 | sema.arena, | |
| 1532 | var_type, | |
| 1533 | true, | |
| 1534 | .One, | |
| 1535 | target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | |
| 1536 | ); | |
| 1525 | 1537 | try sema.requireRuntimeBlock(block, var_decl_src); |
| 1526 | 1538 | return block.addTy(.alloc, ptr_type); |
| 1527 | 1539 | } |
| ... | ... | @@ -1538,7 +1550,13 @@ fn zirAllocMut(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 1538 | 1550 | return sema.analyzeComptimeAlloc(block, var_type); |
| 1539 | 1551 | } |
| 1540 | 1552 | try sema.validateVarType(block, ty_src, var_type); |
| 1541 | const ptr_type = try Module.simplePtrType(sema.arena, var_type, true, .One); | |
| 1553 | const ptr_type = try Module.simplePtrType( | |
| 1554 | sema.arena, | |
| 1555 | var_type, | |
| 1556 | true, | |
| 1557 | .One, | |
| 1558 | target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | |
| 1559 | ); | |
| 1542 | 1560 | try sema.requireRuntimeBlock(block, var_decl_src); |
| 1543 | 1561 | return block.addTy(.alloc, ptr_type); |
| 1544 | 1562 | } |
| ... | ... | @@ -1598,7 +1616,13 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1598 | 1616 | try sema.mod.declareDeclDependency(sema.owner_decl, decl); |
| 1599 | 1617 | |
| 1600 | 1618 | const final_elem_ty = try decl.ty.copy(sema.arena); |
| 1601 | const final_ptr_ty = try Module.simplePtrType(sema.arena, final_elem_ty, true, .One); | |
| 1619 | const final_ptr_ty = try Module.simplePtrType( | |
| 1620 | sema.arena, | |
| 1621 | final_elem_ty, | |
| 1622 | true, | |
| 1623 | .One, | |
| 1624 | target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | |
| 1625 | ); | |
| 1602 | 1626 | const final_ptr_ty_inst = try sema.addType(final_ptr_ty); |
| 1603 | 1627 | sema.air_instructions.items(.data)[ptr_inst].ty_pl.ty = final_ptr_ty_inst; |
| 1604 | 1628 | |
| ... | ... | @@ -1620,7 +1644,13 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Inde |
| 1620 | 1644 | try sema.validateVarType(block, ty_src, final_elem_ty); |
| 1621 | 1645 | } |
| 1622 | 1646 | // Change it to a normal alloc. |
| 1623 | const final_ptr_ty = try Module.simplePtrType(sema.arena, final_elem_ty, true, .One); | |
| 1647 | const final_ptr_ty = try Module.simplePtrType( | |
| 1648 | sema.arena, | |
| 1649 | final_elem_ty, | |
| 1650 | true, | |
| 1651 | .One, | |
| 1652 | target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | |
| 1653 | ); | |
| 1624 | 1654 | sema.air_instructions.set(ptr_inst, .{ |
| 1625 | 1655 | .tag = .alloc, |
| 1626 | 1656 | .data = .{ .ty = final_ptr_ty }, |
| ... | ... | @@ -1774,7 +1804,14 @@ fn zirStoreToBlockPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) Co |
| 1774 | 1804 | } |
| 1775 | 1805 | const ptr = sema.resolveInst(bin_inst.lhs); |
| 1776 | 1806 | const value = sema.resolveInst(bin_inst.rhs); |
| 1777 | const ptr_ty = try Module.simplePtrType(sema.arena, sema.typeOf(value), true, .One); | |
| 1807 | const ptr_ty = try Module.simplePtrType( | |
| 1808 | sema.arena, | |
| 1809 | sema.typeOf(value), | |
| 1810 | true, | |
| 1811 | .One, | |
| 1812 | // TODO figure out which address space is appropriate here | |
| 1813 | target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | |
| 1814 | ); | |
| 1778 | 1815 | // TODO detect when this store should be done at compile-time. For example, |
| 1779 | 1816 | // if expressions should force it when the condition is compile-time known. |
| 1780 | 1817 | const src: LazySrcLoc = .unneeded; |
| ... | ... | @@ -1821,7 +1858,14 @@ fn zirStoreToInferredPtr(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) |
| 1821 | 1858 | // for the inferred allocation. |
| 1822 | 1859 | try inferred_alloc.data.stored_inst_list.append(sema.arena, operand); |
| 1823 | 1860 | // Create a runtime bitcast instruction with exactly the type the pointer wants. |
| 1824 | const ptr_ty = try Module.simplePtrType(sema.arena, operand_ty, true, .One); | |
| 1861 | const ptr_ty = try Module.simplePtrType( | |
| 1862 | sema.arena, | |
| 1863 | operand_ty, | |
| 1864 | true, | |
| 1865 | .One, | |
| 1866 | // TODO figure out which address space is appropriate here | |
| 1867 | target_util.defaultAddressSpace(sema.mod.getTarget(), .local), | |
| 1868 | ); | |
| 1825 | 1869 | const bitcasted_ptr = try block.addTyOp(.bitcast, ptr_ty, ptr); |
| 1826 | 1870 | return sema.storePtr(block, src, bitcasted_ptr, operand); |
| 1827 | 1871 | } |
| ... | ... | @@ -3658,7 +3702,7 @@ fn zirOptionalPayloadPtr( |
| 3658 | 3702 | } |
| 3659 | 3703 | |
| 3660 | 3704 | const child_type = try opt_type.optionalChildAlloc(sema.arena); |
| 3661 | const child_pointer = try Module.simplePtrTypeWithAddressSpace( | |
| 3705 | const child_pointer = try Module.simplePtrType( | |
| 3662 | 3706 | sema.arena, |
| 3663 | 3707 | child_type, |
| 3664 | 3708 | !optional_ptr_ty.isConstPtr(), |
| ... | ... | @@ -3779,7 +3823,7 @@ fn zirErrUnionPayloadPtr( |
| 3779 | 3823 | return sema.mod.fail(&block.base, src, "expected error union type, found {}", .{operand_ty.elemType()}); |
| 3780 | 3824 | |
| 3781 | 3825 | const payload_ty = operand_ty.elemType().errorUnionPayload(); |
| 3782 | const operand_pointer_ty = try Module.simplePtrTypeWithAddressSpace( | |
| 3826 | const operand_pointer_ty = try Module.simplePtrType( | |
| 3783 | 3827 | sema.arena, |
| 3784 | 3828 | payload_ty, |
| 3785 | 3829 | !operand_ty.isConstPtr(), |
| ... | ... | @@ -3907,7 +3951,6 @@ fn zirFunc( |
| 3907 | 3951 | ret_ty_body, |
| 3908 | 3952 | cc, |
| 3909 | 3953 | Value.initTag(.null_value), |
| 3910 | .generic, | |
| 3911 | 3954 | false, |
| 3912 | 3955 | inferred_error_set, |
| 3913 | 3956 | false, |
| ... | ... | @@ -3924,7 +3967,6 @@ fn funcCommon( |
| 3924 | 3967 | ret_ty_body: []const Zir.Inst.Index, |
| 3925 | 3968 | cc: std.builtin.CallingConvention, |
| 3926 | 3969 | align_val: Value, |
| 3927 | address_space: std.builtin.AddressSpace, | |
| 3928 | 3970 | var_args: bool, |
| 3929 | 3971 | inferred_error_set: bool, |
| 3930 | 3972 | is_extern: bool, |
| ... | ... | @@ -3982,7 +4024,7 @@ fn funcCommon( |
| 3982 | 4024 | // Hot path for some common function types. |
| 3983 | 4025 | // TODO can we eliminate some of these Type tag values? seems unnecessarily complicated. |
| 3984 | 4026 | if (!is_generic and block.params.items.len == 0 and !var_args and |
| 3985 | align_val.tag() == .null_value and !inferred_error_set and address_space == .generic) | |
| 4027 | align_val.tag() == .null_value and !inferred_error_set) | |
| 3986 | 4028 | { |
| 3987 | 4029 | if (bare_return_type.zigTypeTag() == .NoReturn and cc == .Unspecified) { |
| 3988 | 4030 | break :fn_ty Type.initTag(.fn_noreturn_no_args); |
| ... | ... | @@ -4034,7 +4076,6 @@ fn funcCommon( |
| 4034 | 4076 | .comptime_params = comptime_params.ptr, |
| 4035 | 4077 | .return_type = return_type, |
| 4036 | 4078 | .cc = cc, |
| 4037 | .@"addrspace" = address_space, | |
| 4038 | 4079 | .is_var_args = var_args, |
| 4039 | 4080 | .is_generic = is_generic, |
| 4040 | 4081 | }); |
| ... | ... | @@ -6413,7 +6454,7 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6413 | 6454 | |
| 6414 | 6455 | switch (ty.zigTypeTag()) { |
| 6415 | 6456 | .Fn => { |
| 6416 | const field_values = try sema.arena.alloc(Value, 7); | |
| 6457 | const field_values = try sema.arena.alloc(Value, 6); | |
| 6417 | 6458 | // calling_convention: CallingConvention, |
| 6418 | 6459 | field_values[0] = try Value.Tag.enum_field_index.create( |
| 6419 | 6460 | sema.arena, |
| ... | ... | @@ -6421,19 +6462,14 @@ fn zirTypeInfo(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) CompileEr |
| 6421 | 6462 | ); |
| 6422 | 6463 | // alignment: comptime_int, |
| 6423 | 6464 | field_values[1] = try Value.Tag.int_u64.create(sema.arena, ty.abiAlignment(target)); |
| 6424 | // address_space: AddressSpace, | |
| 6425 | field_values[2] = try Value.Tag.enum_field_index.create( | |
| 6426 | sema.arena, | |
| 6427 | @enumToInt(ty.fnAddressSpace()), | |
| 6428 | ); | |
| 6429 | 6465 | // is_generic: bool, |
| 6430 | field_values[3] = Value.initTag(.bool_false); // TODO | |
| 6466 | field_values[2] = Value.initTag(.bool_false); // TODO | |
| 6431 | 6467 | // is_var_args: bool, |
| 6432 | field_values[4] = Value.initTag(.bool_false); // TODO | |
| 6468 | field_values[3] = Value.initTag(.bool_false); // TODO | |
| 6433 | 6469 | // return_type: ?type, |
| 6434 | field_values[5] = try Value.Tag.ty.create(sema.arena, ty.fnReturnType()); | |
| 6470 | field_values[4] = try Value.Tag.ty.create(sema.arena, ty.fnReturnType()); | |
| 6435 | 6471 | // args: []const FnArg, |
| 6436 | field_values[6] = Value.initTag(.null_value); // TODO | |
| 6472 | field_values[5] = Value.initTag(.null_value); // TODO | |
| 6437 | 6473 | |
| 6438 | 6474 | return sema.addConstant( |
| 6439 | 6475 | type_info_ty, |
| ... | ... | @@ -8063,7 +8099,6 @@ fn zirFuncExtended( |
| 8063 | 8099 | const src: LazySrcLoc = .{ .node_offset = extra.data.src_node }; |
| 8064 | 8100 | const cc_src: LazySrcLoc = .{ .node_offset_fn_type_cc = extra.data.src_node }; |
| 8065 | 8101 | const align_src: LazySrcLoc = src; // TODO add a LazySrcLoc that points at align |
| 8066 | const addrspace_src: LazySrcLoc = src; // TODO(Snektron) add a LazySrcLoc that points at addrspace | |
| 8067 | 8102 | const small = @bitCast(Zir.Inst.ExtendedFunc.Small, extended.small); |
| 8068 | 8103 | |
| 8069 | 8104 | var extra_index: usize = extra.end; |
| ... | ... | @@ -8088,12 +8123,6 @@ fn zirFuncExtended( |
| 8088 | 8123 | break :blk align_tv.val; |
| 8089 | 8124 | } else Value.initTag(.null_value); |
| 8090 | 8125 | |
| 8091 | const address_space: std.builtin.AddressSpace = if (small.has_addrspace) blk: { | |
| 8092 | const addrspace_ref = @intToEnum(Zir.Inst.Ref, sema.code.extra[extra_index]); | |
| 8093 | extra_index += 1; | |
| 8094 | break :blk try sema.analyzeAddrspace(block, addrspace_src, addrspace_ref, .function); | |
| 8095 | } else .generic; | |
| 8096 | ||
| 8097 | 8126 | const ret_ty_body = sema.code.extra[extra_index..][0..extra.data.ret_body_len]; |
| 8098 | 8127 | extra_index += ret_ty_body.len; |
| 8099 | 8128 | |
| ... | ... | @@ -8116,7 +8145,6 @@ fn zirFuncExtended( |
| 8116 | 8145 | ret_ty_body, |
| 8117 | 8146 | cc, |
| 8118 | 8147 | align_val, |
| 8119 | address_space, | |
| 8120 | 8148 | is_var_args, |
| 8121 | 8149 | is_inferred_error, |
| 8122 | 8150 | is_extern, |
| ... | ... | @@ -8309,7 +8337,13 @@ fn panicWithMsg( |
| 8309 | 8337 | const panic_fn = try sema.getBuiltin(block, src, "panic"); |
| 8310 | 8338 | const unresolved_stack_trace_ty = try sema.getBuiltinType(block, src, "StackTrace"); |
| 8311 | 8339 | const stack_trace_ty = try sema.resolveTypeFields(block, src, unresolved_stack_trace_ty); |
| 8312 | const ptr_stack_trace_ty = try Module.simplePtrType(arena, stack_trace_ty, true, .One); | |
| 8340 | const ptr_stack_trace_ty = try Module.simplePtrType( | |
| 8341 | arena, | |
| 8342 | stack_trace_ty, | |
| 8343 | true, | |
| 8344 | .One, | |
| 8345 | target_util.defaultAddressSpace(sema.mod.getTarget(), .global_constant), // TODO might need a place that is more dynamic | |
| 8346 | ); | |
| 8313 | 8347 | const null_stack_trace = try sema.addConstant( |
| 8314 | 8348 | try Module.optionalType(arena, ptr_stack_trace_ty), |
| 8315 | 8349 | Value.initTag(.null_value), |
| ... | ... | @@ -8788,7 +8822,7 @@ fn structFieldPtr( |
| 8788 | 8822 | const field_index = struct_obj.fields.getIndex(field_name) orelse |
| 8789 | 8823 | return sema.failWithBadFieldAccess(block, struct_obj, field_name_src, field_name); |
| 8790 | 8824 | const field = struct_obj.fields.values()[field_index]; |
| 8791 | const ptr_field_ty = try Module.simplePtrTypeWithAddressSpace( | |
| 8825 | const ptr_field_ty = try Module.simplePtrType( | |
| 8792 | 8826 | arena, |
| 8793 | 8827 | field.ty, |
| 8794 | 8828 | struct_ptr_ty.ptrIsMutable(), |
| ... | ... | @@ -8893,7 +8927,7 @@ fn unionFieldPtr( |
| 8893 | 8927 | return sema.failWithBadUnionFieldAccess(block, union_obj, field_name_src, field_name); |
| 8894 | 8928 | |
| 8895 | 8929 | const field = union_obj.fields.values()[field_index]; |
| 8896 | const ptr_field_ty = try Module.simplePtrTypeWithAddressSpace( | |
| 8930 | const ptr_field_ty = try Module.simplePtrType( | |
| 8897 | 8931 | arena, |
| 8898 | 8932 | field.ty, |
| 8899 | 8933 | union_ptr_ty.ptrIsMutable(), |
| ... | ... | @@ -9075,7 +9109,7 @@ fn elemPtrArray( |
| 9075 | 9109 | ) CompileError!Air.Inst.Ref { |
| 9076 | 9110 | const array_ptr_ty = sema.typeOf(array_ptr); |
| 9077 | 9111 | const pointee_type = array_ptr_ty.elemType().elemType(); |
| 9078 | const result_ty = try Module.simplePtrTypeWithAddressSpace( | |
| 9112 | const result_ty = try Module.simplePtrType( | |
| 9079 | 9113 | sema.arena, |
| 9080 | 9114 | pointee_type, |
| 9081 | 9115 | array_ptr_ty.ptrIsMutable(), |
| ... | ... | @@ -9581,11 +9615,11 @@ fn analyzeDeclRef(sema: *Sema, decl: *Decl) CompileError!Air.Inst.Ref { |
| 9581 | 9615 | const decl_tv = try decl.typedValue(); |
| 9582 | 9616 | if (decl_tv.val.castTag(.variable)) |payload| { |
| 9583 | 9617 | const variable = payload.data; |
| 9584 | const ty = try Module.simplePtrTypeWithAddressSpace(sema.arena, decl_tv.ty, variable.is_mutable, .One, decl.@"addrspace"); | |
| 9618 | const ty = try Module.simplePtrType(sema.arena, decl_tv.ty, variable.is_mutable, .One, decl.@"addrspace"); | |
| 9585 | 9619 | return sema.addConstant(ty, try Value.Tag.decl_ref.create(sema.arena, decl)); |
| 9586 | 9620 | } |
| 9587 | 9621 | return sema.addConstant( |
| 9588 | try Module.simplePtrTypeWithAddressSpace(sema.arena, decl_tv.ty, false, .One, decl.@"addrspace"), | |
| 9622 | try Module.simplePtrType(sema.arena, decl_tv.ty, false, .One, decl.@"addrspace"), | |
| 9589 | 9623 | try Value.Tag.decl_ref.create(sema.arena, decl), |
| 9590 | 9624 | ); |
| 9591 | 9625 | } |
| ... | ... | @@ -9608,8 +9642,9 @@ fn analyzeRef( |
| 9608 | 9642 | } |
| 9609 | 9643 | |
| 9610 | 9644 | try sema.requireRuntimeBlock(block, src); |
| 9611 | const ptr_type = try Module.simplePtrType(sema.arena, operand_ty, false, .One); | |
| 9612 | const mut_ptr_type = try Module.simplePtrType(sema.arena, operand_ty, true, .One); | |
| 9645 | const address_space = target_util.defaultAddressSpace(sema.mod.getTarget(), .local); | |
| 9646 | const ptr_type = try Module.simplePtrType(sema.arena, operand_ty, false, .One, address_space); | |
| 9647 | const mut_ptr_type = try Module.simplePtrType(sema.arena, operand_ty, true, .One, address_space); | |
| 9613 | 9648 | const alloc = try block.addTy(.alloc, mut_ptr_type); |
| 9614 | 9649 | try sema.storePtr(block, src, alloc, operand); |
| 9615 | 9650 | |
| ... | ... | @@ -10955,7 +10990,13 @@ fn analyzeComptimeAlloc( |
| 10955 | 10990 | block: *Scope.Block, |
| 10956 | 10991 | var_type: Type, |
| 10957 | 10992 | ) CompileError!Air.Inst.Ref { |
| 10958 | const ptr_type = try Module.simplePtrType(sema.arena, var_type, true, .One); | |
| 10993 | const ptr_type = try Module.simplePtrType( | |
| 10994 | sema.arena, | |
| 10995 | var_type, | |
| 10996 | true, | |
| 10997 | .One, | |
| 10998 | target_util.defaultAddressSpace(sema.mod.getTarget(), .global_constant), | |
| 10999 | ); | |
| 10959 | 11000 | |
| 10960 | 11001 | var anon_decl = try block.startAnonDecl(); |
| 10961 | 11002 | defer anon_decl.deinit(); |
src/Zir.zig+1-14| ... | ... | @@ -2309,7 +2309,6 @@ pub const Inst = struct { |
| 2309 | 2309 | /// 0. lib_name: u32, // null terminated string index, if has_lib_name is set |
| 2310 | 2310 | /// 1. cc: Ref, // if has_cc is set |
| 2311 | 2311 | /// 2. align: Ref, // if has_align is set |
| 2312 | /// 3. addrspace: Ref, // if has_addrspace is set | |
| 2313 | 2312 | /// 3. return_type: Index // for each ret_body_len |
| 2314 | 2313 | /// 4. body: Index // for each body_len |
| 2315 | 2314 | /// 5. src_locs: Func.SrcLocs // if body_len != 0 |
| ... | ... | @@ -2327,10 +2326,9 @@ pub const Inst = struct { |
| 2327 | 2326 | has_lib_name: bool, |
| 2328 | 2327 | has_cc: bool, |
| 2329 | 2328 | has_align: bool, |
| 2330 | has_addrspace: bool, | |
| 2331 | 2329 | is_test: bool, |
| 2332 | 2330 | is_extern: bool, |
| 2333 | _: u8 = undefined, | |
| 2331 | _: u9 = undefined, | |
| 2334 | 2332 | }; |
| 2335 | 2333 | }; |
| 2336 | 2334 | |
| ... | ... | @@ -4483,7 +4481,6 @@ const Writer = struct { |
| 4483 | 4481 | false, |
| 4484 | 4482 | .none, |
| 4485 | 4483 | .none, |
| 4486 | .none, | |
| 4487 | 4484 | body, |
| 4488 | 4485 | src, |
| 4489 | 4486 | src_locs, |
| ... | ... | @@ -4512,11 +4509,6 @@ const Writer = struct { |
| 4512 | 4509 | extra_index += 1; |
| 4513 | 4510 | break :blk align_inst; |
| 4514 | 4511 | }; |
| 4515 | const addrspace_inst: Inst.Ref = if (!small.has_addrspace) .none else blk: { | |
| 4516 | const addrspace_inst = @intToEnum(Zir.Inst.Ref, self.code.extra[extra_index]); | |
| 4517 | extra_index += 1; | |
| 4518 | break :blk addrspace_inst; | |
| 4519 | }; | |
| 4520 | 4512 | |
| 4521 | 4513 | const ret_ty_body = self.code.extra[extra_index..][0..extra.data.ret_body_len]; |
| 4522 | 4514 | extra_index += ret_ty_body.len; |
| ... | ... | @@ -4536,7 +4528,6 @@ const Writer = struct { |
| 4536 | 4528 | small.is_extern, |
| 4537 | 4529 | cc, |
| 4538 | 4530 | align_inst, |
| 4539 | addrspace_inst, | |
| 4540 | 4531 | body, |
| 4541 | 4532 | src, |
| 4542 | 4533 | src_locs, |
| ... | ... | @@ -4619,7 +4610,6 @@ const Writer = struct { |
| 4619 | 4610 | is_extern: bool, |
| 4620 | 4611 | cc: Inst.Ref, |
| 4621 | 4612 | align_inst: Inst.Ref, |
| 4622 | addrspace_inst: Inst.Ref, | |
| 4623 | 4613 | body: []const Inst.Index, |
| 4624 | 4614 | src: LazySrcLoc, |
| 4625 | 4615 | src_locs: Zir.Inst.Func.SrcLocs, |
| ... | ... | @@ -4637,7 +4627,6 @@ const Writer = struct { |
| 4637 | 4627 | |
| 4638 | 4628 | try self.writeOptionalInstRef(stream, ", cc=", cc); |
| 4639 | 4629 | try self.writeOptionalInstRef(stream, ", align=", align_inst); |
| 4640 | try self.writeOptionalInstRef(stream, ", addrspace=", addrspace_inst); | |
| 4641 | 4630 | try self.writeFlag(stream, ", vargs", var_args); |
| 4642 | 4631 | try self.writeFlag(stream, ", extern", is_extern); |
| 4643 | 4632 | try self.writeFlag(stream, ", inferror", inferred_error_set); |
| ... | ... | @@ -4915,7 +4904,6 @@ fn findDeclsInner( |
| 4915 | 4904 | extra_index += @boolToInt(small.has_lib_name); |
| 4916 | 4905 | extra_index += @boolToInt(small.has_cc); |
| 4917 | 4906 | extra_index += @boolToInt(small.has_align); |
| 4918 | extra_index += @boolToInt(small.has_addrspace); | |
| 4919 | 4907 | const body = zir.extra[extra_index..][0..extra.data.body_len]; |
| 4920 | 4908 | return zir.findDeclsBody(list, body); |
| 4921 | 4909 | }, |
| ... | ... | @@ -5119,7 +5107,6 @@ pub fn getFnInfo(zir: Zir, fn_inst: Inst.Index) FnInfo { |
| 5119 | 5107 | extra_index += @boolToInt(small.has_lib_name); |
| 5120 | 5108 | extra_index += @boolToInt(small.has_cc); |
| 5121 | 5109 | extra_index += @boolToInt(small.has_align); |
| 5122 | extra_index += @boolToInt(small.has_addrspace); | |
| 5123 | 5110 | const ret_ty_body = zir.extra[extra_index..][0..extra.data.ret_body_len]; |
| 5124 | 5111 | extra_index += ret_ty_body.len; |
| 5125 | 5112 | const body = zir.extra[extra_index..][0..extra.data.body_len]; |
src/codegen/llvm.zig+2-1| ... | ... | @@ -700,7 +700,8 @@ pub const DeclGen = struct { |
| 700 | 700 | @intCast(c_uint, llvm_params.len), |
| 701 | 701 | llvm.Bool.fromBool(is_var_args), |
| 702 | 702 | ); |
| 703 | const llvm_addrspace = self.llvmAddressSpace(t.fnAddressSpace()); | |
| 703 | // TODO make .Fn not both a pointer type and a prototype | |
| 704 | const llvm_addrspace = self.llvmAddressSpace(.generic); | |
| 704 | 705 | return llvm_fn_ty.pointerType(llvm_addrspace); |
| 705 | 706 | }, |
| 706 | 707 | .ComptimeInt => unreachable, |
src/stage1/ir.cpp+18-36| ... | ... | @@ -18483,35 +18483,30 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18483 | 18483 | fields[1]->special = ConstValSpecialStatic; |
| 18484 | 18484 | fields[1]->type = ira->codegen->builtin_types.entry_num_lit_int; |
| 18485 | 18485 | bigint_init_unsigned(&fields[1]->data.x_bigint, get_ptr_align(ira->codegen, type_entry)); |
| 18486 | // address_space: AddressSpace | |
| 18487 | ensure_field_index(result->type, "address_space", 2); | |
| 18488 | fields[2]->special = ConstValSpecialStatic; | |
| 18489 | fields[2]->type = get_builtin_type(ira->codegen, "AddressSpace"); | |
| 18490 | bigint_init_unsigned(&fields[2]->data.x_enum_tag, AddressSpaceGeneric); | |
| 18491 | 18486 | // is_generic: bool |
| 18492 | ensure_field_index(result->type, "is_generic", 3); | |
| 18487 | ensure_field_index(result->type, "is_generic", 2); | |
| 18493 | 18488 | bool is_generic = type_entry->data.fn.is_generic; |
| 18494 | fields[3]->special = ConstValSpecialStatic; | |
| 18495 | fields[3]->type = ira->codegen->builtin_types.entry_bool; | |
| 18496 | fields[3]->data.x_bool = is_generic; | |
| 18489 | fields[2]->special = ConstValSpecialStatic; | |
| 18490 | fields[2]->type = ira->codegen->builtin_types.entry_bool; | |
| 18491 | fields[2]->data.x_bool = is_generic; | |
| 18497 | 18492 | // is_varargs: bool |
| 18498 | ensure_field_index(result->type, "is_var_args", 4); | |
| 18493 | ensure_field_index(result->type, "is_var_args", 3); | |
| 18499 | 18494 | bool is_varargs = type_entry->data.fn.fn_type_id.is_var_args; |
| 18500 | fields[4]->special = ConstValSpecialStatic; | |
| 18501 | fields[4]->type = ira->codegen->builtin_types.entry_bool; | |
| 18502 | fields[4]->data.x_bool = is_varargs; | |
| 18495 | fields[3]->special = ConstValSpecialStatic; | |
| 18496 | fields[3]->type = ira->codegen->builtin_types.entry_bool; | |
| 18497 | fields[3]->data.x_bool = is_varargs; | |
| 18503 | 18498 | // return_type: ?type |
| 18504 | ensure_field_index(result->type, "return_type", 5); | |
| 18505 | fields[5]->special = ConstValSpecialStatic; | |
| 18506 | fields[5]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type); | |
| 18499 | ensure_field_index(result->type, "return_type", 4); | |
| 18500 | fields[4]->special = ConstValSpecialStatic; | |
| 18501 | fields[4]->type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_type); | |
| 18507 | 18502 | if (type_entry->data.fn.fn_type_id.return_type == nullptr) |
| 18508 | fields[5]->data.x_optional = nullptr; | |
| 18503 | fields[4]->data.x_optional = nullptr; | |
| 18509 | 18504 | else { |
| 18510 | 18505 | ZigValue *return_type = ira->codegen->pass1_arena->create<ZigValue>(); |
| 18511 | 18506 | return_type->special = ConstValSpecialStatic; |
| 18512 | 18507 | return_type->type = ira->codegen->builtin_types.entry_type; |
| 18513 | 18508 | return_type->data.x_type = type_entry->data.fn.fn_type_id.return_type; |
| 18514 | fields[5]->data.x_optional = return_type; | |
| 18509 | fields[4]->data.x_optional = return_type; | |
| 18515 | 18510 | } |
| 18516 | 18511 | // args: []TypeInfo.FnArg |
| 18517 | 18512 | ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr); |
| ... | ... | @@ -18526,7 +18521,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, Scope *scope, AstNode *sour |
| 18526 | 18521 | fn_arg_array->data.x_array.special = ConstArraySpecialNone; |
| 18527 | 18522 | fn_arg_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count); |
| 18528 | 18523 | |
| 18529 | init_const_slice(ira->codegen, fields[6], fn_arg_array, 0, fn_arg_count, false, nullptr); | |
| 18524 | init_const_slice(ira->codegen, fields[5], fn_arg_array, 0, fn_arg_count, false, nullptr); | |
| 18530 | 18525 | |
| 18531 | 18526 | for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) { |
| 18532 | 18527 | FnTypeParamInfo *fn_param_info = &type_entry->data.fn.fn_type_id.param_info[fn_arg_index]; |
| ... | ... | @@ -19330,22 +19325,9 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_ |
| 19330 | 19325 | if (alignment == nullptr) |
| 19331 | 19326 | return ira->codegen->invalid_inst_gen->value->type; |
| 19332 | 19327 | |
| 19333 | ZigValue *as_value = get_const_field(ira, source_node, payload, "address_space", 2); | |
| 19334 | if (as_value == nullptr) | |
| 19335 | return ira->codegen->invalid_inst_gen->value->type; | |
| 19336 | assert(as_value->special == ConstValSpecialStatic); | |
| 19337 | assert(as_value->type == get_builtin_type(ira->codegen, "AddressSpace")); | |
| 19338 | AddressSpace as = (AddressSpace)bigint_as_u32(&as_value->data.x_enum_tag); | |
| 19339 | if (as != AddressSpaceGeneric) { | |
| 19340 | ir_add_error_node(ira, source_node, buf_sprintf( | |
| 19341 | "address space '%s' not available in stage 1 compiler, must be .generic", | |
| 19342 | address_space_name(as))); | |
| 19343 | return ira->codegen->invalid_inst_gen->value->type; | |
| 19344 | } | |
| 19345 | ||
| 19346 | 19328 | Error err; |
| 19347 | 19329 | bool is_generic; |
| 19348 | if ((err = get_const_field_bool(ira, source_node, payload, "is_generic", 3, &is_generic))) | |
| 19330 | if ((err = get_const_field_bool(ira, source_node, payload, "is_generic", 2, &is_generic))) | |
| 19349 | 19331 | return ira->codegen->invalid_inst_gen->value->type; |
| 19350 | 19332 | if (is_generic) { |
| 19351 | 19333 | ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.is_generic must be false for @Type")); |
| ... | ... | @@ -19353,20 +19335,20 @@ static ZigType *type_info_to_type(IrAnalyze *ira, Scope *scope, AstNode *source_ |
| 19353 | 19335 | } |
| 19354 | 19336 | |
| 19355 | 19337 | bool is_var_args; |
| 19356 | if ((err = get_const_field_bool(ira, source_node, payload, "is_var_args", 4, &is_var_args))) | |
| 19338 | if ((err = get_const_field_bool(ira, source_node, payload, "is_var_args", 3, &is_var_args))) | |
| 19357 | 19339 | return ira->codegen->invalid_inst_gen->value->type; |
| 19358 | 19340 | if (is_var_args && cc != CallingConventionC) { |
| 19359 | 19341 | ir_add_error_node(ira, source_node, buf_sprintf("varargs functions must have C calling convention")); |
| 19360 | 19342 | return ira->codegen->invalid_inst_gen->value->type; |
| 19361 | 19343 | } |
| 19362 | 19344 | |
| 19363 | ZigType *return_type = get_const_field_meta_type_optional(ira, source_node, payload, "return_type", 5); | |
| 19345 | ZigType *return_type = get_const_field_meta_type_optional(ira, source_node, payload, "return_type", 4); | |
| 19364 | 19346 | if (return_type == nullptr) { |
| 19365 | 19347 | ir_add_error_node(ira, source_node, buf_sprintf("TypeInfo.Fn.return_type must be non-null for @Type")); |
| 19366 | 19348 | return ira->codegen->invalid_inst_gen->value->type; |
| 19367 | 19349 | } |
| 19368 | 19350 | |
| 19369 | ZigValue *args_value = get_const_field(ira, source_node, payload, "args", 6); | |
| 19351 | ZigValue *args_value = get_const_field(ira, source_node, payload, "args", 5); | |
| 19370 | 19352 | if (args_value == nullptr) |
| 19371 | 19353 | return ira->codegen->invalid_inst_gen->value->type; |
| 19372 | 19354 | assert(args_value->special == ConstValSpecialStatic); |
src/target.zig+18| ... | ... | @@ -544,3 +544,21 @@ pub fn largestAtomicBits(target: std.Target) u32 { |
| 544 | 544 | .x86_64 => 128, |
| 545 | 545 | }; |
| 546 | 546 | } |
| 547 | ||
| 548 | pub fn defaultAddressSpace( | |
| 549 | target: std.Target, | |
| 550 | context: enum { | |
| 551 | /// Query the default address space for global constant values. | |
| 552 | global_constant, | |
| 553 | /// Query the default address space for global mutable values. | |
| 554 | global_mutable, | |
| 555 | /// Query the default address space for function-local values. | |
| 556 | local, | |
| 557 | /// Query the default address space for functions themselves. | |
| 558 | function, | |
| 559 | }, | |
| 560 | ) std.builtin.AddressSpace { | |
| 561 | _ = target; | |
| 562 | _ = context; | |
| 563 | return .generic; | |
| 564 | } |
src/type.zig-23| ... | ... | @@ -530,8 +530,6 @@ pub const Type = extern union { |
| 530 | 530 | return false; |
| 531 | 531 | if (a.fnCallingConvention() != b.fnCallingConvention()) |
| 532 | 532 | return false; |
| 533 | if (a.fnAddressSpace() != b.fnAddressSpace()) | |
| 534 | return false; | |
| 535 | 533 | const a_param_len = a.fnParamLen(); |
| 536 | 534 | const b_param_len = b.fnParamLen(); |
| 537 | 535 | if (a_param_len != b_param_len) |
| ... | ... | @@ -838,7 +836,6 @@ pub const Type = extern union { |
| 838 | 836 | .return_type = try payload.return_type.copy(allocator), |
| 839 | 837 | .param_types = param_types, |
| 840 | 838 | .cc = payload.cc, |
| 841 | .@"addrspace" = payload.@"addrspace", | |
| 842 | 839 | .is_var_args = payload.is_var_args, |
| 843 | 840 | .is_generic = payload.is_generic, |
| 844 | 841 | .comptime_params = comptime_params.ptr, |
| ... | ... | @@ -1001,9 +998,6 @@ pub const Type = extern union { |
| 1001 | 998 | try writer.writeAll(") callconv(."); |
| 1002 | 999 | try writer.writeAll(@tagName(payload.cc)); |
| 1003 | 1000 | try writer.writeAll(") "); |
| 1004 | if (payload.@"addrspace" != .generic) { | |
| 1005 | try writer.print("addrspace(.{s}) ", .{@tagName(payload.@"addrspace")}); | |
| 1006 | } | |
| 1007 | 1001 | ty = payload.return_type; |
| 1008 | 1002 | continue; |
| 1009 | 1003 | }, |
| ... | ... | @@ -2730,18 +2724,6 @@ pub const Type = extern union { |
| 2730 | 2724 | }; |
| 2731 | 2725 | } |
| 2732 | 2726 | |
| 2733 | pub fn fnAddressSpace(self: Type) std.builtin.AddressSpace { | |
| 2734 | return switch (self.tag()) { | |
| 2735 | .fn_noreturn_no_args => .generic, | |
| 2736 | .fn_void_no_args => .generic, | |
| 2737 | .fn_naked_noreturn_no_args => .generic, | |
| 2738 | .fn_ccc_void_no_args => .generic, | |
| 2739 | .function => self.castTag(.function).?.data.@"addrspace", | |
| 2740 | ||
| 2741 | else => unreachable, | |
| 2742 | }; | |
| 2743 | } | |
| 2744 | ||
| 2745 | 2727 | pub fn fnInfo(ty: Type) Payload.Function.Data { |
| 2746 | 2728 | return switch (ty.tag()) { |
| 2747 | 2729 | .fn_noreturn_no_args => .{ |
| ... | ... | @@ -2749,7 +2731,6 @@ pub const Type = extern union { |
| 2749 | 2731 | .comptime_params = undefined, |
| 2750 | 2732 | .return_type = initTag(.noreturn), |
| 2751 | 2733 | .cc = .Unspecified, |
| 2752 | .@"addrspace" = .generic, | |
| 2753 | 2734 | .is_var_args = false, |
| 2754 | 2735 | .is_generic = false, |
| 2755 | 2736 | }, |
| ... | ... | @@ -2758,7 +2739,6 @@ pub const Type = extern union { |
| 2758 | 2739 | .comptime_params = undefined, |
| 2759 | 2740 | .return_type = initTag(.void), |
| 2760 | 2741 | .cc = .Unspecified, |
| 2761 | .@"addrspace" = .generic, | |
| 2762 | 2742 | .is_var_args = false, |
| 2763 | 2743 | .is_generic = false, |
| 2764 | 2744 | }, |
| ... | ... | @@ -2767,7 +2747,6 @@ pub const Type = extern union { |
| 2767 | 2747 | .comptime_params = undefined, |
| 2768 | 2748 | .return_type = initTag(.noreturn), |
| 2769 | 2749 | .cc = .Naked, |
| 2770 | .@"addrspace" = .generic, | |
| 2771 | 2750 | .is_var_args = false, |
| 2772 | 2751 | .is_generic = false, |
| 2773 | 2752 | }, |
| ... | ... | @@ -2776,7 +2755,6 @@ pub const Type = extern union { |
| 2776 | 2755 | .comptime_params = undefined, |
| 2777 | 2756 | .return_type = initTag(.void), |
| 2778 | 2757 | .cc = .C, |
| 2779 | .@"addrspace" = .generic, | |
| 2780 | 2758 | .is_var_args = false, |
| 2781 | 2759 | .is_generic = false, |
| 2782 | 2760 | }, |
| ... | ... | @@ -3648,7 +3626,6 @@ pub const Type = extern union { |
| 3648 | 3626 | comptime_params: [*]bool, |
| 3649 | 3627 | return_type: Type, |
| 3650 | 3628 | cc: std.builtin.CallingConvention, |
| 3651 | @"addrspace": std.builtin.AddressSpace, | |
| 3652 | 3629 | is_var_args: bool, |
| 3653 | 3630 | is_generic: bool, |
| 3654 | 3631 |
test/compile_errors.zig-20| ... | ... | @@ -410,7 +410,6 @@ pub fn addCases(ctx: *TestContext) !void { |
| 410 | 410 | \\ .Fn = .{ |
| 411 | 411 | \\ .calling_convention = .Unspecified, |
| 412 | 412 | \\ .alignment = 0, |
| 413 | \\ .address_space = .generic, | |
| 414 | 413 | \\ .is_generic = true, |
| 415 | 414 | \\ .is_var_args = false, |
| 416 | 415 | \\ .return_type = u0, |
| ... | ... | @@ -427,7 +426,6 @@ pub fn addCases(ctx: *TestContext) !void { |
| 427 | 426 | \\ .Fn = .{ |
| 428 | 427 | \\ .calling_convention = .Unspecified, |
| 429 | 428 | \\ .alignment = 0, |
| 430 | \\ .address_space = .generic, | |
| 431 | 429 | \\ .is_generic = false, |
| 432 | 430 | \\ .is_var_args = true, |
| 433 | 431 | \\ .return_type = u0, |
| ... | ... | @@ -444,7 +442,6 @@ pub fn addCases(ctx: *TestContext) !void { |
| 444 | 442 | \\ .Fn = .{ |
| 445 | 443 | \\ .calling_convention = .Unspecified, |
| 446 | 444 | \\ .alignment = 0, |
| 447 | \\ .address_space = .generic, | |
| 448 | 445 | \\ .is_generic = false, |
| 449 | 446 | \\ .is_var_args = false, |
| 450 | 447 | \\ .return_type = null, |
| ... | ... | @@ -456,23 +453,6 @@ pub fn addCases(ctx: *TestContext) !void { |
| 456 | 453 | "tmp.zig:1:20: error: TypeInfo.Fn.return_type must be non-null for @Type", |
| 457 | 454 | }); |
| 458 | 455 | |
| 459 | ctx.objErrStage1("@Type(.Fn) with invalid address space ", | |
| 460 | \\const Foo = @Type(.{ | |
| 461 | \\ .Fn = .{ | |
| 462 | \\ .calling_convention = .Unspecified, | |
| 463 | \\ .alignment = 0, | |
| 464 | \\ .address_space = .fs, | |
| 465 | \\ .is_generic = false, | |
| 466 | \\ .is_var_args = false, | |
| 467 | \\ .return_type = u0, | |
| 468 | \\ .args = &[_]@import("std").builtin.TypeInfo.FnArg{}, | |
| 469 | \\ }, | |
| 470 | \\}); | |
| 471 | \\comptime { _ = Foo; } | |
| 472 | , &[_][]const u8{ | |
| 473 | "tmp.zig:1:20: error: address space 'fs' not available in stage 1 compiler, must be .generic", | |
| 474 | }); | |
| 475 | ||
| 476 | 456 | ctx.objErrStage1("@Type for union with opaque field", |
| 477 | 457 | \\const TypeInfo = @import("std").builtin.TypeInfo; |
| 478 | 458 | \\const Untagged = @Type(.{ |