diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2025-08-05 16:24:28 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-05 16:24:28 -0700 |
| commit | d8cecffe314230f1ff42391be98622ac8098833c (patch) | |
| tree | 791ccaa082bd52364d68a1aeb630747a8fa69f90 /src | |
| parent | 3914eaf3571949718bcd986ab8129b3c9f39b1d0 (diff) | |
| parent | 8c11ada66caa011523e5c1019f9bb23c2db89231 (diff) | |
| download | zig-d8cecffe314230f1ff42391be98622ac8098833c.tar.gz zig-d8cecffe314230f1ff42391be98622ac8098833c.zip | |
Merge pull request #24699 from ziglang/bounded
remove RingBuffer; remove BoundedArray; use `@memmove`
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 18 | ||||
| -rw-r--r-- | src/Sema.zig | 6 | ||||
| -rw-r--r-- | src/Zcu.zig | 11 | ||||
| -rw-r--r-- | src/Zcu/PerThread.zig | 5 |
4 files changed, 26 insertions, 14 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 419c56019f..4024e0a49e 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -2103,6 +2103,8 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil .local_zir_cache = local_zir_cache, .error_limit = error_limit, .llvm_object = null, + .analysis_roots_buffer = undefined, + .analysis_roots_len = 0, }; try zcu.init(options.thread_pool.getIdCount()); break :blk zcu; @@ -2933,22 +2935,26 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { try comp.appendFileSystemInput(embed_file.path); } - zcu.analysis_roots.clear(); + zcu.analysis_roots_len = 0; - zcu.analysis_roots.appendAssumeCapacity(zcu.std_mod); + zcu.analysis_roots_buffer[zcu.analysis_roots_len] = zcu.std_mod; + zcu.analysis_roots_len += 1; // Normally we rely on importing std to in turn import the root source file in the start code. // However, the main module is distinct from the root module in tests, so that won't happen there. if (comp.config.is_test and zcu.main_mod != zcu.std_mod) { - zcu.analysis_roots.appendAssumeCapacity(zcu.main_mod); + zcu.analysis_roots_buffer[zcu.analysis_roots_len] = zcu.main_mod; + zcu.analysis_roots_len += 1; } if (zcu.root_mod.deps.get("compiler_rt")) |compiler_rt_mod| { - zcu.analysis_roots.appendAssumeCapacity(compiler_rt_mod); + zcu.analysis_roots_buffer[zcu.analysis_roots_len] = compiler_rt_mod; + zcu.analysis_roots_len += 1; } if (zcu.root_mod.deps.get("ubsan_rt")) |ubsan_rt_mod| { - zcu.analysis_roots.appendAssumeCapacity(ubsan_rt_mod); + zcu.analysis_roots_buffer[zcu.analysis_roots_len] = ubsan_rt_mod; + zcu.analysis_roots_len += 1; } } @@ -4745,7 +4751,7 @@ fn performAllTheWork( try zcu.flushRetryableFailures(); // It's analysis time! Queue up our initial analysis. - for (zcu.analysis_roots.slice()) |mod| { + for (zcu.analysisRoots()) |mod| { try comp.queueJob(.{ .analyze_mod = mod }); } diff --git a/src/Sema.zig b/src/Sema.zig index 29c8daa8b3..5816990eb2 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -2631,7 +2631,7 @@ fn reparentOwnedErrorMsg( const orig_notes = msg.notes.len; msg.notes = try sema.gpa.realloc(msg.notes, orig_notes + 1); - std.mem.copyBackwards(Zcu.ErrorMsg, msg.notes[1..], msg.notes[0..orig_notes]); + @memmove(msg.notes[1..][0..orig_notes], msg.notes[0..orig_notes]); msg.notes[0] = .{ .src_loc = msg.src_loc, .msg = msg.msg, @@ -14464,8 +14464,8 @@ fn analyzeTupleMul( } } for (0..factor) |i| { - mem.copyForwards(InternPool.Index, types[tuple_len * i ..], types[0..tuple_len]); - mem.copyForwards(InternPool.Index, values[tuple_len * i ..], values[0..tuple_len]); + @memmove(types[tuple_len * i ..][0..tuple_len], types[0..tuple_len]); + @memmove(values[tuple_len * i ..][0..tuple_len], values[0..tuple_len]); } break :rs runtime_src; }; diff --git a/src/Zcu.zig b/src/Zcu.zig index c444d57bf6..d77a6edc31 100644 --- a/src/Zcu.zig +++ b/src/Zcu.zig @@ -268,7 +268,8 @@ nav_val_analysis_queued: std.AutoArrayHashMapUnmanaged(InternPool.Nav.Index, voi /// These are the modules which we initially queue for analysis in `Compilation.update`. /// `resolveReferences` will use these as the root of its reachability traversal. -analysis_roots: std.BoundedArray(*Package.Module, 4) = .{}, +analysis_roots_buffer: [4]*Package.Module, +analysis_roots_len: usize = 0, /// This is the cached result of `Zcu.resolveReferences`. It is computed on-demand, and /// reset to `null` when any semantic analysis occurs (since this invalidates the data). /// Allocated into `gpa`. @@ -4013,8 +4014,8 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv // This is not a sufficient size, but a lower bound. try result.ensureTotalCapacity(gpa, @intCast(zcu.reference_table.count())); - try type_queue.ensureTotalCapacity(gpa, zcu.analysis_roots.len); - for (zcu.analysis_roots.slice()) |mod| { + try type_queue.ensureTotalCapacity(gpa, zcu.analysis_roots_len); + for (zcu.analysisRoots()) |mod| { const file = zcu.module_roots.get(mod).?.unwrap() orelse continue; const root_ty = zcu.fileRootType(file); if (root_ty == .none) continue; @@ -4202,6 +4203,10 @@ fn resolveReferencesInner(zcu: *Zcu) !std.AutoHashMapUnmanaged(AnalUnit, ?Resolv return result; } +pub fn analysisRoots(zcu: *Zcu) []*Package.Module { + return zcu.analysis_roots_buffer[0..zcu.analysis_roots_len]; +} + pub fn fileByIndex(zcu: *const Zcu, file_index: File.Index) *File { return zcu.intern_pool.filePtr(file_index); } diff --git a/src/Zcu/PerThread.zig b/src/Zcu/PerThread.zig index de4be438f5..79ad9f14e9 100644 --- a/src/Zcu/PerThread.zig +++ b/src/Zcu/PerThread.zig @@ -2116,8 +2116,9 @@ pub fn computeAliveFiles(pt: Zcu.PerThread) Allocator.Error!bool { // multi-threaded environment (where things like file indices could differ between compiler runs). // The roots of our file liveness analysis will be the analysis roots. - try zcu.alive_files.ensureTotalCapacity(gpa, zcu.analysis_roots.len); - for (zcu.analysis_roots.slice()) |mod| { + const analysis_roots = zcu.analysisRoots(); + try zcu.alive_files.ensureTotalCapacity(gpa, analysis_roots.len); + for (analysis_roots) |mod| { const file_index = zcu.module_roots.get(mod).?.unwrap() orelse continue; const file = zcu.fileByIndex(file_index); |
