bug hunting

This commit is contained in:
Techatrix 2023-01-24 22:07:19 +01:00
parent 05ad3294f1
commit b09c317ae7
5 changed files with 27 additions and 14 deletions

View File

@ -46,15 +46,19 @@ pub fn recordError(
comptime fmt: []const u8,
args: anytype,
) error{OutOfMemory}!void {
try interpreter.errors.put(interpreter.allocator, node_idx, .{
const message = try std.fmt.allocPrint(interpreter.allocator, fmt, args);
errdefer interpreter.allocator.free(message);
const previous = try interpreter.errors.fetchPut(interpreter.allocator, node_idx, .{
.code = code,
.message = try std.fmt.allocPrint(interpreter.allocator, fmt, args),
.message = message,
});
if (previous != null) interpreter.allocator.free(message);
}
pub fn deinit(interpreter: *ComptimeInterpreter) void {
var err_it = interpreter.errors.iterator();
while (err_it.next()) |entry| interpreter.allocator.free(entry.value_ptr.message);
for (interpreter.errors.values()) |err| {
interpreter.allocator.free(err.message);
}
interpreter.errors.deinit(interpreter.allocator);
interpreter.ip.deinit(interpreter.allocator);
@ -302,8 +306,8 @@ pub fn interpret(
const decl = ast.varDecl(tree, node_idx).?;
const type_value = if (decl.ast.type_node != 0) try ((try interpreter.interpret(decl.ast.type_node, namespace, .{})).getValue()) else null;
const init_value = if (decl.ast.init_node != 0) try ((try interpreter.interpret(decl.ast.init_node, namespace, .{})).getValue()) else null;
const type_value = if (decl.ast.type_node != 0) (try interpreter.interpret(decl.ast.type_node, namespace, .{})).maybeGetValue() else null;
const init_value = if (decl.ast.init_node != 0) (try interpreter.interpret(decl.ast.init_node, namespace, .{})).maybeGetValue() else null;
if (type_value == null and init_value == null) return InterpretResult{ .nothing = {} };
@ -470,6 +474,8 @@ pub fn interpret(
const can_have_fields: bool = switch (inner_lhs) {
.simple => |simple| switch (simple) {
.type => blk: {
if (irv.val == .none) break :blk true;
const ty_key = interpreter.ip.indexToKey(irv.val);
if (interpreter.huntItDown(ty_key.getNamespace(), field_name, options)) |decl| {
return InterpretResult{ .value = Value{

View File

@ -68,6 +68,10 @@ pub const Handle = struct {
associated_build_file: ?Uri = null,
pub fn deinit(self: *Handle, allocator: std.mem.Allocator) void {
if (self.interpreter) |interpreter| {
interpreter.deinit();
allocator.destroy(interpreter);
}
self.document_scope.deinit(allocator);
self.tree.deinit(allocator);
allocator.free(self.text);

View File

@ -361,7 +361,7 @@ fn generateDiagnostics(server: *Server, handle: DocumentStore.Handle) error{OutO
var err_it = int.errors.iterator();
while (err_it.next()) |err| {
try diagnostics.append(allocator, .{
diagnostics.appendAssumeCapacity(.{
.range = offsets.nodeToRange(tree, err.key_ptr.*, server.offset_encoding),
.severity = .Error,
.code = .{ .string = err.value_ptr.code },

View File

@ -321,7 +321,8 @@ pub const Key = union(enum) {
.@"anyframe",
.null_type,
.undefined_type,
.enum_literal_type, => true,
.enum_literal_type,
=> true,
.undefined_value,
.void_value,
@ -344,7 +345,8 @@ pub const Key = union(enum) {
.union_type,
.tuple_type,
.vector_type,
.anyframe_type, => true,
.anyframe_type,
=> true,
.int_u64_value,
.int_i64_value,

View File

@ -10,7 +10,7 @@ pub fn dotCompletions(
ip: *InternPool,
ty: InternPool.Index,
val: InternPool.Index,
node: ?Ast.Node.Index
node: ?Ast.Node.Index,
) error{OutOfMemory}!void {
_ = node;
@ -40,7 +40,7 @@ pub fn dotCompletions(
}
},
.union_type => {}, // TODO
.enum_type => |enum_info|{
.enum_type => |enum_info| {
for (enum_info.fields) |field| {
const field_name = ip.indexToKey(field.name).bytes;
try completions.append(arena, .{
@ -70,7 +70,7 @@ pub fn dotCompletions(
.kind = .Field,
.detail = "usize",
});
} else if(ip.indexToKey(pointer_info.elem_type) == .array_type) {
} else if (ip.indexToKey(pointer_info.elem_type) == .array_type) {
try completions.append(arena, .{
.label = "len",
.kind = .Field,
@ -127,7 +127,7 @@ pub fn dotCompletions(
}
},
.tuple_type => |tuple_info| {
for (tuple_info.types) |tuple_ty,i| {
for (tuple_info.types) |tuple_ty, i| {
try completions.append(arena, .{
.label = try std.fmt.allocPrint(arena, "{d}", .{i}),
.kind = .Field,
@ -140,7 +140,8 @@ pub fn dotCompletions(
.error_union_type,
.function_type,
.vector_type,
.anyframe_type => {},
.anyframe_type,
=> {},
.int_u64_value,
.int_i64_value,