diff --git a/.gitignore b/.gitignore index d8a3e73a7..080a075d0 100644 --- a/.gitignore +++ b/.gitignore @@ -66,8 +66,9 @@ src/distributed/token_sharing_rpc_messages.capnp src/distributed/token_sharing_rpc_messages.hpp src/distributed/updates_rpc_messages.capnp src/distributed/updates_rpc_messages.hpp -src/query/frontend/ast/ast.capnp src/query/frontend/ast/ast.hpp +src/query/frontend/ast/ast_serialization.capnp +src/query/frontend/ast/ast_serialization.hpp src/query/plan/distributed_ops.capnp src/query/plan/distributed_ops.hpp src/query/plan/operator.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1da443c57..97f1ef3bc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -117,8 +117,10 @@ add_capnp(distributed/dynamic_worker_rpc_messages.capnp) # distributed_ops.lcp is leading the capnp code generation, so we don't need # to generate any capnp for operator.lcp -add_lcp(query/frontend/ast/ast.lcp CAPNP_SCHEMA @0xb107d3d6b4b1600b) -add_capnp(query/frontend/ast/ast.capnp) +add_lcp(query/frontend/ast/ast.lcp) +add_lcp(query/frontend/ast/ast_serialization.lcp CAPNP_SCHEMA @0xb107d3d6b4b1600b + DEPENDS query/frontend/ast/ast.lcp) +add_capnp(query/frontend/ast/ast_serialization.capnp) add_lcp(query/plan/operator.lcp) add_lcp(query/plan/distributed_ops.lcp CAPNP_SCHEMA @0xe5cae8d045d30c42 DEPENDS query/plan/operator.lcp) diff --git a/src/distributed/bfs_rpc_messages.lcp b/src/distributed/bfs_rpc_messages.lcp index 0f4404d19..d2da36bac 100644 --- a/src/distributed/bfs_rpc_messages.lcp +++ b/src/distributed/bfs_rpc_messages.lcp @@ -18,7 +18,7 @@ cpp<# (lcp:capnp-namespace "distributed") -(lcp:capnp-import 'ast "/query/frontend/ast/ast.capnp") +(lcp:capnp-import 'ast "/query/frontend/ast/ast_serialization.capnp") (lcp:capnp-import 'dist-ops "/query/plan/distributed_ops.capnp") (lcp:capnp-import 'query "/query/serialization.capnp") (lcp:capnp-import 'storage "/storage/serialization.capnp") diff --git a/src/query/frontend/ast/ast.cpp b/src/query/frontend/ast/ast.cpp index 2b9206e48..c39e0aae0 100644 --- a/src/query/frontend/ast/ast.cpp +++ b/src/query/frontend/ast/ast.cpp @@ -2,9 +2,6 @@ #include -#include "storage/serialization.hpp" -#include "utils/serialization.capnp.h" - namespace query { AstStorage::AstStorage() { @@ -33,15 +30,4 @@ ReturnBody CloneReturnBody(AstStorage &storage, const ReturnBody &body) { return new_body; } -// Capnproto serialization. -Tree *AstStorage::Load(const capnp::Tree::Reader &tree, - std::vector *loaded_uids) { - storage_.clear(); - std::unique_ptr root; - ::query::Load(&root, tree, this, loaded_uids); - root_idx_ = storage_.size(); - storage_.emplace_back(std::move(root)); - return storage_[root_idx_].get(); -} - } // namespace query diff --git a/src/query/frontend/ast/ast.lcp b/src/query/frontend/ast/ast.lcp index 212bc29bb..595404e7f 100644 --- a/src/query/frontend/ast/ast.lcp +++ b/src/query/frontend/ast/ast.lcp @@ -11,9 +11,6 @@ #include "query/typed_value.hpp" #include "storage/property_value.hpp" #include "storage/types.hpp" -#include "utils/serialization.hpp" - -#include "ast.capnp.h" // Hash function for the key in pattern atom property maps. namespace std { @@ -35,10 +32,6 @@ class GraphDbAccessor; } cpp<# -(lcp:in-impl - #>cpp - #include "storage/serialization.hpp" - cpp<#) (lcp:namespace query) (lcp:capnp-namespace "query") @@ -168,12 +161,10 @@ class AstStorage { Query *query() const; - Tree *Load(const capnp::Tree::Reader &tree, std::vector *loaded_uids); - - private: + // Public only for serialization access + std::vector> storage_; int next_uid_ = 0; size_t root_idx_; - std::vector> storage_; }; cpp<# @@ -2504,4 +2495,4 @@ cpp<# #undef CLONE_UNARY_EXPRESSION cpp<# -(lcp:pop-namespace) ; namespace query +(lcp:pop-namespace) ;; namespace query diff --git a/src/query/frontend/ast/ast_serialization.lcp b/src/query/frontend/ast/ast_serialization.lcp new file mode 100644 index 000000000..640d71718 --- /dev/null +++ b/src/query/frontend/ast/ast_serialization.lcp @@ -0,0 +1,31 @@ +#>cpp +#pragma once + +#include "query/frontend/ast/ast.hpp" +#include "query/frontend/ast/ast_serialization.capnp.h" +#include "storage/serialization.hpp" +cpp<# + +(load "query/frontend/ast/ast.lcp") + +(lcp:namespace query) + +#>cpp +Tree *Load(AstStorage *ast, const capnp::Tree::Reader &tree, + std::vector *loaded_uids); +cpp<# + +(lcp:in-impl + #>cpp + Tree *Load(AstStorage *ast, const capnp::Tree::Reader &tree, + std::vector *loaded_uids) { + ast->storage_.clear(); + std::unique_ptr root; + ::query::Load(&root, tree, ast, loaded_uids); + ast->root_idx_ = ast->storage_.size(); + ast->storage_.emplace_back(std::move(root)); + return ast->storage_[ast->root_idx_].get(); + } + cpp<#) + +(lcp:pop-namespace) ;; namespace query diff --git a/src/query/plan/distributed_ops.lcp b/src/query/plan/distributed_ops.lcp index b42b6a1c0..87a8da96d 100644 --- a/src/query/plan/distributed_ops.lcp +++ b/src/query/plan/distributed_ops.lcp @@ -3,9 +3,9 @@ #pragma once +#include "query/frontend/ast/ast_serialization.hpp" #include "query/plan/distributed_ops.capnp.h" #include "query/plan/operator.hpp" - cpp<# (load "query/plan/operator.lcp") diff --git a/src/query/plan/operator.lcp b/src/query/plan/operator.lcp index 38125ea06..8cd807d92 100644 --- a/src/query/plan/operator.lcp +++ b/src/query/plan/operator.lcp @@ -139,7 +139,7 @@ cpp<# (lcp:capnp-import 'utils "/utils/serialization.capnp") (lcp:capnp-import 'storage "/storage/serialization.capnp") -(lcp:capnp-import 'ast "/query/frontend/ast/ast.capnp") +(lcp:capnp-import 'ast "/query/frontend/ast/ast_serialization.capnp") (lcp:capnp-import 'semantic "/query/frontend/semantic/symbol.capnp") (lcp:capnp-import 'query "/query/serialization.capnp") diff --git a/src/query/serialization.capnp b/src/query/serialization.capnp index 9c3c75432..35bb60fcc 100644 --- a/src/query/serialization.capnp +++ b/src/query/serialization.capnp @@ -1,6 +1,6 @@ @0xf47e119e21912f20; -using Ast = import "/query/frontend/ast/ast.capnp"; +using Ast = import "/query/frontend/ast/ast_serialization.capnp"; using Cxx = import "/capnp/c++.capnp"; using Storage = import "/storage/serialization.capnp"; using Utils = import "/utils/serialization.capnp"; diff --git a/src/query/serialization.cpp b/src/query/serialization.cpp index 648c363ae..1d7609aa1 100644 --- a/src/query/serialization.cpp +++ b/src/query/serialization.cpp @@ -1,4 +1,4 @@ -#include "serialization.hpp" +#include "query/serialization.hpp" #include "distributed/data_manager.hpp" diff --git a/tests/unit/cypher_main_visitor.cpp b/tests/unit/cypher_main_visitor.cpp index 7c220b280..01b9671fb 100644 --- a/tests/unit/cypher_main_visitor.cpp +++ b/tests/unit/cypher_main_visitor.cpp @@ -11,13 +11,14 @@ #include "query/context.hpp" #include "query/frontend/ast/ast.hpp" +#include "query/frontend/ast/ast_serialization.hpp" #include "query/frontend/ast/cypher_main_visitor.hpp" #include "query/frontend/opencypher/parser.hpp" #include "query/frontend/stripped.hpp" #include "query/typed_value.hpp" #include "capnp/message.h" -#include "query/frontend/ast/ast.capnp.h" +#include "query/frontend/ast/ast_serialization.capnp.h" namespace { @@ -166,7 +167,7 @@ class CapnpAstGenerator : public Base { const query::capnp::Tree::Reader reader = message.getRoot(); std::vector loaded_uids; - new_ast.Load(reader, &loaded_uids); + Load(&new_ast, reader, &loaded_uids); } return new_ast; }()),