From 6eee43af2fdb620a1fc202efbeaa6b5304f6afd0 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Sun, 12 Jul 2020 22:12:09 +0300 Subject: [PATCH] Fixed build on latest zig nightly --- src/analysis.zig | 26 +++++++++++++------------- src/debug_allocator.zig | 5 ++--- src/header.zig | 6 +++--- src/main.zig | 6 +++--- src/references.zig | 16 ++++++++-------- src/requests.zig | 4 ++-- src/semantic_tokens.zig | 6 +++--- src/types.zig | 14 +++++++------- 8 files changed, 41 insertions(+), 42 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index a1968e8..1d1478b 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -102,7 +102,7 @@ pub fn getFunctionSnippet(allocator: *std.mem.Allocator, tree: *ast.Tree, func: switch (param.param_type) { .var_args => try buffer.appendSlice("..."), - .var_type => try buffer.appendSlice("var"), + .any_type => try buffer.appendSlice("anytype"), .type_expr => |type_expr| { var curr_tok = type_expr.firstToken(); var end_tok = type_expr.lastToken(); @@ -156,7 +156,7 @@ pub fn isTypeFunction(tree: *ast.Tree, func: *ast.Node.FnProto) bool { pub fn isGenericFunction(tree: *ast.Tree, func: *ast.Node.FnProto) bool { for (func.paramsConst()) |param| { - if (param.param_type == .var_type or param.comptime_token != null) { + if (param.param_type == .any_type or param.comptime_token != null) { return true; } } @@ -1351,7 +1351,7 @@ pub fn documentPositionContext(arena: *std.heap.ArenaAllocator, document: types. fn addOutlineNodes(allocator: *std.mem.Allocator, tree: *ast.Tree, child: *ast.Node, context: *GetDocumentSymbolsContext) anyerror!void { switch (child.id) { - .StringLiteral, .IntegerLiteral, .BuiltinCall, .Call, .Identifier, .InfixOp, .PrefixOp, .SuffixOp, .ControlFlowExpression, .ArrayInitializerDot, .SwitchElse, .SwitchCase, .For, .EnumLiteral, .PointerIndexPayload, .StructInitializerDot, .PointerPayload, .While, .Switch, .Else, .BoolLiteral, .NullLiteral, .Defer, .StructInitializer, .FieldInitializer, .If, .MultilineStringLiteral, .UndefinedLiteral, .VarType, .Block, .ErrorSetDecl => return, + .StringLiteral, .IntegerLiteral, .BuiltinCall, .Call, .Identifier, .InfixOp, .PrefixOp, .SuffixOp, .ControlFlowExpression, .ArrayInitializerDot, .SwitchElse, .SwitchCase, .For, .EnumLiteral, .PointerIndexPayload, .StructInitializerDot, .PointerPayload, .While, .Switch, .Else, .BoolLiteral, .NullLiteral, .Defer, .StructInitializer, .FieldInitializer, .If, .MultilineStringLiteral, .UndefinedLiteral, .AnyType, .Block, .ErrorSetDecl => return, .ContainerDecl => { const decl = child.cast(ast.Node.ContainerDecl).?; @@ -1600,8 +1600,8 @@ fn iterateSymbolsContainerInternal( arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, orig_handle: *DocumentStore.Handle, - comptime callback: var, - context: var, + comptime callback: anytype, + context: anytype, instance_access: bool, use_trail: *std.ArrayList(*ast.Node.Use), ) error{OutOfMemory}!void { @@ -1651,8 +1651,8 @@ pub fn iterateSymbolsContainer( arena: *std.heap.ArenaAllocator, container_handle: NodeWithHandle, orig_handle: *DocumentStore.Handle, - comptime callback: var, - context: var, + comptime callback: anytype, + context: anytype, instance_access: bool, ) error{OutOfMemory}!void { var use_trail = std.ArrayList(*ast.Node.Use).init(&arena.allocator); @@ -1662,8 +1662,8 @@ pub fn iterateSymbolsContainer( pub fn iterateLabels( handle: *DocumentStore.Handle, source_index: usize, - comptime callback: var, - context: var, + comptime callback: anytype, + context: anytype, ) error{OutOfMemory}!void { for (handle.document_scope.scopes) |scope| { if (source_index >= scope.range.start and source_index < scope.range.end) { @@ -1685,8 +1685,8 @@ fn iterateSymbolsGlobalInternal( arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, source_index: usize, - comptime callback: var, - context: var, + comptime callback: anytype, + context: anytype, use_trail: *std.ArrayList(*ast.Node.Use), ) error{OutOfMemory}!void { for (handle.document_scope.scopes) |scope| { @@ -1720,8 +1720,8 @@ pub fn iterateSymbolsGlobal( arena: *std.heap.ArenaAllocator, handle: *DocumentStore.Handle, source_index: usize, - comptime callback: var, - context: var, + comptime callback: anytype, + context: anytype, ) error{OutOfMemory}!void { var use_trail = std.ArrayList(*ast.Node.Use).init(&arena.allocator); return try iterateSymbolsGlobalInternal(store, arena, handle, source_index, callback, context, &use_trail); diff --git a/src/debug_allocator.zig b/src/debug_allocator.zig index 494dcb4..1ee6317 100644 --- a/src/debug_allocator.zig +++ b/src/debug_allocator.zig @@ -41,7 +41,7 @@ pub const AllocationInfo = struct { self: AllocationInfo, comptime fmt: []const u8, options: std.fmt.FormatOptions, - out_stream: var, + out_stream: anytype, ) !void { @setEvalBranchQuota(2000); @@ -174,8 +174,7 @@ pub fn printRemainingStackTraces(self: DebugAllocator) void { std.debug.print( \\{} allocations - stack traces follow \\------------------------------------ - , - .{self.allocation_strack_addresses.count()}); + , .{self.allocation_strack_addresses.count()}); var it = self.allocation_strack_addresses.iterator(); var idx: usize = 1; while (it.next()) |entry| : (idx += 1) { diff --git a/src/header.zig b/src/header.zig index 3483e24..13b8b25 100644 --- a/src/header.zig +++ b/src/header.zig @@ -12,7 +12,7 @@ const RequestHeader = struct { } }; -pub fn readRequestHeader(allocator: *mem.Allocator, instream: var) !RequestHeader { +pub fn readRequestHeader(allocator: *mem.Allocator, instream: anytype) !RequestHeader { var r = RequestHeader{ .content_length = undefined, .content_type = null, @@ -26,8 +26,8 @@ pub fn readRequestHeader(allocator: *mem.Allocator, instream: var) !RequestHeade if (header.len == 0 or header[header.len - 1] != '\r') return error.MissingCarriageReturn; if (header.len == 1) break; - const header_name = header[0..mem.indexOf(u8, header, ": ") orelse return error.MissingColon]; - const header_value = header[header_name.len + 2..header.len-1]; + const header_name = header[0 .. mem.indexOf(u8, header, ": ") orelse return error.MissingColon]; + const header_value = header[header_name.len + 2 .. header.len - 1]; if (mem.eql(u8, header_name, "Content-Length")) { if (header_value.len == 0) return error.MissingHeaderValue; r.content_length = std.fmt.parseInt(usize, header_value, 10) catch return error.InvalidContentLength; diff --git a/src/main.zig b/src/main.zig index d738259..e95b4a1 100644 --- a/src/main.zig +++ b/src/main.zig @@ -23,7 +23,7 @@ pub fn log( comptime message_level: std.log.Level, comptime scope: @Type(.EnumLiteral), comptime format: []const u8, - args: var, + args: anytype, ) void { var arena = std.heap.ArenaAllocator.init(allocator); defer arena.deinit(); @@ -119,7 +119,7 @@ const no_semantic_tokens_response = ; /// Sends a request or response -fn send(arena: *std.heap.ArenaAllocator, reqOrRes: var) !void { +fn send(arena: *std.heap.ArenaAllocator, reqOrRes: anytype) !void { var arr = std.ArrayList(u8).init(&arena.allocator); try std.json.stringify(reqOrRes, .{}, arr.writer()); @@ -1381,7 +1381,7 @@ fn referencesHandler(arena: *std.heap.ArenaAllocator, id: types.RequestId, req: } // Needed for the hack seen below. -fn extractErr(val: var) anyerror { +fn extractErr(val: anytype) anyerror { val catch |e| return e; return error.HackDone; } diff --git a/src/references.zig b/src/references.zig index 46499e2..f6ec9c3 100644 --- a/src/references.zig +++ b/src/references.zig @@ -10,8 +10,8 @@ fn tokenReference( handle: *DocumentStore.Handle, tok: ast.TokenIndex, encoding: offsets.Encoding, - context: var, - comptime handler: var, + context: anytype, + comptime handler: anytype, ) !void { const loc = offsets.tokenRelativeLocation(handle.tree, 0, tok, encoding) catch return; try handler(context, types.Location{ @@ -34,8 +34,8 @@ pub fn labelReferences( decl: analysis.DeclWithHandle, encoding: offsets.Encoding, include_decl: bool, - context: var, - comptime handler: var, + context: anytype, + comptime handler: anytype, ) !void { std.debug.assert(decl.decl.* == .label_decl); const handle = decl.handle; @@ -69,8 +69,8 @@ fn symbolReferencesInternal( node_handle: analysis.NodeWithHandle, decl: analysis.DeclWithHandle, encoding: offsets.Encoding, - context: var, - comptime handler: var, + context: anytype, + comptime handler: anytype, ) error{OutOfMemory}!void { const node = node_handle.node; const handle = node_handle.handle; @@ -354,8 +354,8 @@ pub fn symbolReferences( decl_handle: analysis.DeclWithHandle, encoding: offsets.Encoding, include_decl: bool, - context: var, - comptime handler: var, + context: anytype, + comptime handler: anytype, ) !void { std.debug.assert(decl_handle.decl.* != .label_decl); const curr_handle = decl_handle.handle; diff --git a/src/requests.zig b/src/requests.zig index 0bfd646..26b98cb 100644 --- a/src/requests.zig +++ b/src/requests.zig @@ -14,7 +14,7 @@ fn Default(comptime T: type, comptime default_value: T) type { }; } -fn Transform(comptime Original: type, comptime transform_fn: var) type { +fn Transform(comptime Original: type, comptime transform_fn: anytype) type { return struct { pub const original_type = Original; pub const transform = transform_fn; @@ -23,7 +23,7 @@ fn Transform(comptime Original: type, comptime transform_fn: var) type { }; } -inline fn fromDynamicTreeInternal(arena: *std.heap.ArenaAllocator, value: std.json.Value, out: var) error{ MalformedJson, OutOfMemory }!void { +inline fn fromDynamicTreeInternal(arena: *std.heap.ArenaAllocator, value: std.json.Value, out: anytype) error{ MalformedJson, OutOfMemory }!void { const T = comptime std.meta.Child(@TypeOf(out)); if (comptime std.meta.trait.is(.Struct)(T)) { diff --git a/src/semantic_tokens.zig b/src/semantic_tokens.zig index 9dda7d0..1e274b4 100644 --- a/src/semantic_tokens.zig +++ b/src/semantic_tokens.zig @@ -198,7 +198,7 @@ fn writeContainerField( store: *DocumentStore, container_field: *ast.Node.ContainerField, field_token_type: ?TokenType, - child_frame: var, + child_frame: anytype, ) !void { if (container_field.doc_comments) |docs| try writeDocComments(builder, builder.handle.tree, docs); try writeToken(builder, container_field.comptime_token, .keyword); @@ -356,7 +356,7 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D try writeToken(builder, param_decl.comptime_token, .keyword); try writeTokenMod(builder, param_decl.name_token, .parameter, .{ .definition = true }); switch (param_decl.param_type) { - .var_type => |var_node| try writeToken(builder, var_node.firstToken(), .type), + .any_type => |var_node| try writeToken(builder, var_node.firstToken(), .type), .var_args => |var_args_tok| try writeToken(builder, var_args_tok, .operator), .type_expr => |type_expr| try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, type_expr }), } @@ -708,7 +708,7 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D try await @asyncCall(child_frame, {}, writeNodeTokens, .{ builder, arena, store, asm_expr.template }); // TODO Inputs, outputs. }, - .VarType => { + .AnyType => { try writeToken(builder, node.firstToken(), .type); }, .TestDecl => { diff --git a/src/types.zig b/src/types.zig index d6a12c0..4944f1e 100644 --- a/src/types.zig +++ b/src/types.zig @@ -97,7 +97,7 @@ pub const MessageType = enum(Integer) { pub fn jsonStringify( value: MessageType, options: json.StringifyOptions, - out_stream: var, + out_stream: anytype, ) !void { try json.stringify(@enumToInt(value), options, out_stream); } @@ -117,7 +117,7 @@ pub const DiagnosticSeverity = enum(Integer) { pub fn jsonStringify( value: DiagnosticSeverity, options: json.StringifyOptions, - out_stream: var, + out_stream: anytype, ) !void { try json.stringify(@enumToInt(value), options, out_stream); } @@ -149,7 +149,7 @@ pub const WorkspaceEdit = struct { pub fn jsonStringify( self: WorkspaceEdit, options: std.json.StringifyOptions, - writer: var, + writer: anytype, ) @TypeOf(writer).Error!void { try writer.writeByte('{'); if (self.changes) |changes| { @@ -182,7 +182,7 @@ pub const MarkupKind = enum(u1) { pub fn jsonStringify( value: MarkupKind, options: json.StringifyOptions, - out_stream: var, + out_stream: anytype, ) !void { const str = switch (value) { .PlainText => "plaintext", @@ -249,7 +249,7 @@ pub const CompletionItemKind = enum(Integer) { pub fn jsonStringify( value: CompletionItemKind, options: json.StringifyOptions, - out_stream: var, + out_stream: anytype, ) !void { try json.stringify(@enumToInt(value), options, out_stream); } @@ -262,7 +262,7 @@ pub const InsertTextFormat = enum(Integer) { pub fn jsonStringify( value: InsertTextFormat, options: json.StringifyOptions, - out_stream: var, + out_stream: anytype, ) !void { try json.stringify(@enumToInt(value), options, out_stream); } @@ -311,7 +311,7 @@ const SymbolKind = enum { pub fn jsonStringify( value: SymbolKind, options: json.StringifyOptions, - out_stream: var, + out_stream: anytype, ) !void { try json.stringify(@enumToInt(value), options, out_stream); }