From 87aa4c09e1069714beac1d33bb13cb19f01b9f4c Mon Sep 17 00:00:00 2001 From: Auguste Rame <19855629+SuperAuguste@users.noreply.github.com> Date: Wed, 16 Nov 2022 19:28:01 -0500 Subject: [PATCH] Quick comptime interpreter fix, place it behind an option (#761) * Quick fix * Add config option --- README.md | 1 + schema.json | 5 +++++ src/ComptimeInterpreter.zig | 2 +- src/Config.zig | 3 +++ src/analysis.zig | 2 +- 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9928f8c..819f3fd 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,7 @@ The following options are currently available. |`max_detail_length`|`usize`|`1024 * 1024`| The detail field of completions is truncated to be no longer than this (in bytes). | `skip_std_references` | `bool` | `false` | When true, skips searching for references in std. Improves lookup speed for functions in user's code. Renaming and go-to-definition will continue to work as is. | `highlight_global_var_declarations` | `bool` | `false` | Whether to highlight global var declarations. +| `use_comptime_interpreter` | `bool` | `false` | Whether to use the comptime interpreter. ### Per-build Configuration Options diff --git a/schema.json b/schema.json index 2d0fd0f..f400f26 100644 --- a/schema.json +++ b/schema.json @@ -99,6 +99,11 @@ "description": "Whether to highlight global var declarations", "type": "boolean", "default": "false" + }, + "use_comptime_interpreter": { + "description": "Whether to use the comptime interpreter", + "type": "boolean", + "default": "false" } } } diff --git a/src/ComptimeInterpreter.zig b/src/ComptimeInterpreter.zig index 619c3cc..587ade5 100644 --- a/src/ComptimeInterpreter.zig +++ b/src/ComptimeInterpreter.zig @@ -1421,7 +1421,7 @@ pub fn call( const tree = interpreter.getHandle().tree; const tags = tree.nodes.items(.tag); - std.debug.assert(tags[func_node_idx] == .fn_decl); + if (tags[func_node_idx] != .fn_decl) return error.CriticalAstFailure; // TODO: Make argument scope to evaluate arguments in var fn_scope = try interpreter.newScope(scope, func_node_idx); diff --git a/src/Config.zig b/src/Config.zig index 642a096..ae7fd55 100644 --- a/src/Config.zig +++ b/src/Config.zig @@ -79,6 +79,9 @@ builtin_path: ?[]const u8 = null, /// Whether to highlight global var declarations. highlight_global_var_declarations: bool = false, +/// Whether to use the comptime interpreter +use_comptime_interpreter: bool = false, + pub fn loadFromFile(allocator: std.mem.Allocator, file_path: []const u8) ?Config { const tracy_zone = tracy.trace(@src()); defer tracy_zone.end(); diff --git a/src/analysis.zig b/src/analysis.zig index a9faf06..8804cba 100644 --- a/src/analysis.zig +++ b/src/analysis.zig @@ -745,7 +745,7 @@ pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAl const body = decl.handle.tree.nodes.items(.data)[decl_node].rhs; if (try resolveReturnType(store, arena, fn_decl, decl.handle, bound_type_params, if (has_body) body else null)) |ret| { return ret; - } else { + } else if (store.config.use_comptime_interpreter) { // TODO: Better case-by-case; we just use the ComptimeInterpreter when all else fails, // probably better to use it more liberally // TODO: Handle non-isolate args; e.g. `const T = u8; TypeFunc(T);`