difftreelog
perf move error and stacktrace to heap
in: master
3 files changed
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth1use crate::{2 builtin::{format::FormatError, sort::SortError},3 ValType,4};5use jrsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};6use std::{path::PathBuf, rc::Rc};78#[derive(Debug, Clone)]9pub enum Error {10 IntristicNotFound(Rc<str>, Rc<str>),11 IntristicArgumentReorderingIsNotSupportedYet,1213 UnaryOperatorDoesNotOperateOnType(UnaryOpType, ValType),14 BinaryOperatorDoesNotOperateOnValues(BinaryOpType, ValType, ValType),1516 NoTopLevelObjectFound,17 CantUseSelfOutsideOfObject,18 CantUseSuperOutsideOfObject,1920 InComprehensionCanOnlyIterateOverArray,2122 ArrayBoundsError(usize, usize),2324 AssertionFailed(Rc<str>),2526 VariableIsNotDefined(String),27 TypeMismatch(&'static str, Vec<ValType>, ValType),28 NoSuchField(Rc<str>),2930 UnknownVariable(Rc<str>),3132 OnlyFunctionsCanBeCalledGot(ValType),33 UnknownFunctionParameter(String),34 BindingParameterASecondTime(Rc<str>),35 TooManyArgsFunctionHas(usize),36 FunctionParameterNotBoundInCall(Rc<str>),3738 UndefinedExternalVariable(Rc<str>),39 UndefinedExternalFunction(Rc<str>),4041 FieldMustBeStringGot(ValType),4243 AttemptedIndexAnArrayWithString(Rc<str>),44 ValueIndexMustBeTypeGot(ValType, ValType, ValType),45 CantIndexInto(ValType),4647 StandaloneSuper,4849 ImportFileNotFound(PathBuf, PathBuf),50 ResolvedFileNotFound(PathBuf),51 ImportBadFileUtf8(PathBuf),52 ImportNotSupported(PathBuf, PathBuf),53 ImportSyntaxError {54 path: Rc<PathBuf>,55 source_code: Rc<str>,56 error: Box<jrsonnet_parser::ParseError>,57 },5859 RuntimeError(Rc<str>),60 StackOverflow,61 FractionalIndex,62 DivisionByZero,6364 StringManifestOutputIsNotAString,65 StreamManifestOutputIsNotAArray,66 MultiManifestOutputIsNotAObject,6768 StreamManifestOutputCannotBeRecursed,69 StreamManifestCannotNestString,7071 ImportCallbackError(String),72 InvalidUnicodeCodepointGot(u32),7374 Format(FormatError),75 Sort(SortError),76}77impl From<Error> for LocError {78 fn from(e: Error) -> Self {79 Self(e, StackTrace(vec![]))80 }81}8283#[derive(Clone, Debug)]84pub struct StackTraceElement {85 pub location: ExprLocation,86 pub desc: String,87}88#[derive(Debug, Clone)]89pub struct StackTrace(pub Vec<StackTraceElement>);9091#[derive(Debug, Clone)]92pub struct LocError(pub Error, pub StackTrace);93impl LocError {94 pub fn new(e: Error) -> Self {95 Self(e, StackTrace(vec![]))96 }97}9899pub type Result<V> = std::result::Result<V, LocError>;100101#[macro_export]102macro_rules! throw {103 ($e: expr) => {104 return Err($e.into());105 };106}1use crate::{2 builtin::{format::FormatError, sort::SortError},3 ValType,4};5use jrsonnet_parser::{BinaryOpType, ExprLocation, UnaryOpType};6use std::{path::PathBuf, rc::Rc};78#[derive(Debug, Clone)]9pub enum Error {10 IntristicNotFound(Rc<str>, Rc<str>),11 IntristicArgumentReorderingIsNotSupportedYet,1213 UnaryOperatorDoesNotOperateOnType(UnaryOpType, ValType),14 BinaryOperatorDoesNotOperateOnValues(BinaryOpType, ValType, ValType),1516 NoTopLevelObjectFound,17 CantUseSelfOutsideOfObject,18 CantUseSuperOutsideOfObject,1920 InComprehensionCanOnlyIterateOverArray,2122 ArrayBoundsError(usize, usize),2324 AssertionFailed(Rc<str>),2526 VariableIsNotDefined(String),27 TypeMismatch(&'static str, Vec<ValType>, ValType),28 NoSuchField(Rc<str>),2930 UnknownVariable(Rc<str>),3132 OnlyFunctionsCanBeCalledGot(ValType),33 UnknownFunctionParameter(String),34 BindingParameterASecondTime(Rc<str>),35 TooManyArgsFunctionHas(usize),36 FunctionParameterNotBoundInCall(Rc<str>),3738 UndefinedExternalVariable(Rc<str>),39 UndefinedExternalFunction(Rc<str>),4041 FieldMustBeStringGot(ValType),4243 AttemptedIndexAnArrayWithString(Rc<str>),44 ValueIndexMustBeTypeGot(ValType, ValType, ValType),45 CantIndexInto(ValType),4647 StandaloneSuper,4849 ImportFileNotFound(PathBuf, PathBuf),50 ResolvedFileNotFound(PathBuf),51 ImportBadFileUtf8(PathBuf),52 ImportNotSupported(PathBuf, PathBuf),53 ImportSyntaxError {54 path: Rc<PathBuf>,55 source_code: Rc<str>,56 error: Box<jrsonnet_parser::ParseError>,57 },5859 RuntimeError(Rc<str>),60 StackOverflow,61 FractionalIndex,62 DivisionByZero,6364 StringManifestOutputIsNotAString,65 StreamManifestOutputIsNotAArray,66 MultiManifestOutputIsNotAObject,6768 StreamManifestOutputCannotBeRecursed,69 StreamManifestCannotNestString,7071 ImportCallbackError(String),72 InvalidUnicodeCodepointGot(u32),7374 Format(FormatError),75 Sort(SortError),76}77impl From<Error> for LocError {78 fn from(e: Error) -> Self {79 Self::new(e)80 }81}8283#[derive(Clone, Debug)]84pub struct StackTraceElement {85 pub location: ExprLocation,86 pub desc: String,87}88#[derive(Debug, Clone)]89pub struct StackTrace(pub Vec<StackTraceElement>);9091#[derive(Debug, Clone)]92pub struct LocError(Box<(Error, StackTrace)>);93impl LocError {94 pub fn new(e: Error) -> Self {95 Self(Box::new((e, StackTrace(vec![]))))96 }9798 pub fn error(&self) -> &Error {99 &(self.0).0100 }101 pub fn trace(&self) -> &StackTrace {102 &(self.0).1103 }104 pub fn trace_mut(&mut self) -> &mut StackTrace {105 &mut (self.0).1106 }107}108109pub type Result<V> = std::result::Result<V, LocError>;110111#[macro_export]112macro_rules! throw {113 ($e: expr) => {114 return Err($e.into());115 };116}crates/jrsonnet-evaluator/src/lib.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/lib.rs
+++ b/crates/jrsonnet-evaluator/src/lib.rs
@@ -285,7 +285,7 @@
let result = f();
self.data_mut().stack_depth -= 1;
if let Err(mut err) = result {
- (err.1).0.push(StackTraceElement {
+ err.trace_mut().0.push(StackTraceElement {
location: e.clone(),
desc: frame_desc(),
});
crates/jrsonnet-evaluator/src/trace/mod.rsdiffbeforeafterboth--- a/crates/jrsonnet-evaluator/src/trace/mod.rs
+++ b/crates/jrsonnet-evaluator/src/trace/mod.rs
@@ -86,8 +86,9 @@
evaluation_state: &EvaluationState,
error: &LocError,
) -> Result<(), std::fmt::Error> {
- writeln!(out, "{:?}", error.0)?;
- let file_names = (error.1)
+ writeln!(out, "{:?}", error.error())?;
+ let file_names = error
+ .trace()
.0
.iter()
.map(|el| {
@@ -105,7 +106,7 @@
})
.collect::<Vec<_>>();
let align = file_names.iter().map(|e| e.len()).max().unwrap_or(0);
- for (i, (el, file)) in (error.1).0.iter().zip(file_names).enumerate() {
+ for (i, (el, file)) in error.trace().0.iter().zip(file_names).enumerate() {
if i != 0 {
writeln!(out)?;
}
@@ -131,8 +132,8 @@
evaluation_state: &EvaluationState,
error: &LocError,
) -> Result<(), std::fmt::Error> {
- writeln!(out, "{:?}", error.0)?;
- for (i, item) in (error.1).0.iter().enumerate() {
+ writeln!(out, "{:?}", error.error())?;
+ for (i, item) in error.trace().0.iter().enumerate() {
if i != 0 {
writeln!(out)?;
}
@@ -170,8 +171,8 @@
display_list::{DisplayList, FormatOptions},
snippet::{AnnotationType, Slice, Snippet, SourceAnnotation},
};
- writeln!(out, "{:?}", error.0)?;
- let trace = &error.1;
+ writeln!(out, "{:?}", error.error())?;
+ let trace = &error.trace();
for item in trace.0.iter() {
let desc = &item.desc;
let source = item.location.clone();