Commit a81ce929 authored by Kenton Varda's avatar Kenton Varda

Fix valgrind bugs.

parent 851f51e5
...@@ -179,6 +179,10 @@ private: ...@@ -179,6 +179,10 @@ private:
Content guardedContent; // Read using getContent() only! Content guardedContent; // Read using getContent() only!
bool inGetContent = false; // True while getContent() is running; detects cycles. bool inGetContent = false; // True while getContent() is running; detects cycles.
kj::Maybe<schema::Node::Reader> loadedFinalSchema;
// Copy of `finalSchema` as loaded into the final schema loader. This doesn't go away if the
// workspace is destroyed.
// --------------------------------------------- // ---------------------------------------------
static uint64_t generateId(uint64_t parentId, kj::StringPtr declName, static uint64_t generateId(uint64_t parentId, kj::StringPtr declName,
...@@ -515,12 +519,11 @@ kj::Maybe<Compiler::Node::Content&> Compiler::Node::getContent(Content::State mi ...@@ -515,12 +519,11 @@ kj::Maybe<Compiler::Node::Content&> Compiler::Node::getContent(Content::State mi
} }
} }
// If the Workspace is destroyed while this Node is still in the BOOTSTRAP state, // If the Workspace is destroyed, revert the node to the EXPANDED state, because the
// revert it to the EXPANDED state, because the NodeTranslator is no longer valid in this // NodeTranslator is no longer valid in this case.
// case.
workspace.arena.copy(kj::defer([&content]() { workspace.arena.copy(kj::defer([&content]() {
content.bootstrapSchema = nullptr; content.bootstrapSchema = nullptr;
if (content.state == Content::BOOTSTRAP) { if (content.state > Content::EXPANDED) {
content.state = Content::EXPANDED; content.state = Content::EXPANDED;
} }
})); }));
...@@ -640,7 +643,10 @@ kj::Maybe<Compiler::Node&> Compiler::Node::lookup(const DeclName::Reader& name) ...@@ -640,7 +643,10 @@ kj::Maybe<Compiler::Node&> Compiler::Node::lookup(const DeclName::Reader& name)
} }
kj::Maybe<Schema> Compiler::Node::getBootstrapSchema() { kj::Maybe<Schema> Compiler::Node::getBootstrapSchema() {
KJ_IF_MAYBE(content, getContent(Content::BOOTSTRAP)) { KJ_IF_MAYBE(schema, loadedFinalSchema) {
// We don't need to rebuild the bootstrap schema if we already have a final schema.
return module->getCompiler().getWorkspace().bootstrapLoader.loadOnce(*schema);
} else KJ_IF_MAYBE(content, getContent(Content::BOOTSTRAP)) {
if (content->state == Content::FINISHED && content->bootstrapSchema == nullptr) { if (content->state == Content::FINISHED && content->bootstrapSchema == nullptr) {
// The bootstrap schema was discarded. Copy it from the final schema. // The bootstrap schema was discarded. Copy it from the final schema.
// (We can't just return the final schema because using it could trigger schema loader // (We can't just return the final schema because using it could trigger schema loader
...@@ -658,7 +664,9 @@ kj::Maybe<Schema> Compiler::Node::getBootstrapSchema() { ...@@ -658,7 +664,9 @@ kj::Maybe<Schema> Compiler::Node::getBootstrapSchema() {
} }
} }
kj::Maybe<schema::Node::Reader> Compiler::Node::getFinalSchema() { kj::Maybe<schema::Node::Reader> Compiler::Node::getFinalSchema() {
KJ_IF_MAYBE(content, getContent(Content::FINISHED)) { KJ_IF_MAYBE(schema, loadedFinalSchema) {
return *schema;
} else KJ_IF_MAYBE(content, getContent(Content::FINISHED)) {
return content->finalSchema; return content->finalSchema;
} else { } else {
return nullptr; return nullptr;
...@@ -671,9 +679,11 @@ void Compiler::Node::loadFinalSchema(const SchemaLoader& loader) { ...@@ -671,9 +679,11 @@ void Compiler::Node::loadFinalSchema(const SchemaLoader& loader) {
KJ_MAP(auxSchema, content->auxSchemas) { KJ_MAP(auxSchema, content->auxSchemas) {
return loader.loadOnce(auxSchema); return loader.loadOnce(auxSchema);
}; };
loader.loadOnce(*finalSchema); loadedFinalSchema = loader.loadOnce(*finalSchema).getProto();
} }
})) { })) {
// Schema validation threw an exception.
// Don't try loading this again. // Don't try loading this again.
content->finalSchema = nullptr; content->finalSchema = nullptr;
......
...@@ -1346,7 +1346,7 @@ DynamicList::Reader DynamicList::Builder::asReader() const { ...@@ -1346,7 +1346,7 @@ DynamicList::Reader DynamicList::Builder::asReader() const {
// ======================================================================================= // =======================================================================================
DynamicValue::Reader::Reader(ConstSchema constant) { DynamicValue::Reader::Reader(ConstSchema constant): type(VOID) {
auto typeSchema = constant.getProto().getConst().getType(); auto typeSchema = constant.getProto().getConst().getType();
auto value = constant.getProto().getConst().getValue(); auto value = constant.getProto().getConst().getValue();
switch (typeSchema.which()) { switch (typeSchema.which()) {
......
linux-gcc-4.7 1748 ./super-test.sh tmpdir capnp-gcc-4.7 quick linux-gcc-4.7 1758 ./super-test.sh tmpdir capnp-gcc-4.7 quick
linux-gcc-4.8 1751 ./super-test.sh tmpdir capnp-gcc-4.8 quick gcc-4.8 linux-gcc-4.8 1761 ./super-test.sh tmpdir capnp-gcc-4.8 quick gcc-4.8
linux-clang 1771 ./super-test.sh tmpdir capnp-clang quick clang linux-clang 1781 ./super-test.sh tmpdir capnp-clang quick clang
mac 800 ./super-test.sh remote beat caffeinate quick mac 800 ./super-test.sh remote beat caffeinate quick
cygwin 805 ./super-test.sh remote Kenton@flashman quick cygwin 805 ./super-test.sh remote Kenton@flashman quick
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment