Skip to content

Commit c234191

Browse files
authored
Add raw term symbol to definitions (#907)
This is an alternative formulation to runtimeverification/k#3829; that PR contains the original context for why this change is necessary. Rather than adding a regular symbol to the K standard library source and using a check in the frontend to ensure that user code doesn't mention it, we directly emit a symbol into each definition with a name that the frontend cannot reference. We also bump the version number for the proof hint format so that this non-standard symbol must be explicitly accepted by the Python client code.
1 parent 6046ece commit c234191

File tree

6 files changed

+35
-2
lines changed

6 files changed

+35
-2
lines changed

include/kllvm/ast/AST.h

+7
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,13 @@ class KOREDefinition {
905905

906906
KORESymbol *injSymbol;
907907

908+
/*
909+
* Insert symbols into this definition that have knowable labels, but cannot
910+
* be directly referenced in user code:
911+
* - rawTerm(KItem) for serializing non-symbol backend terms
912+
*/
913+
void insertReservedSymbols();
914+
908915
public:
909916
static ptr<KOREDefinition> Create() {
910917
return ptr<KOREDefinition>(new KOREDefinition());

include/kllvm/binary/ProofTraceValidator.h

+4
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,10 @@ class ProofTraceValidator {
152152
return false;
153153
}
154154

155+
if (version != 3) {
156+
return false;
157+
}
158+
155159
print(fmt::format("version: {}", version));
156160

157161
return true;

include/runtime/header.h

+1
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ extern const uint32_t first_inj_tag, last_inj_tag;
407407
bool is_injection(block *);
408408
block *strip_injection(block *);
409409
block *constructKItemInj(void *subject, const char *sort, bool raw_value);
410+
block *constructRawTerm(void *subject, const char *sort);
410411
}
411412

412413
std::string floatToString(const floating *);

lib/ast/AST.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -1709,7 +1709,21 @@ void KOREDefinition::addAttribute(sptr<KORECompositePattern> Attribute) {
17091709
attributes.insert({name, std::move(Attribute)});
17101710
}
17111711

1712+
void KOREDefinition::insertReservedSymbols() {
1713+
auto mod = KOREModule::Create("K-RAW-TERM");
1714+
auto decl = KORESymbolDeclaration::Create("rawTerm", true);
1715+
auto sort = KORECompositeSort::Create("SortKItem");
1716+
1717+
decl->getSymbol()->addSort(sort);
1718+
decl->getSymbol()->addArgument(sort);
1719+
mod->addDeclaration(std::move(decl));
1720+
1721+
addModule(std::move(mod));
1722+
}
1723+
17121724
void KOREDefinition::preprocess() {
1725+
insertReservedSymbols();
1726+
17131727
for (auto iter = axioms.begin(); iter != axioms.end(); ++iter) {
17141728
auto axiom = *iter;
17151729
axiom->pattern = axiom->pattern->expandAliases(this);

runtime/util/ConfigurationSerializer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ void serializeTermToFile(
440440

441441
void serializeRawTermToFile(
442442
const char *filename, void *subject, const char *sort) {
443-
block *term = constructKItemInj(subject, sort, true);
443+
block *term = constructRawTerm(subject, sort);
444444

445445
char *data;
446446
size_t size;

runtime/util/util.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,15 @@ block *constructKItemInj(void *subject, const char *sort, bool raw_value) {
2929
return static_cast<block *>(constructCompositePattern(tag, args));
3030
}
3131

32+
block *constructRawTerm(void *subject, const char *sort) {
33+
auto tag = getTagForSymbolName("rawTerm{}");
34+
auto args = std::vector{
35+
static_cast<void *>(constructKItemInj(subject, sort, true))};
36+
return static_cast<block *>(constructCompositePattern(tag, args));
37+
}
38+
3239
void printProofHintHeader(char *output_file) {
33-
uint32_t version = 2;
40+
uint32_t version = 3;
3441
FILE *file = fopen(output_file, "a");
3542
fprintf(file, "HINT");
3643
fwrite(&version, sizeof(version), 1, file);

0 commit comments

Comments
 (0)