From 6c718a59c4050885ca4910c534e4f4976628a5c1 Mon Sep 17 00:00:00 2001 From: Alexandros Naskos Date: Thu, 18 Jun 2020 03:23:56 +0300 Subject: [PATCH] Fixed infinite loop --- src/analysis.zig | 4 ++++ src/semantic_tokens.zig | 33 ++++++++++++++++++--------------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/analysis.zig b/src/analysis.zig index 0f3413b..4b27967 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -580,6 +580,10 @@ fn resolveTypeOfNodeInternal( } if (try lookupSymbolGlobal(store, arena, handle, handle.tree.getNodeSource(node), handle.tree.token_locs[node.firstToken()].start)) |child| { + switch(child.decl.*) { + .ast_node => |n| if (n == node) return null, + else => {}, + } return try child.resolveType(store, arena, bound_type_params); } return null; diff --git a/src/semantic_tokens.zig b/src/semantic_tokens.zig index a75b10e..f37eb77 100644 --- a/src/semantic_tokens.zig +++ b/src/semantic_tokens.zig @@ -254,21 +254,24 @@ fn writeNodeTokens(builder: *Builder, arena: *std.heap.ArenaAllocator, store: *D return try writeToken(builder, node.firstToken(), .parameter); } // TODO: Clean this up. - // @TODO This stack overflows - // var bound_type_params = analysis.BoundTypeParams.init(&arena.allocator); - // if (try child.resolveType(store, arena, &bound_type_params)) |decl_type| { - // if (decl_type.type.is_type_val) { - // const tok_type = if (decl_type.isStructType()) - // .@"struct" - // else if (decl_type.isEnumType()) - // .@"enum" - // else if (decl_type.isUnionType()) - // .@"union" - // else - // TokenType.type; - // return try writeTokenMod(builder, node.firstToken(), tok_type, .{}); - // } - // } + var bound_type_params = analysis.BoundTypeParams.init(&arena.allocator); + + var resolve_type_frame = try arena.child_allocator.alignedAlloc(u8, std.Target.stack_align, @sizeOf(@Frame(analysis.DeclWithHandle.resolveType))); + defer arena.child_allocator.free(resolve_type_frame); + + if (try child.resolveType(store, arena, &bound_type_params)) |decl_type| { + if (decl_type.type.is_type_val) { + const tok_type = if (decl_type.isStructType()) + .@"struct" + else if (decl_type.isEnumType()) + .@"enum" + else if (decl_type.isUnionType()) + .@"union" + else + TokenType.type; + return try writeTokenMod(builder, node.firstToken(), tok_type, .{}); + } + } } }, .FnProto => {