mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-10 08:16:15 +02:00
de-const evalState exceptions
This commit is contained in:
parent
f9cdb6af8d
commit
7ddef73d02
7 changed files with 54 additions and 50 deletions
|
@ -118,9 +118,10 @@ ref<EvalState> EvalCommand::getEvalState()
|
|||
searchPath, getEvalStore(), getStore())
|
||||
#endif
|
||||
;
|
||||
// TODO move this somewhere else. Its only here to get the evalState ptr!
|
||||
if (startReplOnEvalErrors)
|
||||
// debuggerHook = [evalState{ref<EvalState>(evalState)}](const Error * error, const Env & env, const Expr & expr) {
|
||||
debuggerHook = [](const EvalState & evalState, const Error * error, const Env & env, const Expr & expr) {
|
||||
debuggerHook = [](EvalState & evalState, const Error * error, const Env & env, const Expr & expr) {
|
||||
auto dts =
|
||||
error && expr.getPos()
|
||||
? std::make_unique<DebugTraceStacker>(
|
||||
|
@ -137,9 +138,9 @@ ref<EvalState> EvalCommand::getEvalState()
|
|||
if (error)
|
||||
printError("%s\n\n" ANSI_BOLD "Starting REPL to allow you to inspect the current state of the evaluator.\n" ANSI_NORMAL, error->what());
|
||||
|
||||
auto se = evalState->getStaticEnv(expr);
|
||||
auto se = evalState.getStaticEnv(expr);
|
||||
if (se) {
|
||||
auto vm = mapStaticEnvBindings(evalState->symbols, *se.get(), env);
|
||||
auto vm = mapStaticEnvBindings(evalState.symbols, *se.get(), env);
|
||||
runRepl(evalState, *vm);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -274,7 +274,8 @@ void printClosureDiff(
|
|||
|
||||
|
||||
void runRepl(
|
||||
EvalState & evalState,
|
||||
ref<EvalState> evalState,
|
||||
// EvalState & evalState,
|
||||
const ValMap & extraEnv);
|
||||
|
||||
}
|
||||
|
|
|
@ -96,6 +96,7 @@ std::string removeWhitespace(std::string s)
|
|||
}
|
||||
|
||||
|
||||
// NixRepl::NixRepl(ref<EvalState> state)
|
||||
NixRepl::NixRepl(ref<EvalState> state)
|
||||
: state(state)
|
||||
, debugTraceIndex(0)
|
||||
|
@ -1012,7 +1013,8 @@ std::ostream & NixRepl::printValue(std::ostream & str, Value & v, unsigned int m
|
|||
}
|
||||
|
||||
void runRepl(
|
||||
EvalState& evalState,
|
||||
ref<EvalState> evalState,
|
||||
// EvalState& evalState,
|
||||
const ValMap & extraEnv)
|
||||
{
|
||||
auto repl = std::make_unique<NixRepl>(evalState);
|
||||
|
|
|
@ -814,7 +814,7 @@ std::unique_ptr<ValMap> mapStaticEnvBindings(const SymbolTable & st, const Stati
|
|||
of stack space, which is a real killer in the recursive
|
||||
evaluator. So here are some helper functions for throwing
|
||||
exceptions. */
|
||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, Env & env, Expr & expr) const
|
||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, Env & env, Expr & expr)
|
||||
{
|
||||
auto error = EvalError({
|
||||
.msg = hintfmt(s),
|
||||
|
@ -824,7 +824,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s, Env & env, Expr
|
|||
debugThrow(error, env, expr);
|
||||
}
|
||||
|
||||
void EvalState::throwEvalError(const PosIdx pos, const char * s) const
|
||||
void EvalState::throwEvalError(const PosIdx pos, const char * s)
|
||||
{
|
||||
auto error = EvalError({
|
||||
.msg = hintfmt(s),
|
||||
|
@ -834,7 +834,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s) const
|
|||
debugThrowLastTrace(error);
|
||||
}
|
||||
|
||||
void EvalState::throwEvalError(const char * s, const std::string & s2) const
|
||||
void EvalState::throwEvalError(const char * s, const std::string & s2)
|
||||
{
|
||||
auto error = EvalError(s, s2);
|
||||
|
||||
|
@ -842,7 +842,7 @@ void EvalState::throwEvalError(const char * s, const std::string & s2) const
|
|||
}
|
||||
|
||||
void EvalState::throwEvalError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
||||
const std::string & s2, Env & env, Expr & expr) const
|
||||
const std::string & s2, Env & env, Expr & expr)
|
||||
{
|
||||
auto error = EvalError(ErrorInfo{
|
||||
.msg = hintfmt(s, s2),
|
||||
|
@ -853,7 +853,7 @@ void EvalState::throwEvalError(const PosIdx pos, const Suggestions & suggestions
|
|||
debugThrow(error, env, expr);
|
||||
}
|
||||
|
||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2) const
|
||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2)
|
||||
{
|
||||
auto error = EvalError({
|
||||
.msg = hintfmt(s, s2),
|
||||
|
@ -863,7 +863,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::stri
|
|||
debugThrowLastTrace(error);
|
||||
}
|
||||
|
||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2, Env & env, Expr & expr) const
|
||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2, Env & env, Expr & expr)
|
||||
{
|
||||
auto error = EvalError({
|
||||
.msg = hintfmt(s, s2),
|
||||
|
@ -874,7 +874,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::stri
|
|||
}
|
||||
|
||||
void EvalState::throwEvalError(const char * s, const std::string & s2,
|
||||
const std::string & s3) const
|
||||
const std::string & s3)
|
||||
{
|
||||
auto error = EvalError({
|
||||
.msg = hintfmt(s, s2),
|
||||
|
@ -885,7 +885,7 @@ void EvalState::throwEvalError(const char * s, const std::string & s2,
|
|||
}
|
||||
|
||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
||||
const std::string & s3) const
|
||||
const std::string & s3)
|
||||
{
|
||||
auto error = EvalError({
|
||||
.msg = hintfmt(s, s2),
|
||||
|
@ -896,7 +896,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::stri
|
|||
}
|
||||
|
||||
void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
||||
const std::string & s3, Env & env, Expr & expr) const
|
||||
const std::string & s3, Env & env, Expr & expr)
|
||||
{
|
||||
auto error = EvalError({
|
||||
.msg = hintfmt(s, s2),
|
||||
|
@ -906,7 +906,7 @@ void EvalState::throwEvalError(const PosIdx pos, const char * s, const std::stri
|
|||
debugThrow(error, env, expr);
|
||||
}
|
||||
|
||||
void EvalState::throwEvalError(const PosIdx p1, const char * s, const Symbol sym, const PosIdx p2, Env & env, Expr & expr) const
|
||||
void EvalState::throwEvalError(const PosIdx p1, const char * s, const Symbol sym, const PosIdx p2, Env & env, Expr & expr)
|
||||
{
|
||||
// p1 is where the error occurred; p2 is a position mentioned in the message.
|
||||
auto error = EvalError({
|
||||
|
@ -917,7 +917,7 @@ void EvalState::throwEvalError(const PosIdx p1, const char * s, const Symbol sym
|
|||
debugThrow(error, env, expr);
|
||||
}
|
||||
|
||||
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v) const
|
||||
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v)
|
||||
{
|
||||
auto error = TypeError({
|
||||
.msg = hintfmt(s, showType(v)),
|
||||
|
@ -927,7 +927,7 @@ void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v
|
|||
debugThrowLastTrace(error);
|
||||
}
|
||||
|
||||
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v, Env & env, Expr & expr) const
|
||||
void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v, Env & env, Expr & expr)
|
||||
{
|
||||
auto error = TypeError({
|
||||
.msg = hintfmt(s, showType(v)),
|
||||
|
@ -937,7 +937,7 @@ void EvalState::throwTypeError(const PosIdx pos, const char * s, const Value & v
|
|||
debugThrow(error, env, expr);
|
||||
}
|
||||
|
||||
void EvalState::throwTypeError(const PosIdx pos, const char * s) const
|
||||
void EvalState::throwTypeError(const PosIdx pos, const char * s)
|
||||
{
|
||||
auto error = TypeError({
|
||||
.msg = hintfmt(s),
|
||||
|
@ -948,7 +948,7 @@ void EvalState::throwTypeError(const PosIdx pos, const char * s) const
|
|||
}
|
||||
|
||||
void EvalState::throwTypeError(const PosIdx pos, const char * s, const ExprLambda & fun,
|
||||
const Symbol s2, Env & env, Expr &expr) const
|
||||
const Symbol s2, Env & env, Expr &expr)
|
||||
{
|
||||
auto error = TypeError({
|
||||
.msg = hintfmt(s, fun.showNamePos(*this), symbols[s2]),
|
||||
|
@ -959,7 +959,7 @@ void EvalState::throwTypeError(const PosIdx pos, const char * s, const ExprLambd
|
|||
}
|
||||
|
||||
void EvalState::throwTypeError(const PosIdx pos, const Suggestions & suggestions, const char * s,
|
||||
const ExprLambda & fun, const Symbol s2, Env & env, Expr &expr) const
|
||||
const ExprLambda & fun, const Symbol s2, Env & env, Expr &expr)
|
||||
{
|
||||
auto error = TypeError(ErrorInfo {
|
||||
.msg = hintfmt(s, fun.showNamePos(*this), symbols[s2]),
|
||||
|
@ -970,7 +970,7 @@ void EvalState::throwTypeError(const PosIdx pos, const Suggestions & suggestions
|
|||
debugThrow(error, env, expr);
|
||||
}
|
||||
|
||||
void EvalState::throwTypeError(const char * s, const Value & v, Env & env, Expr &expr) const
|
||||
void EvalState::throwTypeError(const char * s, const Value & v, Env & env, Expr &expr)
|
||||
{
|
||||
auto error = TypeError({
|
||||
.msg = hintfmt(s, showType(v)),
|
||||
|
@ -980,7 +980,7 @@ void EvalState::throwTypeError(const char * s, const Value & v, Env & env, Expr
|
|||
debugThrow(error, env, expr);
|
||||
}
|
||||
|
||||
void EvalState::throwAssertionError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr) const
|
||||
void EvalState::throwAssertionError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
||||
{
|
||||
auto error = AssertionError({
|
||||
.msg = hintfmt(s, s1),
|
||||
|
@ -990,7 +990,7 @@ void EvalState::throwAssertionError(const PosIdx pos, const char * s, const std:
|
|||
debugThrow(error, env, expr);
|
||||
}
|
||||
|
||||
void EvalState::throwUndefinedVarError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr) const
|
||||
void EvalState::throwUndefinedVarError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
||||
{
|
||||
auto error = UndefinedVarError({
|
||||
.msg = hintfmt(s, s1),
|
||||
|
@ -1000,7 +1000,7 @@ void EvalState::throwUndefinedVarError(const PosIdx pos, const char * s, const s
|
|||
debugThrow(error, env, expr);
|
||||
}
|
||||
|
||||
void EvalState::throwMissingArgumentError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr) const
|
||||
void EvalState::throwMissingArgumentError(const PosIdx pos, const char * s, const std::string & s1, Env & env, Expr &expr)
|
||||
{
|
||||
auto error = MissingArgumentError({
|
||||
.msg = hintfmt(s, s1),
|
||||
|
|
|
@ -143,7 +143,7 @@ public:
|
|||
|
||||
template<class E>
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void debugThrow(const E &error, const Env & env, const Expr & expr) const
|
||||
void debugThrow(const E &error, const Env & env, const Expr & expr)
|
||||
{
|
||||
if (debuggerHook)
|
||||
debuggerHook(*this, &error, env, expr);
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
|
||||
template<class E>
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void debugThrowLastTrace(E & e) const
|
||||
void debugThrowLastTrace(E & e)
|
||||
{
|
||||
// Call this in the situation where Expr and Env are inaccessible.
|
||||
// The debugger will start in the last context that's in the
|
||||
|
@ -312,68 +312,68 @@ public:
|
|||
std::string_view forceStringNoCtx(Value & v, const PosIdx pos = noPos);
|
||||
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const PosIdx pos, const char * s) const;
|
||||
void throwEvalError(const PosIdx pos, const char * s);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const PosIdx pos, const char * s,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const char * s, const std::string & s2) const;
|
||||
void throwEvalError(const char * s, const std::string & s2);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2) const;
|
||||
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const char * s, const std::string & s2,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const char * s, const std::string & s2, const std::string & s3,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2, const std::string & s3,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2, const std::string & s3) const;
|
||||
void throwEvalError(const PosIdx pos, const char * s, const std::string & s2, const std::string & s3);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const char * s, const std::string & s2, const std::string & s3) const;
|
||||
void throwEvalError(const char * s, const std::string & s2, const std::string & s3);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const PosIdx pos, const Suggestions & suggestions, const char * s, const std::string & s2,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwEvalError(const PosIdx p1, const char * s, const Symbol sym, const PosIdx p2,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwTypeError(const PosIdx pos, const char * s, const Value & v) const;
|
||||
void throwTypeError(const PosIdx pos, const char * s, const Value & v);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwTypeError(const PosIdx pos, const char * s, const Value & v,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwTypeError(const PosIdx pos, const char * s) const;
|
||||
void throwTypeError(const PosIdx pos, const char * s);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwTypeError(const PosIdx pos, const char * s,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwTypeError(const PosIdx pos, const char * s, const ExprLambda & fun, const Symbol s2,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwTypeError(const PosIdx pos, const Suggestions & suggestions, const char * s, const ExprLambda & fun, const Symbol s2,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwTypeError(const char * s, const Value & v,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwAssertionError(const PosIdx pos, const char * s, const std::string & s1,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwUndefinedVarError(const PosIdx pos, const char * s, const std::string & s1,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
|
||||
[[gnu::noinline, gnu::noreturn]]
|
||||
void throwMissingArgumentError(const PosIdx pos, const char * s, const std::string & s1,
|
||||
Env & env, Expr & expr) const;
|
||||
Env & env, Expr & expr);
|
||||
|
||||
[[gnu::noinline]]
|
||||
void addErrorTrace(Error & e, const char * s, const std::string & s2) const;
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace nix {
|
|||
|
||||
/* Launch the nix debugger */
|
||||
|
||||
std::function<void(const EvalState & evalState,const Error * error, const Env & env, const Expr & expr)> debuggerHook;
|
||||
std::function<void(EvalState & evalState,const Error * error, const Env & env, const Expr & expr)> debuggerHook;
|
||||
|
||||
/* Displaying abstract syntax trees. */
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ MakeError(UndefinedVarError, Error);
|
|||
MakeError(MissingArgumentError, EvalError);
|
||||
MakeError(RestrictedPathError, Error);
|
||||
|
||||
extern std::function<void(const EvalState & evalState, const Error * error, const Env & env, const Expr & expr)> debuggerHook;
|
||||
extern std::function<void(EvalState & evalState, const Error * error, const Env & env, const Expr & expr)> debuggerHook;
|
||||
|
||||
/* Position objects. */
|
||||
|
||||
|
|
Loading…
Reference in a new issue