refactor(tvix/eval): add SourceCode directly into error types

With this change it's no longer necessary to track the SourceCode
struct separately from the evaluation for error reporting: It's just
stored directly in the errors.

This also ends up resolving an issue in compiler::bindings, where we
cloned the Arc containing file references way too often. In fact those
clones probably compensate for all additional SourceCode clones during
error construction now.

Change-Id: Ice93bf161e61f8ea3d48103435e20c53e6aa8c3a
Reviewed-on: https://cl.tvl.fyi/c/depot/+/10986
Reviewed-by: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
This commit is contained in:
Vincent Ambo 2024-02-20 15:29:30 +07:00 committed by tazjin
parent b38badf206
commit 3c87687798
6 changed files with 67 additions and 40 deletions

View file

@ -261,7 +261,7 @@ where
code.as_ref(),
file.clone(),
location,
source,
source.clone(),
self.builtins,
self.src_builtins,
self.enable_import,
@ -295,6 +295,7 @@ where
nix_path,
self.io_handle,
runtime_observer,
source,
globals,
lambda,
self.strict,
@ -335,6 +336,7 @@ fn parse_compile_internal(
result.errors.push(Error::new(
ErrorKind::ParseErrors(parse_errors.to_vec()),
file.span,
source,
));
return None;
}
@ -344,13 +346,15 @@ fn parse_compile_internal(
// the result, in case the caller needs it for something.
result.expr = parsed.tree().expr();
let builtins = crate::compiler::prepare_globals(builtins, src_builtins, source, enable_import);
let builtins =
crate::compiler::prepare_globals(builtins, src_builtins, source.clone(), enable_import);
let compiler_result = match compiler::compile(
result.expr.as_ref().unwrap(),
location,
file,
builtins,
&source,
&file,
compiler_observer,
) {
Ok(result) => result,