diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-02-04 00:31:33 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-02-04 00:33:21 +0100 |
commit | bd383d1b6f91c4fe7ac21c52771e92027f649fa0 (patch) | |
tree | 6845b5d2f709df2cbf06bca8de67cdab075902d2 /src/libexpr/eval-inline.hh | |
parent | 4c755c3b3fc427afe192d223b37c288c88cc57d5 (diff) |
Make most calls to determinePos() lazy
Diffstat (limited to 'src/libexpr/eval-inline.hh')
-rw-r--r-- | src/libexpr/eval-inline.hh | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/src/libexpr/eval-inline.hh b/src/libexpr/eval-inline.hh index 08acb0877..aef1f6351 100644 --- a/src/libexpr/eval-inline.hh +++ b/src/libexpr/eval-inline.hh @@ -15,12 +15,6 @@ LocalNoInlineNoReturn(void throwEvalError(const Pos & pos, const char * s)) }); } -LocalNoInlineNoReturn(void throwTypeError(const char * s, const Value & v)) -{ - throw TypeError(s, showType(v)); -} - - LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const Value & v)) { throw TypeError({ @@ -32,6 +26,13 @@ LocalNoInlineNoReturn(void throwTypeError(const Pos & pos, const char * s, const void EvalState::forceValue(Value & v, const Pos & pos) { + forceValue(v, [&]() { return pos; }); +} + + +template<typename Callable> +void EvalState::forceValue(Value & v, Callable getPos) +{ if (v.isThunk()) { Env * env = v.thunk.env; Expr * expr = v.thunk.expr; @@ -47,15 +48,22 @@ void EvalState::forceValue(Value & v, const Pos & pos) else if (v.isApp()) callFunction(*v.app.left, *v.app.right, v, noPos); else if (v.isBlackhole()) - throwEvalError(pos, "infinite recursion encountered"); + throwEvalError(getPos(), "infinite recursion encountered"); } inline void EvalState::forceAttrs(Value & v, const Pos & pos) { - forceValue(v, pos); + forceAttrs(v, [&]() { return pos; }); +} + + +template <typename Callable> +inline void EvalState::forceAttrs(Value & v, Callable getPos) +{ + forceValue(v, getPos); if (v.type() != nAttrs) - throwTypeError(pos, "value is %1% while a set was expected", v); + throwTypeError(getPos(), "value is %1% while a set was expected", v); } |