| author | |
| committer | |
| log | b820d5df79e714b3a3ad3c09480abdafff058de8 |
| tree | b6fcf4066de92f3ab01a56166719757aef2e0a83 |
| parent | 275e926cf851144ef6a4c64963e47f3b955870cc |
| parent | c4848694d20c19b78657ee46f18028737290c829 |
| signature |
llvm: enable the backend even when not linked to llvm12 files changed, 148 insertions(+), 248 deletions(-)
lib/std/mem.zig+14-7| ... | ... | @@ -4138,23 +4138,24 @@ test "bytesAsSlice preserves pointer attributes" { |
| 4138 | 4138 | try testing.expectEqual(in.alignment, out.alignment); |
| 4139 | 4139 | } |
| 4140 | 4140 | |
| 4141 | fn SliceAsBytesReturnType(comptime sliceType: type) type { | |
| 4142 | if (!trait.isSlice(sliceType) and !trait.isPtrTo(.Array)(sliceType)) { | |
| 4143 | @compileError("expected []T or *[_]T, passed " ++ @typeName(sliceType)); | |
| 4141 | fn SliceAsBytesReturnType(comptime Slice: type) type { | |
| 4142 | if (!trait.isSlice(Slice) and !trait.isPtrTo(.Array)(Slice)) { | |
| 4143 | @compileError("expected []T or *[_]T, passed " ++ @typeName(Slice)); | |
| 4144 | 4144 | } |
| 4145 | 4145 | |
| 4146 | return CopyPtrAttrs(sliceType, .Slice, u8); | |
| 4146 | return CopyPtrAttrs(Slice, .Slice, u8); | |
| 4147 | 4147 | } |
| 4148 | 4148 | |
| 4149 | 4149 | /// Given a slice, returns a slice of the underlying bytes, preserving pointer attributes. |
| 4150 | 4150 | pub fn sliceAsBytes(slice: anytype) SliceAsBytesReturnType(@TypeOf(slice)) { |
| 4151 | 4151 | const Slice = @TypeOf(slice); |
| 4152 | 4152 | |
| 4153 | // a slice of zero-bit values always occupies zero bytes | |
| 4154 | if (@sizeOf(meta.Elem(Slice)) == 0) return &[0]u8{}; | |
| 4155 | ||
| 4153 | 4156 | // let's not give an undefined pointer to @ptrCast |
| 4154 | 4157 | // it may be equal to zero and fail a null check |
| 4155 | if (slice.len == 0 and comptime meta.sentinel(Slice) == null) { | |
| 4156 | return &[0]u8{}; | |
| 4157 | } | |
| 4158 | if (slice.len == 0 and comptime meta.sentinel(Slice) == null) return &[0]u8{}; | |
| 4158 | 4159 | |
| 4159 | 4160 | const cast_target = CopyPtrAttrs(Slice, .Many, u8); |
| 4160 | 4161 | |
| ... | ... | @@ -4177,6 +4178,12 @@ test "sliceAsBytes with sentinel slice" { |
| 4177 | 4178 | try testing.expect(bytes.len == 0); |
| 4178 | 4179 | } |
| 4179 | 4180 | |
| 4181 | test "sliceAsBytes with zero-bit element type" { | |
| 4182 | const lots_of_nothing = [1]void{{}} ** 10_000; | |
| 4183 | const bytes = sliceAsBytes(&lots_of_nothing); | |
| 4184 | try testing.expect(bytes.len == 0); | |
| 4185 | } | |
| 4186 | ||
| 4180 | 4187 | test "sliceAsBytes packed struct at runtime and comptime" { |
| 4181 | 4188 | const Foo = packed struct { |
| 4182 | 4189 | a: u4, |
src/Compilation.zig+2-2| ... | ... | @@ -1027,7 +1027,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1027 | 1027 | return error.TargetRequiresSingleThreaded; |
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: { | |
| 1030 | const llvm_cpu_features: ?[*:0]const u8 = if (use_llvm) blk: { | |
| 1031 | 1031 | var buf = std.ArrayList(u8).init(arena); |
| 1032 | 1032 | for (options.target.cpu.arch.allFeaturesList(), 0..) |feature, index_usize| { |
| 1033 | 1033 | const index = @as(Target.Cpu.Feature.Set.Index, @intCast(index_usize)); |
| ... | ... | @@ -5182,7 +5182,7 @@ pub fn dump_argv(argv: []const []const u8) void { |
| 5182 | 5182 | } |
| 5183 | 5183 | |
| 5184 | 5184 | pub fn getZigBackend(comp: Compilation) std.builtin.CompilerBackend { |
| 5185 | if (build_options.have_llvm and comp.bin_file.options.use_llvm) return .stage2_llvm; | |
| 5185 | if (comp.bin_file.options.use_llvm) return .stage2_llvm; | |
| 5186 | 5186 | const target = comp.bin_file.options.target; |
| 5187 | 5187 | if (target.ofmt == .c) return .stage2_c; |
| 5188 | 5188 | return switch (target.cpu.arch) { |
src/Sema.zig+11-67| ... | ... | @@ -5068,7 +5068,7 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr |
| 5068 | 5068 | if (val.isUndef(mod)) { |
| 5069 | 5069 | return sema.fail(block, src, "cannot dereference undefined value", .{}); |
| 5070 | 5070 | } |
| 5071 | } else if (!(try sema.validateRunTimeType(elem_ty, false))) { | |
| 5071 | } else if (try sema.typeRequiresComptime(elem_ty)) { | |
| 5072 | 5072 | const msg = msg: { |
| 5073 | 5073 | const msg = try sema.errMsg( |
| 5074 | 5074 | block, |
| ... | ... | @@ -5826,8 +5826,7 @@ fn analyzeBlockBody( |
| 5826 | 5826 | // TODO add note "missing else causes void value" |
| 5827 | 5827 | |
| 5828 | 5828 | const type_src = src; // TODO: better source location |
| 5829 | const valid_rt = try sema.validateRunTimeType(resolved_ty, false); | |
| 5830 | if (!valid_rt) { | |
| 5829 | if (try sema.typeRequiresComptime(resolved_ty)) { | |
| 5831 | 5830 | const msg = msg: { |
| 5832 | 5831 | const msg = try sema.errMsg(child_block, type_src, "value with comptime-only type '{}' depends on runtime control flow", .{resolved_ty.fmt(mod)}); |
| 5833 | 5832 | errdefer msg.destroy(sema.gpa); |
| ... | ... | @@ -24684,7 +24683,8 @@ fn validateVarType( |
| 24684 | 24683 | return sema.failWithOwnedErrorMsg(msg); |
| 24685 | 24684 | } |
| 24686 | 24685 | |
| 24687 | if (try sema.validateRunTimeType(var_ty, is_extern)) return; | |
| 24686 | if (is_extern and var_ty.zigTypeTag(mod) == .Opaque) return; | |
| 24687 | if (!try sema.typeRequiresComptime(var_ty)) return; | |
| 24688 | 24688 | |
| 24689 | 24689 | const msg = msg: { |
| 24690 | 24690 | const msg = try sema.errMsg(block, src, "variable of type '{}' must be const or comptime", .{var_ty.fmt(mod)}); |
| ... | ... | @@ -24701,61 +24701,6 @@ fn validateVarType( |
| 24701 | 24701 | return sema.failWithOwnedErrorMsg(msg); |
| 24702 | 24702 | } |
| 24703 | 24703 | |
| 24704 | fn validateRunTimeType( | |
| 24705 | sema: *Sema, | |
| 24706 | var_ty: Type, | |
| 24707 | is_extern: bool, | |
| 24708 | ) CompileError!bool { | |
| 24709 | const mod = sema.mod; | |
| 24710 | var ty = var_ty; | |
| 24711 | while (true) switch (ty.zigTypeTag(mod)) { | |
| 24712 | .Bool, | |
| 24713 | .Int, | |
| 24714 | .Float, | |
| 24715 | .ErrorSet, | |
| 24716 | .Frame, | |
| 24717 | .AnyFrame, | |
| 24718 | .Void, | |
| 24719 | => return true, | |
| 24720 | ||
| 24721 | .Enum => return !(try sema.typeRequiresComptime(ty)), | |
| 24722 | ||
| 24723 | .ComptimeFloat, | |
| 24724 | .ComptimeInt, | |
| 24725 | .EnumLiteral, | |
| 24726 | .NoReturn, | |
| 24727 | .Type, | |
| 24728 | .Undefined, | |
| 24729 | .Null, | |
| 24730 | .Fn, | |
| 24731 | => return false, | |
| 24732 | ||
| 24733 | .Pointer => { | |
| 24734 | const elem_ty = ty.childType(mod); | |
| 24735 | switch (elem_ty.zigTypeTag(mod)) { | |
| 24736 | .Opaque => return true, | |
| 24737 | .Fn => return elem_ty.isFnOrHasRuntimeBits(mod), | |
| 24738 | else => ty = elem_ty, | |
| 24739 | } | |
| 24740 | }, | |
| 24741 | .Opaque => return is_extern, | |
| 24742 | ||
| 24743 | .Optional => { | |
| 24744 | const child_ty = ty.optionalChild(mod); | |
| 24745 | return sema.validateRunTimeType(child_ty, is_extern); | |
| 24746 | }, | |
| 24747 | .Array, .Vector => ty = ty.childType(mod), | |
| 24748 | ||
| 24749 | .ErrorUnion => ty = ty.errorUnionPayload(mod), | |
| 24750 | ||
| 24751 | .Struct, .Union => { | |
| 24752 | const resolved_ty = try sema.resolveTypeFields(ty); | |
| 24753 | const needs_comptime = try sema.typeRequiresComptime(resolved_ty); | |
| 24754 | return !needs_comptime; | |
| 24755 | }, | |
| 24756 | }; | |
| 24757 | } | |
| 24758 | ||
| 24759 | 24704 | const TypeSet = std.AutoHashMapUnmanaged(InternPool.Index, void); |
| 24760 | 24705 | |
| 24761 | 24706 | fn explainWhyTypeIsComptime( |
| ... | ... | @@ -26754,8 +26699,7 @@ fn validateRuntimeElemAccess( |
| 26754 | 26699 | parent_src: LazySrcLoc, |
| 26755 | 26700 | ) CompileError!void { |
| 26756 | 26701 | const mod = sema.mod; |
| 26757 | const valid_rt = try sema.validateRunTimeType(elem_ty, false); | |
| 26758 | if (!valid_rt) { | |
| 26702 | if (try sema.typeRequiresComptime(elem_ty)) { | |
| 26759 | 26703 | const msg = msg: { |
| 26760 | 26704 | const msg = try sema.errMsg( |
| 26761 | 26705 | block, |
| ... | ... | @@ -36235,10 +36179,10 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 36235 | 36179 | .int_type => return false, |
| 36236 | 36180 | .ptr_type => |ptr_type| { |
| 36237 | 36181 | const child_ty = ptr_type.child.toType(); |
| 36238 | if (child_ty.zigTypeTag(mod) == .Fn) { | |
| 36239 | return mod.typeToFunc(child_ty).?.is_generic; | |
| 36240 | } else { | |
| 36241 | return sema.typeRequiresComptime(child_ty); | |
| 36182 | switch (child_ty.zigTypeTag(mod)) { | |
| 36183 | .Fn => return mod.typeToFunc(child_ty).?.is_generic, | |
| 36184 | .Opaque => return false, | |
| 36185 | else => return sema.typeRequiresComptime(child_ty), | |
| 36242 | 36186 | } |
| 36243 | 36187 | }, |
| 36244 | 36188 | .anyframe_type => |child| { |
| ... | ... | @@ -36275,7 +36219,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 36275 | 36219 | .c_longlong, |
| 36276 | 36220 | .c_ulonglong, |
| 36277 | 36221 | .c_longdouble, |
| 36278 | .anyopaque, | |
| 36279 | 36222 | .bool, |
| 36280 | 36223 | .void, |
| 36281 | 36224 | .anyerror, |
| ... | ... | @@ -36294,6 +36237,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 36294 | 36237 | .adhoc_inferred_error_set, |
| 36295 | 36238 | => false, |
| 36296 | 36239 | |
| 36240 | .anyopaque, | |
| 36297 | 36241 | .type, |
| 36298 | 36242 | .comptime_int, |
| 36299 | 36243 | .comptime_float, |
| ... | ... | @@ -36361,7 +36305,7 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool { |
| 36361 | 36305 | } |
| 36362 | 36306 | }, |
| 36363 | 36307 | |
| 36364 | .opaque_type => false, | |
| 36308 | .opaque_type => true, | |
| 36365 | 36309 | .enum_type => |enum_type| try sema.typeRequiresComptime(enum_type.tag_ty.toType()), |
| 36366 | 36310 | |
| 36367 | 36311 | // values, not types |
src/codegen/llvm.zig+42-33| ... | ... | @@ -8,7 +8,7 @@ const native_endian = builtin.cpu.arch.endian(); |
| 8 | 8 | const DW = std.dwarf; |
| 9 | 9 | |
| 10 | 10 | const Builder = @import("llvm/Builder.zig"); |
| 11 | const llvm = if (build_options.have_llvm or true) | |
| 11 | const llvm = if (build_options.have_llvm) | |
| 12 | 12 | @import("llvm/bindings.zig") |
| 13 | 13 | else |
| 14 | 14 | @compileError("LLVM unavailable"); |
| ... | ... | @@ -764,15 +764,37 @@ pub const Object = struct { |
| 764 | 764 | builder: Builder, |
| 765 | 765 | |
| 766 | 766 | module: *Module, |
| 767 | di_builder: ?*llvm.DIBuilder, | |
| 767 | di_builder: ?if (build_options.have_llvm) *llvm.DIBuilder else noreturn, | |
| 768 | 768 | /// One of these mappings: |
| 769 | 769 | /// - *Module.File => *DIFile |
| 770 | 770 | /// - *Module.Decl (Fn) => *DISubprogram |
| 771 | 771 | /// - *Module.Decl (Non-Fn) => *DIGlobalVariable |
| 772 | di_map: std.AutoHashMapUnmanaged(*const anyopaque, *llvm.DINode), | |
| 773 | di_compile_unit: ?*llvm.DICompileUnit, | |
| 774 | target_machine: *llvm.TargetMachine, | |
| 775 | target_data: *llvm.TargetData, | |
| 772 | di_map: if (build_options.have_llvm) std.AutoHashMapUnmanaged(*const anyopaque, *llvm.DINode) else struct { | |
| 773 | const K = *const anyopaque; | |
| 774 | const V = noreturn; | |
| 775 | ||
| 776 | const Self = @This(); | |
| 777 | ||
| 778 | metadata: ?noreturn = null, | |
| 779 | size: Size = 0, | |
| 780 | available: Size = 0, | |
| 781 | ||
| 782 | pub const Size = u0; | |
| 783 | ||
| 784 | pub fn deinit(self: *Self, allocator: Allocator) void { | |
| 785 | _ = allocator; | |
| 786 | self.* = undefined; | |
| 787 | } | |
| 788 | ||
| 789 | pub fn get(self: Self, key: K) ?V { | |
| 790 | _ = self; | |
| 791 | _ = key; | |
| 792 | return null; | |
| 793 | } | |
| 794 | }, | |
| 795 | di_compile_unit: ?if (build_options.have_llvm) *llvm.DICompileUnit else noreturn, | |
| 796 | target_machine: if (build_options.have_llvm) *llvm.TargetMachine else void, | |
| 797 | target_data: if (build_options.have_llvm) *llvm.TargetData else void, | |
| 776 | 798 | target: std.Target, |
| 777 | 799 | /// Ideally we would use `llvm_module.getNamedFunction` to go from *Decl to LLVM function, |
| 778 | 800 | /// but that has some downsides: |
| ... | ... | @@ -830,8 +852,8 @@ pub const Object = struct { |
| 830 | 852 | }); |
| 831 | 853 | errdefer builder.deinit(); |
| 832 | 854 | |
| 833 | var target_machine: *llvm.TargetMachine = undefined; | |
| 834 | var target_data: *llvm.TargetData = undefined; | |
| 855 | var target_machine: if (build_options.have_llvm) *llvm.TargetMachine else void = undefined; | |
| 856 | var target_data: if (build_options.have_llvm) *llvm.TargetData else void = undefined; | |
| 835 | 857 | if (builder.useLibLlvm()) { |
| 836 | 858 | if (!options.strip) { |
| 837 | 859 | switch (options.target.ofmt) { |
| ... | ... | @@ -946,7 +968,7 @@ pub const Object = struct { |
| 946 | 968 | .module = options.module.?, |
| 947 | 969 | .di_map = .{}, |
| 948 | 970 | .di_builder = if (builder.useLibLlvm()) builder.llvm.di_builder else null, // TODO |
| 949 | .di_compile_unit = builder.llvm.di_compile_unit, | |
| 971 | .di_compile_unit = if (builder.useLibLlvm()) builder.llvm.di_compile_unit else null, | |
| 950 | 972 | .target_machine = target_machine, |
| 951 | 973 | .target_data = target_data, |
| 952 | 974 | .target = options.target, |
| ... | ... | @@ -961,9 +983,9 @@ pub const Object = struct { |
| 961 | 983 | } |
| 962 | 984 | |
| 963 | 985 | pub fn deinit(self: *Object, gpa: Allocator) void { |
| 986 | self.di_map.deinit(gpa); | |
| 987 | self.di_type_map.deinit(gpa); | |
| 964 | 988 | if (self.builder.useLibLlvm()) { |
| 965 | self.di_map.deinit(gpa); | |
| 966 | self.di_type_map.deinit(gpa); | |
| 967 | 989 | self.target_data.dispose(); |
| 968 | 990 | self.target_machine.dispose(); |
| 969 | 991 | } |
| ... | ... | @@ -1519,8 +1541,8 @@ pub const Object = struct { |
| 1519 | 1541 | |
| 1520 | 1542 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 1521 | 1543 | |
| 1522 | var di_file: ?*llvm.DIFile = null; | |
| 1523 | var di_scope: ?*llvm.DIScope = null; | |
| 1544 | var di_file: ?if (build_options.have_llvm) *llvm.DIFile else noreturn = null; | |
| 1545 | var di_scope: ?if (build_options.have_llvm) *llvm.DIScope else noreturn = null; | |
| 1524 | 1546 | |
| 1525 | 1547 | if (o.di_builder) |dib| { |
| 1526 | 1548 | di_file = try o.getDIFile(gpa, mod.namespacePtr(decl.src_namespace).file_scope); |
| ... | ... | @@ -4425,7 +4447,8 @@ pub const DeclGen = struct { |
| 4425 | 4447 | }, &o.builder); |
| 4426 | 4448 | |
| 4427 | 4449 | if (o.di_builder) |dib| { |
| 4428 | const di_file = try o.getDIFile(o.gpa, mod.namespacePtr(decl.src_namespace).file_scope); | |
| 4450 | const di_file = | |
| 4451 | try o.getDIFile(o.gpa, mod.namespacePtr(decl.src_namespace).file_scope); | |
| 4429 | 4452 | |
| 4430 | 4453 | const line_number = decl.src_line + 1; |
| 4431 | 4454 | const is_internal_linkage = !o.module.decl_exports.contains(decl_index); |
| ... | ... | @@ -4453,18 +4476,18 @@ pub const FuncGen = struct { |
| 4453 | 4476 | air: Air, |
| 4454 | 4477 | liveness: Liveness, |
| 4455 | 4478 | wip: Builder.WipFunction, |
| 4456 | di_scope: ?*llvm.DIScope, | |
| 4457 | di_file: ?*llvm.DIFile, | |
| 4479 | di_scope: ?if (build_options.have_llvm) *llvm.DIScope else noreturn, | |
| 4480 | di_file: ?if (build_options.have_llvm) *llvm.DIFile else noreturn, | |
| 4458 | 4481 | base_line: u32, |
| 4459 | 4482 | prev_dbg_line: c_uint, |
| 4460 | 4483 | prev_dbg_column: c_uint, |
| 4461 | 4484 | |
| 4462 | 4485 | /// Stack of locations where a call was inlined. |
| 4463 | dbg_inlined: std.ArrayListUnmanaged(DbgState) = .{}, | |
| 4486 | dbg_inlined: std.ArrayListUnmanaged(if (build_options.have_llvm) DbgState else void) = .{}, | |
| 4464 | 4487 | |
| 4465 | 4488 | /// Stack of `DILexicalBlock`s. dbg_block instructions cannot happend accross |
| 4466 | 4489 | /// dbg_inline instructions so no special handling there is required. |
| 4467 | dbg_block_stack: std.ArrayListUnmanaged(*llvm.DIScope) = .{}, | |
| 4490 | dbg_block_stack: std.ArrayListUnmanaged(if (build_options.have_llvm) *llvm.DIScope else void) = .{}, | |
| 4468 | 4491 | |
| 4469 | 4492 | /// This stores the LLVM values used in a function, such that they can be referred to |
| 4470 | 4493 | /// in other instructions. This table is cleared before every function is generated. |
| ... | ... | @@ -4495,7 +4518,7 @@ pub const FuncGen = struct { |
| 4495 | 4518 | |
| 4496 | 4519 | sync_scope: Builder.SyncScope, |
| 4497 | 4520 | |
| 4498 | const DbgState = struct { loc: *llvm.DILocation, scope: *llvm.DIScope, base_line: u32 }; | |
| 4521 | const DbgState = if (build_options.have_llvm) struct { loc: *llvm.DILocation, scope: *llvm.DIScope, base_line: u32 } else struct {}; | |
| 4499 | 4522 | const BreakList = union { |
| 4500 | 4523 | list: std.MultiArrayList(struct { |
| 4501 | 4524 | bb: Builder.Function.Block.Index, |
| ... | ... | @@ -6230,8 +6253,6 @@ pub const FuncGen = struct { |
| 6230 | 6253 | } |
| 6231 | 6254 | |
| 6232 | 6255 | fn airDbgStmt(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6233 | if (!self.dg.object.builder.useLibLlvm()) return .none; | |
| 6234 | ||
| 6235 | 6256 | const di_scope = self.di_scope orelse return .none; |
| 6236 | 6257 | const dbg_stmt = self.air.instructions.items(.data)[inst].dbg_stmt; |
| 6237 | 6258 | self.prev_dbg_line = @intCast(self.base_line + dbg_stmt.line + 1); |
| ... | ... | @@ -6251,8 +6272,6 @@ pub const FuncGen = struct { |
| 6251 | 6272 | |
| 6252 | 6273 | fn airDbgInlineBegin(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6253 | 6274 | const o = self.dg.object; |
| 6254 | if (!o.builder.useLibLlvm()) return .none; | |
| 6255 | ||
| 6256 | 6275 | const dib = o.di_builder orelse return .none; |
| 6257 | 6276 | const ty_fn = self.air.instructions.items(.data)[inst].ty_fn; |
| 6258 | 6277 | |
| ... | ... | @@ -6311,8 +6330,6 @@ pub const FuncGen = struct { |
| 6311 | 6330 | |
| 6312 | 6331 | fn airDbgInlineEnd(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6313 | 6332 | const o = self.dg.object; |
| 6314 | if (!o.builder.useLibLlvm()) return .none; | |
| 6315 | ||
| 6316 | 6333 | if (o.di_builder == null) return .none; |
| 6317 | 6334 | const ty_fn = self.air.instructions.items(.data)[inst].ty_fn; |
| 6318 | 6335 | |
| ... | ... | @@ -6328,8 +6345,6 @@ pub const FuncGen = struct { |
| 6328 | 6345 | |
| 6329 | 6346 | fn airDbgBlockBegin(self: *FuncGen) !Builder.Value { |
| 6330 | 6347 | const o = self.dg.object; |
| 6331 | if (!o.builder.useLibLlvm()) return .none; | |
| 6332 | ||
| 6333 | 6348 | const dib = o.di_builder orelse return .none; |
| 6334 | 6349 | const old_scope = self.di_scope.?; |
| 6335 | 6350 | try self.dbg_block_stack.append(self.gpa, old_scope); |
| ... | ... | @@ -6340,8 +6355,6 @@ pub const FuncGen = struct { |
| 6340 | 6355 | |
| 6341 | 6356 | fn airDbgBlockEnd(self: *FuncGen) !Builder.Value { |
| 6342 | 6357 | const o = self.dg.object; |
| 6343 | if (!o.builder.useLibLlvm()) return .none; | |
| 6344 | ||
| 6345 | 6358 | if (o.di_builder == null) return .none; |
| 6346 | 6359 | self.di_scope = self.dbg_block_stack.pop(); |
| 6347 | 6360 | return .none; |
| ... | ... | @@ -6349,8 +6362,6 @@ pub const FuncGen = struct { |
| 6349 | 6362 | |
| 6350 | 6363 | fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6351 | 6364 | const o = self.dg.object; |
| 6352 | if (!o.builder.useLibLlvm()) return .none; | |
| 6353 | ||
| 6354 | 6365 | const mod = o.module; |
| 6355 | 6366 | const dib = o.di_builder orelse return .none; |
| 6356 | 6367 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
| ... | ... | @@ -6379,8 +6390,6 @@ pub const FuncGen = struct { |
| 6379 | 6390 | |
| 6380 | 6391 | fn airDbgVarVal(self: *FuncGen, inst: Air.Inst.Index) !Builder.Value { |
| 6381 | 6392 | const o = self.dg.object; |
| 6382 | if (!o.builder.useLibLlvm()) return .none; | |
| 6383 | ||
| 6384 | 6393 | const dib = o.di_builder orelse return .none; |
| 6385 | 6394 | const pl_op = self.air.instructions.items(.data)[inst].pl_op; |
| 6386 | 6395 | const operand = try self.resolveInst(pl_op.operand); |
src/codegen/llvm/Builder.zig+19-19| ... | ... | @@ -5868,7 +5868,7 @@ pub const WipFunction = struct { |
| 5868 | 5868 | vals: []const Value, |
| 5869 | 5869 | blocks: []const Block.Index, |
| 5870 | 5870 | wip: *WipFunction, |
| 5871 | ) if (build_options.have_llvm) Allocator.Error!void else void { | |
| 5871 | ) (if (build_options.have_llvm) Allocator.Error else error{})!void { | |
| 5872 | 5872 | const incoming_len = self.block.ptrConst(wip).incoming; |
| 5873 | 5873 | assert(vals.len == incoming_len and blocks.len == incoming_len); |
| 5874 | 5874 | const instruction = wip.instructions.get(@intFromEnum(self.instruction)); |
| ... | ... | @@ -8389,9 +8389,9 @@ pub fn fnType( |
| 8389 | 8389 | kind: Type.Function.Kind, |
| 8390 | 8390 | ) Allocator.Error!Type { |
| 8391 | 8391 | try self.ensureUnusedTypeCapacity(1, Type.Function, params.len); |
| 8392 | return switch (kind) { | |
| 8393 | inline else => |comptime_kind| self.fnTypeAssumeCapacity(ret, params, comptime_kind), | |
| 8394 | }; | |
| 8392 | switch (kind) { | |
| 8393 | inline else => |comptime_kind| return self.fnTypeAssumeCapacity(ret, params, comptime_kind), | |
| 8394 | } | |
| 8395 | 8395 | } |
| 8396 | 8396 | |
| 8397 | 8397 | pub fn intType(self: *Builder, bits: u24) Allocator.Error!Type { |
| ... | ... | @@ -8411,9 +8411,9 @@ pub fn vectorType( |
| 8411 | 8411 | child: Type, |
| 8412 | 8412 | ) Allocator.Error!Type { |
| 8413 | 8413 | try self.ensureUnusedTypeCapacity(1, Type.Vector, 0); |
| 8414 | return switch (kind) { | |
| 8415 | inline else => |comptime_kind| self.vectorTypeAssumeCapacity(comptime_kind, len, child), | |
| 8416 | }; | |
| 8414 | switch (kind) { | |
| 8415 | inline else => |comptime_kind| return self.vectorTypeAssumeCapacity(comptime_kind, len, child), | |
| 8416 | } | |
| 8417 | 8417 | } |
| 8418 | 8418 | |
| 8419 | 8419 | pub fn arrayType(self: *Builder, len: u64, child: Type) Allocator.Error!Type { |
| ... | ... | @@ -8428,9 +8428,9 @@ pub fn structType( |
| 8428 | 8428 | fields: []const Type, |
| 8429 | 8429 | ) Allocator.Error!Type { |
| 8430 | 8430 | try self.ensureUnusedTypeCapacity(1, Type.Structure, fields.len); |
| 8431 | return switch (kind) { | |
| 8432 | inline else => |comptime_kind| self.structTypeAssumeCapacity(comptime_kind, fields), | |
| 8433 | }; | |
| 8431 | switch (kind) { | |
| 8432 | inline else => |comptime_kind| return self.structTypeAssumeCapacity(comptime_kind, fields), | |
| 8433 | } | |
| 8434 | 8434 | } |
| 8435 | 8435 | |
| 8436 | 8436 | pub fn opaqueType(self: *Builder, name: String) Allocator.Error!Type { |
| ... | ... | @@ -8450,7 +8450,7 @@ pub fn namedTypeSetBody( |
| 8450 | 8450 | self: *Builder, |
| 8451 | 8451 | named_type: Type, |
| 8452 | 8452 | body_type: Type, |
| 8453 | ) if (build_options.have_llvm) Allocator.Error!void else void { | |
| 8453 | ) (if (build_options.have_llvm) Allocator.Error else error{})!void { | |
| 8454 | 8454 | const named_item = self.type_items.items[@intFromEnum(named_type)]; |
| 8455 | 8455 | self.type_extra.items[named_item.data + std.meta.fieldIndex(Type.NamedStructure, "body").?] = |
| 8456 | 8456 | @intFromEnum(body_type); |
| ... | ... | @@ -9985,7 +9985,7 @@ fn fnTypeAssumeCapacity( |
| 9985 | 9985 | ret: Type, |
| 9986 | 9986 | params: []const Type, |
| 9987 | 9987 | comptime kind: Type.Function.Kind, |
| 9988 | ) if (build_options.have_llvm) Allocator.Error!Type else Type { | |
| 9988 | ) (if (build_options.have_llvm) Allocator.Error else error{})!Type { | |
| 9989 | 9989 | const tag: Type.Tag = switch (kind) { |
| 9990 | 9990 | .normal => .function, |
| 9991 | 9991 | .vararg => .vararg_function, |
| ... | ... | @@ -10169,7 +10169,7 @@ fn structTypeAssumeCapacity( |
| 10169 | 10169 | self: *Builder, |
| 10170 | 10170 | comptime kind: Type.Structure.Kind, |
| 10171 | 10171 | fields: []const Type, |
| 10172 | ) if (build_options.have_llvm) Allocator.Error!Type else Type { | |
| 10172 | ) (if (build_options.have_llvm) Allocator.Error else error{})!Type { | |
| 10173 | 10173 | const tag: Type.Tag = switch (kind) { |
| 10174 | 10174 | .normal => .structure, |
| 10175 | 10175 | .@"packed" => .packed_structure, |
| ... | ... | @@ -10397,7 +10397,7 @@ fn bigIntConstAssumeCapacity( |
| 10397 | 10397 | self: *Builder, |
| 10398 | 10398 | ty: Type, |
| 10399 | 10399 | value: std.math.big.int.Const, |
| 10400 | ) if (build_options.have_llvm) Allocator.Error!Constant else Constant { | |
| 10400 | ) Allocator.Error!Constant { | |
| 10401 | 10401 | const type_item = self.type_items.items[@intFromEnum(ty)]; |
| 10402 | 10402 | assert(type_item.tag == .integer); |
| 10403 | 10403 | const bits = type_item.data; |
| ... | ... | @@ -10743,7 +10743,7 @@ fn structConstAssumeCapacity( |
| 10743 | 10743 | self: *Builder, |
| 10744 | 10744 | ty: Type, |
| 10745 | 10745 | vals: []const Constant, |
| 10746 | ) if (build_options.have_llvm) Allocator.Error!Constant else Constant { | |
| 10746 | ) (if (build_options.have_llvm) Allocator.Error else error{})!Constant { | |
| 10747 | 10747 | const type_item = self.type_items.items[@intFromEnum(ty)]; |
| 10748 | 10748 | var extra = self.typeExtraDataTrail(Type.Structure, switch (type_item.tag) { |
| 10749 | 10749 | .structure, .packed_structure => type_item.data, |
| ... | ... | @@ -10791,7 +10791,7 @@ fn arrayConstAssumeCapacity( |
| 10791 | 10791 | self: *Builder, |
| 10792 | 10792 | ty: Type, |
| 10793 | 10793 | vals: []const Constant, |
| 10794 | ) if (build_options.have_llvm) Allocator.Error!Constant else Constant { | |
| 10794 | ) (if (build_options.have_llvm) Allocator.Error else error{})!Constant { | |
| 10795 | 10795 | const type_item = self.type_items.items[@intFromEnum(ty)]; |
| 10796 | 10796 | const type_extra: struct { len: u64, child: Type } = switch (type_item.tag) { |
| 10797 | 10797 | inline .small_array, .array => |kind| extra: { |
| ... | ... | @@ -10859,7 +10859,7 @@ fn vectorConstAssumeCapacity( |
| 10859 | 10859 | self: *Builder, |
| 10860 | 10860 | ty: Type, |
| 10861 | 10861 | vals: []const Constant, |
| 10862 | ) if (build_options.have_llvm) Allocator.Error!Constant else Constant { | |
| 10862 | ) (if (build_options.have_llvm) Allocator.Error else error{})!Constant { | |
| 10863 | 10863 | assert(ty.isVector(self)); |
| 10864 | 10864 | assert(ty.vectorLen(self) == vals.len); |
| 10865 | 10865 | for (vals) |val| assert(ty.childType(self) == val.typeOf(self)); |
| ... | ... | @@ -10893,7 +10893,7 @@ fn splatConstAssumeCapacity( |
| 10893 | 10893 | self: *Builder, |
| 10894 | 10894 | ty: Type, |
| 10895 | 10895 | val: Constant, |
| 10896 | ) if (build_options.have_llvm) Allocator.Error!Constant else Constant { | |
| 10896 | ) (if (build_options.have_llvm) Allocator.Error else error{})!Constant { | |
| 10897 | 10897 | assert(ty.scalarType(self) == val.typeOf(self)); |
| 10898 | 10898 | |
| 10899 | 10899 | if (!ty.isVector(self)) return val; |
| ... | ... | @@ -11182,7 +11182,7 @@ fn gepConstAssumeCapacity( |
| 11182 | 11182 | base: Constant, |
| 11183 | 11183 | inrange: ?u16, |
| 11184 | 11184 | indices: []const Constant, |
| 11185 | ) if (build_options.have_llvm) Allocator.Error!Constant else Constant { | |
| 11185 | ) (if (build_options.have_llvm) Allocator.Error else error{})!Constant { | |
| 11186 | 11186 | const tag: Constant.Tag = switch (kind) { |
| 11187 | 11187 | .normal => .getelementptr, |
| 11188 | 11188 | .inbounds => .@"getelementptr inbounds", |
src/link/Coff.zig+14-27| ... | ... | @@ -225,7 +225,7 @@ pub const min_text_capacity = padToIdeal(minimum_text_block_size); |
| 225 | 225 | pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Coff { |
| 226 | 226 | assert(options.target.ofmt == .coff); |
| 227 | 227 | |
| 228 | if (build_options.have_llvm and options.use_llvm) { | |
| 228 | if (options.use_llvm) { | |
| 229 | 229 | return createEmpty(allocator, options); |
| 230 | 230 | } |
| 231 | 231 | |
| ... | ... | @@ -267,8 +267,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff { |
| 267 | 267 | .data_directories = comptime mem.zeroes([coff.IMAGE_NUMBEROF_DIRECTORY_ENTRIES]coff.ImageDataDirectory), |
| 268 | 268 | }; |
| 269 | 269 | |
| 270 | const use_llvm = build_options.have_llvm and options.use_llvm; | |
| 271 | if (use_llvm) { | |
| 270 | if (options.use_llvm) { | |
| 272 | 271 | self.llvm_object = try LlvmObject.create(gpa, options); |
| 273 | 272 | } |
| 274 | 273 | return self; |
| ... | ... | @@ -277,9 +276,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Coff { |
| 277 | 276 | pub fn deinit(self: *Coff) void { |
| 278 | 277 | const gpa = self.base.allocator; |
| 279 | 278 | |
| 280 | if (build_options.have_llvm) { | |
| 281 | if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa); | |
| 282 | } | |
| 279 | if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa); | |
| 283 | 280 | |
| 284 | 281 | for (self.objects.items) |*object| { |
| 285 | 282 | object.deinit(gpa); |
| ... | ... | @@ -1036,10 +1033,8 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air: |
| 1036 | 1033 | if (build_options.skip_non_native and builtin.object_format != .coff) { |
| 1037 | 1034 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1038 | 1035 | } |
| 1039 | if (build_options.have_llvm) { | |
| 1040 | if (self.llvm_object) |llvm_object| { | |
| 1041 | return llvm_object.updateFunc(mod, func_index, air, liveness); | |
| 1042 | } | |
| 1036 | if (self.llvm_object) |llvm_object| { | |
| 1037 | return llvm_object.updateFunc(mod, func_index, air, liveness); | |
| 1043 | 1038 | } |
| 1044 | 1039 | const tracy = trace(@src()); |
| 1045 | 1040 | defer tracy.end(); |
| ... | ... | @@ -1147,9 +1142,7 @@ pub fn updateDecl( |
| 1147 | 1142 | if (build_options.skip_non_native and builtin.object_format != .coff) { |
| 1148 | 1143 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1149 | 1144 | } |
| 1150 | if (build_options.have_llvm) { | |
| 1151 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); | |
| 1152 | } | |
| 1145 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); | |
| 1153 | 1146 | const tracy = trace(@src()); |
| 1154 | 1147 | defer tracy.end(); |
| 1155 | 1148 | |
| ... | ... | @@ -1390,9 +1383,7 @@ fn freeUnnamedConsts(self: *Coff, decl_index: Module.Decl.Index) void { |
| 1390 | 1383 | } |
| 1391 | 1384 | |
| 1392 | 1385 | pub fn freeDecl(self: *Coff, decl_index: Module.Decl.Index) void { |
| 1393 | if (build_options.have_llvm) { | |
| 1394 | if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index); | |
| 1395 | } | |
| 1386 | if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index); | |
| 1396 | 1387 | |
| 1397 | 1388 | const mod = self.base.options.module.?; |
| 1398 | 1389 | const decl = mod.declPtr(decl_index); |
| ... | ... | @@ -1419,7 +1410,7 @@ pub fn updateDeclExports( |
| 1419 | 1410 | |
| 1420 | 1411 | const ip = &mod.intern_pool; |
| 1421 | 1412 | |
| 1422 | if (build_options.have_llvm) { | |
| 1413 | if (self.base.options.use_llvm) { | |
| 1423 | 1414 | // Even in the case of LLVM, we need to notice certain exported symbols in order to |
| 1424 | 1415 | // detect the default subsystem. |
| 1425 | 1416 | for (exports) |exp| { |
| ... | ... | @@ -1448,10 +1439,10 @@ pub fn updateDeclExports( |
| 1448 | 1439 | } |
| 1449 | 1440 | } |
| 1450 | 1441 | } |
| 1451 | ||
| 1452 | if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports); | |
| 1453 | 1442 | } |
| 1454 | 1443 | |
| 1444 | if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports); | |
| 1445 | ||
| 1455 | 1446 | if (self.base.options.emit == null) return; |
| 1456 | 1447 | |
| 1457 | 1448 | const gpa = self.base.allocator; |
| ... | ... | @@ -1583,10 +1574,8 @@ fn resolveGlobalSymbol(self: *Coff, current: SymbolWithLoc) !void { |
| 1583 | 1574 | |
| 1584 | 1575 | pub fn flush(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void { |
| 1585 | 1576 | if (self.base.options.emit == null) { |
| 1586 | if (build_options.have_llvm) { | |
| 1587 | if (self.llvm_object) |llvm_object| { | |
| 1588 | return try llvm_object.flushModule(comp, prog_node); | |
| 1589 | } | |
| 1577 | if (self.llvm_object) |llvm_object| { | |
| 1578 | return try llvm_object.flushModule(comp, prog_node); | |
| 1590 | 1579 | } |
| 1591 | 1580 | return; |
| 1592 | 1581 | } |
| ... | ... | @@ -1604,10 +1593,8 @@ pub fn flushModule(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod |
| 1604 | 1593 | const tracy = trace(@src()); |
| 1605 | 1594 | defer tracy.end(); |
| 1606 | 1595 | |
| 1607 | if (build_options.have_llvm) { | |
| 1608 | if (self.llvm_object) |llvm_object| { | |
| 1609 | return try llvm_object.flushModule(comp, prog_node); | |
| 1610 | } | |
| 1596 | if (self.llvm_object) |llvm_object| { | |
| 1597 | return try llvm_object.flushModule(comp, prog_node); | |
| 1611 | 1598 | } |
| 1612 | 1599 | |
| 1613 | 1600 | var sub_prog_node = prog_node.start("COFF Flush", 0); |
src/link/Elf.zig+11-25| ... | ... | @@ -225,7 +225,7 @@ pub const PtrWidth = enum { p32, p64 }; |
| 225 | 225 | pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Elf { |
| 226 | 226 | assert(options.target.ofmt == .elf); |
| 227 | 227 | |
| 228 | if (build_options.have_llvm and options.use_llvm) { | |
| 228 | if (options.use_llvm) { | |
| 229 | 229 | return createEmpty(allocator, options); |
| 230 | 230 | } |
| 231 | 231 | |
| ... | ... | @@ -304,7 +304,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf { |
| 304 | 304 | .ptr_width = ptr_width, |
| 305 | 305 | .page_size = page_size, |
| 306 | 306 | }; |
| 307 | const use_llvm = build_options.have_llvm and options.use_llvm; | |
| 307 | const use_llvm = options.use_llvm; | |
| 308 | 308 | if (use_llvm) { |
| 309 | 309 | self.llvm_object = try LlvmObject.create(gpa, options); |
| 310 | 310 | } |
| ... | ... | @@ -314,9 +314,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Elf { |
| 314 | 314 | pub fn deinit(self: *Elf) void { |
| 315 | 315 | const gpa = self.base.allocator; |
| 316 | 316 | |
| 317 | if (build_options.have_llvm) { | |
| 318 | if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa); | |
| 319 | } | |
| 317 | if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa); | |
| 320 | 318 | |
| 321 | 319 | for (self.sections.items(.free_list)) |*free_list| { |
| 322 | 320 | free_list.deinit(gpa); |
| ... | ... | @@ -1005,10 +1003,8 @@ pub fn markDirty(self: *Elf, shdr_index: u16, phdr_index: ?u16) void { |
| 1005 | 1003 | |
| 1006 | 1004 | pub fn flush(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void { |
| 1007 | 1005 | if (self.base.options.emit == null) { |
| 1008 | if (build_options.have_llvm) { | |
| 1009 | if (self.llvm_object) |llvm_object| { | |
| 1010 | return try llvm_object.flushModule(comp, prog_node); | |
| 1011 | } | |
| 1006 | if (self.llvm_object) |llvm_object| { | |
| 1007 | return try llvm_object.flushModule(comp, prog_node); | |
| 1012 | 1008 | } |
| 1013 | 1009 | return; |
| 1014 | 1010 | } |
| ... | ... | @@ -1026,10 +1022,8 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node |
| 1026 | 1022 | const tracy = trace(@src()); |
| 1027 | 1023 | defer tracy.end(); |
| 1028 | 1024 | |
| 1029 | if (build_options.have_llvm) { | |
| 1030 | if (self.llvm_object) |llvm_object| { | |
| 1031 | return try llvm_object.flushModule(comp, prog_node); | |
| 1032 | } | |
| 1025 | if (self.llvm_object) |llvm_object| { | |
| 1026 | return try llvm_object.flushModule(comp, prog_node); | |
| 1033 | 1027 | } |
| 1034 | 1028 | |
| 1035 | 1029 | const gpa = self.base.allocator; |
| ... | ... | @@ -2392,9 +2386,7 @@ fn freeUnnamedConsts(self: *Elf, decl_index: Module.Decl.Index) void { |
| 2392 | 2386 | } |
| 2393 | 2387 | |
| 2394 | 2388 | pub fn freeDecl(self: *Elf, decl_index: Module.Decl.Index) void { |
| 2395 | if (build_options.have_llvm) { | |
| 2396 | if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index); | |
| 2397 | } | |
| 2389 | if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index); | |
| 2398 | 2390 | |
| 2399 | 2391 | const mod = self.base.options.module.?; |
| 2400 | 2392 | const decl = mod.declPtr(decl_index); |
| ... | ... | @@ -2577,9 +2569,7 @@ pub fn updateFunc(self: *Elf, mod: *Module, func_index: InternPool.Index, air: A |
| 2577 | 2569 | if (build_options.skip_non_native and builtin.object_format != .elf) { |
| 2578 | 2570 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 2579 | 2571 | } |
| 2580 | if (build_options.have_llvm) { | |
| 2581 | if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness); | |
| 2582 | } | |
| 2572 | if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness); | |
| 2583 | 2573 | |
| 2584 | 2574 | const tracy = trace(@src()); |
| 2585 | 2575 | defer tracy.end(); |
| ... | ... | @@ -2637,9 +2627,7 @@ pub fn updateDecl( |
| 2637 | 2627 | if (build_options.skip_non_native and builtin.object_format != .elf) { |
| 2638 | 2628 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 2639 | 2629 | } |
| 2640 | if (build_options.have_llvm) { | |
| 2641 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); | |
| 2642 | } | |
| 2630 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); | |
| 2643 | 2631 | |
| 2644 | 2632 | const tracy = trace(@src()); |
| 2645 | 2633 | defer tracy.end(); |
| ... | ... | @@ -2859,9 +2847,7 @@ pub fn updateDeclExports( |
| 2859 | 2847 | if (build_options.skip_non_native and builtin.object_format != .elf) { |
| 2860 | 2848 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 2861 | 2849 | } |
| 2862 | if (build_options.have_llvm) { | |
| 2863 | if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports); | |
| 2864 | } | |
| 2850 | if (self.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports); | |
| 2865 | 2851 | |
| 2866 | 2852 | if (self.base.options.emit == null) return; |
| 2867 | 2853 |
src/link/MachO.zig+12-27| ... | ... | @@ -422,7 +422,6 @@ pub fn openPath(allocator: Allocator, options: link.Options) !*MachO { |
| 422 | 422 | pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO { |
| 423 | 423 | const cpu_arch = options.target.cpu.arch; |
| 424 | 424 | const page_size: u16 = if (cpu_arch == .aarch64) 0x4000 else 0x1000; |
| 425 | const use_llvm = build_options.have_llvm and options.use_llvm; | |
| 426 | 425 | |
| 427 | 426 | const self = try gpa.create(MachO); |
| 428 | 427 | errdefer gpa.destroy(self); |
| ... | ... | @@ -435,13 +434,13 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO { |
| 435 | 434 | .file = null, |
| 436 | 435 | }, |
| 437 | 436 | .page_size = page_size, |
| 438 | .mode = if (use_llvm or options.module == null or options.cache_mode == .whole) | |
| 437 | .mode = if (options.use_llvm or options.module == null or options.cache_mode == .whole) | |
| 439 | 438 | .zld |
| 440 | 439 | else |
| 441 | 440 | .incremental, |
| 442 | 441 | }; |
| 443 | 442 | |
| 444 | if (use_llvm) { | |
| 443 | if (options.use_llvm) { | |
| 445 | 444 | self.llvm_object = try LlvmObject.create(gpa, options); |
| 446 | 445 | } |
| 447 | 446 | |
| ... | ... | @@ -452,10 +451,8 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*MachO { |
| 452 | 451 | |
| 453 | 452 | pub fn flush(self: *MachO, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void { |
| 454 | 453 | if (self.base.options.emit == null) { |
| 455 | if (build_options.have_llvm) { | |
| 456 | if (self.llvm_object) |llvm_object| { | |
| 457 | try llvm_object.flushModule(comp, prog_node); | |
| 458 | } | |
| 454 | if (self.llvm_object) |llvm_object| { | |
| 455 | try llvm_object.flushModule(comp, prog_node); | |
| 459 | 456 | } |
| 460 | 457 | return; |
| 461 | 458 | } |
| ... | ... | @@ -479,10 +476,8 @@ pub fn flushModule(self: *MachO, comp: *Compilation, prog_node: *std.Progress.No |
| 479 | 476 | const tracy = trace(@src()); |
| 480 | 477 | defer tracy.end(); |
| 481 | 478 | |
| 482 | if (build_options.have_llvm) { | |
| 483 | if (self.llvm_object) |llvm_object| { | |
| 484 | return try llvm_object.flushModule(comp, prog_node); | |
| 485 | } | |
| 479 | if (self.llvm_object) |llvm_object| { | |
| 480 | return try llvm_object.flushModule(comp, prog_node); | |
| 486 | 481 | } |
| 487 | 482 | |
| 488 | 483 | var arena_allocator = std.heap.ArenaAllocator.init(self.base.allocator); |
| ... | ... | @@ -1622,9 +1617,7 @@ fn resolveSymbolsInDylibs(self: *MachO, actions: *std.ArrayList(ResolveAction)) |
| 1622 | 1617 | pub fn deinit(self: *MachO) void { |
| 1623 | 1618 | const gpa = self.base.allocator; |
| 1624 | 1619 | |
| 1625 | if (build_options.have_llvm) { | |
| 1626 | if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa); | |
| 1627 | } | |
| 1620 | if (self.llvm_object) |llvm_object| llvm_object.destroy(gpa); | |
| 1628 | 1621 | |
| 1629 | 1622 | if (self.d_sym) |*d_sym| { |
| 1630 | 1623 | d_sym.deinit(); |
| ... | ... | @@ -1855,9 +1848,7 @@ pub fn updateFunc(self: *MachO, mod: *Module, func_index: InternPool.Index, air: |
| 1855 | 1848 | if (build_options.skip_non_native and builtin.object_format != .macho) { |
| 1856 | 1849 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1857 | 1850 | } |
| 1858 | if (build_options.have_llvm) { | |
| 1859 | if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness); | |
| 1860 | } | |
| 1851 | if (self.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness); | |
| 1861 | 1852 | const tracy = trace(@src()); |
| 1862 | 1853 | defer tracy.end(); |
| 1863 | 1854 | |
| ... | ... | @@ -1979,9 +1970,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo |
| 1979 | 1970 | if (build_options.skip_non_native and builtin.object_format != .macho) { |
| 1980 | 1971 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1981 | 1972 | } |
| 1982 | if (build_options.have_llvm) { | |
| 1983 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); | |
| 1984 | } | |
| 1973 | if (self.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); | |
| 1985 | 1974 | const tracy = trace(@src()); |
| 1986 | 1975 | defer tracy.end(); |
| 1987 | 1976 | |
| ... | ... | @@ -2387,10 +2376,8 @@ pub fn updateDeclExports( |
| 2387 | 2376 | if (build_options.skip_non_native and builtin.object_format != .macho) { |
| 2388 | 2377 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 2389 | 2378 | } |
| 2390 | if (build_options.have_llvm) { | |
| 2391 | if (self.llvm_object) |llvm_object| | |
| 2392 | return llvm_object.updateDeclExports(mod, decl_index, exports); | |
| 2393 | } | |
| 2379 | if (self.llvm_object) |llvm_object| | |
| 2380 | return llvm_object.updateDeclExports(mod, decl_index, exports); | |
| 2394 | 2381 | |
| 2395 | 2382 | if (self.base.options.emit == null) return; |
| 2396 | 2383 | |
| ... | ... | @@ -2542,9 +2529,7 @@ fn freeUnnamedConsts(self: *MachO, decl_index: Module.Decl.Index) void { |
| 2542 | 2529 | } |
| 2543 | 2530 | |
| 2544 | 2531 | pub fn freeDecl(self: *MachO, decl_index: Module.Decl.Index) void { |
| 2545 | if (build_options.have_llvm) { | |
| 2546 | if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index); | |
| 2547 | } | |
| 2532 | if (self.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index); | |
| 2548 | 2533 | const mod = self.base.options.module.?; |
| 2549 | 2534 | const decl = mod.declPtr(decl_index); |
| 2550 | 2535 |
src/link/NvPtx.zig-8| ... | ... | @@ -27,7 +27,6 @@ llvm_object: *LlvmObject, |
| 27 | 27 | ptx_file_name: []const u8, |
| 28 | 28 | |
| 29 | 29 | pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx { |
| 30 | if (!build_options.have_llvm) return error.PtxArchNotSupported; | |
| 31 | 30 | if (!options.use_llvm) return error.PtxArchNotSupported; |
| 32 | 31 | |
| 33 | 32 | if (!options.target.cpu.arch.isNvptx()) return error.PtxArchNotSupported; |
| ... | ... | @@ -55,7 +54,6 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*NvPtx { |
| 55 | 54 | } |
| 56 | 55 | |
| 57 | 56 | pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*NvPtx { |
| 58 | if (!build_options.have_llvm) @panic("nvptx target requires a zig compiler with llvm enabled."); | |
| 59 | 57 | if (!options.use_llvm) return error.PtxArchNotSupported; |
| 60 | 58 | assert(options.target.ofmt == .nvptx); |
| 61 | 59 | |
| ... | ... | @@ -64,18 +62,15 @@ pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Option |
| 64 | 62 | } |
| 65 | 63 | |
| 66 | 64 | pub fn deinit(self: *NvPtx) void { |
| 67 | if (!build_options.have_llvm) return; | |
| 68 | 65 | self.llvm_object.destroy(self.base.allocator); |
| 69 | 66 | self.base.allocator.free(self.ptx_file_name); |
| 70 | 67 | } |
| 71 | 68 | |
| 72 | 69 | pub fn updateFunc(self: *NvPtx, module: *Module, func_index: InternPool.Index, air: Air, liveness: Liveness) !void { |
| 73 | if (!build_options.have_llvm) return; | |
| 74 | 70 | try self.llvm_object.updateFunc(module, func_index, air, liveness); |
| 75 | 71 | } |
| 76 | 72 | |
| 77 | 73 | pub fn updateDecl(self: *NvPtx, module: *Module, decl_index: Module.Decl.Index) !void { |
| 78 | if (!build_options.have_llvm) return; | |
| 79 | 74 | return self.llvm_object.updateDecl(module, decl_index); |
| 80 | 75 | } |
| 81 | 76 | |
| ... | ... | @@ -85,7 +80,6 @@ pub fn updateDeclExports( |
| 85 | 80 | decl_index: Module.Decl.Index, |
| 86 | 81 | exports: []const *Module.Export, |
| 87 | 82 | ) !void { |
| 88 | if (!build_options.have_llvm) return; | |
| 89 | 83 | if (build_options.skip_non_native and builtin.object_format != .nvptx) { |
| 90 | 84 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 91 | 85 | } |
| ... | ... | @@ -93,7 +87,6 @@ pub fn updateDeclExports( |
| 93 | 87 | } |
| 94 | 88 | |
| 95 | 89 | pub fn freeDecl(self: *NvPtx, decl_index: Module.Decl.Index) void { |
| 96 | if (!build_options.have_llvm) return; | |
| 97 | 90 | return self.llvm_object.freeDecl(decl_index); |
| 98 | 91 | } |
| 99 | 92 | |
| ... | ... | @@ -102,7 +95,6 @@ pub fn flush(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.Node) li |
| 102 | 95 | } |
| 103 | 96 | |
| 104 | 97 | pub fn flushModule(self: *NvPtx, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void { |
| 105 | if (!build_options.have_llvm) return; | |
| 106 | 98 | if (build_options.skip_non_native) { |
| 107 | 99 | @panic("Attempted to compile for architecture that was disabled by build configuration"); |
| 108 | 100 | } |
src/link/Wasm.zig+12-27| ... | ... | @@ -360,7 +360,7 @@ pub const StringTable = struct { |
| 360 | 360 | pub fn openPath(allocator: Allocator, sub_path: []const u8, options: link.Options) !*Wasm { |
| 361 | 361 | assert(options.target.ofmt == .wasm); |
| 362 | 362 | |
| 363 | if (build_options.have_llvm and options.use_llvm and options.use_lld) { | |
| 363 | if (options.use_llvm and options.use_lld) { | |
| 364 | 364 | return createEmpty(allocator, options); |
| 365 | 365 | } |
| 366 | 366 | |
| ... | ... | @@ -522,8 +522,7 @@ pub fn createEmpty(gpa: Allocator, options: link.Options) !*Wasm { |
| 522 | 522 | .name = undefined, |
| 523 | 523 | }; |
| 524 | 524 | |
| 525 | const use_llvm = build_options.have_llvm and options.use_llvm; | |
| 526 | if (use_llvm) { | |
| 525 | if (options.use_llvm) { | |
| 527 | 526 | wasm.llvm_object = try LlvmObject.create(gpa, options); |
| 528 | 527 | } |
| 529 | 528 | return wasm; |
| ... | ... | @@ -1273,9 +1272,7 @@ fn checkUndefinedSymbols(wasm: *const Wasm) !void { |
| 1273 | 1272 | |
| 1274 | 1273 | pub fn deinit(wasm: *Wasm) void { |
| 1275 | 1274 | const gpa = wasm.base.allocator; |
| 1276 | if (build_options.have_llvm) { | |
| 1277 | if (wasm.llvm_object) |llvm_object| llvm_object.destroy(gpa); | |
| 1278 | } | |
| 1275 | if (wasm.llvm_object) |llvm_object| llvm_object.destroy(gpa); | |
| 1279 | 1276 | |
| 1280 | 1277 | for (wasm.func_types.items) |*func_type| { |
| 1281 | 1278 | func_type.deinit(gpa); |
| ... | ... | @@ -1354,9 +1351,7 @@ pub fn updateFunc(wasm: *Wasm, mod: *Module, func_index: InternPool.Index, air: |
| 1354 | 1351 | if (build_options.skip_non_native and builtin.object_format != .wasm) { |
| 1355 | 1352 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1356 | 1353 | } |
| 1357 | if (build_options.have_llvm) { | |
| 1358 | if (wasm.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness); | |
| 1359 | } | |
| 1354 | if (wasm.llvm_object) |llvm_object| return llvm_object.updateFunc(mod, func_index, air, liveness); | |
| 1360 | 1355 | |
| 1361 | 1356 | const tracy = trace(@src()); |
| 1362 | 1357 | defer tracy.end(); |
| ... | ... | @@ -1422,9 +1417,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi |
| 1422 | 1417 | if (build_options.skip_non_native and builtin.object_format != .wasm) { |
| 1423 | 1418 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1424 | 1419 | } |
| 1425 | if (build_options.have_llvm) { | |
| 1426 | if (wasm.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); | |
| 1427 | } | |
| 1420 | if (wasm.llvm_object) |llvm_object| return llvm_object.updateDecl(mod, decl_index); | |
| 1428 | 1421 | |
| 1429 | 1422 | const tracy = trace(@src()); |
| 1430 | 1423 | defer tracy.end(); |
| ... | ... | @@ -1708,9 +1701,7 @@ pub fn updateDeclExports( |
| 1708 | 1701 | if (build_options.skip_non_native and builtin.object_format != .wasm) { |
| 1709 | 1702 | @panic("Attempted to compile for object format that was disabled by build configuration"); |
| 1710 | 1703 | } |
| 1711 | if (build_options.have_llvm) { | |
| 1712 | if (wasm.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports); | |
| 1713 | } | |
| 1704 | if (wasm.llvm_object) |llvm_object| return llvm_object.updateDeclExports(mod, decl_index, exports); | |
| 1714 | 1705 | |
| 1715 | 1706 | if (wasm.base.options.emit == null) return; |
| 1716 | 1707 | |
| ... | ... | @@ -1811,9 +1802,7 @@ pub fn updateDeclExports( |
| 1811 | 1802 | } |
| 1812 | 1803 | |
| 1813 | 1804 | pub fn freeDecl(wasm: *Wasm, decl_index: Module.Decl.Index) void { |
| 1814 | if (build_options.have_llvm) { | |
| 1815 | if (wasm.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index); | |
| 1816 | } | |
| 1805 | if (wasm.llvm_object) |llvm_object| return llvm_object.freeDecl(decl_index); | |
| 1817 | 1806 | const mod = wasm.base.options.module.?; |
| 1818 | 1807 | const decl = mod.declPtr(decl_index); |
| 1819 | 1808 | const atom_index = wasm.decls.get(decl_index).?; |
| ... | ... | @@ -3137,17 +3126,15 @@ fn resetState(wasm: *Wasm) void { |
| 3137 | 3126 | |
| 3138 | 3127 | pub fn flush(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Node) link.File.FlushError!void { |
| 3139 | 3128 | if (wasm.base.options.emit == null) { |
| 3140 | if (build_options.have_llvm) { | |
| 3141 | if (wasm.llvm_object) |llvm_object| { | |
| 3142 | return try llvm_object.flushModule(comp, prog_node); | |
| 3143 | } | |
| 3129 | if (wasm.llvm_object) |llvm_object| { | |
| 3130 | return try llvm_object.flushModule(comp, prog_node); | |
| 3144 | 3131 | } |
| 3145 | 3132 | return; |
| 3146 | 3133 | } |
| 3147 | 3134 | |
| 3148 | 3135 | if (build_options.have_llvm and wasm.base.options.use_lld) { |
| 3149 | 3136 | return wasm.linkWithLLD(comp, prog_node); |
| 3150 | } else if (build_options.have_llvm and wasm.base.options.use_llvm and !wasm.base.options.use_lld) { | |
| 3137 | } else if (wasm.base.options.use_llvm and !wasm.base.options.use_lld) { | |
| 3151 | 3138 | return wasm.linkWithZld(comp, prog_node); |
| 3152 | 3139 | } else { |
| 3153 | 3140 | return wasm.flushModule(comp, prog_node); |
| ... | ... | @@ -3365,10 +3352,8 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod |
| 3365 | 3352 | const tracy = trace(@src()); |
| 3366 | 3353 | defer tracy.end(); |
| 3367 | 3354 | |
| 3368 | if (build_options.have_llvm) { | |
| 3369 | if (wasm.llvm_object) |llvm_object| { | |
| 3370 | return try llvm_object.flushModule(comp, prog_node); | |
| 3371 | } | |
| 3355 | if (wasm.llvm_object) |llvm_object| { | |
| 3356 | return try llvm_object.flushModule(comp, prog_node); | |
| 3372 | 3357 | } |
| 3373 | 3358 | |
| 3374 | 3359 | var sub_prog_node = prog_node.start("Wasm Flush", 0); |
src/type.zig+6-6| ... | ... | @@ -2664,10 +2664,10 @@ pub const Type = struct { |
| 2664 | 2664 | .int_type => false, |
| 2665 | 2665 | .ptr_type => |ptr_type| { |
| 2666 | 2666 | const child_ty = ptr_type.child.toType(); |
| 2667 | if (child_ty.zigTypeTag(mod) == .Fn) { | |
| 2668 | return false; | |
| 2669 | } else { | |
| 2670 | return child_ty.comptimeOnly(mod); | |
| 2667 | switch (child_ty.zigTypeTag(mod)) { | |
| 2668 | .Fn => return mod.typeToFunc(child_ty).?.is_generic, | |
| 2669 | .Opaque => return false, | |
| 2670 | else => return child_ty.comptimeOnly(mod), | |
| 2671 | 2671 | } |
| 2672 | 2672 | }, |
| 2673 | 2673 | .anyframe_type => |child| { |
| ... | ... | @@ -2704,7 +2704,6 @@ pub const Type = struct { |
| 2704 | 2704 | .c_longlong, |
| 2705 | 2705 | .c_ulonglong, |
| 2706 | 2706 | .c_longdouble, |
| 2707 | .anyopaque, | |
| 2708 | 2707 | .bool, |
| 2709 | 2708 | .void, |
| 2710 | 2709 | .anyerror, |
| ... | ... | @@ -2723,6 +2722,7 @@ pub const Type = struct { |
| 2723 | 2722 | .extern_options, |
| 2724 | 2723 | => false, |
| 2725 | 2724 | |
| 2725 | .anyopaque, | |
| 2726 | 2726 | .type, |
| 2727 | 2727 | .comptime_int, |
| 2728 | 2728 | .comptime_float, |
| ... | ... | @@ -2769,7 +2769,7 @@ pub const Type = struct { |
| 2769 | 2769 | } |
| 2770 | 2770 | }, |
| 2771 | 2771 | |
| 2772 | .opaque_type => false, | |
| 2772 | .opaque_type => true, | |
| 2773 | 2773 | |
| 2774 | 2774 | .enum_type => |enum_type| enum_type.tag_ty.toType().comptimeOnly(mod), |
| 2775 | 2775 |
test/behavior/optional.zig+5| ... | ... | @@ -498,3 +498,8 @@ test "cast slice to const slice nested in error union and optional" { |
| 498 | 498 | }; |
| 499 | 499 | try std.testing.expectError(error.Foo, S.outer()); |
| 500 | 500 | } |
| 501 | ||
| 502 | test "variable of optional of noreturn" { | |
| 503 | var null_opv: ?noreturn = null; | |
| 504 | try std.testing.expectEqual(@as(?noreturn, null), null_opv); | |
| 505 | } |