| ... | @@ -20,8 +20,8 @@ const ast = std.zig.ast; | ... | @@ -20,8 +20,8 @@ const ast = std.zig.ast; |
| 20 | const trace = @import("tracy.zig").trace; | 20 | const trace = @import("tracy.zig").trace; |
| 21 | const liveness = @import("liveness.zig"); | 21 | const liveness = @import("liveness.zig"); |
| 22 | | 22 | |
| 23 | /// General-purpose allocator. | 23 | /// General-purpose allocator. Used for both temporary and long-term storage. |
| 24 | allocator: *Allocator, | 24 | gpa: *Allocator, |
| 25 | /// Pointer to externally managed resource. | 25 | /// Pointer to externally managed resource. |
| 26 | root_pkg: *Package, | 26 | root_pkg: *Package, |
| 27 | /// Module owns this resource. | 27 | /// Module owns this resource. |
| ... | @@ -33,7 +33,7 @@ bin_file_path: []const u8, | ... | @@ -33,7 +33,7 @@ bin_file_path: []const u8, |
| 33 | /// It's rare for a decl to be exported, so we save memory by having a sparse map of | 33 | /// It's rare for a decl to be exported, so we save memory by having a sparse map of |
| 34 | /// Decl pointers to details about them being exported. | 34 | /// Decl pointers to details about them being exported. |
| 35 | /// The Export memory is owned by the `export_owners` table; the slice itself is owned by this table. | 35 | /// The Export memory is owned by the `export_owners` table; the slice itself is owned by this table. |
| 36 | decl_exports: std.AutoHashMap(*Decl, []*Export), | 36 | decl_exports: std.AutoHashMapUnmanaged(*Decl, []*Export) = .{}, |
| 37 | /// We track which export is associated with the given symbol name for quick | 37 | /// We track which export is associated with the given symbol name for quick |
| 38 | /// detection of symbol collisions. | 38 | /// detection of symbol collisions. |
| 39 | symbol_exports: std.StringHashMap(*Export), | 39 | symbol_exports: std.StringHashMap(*Export), |
| ... | @@ -41,9 +41,9 @@ symbol_exports: std.StringHashMap(*Export), | ... | @@ -41,9 +41,9 @@ symbol_exports: std.StringHashMap(*Export), |
| 41 | /// is modified. Note that the key of this table is not the Decl being exported, but the Decl that | 41 | /// is modified. Note that the key of this table is not the Decl being exported, but the Decl that |
| 42 | /// is performing the export of another Decl. | 42 | /// is performing the export of another Decl. |
| 43 | /// This table owns the Export memory. | 43 | /// This table owns the Export memory. |
| 44 | export_owners: std.AutoHashMap(*Decl, []*Export), | 44 | export_owners: std.AutoHashMapUnmanaged(*Decl, []*Export) = .{}, |
| 45 | /// Maps fully qualified namespaced names to the Decl struct for them. | 45 | /// Maps fully qualified namespaced names to the Decl struct for them. |
| 46 | decl_table: DeclTable, | 46 | decl_table: std.HashMapUnmanaged(Scope.NameHash, *Decl, Scope.name_hash_hash, Scope.name_hash_eql, false) = .{}, |
| 47 | | 47 | |
| 48 | optimize_mode: std.builtin.Mode, | 48 | optimize_mode: std.builtin.Mode, |
| 49 | link_error_flags: link.ElfFile.ErrorFlags = .{}, | 49 | link_error_flags: link.ElfFile.ErrorFlags = .{}, |
| ... | @@ -55,13 +55,13 @@ work_queue: std.fifo.LinearFifo(WorkItem, .Dynamic), | ... | @@ -55,13 +55,13 @@ work_queue: std.fifo.LinearFifo(WorkItem, .Dynamic), |
| 55 | /// The ErrorMsg memory is owned by the decl, using Module's allocator. | 55 | /// The ErrorMsg memory is owned by the decl, using Module's allocator. |
| 56 | /// Note that a Decl can succeed but the Fn it represents can fail. In this case, | 56 | /// Note that a Decl can succeed but the Fn it represents can fail. In this case, |
| 57 | /// a Decl can have a failed_decls entry but have analysis status of success. | 57 | /// a Decl can have a failed_decls entry but have analysis status of success. |
| 58 | failed_decls: std.AutoHashMap(*Decl, *ErrorMsg), | 58 | failed_decls: std.AutoHashMapUnmanaged(*Decl, *ErrorMsg) = .{}, |
| 59 | /// Using a map here for consistency with the other fields here. | 59 | /// Using a map here for consistency with the other fields here. |
| 60 | /// The ErrorMsg memory is owned by the `Scope`, using Module's allocator. | 60 | /// The ErrorMsg memory is owned by the `Scope`, using Module's allocator. |
| 61 | failed_files: std.AutoHashMap(*Scope, *ErrorMsg), | 61 | failed_files: std.AutoHashMapUnmanaged(*Scope, *ErrorMsg) = .{}, |
| 62 | /// Using a map here for consistency with the other fields here. | 62 | /// Using a map here for consistency with the other fields here. |
| 63 | /// The ErrorMsg memory is owned by the `Export`, using Module's allocator. | 63 | /// The ErrorMsg memory is owned by the `Export`, using Module's allocator. |
| 64 | failed_exports: std.AutoHashMap(*Export, *ErrorMsg), | 64 | failed_exports: std.AutoHashMapUnmanaged(*Export, *ErrorMsg) = .{}, |
| 65 | | 65 | |
| 66 | /// Incrementing integer used to compare against the corresponding Decl | 66 | /// Incrementing integer used to compare against the corresponding Decl |
| 67 | /// field to determine whether a Decl's status applies to an ongoing update, or a | 67 | /// field to determine whether a Decl's status applies to an ongoing update, or a |
| ... | @@ -76,8 +76,6 @@ deletion_set: std.ArrayListUnmanaged(*Decl) = .{}, | ... | @@ -76,8 +76,6 @@ deletion_set: std.ArrayListUnmanaged(*Decl) = .{}, |
| 76 | | 76 | |
| 77 | keep_source_files_loaded: bool, | 77 | keep_source_files_loaded: bool, |
| 78 | | 78 | |
| 79 | const DeclTable = std.HashMap(Scope.NameHash, *Decl, Scope.name_hash_hash, Scope.name_hash_eql, false); | | |
| 80 | | | |
| 81 | const WorkItem = union(enum) { | 79 | const WorkItem = union(enum) { |
| 82 | /// Write the machine code for a Decl to the output file. | 80 | /// Write the machine code for a Decl to the output file. |
| 83 | codegen_decl: *Decl, | 81 | codegen_decl: *Decl, |
| ... | @@ -176,19 +174,23 @@ pub const Decl = struct { | ... | @@ -176,19 +174,23 @@ pub const Decl = struct { |
| 176 | | 174 | |
| 177 | /// The shallow set of other decls whose typed_value could possibly change if this Decl's | 175 | /// The shallow set of other decls whose typed_value could possibly change if this Decl's |
| 178 | /// typed_value is modified. | 176 | /// typed_value is modified. |
| 179 | dependants: ArrayListUnmanaged(*Decl) = ArrayListUnmanaged(*Decl){}, | 177 | dependants: DepsTable = .{}, |
| 180 | /// The shallow set of other decls whose typed_value changing indicates that this Decl's | 178 | /// The shallow set of other decls whose typed_value changing indicates that this Decl's |
| 181 | /// typed_value may need to be regenerated. | 179 | /// typed_value may need to be regenerated. |
| 182 | dependencies: ArrayListUnmanaged(*Decl) = ArrayListUnmanaged(*Decl){}, | 180 | dependencies: DepsTable = .{}, |
| | 181 | |
| | 182 | /// The reason this is not `std.AutoHashMapUnmanaged` is a workaround for |
| | 183 | /// stage1 compiler giving me: `error: struct 'Module.Decl' depends on itself` |
| | 184 | pub const DepsTable = std.HashMapUnmanaged(*Decl, void, std.hash_map.getAutoHashFn(*Decl), std.hash_map.getAutoEqlFn(*Decl), false); |
| 183 | | 185 | |
| 184 | pub fn destroy(self: *Decl, allocator: *Allocator) void { | 186 | pub fn destroy(self: *Decl, gpa: *Allocator) void { |
| 185 | allocator.free(mem.spanZ(self.name)); | 187 | gpa.free(mem.spanZ(self.name)); |
| 186 | if (self.typedValueManaged()) |tvm| { | 188 | if (self.typedValueManaged()) |tvm| { |
| 187 | tvm.deinit(allocator); | 189 | tvm.deinit(gpa); |
| 188 | } | 190 | } |
| 189 | self.dependants.deinit(allocator); | 191 | self.dependants.deinit(gpa); |
| 190 | self.dependencies.deinit(allocator); | 192 | self.dependencies.deinit(gpa); |
| 191 | allocator.destroy(self); | 193 | gpa.destroy(self); |
| 192 | } | 194 | } |
| 193 | | 195 | |
| 194 | pub fn src(self: Decl) usize { | 196 | pub fn src(self: Decl) usize { |
| ... | @@ -247,23 +249,11 @@ pub const Decl = struct { | ... | @@ -247,23 +249,11 @@ pub const Decl = struct { |
| 247 | } | 249 | } |
| 248 | | 250 | |
| 249 | fn removeDependant(self: *Decl, other: *Decl) void { | 251 | fn removeDependant(self: *Decl, other: *Decl) void { |
| 250 | for (self.dependants.items) |item, i| { | 252 | self.dependants.removeAssertDiscard(other); |
| 251 | if (item == other) { | | |
| 252 | _ = self.dependants.swapRemove(i); | | |
| 253 | return; | | |
| 254 | } | | |
| 255 | } | | |
| 256 | unreachable; | | |
| 257 | } | 253 | } |
| 258 | | 254 | |
| 259 | fn removeDependency(self: *Decl, other: *Decl) void { | 255 | fn removeDependency(self: *Decl, other: *Decl) void { |
| 260 | for (self.dependencies.items) |item, i| { | 256 | self.dependencies.removeAssertDiscard(other); |
| 261 | if (item == other) { | | |
| 262 | _ = self.dependencies.swapRemove(i); | | |
| 263 | return; | | |
| 264 | } | | |
| 265 | } | | |
| 266 | unreachable; | | |
| 267 | } | 257 | } |
| 268 | }; | 258 | }; |
| 269 | | 259 | |
| ... | @@ -390,10 +380,10 @@ pub const Scope = struct { | ... | @@ -390,10 +380,10 @@ pub const Scope = struct { |
| 390 | } | 380 | } |
| 391 | } | 381 | } |
| 392 | | 382 | |
| 393 | pub fn unload(base: *Scope, allocator: *Allocator) void { | 383 | pub fn unload(base: *Scope, gpa: *Allocator) void { |
| 394 | switch (base.tag) { | 384 | switch (base.tag) { |
| 395 | .file => return @fieldParentPtr(File, "base", base).unload(allocator), | 385 | .file => return @fieldParentPtr(File, "base", base).unload(gpa), |
| 396 | .zir_module => return @fieldParentPtr(ZIRModule, "base", base).unload(allocator), | 386 | .zir_module => return @fieldParentPtr(ZIRModule, "base", base).unload(gpa), |
| 397 | .block => unreachable, | 387 | .block => unreachable, |
| 398 | .gen_zir => unreachable, | 388 | .gen_zir => unreachable, |
| 399 | .decl => unreachable, | 389 | .decl => unreachable, |
| ... | @@ -422,17 +412,17 @@ pub const Scope = struct { | ... | @@ -422,17 +412,17 @@ pub const Scope = struct { |
| 422 | } | 412 | } |
| 423 | | 413 | |
| 424 | /// Asserts the scope is a File or ZIRModule and deinitializes it, then deallocates it. | 414 | /// Asserts the scope is a File or ZIRModule and deinitializes it, then deallocates it. |
| 425 | pub fn destroy(base: *Scope, allocator: *Allocator) void { | 415 | pub fn destroy(base: *Scope, gpa: *Allocator) void { |
| 426 | switch (base.tag) { | 416 | switch (base.tag) { |
| 427 | .file => { | 417 | .file => { |
| 428 | const scope_file = @fieldParentPtr(File, "base", base); | 418 | const scope_file = @fieldParentPtr(File, "base", base); |
| 429 | scope_file.deinit(allocator); | 419 | scope_file.deinit(gpa); |
| 430 | allocator.destroy(scope_file); | 420 | gpa.destroy(scope_file); |
| 431 | }, | 421 | }, |
| 432 | .zir_module => { | 422 | .zir_module => { |
| 433 | const scope_zir_module = @fieldParentPtr(ZIRModule, "base", base); | 423 | const scope_zir_module = @fieldParentPtr(ZIRModule, "base", base); |
| 434 | scope_zir_module.deinit(allocator); | 424 | scope_zir_module.deinit(gpa); |
| 435 | allocator.destroy(scope_zir_module); | 425 | gpa.destroy(scope_zir_module); |
| 436 | }, | 426 | }, |
| 437 | .block => unreachable, | 427 | .block => unreachable, |
| 438 | .gen_zir => unreachable, | 428 | .gen_zir => unreachable, |
| ... | @@ -483,7 +473,7 @@ pub const Scope = struct { | ... | @@ -483,7 +473,7 @@ pub const Scope = struct { |
| 483 | /// Direct children of the file. | 473 | /// Direct children of the file. |
| 484 | decls: ArrayListUnmanaged(*Decl), | 474 | decls: ArrayListUnmanaged(*Decl), |
| 485 | | 475 | |
| 486 | pub fn unload(self: *File, allocator: *Allocator) void { | 476 | pub fn unload(self: *File, gpa: *Allocator) void { |
| 487 | switch (self.status) { | 477 | switch (self.status) { |
| 488 | .never_loaded, | 478 | .never_loaded, |
| 489 | .unloaded_parse_failure, | 479 | .unloaded_parse_failure, |
| ... | @@ -497,16 +487,16 @@ pub const Scope = struct { | ... | @@ -497,16 +487,16 @@ pub const Scope = struct { |
| 497 | } | 487 | } |
| 498 | switch (self.source) { | 488 | switch (self.source) { |
| 499 | .bytes => |bytes| { | 489 | .bytes => |bytes| { |
| 500 | allocator.free(bytes); | 490 | gpa.free(bytes); |
| 501 | self.source = .{ .unloaded = {} }; | 491 | self.source = .{ .unloaded = {} }; |
| 502 | }, | 492 | }, |
| 503 | .unloaded => {}, | 493 | .unloaded => {}, |
| 504 | } | 494 | } |
| 505 | } | 495 | } |
| 506 | | 496 | |
| 507 | pub fn deinit(self: *File, allocator: *Allocator) void { | 497 | pub fn deinit(self: *File, gpa: *Allocator) void { |
| 508 | self.decls.deinit(allocator); | 498 | self.decls.deinit(gpa); |
| 509 | self.unload(allocator); | 499 | self.unload(gpa); |
| 510 | self.* = undefined; | 500 | self.* = undefined; |
| 511 | } | 501 | } |
| 512 | | 502 | |
| ... | @@ -528,7 +518,7 @@ pub const Scope = struct { | ... | @@ -528,7 +518,7 @@ pub const Scope = struct { |
| 528 | switch (self.source) { | 518 | switch (self.source) { |
| 529 | .unloaded => { | 519 | .unloaded => { |
| 530 | const source = try module.root_pkg.root_src_dir.readFileAllocOptions( | 520 | const source = try module.root_pkg.root_src_dir.readFileAllocOptions( |
| 531 | module.allocator, | 521 | module.gpa, |
| 532 | self.sub_file_path, | 522 | self.sub_file_path, |
| 533 | std.math.maxInt(u32), | 523 | std.math.maxInt(u32), |
| 534 | 1, | 524 | 1, |
| ... | @@ -576,7 +566,7 @@ pub const Scope = struct { | ... | @@ -576,7 +566,7 @@ pub const Scope = struct { |
| 576 | /// not this one. | 566 | /// not this one. |
| 577 | decls: ArrayListUnmanaged(*Decl), | 567 | decls: ArrayListUnmanaged(*Decl), |
| 578 | | 568 | |
| 579 | pub fn unload(self: *ZIRModule, allocator: *Allocator) void { | 569 | pub fn unload(self: *ZIRModule, gpa: *Allocator) void { |
| 580 | switch (self.status) { | 570 | switch (self.status) { |
| 581 | .never_loaded, | 571 | .never_loaded, |
| 582 | .unloaded_parse_failure, | 572 | .unloaded_parse_failure, |
| ... | @@ -585,30 +575,30 @@ pub const Scope = struct { | ... | @@ -585,30 +575,30 @@ pub const Scope = struct { |
| 585 | => {}, | 575 | => {}, |
| 586 | | 576 | |
| 587 | .loaded_success => { | 577 | .loaded_success => { |
| 588 | self.contents.module.deinit(allocator); | 578 | self.contents.module.deinit(gpa); |
| 589 | allocator.destroy(self.contents.module); | 579 | gpa.destroy(self.contents.module); |
| 590 | self.contents = .{ .not_available = {} }; | 580 | self.contents = .{ .not_available = {} }; |
| 591 | self.status = .unloaded_success; | 581 | self.status = .unloaded_success; |
| 592 | }, | 582 | }, |
| 593 | .loaded_sema_failure => { | 583 | .loaded_sema_failure => { |
| 594 | self.contents.module.deinit(allocator); | 584 | self.contents.module.deinit(gpa); |
| 595 | allocator.destroy(self.contents.module); | 585 | gpa.destroy(self.contents.module); |
| 596 | self.contents = .{ .not_available = {} }; | 586 | self.contents = .{ .not_available = {} }; |
| 597 | self.status = .unloaded_sema_failure; | 587 | self.status = .unloaded_sema_failure; |
| 598 | }, | 588 | }, |
| 599 | } | 589 | } |
| 600 | switch (self.source) { | 590 | switch (self.source) { |
| 601 | .bytes => |bytes| { | 591 | .bytes => |bytes| { |
| 602 | allocator.free(bytes); | 592 | gpa.free(bytes); |
| 603 | self.source = .{ .unloaded = {} }; | 593 | self.source = .{ .unloaded = {} }; |
| 604 | }, | 594 | }, |
| 605 | .unloaded => {}, | 595 | .unloaded => {}, |
| 606 | } | 596 | } |
| 607 | } | 597 | } |
| 608 | | 598 | |
| 609 | pub fn deinit(self: *ZIRModule, allocator: *Allocator) void { | 599 | pub fn deinit(self: *ZIRModule, gpa: *Allocator) void { |
| 610 | self.decls.deinit(allocator); | 600 | self.decls.deinit(gpa); |
| 611 | self.unload(allocator); | 601 | self.unload(gpa); |
| 612 | self.* = undefined; | 602 | self.* = undefined; |
| 613 | } | 603 | } |
| 614 | | 604 | |
| ... | @@ -630,7 +620,7 @@ pub const Scope = struct { | ... | @@ -630,7 +620,7 @@ pub const Scope = struct { |
| 630 | switch (self.source) { | 620 | switch (self.source) { |
| 631 | .unloaded => { | 621 | .unloaded => { |
| 632 | const source = try module.root_pkg.root_src_dir.readFileAllocOptions( | 622 | const source = try module.root_pkg.root_src_dir.readFileAllocOptions( |
| 633 | module.allocator, | 623 | module.gpa, |
| 634 | self.sub_file_path, | 624 | self.sub_file_path, |
| 635 | std.math.maxInt(u32), | 625 | std.math.maxInt(u32), |
| 636 | 1, | 626 | 1, |
| ... | @@ -701,8 +691,8 @@ pub const AllErrors = struct { | ... | @@ -701,8 +691,8 @@ pub const AllErrors = struct { |
| 701 | msg: []const u8, | 691 | msg: []const u8, |
| 702 | }; | 692 | }; |
| 703 | | 693 | |
| 704 | pub fn deinit(self: *AllErrors, allocator: *Allocator) void { | 694 | pub fn deinit(self: *AllErrors, gpa: *Allocator) void { |
| 705 | self.arena.promote(allocator).deinit(); | 695 | self.arena.promote(gpa).deinit(); |
| 706 | } | 696 | } |
| 707 | | 697 | |
| 708 | fn add( | 698 | fn add( |
| ... | @@ -772,20 +762,14 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { | ... | @@ -772,20 +762,14 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { |
| 772 | }; | 762 | }; |
| 773 | | 763 | |
| 774 | return Module{ | 764 | return Module{ |
| 775 | .allocator = gpa, | 765 | .gpa = gpa, |
| 776 | .root_pkg = options.root_pkg, | 766 | .root_pkg = options.root_pkg, |
| 777 | .root_scope = root_scope, | 767 | .root_scope = root_scope, |
| 778 | .bin_file_dir = bin_file_dir, | 768 | .bin_file_dir = bin_file_dir, |
| 779 | .bin_file_path = options.bin_file_path, | 769 | .bin_file_path = options.bin_file_path, |
| 780 | .bin_file = bin_file, | 770 | .bin_file = bin_file, |
| 781 | .optimize_mode = options.optimize_mode, | 771 | .optimize_mode = options.optimize_mode, |
| 782 | .decl_table = DeclTable.init(gpa), | | |
| 783 | .decl_exports = std.AutoHashMap(*Decl, []*Export).init(gpa), | | |
| 784 | .symbol_exports = std.StringHashMap(*Export).init(gpa), | 772 | .symbol_exports = std.StringHashMap(*Export).init(gpa), |
| 785 | .export_owners = std.AutoHashMap(*Decl, []*Export).init(gpa), | | |
| 786 | .failed_decls = std.AutoHashMap(*Decl, *ErrorMsg).init(gpa), | | |
| 787 | .failed_files = std.AutoHashMap(*Scope, *ErrorMsg).init(gpa), | | |
| 788 | .failed_exports = std.AutoHashMap(*Export, *ErrorMsg).init(gpa), | | |
| 789 | .work_queue = std.fifo.LinearFifo(WorkItem, .Dynamic).init(gpa), | 773 | .work_queue = std.fifo.LinearFifo(WorkItem, .Dynamic).init(gpa), |
| 790 | .keep_source_files_loaded = options.keep_source_files_loaded, | 774 | .keep_source_files_loaded = options.keep_source_files_loaded, |
| 791 | }; | 775 | }; |
| ... | @@ -793,51 +777,51 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { | ... | @@ -793,51 +777,51 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { |
| 793 | | 777 | |
| 794 | pub fn deinit(self: *Module) void { | 778 | pub fn deinit(self: *Module) void { |
| 795 | self.bin_file.deinit(); | 779 | self.bin_file.deinit(); |
| 796 | const allocator = self.allocator; | 780 | const gpa = self.gpa; |
| 797 | self.deletion_set.deinit(allocator); | 781 | self.deletion_set.deinit(gpa); |
| 798 | self.work_queue.deinit(); | 782 | self.work_queue.deinit(); |
| 799 | | 783 | |
| 800 | for (self.decl_table.items()) |entry| { | 784 | for (self.decl_table.items()) |entry| { |
| 801 | entry.value.destroy(allocator); | 785 | entry.value.destroy(gpa); |
| 802 | } | 786 | } |
| 803 | self.decl_table.deinit(); | 787 | self.decl_table.deinit(gpa); |
| 804 | | 788 | |
| 805 | for (self.failed_decls.items()) |entry| { | 789 | for (self.failed_decls.items()) |entry| { |
| 806 | entry.value.destroy(allocator); | 790 | entry.value.destroy(gpa); |
| 807 | } | 791 | } |
| 808 | self.failed_decls.deinit(); | 792 | self.failed_decls.deinit(gpa); |
| 809 | | 793 | |
| 810 | for (self.failed_files.items()) |entry| { | 794 | for (self.failed_files.items()) |entry| { |
| 811 | entry.value.destroy(allocator); | 795 | entry.value.destroy(gpa); |
| 812 | } | 796 | } |
| 813 | self.failed_files.deinit(); | 797 | self.failed_files.deinit(gpa); |
| 814 | | 798 | |
| 815 | for (self.failed_exports.items()) |entry| { | 799 | for (self.failed_exports.items()) |entry| { |
| 816 | entry.value.destroy(allocator); | 800 | entry.value.destroy(gpa); |
| 817 | } | 801 | } |
| 818 | self.failed_exports.deinit(); | 802 | self.failed_exports.deinit(gpa); |
| 819 | | 803 | |
| 820 | for (self.decl_exports.items()) |entry| { | 804 | for (self.decl_exports.items()) |entry| { |
| 821 | const export_list = entry.value; | 805 | const export_list = entry.value; |
| 822 | allocator.free(export_list); | 806 | gpa.free(export_list); |
| 823 | } | 807 | } |
| 824 | self.decl_exports.deinit(); | 808 | self.decl_exports.deinit(gpa); |
| 825 | | 809 | |
| 826 | for (self.export_owners.items()) |entry| { | 810 | for (self.export_owners.items()) |entry| { |
| 827 | freeExportList(allocator, entry.value); | 811 | freeExportList(gpa, entry.value); |
| 828 | } | 812 | } |
| 829 | self.export_owners.deinit(); | 813 | self.export_owners.deinit(gpa); |
| 830 | | 814 | |
| 831 | self.symbol_exports.deinit(); | 815 | self.symbol_exports.deinit(); |
| 832 | self.root_scope.destroy(allocator); | 816 | self.root_scope.destroy(gpa); |
| 833 | self.* = undefined; | 817 | self.* = undefined; |
| 834 | } | 818 | } |
| 835 | | 819 | |
| 836 | fn freeExportList(allocator: *Allocator, export_list: []*Export) void { | 820 | fn freeExportList(gpa: *Allocator, export_list: []*Export) void { |
| 837 | for (export_list) |exp| { | 821 | for (export_list) |exp| { |
| 838 | allocator.destroy(exp); | 822 | gpa.destroy(exp); |
| 839 | } | 823 | } |
| 840 | allocator.free(export_list); | 824 | gpa.free(export_list); |
| 841 | } | 825 | } |
| 842 | | 826 | |
| 843 | pub fn target(self: Module) std.Target { | 827 | pub fn target(self: Module) std.Target { |
| ... | @@ -855,7 +839,7 @@ pub fn update(self: *Module) !void { | ... | @@ -855,7 +839,7 @@ pub fn update(self: *Module) !void { |
| 855 | // Until then we simulate a full cache miss. Source files could have been loaded for any reason; | 839 | // Until then we simulate a full cache miss. Source files could have been loaded for any reason; |
| 856 | // to force a refresh we unload now. | 840 | // to force a refresh we unload now. |
| 857 | if (self.root_scope.cast(Scope.File)) |zig_file| { | 841 | if (self.root_scope.cast(Scope.File)) |zig_file| { |
| 858 | zig_file.unload(self.allocator); | 842 | zig_file.unload(self.gpa); |
| 859 | self.analyzeRootSrcFile(zig_file) catch |err| switch (err) { | 843 | self.analyzeRootSrcFile(zig_file) catch |err| switch (err) { |
| 860 | error.AnalysisFail => { | 844 | error.AnalysisFail => { |
| 861 | assert(self.totalErrorCount() != 0); | 845 | assert(self.totalErrorCount() != 0); |
| ... | @@ -863,7 +847,7 @@ pub fn update(self: *Module) !void { | ... | @@ -863,7 +847,7 @@ pub fn update(self: *Module) !void { |
| 863 | else => |e| return e, | 847 | else => |e| return e, |
| 864 | }; | 848 | }; |
| 865 | } else if (self.root_scope.cast(Scope.ZIRModule)) |zir_module| { | 849 | } else if (self.root_scope.cast(Scope.ZIRModule)) |zir_module| { |
| 866 | zir_module.unload(self.allocator); | 850 | zir_module.unload(self.gpa); |
| 867 | self.analyzeRootZIRModule(zir_module) catch |err| switch (err) { | 851 | self.analyzeRootZIRModule(zir_module) catch |err| switch (err) { |
| 868 | error.AnalysisFail => { | 852 | error.AnalysisFail => { |
| 869 | assert(self.totalErrorCount() != 0); | 853 | assert(self.totalErrorCount() != 0); |
| ... | @@ -876,7 +860,7 @@ pub fn update(self: *Module) !void { | ... | @@ -876,7 +860,7 @@ pub fn update(self: *Module) !void { |
| 876 | | 860 | |
| 877 | // Process the deletion set. | 861 | // Process the deletion set. |
| 878 | while (self.deletion_set.popOrNull()) |decl| { | 862 | while (self.deletion_set.popOrNull()) |decl| { |
| 879 | if (decl.dependants.items.len != 0) { | 863 | if (decl.dependants.items().len != 0) { |
| 880 | decl.deletion_flag = false; | 864 | decl.deletion_flag = false; |
| 881 | continue; | 865 | continue; |
| 882 | } | 866 | } |
| ... | @@ -889,7 +873,7 @@ pub fn update(self: *Module) !void { | ... | @@ -889,7 +873,7 @@ pub fn update(self: *Module) !void { |
| 889 | // to report error messages. Otherwise we unload all source files to save memory. | 873 | // to report error messages. Otherwise we unload all source files to save memory. |
| 890 | if (self.totalErrorCount() == 0) { | 874 | if (self.totalErrorCount() == 0) { |
| 891 | if (!self.keep_source_files_loaded) { | 875 | if (!self.keep_source_files_loaded) { |
| 892 | self.root_scope.unload(self.allocator); | 876 | self.root_scope.unload(self.gpa); |
| 893 | } | 877 | } |
| 894 | try self.bin_file.flush(); | 878 | try self.bin_file.flush(); |
| 895 | } | 879 | } |
| ... | @@ -915,10 +899,10 @@ pub fn totalErrorCount(self: *Module) usize { | ... | @@ -915,10 +899,10 @@ pub fn totalErrorCount(self: *Module) usize { |
| 915 | } | 899 | } |
| 916 | | 900 | |
| 917 | pub fn getAllErrorsAlloc(self: *Module) !AllErrors { | 901 | pub fn getAllErrorsAlloc(self: *Module) !AllErrors { |
| 918 | var arena = std.heap.ArenaAllocator.init(self.allocator); | 902 | var arena = std.heap.ArenaAllocator.init(self.gpa); |
| 919 | errdefer arena.deinit(); | 903 | errdefer arena.deinit(); |
| 920 | | 904 | |
| 921 | var errors = std.ArrayList(AllErrors.Message).init(self.allocator); | 905 | var errors = std.ArrayList(AllErrors.Message).init(self.gpa); |
| 922 | defer errors.deinit(); | 906 | defer errors.deinit(); |
| 923 | | 907 | |
| 924 | for (self.failed_files.items()) |entry| { | 908 | for (self.failed_files.items()) |entry| { |
| ... | @@ -989,9 +973,9 @@ pub fn performAllTheWork(self: *Module) error{OutOfMemory}!void { | ... | @@ -989,9 +973,9 @@ pub fn performAllTheWork(self: *Module) error{OutOfMemory}!void { |
| 989 | } | 973 | } |
| 990 | // Here we tack on additional allocations to the Decl's arena. The allocations are | 974 | // Here we tack on additional allocations to the Decl's arena. The allocations are |
| 991 | // lifetime annotations in the ZIR. | 975 | // lifetime annotations in the ZIR. |
| 992 | var decl_arena = decl.typed_value.most_recent.arena.?.promote(self.allocator); | 976 | var decl_arena = decl.typed_value.most_recent.arena.?.promote(self.gpa); |
| 993 | defer decl.typed_value.most_recent.arena.?.* = decl_arena.state; | 977 | defer decl.typed_value.most_recent.arena.?.* = decl_arena.state; |
| 994 | try liveness.analyze(self.allocator, &decl_arena.allocator, payload.func.analysis.success); | 978 | try liveness.analyze(self.gpa, &decl_arena.allocator, payload.func.analysis.success); |
| 995 | } | 979 | } |
| 996 | | 980 | |
| 997 | assert(decl.typed_value.most_recent.typed_value.ty.hasCodeGenBits()); | 981 | assert(decl.typed_value.most_recent.typed_value.ty.hasCodeGenBits()); |
| ... | @@ -1002,9 +986,9 @@ pub fn performAllTheWork(self: *Module) error{OutOfMemory}!void { | ... | @@ -1002,9 +986,9 @@ pub fn performAllTheWork(self: *Module) error{OutOfMemory}!void { |
| 1002 | decl.analysis = .dependency_failure; | 986 | decl.analysis = .dependency_failure; |
| 1003 | }, | 987 | }, |
| 1004 | else => { | 988 | else => { |
| 1005 | try self.failed_decls.ensureCapacity(self.failed_decls.items().len + 1); | 989 | try self.failed_decls.ensureCapacity(self.gpa, self.failed_decls.items().len + 1); |
| 1006 | self.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create( | 990 | self.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create( |
| 1007 | self.allocator, | 991 | self.gpa, |
| 1008 | decl.src(), | 992 | decl.src(), |
| 1009 | "unable to codegen: {}", | 993 | "unable to codegen: {}", |
| 1010 | .{@errorName(err)}, | 994 | .{@errorName(err)}, |
| ... | @@ -1048,16 +1032,17 @@ fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void { | ... | @@ -1048,16 +1032,17 @@ fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void { |
| 1048 | // prior to re-analysis. | 1032 | // prior to re-analysis. |
| 1049 | self.deleteDeclExports(decl); | 1033 | self.deleteDeclExports(decl); |
| 1050 | // Dependencies will be re-discovered, so we remove them here prior to re-analysis. | 1034 | // Dependencies will be re-discovered, so we remove them here prior to re-analysis. |
| 1051 | for (decl.dependencies.items) |dep| { | 1035 | for (decl.dependencies.items()) |entry| { |
| | 1036 | const dep = entry.key; |
| 1052 | dep.removeDependant(decl); | 1037 | dep.removeDependant(decl); |
| 1053 | if (dep.dependants.items.len == 0 and !dep.deletion_flag) { | 1038 | if (dep.dependants.items().len == 0 and !dep.deletion_flag) { |
| 1054 | // We don't perform a deletion here, because this Decl or another one | 1039 | // We don't perform a deletion here, because this Decl or another one |
| 1055 | // may end up referencing it before the update is complete. | 1040 | // may end up referencing it before the update is complete. |
| 1056 | dep.deletion_flag = true; | 1041 | dep.deletion_flag = true; |
| 1057 | try self.deletion_set.append(self.allocator, dep); | 1042 | try self.deletion_set.append(self.gpa, dep); |
| 1058 | } | 1043 | } |
| 1059 | } | 1044 | } |
| 1060 | decl.dependencies.shrink(self.allocator, 0); | 1045 | decl.dependencies.clearRetainingCapacity(); |
| 1061 | | 1046 | |
| 1062 | break :blk true; | 1047 | break :blk true; |
| 1063 | }, | 1048 | }, |
| ... | @@ -1072,9 +1057,9 @@ fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void { | ... | @@ -1072,9 +1057,9 @@ fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void { |
| 1072 | error.OutOfMemory => return error.OutOfMemory, | 1057 | error.OutOfMemory => return error.OutOfMemory, |
| 1073 | error.AnalysisFail => return error.AnalysisFail, | 1058 | error.AnalysisFail => return error.AnalysisFail, |
| 1074 | else => { | 1059 | else => { |
| 1075 | try self.failed_decls.ensureCapacity(self.failed_decls.items().len + 1); | 1060 | try self.failed_decls.ensureCapacity(self.gpa, self.failed_decls.items().len + 1); |
| 1076 | self.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create( | 1061 | self.failed_decls.putAssumeCapacityNoClobber(decl, try ErrorMsg.create( |
| 1077 | self.allocator, | 1062 | self.gpa, |
| 1078 | decl.src(), | 1063 | decl.src(), |
| 1079 | "unable to analyze: {}", | 1064 | "unable to analyze: {}", |
| 1080 | .{@errorName(err)}, | 1065 | .{@errorName(err)}, |
| ... | @@ -1088,7 +1073,8 @@ fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void { | ... | @@ -1088,7 +1073,8 @@ fn ensureDeclAnalyzed(self: *Module, decl: *Decl) InnerError!void { |
| 1088 | // We may need to chase the dependants and re-analyze them. | 1073 | // We may need to chase the dependants and re-analyze them. |
| 1089 | // However, if the decl is a function, and the type is the same, we do not need to. | 1074 | // However, if the decl is a function, and the type is the same, we do not need to. |
| 1090 | if (type_changed or decl.typed_value.most_recent.typed_value.val.tag() != .function) { | 1075 | if (type_changed or decl.typed_value.most_recent.typed_value.val.tag() != .function) { |
| 1091 | for (decl.dependants.items) |dep| { | 1076 | for (decl.dependants.items()) |entry| { |
| | 1077 | const dep = entry.key; |
| 1092 | switch (dep.analysis) { | 1078 | switch (dep.analysis) { |
| 1093 | .unreferenced => unreachable, | 1079 | .unreferenced => unreachable, |
| 1094 | .in_progress => unreachable, | 1080 | .in_progress => unreachable, |
| ... | @@ -1127,8 +1113,8 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { | ... | @@ -1127,8 +1113,8 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1127 | // to complete the Decl analysis. | 1113 | // to complete the Decl analysis. |
| 1128 | var fn_type_scope: Scope.GenZIR = .{ | 1114 | var fn_type_scope: Scope.GenZIR = .{ |
| 1129 | .decl = decl, | 1115 | .decl = decl, |
| 1130 | .arena = std.heap.ArenaAllocator.init(self.allocator), | 1116 | .arena = std.heap.ArenaAllocator.init(self.gpa), |
| 1131 | .instructions = std.ArrayList(*zir.Inst).init(self.allocator), | 1117 | .instructions = std.ArrayList(*zir.Inst).init(self.gpa), |
| 1132 | }; | 1118 | }; |
| 1133 | defer fn_type_scope.arena.deinit(); | 1119 | defer fn_type_scope.arena.deinit(); |
| 1134 | defer fn_type_scope.instructions.deinit(); | 1120 | defer fn_type_scope.instructions.deinit(); |
| ... | @@ -1178,7 +1164,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { | ... | @@ -1178,7 +1164,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1178 | _ = try self.addZIRInst(&fn_type_scope.base, fn_src, zir.Inst.Return, .{ .operand = fn_type_inst }, .{}); | 1164 | _ = try self.addZIRInst(&fn_type_scope.base, fn_src, zir.Inst.Return, .{ .operand = fn_type_inst }, .{}); |
| 1179 | | 1165 | |
| 1180 | // We need the memory for the Type to go into the arena for the Decl | 1166 | // We need the memory for the Type to go into the arena for the Decl |
| 1181 | var decl_arena = std.heap.ArenaAllocator.init(self.allocator); | 1167 | var decl_arena = std.heap.ArenaAllocator.init(self.gpa); |
| 1182 | errdefer decl_arena.deinit(); | 1168 | errdefer decl_arena.deinit(); |
| 1183 | const decl_arena_state = try decl_arena.allocator.create(std.heap.ArenaAllocator.State); | 1169 | const decl_arena_state = try decl_arena.allocator.create(std.heap.ArenaAllocator.State); |
| 1184 | | 1170 | |
| ... | @@ -1189,7 +1175,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { | ... | @@ -1189,7 +1175,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1189 | .instructions = .{}, | 1175 | .instructions = .{}, |
| 1190 | .arena = &decl_arena.allocator, | 1176 | .arena = &decl_arena.allocator, |
| 1191 | }; | 1177 | }; |
| 1192 | defer block_scope.instructions.deinit(self.allocator); | 1178 | defer block_scope.instructions.deinit(self.gpa); |
| 1193 | | 1179 | |
| 1194 | const fn_type = try self.analyzeBodyValueAsType(&block_scope, .{ | 1180 | const fn_type = try self.analyzeBodyValueAsType(&block_scope, .{ |
| 1195 | .instructions = fn_type_scope.instructions.items, | 1181 | .instructions = fn_type_scope.instructions.items, |
| ... | @@ -1202,8 +1188,8 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { | ... | @@ -1202,8 +1188,8 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1202 | // pass completes, and semantic analysis of it completes. | 1188 | // pass completes, and semantic analysis of it completes. |
| 1203 | var gen_scope: Scope.GenZIR = .{ | 1189 | var gen_scope: Scope.GenZIR = .{ |
| 1204 | .decl = decl, | 1190 | .decl = decl, |
| 1205 | .arena = std.heap.ArenaAllocator.init(self.allocator), | 1191 | .arena = std.heap.ArenaAllocator.init(self.gpa), |
| 1206 | .instructions = std.ArrayList(*zir.Inst).init(self.allocator), | 1192 | .instructions = std.ArrayList(*zir.Inst).init(self.gpa), |
| 1207 | }; | 1193 | }; |
| 1208 | errdefer gen_scope.arena.deinit(); | 1194 | errdefer gen_scope.arena.deinit(); |
| 1209 | defer gen_scope.instructions.deinit(); | 1195 | defer gen_scope.instructions.deinit(); |
| ... | @@ -1235,7 +1221,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { | ... | @@ -1235,7 +1221,7 @@ fn astGenAndAnalyzeDecl(self: *Module, decl: *Decl) !bool { |
| 1235 | prev_type_has_bits = tvm.typed_value.ty.hasCodeGenBits(); | 1221 | prev_type_has_bits = tvm.typed_value.ty.hasCodeGenBits(); |
| 1236 | type_changed = !tvm.typed_value.ty.eql(fn_type); | 1222 | type_changed = !tvm.typed_value.ty.eql(fn_type); |
| 1237 | | 1223 | |
| 1238 | tvm.deinit(self.allocator); | 1224 | tvm.deinit(self.gpa); |
| 1239 | } | 1225 | } |
| 1240 | | 1226 | |
| 1241 | decl_arena_state.* = decl_arena.state; | 1227 | decl_arena_state.* = decl_arena.state; |
| ... | @@ -1626,40 +1612,31 @@ fn getSimplePrimitiveValue(name: []const u8) ?TypedValue { | ... | @@ -1626,40 +1612,31 @@ fn getSimplePrimitiveValue(name: []const u8) ?TypedValue { |
| 1626 | } | 1612 | } |
| 1627 | | 1613 | |
| 1628 | fn declareDeclDependency(self: *Module, depender: *Decl, dependee: *Decl) !void { | 1614 | fn declareDeclDependency(self: *Module, depender: *Decl, dependee: *Decl) !void { |
| 1629 | try depender.dependencies.ensureCapacity(self.allocator, depender.dependencies.items.len + 1); | 1615 | try depender.dependencies.ensureCapacity(self.gpa, depender.dependencies.items().len + 1); |
| 1630 | try dependee.dependants.ensureCapacity(self.allocator, dependee.dependants.items.len + 1); | 1616 | try dependee.dependants.ensureCapacity(self.gpa, dependee.dependants.items().len + 1); |
| 1631 | | | |
| 1632 | for (depender.dependencies.items) |item| { | | |
| 1633 | if (item == dependee) break; // Already in the set. | | |
| 1634 | } else { | | |
| 1635 | depender.dependencies.appendAssumeCapacity(dependee); | | |
| 1636 | } | | |
| 1637 | | 1617 | |
| 1638 | for (dependee.dependants.items) |item| { | 1618 | depender.dependencies.putAssumeCapacity(dependee, {}); |
| 1639 | if (item == depender) break; // Already in the set. | 1619 | dependee.dependants.putAssumeCapacity(depender, {}); |
| 1640 | } else { | | |
| 1641 | dependee.dependants.appendAssumeCapacity(depender); | | |
| 1642 | } | | |
| 1643 | } | 1620 | } |
| 1644 | | 1621 | |
| 1645 | fn getSrcModule(self: *Module, root_scope: *Scope.ZIRModule) !*zir.Module { | 1622 | fn getSrcModule(self: *Module, root_scope: *Scope.ZIRModule) !*zir.Module { |
| 1646 | switch (root_scope.status) { | 1623 | switch (root_scope.status) { |
| 1647 | .never_loaded, .unloaded_success => { | 1624 | .never_loaded, .unloaded_success => { |
| 1648 | try self.failed_files.ensureCapacity(self.failed_files.items().len + 1); | 1625 | try self.failed_files.ensureCapacity(self.gpa, self.failed_files.items().len + 1); |
| 1649 | | 1626 | |
| 1650 | const source = try root_scope.getSource(self); | 1627 | const source = try root_scope.getSource(self); |
| 1651 | | 1628 | |
| 1652 | var keep_zir_module = false; | 1629 | var keep_zir_module = false; |
| 1653 | const zir_module = try self.allocator.create(zir.Module); | 1630 | const zir_module = try self.gpa.create(zir.Module); |
| 1654 | defer if (!keep_zir_module) self.allocator.destroy(zir_module); | 1631 | defer if (!keep_zir_module) self.gpa.destroy(zir_module); |
| 1655 | | 1632 | |
| 1656 | zir_module.* = try zir.parse(self.allocator, source); | 1633 | zir_module.* = try zir.parse(self.gpa, source); |
| 1657 | defer if (!keep_zir_module) zir_module.deinit(self.allocator); | 1634 | defer if (!keep_zir_module) zir_module.deinit(self.gpa); |
| 1658 | | 1635 | |
| 1659 | if (zir_module.error_msg) |src_err_msg| { | 1636 | if (zir_module.error_msg) |src_err_msg| { |
| 1660 | self.failed_files.putAssumeCapacityNoClobber( | 1637 | self.failed_files.putAssumeCapacityNoClobber( |
| 1661 | &root_scope.base, | 1638 | &root_scope.base, |
| 1662 | try ErrorMsg.create(self.allocator, src_err_msg.byte_offset, "{}", .{src_err_msg.msg}), | 1639 | try ErrorMsg.create(self.gpa, src_err_msg.byte_offset, "{}", .{src_err_msg.msg}), |
| 1663 | ); | 1640 | ); |
| 1664 | root_scope.status = .unloaded_parse_failure; | 1641 | root_scope.status = .unloaded_parse_failure; |
| 1665 | return error.AnalysisFail; | 1642 | return error.AnalysisFail; |
| ... | @@ -1686,22 +1663,22 @@ fn getAstTree(self: *Module, root_scope: *Scope.File) !*ast.Tree { | ... | @@ -1686,22 +1663,22 @@ fn getAstTree(self: *Module, root_scope: *Scope.File) !*ast.Tree { |
| 1686 | | 1663 | |
| 1687 | switch (root_scope.status) { | 1664 | switch (root_scope.status) { |
| 1688 | .never_loaded, .unloaded_success => { | 1665 | .never_loaded, .unloaded_success => { |
| 1689 | try self.failed_files.ensureCapacity(self.failed_files.items().len + 1); | 1666 | try self.failed_files.ensureCapacity(self.gpa, self.failed_files.items().len + 1); |
| 1690 | | 1667 | |
| 1691 | const source = try root_scope.getSource(self); | 1668 | const source = try root_scope.getSource(self); |
| 1692 | | 1669 | |
| 1693 | var keep_tree = false; | 1670 | var keep_tree = false; |
| 1694 | const tree = try std.zig.parse(self.allocator, source); | 1671 | const tree = try std.zig.parse(self.gpa, source); |
| 1695 | defer if (!keep_tree) tree.deinit(); | 1672 | defer if (!keep_tree) tree.deinit(); |
| 1696 | | 1673 | |
| 1697 | if (tree.errors.len != 0) { | 1674 | if (tree.errors.len != 0) { |
| 1698 | const parse_err = tree.errors[0]; | 1675 | const parse_err = tree.errors[0]; |
| 1699 | | 1676 | |
| 1700 | var msg = std.ArrayList(u8).init(self.allocator); | 1677 | var msg = std.ArrayList(u8).init(self.gpa); |
| 1701 | defer msg.deinit(); | 1678 | defer msg.deinit(); |
| 1702 | | 1679 | |
| 1703 | try parse_err.render(tree.token_ids, msg.outStream()); | 1680 | try parse_err.render(tree.token_ids, msg.outStream()); |
| 1704 | const err_msg = try self.allocator.create(ErrorMsg); | 1681 | const err_msg = try self.gpa.create(ErrorMsg); |
| 1705 | err_msg.* = .{ | 1682 | err_msg.* = .{ |
| 1706 | .msg = msg.toOwnedSlice(), | 1683 | .msg = msg.toOwnedSlice(), |
| 1707 | .byte_offset = tree.token_locs[parse_err.loc()].start, | 1684 | .byte_offset = tree.token_locs[parse_err.loc()].start, |
| ... | @@ -1732,11 +1709,11 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void { | ... | @@ -1732,11 +1709,11 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void { |
| 1732 | const decls = tree.root_node.decls(); | 1709 | const decls = tree.root_node.decls(); |
| 1733 | | 1710 | |
| 1734 | try self.work_queue.ensureUnusedCapacity(decls.len); | 1711 | try self.work_queue.ensureUnusedCapacity(decls.len); |
| 1735 | try root_scope.decls.ensureCapacity(self.allocator, decls.len); | 1712 | try root_scope.decls.ensureCapacity(self.gpa, decls.len); |
| 1736 | | 1713 | |
| 1737 | // Keep track of the decls that we expect to see in this file so that | 1714 | // Keep track of the decls that we expect to see in this file so that |
| 1738 | // we know which ones have been deleted. | 1715 | // we know which ones have been deleted. |
| 1739 | var deleted_decls = std.AutoHashMap(*Decl, void).init(self.allocator); | 1716 | var deleted_decls = std.AutoHashMap(*Decl, void).init(self.gpa); |
| 1740 | defer deleted_decls.deinit(); | 1717 | defer deleted_decls.deinit(); |
| 1741 | try deleted_decls.ensureCapacity(root_scope.decls.items.len); | 1718 | try deleted_decls.ensureCapacity(root_scope.decls.items.len); |
| 1742 | for (root_scope.decls.items) |file_decl| { | 1719 | for (root_scope.decls.items) |file_decl| { |
| ... | @@ -1760,9 +1737,9 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void { | ... | @@ -1760,9 +1737,9 @@ fn analyzeRootSrcFile(self: *Module, root_scope: *Scope.File) !void { |
| 1760 | decl.src_index = decl_i; | 1737 | decl.src_index = decl_i; |
| 1761 | if (deleted_decls.remove(decl) == null) { | 1738 | if (deleted_decls.remove(decl) == null) { |
| 1762 | decl.analysis = .sema_failure; | 1739 | decl.analysis = .sema_failure; |
| 1763 | const err_msg = try ErrorMsg.create(self.allocator, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name}); | 1740 | const err_msg = try ErrorMsg.create(self.gpa, tree.token_locs[name_tok].start, "redefinition of '{}'", .{decl.name}); |
| 1764 | errdefer err_msg.destroy(self.allocator); | 1741 | errdefer err_msg.destroy(self.gpa); |
| 1765 | try self.failed_decls.putNoClobber(decl, err_msg); | 1742 | try self.failed_decls.putNoClobber(self.gpa, decl, err_msg); |
| 1766 | } else { | 1743 | } else { |
| 1767 | if (!srcHashEql(decl.contents_hash, contents_hash)) { | 1744 | if (!srcHashEql(decl.contents_hash, contents_hash)) { |
| 1768 | try self.markOutdatedDecl(decl); | 1745 | try self.markOutdatedDecl(decl); |
| ... | @@ -1796,14 +1773,14 @@ fn analyzeRootZIRModule(self: *Module, root_scope: *Scope.ZIRModule) !void { | ... | @@ -1796,14 +1773,14 @@ fn analyzeRootZIRModule(self: *Module, root_scope: *Scope.ZIRModule) !void { |
| 1796 | const src_module = try self.getSrcModule(root_scope); | 1773 | const src_module = try self.getSrcModule(root_scope); |
| 1797 | | 1774 | |
| 1798 | try self.work_queue.ensureUnusedCapacity(src_module.decls.len); | 1775 | try self.work_queue.ensureUnusedCapacity(src_module.decls.len); |
| 1799 | try root_scope.decls.ensureCapacity(self.allocator, src_module.decls.len); | 1776 | try root_scope.decls.ensureCapacity(self.gpa, src_module.decls.len); |
| 1800 | | 1777 | |
| 1801 | var exports_to_resolve = std.ArrayList(*zir.Decl).init(self.allocator); | 1778 | var exports_to_resolve = std.ArrayList(*zir.Decl).init(self.gpa); |
| 1802 | defer exports_to_resolve.deinit(); | 1779 | defer exports_to_resolve.deinit(); |
| 1803 | | 1780 | |
| 1804 | // Keep track of the decls that we expect to see in this file so that | 1781 | // Keep track of the decls that we expect to see in this file so that |
| 1805 | // we know which ones have been deleted. | 1782 | // we know which ones have been deleted. |
| 1806 | var deleted_decls = std.AutoHashMap(*Decl, void).init(self.allocator); | 1783 | var deleted_decls = std.AutoHashMap(*Decl, void).init(self.gpa); |
| 1807 | defer deleted_decls.deinit(); | 1784 | defer deleted_decls.deinit(); |
| 1808 | try deleted_decls.ensureCapacity(self.decl_table.items().len); | 1785 | try deleted_decls.ensureCapacity(self.decl_table.items().len); |
| 1809 | for (self.decl_table.items()) |entry| { | 1786 | for (self.decl_table.items()) |entry| { |
| ... | @@ -1845,7 +1822,7 @@ fn analyzeRootZIRModule(self: *Module, root_scope: *Scope.ZIRModule) !void { | ... | @@ -1845,7 +1822,7 @@ fn analyzeRootZIRModule(self: *Module, root_scope: *Scope.ZIRModule) !void { |
| 1845 | } | 1822 | } |
| 1846 | | 1823 | |
| 1847 | fn deleteDecl(self: *Module, decl: *Decl) !void { | 1824 | fn deleteDecl(self: *Module, decl: *Decl) !void { |
| 1848 | try self.deletion_set.ensureCapacity(self.allocator, self.deletion_set.items.len + decl.dependencies.items.len); | 1825 | try self.deletion_set.ensureCapacity(self.gpa, self.deletion_set.items.len + decl.dependencies.items().len); |
| 1849 | | 1826 | |
| 1850 | // Remove from the namespace it resides in. In the case of an anonymous Decl it will | 1827 | // Remove from the namespace it resides in. In the case of an anonymous Decl it will |
| 1851 | // not be present in the set, and this does nothing. | 1828 | // not be present in the set, and this does nothing. |
| ... | @@ -1855,9 +1832,10 @@ fn deleteDecl(self: *Module, decl: *Decl) !void { | ... | @@ -1855,9 +1832,10 @@ fn deleteDecl(self: *Module, decl: *Decl) !void { |
| 1855 | const name_hash = decl.fullyQualifiedNameHash(); | 1832 | const name_hash = decl.fullyQualifiedNameHash(); |
| 1856 | self.decl_table.removeAssertDiscard(name_hash); | 1833 | self.decl_table.removeAssertDiscard(name_hash); |
| 1857 | // Remove itself from its dependencies, because we are about to destroy the decl pointer. | 1834 | // Remove itself from its dependencies, because we are about to destroy the decl pointer. |
| 1858 | for (decl.dependencies.items) |dep| { | 1835 | for (decl.dependencies.items()) |entry| { |
| | 1836 | const dep = entry.key; |
| 1859 | dep.removeDependant(decl); | 1837 | dep.removeDependant(decl); |
| 1860 | if (dep.dependants.items.len == 0 and !dep.deletion_flag) { | 1838 | if (dep.dependants.items().len == 0 and !dep.deletion_flag) { |
| 1861 | // We don't recursively perform a deletion here, because during the update, | 1839 | // We don't recursively perform a deletion here, because during the update, |
| 1862 | // another reference to it may turn up. | 1840 | // another reference to it may turn up. |
| 1863 | dep.deletion_flag = true; | 1841 | dep.deletion_flag = true; |
| ... | @@ -1865,7 +1843,8 @@ fn deleteDecl(self: *Module, decl: *Decl) !void { | ... | @@ -1865,7 +1843,8 @@ fn deleteDecl(self: *Module, decl: *Decl) !void { |
| 1865 | } | 1843 | } |
| 1866 | } | 1844 | } |
| 1867 | // Anything that depends on this deleted decl certainly needs to be re-analyzed. | 1845 | // Anything that depends on this deleted decl certainly needs to be re-analyzed. |
| 1868 | for (decl.dependants.items) |dep| { | 1846 | for (decl.dependants.items()) |entry| { |
| | 1847 | const dep = entry.key; |
| 1869 | dep.removeDependency(decl); | 1848 | dep.removeDependency(decl); |
| 1870 | if (dep.analysis != .outdated) { | 1849 | if (dep.analysis != .outdated) { |
| 1871 | // TODO Move this failure possibility to the top of the function. | 1850 | // TODO Move this failure possibility to the top of the function. |
| ... | @@ -1873,11 +1852,11 @@ fn deleteDecl(self: *Module, decl: *Decl) !void { | ... | @@ -1873,11 +1852,11 @@ fn deleteDecl(self: *Module, decl: *Decl) !void { |
| 1873 | } | 1852 | } |
| 1874 | } | 1853 | } |
| 1875 | if (self.failed_decls.remove(decl)) |entry| { | 1854 | if (self.failed_decls.remove(decl)) |entry| { |
| 1876 | entry.value.destroy(self.allocator); | 1855 | entry.value.destroy(self.gpa); |
| 1877 | } | 1856 | } |
| 1878 | self.deleteDeclExports(decl); | 1857 | self.deleteDeclExports(decl); |
| 1879 | self.bin_file.freeDecl(decl); | 1858 | self.bin_file.freeDecl(decl); |
| 1880 | decl.destroy(self.allocator); | 1859 | decl.destroy(self.gpa); |
| 1881 | } | 1860 | } |
| 1882 | | 1861 | |
| 1883 | /// Delete all the Export objects that are caused by this Decl. Re-analysis of | 1862 | /// Delete all the Export objects that are caused by this Decl. Re-analysis of |
| ... | @@ -1899,7 +1878,7 @@ fn deleteDeclExports(self: *Module, decl: *Decl) void { | ... | @@ -1899,7 +1878,7 @@ fn deleteDeclExports(self: *Module, decl: *Decl) void { |
| 1899 | i += 1; | 1878 | i += 1; |
| 1900 | } | 1879 | } |
| 1901 | } | 1880 | } |
| 1902 | decl_exports_kv.value = self.allocator.shrink(list, new_len); | 1881 | decl_exports_kv.value = self.gpa.shrink(list, new_len); |
| 1903 | if (new_len == 0) { | 1882 | if (new_len == 0) { |
| 1904 | self.decl_exports.removeAssertDiscard(exp.exported_decl); | 1883 | self.decl_exports.removeAssertDiscard(exp.exported_decl); |
| 1905 | } | 1884 | } |
| ... | @@ -1907,12 +1886,12 @@ fn deleteDeclExports(self: *Module, decl: *Decl) void { | ... | @@ -1907,12 +1886,12 @@ fn deleteDeclExports(self: *Module, decl: *Decl) void { |
| 1907 | | 1886 | |
| 1908 | self.bin_file.deleteExport(exp.link); | 1887 | self.bin_file.deleteExport(exp.link); |
| 1909 | if (self.failed_exports.remove(exp)) |entry| { | 1888 | if (self.failed_exports.remove(exp)) |entry| { |
| 1910 | entry.value.destroy(self.allocator); | 1889 | entry.value.destroy(self.gpa); |
| 1911 | } | 1890 | } |
| 1912 | _ = self.symbol_exports.remove(exp.options.name); | 1891 | _ = self.symbol_exports.remove(exp.options.name); |
| 1913 | self.allocator.destroy(exp); | 1892 | self.gpa.destroy(exp); |
| 1914 | } | 1893 | } |
| 1915 | self.allocator.free(kv.value); | 1894 | self.gpa.free(kv.value); |
| 1916 | } | 1895 | } |
| 1917 | | 1896 | |
| 1918 | fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void { | 1897 | fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void { |
| ... | @@ -1920,7 +1899,7 @@ fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void { | ... | @@ -1920,7 +1899,7 @@ fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void { |
| 1920 | defer tracy.end(); | 1899 | defer tracy.end(); |
| 1921 | | 1900 | |
| 1922 | // Use the Decl's arena for function memory. | 1901 | // Use the Decl's arena for function memory. |
| 1923 | var arena = decl.typed_value.most_recent.arena.?.promote(self.allocator); | 1902 | var arena = decl.typed_value.most_recent.arena.?.promote(self.gpa); |
| 1924 | defer decl.typed_value.most_recent.arena.?.* = arena.state; | 1903 | defer decl.typed_value.most_recent.arena.?.* = arena.state; |
| 1925 | var inner_block: Scope.Block = .{ | 1904 | var inner_block: Scope.Block = .{ |
| 1926 | .parent = null, | 1905 | .parent = null, |
| ... | @@ -1929,10 +1908,10 @@ fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void { | ... | @@ -1929,10 +1908,10 @@ fn analyzeFnBody(self: *Module, decl: *Decl, func: *Fn) !void { |
| 1929 | .instructions = .{}, | 1908 | .instructions = .{}, |
| 1930 | .arena = &arena.allocator, | 1909 | .arena = &arena.allocator, |
| 1931 | }; | 1910 | }; |
| 1932 | defer inner_block.instructions.deinit(self.allocator); | 1911 | defer inner_block.instructions.deinit(self.gpa); |
| 1933 | | 1912 | |
| 1934 | const fn_zir = func.analysis.queued; | 1913 | const fn_zir = func.analysis.queued; |
| 1935 | defer fn_zir.arena.promote(self.allocator).deinit(); | 1914 | defer fn_zir.arena.promote(self.gpa).deinit(); |
| 1936 | func.analysis = .{ .in_progress = {} }; | 1915 | func.analysis = .{ .in_progress = {} }; |
| 1937 | //std.debug.warn("set {} to in_progress\n", .{decl.name}); | 1916 | //std.debug.warn("set {} to in_progress\n", .{decl.name}); |
| 1938 | | 1917 | |
| ... | @@ -1947,7 +1926,7 @@ fn markOutdatedDecl(self: *Module, decl: *Decl) !void { | ... | @@ -1947,7 +1926,7 @@ fn markOutdatedDecl(self: *Module, decl: *Decl) !void { |
| 1947 | //std.debug.warn("mark {} outdated\n", .{decl.name}); | 1926 | //std.debug.warn("mark {} outdated\n", .{decl.name}); |
| 1948 | try self.work_queue.writeItem(.{ .analyze_decl = decl }); | 1927 | try self.work_queue.writeItem(.{ .analyze_decl = decl }); |
| 1949 | if (self.failed_decls.remove(decl)) |entry| { | 1928 | if (self.failed_decls.remove(decl)) |entry| { |
| 1950 | entry.value.destroy(self.allocator); | 1929 | entry.value.destroy(self.gpa); |
| 1951 | } | 1930 | } |
| 1952 | decl.analysis = .outdated; | 1931 | decl.analysis = .outdated; |
| 1953 | } | 1932 | } |
| ... | @@ -1958,7 +1937,7 @@ fn allocateNewDecl( | ... | @@ -1958,7 +1937,7 @@ fn allocateNewDecl( |
| 1958 | src_index: usize, | 1937 | src_index: usize, |
| 1959 | contents_hash: std.zig.SrcHash, | 1938 | contents_hash: std.zig.SrcHash, |
| 1960 | ) !*Decl { | 1939 | ) !*Decl { |
| 1961 | const new_decl = try self.allocator.create(Decl); | 1940 | const new_decl = try self.gpa.create(Decl); |
| 1962 | new_decl.* = .{ | 1941 | new_decl.* = .{ |
| 1963 | .name = "", | 1942 | .name = "", |
| 1964 | .scope = scope.namespace(), | 1943 | .scope = scope.namespace(), |
| ... | @@ -1981,10 +1960,10 @@ fn createNewDecl( | ... | @@ -1981,10 +1960,10 @@ fn createNewDecl( |
| 1981 | name_hash: Scope.NameHash, | 1960 | name_hash: Scope.NameHash, |
| 1982 | contents_hash: std.zig.SrcHash, | 1961 | contents_hash: std.zig.SrcHash, |
| 1983 | ) !*Decl { | 1962 | ) !*Decl { |
| 1984 | try self.decl_table.ensureCapacity(self.decl_table.items().len + 1); | 1963 | try self.decl_table.ensureCapacity(self.gpa, self.decl_table.items().len + 1); |
| 1985 | const new_decl = try self.allocateNewDecl(scope, src_index, contents_hash); | 1964 | const new_decl = try self.allocateNewDecl(scope, src_index, contents_hash); |
| 1986 | errdefer self.allocator.destroy(new_decl); | 1965 | errdefer self.gpa.destroy(new_decl); |
| 1987 | new_decl.name = try mem.dupeZ(self.allocator, u8, decl_name); | 1966 | new_decl.name = try mem.dupeZ(self.gpa, u8, decl_name); |
| 1988 | self.decl_table.putAssumeCapacityNoClobber(name_hash, new_decl); | 1967 | self.decl_table.putAssumeCapacityNoClobber(name_hash, new_decl); |
| 1989 | return new_decl; | 1968 | return new_decl; |
| 1990 | } | 1969 | } |
| ... | @@ -1992,7 +1971,7 @@ fn createNewDecl( | ... | @@ -1992,7 +1971,7 @@ fn createNewDecl( |
| 1992 | fn analyzeZirDecl(self: *Module, decl: *Decl, src_decl: *zir.Decl) InnerError!bool { | 1971 | fn analyzeZirDecl(self: *Module, decl: *Decl, src_decl: *zir.Decl) InnerError!bool { |
| 1993 | var decl_scope: Scope.DeclAnalysis = .{ | 1972 | var decl_scope: Scope.DeclAnalysis = .{ |
| 1994 | .decl = decl, | 1973 | .decl = decl, |
| 1995 | .arena = std.heap.ArenaAllocator.init(self.allocator), | 1974 | .arena = std.heap.ArenaAllocator.init(self.gpa), |
| 1996 | }; | 1975 | }; |
| 1997 | errdefer decl_scope.arena.deinit(); | 1976 | errdefer decl_scope.arena.deinit(); |
| 1998 | | 1977 | |
| ... | @@ -2008,7 +1987,7 @@ fn analyzeZirDecl(self: *Module, decl: *Decl, src_decl: *zir.Decl) InnerError!bo | ... | @@ -2008,7 +1987,7 @@ fn analyzeZirDecl(self: *Module, decl: *Decl, src_decl: *zir.Decl) InnerError!bo |
| 2008 | prev_type_has_bits = tvm.typed_value.ty.hasCodeGenBits(); | 1987 | prev_type_has_bits = tvm.typed_value.ty.hasCodeGenBits(); |
| 2009 | type_changed = !tvm.typed_value.ty.eql(typed_value.ty); | 1988 | type_changed = !tvm.typed_value.ty.eql(typed_value.ty); |
| 2010 | | 1989 | |
| 2011 | tvm.deinit(self.allocator); | 1990 | tvm.deinit(self.gpa); |
| 2012 | } | 1991 | } |
| 2013 | | 1992 | |
| 2014 | arena_state.* = decl_scope.arena.state; | 1993 | arena_state.* = decl_scope.arena.state; |
| ... | @@ -2146,11 +2125,11 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const | ... | @@ -2146,11 +2125,11 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const |
| 2146 | else => return self.fail(scope, src, "unable to export type '{}'", .{typed_value.ty}), | 2125 | else => return self.fail(scope, src, "unable to export type '{}'", .{typed_value.ty}), |
| 2147 | } | 2126 | } |
| 2148 | | 2127 | |
| 2149 | try self.decl_exports.ensureCapacity(self.decl_exports.items().len + 1); | 2128 | try self.decl_exports.ensureCapacity(self.gpa, self.decl_exports.items().len + 1); |
| 2150 | try self.export_owners.ensureCapacity(self.export_owners.items().len + 1); | 2129 | try self.export_owners.ensureCapacity(self.gpa, self.export_owners.items().len + 1); |
| 2151 | | 2130 | |
| 2152 | const new_export = try self.allocator.create(Export); | 2131 | const new_export = try self.gpa.create(Export); |
| 2153 | errdefer self.allocator.destroy(new_export); | 2132 | errdefer self.gpa.destroy(new_export); |
| 2154 | | 2133 | |
| 2155 | const owner_decl = scope.decl().?; | 2134 | const owner_decl = scope.decl().?; |
| 2156 | | 2135 | |
| ... | @@ -2164,27 +2143,27 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const | ... | @@ -2164,27 +2143,27 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const |
| 2164 | }; | 2143 | }; |
| 2165 | | 2144 | |
| 2166 | // Add to export_owners table. | 2145 | // Add to export_owners table. |
| 2167 | const eo_gop = self.export_owners.getOrPut(owner_decl) catch unreachable; | 2146 | const eo_gop = self.export_owners.getOrPut(self.gpa, owner_decl) catch unreachable; |
| 2168 | if (!eo_gop.found_existing) { | 2147 | if (!eo_gop.found_existing) { |
| 2169 | eo_gop.entry.value = &[0]*Export{}; | 2148 | eo_gop.entry.value = &[0]*Export{}; |
| 2170 | } | 2149 | } |
| 2171 | eo_gop.entry.value = try self.allocator.realloc(eo_gop.entry.value, eo_gop.entry.value.len + 1); | 2150 | eo_gop.entry.value = try self.gpa.realloc(eo_gop.entry.value, eo_gop.entry.value.len + 1); |
| 2172 | eo_gop.entry.value[eo_gop.entry.value.len - 1] = new_export; | 2151 | eo_gop.entry.value[eo_gop.entry.value.len - 1] = new_export; |
| 2173 | errdefer eo_gop.entry.value = self.allocator.shrink(eo_gop.entry.value, eo_gop.entry.value.len - 1); | 2152 | errdefer eo_gop.entry.value = self.gpa.shrink(eo_gop.entry.value, eo_gop.entry.value.len - 1); |
| 2174 | | 2153 | |
| 2175 | // Add to exported_decl table. | 2154 | // Add to exported_decl table. |
| 2176 | const de_gop = self.decl_exports.getOrPut(exported_decl) catch unreachable; | 2155 | const de_gop = self.decl_exports.getOrPut(self.gpa, exported_decl) catch unreachable; |
| 2177 | if (!de_gop.found_existing) { | 2156 | if (!de_gop.found_existing) { |
| 2178 | de_gop.entry.value = &[0]*Export{}; | 2157 | de_gop.entry.value = &[0]*Export{}; |
| 2179 | } | 2158 | } |
| 2180 | de_gop.entry.value = try self.allocator.realloc(de_gop.entry.value, de_gop.entry.value.len + 1); | 2159 | de_gop.entry.value = try self.gpa.realloc(de_gop.entry.value, de_gop.entry.value.len + 1); |
| 2181 | de_gop.entry.value[de_gop.entry.value.len - 1] = new_export; | 2160 | de_gop.entry.value[de_gop.entry.value.len - 1] = new_export; |
| 2182 | errdefer de_gop.entry.value = self.allocator.shrink(de_gop.entry.value, de_gop.entry.value.len - 1); | 2161 | errdefer de_gop.entry.value = self.gpa.shrink(de_gop.entry.value, de_gop.entry.value.len - 1); |
| 2183 | | 2162 | |
| 2184 | if (self.symbol_exports.get(symbol_name)) |_| { | 2163 | if (self.symbol_exports.get(symbol_name)) |_| { |
| 2185 | try self.failed_exports.ensureCapacity(self.failed_exports.items().len + 1); | 2164 | try self.failed_exports.ensureCapacity(self.gpa, self.failed_exports.items().len + 1); |
| 2186 | self.failed_exports.putAssumeCapacityNoClobber(new_export, try ErrorMsg.create( | 2165 | self.failed_exports.putAssumeCapacityNoClobber(new_export, try ErrorMsg.create( |
| 2187 | self.allocator, | 2166 | self.gpa, |
| 2188 | src, | 2167 | src, |
| 2189 | "exported symbol collision: {}", | 2168 | "exported symbol collision: {}", |
| 2190 | .{symbol_name}, | 2169 | .{symbol_name}, |
| ... | @@ -2198,9 +2177,9 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const | ... | @@ -2198,9 +2177,9 @@ fn analyzeExport(self: *Module, scope: *Scope, src: usize, symbol_name: []const |
| 2198 | self.bin_file.updateDeclExports(self, exported_decl, de_gop.entry.value) catch |err| switch (err) { | 2177 | self.bin_file.updateDeclExports(self, exported_decl, de_gop.entry.value) catch |err| switch (err) { |
| 2199 | error.OutOfMemory => return error.OutOfMemory, | 2178 | error.OutOfMemory => return error.OutOfMemory, |
| 2200 | else => { | 2179 | else => { |
| 2201 | try self.failed_exports.ensureCapacity(self.failed_exports.items().len + 1); | 2180 | try self.failed_exports.ensureCapacity(self.gpa, self.failed_exports.items().len + 1); |
| 2202 | self.failed_exports.putAssumeCapacityNoClobber(new_export, try ErrorMsg.create( | 2181 | self.failed_exports.putAssumeCapacityNoClobber(new_export, try ErrorMsg.create( |
| 2203 | self.allocator, | 2182 | self.gpa, |
| 2204 | src, | 2183 | src, |
| 2205 | "unable to export: {}", | 2184 | "unable to export: {}", |
| 2206 | .{@errorName(err)}, | 2185 | .{@errorName(err)}, |
| ... | @@ -2224,13 +2203,13 @@ fn addNewInstArgs( | ... | @@ -2224,13 +2203,13 @@ fn addNewInstArgs( |
| 2224 | } | 2203 | } |
| 2225 | | 2204 | |
| 2226 | fn newZIRInst( | 2205 | fn newZIRInst( |
| 2227 | allocator: *Allocator, | 2206 | gpa: *Allocator, |
| 2228 | src: usize, | 2207 | src: usize, |
| 2229 | comptime T: type, | 2208 | comptime T: type, |
| 2230 | positionals: std.meta.fieldInfo(T, "positionals").field_type, | 2209 | positionals: std.meta.fieldInfo(T, "positionals").field_type, |
| 2231 | kw_args: std.meta.fieldInfo(T, "kw_args").field_type, | 2210 | kw_args: std.meta.fieldInfo(T, "kw_args").field_type, |
| 2232 | ) !*zir.Inst { | 2211 | ) !*zir.Inst { |
| 2233 | const inst = try allocator.create(T); | 2212 | const inst = try gpa.create(T); |
| 2234 | inst.* = .{ | 2213 | inst.* = .{ |
| 2235 | .base = .{ | 2214 | .base = .{ |
| 2236 | .tag = T.base_tag, | 2215 | .tag = T.base_tag, |
| ... | @@ -2273,7 +2252,7 @@ fn addNewInst(self: *Module, block: *Scope.Block, src: usize, ty: Type, comptime | ... | @@ -2273,7 +2252,7 @@ fn addNewInst(self: *Module, block: *Scope.Block, src: usize, ty: Type, comptime |
| 2273 | }, | 2252 | }, |
| 2274 | .args = undefined, | 2253 | .args = undefined, |
| 2275 | }; | 2254 | }; |
| 2276 | try block.instructions.append(self.allocator, &inst.base); | 2255 | try block.instructions.append(self.gpa, &inst.base); |
| 2277 | return inst; | 2256 | return inst; |
| 2278 | } | 2257 | } |
| 2279 | | 2258 | |
| ... | @@ -2433,7 +2412,7 @@ fn analyzeInst(self: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!*In | ... | @@ -2433,7 +2412,7 @@ fn analyzeInst(self: *Module, scope: *Scope, old_inst: *zir.Inst) InnerError!*In |
| 2433 | fn analyzeInstStr(self: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerError!*Inst { | 2412 | fn analyzeInstStr(self: *Module, scope: *Scope, str_inst: *zir.Inst.Str) InnerError!*Inst { |
| 2434 | // The bytes references memory inside the ZIR module, which can get deallocated | 2413 | // The bytes references memory inside the ZIR module, which can get deallocated |
| 2435 | // after semantic analysis is complete. We need the memory to be in the new anonymous Decl's arena. | 2414 | // after semantic analysis is complete. We need the memory to be in the new anonymous Decl's arena. |
| 2436 | var new_decl_arena = std.heap.ArenaAllocator.init(self.allocator); | 2415 | var new_decl_arena = std.heap.ArenaAllocator.init(self.gpa); |
| 2437 | const arena_bytes = try new_decl_arena.allocator.dupe(u8, str_inst.positionals.bytes); | 2416 | const arena_bytes = try new_decl_arena.allocator.dupe(u8, str_inst.positionals.bytes); |
| 2438 | | 2417 | |
| 2439 | const ty_payload = try scope.arena().create(Type.Payload.Array_u8_Sentinel0); | 2418 | const ty_payload = try scope.arena().create(Type.Payload.Array_u8_Sentinel0); |
| ... | @@ -2457,8 +2436,8 @@ fn createAnonymousDecl( | ... | @@ -2457,8 +2436,8 @@ fn createAnonymousDecl( |
| 2457 | ) !*Decl { | 2436 | ) !*Decl { |
| 2458 | const name_index = self.getNextAnonNameIndex(); | 2437 | const name_index = self.getNextAnonNameIndex(); |
| 2459 | const scope_decl = scope.decl().?; | 2438 | const scope_decl = scope.decl().?; |
| 2460 | const name = try std.fmt.allocPrint(self.allocator, "{}${}", .{ scope_decl.name, name_index }); | 2439 | const name = try std.fmt.allocPrint(self.gpa, "{}${}", .{ scope_decl.name, name_index }); |
| 2461 | defer self.allocator.free(name); | 2440 | defer self.gpa.free(name); |
| 2462 | const name_hash = scope.namespace().fullyQualifiedNameHash(name); | 2441 | const name_hash = scope.namespace().fullyQualifiedNameHash(name); |
| 2463 | const src_hash: std.zig.SrcHash = undefined; | 2442 | const src_hash: std.zig.SrcHash = undefined; |
| 2464 | const new_decl = try self.createNewDecl(scope, name, scope_decl.src_index, name_hash, src_hash); | 2443 | const new_decl = try self.createNewDecl(scope, name, scope_decl.src_index, name_hash, src_hash); |
| ... | @@ -2554,8 +2533,8 @@ fn analyzeInstBlock(self: *Module, scope: *Scope, inst: *zir.Inst.Block) InnerEr | ... | @@ -2554,8 +2533,8 @@ fn analyzeInstBlock(self: *Module, scope: *Scope, inst: *zir.Inst.Block) InnerEr |
| 2554 | }; | 2533 | }; |
| 2555 | const label = &child_block.label.?; | 2534 | const label = &child_block.label.?; |
| 2556 | | 2535 | |
| 2557 | defer child_block.instructions.deinit(self.allocator); | 2536 | defer child_block.instructions.deinit(self.gpa); |
| 2558 | defer label.results.deinit(self.allocator); | 2537 | defer label.results.deinit(self.gpa); |
| 2559 | | 2538 | |
| 2560 | try self.analyzeBody(&child_block.base, inst.positionals.body); | 2539 | try self.analyzeBody(&child_block.base, inst.positionals.body); |
| 2561 | | 2540 | |
| ... | @@ -2567,7 +2546,7 @@ fn analyzeInstBlock(self: *Module, scope: *Scope, inst: *zir.Inst.Block) InnerEr | ... | @@ -2567,7 +2546,7 @@ fn analyzeInstBlock(self: *Module, scope: *Scope, inst: *zir.Inst.Block) InnerEr |
| 2567 | // No need to add the Block instruction; we can add the instructions to the parent block directly. | 2546 | // No need to add the Block instruction; we can add the instructions to the parent block directly. |
| 2568 | // Blocks are terminated with a noreturn instruction which we do not want to include. | 2547 | // Blocks are terminated with a noreturn instruction which we do not want to include. |
| 2569 | const instrs = child_block.instructions.items; | 2548 | const instrs = child_block.instructions.items; |
| 2570 | try parent_block.instructions.appendSlice(self.allocator, instrs[0 .. instrs.len - 1]); | 2549 | try parent_block.instructions.appendSlice(self.gpa, instrs[0 .. instrs.len - 1]); |
| 2571 | if (label.results.items.len == 1) { | 2550 | if (label.results.items.len == 1) { |
| 2572 | return label.results.items[0]; | 2551 | return label.results.items[0]; |
| 2573 | } else { | 2552 | } else { |
| ... | @@ -2577,7 +2556,7 @@ fn analyzeInstBlock(self: *Module, scope: *Scope, inst: *zir.Inst.Block) InnerEr | ... | @@ -2577,7 +2556,7 @@ fn analyzeInstBlock(self: *Module, scope: *Scope, inst: *zir.Inst.Block) InnerEr |
| 2577 | | 2556 | |
| 2578 | // Need to set the type and emit the Block instruction. This allows machine code generation | 2557 | // Need to set the type and emit the Block instruction. This allows machine code generation |
| 2579 | // to emit a jump instruction to after the block when it encounters the break. | 2558 | // to emit a jump instruction to after the block when it encounters the break. |
| 2580 | try parent_block.instructions.append(self.allocator, &block_inst.base); | 2559 | try parent_block.instructions.append(self.gpa, &block_inst.base); |
| 2581 | block_inst.base.ty = try self.resolvePeerTypes(scope, label.results.items); | 2560 | block_inst.base.ty = try self.resolvePeerTypes(scope, label.results.items); |
| 2582 | block_inst.args.body = .{ .instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items) }; | 2561 | block_inst.args.body = .{ .instructions = try parent_block.arena.dupe(*Inst, child_block.instructions.items) }; |
| 2583 | return &block_inst.base; | 2562 | return &block_inst.base; |
| ... | @@ -2596,7 +2575,7 @@ fn analyzeInstBreakVoid(self: *Module, scope: *Scope, inst: *zir.Inst.BreakVoid) | ... | @@ -2596,7 +2575,7 @@ fn analyzeInstBreakVoid(self: *Module, scope: *Scope, inst: *zir.Inst.BreakVoid) |
| 2596 | while (opt_block) |block| { | 2575 | while (opt_block) |block| { |
| 2597 | if (block.label) |*label| { | 2576 | if (block.label) |*label| { |
| 2598 | if (mem.eql(u8, label.name, label_name)) { | 2577 | if (mem.eql(u8, label.name, label_name)) { |
| 2599 | try label.results.append(self.allocator, void_inst); | 2578 | try label.results.append(self.gpa, void_inst); |
| 2600 | return self.constNoReturn(scope, inst.base.src); | 2579 | return self.constNoReturn(scope, inst.base.src); |
| 2601 | } | 2580 | } |
| 2602 | } | 2581 | } |
| ... | @@ -2719,8 +2698,8 @@ fn analyzeInstCall(self: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerErro | ... | @@ -2719,8 +2698,8 @@ fn analyzeInstCall(self: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerErro |
| 2719 | | 2698 | |
| 2720 | // TODO handle function calls of generic functions | 2699 | // TODO handle function calls of generic functions |
| 2721 | | 2700 | |
| 2722 | const fn_param_types = try self.allocator.alloc(Type, fn_params_len); | 2701 | const fn_param_types = try self.gpa.alloc(Type, fn_params_len); |
| 2723 | defer self.allocator.free(fn_param_types); | 2702 | defer self.gpa.free(fn_param_types); |
| 2724 | func.ty.fnParamTypes(fn_param_types); | 2703 | func.ty.fnParamTypes(fn_param_types); |
| 2725 | | 2704 | |
| 2726 | const casted_args = try scope.arena().alloc(*Inst, fn_params_len); | 2705 | const casted_args = try scope.arena().alloc(*Inst, fn_params_len); |
| ... | @@ -2739,7 +2718,7 @@ fn analyzeInstCall(self: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerErro | ... | @@ -2739,7 +2718,7 @@ fn analyzeInstCall(self: *Module, scope: *Scope, inst: *zir.Inst.Call) InnerErro |
| 2739 | fn analyzeInstFn(self: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!*Inst { | 2718 | fn analyzeInstFn(self: *Module, scope: *Scope, fn_inst: *zir.Inst.Fn) InnerError!*Inst { |
| 2740 | const fn_type = try self.resolveType(scope, fn_inst.positionals.fn_type); | 2719 | const fn_type = try self.resolveType(scope, fn_inst.positionals.fn_type); |
| 2741 | const fn_zir = blk: { | 2720 | const fn_zir = blk: { |
| 2742 | var fn_arena = std.heap.ArenaAllocator.init(self.allocator); | 2721 | var fn_arena = std.heap.ArenaAllocator.init(self.gpa); |
| 2743 | errdefer fn_arena.deinit(); | 2722 | errdefer fn_arena.deinit(); |
| 2744 | | 2723 | |
| 2745 | const fn_zir = try scope.arena().create(Fn.ZIR); | 2724 | const fn_zir = try scope.arena().create(Fn.ZIR); |
| ... | @@ -3120,7 +3099,7 @@ fn analyzeInstCondBr(self: *Module, scope: *Scope, inst: *zir.Inst.CondBr) Inner | ... | @@ -3120,7 +3099,7 @@ fn analyzeInstCondBr(self: *Module, scope: *Scope, inst: *zir.Inst.CondBr) Inner |
| 3120 | .instructions = .{}, | 3099 | .instructions = .{}, |
| 3121 | .arena = parent_block.arena, | 3100 | .arena = parent_block.arena, |
| 3122 | }; | 3101 | }; |
| 3123 | defer true_block.instructions.deinit(self.allocator); | 3102 | defer true_block.instructions.deinit(self.gpa); |
| 3124 | try self.analyzeBody(&true_block.base, inst.positionals.true_body); | 3103 | try self.analyzeBody(&true_block.base, inst.positionals.true_body); |
| 3125 | | 3104 | |
| 3126 | var false_block: Scope.Block = .{ | 3105 | var false_block: Scope.Block = .{ |
| ... | @@ -3130,7 +3109,7 @@ fn analyzeInstCondBr(self: *Module, scope: *Scope, inst: *zir.Inst.CondBr) Inner | ... | @@ -3130,7 +3109,7 @@ fn analyzeInstCondBr(self: *Module, scope: *Scope, inst: *zir.Inst.CondBr) Inner |
| 3130 | .instructions = .{}, | 3109 | .instructions = .{}, |
| 3131 | .arena = parent_block.arena, | 3110 | .arena = parent_block.arena, |
| 3132 | }; | 3111 | }; |
| 3133 | defer false_block.instructions.deinit(self.allocator); | 3112 | defer false_block.instructions.deinit(self.gpa); |
| 3134 | try self.analyzeBody(&false_block.base, inst.positionals.false_body); | 3113 | try self.analyzeBody(&false_block.base, inst.positionals.false_body); |
| 3135 | | 3114 | |
| 3136 | return self.addNewInstArgs(parent_block, inst.base.src, Type.initTag(.void), Inst.CondBr, Inst.Args(Inst.CondBr){ | 3115 | return self.addNewInstArgs(parent_block, inst.base.src, Type.initTag(.void), Inst.CondBr, Inst.Args(Inst.CondBr){ |
| ... | @@ -3284,7 +3263,7 @@ fn cmpNumeric( | ... | @@ -3284,7 +3263,7 @@ fn cmpNumeric( |
| 3284 | return self.constUndef(scope, src, Type.initTag(.bool)); | 3263 | return self.constUndef(scope, src, Type.initTag(.bool)); |
| 3285 | const is_unsigned = if (lhs_is_float) x: { | 3264 | const is_unsigned = if (lhs_is_float) x: { |
| 3286 | var bigint_space: Value.BigIntSpace = undefined; | 3265 | var bigint_space: Value.BigIntSpace = undefined; |
| 3287 | var bigint = try lhs_val.toBigInt(&bigint_space).toManaged(self.allocator); | 3266 | var bigint = try lhs_val.toBigInt(&bigint_space).toManaged(self.gpa); |
| 3288 | defer bigint.deinit(); | 3267 | defer bigint.deinit(); |
| 3289 | const zcmp = lhs_val.orderAgainstZero(); | 3268 | const zcmp = lhs_val.orderAgainstZero(); |
| 3290 | if (lhs_val.floatHasFraction()) { | 3269 | if (lhs_val.floatHasFraction()) { |
| ... | @@ -3319,7 +3298,7 @@ fn cmpNumeric( | ... | @@ -3319,7 +3298,7 @@ fn cmpNumeric( |
| 3319 | return self.constUndef(scope, src, Type.initTag(.bool)); | 3298 | return self.constUndef(scope, src, Type.initTag(.bool)); |
| 3320 | const is_unsigned = if (rhs_is_float) x: { | 3299 | const is_unsigned = if (rhs_is_float) x: { |
| 3321 | var bigint_space: Value.BigIntSpace = undefined; | 3300 | var bigint_space: Value.BigIntSpace = undefined; |
| 3322 | var bigint = try rhs_val.toBigInt(&bigint_space).toManaged(self.allocator); | 3301 | var bigint = try rhs_val.toBigInt(&bigint_space).toManaged(self.gpa); |
| 3323 | defer bigint.deinit(); | 3302 | defer bigint.deinit(); |
| 3324 | const zcmp = rhs_val.orderAgainstZero(); | 3303 | const zcmp = rhs_val.orderAgainstZero(); |
| 3325 | if (rhs_val.floatHasFraction()) { | 3304 | if (rhs_val.floatHasFraction()) { |
| ... | @@ -3457,7 +3436,7 @@ fn coerceArrayPtrToSlice(self: *Module, scope: *Scope, dest_type: Type, inst: *I | ... | @@ -3457,7 +3436,7 @@ fn coerceArrayPtrToSlice(self: *Module, scope: *Scope, dest_type: Type, inst: *I |
| 3457 | | 3436 | |
| 3458 | fn fail(self: *Module, scope: *Scope, src: usize, comptime format: []const u8, args: var) InnerError { | 3437 | fn fail(self: *Module, scope: *Scope, src: usize, comptime format: []const u8, args: var) InnerError { |
| 3459 | @setCold(true); | 3438 | @setCold(true); |
| 3460 | const err_msg = try ErrorMsg.create(self.allocator, src, format, args); | 3439 | const err_msg = try ErrorMsg.create(self.gpa, src, format, args); |
| 3461 | return self.failWithOwnedErrorMsg(scope, src, err_msg); | 3440 | return self.failWithOwnedErrorMsg(scope, src, err_msg); |
| 3462 | } | 3441 | } |
| 3463 | | 3442 | |
| ... | @@ -3487,9 +3466,9 @@ fn failNode( | ... | @@ -3487,9 +3466,9 @@ fn failNode( |
| 3487 | | 3466 | |
| 3488 | fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *ErrorMsg) InnerError { | 3467 | fn failWithOwnedErrorMsg(self: *Module, scope: *Scope, src: usize, err_msg: *ErrorMsg) InnerError { |
| 3489 | { | 3468 | { |
| 3490 | errdefer err_msg.destroy(self.allocator); | 3469 | errdefer err_msg.destroy(self.gpa); |
| 3491 | try self.failed_decls.ensureCapacity(self.failed_decls.items().len + 1); | 3470 | try self.failed_decls.ensureCapacity(self.gpa, self.failed_decls.items().len + 1); |
| 3492 | try self.failed_files.ensureCapacity(self.failed_files.items().len + 1); | 3471 | try self.failed_files.ensureCapacity(self.gpa, self.failed_files.items().len + 1); |
| 3493 | } | 3472 | } |
| 3494 | switch (scope.tag) { | 3473 | switch (scope.tag) { |
| 3495 | .decl => { | 3474 | .decl => { |
| ... | @@ -3542,28 +3521,28 @@ pub const ErrorMsg = struct { | ... | @@ -3542,28 +3521,28 @@ pub const ErrorMsg = struct { |
| 3542 | byte_offset: usize, | 3521 | byte_offset: usize, |
| 3543 | msg: []const u8, | 3522 | msg: []const u8, |
| 3544 | | 3523 | |
| 3545 | pub fn create(allocator: *Allocator, byte_offset: usize, comptime format: []const u8, args: var) !*ErrorMsg { | 3524 | pub fn create(gpa: *Allocator, byte_offset: usize, comptime format: []const u8, args: var) !*ErrorMsg { |
| 3546 | const self = try allocator.create(ErrorMsg); | 3525 | const self = try gpa.create(ErrorMsg); |
| 3547 | errdefer allocator.destroy(self); | 3526 | errdefer gpa.destroy(self); |
| 3548 | self.* = try init(allocator, byte_offset, format, args); | 3527 | self.* = try init(gpa, byte_offset, format, args); |
| 3549 | return self; | 3528 | return self; |
| 3550 | } | 3529 | } |
| 3551 | | 3530 | |
| 3552 | /// Assumes the ErrorMsg struct and msg were both allocated with allocator. | 3531 | /// Assumes the ErrorMsg struct and msg were both allocated with allocator. |
| 3553 | pub fn destroy(self: *ErrorMsg, allocator: *Allocator) void { | 3532 | pub fn destroy(self: *ErrorMsg, gpa: *Allocator) void { |
| 3554 | self.deinit(allocator); | 3533 | self.deinit(gpa); |
| 3555 | allocator.destroy(self); | 3534 | gpa.destroy(self); |
| 3556 | } | 3535 | } |
| 3557 | | 3536 | |
| 3558 | pub fn init(allocator: *Allocator, byte_offset: usize, comptime format: []const u8, args: var) !ErrorMsg { | 3537 | pub fn init(gpa: *Allocator, byte_offset: usize, comptime format: []const u8, args: var) !ErrorMsg { |
| 3559 | return ErrorMsg{ | 3538 | return ErrorMsg{ |
| 3560 | .byte_offset = byte_offset, | 3539 | .byte_offset = byte_offset, |
| 3561 | .msg = try std.fmt.allocPrint(allocator, format, args), | 3540 | .msg = try std.fmt.allocPrint(gpa, format, args), |
| 3562 | }; | 3541 | }; |
| 3563 | } | 3542 | } |
| 3564 | | 3543 | |
| 3565 | pub fn deinit(self: *ErrorMsg, allocator: *Allocator) void { | 3544 | pub fn deinit(self: *ErrorMsg, gpa: *Allocator) void { |
| 3566 | allocator.free(self.msg); | 3545 | gpa.free(self.msg); |
| 3567 | self.* = undefined; | 3546 | self.* = undefined; |
| 3568 | } | 3547 | } |
| 3569 | }; | 3548 | }; |