aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval-cache.cc
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-02-25 20:35:11 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2021-02-25 21:51:05 +0000
commitca0994819d68aee26a2906c37a47ae609ac46c4c (patch)
treec96805c008c22926b1eaadc340a99323d53be532 /src/libexpr/eval-cache.cc
parent10e81bf871551901ff0383bdede0f79325e93867 (diff)
parentc189031e8be0530d73a817571ad7f81ad5eedce6 (diff)
Merge remote-tracking branch 'upstream/master' into path-info
Diffstat (limited to 'src/libexpr/eval-cache.cc')
-rw-r--r--src/libexpr/eval-cache.cc41
1 files changed, 25 insertions, 16 deletions
diff --git a/src/libexpr/eval-cache.cc b/src/libexpr/eval-cache.cc
index 381344b40..98d91c905 100644
--- a/src/libexpr/eval-cache.cc
+++ b/src/libexpr/eval-cache.cc
@@ -390,14 +390,14 @@ Value & AttrCursor::forceValue()
}
if (root->db && (!cachedValue || std::get_if<placeholder_t>(&cachedValue->second))) {
- if (v.type == tString)
+ if (v.type() == nString)
cachedValue = {root->db->setString(getKey(), v.string.s, v.string.context),
string_t{v.string.s, {}}};
- else if (v.type == tPath)
- cachedValue = {root->db->setString(getKey(), v.path), v.path};
- else if (v.type == tBool)
+ else if (v.type() == nPath)
+ cachedValue = {root->db->setString(getKey(), v.path), string_t{v.path, {}}};
+ else if (v.type() == nBool)
cachedValue = {root->db->setBool(getKey(), v.boolean), v.boolean};
- else if (v.type == tAttrs)
+ else if (v.type() == nAttrs)
; // FIXME: do something?
else
cachedValue = {root->db->setMisc(getKey()), misc_t()};
@@ -442,7 +442,7 @@ std::shared_ptr<AttrCursor> AttrCursor::maybeGetAttr(Symbol name, bool forceErro
auto & v = forceValue();
- if (v.type != tAttrs)
+ if (v.type() != nAttrs)
return nullptr;
//throw TypeError("'%s' is not an attribute set", getAttrPathStr());
@@ -512,10 +512,10 @@ std::string AttrCursor::getString()
auto & v = forceValue();
- if (v.type != tString && v.type != tPath)
- throw TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type));
+ if (v.type() != nString && v.type() != nPath)
+ throw TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type()));
- return v.type == tString ? v.string.s : v.path;
+ return v.type() == nString ? v.string.s : v.path;
}
string_t AttrCursor::getStringWithContext()
@@ -525,8 +525,17 @@ string_t AttrCursor::getStringWithContext()
cachedValue = root->db->getAttr(getKey(), root->state.symbols);
if (cachedValue && !std::get_if<placeholder_t>(&cachedValue->second)) {
if (auto s = std::get_if<string_t>(&cachedValue->second)) {
- debug("using cached string attribute '%s'", getAttrPathStr());
- return *s;
+ bool valid = true;
+ for (auto & c : s->second) {
+ if (!root->state.store->isValidPath(root->state.store->parseStorePath(c.first))) {
+ valid = false;
+ break;
+ }
+ }
+ if (valid) {
+ debug("using cached string attribute '%s'", getAttrPathStr());
+ return *s;
+ }
} else
throw TypeError("'%s' is not a string", getAttrPathStr());
}
@@ -534,12 +543,12 @@ string_t AttrCursor::getStringWithContext()
auto & v = forceValue();
- if (v.type == tString)
+ if (v.type() == nString)
return {v.string.s, v.getContext()};
- else if (v.type == tPath)
+ else if (v.type() == nPath)
return {v.path, {}};
else
- throw TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type));
+ throw TypeError("'%s' is not a string but %s", getAttrPathStr(), showType(v.type()));
}
bool AttrCursor::getBool()
@@ -558,7 +567,7 @@ bool AttrCursor::getBool()
auto & v = forceValue();
- if (v.type != tBool)
+ if (v.type() != nBool)
throw TypeError("'%s' is not a Boolean", getAttrPathStr());
return v.boolean;
@@ -580,7 +589,7 @@ std::vector<Symbol> AttrCursor::getAttrs()
auto & v = forceValue();
- if (v.type != tAttrs)
+ if (v.type() != nAttrs)
throw TypeError("'%s' is not an attribute set", getAttrPathStr());
std::vector<Symbol> attrs;