From 5c0175d90a583578f4e1575c3154aa39686c1545 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 4 Feb 2019 22:10:19 +1100 Subject: [PATCH] Remove peephole regex optimization pass The current implementation is wrong as it crosses basic blocks boundaries. Doing basic block decomposition of regex is probably a tad too complex for this single optimization. Fixes #2711 --- src/regex_impl.cc | 17 ----------------- .../2711-weird-regex-highlighter-behaviour/cmd | 1 + .../2711-weird-regex-highlighter-behaviour/in | 1 + .../2711-weird-regex-highlighter-behaviour/rc | 1 + .../ui-out | 7 +++++++ 5 files changed, 10 insertions(+), 17 deletions(-) create mode 100644 test/regression/2711-weird-regex-highlighter-behaviour/cmd create mode 100644 test/regression/2711-weird-regex-highlighter-behaviour/in create mode 100644 test/regression/2711-weird-regex-highlighter-behaviour/rc create mode 100644 test/regression/2711-weird-regex-highlighter-behaviour/ui-out diff --git a/src/regex_impl.cc b/src/regex_impl.cc index 1ff73472..78ddb375 100644 --- a/src/regex_impl.cc +++ b/src/regex_impl.cc @@ -684,7 +684,6 @@ struct RegexCompiler { m_program.forward_start_desc = compute_start_desc(); compile_node(0); - peephole_optimize(0, m_program.instructions.size()); push_inst(CompiledRegex::Match); } @@ -693,7 +692,6 @@ struct RegexCompiler m_program.first_backward_inst = m_program.instructions.size(); m_program.backward_start_desc = compute_start_desc(); compile_node(0); - peephole_optimize(m_program.first_backward_inst, m_program.instructions.size()); push_inst(CompiledRegex::Match); } else @@ -1021,21 +1019,6 @@ private: return std::make_unique(start_desc); } - void peephole_optimize(size_t begin, size_t end) - { - if (not (m_flags & RegexCompileFlags::Optimize)) - return; - - // Move saves after all assertions on the same character - auto is_assertion = [](CompiledRegex::Op op) { return op >= CompiledRegex::LineStart; }; - for (auto i = begin, j = begin + 1; j < end; ++i, ++j) - { - if (m_program.instructions[i].op == CompiledRegex::Save and - is_assertion(m_program.instructions[j].op)) - std::swap(m_program.instructions[i], m_program.instructions[j]); - } - } - const ParsedRegex::Node& get_node(ParsedRegex::NodeIndex index) const { return m_parsed_regex.nodes[index]; diff --git a/test/regression/2711-weird-regex-highlighter-behaviour/cmd b/test/regression/2711-weird-regex-highlighter-behaviour/cmd new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/test/regression/2711-weird-regex-highlighter-behaviour/cmd @@ -0,0 +1 @@ + diff --git a/test/regression/2711-weird-regex-highlighter-behaviour/in b/test/regression/2711-weird-regex-highlighter-behaviour/in new file mode 100644 index 00000000..6f0c951f --- /dev/null +++ b/test/regression/2711-weird-regex-highlighter-behaviour/in @@ -0,0 +1 @@ +foo.bar(); diff --git a/test/regression/2711-weird-regex-highlighter-behaviour/rc b/test/regression/2711-weird-regex-highlighter-behaviour/rc new file mode 100644 index 00000000..bf82861a --- /dev/null +++ b/test/regression/2711-weird-regex-highlighter-behaviour/rc @@ -0,0 +1 @@ +add-highlighter buffer/ regex ((?))[a-zA-Z](\w+)?\b(?![>"\(]) 0:red diff --git a/test/regression/2711-weird-regex-highlighter-behaviour/ui-out b/test/regression/2711-weird-regex-highlighter-behaviour/ui-out new file mode 100644 index 00000000..c526a3c0 --- /dev/null +++ b/test/regression/2711-weird-regex-highlighter-behaviour/ui-out @@ -0,0 +1,7 @@ +{ "jsonrpc": "2.0", "method": "set_ui_options", "params": [{}] } +{ "jsonrpc": "2.0", "method": "draw", "params": [[[{ "face": { "fg": "black", "bg": "white", "attributes": [] }, "contents": "f" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "oo.bar();\u000a" }]], { "fg": "default", "bg": "default", "attributes": [] }, { "fg": "blue", "bg": "default", "attributes": [] }] } +{ "jsonrpc": "2.0", "method": "menu_hide", "params": [] } +{ "jsonrpc": "2.0", "method": "info_hide", "params": [] } +{ "jsonrpc": "2.0", "method": "draw_status", "params": [[], [{ "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": "out 1:1 " }, { "face": { "fg": "black", "bg": "yellow", "attributes": [] }, "contents": "" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " " }, { "face": { "fg": "blue", "bg": "default", "attributes": [] }, "contents": "1 sel" }, { "face": { "fg": "default", "bg": "default", "attributes": [] }, "contents": " - client0@[kak-tests]" }], { "fg": "cyan", "bg": "default", "attributes": [] }] } +{ "jsonrpc": "2.0", "method": "set_cursor", "params": ["buffer", { "line": 0, "column": 0 }] } +{ "jsonrpc": "2.0", "method": "refresh", "params": [true] }