Skip to content

Commit

Permalink
fix stack overflow due to cyclically anytype resolution (#1365)
Browse files Browse the repository at this point in the history
  • Loading branch information
Techatrix authored Jul 30, 2023
1 parent f220701 commit f71c42b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/analysis.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2611,6 +2611,12 @@ pub const DeclWithHandle = struct {
.param_payload => |pay| {
// handle anytype
if (pay.param.type_expr == 0) {
// protection against recursive callsite resolution
const node_with_uri = NodeWithUri{ .node = pay.func, .uri = self.handle.uri };
const gop_resolved = try analyser.resolved_nodes.getOrPut(analyser.gpa, node_with_uri);
if (gop_resolved.found_existing) return gop_resolved.value_ptr.*;
gop_resolved.value_ptr.* = null;

var func_decl = Declaration{ .ast_node = pay.func };

var func_buf: [1]Ast.Node.Index = undefined;
Expand All @@ -2630,7 +2636,6 @@ pub const DeclWithHandle = struct {

// TODO: Set `workspace` to true; current problems
// - we gather dependencies, not dependents
// - stack overflow due to cyclically anytype resolution(?)

var possible = std.ArrayListUnmanaged(Type.EitherEntry){};
var deduplicator = TypeWithHandle.Deduplicator{};
Expand Down Expand Up @@ -2668,7 +2673,9 @@ pub const DeclWithHandle = struct {
}
}

return TypeWithHandle.fromEither(analyser.gpa, try possible.toOwnedSlice(analyser.arena.allocator()), self.handle);
const maybe_type_handle = try TypeWithHandle.fromEither(analyser.gpa, try possible.toOwnedSlice(analyser.arena.allocator()), self.handle);
if (maybe_type_handle) |type_handle| analyser.resolved_nodes.getPtr(node_with_uri).?.* = type_handle;
return maybe_type_handle;
}

const param_decl = pay.param;
Expand Down

0 comments on commit f71c42b

Please sign in to comment.