Quick comptime interpreter fix, place it behind an option (#761)

* Quick fix

* Add config option
This commit is contained in:
Auguste Rame 2022-11-16 19:28:01 -05:00 committed by GitHub
parent 355d56376f
commit 87aa4c09e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 2 deletions

View File

@ -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). |`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. | `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. | `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 ### Per-build Configuration Options

View File

@ -99,6 +99,11 @@
"description": "Whether to highlight global var declarations", "description": "Whether to highlight global var declarations",
"type": "boolean", "type": "boolean",
"default": "false" "default": "false"
},
"use_comptime_interpreter": {
"description": "Whether to use the comptime interpreter",
"type": "boolean",
"default": "false"
} }
} }
} }

View File

@ -1421,7 +1421,7 @@ pub fn call(
const tree = interpreter.getHandle().tree; const tree = interpreter.getHandle().tree;
const tags = tree.nodes.items(.tag); 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 // TODO: Make argument scope to evaluate arguments in
var fn_scope = try interpreter.newScope(scope, func_node_idx); var fn_scope = try interpreter.newScope(scope, func_node_idx);

View File

@ -79,6 +79,9 @@ builtin_path: ?[]const u8 = null,
/// Whether to highlight global var declarations. /// Whether to highlight global var declarations.
highlight_global_var_declarations: bool = false, 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 { pub fn loadFromFile(allocator: std.mem.Allocator, file_path: []const u8) ?Config {
const tracy_zone = tracy.trace(@src()); const tracy_zone = tracy.trace(@src());
defer tracy_zone.end(); defer tracy_zone.end();

View File

@ -745,7 +745,7 @@ pub fn resolveTypeOfNodeInternal(store: *DocumentStore, arena: *std.heap.ArenaAl
const body = decl.handle.tree.nodes.items(.data)[decl_node].rhs; 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| { if (try resolveReturnType(store, arena, fn_decl, decl.handle, bound_type_params, if (has_body) body else null)) |ret| {
return 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, // TODO: Better case-by-case; we just use the ComptimeInterpreter when all else fails,
// probably better to use it more liberally // probably better to use it more liberally
// TODO: Handle non-isolate args; e.g. `const T = u8; TypeFunc(T);` // TODO: Handle non-isolate args; e.g. `const T = u8; TypeFunc(T);`