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
This commit is contained in:
Maxime Coste 2019-02-04 22:10:19 +11:00
parent d9d2140ea2
commit 5c0175d90a
5 changed files with 10 additions and 17 deletions

View File

@ -684,7 +684,6 @@ struct RegexCompiler
{
m_program.forward_start_desc = compute_start_desc<RegexMode::Forward>();
compile_node<RegexMode::Forward>(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<RegexMode::Backward>();
compile_node<RegexMode::Backward>(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<CompiledRegex::StartDesc>(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];

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
foo.bar();

View File

@ -0,0 +1 @@
add-highlighter buffer/ regex ((?<!\.\.)(?<=\.)|(?<=->))[a-zA-Z](\w+)?\b(?![>"\(]) 0:red

View File

@ -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] }