diff options
-rw-r--r-- | src/mongo/db/exec/sbe/expressions/expression.cpp | 47 | ||||
-rw-r--r-- | src/mongo/db/exec/sbe/stages/union.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/exec/sbe/util/debug_print.cpp | 11 |
3 files changed, 49 insertions, 24 deletions
diff --git a/src/mongo/db/exec/sbe/expressions/expression.cpp b/src/mongo/db/exec/sbe/expressions/expression.cpp index d337cd8fa14..7176ce3e56a 100644 --- a/src/mongo/db/exec/sbe/expressions/expression.cpp +++ b/src/mongo/db/exec/sbe/expressions/expression.cpp @@ -239,6 +239,7 @@ std::vector<DebugPrinter::Block> EPrimBinary::debugPrint() const { invariant(!hasCollatorArg || isComparisonOp(_op)); + ret.emplace_back("(`"); DebugPrinter::addBlocks(ret, _nodes[0]->debugPrint()); switch (_op) { @@ -292,6 +293,7 @@ std::vector<DebugPrinter::Block> EPrimBinary::debugPrint() const { } DebugPrinter::addBlocks(ret, _nodes[1]->debugPrint()); + ret.emplace_back("`)"); return ret; } @@ -335,7 +337,9 @@ std::vector<DebugPrinter::Block> EPrimUnary::debugPrint() const { MONGO_UNREACHABLE; } + ret.emplace_back("`(`"); DebugPrinter::addBlocks(ret, _nodes[0]->debugPrint()); + ret.emplace_back("`)"); return ret; } @@ -733,7 +737,7 @@ std::vector<DebugPrinter::Block> EFunction::debugPrint() const { std::vector<DebugPrinter::Block> ret; DebugPrinter::addKeyword(ret, _name); - ret.emplace_back("(`"); + ret.emplace_back("`(`"); for (size_t idx = 0; idx < _nodes.size(); ++idx) { if (idx) { ret.emplace_back("`,"); @@ -780,20 +784,24 @@ vm::CodeFragment EIf::compileDirect(CompileCtx& ctx) const { std::vector<DebugPrinter::Block> EIf::debugPrint() const { std::vector<DebugPrinter::Block> ret; - DebugPrinter::addKeyword(ret, "if"); - ret.emplace_back("(`"); + ret.emplace_back(DebugPrinter::Block::cmdIncIndent); // Print the condition. + DebugPrinter::addKeyword(ret, "if"); DebugPrinter::addBlocks(ret, _nodes[0]->debugPrint()); - ret.emplace_back("`,"); + DebugPrinter::addNewLine(ret); + // Print thenBranch. + DebugPrinter::addKeyword(ret, "then"); DebugPrinter::addBlocks(ret, _nodes[1]->debugPrint()); - ret.emplace_back("`,"); + DebugPrinter::addNewLine(ret); + // Print elseBranch. + DebugPrinter::addKeyword(ret, "else"); DebugPrinter::addBlocks(ret, _nodes[2]->debugPrint()); - ret.emplace_back("`)"); + ret.emplace_back(DebugPrinter::Block::cmdDecIndent); return ret; } @@ -836,22 +844,30 @@ vm::CodeFragment ELocalBind::compileDirect(CompileCtx& ctx) const { std::vector<DebugPrinter::Block> ELocalBind::debugPrint() const { std::vector<DebugPrinter::Block> ret; - DebugPrinter::addKeyword(ret, "let"); + ret.emplace_back(DebugPrinter::Block::cmdIncIndent); + DebugPrinter::addKeyword(ret, "let"); ret.emplace_back("[`"); + ret.emplace_back(DebugPrinter::Block::cmdIncIndent); + for (size_t idx = 0; idx < _nodes.size() - 1; ++idx) { if (idx != 0) { - ret.emplace_back("`,"); + DebugPrinter::addNewLine(ret); } DebugPrinter::addIdentifier(ret, _frameId, idx); ret.emplace_back("="); DebugPrinter::addBlocks(ret, _nodes[idx]->debugPrint()); } - ret.emplace_back("`]"); + ret.emplace_back(DebugPrinter::Block::cmdDecIndent); + ret.emplace_back("]"); + DebugPrinter::addNewLine(ret); + DebugPrinter::addKeyword(ret, "in"); DebugPrinter::addBlocks(ret, _nodes.back()->debugPrint()); + ret.emplace_back(DebugPrinter::Block::cmdDecIndent); + return ret; } @@ -896,10 +912,13 @@ vm::CodeFragment ELocalLambda::compileDirect(CompileCtx& ctx) const { std::vector<DebugPrinter::Block> ELocalLambda::debugPrint() const { std::vector<DebugPrinter::Block> ret; - DebugPrinter::addKeyword(ret, "\\"); + DebugPrinter::addKeyword(ret, "lambda"); + ret.emplace_back("`(`"); DebugPrinter::addIdentifier(ret, _frameId, 0); - ret.emplace_back("."); + ret.emplace_back("`)"); + ret.emplace_back("{"); DebugPrinter::addBlocks(ret, _nodes.back()->debugPrint()); + ret.emplace_back("}"); return ret; } @@ -930,11 +949,13 @@ std::vector<DebugPrinter::Block> EFail::debugPrint() const { std::vector<DebugPrinter::Block> ret; DebugPrinter::addKeyword(ret, "fail"); - ret.emplace_back("("); + ret.emplace_back("`(`"); ret.emplace_back(std::to_string(_code)); - ret.emplace_back(",`"); + ret.emplace_back("`,"); + ret.emplace_back("\"`"); ret.emplace_back(getStringView(_messageTag, _messageVal)); + ret.emplace_back("`\"`"); ret.emplace_back("`)"); diff --git a/src/mongo/db/exec/sbe/stages/union.cpp b/src/mongo/db/exec/sbe/stages/union.cpp index 2fd6d0b4fc5..9d619f2f505 100644 --- a/src/mongo/db/exec/sbe/stages/union.cpp +++ b/src/mongo/db/exec/sbe/stages/union.cpp @@ -27,10 +27,10 @@ * it in the license file. */ -#include "mongo/platform/basic.h" - #include "mongo/db/exec/sbe/stages/union.h" +#include <fmt/format.h> + #include "mongo/db/exec/sbe/expressions/expression.h" #include "mongo/db/exec/sbe/size_estimator.h" @@ -197,9 +197,10 @@ std::vector<DebugPrinter::Block> UnionStage::debugPrint() const { } ret.emplace_back(DebugPrinter::Block("`]")); - ret.emplace_back(DebugPrinter::Block("[`")); ret.emplace_back(DebugPrinter::Block::cmdIncIndent); for (size_t childNum = 0; childNum < _children.size(); childNum++) { + DebugPrinter::addKeyword(ret, "branch{}"_format(childNum)); + ret.emplace_back(DebugPrinter::Block("[`")); for (size_t idx = 0; idx < _inputVals[childNum].size(); idx++) { if (idx) { @@ -209,15 +210,11 @@ std::vector<DebugPrinter::Block> UnionStage::debugPrint() const { } ret.emplace_back(DebugPrinter::Block("`]")); + ret.emplace_back(DebugPrinter::Block::cmdIncIndent); DebugPrinter::addBlocks(ret, _children[childNum]->debugPrint()); - - if (childNum + 1 < _children.size()) { - ret.emplace_back(DebugPrinter::Block(",")); - DebugPrinter::addNewLine(ret); - } + ret.emplace_back(DebugPrinter::Block::cmdDecIndent); } ret.emplace_back(DebugPrinter::Block::cmdDecIndent); - ret.emplace_back(DebugPrinter::Block("`]")); return ret; } diff --git a/src/mongo/db/exec/sbe/util/debug_print.cpp b/src/mongo/db/exec/sbe/util/debug_print.cpp index e3d831b5ab5..c4b210e9a7a 100644 --- a/src/mongo/db/exec/sbe/util/debug_print.cpp +++ b/src/mongo/db/exec/sbe/util/debug_print.cpp @@ -38,6 +38,7 @@ namespace sbe { std::string DebugPrinter::print(const std::vector<Block>& blocks) { std::string ret; int ident = 0; + size_t blockIndex = 0; for (auto& b : blocks) { bool addSpace = true; switch (b.cmd) { @@ -48,8 +49,13 @@ std::string DebugPrinter::print(const std::vector<Block>& blocks) { break; case Block::cmdDecIndent: --ident; - ret.append("\n"); - addIndent(ident, ret); + // Avoid unnecessary whitespace if there are multiple adjacent "decrement indent" + // tokens. + if (blockIndex == blocks.size() || + blocks[blockIndex + 1].cmd != Block::cmdDecIndent) { + ret.append("\n"); + addIndent(ident, ret); + } break; case Block::cmdNewLine: ret.append("\n"); @@ -111,6 +117,7 @@ std::string DebugPrinter::print(const std::vector<Block>& blocks) { } } } + ++blockIndex; } return ret; |