| author | |
| committer | |
| log | 731c35f15a1469c9523b71476f1e069d5bcfd979 |
| tree | 00b0244c86df035ff721cb45216594426007ce96 |
| parent | 3d99fb3352eca9da68b6033ad22a166ed68ed36a |
Previously, stage2 used a global decl_table for all Decl objects, keyed
by a 16-byte name hash that was hopefully unique. Now, there is a tree
of Namespace objects that own their named Decl objects.6 files changed, 0 insertions(+), 49 deletions(-)
BRANCH_TODO-25| ... | ... | @@ -3,21 +3,6 @@ |
| 3 | 3 | their indexes starting at 0 so that we can use an array to store Sema |
| 4 | 4 | results rather than a map. |
| 5 | 5 | |
| 6 | * get rid of NameHash | |
| 7 | * handle decl collision with usingnamespace | |
| 8 | * the decl doing the looking up needs to create a decl dependency | |
| 9 | on each usingnamespace decl | |
| 10 | * handle usingnamespace cycles | |
| 11 | ||
| 12 | * compile error for return inside defer expression | |
| 13 | ||
| 14 | * when block has noreturn statement | |
| 15 | - avoid emitting defers | |
| 16 | - compile error for unreachable code | |
| 17 | ||
| 18 | * detect `return error.Foo` and emit ZIR that unconditionally generates errdefers | |
| 19 | * `return`: check return operand and generate errdefers if necessary | |
| 20 | ||
| 21 | 6 | * have failed_trees and just put the file in there |
| 22 | 7 | - this way we can emit all the parse errors not just the first one |
| 23 | 8 | - but maybe we want just the first one? |
| ... | ... | @@ -58,13 +43,3 @@ |
| 58 | 43 | * repl: if you try `run` with -ofmt=c you get an access denied error because it |
| 59 | 44 | tries to execute the .c file as a child process instead of executing `zig run` |
| 60 | 45 | on it. |
| 61 | ||
| 62 | === file issues: === | |
| 63 | ||
| 64 | * C backend: honor the exported symbol name. Right now if you do `pub fn main` | |
| 65 | it generates bogus C code because the `@export` name is not honored, and it allows | |
| 66 | the `main` which should be not exported, to clobber the exported symbol name. | |
| 67 | ||
| 68 | * get the test runner and `zig test` working | |
| 69 | - get behavior tests passing for stage2 | |
| 70 |
src/Compilation.zig-1| ... | ... | @@ -3563,7 +3563,6 @@ fn buildOutputFromZig( |
| 3563 | 3563 | .handle = special_dir, |
| 3564 | 3564 | }, |
| 3565 | 3565 | .root_src_path = src_basename, |
| 3566 | .namespace_hash = Package.root_namespace_hash, | |
| 3567 | 3566 | }; |
| 3568 | 3567 | const root_name = src_basename[0 .. src_basename.len - std.fs.path.extension(src_basename).len]; |
| 3569 | 3568 | const target = comp.getTarget(); |
src/Module.zig-7| ... | ... | @@ -798,8 +798,6 @@ pub const Var = struct { |
| 798 | 798 | pub const Scope = struct { |
| 799 | 799 | tag: Tag, |
| 800 | 800 | |
| 801 | pub const NameHash = [16]u8; | |
| 802 | ||
| 803 | 801 | pub fn cast(base: *Scope, comptime T: type) ?*T { |
| 804 | 802 | if (base.tag != T.base_tag) |
| 805 | 803 | return null; |
| ... | ... | @@ -839,7 +837,6 @@ pub const Scope = struct { |
| 839 | 837 | .namespace => return @fieldParentPtr(Namespace, "base", base).file_scope.sub_file_path, |
| 840 | 838 | .file => return @fieldParentPtr(File, "base", base).sub_file_path, |
| 841 | 839 | .block => unreachable, |
| 842 | .decl_ref => unreachable, | |
| 843 | 840 | } |
| 844 | 841 | } |
| 845 | 842 | |
| ... | ... | @@ -861,10 +858,6 @@ pub const Scope = struct { |
| 861 | 858 | /// Namespace owned by structs, enums, unions, and opaques for decls. |
| 862 | 859 | namespace, |
| 863 | 860 | block, |
| 864 | /// Used for simple error reporting. Only contains a reference to a | |
| 865 | /// `Decl` for use with `srcDecl` and `ownerDecl`. | |
| 866 | /// Has no parents or children. | |
| 867 | decl_ref, | |
| 868 | 861 | }; |
| 869 | 862 | |
| 870 | 863 | /// The container that structs, enums, unions, and opaques have. |
src/Package.zig-11| ... | ... | @@ -11,22 +11,15 @@ const Module = @import("Module.zig"); |
| 11 | 11 | |
| 12 | 12 | pub const Table = std.StringHashMapUnmanaged(*Package); |
| 13 | 13 | |
| 14 | pub const root_namespace_hash: Module.Scope.NameHash = .{ | |
| 15 | 0, 0, 6, 6, 6, 0, 0, 0, | |
| 16 | 6, 9, 0, 0, 0, 4, 2, 0, | |
| 17 | }; | |
| 18 | ||
| 19 | 14 | root_src_directory: Compilation.Directory, |
| 20 | 15 | /// Relative to `root_src_directory`. May contain path separators. |
| 21 | 16 | root_src_path: []const u8, |
| 22 | 17 | table: Table = .{}, |
| 23 | 18 | parent: ?*Package = null, |
| 24 | namespace_hash: Module.Scope.NameHash, | |
| 25 | 19 | /// Whether to free `root_src_directory` on `destroy`. |
| 26 | 20 | root_src_directory_owned: bool = false, |
| 27 | 21 | |
| 28 | 22 | /// Allocate a Package. No references to the slices passed are kept. |
| 29 | /// Don't forget to set `namespace_hash` later. | |
| 30 | 23 | pub fn create( |
| 31 | 24 | gpa: *Allocator, |
| 32 | 25 | /// Null indicates the current working directory |
| ... | ... | @@ -50,7 +43,6 @@ pub fn create( |
| 50 | 43 | }, |
| 51 | 44 | .root_src_path = owned_src_path, |
| 52 | 45 | .root_src_directory_owned = true, |
| 53 | .namespace_hash = undefined, | |
| 54 | 46 | }; |
| 55 | 47 | |
| 56 | 48 | return ptr; |
| ... | ... | @@ -82,14 +74,12 @@ pub fn createWithDir( |
| 82 | 74 | }, |
| 83 | 75 | .root_src_directory_owned = true, |
| 84 | 76 | .root_src_path = owned_src_path, |
| 85 | .namespace_hash = undefined, | |
| 86 | 77 | }; |
| 87 | 78 | } else { |
| 88 | 79 | ptr.* = .{ |
| 89 | 80 | .root_src_directory = directory, |
| 90 | 81 | .root_src_directory_owned = false, |
| 91 | 82 | .root_src_path = owned_src_path, |
| 92 | .namespace_hash = undefined, | |
| 93 | 83 | }; |
| 94 | 84 | } |
| 95 | 85 | return ptr; |
| ... | ... | @@ -129,6 +119,5 @@ pub fn add(pkg: *Package, gpa: *Allocator, name: []const u8, package: *Package) |
| 129 | 119 | pub fn addAndAdopt(parent: *Package, gpa: *Allocator, name: []const u8, child: *Package) !void { |
| 130 | 120 | assert(child.parent == null); // make up your mind, who is the parent?? |
| 131 | 121 | child.parent = parent; |
| 132 | child.namespace_hash = std.zig.hashName(parent.namespace_hash, ":", name); | |
| 133 | 122 | return parent.add(gpa, name, child); |
| 134 | 123 | } |
src/main.zig-4| ... | ... | @@ -630,7 +630,6 @@ fn buildOutputType( |
| 630 | 630 | var pkg_tree_root: Package = .{ |
| 631 | 631 | .root_src_directory = .{ .path = null, .handle = fs.cwd() }, |
| 632 | 632 | .root_src_path = &[0]u8{}, |
| 633 | .namespace_hash = Package.root_namespace_hash, | |
| 634 | 633 | }; |
| 635 | 634 | defer freePkgTree(gpa, &pkg_tree_root, false); |
| 636 | 635 | var cur_pkg: *Package = &pkg_tree_root; |
| ... | ... | @@ -1768,7 +1767,6 @@ fn buildOutputType( |
| 1768 | 1767 | if (root_pkg) |pkg| { |
| 1769 | 1768 | pkg.table = pkg_tree_root.table; |
| 1770 | 1769 | pkg_tree_root.table = .{}; |
| 1771 | pkg.namespace_hash = pkg_tree_root.namespace_hash; | |
| 1772 | 1770 | } |
| 1773 | 1771 | |
| 1774 | 1772 | const self_exe_path = try fs.selfExePathAlloc(arena); |
| ... | ... | @@ -2657,7 +2655,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v |
| 2657 | 2655 | .handle = try zig_lib_directory.handle.openDir(std_special, .{}), |
| 2658 | 2656 | }, |
| 2659 | 2657 | .root_src_path = "build_runner.zig", |
| 2660 | .namespace_hash = Package.root_namespace_hash, | |
| 2661 | 2658 | }; |
| 2662 | 2659 | defer root_pkg.root_src_directory.handle.close(); |
| 2663 | 2660 | |
| ... | ... | @@ -2703,7 +2700,6 @@ pub fn cmdBuild(gpa: *Allocator, arena: *Allocator, args: []const []const u8) !v |
| 2703 | 2700 | var build_pkg: Package = .{ |
| 2704 | 2701 | .root_src_directory = build_directory, |
| 2705 | 2702 | .root_src_path = build_zig_basename, |
| 2706 | .namespace_hash = undefined, | |
| 2707 | 2703 | }; |
| 2708 | 2704 | try root_pkg.addAndAdopt(arena, "@build", &build_pkg); |
| 2709 | 2705 |
src/test.zig-1| ... | ... | @@ -611,7 +611,6 @@ pub const TestContext = struct { |
| 611 | 611 | var root_pkg: Package = .{ |
| 612 | 612 | .root_src_directory = .{ .path = tmp_dir_path, .handle = tmp.dir }, |
| 613 | 613 | .root_src_path = tmp_src_path, |
| 614 | .namespace_hash = Package.root_namespace_hash, | |
| 615 | 614 | }; |
| 616 | 615 | defer root_pkg.table.deinit(allocator); |
| 617 | 616 |