refactor(tvix/eval): Box the strings in CatchableErrorKind
These strings are allocated once and never changed, so they don't need the additional overhead of a capacity given by String - instead, we can use Box<str> and save on 16 bytes for each of these, *and* for each Value since this is currently the largest Value variant. Change-Id: I3e5cb070fe6c5bf82114c92d04f6bae775663a7e Reviewed-on: https://cl.tvl.fyi/c/depot/+/10796 Autosubmit: aspen <root@gws.fyi> Reviewed-by: sterni <sternenseemann@systemli.org> Tested-by: BuildkiteCI
This commit is contained in:
parent
5d2ae840f1
commit
5d72d3980f
3 changed files with 14 additions and 13 deletions
|
@ -476,7 +476,7 @@ mod pure_builtins {
|
||||||
async fn builtin_filterSource(_co: GenCo, #[lazy] _e: Value) -> Result<Value, ErrorKind> {
|
async fn builtin_filterSource(_co: GenCo, #[lazy] _e: Value) -> Result<Value, ErrorKind> {
|
||||||
// TODO: implement for nixpkgs compatibility
|
// TODO: implement for nixpkgs compatibility
|
||||||
Ok(Value::Catchable(CatchableErrorKind::UnimplementedFeature(
|
Ok(Value::Catchable(CatchableErrorKind::UnimplementedFeature(
|
||||||
"filterSource".to_string(),
|
"filterSource".into(),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,7 +695,7 @@ mod pure_builtins {
|
||||||
) -> Result<Value, ErrorKind> {
|
) -> Result<Value, ErrorKind> {
|
||||||
// FIXME: propagate contexts here.
|
// FIXME: propagate contexts here.
|
||||||
Ok(Value::Catchable(CatchableErrorKind::UnimplementedFeature(
|
Ok(Value::Catchable(CatchableErrorKind::UnimplementedFeature(
|
||||||
"hashString".to_string(),
|
"hashString".into(),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1392,7 +1392,7 @@ mod pure_builtins {
|
||||||
// TODO(sterni): coerces to string
|
// TODO(sterni): coerces to string
|
||||||
// We do not care about the context here explicitly.
|
// We do not care about the context here explicitly.
|
||||||
Ok(Value::Catchable(CatchableErrorKind::Throw(
|
Ok(Value::Catchable(CatchableErrorKind::Throw(
|
||||||
message.to_contextful_str()?.to_string(),
|
message.to_contextful_str()?.to_string().into(),
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1531,9 +1531,7 @@ pub fn pure_builtins() -> Vec<(&'static str, Value)> {
|
||||||
// TODO: implement for nixpkgs compatibility
|
// TODO: implement for nixpkgs compatibility
|
||||||
result.push((
|
result.push((
|
||||||
"__curPos",
|
"__curPos",
|
||||||
Value::Catchable(CatchableErrorKind::UnimplementedFeature(
|
Value::Catchable(CatchableErrorKind::UnimplementedFeature("__curPos".into())),
|
||||||
"__curPos".to_string(),
|
|
||||||
)),
|
|
||||||
));
|
));
|
||||||
|
|
||||||
result
|
result
|
||||||
|
|
|
@ -40,11 +40,11 @@ use crate::{SourceCode, Value};
|
||||||
///
|
///
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub enum CatchableErrorKind {
|
pub enum CatchableErrorKind {
|
||||||
Throw(String),
|
Throw(Box<str>),
|
||||||
AssertionFailed,
|
AssertionFailed,
|
||||||
UnimplementedFeature(String),
|
UnimplementedFeature(Box<str>),
|
||||||
/// Resolving a user-supplied angle brackets path literal failed in some way.
|
/// Resolving a user-supplied angle brackets path literal failed in some way.
|
||||||
NixPathResolution(String),
|
NixPathResolution(Box<str>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
|
|
@ -138,10 +138,13 @@ impl NixSearchPath {
|
||||||
return Ok(Ok(p));
|
return Ok(Ok(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(Err(CatchableErrorKind::NixPathResolution(format!(
|
Ok(Err(CatchableErrorKind::NixPathResolution(
|
||||||
|
format!(
|
||||||
"path '{}' was not found in the Nix search path",
|
"path '{}' was not found in the Nix search path",
|
||||||
path.display()
|
path.display()
|
||||||
))))
|
)
|
||||||
|
.into_boxed_str(),
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue