1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-10-18 00:16:11 -04:00

Compare commits

..

2 commits

Author SHA1 Message Date
Rebecca Turner 9723f533d8
Add comment 2024-02-06 16:50:47 -08:00
Rebecca Turner 474fc4078a
Add comments 2024-02-06 16:49:28 -08:00
3 changed files with 10 additions and 23 deletions

View file

@ -91,7 +91,7 @@ void EvalErrorBuilder<T>::debugThrow()
// `EvalState` is the only class that can construct an `EvalErrorBuilder`,
// and it does so in dynamic storage. This is the final method called on
// any such instancve and must delete itself before throwing the underlying
// any such instance and must delete itself before throwing the underlying
// error.
auto error = std::move(this->error);
delete this;

View file

@ -56,6 +56,11 @@ public:
}
};
/**
* `EvalErrorBuilder`s may only be constructed by `EvalState`. The `debugThrow`
* method must be the final method in any such `EvalErrorBuilder` usage, and it
* handles deleting the object.
*/
template<class T>
class EvalErrorBuilder final
{
@ -90,29 +95,10 @@ public:
[[nodiscard, gnu::noinline]] EvalErrorBuilder<T> &
addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs);
/**
* Delete the `EvalErrorBuilder` and throw the underlying exception.
*/
[[gnu::noinline, gnu::noreturn]] void debugThrow();
};
/**
* The size needed to allocate any `EvalErrorBuilder<T>`.
*
* The list of classes here needs to be kept in sync with the list of `template
* class` declarations in `eval-error.cc`.
*
* This is used by `EvalState` to preallocate a buffer of sufficient size for
* any `EvalErrorBuilder<T>` to avoid allocating while evaluating Nix code.
*/
constexpr size_t EVAL_ERROR_BUILDER_SIZE = std::max({
sizeof(EvalErrorBuilder<EvalError>),
sizeof(EvalErrorBuilder<AssertionError>),
sizeof(EvalErrorBuilder<ThrownError>),
sizeof(EvalErrorBuilder<Abort>),
sizeof(EvalErrorBuilder<TypeError>),
sizeof(EvalErrorBuilder<UndefinedVarError>),
sizeof(EvalErrorBuilder<MissingArgumentError>),
sizeof(EvalErrorBuilder<InfiniteRecursionError>),
sizeof(EvalErrorBuilder<CachedEvalError>),
sizeof(EvalErrorBuilder<InvalidPathError>),
});
}

View file

@ -239,6 +239,7 @@ public:
template<class T, typename... Args>
[[nodiscard, gnu::noinline]]
EvalErrorBuilder<T> & error(const Args & ... args) {
// `EvalErrorBuilder::debugThrow` performs the corresponding `delete`.
return *new EvalErrorBuilder<T>(*this, args...);
}