| author | |
| committer | |
| log | 937e8cb7051a3de537e11c2d52946f772f7449c3 |
| tree | 94d5b2cc7c19a9a16fd13099e10249ef64278b8f |
| parent | 873c695c41dffd89ba7ef1b3ed6662e429bfa00d |
| parent | 864bb5dc075fdc549e116b93914f30bff8cc7cf5 |
| signature |
C backend: remove unneeded ordering mechanism3 files changed, 42 insertions(+), 58 deletions(-)
src/Compilation.zig+1-1| ... | @@ -3495,7 +3495,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v | ... | @@ -3495,7 +3495,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v |
| 3495 | .module = module, | 3495 | .module = module, |
| 3496 | .error_msg = null, | 3496 | .error_msg = null, |
| 3497 | .decl_index = decl_index.toOptional(), | 3497 | .decl_index = decl_index.toOptional(), |
| 3498 | .decl = decl, | 3498 | .is_naked_fn = false, |
| 3499 | .fwd_decl = fwd_decl.toManaged(gpa), | 3499 | .fwd_decl = fwd_decl.toManaged(gpa), |
| 3500 | .ctypes = .{}, | 3500 | .ctypes = .{}, |
| 3501 | }; | 3501 | }; |
src/codegen/c.zig+27-21| ... | @@ -522,8 +522,8 @@ pub const Object = struct { | ... | @@ -522,8 +522,8 @@ pub const Object = struct { |
| 522 | pub const DeclGen = struct { | 522 | pub const DeclGen = struct { |
| 523 | gpa: mem.Allocator, | 523 | gpa: mem.Allocator, |
| 524 | module: *Module, | 524 | module: *Module, |
| 525 | decl: ?*Decl, | ||
| 526 | decl_index: Decl.OptionalIndex, | 525 | decl_index: Decl.OptionalIndex, |
| 526 | is_naked_fn: bool, | ||
| 527 | /// This is a borrowed reference from `link.C`. | 527 | /// This is a borrowed reference from `link.C`. |
| 528 | fwd_decl: std.ArrayList(u8), | 528 | fwd_decl: std.ArrayList(u8), |
| 529 | error_msg: ?*Module.ErrorMsg, | 529 | error_msg: ?*Module.ErrorMsg, |
| ... | @@ -532,8 +532,10 @@ pub const DeclGen = struct { | ... | @@ -532,8 +532,10 @@ pub const DeclGen = struct { |
| 532 | fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } { | 532 | fn fail(dg: *DeclGen, comptime format: []const u8, args: anytype) error{ AnalysisFail, OutOfMemory } { |
| 533 | @setCold(true); | 533 | @setCold(true); |
| 534 | const mod = dg.module; | 534 | const mod = dg.module; |
| 535 | const decl_index = dg.decl_index.unwrap().?; | ||
| 536 | const decl = mod.declPtr(decl_index); | ||
| 535 | const src = LazySrcLoc.nodeOffset(0); | 537 | const src = LazySrcLoc.nodeOffset(0); |
| 536 | const src_loc = src.toSrcLoc(dg.decl.?, mod); | 538 | const src_loc = src.toSrcLoc(decl, mod); |
| 537 | dg.error_msg = try Module.ErrorMsg.create(dg.gpa, src_loc, format, args); | 539 | dg.error_msg = try Module.ErrorMsg.create(dg.gpa, src_loc, format, args); |
| 538 | return error.AnalysisFail; | 540 | return error.AnalysisFail; |
| 539 | } | 541 | } |
| ... | @@ -2493,8 +2495,8 @@ fn genExports(o: *Object) !void { | ... | @@ -2493,8 +2495,8 @@ fn genExports(o: *Object) !void { |
| 2493 | 2495 | ||
| 2494 | const mod = o.dg.module; | 2496 | const mod = o.dg.module; |
| 2495 | const ip = &mod.intern_pool; | 2497 | const ip = &mod.intern_pool; |
| 2496 | const decl = o.dg.decl.?; | ||
| 2497 | const decl_index = o.dg.decl_index.unwrap().?; | 2498 | const decl_index = o.dg.decl_index.unwrap().?; |
| 2499 | const decl = mod.declPtr(decl_index); | ||
| 2498 | const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() }; | 2500 | const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() }; |
| 2499 | const fwd = o.dg.fwd_decl.writer(); | 2501 | const fwd = o.dg.fwd_decl.writer(); |
| 2500 | 2502 | ||
| ... | @@ -2634,9 +2636,10 @@ pub fn genFunc(f: *Function) !void { | ... | @@ -2634,9 +2636,10 @@ pub fn genFunc(f: *Function) !void { |
| 2634 | const mod = o.dg.module; | 2636 | const mod = o.dg.module; |
| 2635 | const gpa = o.dg.gpa; | 2637 | const gpa = o.dg.gpa; |
| 2636 | const decl_index = o.dg.decl_index.unwrap().?; | 2638 | const decl_index = o.dg.decl_index.unwrap().?; |
| 2639 | const decl = mod.declPtr(decl_index); | ||
| 2637 | const tv: TypedValue = .{ | 2640 | const tv: TypedValue = .{ |
| 2638 | .ty = o.dg.decl.?.ty, | 2641 | .ty = decl.ty, |
| 2639 | .val = o.dg.decl.?.val, | 2642 | .val = decl.val, |
| 2640 | }; | 2643 | }; |
| 2641 | 2644 | ||
| 2642 | o.code_header = std.ArrayList(u8).init(gpa); | 2645 | o.code_header = std.ArrayList(u8).init(gpa); |
| ... | @@ -2719,19 +2722,20 @@ pub fn genDecl(o: *Object) !void { | ... | @@ -2719,19 +2722,20 @@ pub fn genDecl(o: *Object) !void { |
| 2719 | defer tracy.end(); | 2722 | defer tracy.end(); |
| 2720 | 2723 | ||
| 2721 | const mod = o.dg.module; | 2724 | const mod = o.dg.module; |
| 2722 | const decl = o.dg.decl.?; | 2725 | const decl_index = o.dg.decl_index.unwrap().?; |
| 2723 | const decl_c_value = .{ .decl = o.dg.decl_index.unwrap().? }; | 2726 | const decl_c_value = .{ .decl = decl_index }; |
| 2727 | const decl = mod.declPtr(decl_index); | ||
| 2724 | const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() }; | 2728 | const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() }; |
| 2725 | 2729 | ||
| 2726 | if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return; | 2730 | if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return; |
| 2727 | if (tv.val.getExternFunc(mod)) |_| { | 2731 | if (tv.val.getExternFunc(mod)) |_| { |
| 2728 | const fwd_decl_writer = o.dg.fwd_decl.writer(); | 2732 | const fwd_decl_writer = o.dg.fwd_decl.writer(); |
| 2729 | try fwd_decl_writer.writeAll("zig_extern "); | 2733 | try fwd_decl_writer.writeAll("zig_extern "); |
| 2730 | try o.dg.renderFunctionSignature(fwd_decl_writer, decl_c_value.decl, .forward, .{ .export_index = 0 }); | 2734 | try o.dg.renderFunctionSignature(fwd_decl_writer, decl_index, .forward, .{ .export_index = 0 }); |
| 2731 | try fwd_decl_writer.writeAll(";\n"); | 2735 | try fwd_decl_writer.writeAll(";\n"); |
| 2732 | try genExports(o); | 2736 | try genExports(o); |
| 2733 | } else if (tv.val.getVariable(mod)) |variable| { | 2737 | } else if (tv.val.getVariable(mod)) |variable| { |
| 2734 | try o.dg.renderFwdDecl(decl_c_value.decl, variable); | 2738 | try o.dg.renderFwdDecl(decl_index, variable); |
| 2735 | try genExports(o); | 2739 | try genExports(o); |
| 2736 | 2740 | ||
| 2737 | if (variable.is_extern) return; | 2741 | if (variable.is_extern) return; |
| ... | @@ -2750,7 +2754,7 @@ pub fn genDecl(o: *Object) !void { | ... | @@ -2750,7 +2754,7 @@ pub fn genDecl(o: *Object) !void { |
| 2750 | try w.writeByte(';'); | 2754 | try w.writeByte(';'); |
| 2751 | try o.indent_writer.insertNewline(); | 2755 | try o.indent_writer.insertNewline(); |
| 2752 | } else { | 2756 | } else { |
| 2753 | const is_global = o.dg.module.decl_exports.contains(decl_c_value.decl); | 2757 | const is_global = o.dg.module.decl_exports.contains(decl_index); |
| 2754 | const fwd_decl_writer = o.dg.fwd_decl.writer(); | 2758 | const fwd_decl_writer = o.dg.fwd_decl.writer(); |
| 2755 | 2759 | ||
| 2756 | try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static "); | 2760 | try fwd_decl_writer.writeAll(if (is_global) "zig_extern " else "static "); |
| ... | @@ -2773,12 +2777,14 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void { | ... | @@ -2773,12 +2777,14 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void { |
| 2773 | const tracy = trace(@src()); | 2777 | const tracy = trace(@src()); |
| 2774 | defer tracy.end(); | 2778 | defer tracy.end(); |
| 2775 | 2779 | ||
| 2780 | const mod = dg.module; | ||
| 2781 | const decl_index = dg.decl_index.unwrap().?; | ||
| 2782 | const decl = mod.declPtr(decl_index); | ||
| 2776 | const tv: TypedValue = .{ | 2783 | const tv: TypedValue = .{ |
| 2777 | .ty = dg.decl.?.ty, | 2784 | .ty = decl.ty, |
| 2778 | .val = dg.decl.?.val, | 2785 | .val = decl.val, |
| 2779 | }; | 2786 | }; |
| 2780 | const writer = dg.fwd_decl.writer(); | 2787 | const writer = dg.fwd_decl.writer(); |
| 2781 | const mod = dg.module; | ||
| 2782 | 2788 | ||
| 2783 | switch (tv.ty.zigTypeTag(mod)) { | 2789 | switch (tv.ty.zigTypeTag(mod)) { |
| 2784 | .Fn => { | 2790 | .Fn => { |
| ... | @@ -3504,8 +3510,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue { | ... | @@ -3504,8 +3510,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue { |
| 3504 | } else { | 3510 | } else { |
| 3505 | try reap(f, inst, &.{un_op}); | 3511 | try reap(f, inst, &.{un_op}); |
| 3506 | // Not even allowed to return void in a naked function. | 3512 | // Not even allowed to return void in a naked function. |
| 3507 | if (if (f.object.dg.decl) |decl| decl.ty.fnCallingConvention(mod) != .Naked else true) | 3513 | if (!f.object.dg.is_naked_fn) try writer.writeAll("return;\n"); |
| 3508 | try writer.writeAll("return;\n"); | ||
| 3509 | } | 3514 | } |
| 3510 | return .none; | 3515 | return .none; |
| 3511 | } | 3516 | } |
| ... | @@ -4144,7 +4149,7 @@ fn airCall( | ... | @@ -4144,7 +4149,7 @@ fn airCall( |
| 4144 | ) !CValue { | 4149 | ) !CValue { |
| 4145 | const mod = f.object.dg.module; | 4150 | const mod = f.object.dg.module; |
| 4146 | // Not even allowed to call panic in a naked function. | 4151 | // Not even allowed to call panic in a naked function. |
| 4147 | if (f.object.dg.decl) |decl| if (decl.ty.fnCallingConvention(mod) == .Naked) return .none; | 4152 | if (f.object.dg.is_naked_fn) return .none; |
| 4148 | 4153 | ||
| 4149 | const gpa = f.object.dg.gpa; | 4154 | const gpa = f.object.dg.gpa; |
| 4150 | const writer = f.object.writer(); | 4155 | const writer = f.object.writer(); |
| ... | @@ -4637,9 +4642,8 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca | ... | @@ -4637,9 +4642,8 @@ fn bitcast(f: *Function, dest_ty: Type, operand: CValue, operand_ty: Type) !Loca |
| 4637 | } | 4642 | } |
| 4638 | 4643 | ||
| 4639 | fn airTrap(f: *Function, writer: anytype) !CValue { | 4644 | fn airTrap(f: *Function, writer: anytype) !CValue { |
| 4640 | const mod = f.object.dg.module; | ||
| 4641 | // Not even allowed to call trap in a naked function. | 4645 | // Not even allowed to call trap in a naked function. |
| 4642 | if (f.object.dg.decl) |decl| if (decl.ty.fnCallingConvention(mod) == .Naked) return .none; | 4646 | if (f.object.dg.is_naked_fn) return .none; |
| 4643 | 4647 | ||
| 4644 | try writer.writeAll("zig_trap();\n"); | 4648 | try writer.writeAll("zig_trap();\n"); |
| 4645 | return .none; | 4649 | return .none; |
| ... | @@ -4682,9 +4686,8 @@ fn airFence(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -4682,9 +4686,8 @@ fn airFence(f: *Function, inst: Air.Inst.Index) !CValue { |
| 4682 | } | 4686 | } |
| 4683 | 4687 | ||
| 4684 | fn airUnreach(f: *Function) !CValue { | 4688 | fn airUnreach(f: *Function) !CValue { |
| 4685 | const mod = f.object.dg.module; | ||
| 4686 | // Not even allowed to call unreachable in a naked function. | 4689 | // Not even allowed to call unreachable in a naked function. |
| 4687 | if (f.object.dg.decl) |decl| if (decl.ty.fnCallingConvention(mod) == .Naked) return .none; | 4690 | if (f.object.dg.is_naked_fn) return .none; |
| 4688 | 4691 | ||
| 4689 | try f.object.writer().writeAll("zig_unreachable();\n"); | 4692 | try f.object.writer().writeAll("zig_unreachable();\n"); |
| 4690 | return .none; | 4693 | return .none; |
| ... | @@ -7194,8 +7197,11 @@ fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue { | ... | @@ -7194,8 +7197,11 @@ fn airMulAdd(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7194 | } | 7197 | } |
| 7195 | 7198 | ||
| 7196 | fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue { | 7199 | fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue { |
| 7200 | const mod = f.object.dg.module; | ||
| 7197 | const inst_ty = f.typeOfIndex(inst); | 7201 | const inst_ty = f.typeOfIndex(inst); |
| 7198 | const fn_cty = try f.typeToCType(f.object.dg.decl.?.ty, .complete); | 7202 | const decl_index = f.object.dg.decl_index.unwrap().?; |
| 7203 | const decl = mod.declPtr(decl_index); | ||
| 7204 | const fn_cty = try f.typeToCType(decl.ty, .complete); | ||
| 7199 | const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len; | 7205 | const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len; |
| 7200 | 7206 | ||
| 7201 | const writer = f.object.writer(); | 7207 | const writer = f.object.writer(); |
src/link/C.zig+14-36| ... | @@ -139,6 +139,7 @@ pub fn updateFunc(self: *C, module: *Module, func_index: InternPool.Index, air: | ... | @@ -139,6 +139,7 @@ pub fn updateFunc(self: *C, module: *Module, func_index: InternPool.Index, air: |
| 139 | 139 | ||
| 140 | const func = module.funcInfo(func_index); | 140 | const func = module.funcInfo(func_index); |
| 141 | const decl_index = func.owner_decl; | 141 | const decl_index = func.owner_decl; |
| 142 | const decl = module.declPtr(decl_index); | ||
| 142 | const gop = try self.decl_table.getOrPut(gpa, decl_index); | 143 | const gop = try self.decl_table.getOrPut(gpa, decl_index); |
| 143 | if (!gop.found_existing) { | 144 | if (!gop.found_existing) { |
| 144 | gop.value_ptr.* = .{}; | 145 | gop.value_ptr.* = .{}; |
| ... | @@ -163,7 +164,7 @@ pub fn updateFunc(self: *C, module: *Module, func_index: InternPool.Index, air: | ... | @@ -163,7 +164,7 @@ pub fn updateFunc(self: *C, module: *Module, func_index: InternPool.Index, air: |
| 163 | .module = module, | 164 | .module = module, |
| 164 | .error_msg = null, | 165 | .error_msg = null, |
| 165 | .decl_index = decl_index.toOptional(), | 166 | .decl_index = decl_index.toOptional(), |
| 166 | .decl = module.declPtr(decl_index), | 167 | .is_naked_fn = decl.ty.fnCallingConvention(module) == .Naked, |
| 167 | .fwd_decl = fwd_decl.toManaged(gpa), | 168 | .fwd_decl = fwd_decl.toManaged(gpa), |
| 168 | .ctypes = ctypes.*, | 169 | .ctypes = ctypes.*, |
| 169 | }, | 170 | }, |
| ... | @@ -216,15 +217,13 @@ pub fn updateDecl(self: *C, module: *Module, decl_index: Module.Decl.Index) !voi | ... | @@ -216,15 +217,13 @@ pub fn updateDecl(self: *C, module: *Module, decl_index: Module.Decl.Index) !voi |
| 216 | fwd_decl.clearRetainingCapacity(); | 217 | fwd_decl.clearRetainingCapacity(); |
| 217 | code.clearRetainingCapacity(); | 218 | code.clearRetainingCapacity(); |
| 218 | 219 | ||
| 219 | const decl = module.declPtr(decl_index); | ||
| 220 | |||
| 221 | var object: codegen.Object = .{ | 220 | var object: codegen.Object = .{ |
| 222 | .dg = .{ | 221 | .dg = .{ |
| 223 | .gpa = gpa, | 222 | .gpa = gpa, |
| 224 | .module = module, | 223 | .module = module, |
| 225 | .error_msg = null, | 224 | .error_msg = null, |
| 226 | .decl_index = decl_index.toOptional(), | 225 | .decl_index = decl_index.toOptional(), |
| 227 | .decl = decl, | 226 | .is_naked_fn = false, |
| 228 | .fwd_decl = fwd_decl.toManaged(gpa), | 227 | .fwd_decl = fwd_decl.toManaged(gpa), |
| 229 | .ctypes = ctypes.*, | 228 | .ctypes = ctypes.*, |
| 230 | }, | 229 | }, |
| ... | @@ -322,29 +321,19 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo | ... | @@ -322,29 +321,19 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo |
| 322 | self.lazy_code_buf.clearRetainingCapacity(); | 321 | self.lazy_code_buf.clearRetainingCapacity(); |
| 323 | try self.flushErrDecls(&f.lazy_ctypes); | 322 | try self.flushErrDecls(&f.lazy_ctypes); |
| 324 | 323 | ||
| 324 | // Unlike other backends, the .c code we are emitting has order-dependent decls. | ||
| 325 | // `CType`s, forward decls, and non-functions first. | 325 | // `CType`s, forward decls, and non-functions first. |
| 326 | // Unlike other backends, the .c code we are emitting is order-dependent. Therefore | ||
| 327 | // we must traverse the set of Decls that we are emitting according to their dependencies. | ||
| 328 | // Our strategy is to populate a set of remaining decls, pop Decls one by one, | ||
| 329 | // recursively chasing their dependencies. | ||
| 330 | try f.remaining_decls.ensureUnusedCapacity(gpa, self.decl_table.count()); | ||
| 331 | |||
| 332 | const decl_keys = self.decl_table.keys(); | ||
| 333 | const decl_values = self.decl_table.values(); | ||
| 334 | for (decl_keys) |decl_index| { | ||
| 335 | assert(module.declPtr(decl_index).has_tv); | ||
| 336 | f.remaining_decls.putAssumeCapacityNoClobber(decl_index, {}); | ||
| 337 | } | ||
| 338 | 326 | ||
| 339 | { | 327 | { |
| 340 | var export_names: std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{}; | 328 | var export_names: std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{}; |
| 341 | defer export_names.deinit(gpa); | 329 | defer export_names.deinit(gpa); |
| 342 | try export_names.ensureTotalCapacity(gpa, @as(u32, @intCast(module.decl_exports.entries.len))); | 330 | try export_names.ensureTotalCapacity(gpa, @intCast(module.decl_exports.entries.len)); |
| 343 | for (module.decl_exports.values()) |exports| for (exports.items) |@"export"| | 331 | for (module.decl_exports.values()) |exports| for (exports.items) |@"export"| |
| 344 | try export_names.put(gpa, @"export".opts.name, {}); | 332 | try export_names.put(gpa, @"export".opts.name, {}); |
| 345 | 333 | ||
| 346 | while (f.remaining_decls.popOrNull()) |kv| { | 334 | const decl_keys = self.decl_table.keys(); |
| 347 | const decl_index = kv.key; | 335 | for (decl_keys) |decl_index| { |
| 336 | assert(module.declPtr(decl_index).has_tv); | ||
| 348 | try self.flushDecl(&f, decl_index, export_names); | 337 | try self.flushDecl(&f, decl_index, export_names); |
| 349 | } | 338 | } |
| 350 | } | 339 | } |
| ... | @@ -355,9 +344,9 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo | ... | @@ -355,9 +344,9 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo |
| 355 | assert(f.ctypes.count() == 0); | 344 | assert(f.ctypes.count() == 0); |
| 356 | try self.flushCTypes(&f, .none, f.lazy_ctypes); | 345 | try self.flushCTypes(&f, .none, f.lazy_ctypes); |
| 357 | 346 | ||
| 358 | var it = self.decl_table.iterator(); | 347 | for (self.decl_table.keys(), self.decl_table.values()) |decl_index, db| { |
| 359 | while (it.next()) |entry| | 348 | try self.flushCTypes(&f, decl_index.toOptional(), db.ctypes); |
| 360 | try self.flushCTypes(&f, entry.key_ptr.toOptional(), entry.value_ptr.ctypes); | 349 | } |
| 361 | } | 350 | } |
| 362 | 351 | ||
| 363 | f.all_buffers.items[ctypes_index] = .{ | 352 | f.all_buffers.items[ctypes_index] = .{ |
| ... | @@ -374,6 +363,7 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo | ... | @@ -374,6 +363,7 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo |
| 374 | f.file_size += lazy_fwd_decl_len; | 363 | f.file_size += lazy_fwd_decl_len; |
| 375 | 364 | ||
| 376 | // Now the code. | 365 | // Now the code. |
| 366 | const decl_values = self.decl_table.values(); | ||
| 377 | try f.all_buffers.ensureUnusedCapacity(gpa, 1 + decl_values.len); | 367 | try f.all_buffers.ensureUnusedCapacity(gpa, 1 + decl_values.len); |
| 378 | f.appendBufAssumeCapacity(self.lazy_code_buf.items); | 368 | f.appendBufAssumeCapacity(self.lazy_code_buf.items); |
| 379 | for (decl_values) |decl| f.appendBufAssumeCapacity(self.getString(decl.code)); | 369 | for (decl_values) |decl| f.appendBufAssumeCapacity(self.getString(decl.code)); |
| ... | @@ -384,8 +374,6 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo | ... | @@ -384,8 +374,6 @@ pub fn flushModule(self: *C, _: *Compilation, prog_node: *std.Progress.Node) !vo |
| 384 | } | 374 | } |
| 385 | 375 | ||
| 386 | const Flush = struct { | 376 | const Flush = struct { |
| 387 | remaining_decls: std.AutoArrayHashMapUnmanaged(Module.Decl.Index, void) = .{}, | ||
| 388 | |||
| 389 | ctypes: codegen.CType.Store = .{}, | 377 | ctypes: codegen.CType.Store = .{}, |
| 390 | ctypes_map: std.ArrayListUnmanaged(codegen.CType.Index) = .{}, | 378 | ctypes_map: std.ArrayListUnmanaged(codegen.CType.Index) = .{}, |
| 391 | ctypes_buf: std.ArrayListUnmanaged(u8) = .{}, | 379 | ctypes_buf: std.ArrayListUnmanaged(u8) = .{}, |
| ... | @@ -416,7 +404,6 @@ const Flush = struct { | ... | @@ -416,7 +404,6 @@ const Flush = struct { |
| 416 | f.ctypes_buf.deinit(gpa); | 404 | f.ctypes_buf.deinit(gpa); |
| 417 | f.ctypes_map.deinit(gpa); | 405 | f.ctypes_map.deinit(gpa); |
| 418 | f.ctypes.deinit(gpa); | 406 | f.ctypes.deinit(gpa); |
| 419 | f.remaining_decls.deinit(gpa); | ||
| 420 | } | 407 | } |
| 421 | }; | 408 | }; |
| 422 | 409 | ||
| ... | @@ -522,7 +509,7 @@ fn flushErrDecls(self: *C, ctypes: *codegen.CType.Store) FlushDeclError!void { | ... | @@ -522,7 +509,7 @@ fn flushErrDecls(self: *C, ctypes: *codegen.CType.Store) FlushDeclError!void { |
| 522 | .module = self.base.options.module.?, | 509 | .module = self.base.options.module.?, |
| 523 | .error_msg = null, | 510 | .error_msg = null, |
| 524 | .decl_index = .none, | 511 | .decl_index = .none, |
| 525 | .decl = null, | 512 | .is_naked_fn = false, |
| 526 | .fwd_decl = fwd_decl.toManaged(gpa), | 513 | .fwd_decl = fwd_decl.toManaged(gpa), |
| 527 | .ctypes = ctypes.*, | 514 | .ctypes = ctypes.*, |
| 528 | }, | 515 | }, |
| ... | @@ -556,7 +543,7 @@ fn flushLazyFn(self: *C, ctypes: *codegen.CType.Store, lazy_fn: codegen.LazyFnMa | ... | @@ -556,7 +543,7 @@ fn flushLazyFn(self: *C, ctypes: *codegen.CType.Store, lazy_fn: codegen.LazyFnMa |
| 556 | .module = self.base.options.module.?, | 543 | .module = self.base.options.module.?, |
| 557 | .error_msg = null, | 544 | .error_msg = null, |
| 558 | .decl_index = .none, | 545 | .decl_index = .none, |
| 559 | .decl = null, | 546 | .is_naked_fn = false, |
| 560 | .fwd_decl = fwd_decl.toManaged(gpa), | 547 | .fwd_decl = fwd_decl.toManaged(gpa), |
| 561 | .ctypes = ctypes.*, | 548 | .ctypes = ctypes.*, |
| 562 | }, | 549 | }, |
| ... | @@ -591,7 +578,6 @@ fn flushLazyFns(self: *C, f: *Flush, lazy_fns: codegen.LazyFnMap) FlushDeclError | ... | @@ -591,7 +578,6 @@ fn flushLazyFns(self: *C, f: *Flush, lazy_fns: codegen.LazyFnMap) FlushDeclError |
| 591 | } | 578 | } |
| 592 | } | 579 | } |
| 593 | 580 | ||
| 594 | /// Assumes `decl` was in the `remaining_decls` set, and has already been removed. | ||
| 595 | fn flushDecl( | 581 | fn flushDecl( |
| 596 | self: *C, | 582 | self: *C, |
| 597 | f: *Flush, | 583 | f: *Flush, |
| ... | @@ -601,14 +587,6 @@ fn flushDecl( | ... | @@ -601,14 +587,6 @@ fn flushDecl( |
| 601 | const gpa = self.base.allocator; | 587 | const gpa = self.base.allocator; |
| 602 | const mod = self.base.options.module.?; | 588 | const mod = self.base.options.module.?; |
| 603 | const decl = mod.declPtr(decl_index); | 589 | const decl = mod.declPtr(decl_index); |
| 604 | // Before flushing any particular Decl we must ensure its | ||
| 605 | // dependencies are already flushed, so that the order in the .c | ||
| 606 | // file comes out correctly. | ||
| 607 | for (decl.dependencies.keys()) |dep| { | ||
| 608 | if (f.remaining_decls.swapRemove(dep)) { | ||
| 609 | try flushDecl(self, f, dep, export_names); | ||
| 610 | } | ||
| 611 | } | ||
| 612 | 590 | ||
| 613 | const decl_block = self.decl_table.getPtr(decl_index).?; | 591 | const decl_block = self.decl_table.getPtr(decl_index).?; |
| 614 | 592 |