Skip to content

Commit d9c90ba

Browse files
Introducing new llvm_pattern_matching_failure_event to Proof Events (#1134)
Fixes: Pi-Squared-Inc/pi2#1722 This PR introduces a new function event called `llvm_pattern_matching_failure_event`, which is identified by the `pattern_matching_failure_sentinel`. This new event flags to the user that an attempt to apply a rule failed in pattern matching its constructor; therefore, no further simplification can be done at this point.
1 parent bd52e46 commit d9c90ba

File tree

92 files changed

+248
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+248
-87
lines changed

docs/proof-trace.md

Lines changed: 5 additions & 0 deletions

include/kllvm/binary/ProofTraceParser.h

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ constexpr uint64_t hook_result_sentinel = detail::word(0xBB);
3434
constexpr uint64_t rule_event_sentinel = detail::word(0x22);
3535
constexpr uint64_t side_condition_event_sentinel = detail::word(0xEE);
3636
constexpr uint64_t side_condition_end_sentinel = detail::word(0x33);
37+
constexpr uint64_t pattern_matching_failure_sentinel = detail::word(0x44);
3738

3839
class llvm_step_event : public std::enable_shared_from_this<llvm_step_event> {
3940
public:
@@ -149,6 +150,28 @@ class llvm_side_condition_end_event : public llvm_step_event {
149150
const override;
150151
};
151152

153+
class llvm_pattern_matching_failure_event : public llvm_step_event {
154+
private:
155+
std::string function_name_;
156+
157+
llvm_pattern_matching_failure_event(std::string function_name)
158+
: function_name_(std::move(function_name)) { }
159+
160+
public:
161+
static sptr<llvm_pattern_matching_failure_event>
162+
create(std::string function_name) {
163+
return sptr<llvm_pattern_matching_failure_event>(
164+
new llvm_pattern_matching_failure_event(std::move(function_name)));
165+
}
166+
167+
[[nodiscard]] std::string const &get_function_name() const {
168+
return function_name_;
169+
}
170+
171+
void print(std::ostream &out, bool expand_terms, unsigned indent = 0U)
172+
const override;
173+
};
174+
152175
class llvm_event;
153176

154177
class llvm_function_event : public llvm_step_event {
@@ -296,7 +319,7 @@ class llvm_rewrite_trace {
296319

297320
class proof_trace_parser {
298321
public:
299-
static constexpr uint32_t expected_version = 11U;
322+
static constexpr uint32_t expected_version = 12U;
300323

301324
private:
302325
bool verbose_;
@@ -545,6 +568,22 @@ class proof_trace_parser {
545568
return event;
546569
}
547570

571+
sptr<llvm_pattern_matching_failure_event> static parse_pattern_matching_failure(
572+
proof_trace_buffer &buffer) {
573+
if (!buffer.check_word(pattern_matching_failure_sentinel)) {
574+
return nullptr;
575+
}
576+
577+
std::string function_name;
578+
if (!buffer.read_string(function_name)) {
579+
return nullptr;
580+
}
581+
582+
auto event = llvm_pattern_matching_failure_event::create(function_name);
583+
584+
return event;
585+
}
586+
548587
bool parse_argument(proof_trace_buffer &buffer, llvm_event &event) {
549588
if (!buffer.eof() && buffer.peek() == '\x7F') {
550589
uint64_t pattern_len = 0;
@@ -608,6 +647,16 @@ class proof_trace_parser {
608647
return true;
609648
}
610649

650+
case pattern_matching_failure_sentinel: {
651+
auto pattern_matching_failure_event
652+
= parse_pattern_matching_failure(buffer);
653+
if (!pattern_matching_failure_event) {
654+
return false;
655+
}
656+
event.set_step_event(pattern_matching_failure_event);
657+
return true;
658+
}
659+
611660
default: return false;
612661
}
613662
}
@@ -629,6 +678,9 @@ class proof_trace_parser {
629678

630679
case side_condition_end_sentinel: return parse_side_condition_end(buffer);
631680

681+
case pattern_matching_failure_sentinel:
682+
return parse_pattern_matching_failure(buffer);
683+
632684
default: return nullptr;
633685
}
634686
}

include/kllvm/codegen/ProofEvent.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ class proof_event {
129129
kore_axiom_declaration const &axiom, llvm::Value *check_result,
130130
llvm::BasicBlock *current_block);
131131

132+
[[nodiscard]] llvm::BasicBlock *pattern_matching_failure(
133+
kore_composite_pattern const &pattern, llvm::BasicBlock *current_block);
134+
132135
proof_event(kore_definition *definition, llvm::Module *module)
133136
: definition_(definition)
134137
, module_(module)

lib/binary/ProofTraceParser.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ void llvm_side_condition_end_event::print(
7777
(result_ ? "true" : "false"));
7878
}
7979

80+
void llvm_pattern_matching_failure_event::print(
81+
std::ostream &out, bool expand_terms, unsigned ind) const {
82+
std::string indent(ind * indent_size, ' ');
83+
out << fmt::format(
84+
"{}pattern matching failure: {}\n", indent, function_name_);
85+
}
86+
8087
void llvm_function_event::print(
8188
std::ostream &out, bool expand_terms, unsigned ind) const {
8289
std::string indent(ind * indent_size, ' ');

lib/codegen/Decision.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,8 @@ void add_owise(
922922
auto var = kore_variable_pattern::create(name, symbol->get_arguments()[i]);
923923
pat->add_argument(std::move(var));
924924
}
925+
proof_event p(d, module);
926+
stuck = p.pattern_matching_failure(*pat, stuck);
925927
create_term creator = create_term(final_subst, d, stuck, module, true);
926928
llvm::Value *retval = creator(pat.get()).first;
927929

lib/codegen/ProofEvent.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,4 +381,24 @@ llvm::BasicBlock *proof_event::side_condition_event_post(
381381
return merge_block;
382382
}
383383

384+
llvm::BasicBlock *proof_event::pattern_matching_failure(
385+
kore_composite_pattern const &pattern, llvm::BasicBlock *current_block) {
386+
387+
if (!proof_hint_instrumentation) {
388+
return current_block;
389+
}
390+
391+
auto [true_block, merge_block, proof_writer]
392+
= event_prelude("pattern_matching_failure", current_block);
393+
394+
std::string function_name = ast_to_string(*pattern.get_constructor());
395+
396+
emit_write_uint64(proof_writer, detail::word(0x44), true_block);
397+
emit_write_string(proof_writer, function_name, true_block);
398+
399+
llvm::BranchInst::Create(merge_block, true_block);
400+
401+
return merge_block;
402+
}
403+
384404
} // namespace kllvm

runtime/util/util.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ block *construct_raw_term(void *subject, char const *sort, bool raw_value) {
3535
}
3636

3737
void print_proof_hint_header(kllvm::proof_trace_writer *writer) {
38-
uint32_t version = 11;
38+
uint32_t version = 12;
3939
writer->write_string("HINT");
4040
writer->write_uint32(version);
4141
}

test/output/add-rewrite/input.proof.debug.out.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 11
1+
version: 12
22
hook: MAP.element Lbl'UndsPipe'-'-GT-Unds'{} ()
33
function: Lbl'UndsPipe'-'-GT-Unds'{} ()
44
arg: kore[\dv{SortKConfigVar{}}("$PGM")]

test/output/add-rewrite/input.proof.out.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 11
1+
version: 12
22
hook: MAP.element Lbl'UndsPipe'-'-GT-Unds'{} ()
33
function: Lbl'UndsPipe'-'-GT-Unds'{} ()
44
arg: kore[\dv{SortKConfigVar{}}("$PGM")]

test/output/arith/add.proof.out.diff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: 11
1+
version: 12
22
hook: MAP.element Lbl'UndsPipe'-'-GT-Unds'{} ()
33
function: Lbl'UndsPipe'-'-GT-Unds'{} ()
44
arg: kore[\dv{SortKConfigVar{}}("$PGM")]

0 commit comments

Comments
 (0)