Skip to content

Commit 6b05cb6

Browse files
authored
Merge pull request #1605 from zigtools/nullptrdevs/var-never-mutated
Zig AstGen changes, unnecessary use of 'var'
2 parents e89b712 + bdc762a commit 6b05cb6

31 files changed

+738
-100
lines changed

build.zig

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ pub fn build(b: *std.build.Builder) !void {
9696
const exe_options_module = exe_options.createModule();
9797
const known_folders_module = b.dependency("known_folders", .{}).module("known-folders");
9898
const diffz_module = b.dependency("diffz", .{}).module("diffz");
99-
const binned_allocator_module = b.dependency("binned_allocator", .{}).module("binned_allocator");
10099

101100
const exe = b.addExecutable(.{
102101
.name = "zls",
@@ -111,7 +110,6 @@ pub fn build(b: *std.build.Builder) !void {
111110
exe.addModule("build_options", exe_options_module);
112111
exe.addModule("known-folders", known_folders_module);
113112
exe.addModule("diffz", diffz_module);
114-
exe.addModule("binned_allocator", binned_allocator_module);
115113

116114
if (enable_tracy) {
117115
const client_cpp = "src/tracy/public/TracyClient.cpp";

build.zig.zon

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,12 @@
55

66
.dependencies = .{
77
.known_folders = .{
8-
.url = "https://github.com/ziglibs/known-folders/archive/a564f582122326328dad6b59209d070d57c4e6ae.tar.gz",
9-
.hash = "1220bb12c9bfe291eed1afe6a2070c7c39918ab1979f24a281bba39dfb23f5bcd544",
8+
.url = "https://github.com/ziglibs/known-folders/archive/855473062efac722624737f1adc56f9c0dd92017.tar.gz",
9+
.hash = "1220f9d9dd88b1352b1a2bde4a96f547a1591d66ad0a9d76854d0c2c7fa59eef2508",
1010
},
1111
.diffz = .{
12-
.url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz",
13-
.hash = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864",
14-
},
15-
.binned_allocator = .{
16-
// upstream: https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904
17-
.url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz",
18-
.hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5",
12+
.url = "https://github.com/ziglibs/diffz/archive/86f5435f63961dcdba8b76e47b44e2381671fb09.tar.gz",
13+
.hash = "122014b1776beda990cdc7bdbecc6960bdce9eb762d6dc7cc6664517f171becc17dd",
1914
},
2015
},
2116
.paths = .{""},

deps.nix

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,6 @@
33
{ linkFarm, fetchzip }:
44

55
linkFarm "zig-packages" [
6-
{
7-
name = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5";
8-
path = fetchzip {
9-
url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz";
10-
hash = "sha256-m/kr4kmkG2rLkAj5YwvM0HmXTd+chAiQHzYK6ozpWlw=";
11-
};
12-
}
136
{
147
name = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864";
158
path = fetchzip {

src/ComptimeInterpreter.zig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,9 @@ pub fn interpret(
215215
continue;
216216
};
217217

218-
var init_value = try (try interpreter.interpret(container_field.ast.type_expr, container_namespace, .{})).getValue();
218+
const init_value = try (try interpreter.interpret(container_field.ast.type_expr, container_namespace, .{})).getValue();
219219

220-
var default_value = if (container_field.ast.value_expr == 0)
220+
const default_value = if (container_field.ast.value_expr == 0)
221221
Index.none
222222
else
223223
(try (try interpreter.interpret(container_field.ast.value_expr, container_namespace, .{})).getValue()).index; // TODO check ty
@@ -443,7 +443,7 @@ pub fn interpret(
443443
const field_name = tree.tokenSlice(data[node_idx].rhs);
444444

445445
var ir = try interpreter.interpret(data[node_idx].lhs, namespace, options);
446-
var ir_value = try ir.getValue();
446+
const ir_value = try ir.getValue();
447447

448448
const val_index = ir_value.index;
449449
const val = interpreter.ip.indexToKey(val_index);
@@ -883,7 +883,7 @@ pub fn interpret(
883883
} };
884884
}
885885

886-
var import_uri = (try interpreter.document_store.uriFromImportStr(interpreter.allocator, interpreter.getHandle().*, import_str[1 .. import_str.len - 1])) orelse return error.ImportFailure;
886+
const import_uri = (try interpreter.document_store.uriFromImportStr(interpreter.allocator, interpreter.getHandle().*, import_str[1 .. import_str.len - 1])) orelse return error.ImportFailure;
887887
defer interpreter.allocator.free(import_uri);
888888

889889
const import_handle = interpreter.document_store.getOrLoadHandle(import_uri) orelse return error.ImportFailure;
@@ -1248,7 +1248,7 @@ pub fn call(
12481248
var arg_index: usize = 0;
12491249
while (ast.nextFnParam(&arg_it)) |param| {
12501250
if (arg_index >= arguments.len) return error.MissingArguments;
1251-
var tex = try (try interpreter.interpret(param.type_expr, fn_namespace, options)).getValue();
1251+
const tex = try (try interpreter.interpret(param.type_expr, fn_namespace, options)).getValue();
12521252
const tex_ty = interpreter.ip.indexToKey(tex.index).typeOf();
12531253
if (tex_ty != .type_type) {
12541254
try interpreter.recordError(

src/DocumentScope.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ noinline fn walkContainerDecl(
678678
const doc = try Analyser.getDocComments(allocator, tree, decl);
679679
errdefer if (doc) |d| allocator.free(d);
680680
// TODO: Fix allocation; just store indices
681-
var gop_res = try context.doc_scope.enum_completions.getOrPut(allocator, .{
681+
const gop_res = try context.doc_scope.enum_completions.getOrPut(allocator, .{
682682
.label = name,
683683
.kind = .EnumMember,
684684
.insertText = name,

src/DocumentStore.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ pub const Handle = struct {
409409
var old_analysis_errors = self.analysis_errors;
410410
var old_document_scope = if (old_status.has_document_scope) self.impl.document_scope else null;
411411
var old_zir = if (old_status.has_zir) self.impl.zir else null;
412-
var old_comptime_interpreter = if (old_status.has_comptime_interpreter) self.impl.comptime_interpreter else null;
412+
const old_comptime_interpreter = if (old_status.has_comptime_interpreter) self.impl.comptime_interpreter else null;
413413

414414
self.tree = new_tree;
415415
self.import_uris = .{};
@@ -877,7 +877,7 @@ pub fn loadBuildConfiguration(self: *DocumentStore, build_file_uri: Uri) !std.js
877877
self.allocator.free(args);
878878
}
879879

880-
var zig_run_result = blk: {
880+
const zig_run_result = blk: {
881881
const tracy_zone2 = tracy.trace(@src());
882882
defer tracy_zone2.end();
883883
break :blk try std.process.Child.run(.{
@@ -1194,7 +1194,7 @@ fn collectCIncludes(allocator: std.mem.Allocator, tree: Ast) error{OutOfMemory}!
11941194
const tracy_zone = tracy.trace(@src());
11951195
defer tracy_zone.end();
11961196

1197-
var cimport_nodes = try analysis.collectCImportNodes(allocator, tree);
1197+
const cimport_nodes = try analysis.collectCImportNodes(allocator, tree);
11981198
defer allocator.free(cimport_nodes);
11991199

12001200
var sources = std.MultiArrayList(CImportHandle){};

src/Server.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,7 @@ fn codeActionHandler(server: *Server, arena: std.mem.Allocator, request: types.C
16061606
}
16071607

16081608
const Result = getRequestMetadata("textDocument/codeAction").?.Result;
1609-
var result = try arena.alloc(std.meta.Child(std.meta.Child(Result)), actions.items.len);
1609+
const result = try arena.alloc(std.meta.Child(std.meta.Child(Result)), actions.items.len);
16101610
for (actions.items, result) |action, *out| {
16111611
out.* = .{ .CodeAction = action };
16121612
}

src/ZigCompileServer.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub const Options = struct {
1515
};
1616

1717
pub fn init(options: Options) Client {
18-
var s: Client = .{
18+
const s: Client = .{
1919
.in = options.in,
2020
.out = options.out,
2121
.pooler = std.io.poll(options.gpa, StreamEnum, .{ .in = options.in }),

src/analyser/InternPool.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,14 +1836,14 @@ pub fn resolvePeerTypes(ip: *InternPool, gpa: Allocator, types: []const Index, t
18361836

18371837
var arena_allocator = std.heap.ArenaAllocator.init(gpa);
18381838
defer arena_allocator.deinit();
1839-
var arena = arena_allocator.allocator();
1839+
const arena = arena_allocator.allocator();
18401840

18411841
var chosen = types[0];
18421842
// If this is non-null then it does the following thing, depending on the chosen zigTypeTag().
18431843
// * ErrorSet: this is an override
18441844
// * ErrorUnion: this is an override of the error set only
18451845
// * other: at the end we make an ErrorUnion with the other thing and this
1846-
var err_set_ty: Index = Index.none;
1846+
const err_set_ty: Index = Index.none;
18471847
var any_are_null = false;
18481848
var seen_const = false;
18491849
var convert_to_slice = false;

src/analyser/encoding.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pub fn decode(extra: *[]const u8, comptime T: type) T {
147147
.Array => |info| blk: {
148148
var array: T = undefined;
149149
var i: usize = 0;
150-
while (i < info.len) {
150+
while (i < info.len) : (i += 1) {
151151
array[i] = decode(extra, info.child);
152152
}
153153
break :blk array;

0 commit comments

Comments
 (0)