Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zig AstGen changes, unnecessary use of 'var' #1605

Merged
merged 8 commits into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ pub fn build(b: *std.build.Builder) !void {
const exe_options_module = exe_options.createModule();
const known_folders_module = b.dependency("known_folders", .{}).module("known-folders");
const diffz_module = b.dependency("diffz", .{}).module("diffz");
const binned_allocator_module = b.dependency("binned_allocator", .{}).module("binned_allocator");

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

if (enable_tracy) {
const client_cpp = "src/tracy/public/TracyClient.cpp";
Expand Down
13 changes: 4 additions & 9 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,12 @@

.dependencies = .{
.known_folders = .{
.url = "https://github.com/ziglibs/known-folders/archive/a564f582122326328dad6b59209d070d57c4e6ae.tar.gz",
.hash = "1220bb12c9bfe291eed1afe6a2070c7c39918ab1979f24a281bba39dfb23f5bcd544",
.url = "https://github.com/ziglibs/known-folders/archive/855473062efac722624737f1adc56f9c0dd92017.tar.gz",
.hash = "1220f9d9dd88b1352b1a2bde4a96f547a1591d66ad0a9d76854d0c2c7fa59eef2508",
},
.diffz = .{
.url = "https://github.com/ziglibs/diffz/archive/90353d401c59e2ca5ed0abe5444c29ad3d7489aa.tar.gz",
.hash = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864",
},
.binned_allocator = .{
// upstream: https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904
.url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz",
.hash = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5",
.url = "https://github.com/ziglibs/diffz/archive/86f5435f63961dcdba8b76e47b44e2381671fb09.tar.gz",
.hash = "122014b1776beda990cdc7bdbecc6960bdce9eb762d6dc7cc6664517f171becc17dd",
},
},
.paths = .{""},
Expand Down
7 changes: 0 additions & 7 deletions deps.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
{ linkFarm, fetchzip }:

linkFarm "zig-packages" [
{
name = "1220363c7e27b2d3f39de6ff6e90f9537a0634199860fea237a55ddb1e1717f5d6a5";
path = fetchzip {
url = "https://gist.github.com/antlilja/8372900fcc09e38d7b0b6bbaddad3904/archive/6c3321e0969ff2463f8335da5601986cf2108690.tar.gz";
hash = "sha256-m/kr4kmkG2rLkAj5YwvM0HmXTd+chAiQHzYK6ozpWlw=";
};
}
{
name = "122089a8247a693cad53beb161bde6c30f71376cd4298798d45b32740c3581405864";
path = fetchzip {
Expand Down
10 changes: 5 additions & 5 deletions src/ComptimeInterpreter.zig
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,9 @@ pub fn interpret(
continue;
};

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

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

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

const val_index = ir_value.index;
const val = interpreter.ip.indexToKey(val_index);
Expand Down Expand Up @@ -883,7 +883,7 @@ pub fn interpret(
} };
}

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

const import_handle = interpreter.document_store.getOrLoadHandle(import_uri) orelse return error.ImportFailure;
Expand Down Expand Up @@ -1248,7 +1248,7 @@ pub fn call(
var arg_index: usize = 0;
while (ast.nextFnParam(&arg_it)) |param| {
if (arg_index >= arguments.len) return error.MissingArguments;
var tex = try (try interpreter.interpret(param.type_expr, fn_namespace, options)).getValue();
const tex = try (try interpreter.interpret(param.type_expr, fn_namespace, options)).getValue();
const tex_ty = interpreter.ip.indexToKey(tex.index).typeOf();
if (tex_ty != .type_type) {
try interpreter.recordError(
Expand Down
2 changes: 1 addition & 1 deletion src/DocumentScope.zig
Original file line number Diff line number Diff line change
Expand Up @@ -678,7 +678,7 @@ noinline fn walkContainerDecl(
const doc = try Analyser.getDocComments(allocator, tree, decl);
errdefer if (doc) |d| allocator.free(d);
// TODO: Fix allocation; just store indices
var gop_res = try context.doc_scope.enum_completions.getOrPut(allocator, .{
const gop_res = try context.doc_scope.enum_completions.getOrPut(allocator, .{
.label = name,
.kind = .EnumMember,
.insertText = name,
Expand Down
6 changes: 3 additions & 3 deletions src/DocumentStore.zig
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ pub const Handle = struct {
var old_analysis_errors = self.analysis_errors;
var old_document_scope = if (old_status.has_document_scope) self.impl.document_scope else null;
var old_zir = if (old_status.has_zir) self.impl.zir else null;
var old_comptime_interpreter = if (old_status.has_comptime_interpreter) self.impl.comptime_interpreter else null;
const old_comptime_interpreter = if (old_status.has_comptime_interpreter) self.impl.comptime_interpreter else null;

self.tree = new_tree;
self.import_uris = .{};
Expand Down Expand Up @@ -877,7 +877,7 @@ pub fn loadBuildConfiguration(self: *DocumentStore, build_file_uri: Uri) !std.js
self.allocator.free(args);
}

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

var cimport_nodes = try analysis.collectCImportNodes(allocator, tree);
const cimport_nodes = try analysis.collectCImportNodes(allocator, tree);
defer allocator.free(cimport_nodes);

var sources = std.MultiArrayList(CImportHandle){};
Expand Down
2 changes: 1 addition & 1 deletion src/Server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1606,7 +1606,7 @@ fn codeActionHandler(server: *Server, arena: std.mem.Allocator, request: types.C
}

const Result = getRequestMetadata("textDocument/codeAction").?.Result;
var result = try arena.alloc(std.meta.Child(std.meta.Child(Result)), actions.items.len);
const result = try arena.alloc(std.meta.Child(std.meta.Child(Result)), actions.items.len);
for (actions.items, result) |action, *out| {
out.* = .{ .CodeAction = action };
}
Expand Down
2 changes: 1 addition & 1 deletion src/ZigCompileServer.zig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub const Options = struct {
};

pub fn init(options: Options) Client {
var s: Client = .{
const s: Client = .{
.in = options.in,
.out = options.out,
.pooler = std.io.poll(options.gpa, StreamEnum, .{ .in = options.in }),
Expand Down
4 changes: 2 additions & 2 deletions src/analyser/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1836,14 +1836,14 @@ pub fn resolvePeerTypes(ip: *InternPool, gpa: Allocator, types: []const Index, t

var arena_allocator = std.heap.ArenaAllocator.init(gpa);
defer arena_allocator.deinit();
var arena = arena_allocator.allocator();
const arena = arena_allocator.allocator();

var chosen = types[0];
// If this is non-null then it does the following thing, depending on the chosen zigTypeTag().
// * ErrorSet: this is an override
// * ErrorUnion: this is an override of the error set only
// * other: at the end we make an ErrorUnion with the other thing and this
var err_set_ty: Index = Index.none;
const err_set_ty: Index = Index.none;
var any_are_null = false;
var seen_const = false;
var convert_to_slice = false;
Expand Down
2 changes: 1 addition & 1 deletion src/analyser/encoding.zig
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn decode(extra: *[]const u8, comptime T: type) T {
.Array => |info| blk: {
var array: T = undefined;
var i: usize = 0;
while (i < info.len) {
while (i < info.len) : (i += 1) {
array[i] = decode(extra, info.child);
}
break :blk array;
Expand Down
12 changes: 6 additions & 6 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ pub fn getFunctionSnippet(
try buf_stream.writeAll("...");
} else if (param.type_expr != 0) {
var curr_token = tree.firstToken(param.type_expr);
var end_token = ast.lastToken(tree, param.type_expr);
const end_token = ast.lastToken(tree, param.type_expr);
while (curr_token <= end_token) : (curr_token += 1) {
const tag = token_tags[curr_token];
const is_comma = tag == .comma;
Expand Down Expand Up @@ -1493,7 +1493,7 @@ fn resolveTypeOfNodeUncached(analyser: *Analyser, node_handle: NodeWithHandle) e
// Need at least one char between the quotes, eg "a"
if (field_name.len < 2) return null;

var lhs = (try analyser.resolveTypeOfNodeInternal(.{
const lhs = (try analyser.resolveTypeOfNodeInternal(.{
.node = params[0],
.handle = handle,
})) orelse return null;
Expand Down Expand Up @@ -2396,10 +2396,10 @@ pub fn getFieldAccessType(
const curr_handle = if (current_type == null) handle else current_type.?.handle;
if (std.mem.eql(u8, tokenizer.buffer[tok.loc.start..tok.loc.end], "@import")) {
if (tokenizer.next().tag != .l_paren) return null;
var import_str_tok = tokenizer.next(); // should be the .string_literal
const import_str_tok = tokenizer.next(); // should be the .string_literal
if (import_str_tok.tag != .string_literal) return null;
if (import_str_tok.loc.end - import_str_tok.loc.start < 2) return null;
var import_str = offsets.locToSlice(tokenizer.buffer, .{
const import_str = offsets.locToSlice(tokenizer.buffer, .{
.start = import_str_tok.loc.start + 1,
.end = import_str_tok.loc.end - 1,
});
Expand Down Expand Up @@ -2563,7 +2563,7 @@ pub fn getPositionContext(

var line_loc = if (!lookahead) offsets.lineLocAtIndex(text, new_index) else offsets.lineLocUntilIndex(text, new_index);

var line = offsets.locToSlice(text, line_loc);
const line = offsets.locToSlice(text, line_loc);
if (std.mem.startsWith(u8, std.mem.trimLeft(u8, line, " \t"), "//")) return .comment;

// Check if the (trimmed) line starts with a '.', ie a continuation
Expand Down Expand Up @@ -2742,7 +2742,7 @@ pub fn getPositionContext(

if (line.len == 0) return .empty;

var held_line = try allocator.dupeZ(u8, offsets.locToSlice(text, line_loc));
const held_line = try allocator.dupeZ(u8, offsets.locToSlice(text, line_loc));
defer allocator.free(held_line);

switch (line[0]) {
Expand Down
2 changes: 1 addition & 1 deletion src/ast.zig
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ pub fn lastToken(tree: Ast, node: Ast.Node.Index) Ast.TokenIndex {
const token = lastToken(tree, datas[n].lhs) + 3; // rparen, lbrace, rbrace
return end_offset + (findMatchingRBrace(tree, token) orelse token);
} else {
var token = lastToken(tree, tree.extra_data[cases.end - 1]) + 1; // for the rbrace
const token = lastToken(tree, tree.extra_data[cases.end - 1]) + 1; // for the rbrace
return end_offset + (findMatchingRBrace(tree, token) orelse token);
}
},
Expand Down
Loading