From 7ad0f68f727bfdfbb7be0b42b7ba8369ab5f55b0 Mon Sep 17 00:00:00 2001 From: Richard Feldman Date: Tue, 7 Oct 2025 15:05:24 -0400 Subject: [PATCH] Revise some more comments --- src/repl/Repl.zig | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/repl/Repl.zig b/src/repl/Repl.zig index 932c07fb70..e4c0e30306 100644 --- a/src/repl/Repl.zig +++ b/src/repl/Repl.zig @@ -355,9 +355,9 @@ fn evaluatePureExpression(self: *Repl, expr_source: []const u8, def_ident: ?[]co var module_env = try ModuleEnv.init(self.allocator, full_source); defer module_env.deinit(); - // Parse based on context: - // - If we have past_defs OR a def_ident (i.e., current input is a definition), parse as file - // - Otherwise, parse as expression + // Parse as a file if buildFullSource wrapped the input in a synthetic `main! = |_| `. + // This happens when we have past definitions to include, or when evaluating a definition (def_ident != null). + // Otherwise, parse the input directly as an expression. const need_file_parse = self.past_defs.items.len > 0 or def_ident != null; var parse_ast = if (need_file_parse) @@ -393,10 +393,8 @@ fn evaluatePureExpression(self: *Repl, expr_source: []const u8, def_ident: ?[]co // Canonicalize based on whether we have past definitions or a def_ident const canonical_expr_idx: can.CIR.Expr.Idx = if (self.past_defs.items.len > 0 or def_ident != null) blk: { - // HACK: When there are past definitions, buildFullSource wraps the expression in a synthetic - // file containing `main! = |_| ` so it can be evaluated. This is a workaround for - // limitations in the current evaluation system. Ideally, the REPL should handle statements - // and expressions directly without constructing fake files. + // When there are past definitions, buildFullSource wraps the expression in a synthetic + // `main! = |_| ` so it can be evaluated along with those definitions. czer.canonicalizeFile() catch |err| { return try std.fmt.allocPrint(self.allocator, "Canonicalize file error: {}", .{err}); };