The checked-arithmetic helpers every generated module carries no longer test __TINYC__.
3684 lines
144 KiB
C
3684 lines
144 KiB
C
/* Generated by zi2c from compiler_proof.zi. */
|
|
#include <stdbool.h>
|
|
#include "zir_bounds.h"
|
|
#include "zir_string.h"
|
|
#include "zir_vec.h"
|
|
#define ZIRAN_COMPILER_PROOF_H_PRIVATE 1
|
|
#include "compiler_proof.h"
|
|
#undef ZIRAN_COMPILER_PROOF_H_PRIVATE
|
|
#ifndef ZIRAN_HELPER_ZiShl32
|
|
#define ZIRAN_HELPER_ZiShl32
|
|
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__)
|
|
#define ZiShl32(a, s, w) __extension__ ({ uint32_t __zi_a = (a); uint64_t __zi_s = (s); if(__zi_s >= (uint64_t)(w)) abort(); (uint32_t)(__zi_a << __zi_s); })
|
|
#else
|
|
static inline uint32_t ZiShl32(uint32_t a, uint64_t s, int w) {
|
|
if(s >= (uint64_t)w) abort();
|
|
return (uint32_t)(a << s);
|
|
}
|
|
#endif
|
|
#endif
|
|
|
|
#ifndef ZIRAN_HELPER_ZiShl64
|
|
#define ZIRAN_HELPER_ZiShl64
|
|
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__)
|
|
#define ZiShl64(a, s, w) __extension__ ({ uint64_t __zi_a = (a); uint64_t __zi_s = (s); if(__zi_s >= (uint64_t)(w)) abort(); (uint64_t)(__zi_a << __zi_s); })
|
|
#else
|
|
static inline uint64_t ZiShl64(uint64_t a, uint64_t s, int w) {
|
|
if(s >= (uint64_t)w) abort();
|
|
return (uint64_t)(a << s);
|
|
}
|
|
#endif
|
|
#endif
|
|
#include "vec.h"
|
|
#ifndef ZIR_FOREIGN_zir_f_5116a9a569c28f15_FindType_2a8e44a3
|
|
#define ZIR_FOREIGN_zir_f_5116a9a569c28f15_FindType_2a8e44a3
|
|
#ifdef __APPLE__
|
|
ZirType* zir_foreign_zir_f_5116a9a569c28f15_FindType(ZirModule* m, uint8_t* name, ZirModule** owner) __asm__("_FindType");
|
|
#else
|
|
ZirType* zir_foreign_zir_f_5116a9a569c28f15_FindType(ZirModule* m, uint8_t* name, ZirModule** owner) __asm__("FindType");
|
|
#endif
|
|
static ZirType*
|
|
zir_f_5116a9a569c28f15_FindType(ZirModule* m, uint8_t* name, ZirModule** owner)
|
|
{
|
|
return zir_foreign_zir_f_5116a9a569c28f15_FindType(m, name, owner);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_5116a9a569c28f15_EnumMemberValue_3400a243
|
|
#define ZIR_FOREIGN_zir_f_5116a9a569c28f15_EnumMemberValue_3400a243
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_5116a9a569c28f15_EnumMemberValue(ZirType* type, uint8_t* name, int64_t* value) __asm__("_EnumMemberValue");
|
|
#else
|
|
int32_t zir_foreign_zir_f_5116a9a569c28f15_EnumMemberValue(ZirType* type, uint8_t* name, int64_t* value) __asm__("EnumMemberValue");
|
|
#endif
|
|
static int32_t
|
|
zir_f_5116a9a569c28f15_EnumMemberValue(ZirType* type, uint8_t* name, int64_t* value)
|
|
{
|
|
return zir_foreign_zir_f_5116a9a569c28f15_EnumMemberValue(type, name, value);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_5116a9a569c28f15_ResolveFunction_08b348f2
|
|
#define ZIR_FOREIGN_zir_f_5116a9a569c28f15_ResolveFunction_08b348f2
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_5116a9a569c28f15_ResolveFunction(ZirModule* m, uint8_t* name, ZirModule** owner, ZirFunction** fn) __asm__("_ResolveFunction");
|
|
#else
|
|
int32_t zir_foreign_zir_f_5116a9a569c28f15_ResolveFunction(ZirModule* m, uint8_t* name, ZirModule** owner, ZirFunction** fn) __asm__("ResolveFunction");
|
|
#endif
|
|
static int32_t
|
|
zir_f_5116a9a569c28f15_ResolveFunction(ZirModule* m, uint8_t* name, ZirModule** owner, ZirFunction** fn)
|
|
{
|
|
return zir_foreign_zir_f_5116a9a569c28f15_ResolveFunction(m, name, owner, fn);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_5116a9a569c28f15_ParseExpr_4616b936
|
|
#define ZIR_FOREIGN_zir_f_5116a9a569c28f15_ParseExpr_4616b936
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_5116a9a569c28f15_ParseExpr(ZirFunction* fn, ZirModule* m, uint8_t* text, ZirSourceSpan span) __asm__("_ParseExprNoDefaults");
|
|
#else
|
|
int32_t zir_foreign_zir_f_5116a9a569c28f15_ParseExpr(ZirFunction* fn, ZirModule* m, uint8_t* text, ZirSourceSpan span) __asm__("ParseExprNoDefaults");
|
|
#endif
|
|
static int32_t
|
|
zir_f_5116a9a569c28f15_ParseExpr(ZirFunction* fn, ZirModule* m, uint8_t* text, ZirSourceSpan span)
|
|
{
|
|
return zir_foreign_zir_f_5116a9a569c28f15_ParseExpr(fn, m, text, span);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_5116a9a569c28f15_FunctionAddStmt_b9288904
|
|
#define ZIR_FOREIGN_zir_f_5116a9a569c28f15_FunctionAddStmt_b9288904
|
|
#ifdef __APPLE__
|
|
ZirStmt* zir_foreign_zir_f_5116a9a569c28f15_FunctionAddStmt(ZirFunction* fn, ZirStmtKind kind, uint8_t* text, ZirSourceSpan span) __asm__("_FunctionAddStmt");
|
|
#else
|
|
ZirStmt* zir_foreign_zir_f_5116a9a569c28f15_FunctionAddStmt(ZirFunction* fn, ZirStmtKind kind, uint8_t* text, ZirSourceSpan span) __asm__("FunctionAddStmt");
|
|
#endif
|
|
static ZirStmt*
|
|
zir_f_5116a9a569c28f15_FunctionAddStmt(ZirFunction* fn, ZirStmtKind kind, uint8_t* text, ZirSourceSpan span)
|
|
{
|
|
return zir_foreign_zir_f_5116a9a569c28f15_FunctionAddStmt(fn, kind, text, span);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_5116a9a569c28f15_ModuleAddProof_3f5502ac
|
|
#define ZIR_FOREIGN_zir_f_5116a9a569c28f15_ModuleAddProof_3f5502ac
|
|
#ifdef __APPLE__
|
|
int32_t zir_foreign_zir_f_5116a9a569c28f15_ModuleAddProof(ZirModule* m, uint8_t* name, uint8_t* body, ZirSourceSpan span) __asm__("_ModuleAddProof");
|
|
#else
|
|
int32_t zir_foreign_zir_f_5116a9a569c28f15_ModuleAddProof(ZirModule* m, uint8_t* name, uint8_t* body, ZirSourceSpan span) __asm__("ModuleAddProof");
|
|
#endif
|
|
static int32_t
|
|
zir_f_5116a9a569c28f15_ModuleAddProof(ZirModule* m, uint8_t* name, uint8_t* body, ZirSourceSpan span)
|
|
{
|
|
return zir_foreign_zir_f_5116a9a569c28f15_ModuleAddProof(m, name, body, span);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_5116a9a569c28f15_calloc_793380be
|
|
#define ZIR_FOREIGN_zir_f_5116a9a569c28f15_calloc_793380be
|
|
#ifdef __APPLE__
|
|
uint8_t* zir_foreign_zir_f_5116a9a569c28f15_calloc(size_t count, size_t size) __asm__("_calloc");
|
|
#else
|
|
uint8_t* zir_foreign_zir_f_5116a9a569c28f15_calloc(size_t count, size_t size) __asm__("calloc");
|
|
#endif
|
|
static uint8_t*
|
|
zir_f_5116a9a569c28f15_calloc(size_t count, size_t size)
|
|
{
|
|
return zir_foreign_zir_f_5116a9a569c28f15_calloc(count, size);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_5116a9a569c28f15_realloc_bcfdb19b
|
|
#define ZIR_FOREIGN_zir_f_5116a9a569c28f15_realloc_bcfdb19b
|
|
#ifdef __APPLE__
|
|
uint8_t* zir_foreign_zir_f_5116a9a569c28f15_realloc(uint8_t* data, size_t size) __asm__("_realloc");
|
|
#else
|
|
uint8_t* zir_foreign_zir_f_5116a9a569c28f15_realloc(uint8_t* data, size_t size) __asm__("realloc");
|
|
#endif
|
|
static uint8_t*
|
|
zir_f_5116a9a569c28f15_realloc(uint8_t* data, size_t size)
|
|
{
|
|
return zir_foreign_zir_f_5116a9a569c28f15_realloc(data, size);
|
|
}
|
|
#endif
|
|
#ifndef ZIR_FOREIGN_zir_f_5116a9a569c28f15_free_cf3f1025
|
|
#define ZIR_FOREIGN_zir_f_5116a9a569c28f15_free_cf3f1025
|
|
#ifdef __APPLE__
|
|
void zir_foreign_zir_f_5116a9a569c28f15_free(uint8_t* data) __asm__("_free");
|
|
#else
|
|
void zir_foreign_zir_f_5116a9a569c28f15_free(uint8_t* data) __asm__("free");
|
|
#endif
|
|
static void
|
|
zir_f_5116a9a569c28f15_free(uint8_t* data)
|
|
{
|
|
zir_foreign_zir_f_5116a9a569c28f15_free(data);
|
|
}
|
|
#endif
|
|
#ifndef ZIRAN_MAYBE_UNUSED
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
#define ZIRAN_MAYBE_UNUSED __attribute__((unused))
|
|
#else
|
|
#define ZIRAN_MAYBE_UNUSED
|
|
#endif
|
|
#endif
|
|
static Spelled compiler_proof_C(String text) ZIRAN_MAYBE_UNUSED;
|
|
static Long compiler_proof_CLong(String text) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_Report(ZirSourceSpan span, String code, String message, String name, String tail) ZIRAN_MAYBE_UNUSED;
|
|
static String compiler_proof_Trim(String text) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Unsupported(Context* c, String reason) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_Tick(Context* c, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
|
static String compiler_proof_Args(ZirFunction* fn) ZIRAN_MAYBE_UNUSED;
|
|
static String compiler_proof_Name(Slice buffer) ZIRAN_MAYBE_UNUSED;
|
|
static int64_t compiler_proof_Index(String text, uint8_t byte) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_ParseSignature(String source, Signature* out) ZIRAN_MAYBE_UNUSED;
|
|
static String compiler_proof_Primitive(uint32_t width, bool ziran_keyword_unsigned_0) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_ScalarType(Context* c, ZirModule* m, String name) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_TermType(Context* c, int32_t term) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_SameType(Context* c, int32_t a, int32_t b) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Find(Environment* e, String name) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_Bind(Context* c, Environment* e, String name, int32_t value) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Constant(Context* c, int32_t type, uint64_t value) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Node(Context* c, ProofOp op, int32_t type, int32_t a, int32_t b) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_Valid(ZirFunction* fn, int32_t at) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_CallName(ZirFunction* fn, ZirExpr* call, Slice out) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_BlockClose(ZirFunction* fn, int32_t open, int32_t stop) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_FunctionValue(Context* c, ZirModule* m, ZirFunction* fn, Slice args, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Tag(Context* c, ZirFunction* fn, int32_t index, int32_t result) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Expression(Context* c, ZirModule* m, ZirFunction* fn, int32_t index, Environment* env, int32_t expected, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Binary(Context* c, ZirModule* m, ZirFunction* fn, ZirExpr* e, Environment* env, int32_t expected, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Call(Context* c, ZirModule* m, ZirFunction* fn, ZirExpr* e, Environment* env, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Arms(Context* c, ZirModule* m, ZirFunction* fn, Environment* env, int32_t at, int32_t after, Continuation* rest, int32_t result, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Sequence(Context* c, ZirModule* m, ZirFunction* fn, Environment* env, int32_t start, int32_t stop, Continuation* next, int32_t result, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
|
static ZirLaw* compiler_proof_FindLaw(ZirModule* m, String name, int32_t depth, ZirModule** owner) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_GraphVisit(ZirFunction* fn, int32_t at, Slice seen, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_GraphValid(ZirFunction* fn) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_ParseSteps(ZirProof* p, ZirModule* m) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_PrepareClaim(ZirModule* module, ZirLaw* law) ZIRAN_MAYBE_UNUSED;
|
|
static bool compiler_proof_PrepareProof(ZirModule* module, ZirProof* proof) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Application(Context* c, ZirModule* m, ZirProof* proof, ZirProofStep* step, Environment* env, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
|
static int32_t compiler_proof_Theorem(Context* c, ZirModule* m, ZirLaw* law, Slice args, int32_t depth) ZIRAN_MAYBE_UNUSED;
|
|
|
|
static Spelled
|
|
compiler_proof_C(String text)
|
|
{
|
|
Spelled name = {0};
|
|
Slice value_0 = {name.bytes, 128};
|
|
compiler_ir_CopyText(value_0, text);
|
|
return name;
|
|
}
|
|
|
|
static Long
|
|
compiler_proof_CLong(String text)
|
|
{
|
|
Long ziran_keyword_long_0 = {0};
|
|
Slice value_0 = {ziran_keyword_long_0.bytes, 4096};
|
|
compiler_ir_CopyText(value_0, text);
|
|
return ziran_keyword_long_0;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_Report(ZirSourceSpan span, String code, String message, String name, String tail)
|
|
{
|
|
compiler_services_Diagnose__overload_2(span, code, message, name, tail);
|
|
return false;
|
|
}
|
|
|
|
static String
|
|
compiler_proof_Trim(String text)
|
|
{
|
|
SourceRange range = compiler_text_TrimRange(text);
|
|
return StringRange(text, (int64_t)range.begin, (int64_t)range.end);
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Unsupported(Context* c, String reason)
|
|
{
|
|
bool* value_0 = &(c->unsupported);
|
|
(*value_0) = true;
|
|
String* value_1 = &(c->reason);
|
|
(*value_1) = reason;
|
|
return -1;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_Tick(Context* c, int32_t depth)
|
|
{
|
|
if (depth <= 64) {
|
|
int32_t* value_0 = &(c->kernel.budget);
|
|
(*value_0) = (int32_t)((uint32_t)((*value_0)) - 1u);
|
|
if (c->kernel.budget >= 0) {
|
|
return !c->kernel.exhausted;
|
|
}
|
|
}
|
|
bool* value_1 = &(c->kernel.exhausted);
|
|
(*value_1) = true;
|
|
return false;
|
|
}
|
|
|
|
static String
|
|
compiler_proof_Args(ZirFunction* fn)
|
|
{
|
|
return compiler_ir_CText((uint8_t*)fn->args_text);
|
|
}
|
|
|
|
static String
|
|
compiler_proof_Name(Slice buffer)
|
|
{
|
|
return compiler_ir_BufferText(buffer);
|
|
}
|
|
|
|
static int64_t
|
|
compiler_proof_Index(String text, uint8_t byte)
|
|
{
|
|
int64_t at = 0LL;
|
|
while (at < (int64_t)(text).length && (uint8_t)ZIRAN_INDEX(text.data, text.length, at) != byte) {
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
return at;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_ParseSignature(String source, Signature* out)
|
|
{
|
|
Signature* value_0 = &((*(out)));
|
|
(*value_0) = (Signature){0};
|
|
String value_1 = StringView(NULL, 0);
|
|
{
|
|
String text = source;
|
|
SourceRange range = compiler_text_TrimRange(text);
|
|
value_1 = StringRange(text, (int64_t)range.begin, (int64_t)range.end);
|
|
}
|
|
int64_t value_3 = (int64_t)(value_1).length;
|
|
int64_t value_4 = 0;
|
|
if (value_3 == 0LL) {
|
|
value_4 = -1LL;
|
|
} else {
|
|
value_4 = 0LL;
|
|
}
|
|
int64_t at = value_4;
|
|
while (at >= 0LL) {
|
|
SourcePart part = compiler_text_NextSourcePart(source, at);
|
|
String text = StringRange(source, (int64_t)part.begin, (int64_t)part.end);
|
|
int64_t colon = compiler_proof_Index(text, 58);
|
|
if (out->count == 16 || colon == (int64_t)(text).length) {
|
|
return false;
|
|
}
|
|
String value_5 = StringRange(text, (int64_t)0LL, (int64_t)colon);
|
|
String value_6 = StringView(NULL, 0);
|
|
{
|
|
String text = value_5;
|
|
SourceRange range = compiler_text_TrimRange(text);
|
|
value_6 = StringRange(text, (int64_t)range.begin, (int64_t)range.end);
|
|
}
|
|
String name = value_6;
|
|
String value_8 = StringRange(text, (int64_t)((int64_t)((uint64_t)colon + UINT64_C(1))), (int64_t)(int64_t)(text).length);
|
|
String value_9 = StringView(NULL, 0);
|
|
{
|
|
String text = value_8;
|
|
SourceRange range = compiler_text_TrimRange(text);
|
|
value_9 = StringRange(text, (int64_t)range.begin, (int64_t)range.end);
|
|
}
|
|
String type = value_9;
|
|
bool value_11 = compiler_source_IdentifierText(name, false);
|
|
bool value_12 = !value_11 || (int64_t)(name).length >= 128LL || (int64_t)(type).length == 0LL || (int64_t)(type).length >= 128LL;
|
|
bool value_13 = value_12;
|
|
if (!value_13) {
|
|
int64_t value_14 = compiler_proof_Index(type, 61);
|
|
int64_t value_15 = (int64_t)(type).length;
|
|
value_13 = (value_14 < value_15);
|
|
}
|
|
bool value_16 = value_13;
|
|
if (!value_16) {
|
|
int64_t value_17 = compiler_proof_Index(type, 36);
|
|
int64_t value_18 = (int64_t)(type).length;
|
|
value_16 = (value_17 < value_18);
|
|
}
|
|
if (value_16) {
|
|
return false;
|
|
}
|
|
{
|
|
int32_t range_first_14 = 0;
|
|
int32_t range_last_14 = (int32_t)((uint32_t)(out->count) - 1u);
|
|
int32_t i = range_first_14;
|
|
if (i <= range_last_14) for (;;) {
|
|
if (StringEqual(ZIRAN_INDEX(out->names, 16, i), name)) {
|
|
return false;
|
|
}
|
|
if (i == range_last_14) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
String* value_19 = &(ZIRAN_INDEX(out->names, sizeof(out->names) / sizeof(out->names[0]), out->count));
|
|
(*value_19) = name;
|
|
String* value_20 = &(ZIRAN_INDEX(out->types, sizeof(out->types) / sizeof(out->types[0]), out->count));
|
|
(*value_20) = type;
|
|
int32_t* value_21 = &(out->count);
|
|
(*value_21) = (int32_t)((uint32_t)((*value_21)) + 1u);
|
|
at = part.next;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static String
|
|
compiler_proof_Primitive(uint32_t width, bool ziran_keyword_unsigned_0)
|
|
{
|
|
if (width == 8) {
|
|
String value_0 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_0 = StringLiteral("u8");
|
|
} else {
|
|
value_0 = StringLiteral("s8");
|
|
}
|
|
return value_0;
|
|
}
|
|
if (width == 16) {
|
|
String value_1 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_1 = StringLiteral("u16");
|
|
} else {
|
|
value_1 = StringLiteral("s16");
|
|
}
|
|
return value_1;
|
|
}
|
|
if (width == 32) {
|
|
String value_2 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_2 = StringLiteral("u32");
|
|
} else {
|
|
value_2 = StringLiteral("s32");
|
|
}
|
|
return value_2;
|
|
}
|
|
String value_3 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_3 = StringLiteral("u64");
|
|
} else {
|
|
value_3 = StringLiteral("s64");
|
|
}
|
|
return value_3;
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_ScalarType(Context* c, ZirModule* m, String name)
|
|
{
|
|
if (StringEqual(name, StringLiteral("bool"))) {
|
|
return 0;
|
|
}
|
|
Spelled spelled = compiler_proof_C(name);
|
|
ZirType* type = zir_f_5116a9a569c28f15_FindType(m, &(spelled.bytes[0]), (void *)0);
|
|
bool ziran_keyword_enum_0 = type != ((void *)0) && type->is_enum != 0;
|
|
String value_0 = StringView(NULL, 0);
|
|
if (ziran_keyword_enum_0) {
|
|
Slice value_1 = {type->enum_backing, 128};
|
|
String value_2 = compiler_proof_Name(value_1);
|
|
value_0 = value_2;
|
|
} else {
|
|
value_0 = name;
|
|
}
|
|
String scalar = value_0;
|
|
bool value_3 = ziran_keyword_enum_0 && (StringEqual(scalar, StringLiteral("int")) || StringEqual(scalar, StringLiteral("integer")));
|
|
uint32_t value_4 = 0;
|
|
if (value_3) {
|
|
value_4 = 64;
|
|
} else {
|
|
value_4 = 0;
|
|
}
|
|
uint32_t width = value_4;
|
|
for (int64_t shift = 3LL; shift <= 6LL; shift++) {
|
|
uint32_t bits = ZiShl32(1, (uint64_t)((uint32_t)(shift)), 32);
|
|
String value_5 = scalar;
|
|
String value_6 = StringView(NULL, 0);
|
|
{
|
|
uint32_t width = bits;
|
|
bool ziran_keyword_unsigned_0 = false;
|
|
if (width == 8) {
|
|
String value_8 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_8 = StringLiteral("u8");
|
|
} else {
|
|
value_8 = StringLiteral("s8");
|
|
}
|
|
value_6 = value_8;
|
|
goto value_7;
|
|
}
|
|
if (width == 16) {
|
|
String value_9 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_9 = StringLiteral("u16");
|
|
} else {
|
|
value_9 = StringLiteral("s16");
|
|
}
|
|
value_6 = value_9;
|
|
goto value_7;
|
|
}
|
|
if (width == 32) {
|
|
String value_10 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_10 = StringLiteral("u32");
|
|
} else {
|
|
value_10 = StringLiteral("s32");
|
|
}
|
|
value_6 = value_10;
|
|
goto value_7;
|
|
}
|
|
String value_11 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_11 = StringLiteral("u64");
|
|
} else {
|
|
value_11 = StringLiteral("s64");
|
|
}
|
|
value_6 = value_11;
|
|
value_7: ;
|
|
}
|
|
bool value_12 = StringEqual(value_5, value_6);
|
|
bool value_13 = value_12;
|
|
if (!value_13) {
|
|
String value_14 = scalar;
|
|
String value_15 = StringView(NULL, 0);
|
|
{
|
|
uint32_t width = bits;
|
|
bool ziran_keyword_unsigned_0 = true;
|
|
if (width == 8) {
|
|
String value_17 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_17 = StringLiteral("u8");
|
|
} else {
|
|
value_17 = StringLiteral("s8");
|
|
}
|
|
value_15 = value_17;
|
|
goto value_16;
|
|
}
|
|
if (width == 16) {
|
|
String value_18 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_18 = StringLiteral("u16");
|
|
} else {
|
|
value_18 = StringLiteral("s16");
|
|
}
|
|
value_15 = value_18;
|
|
goto value_16;
|
|
}
|
|
if (width == 32) {
|
|
String value_19 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_19 = StringLiteral("u32");
|
|
} else {
|
|
value_19 = StringLiteral("s32");
|
|
}
|
|
value_15 = value_19;
|
|
goto value_16;
|
|
}
|
|
String value_20 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_20 = StringLiteral("u64");
|
|
} else {
|
|
value_20 = StringLiteral("s64");
|
|
}
|
|
value_15 = value_20;
|
|
value_16: ;
|
|
}
|
|
value_13 = (StringEqual(value_14, value_15));
|
|
}
|
|
if (value_13) {
|
|
width = bits;
|
|
}
|
|
}
|
|
if (width == 0) {
|
|
Context* value_21 = c;
|
|
String value_22 = StringLiteral("proofs require booleans, fixed-width integers, or enums");
|
|
int32_t value_23 = 0;
|
|
{
|
|
Context* c = value_21;
|
|
String reason = value_22;
|
|
bool* value_25 = &(c->unsupported);
|
|
(*value_25) = true;
|
|
String* value_26 = &(c->reason);
|
|
(*value_26) = reason;
|
|
value_23 = -1;
|
|
}
|
|
return value_23;
|
|
}
|
|
uint64_t value_27 = 0;
|
|
if (ziran_keyword_enum_0) {
|
|
value_27 = (uint64_t)(type);
|
|
} else {
|
|
value_27 = 0ULL;
|
|
}
|
|
uint64_t identity = value_27;
|
|
return compiler_proof_kernel_TypeAdd(&(c->kernel), (ProofType){.width = width, .is_unsigned = (uint8_t)ZIRAN_INDEX(scalar.data, scalar.length, 0) == 117, .identity = identity});
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_TermType(Context* c, int32_t term)
|
|
{
|
|
return (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_SameType(Context* c, int32_t a, int32_t b)
|
|
{
|
|
bool value_0 = a >= 0 && b >= 0;
|
|
if (value_0) {
|
|
Context* value_1 = c;
|
|
int32_t value_2 = 0;
|
|
{
|
|
Context* c = value_1;
|
|
int32_t term = a;
|
|
value_2 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
Context* value_4 = c;
|
|
int32_t value_5 = 0;
|
|
{
|
|
Context* c = value_4;
|
|
int32_t term = b;
|
|
value_5 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_0 = (value_2 == value_5);
|
|
}
|
|
return value_0;
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Find(Environment* e, String name)
|
|
{
|
|
int32_t i = (int32_t)((uint32_t)(e->count) - 1u);
|
|
while (i >= 0 && !StringEqual((ZIRAN_INDEX(e->bindings, sizeof(e->bindings) / sizeof(e->bindings[0]), i)).name, name)) {
|
|
i = (int32_t)((uint32_t)i - 1u);
|
|
}
|
|
return i;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_Bind(Context* c, Environment* e, String name, int32_t value)
|
|
{
|
|
if (value < 0) {
|
|
return false;
|
|
}
|
|
if (e->count == 64) {
|
|
bool* value_0 = &(c->kernel.exhausted);
|
|
(*value_0) = true;
|
|
return false;
|
|
}
|
|
Binding* value_1 = &(ZIRAN_INDEX(e->bindings, sizeof(e->bindings) / sizeof(e->bindings[0]), e->count));
|
|
(*value_1) = (Binding){.name = name, .value = value};
|
|
int32_t* value_2 = &(e->count);
|
|
(*value_2) = (int32_t)((uint32_t)((*value_2)) + 1u);
|
|
return true;
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Constant(Context* c, int32_t type, uint64_t value)
|
|
{
|
|
return compiler_proof_kernel_Node(&(c->kernel), (ProofOp)(0), type, -1, -1, -1, value);
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Node(Context* c, ProofOp op, int32_t type, int32_t a, int32_t b)
|
|
{
|
|
return compiler_proof_kernel_Node(&(c->kernel), op, type, a, b, -1, 0ULL);
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_Valid(ZirFunction* fn, int32_t at)
|
|
{
|
|
return at >= 0 && at < fn->expr_count;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_CallName(ZirFunction* fn, ZirExpr* call, Slice out)
|
|
{
|
|
String name = compiler_ir_CText((uint8_t*)call->name);
|
|
if ((int64_t)(name).length > 0LL) {
|
|
return compiler_ir_CopyText(out, name);
|
|
}
|
|
ZirFunction* value_0 = fn;
|
|
int32_t value_1 = call->left;
|
|
bool value_2 = false;
|
|
{
|
|
ZirFunction* fn = value_0;
|
|
int32_t at = value_1;
|
|
value_2 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
if (!value_2) {
|
|
return false;
|
|
}
|
|
ZirExpr* member = &(fn->exprs[call->left]);
|
|
bool value_4 = ((ZirExprKind)(member->kind)) != ((ZirExprKind)(8));
|
|
bool value_5 = value_4;
|
|
if (!value_5) {
|
|
ZirFunction* value_6 = fn;
|
|
int32_t value_7 = member->left;
|
|
bool value_8 = false;
|
|
{
|
|
ZirFunction* fn = value_6;
|
|
int32_t at = value_7;
|
|
value_8 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
value_5 = !value_8;
|
|
}
|
|
if (value_5 || ((ZirExprKind)((fn->exprs[member->left]).kind)) != ((ZirExprKind)(1))) {
|
|
return false;
|
|
}
|
|
String alias = compiler_ir_CText((uint8_t*)(fn->exprs[member->left]).name);
|
|
String field = compiler_ir_CText((uint8_t*)member->name);
|
|
int64_t value_10 = (int64_t)(((uint64_t)((int64_t)(alias).length) + (uint64_t)((int64_t)(field).length)) + UINT64_C(1));
|
|
if (value_10 >= (int64_t)(out).length) {
|
|
return false;
|
|
}
|
|
compiler_ir_CopyText(out, alias);
|
|
uint8_t* value_11 = &(((uint8_t *)out.data)[SliceIndex(out, (int64_t)(int64_t)(alias).length)]);
|
|
(*value_11) = 46;
|
|
Slice value_12 = out;
|
|
Slice value_13 = SliceRange(value_12, (int64_t)((int64_t)((uint64_t)((int64_t)(alias).length) + UINT64_C(1))), (int64_t)(int64_t)(out).length, sizeof(uint8_t));
|
|
return compiler_ir_CopyText(value_13, field);
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_BlockClose(ZirFunction* fn, int32_t open, int32_t stop)
|
|
{
|
|
int64_t level = 1LL;
|
|
{
|
|
int32_t range_first_1 = (int32_t)((uint32_t)open + 1u);
|
|
int32_t range_last_1 = (int32_t)((uint32_t)stop - 1u);
|
|
int32_t i = range_first_1;
|
|
if (i <= range_last_1) for (;;) {
|
|
ZirStmtKind kind = (ZirStmtKind)((fn->stmts[i]).kind);
|
|
bool value_0 = kind == ((ZirStmtKind)(6)) || kind == ((ZirStmtKind)(1)) || kind == ((ZirStmtKind)(7)) || kind == ((ZirStmtKind)(8));
|
|
if (value_0 || kind == ((ZirStmtKind)(16))) {
|
|
level = (int64_t)((uint64_t)level + UINT64_C(1));
|
|
}
|
|
if (kind == ((ZirStmtKind)(2))) {
|
|
level = (int64_t)((uint64_t)level - UINT64_C(1));
|
|
if (level == 0LL) {
|
|
return i;
|
|
}
|
|
}
|
|
if (i == range_last_1) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_FunctionValue(Context* c, ZirModule* m, ZirFunction* fn, Slice args, int32_t depth)
|
|
{
|
|
Context* value_0 = c;
|
|
int32_t value_1 = depth;
|
|
bool value_2 = false;
|
|
{
|
|
Context* c = value_0;
|
|
int32_t depth = value_1;
|
|
if (depth <= 64) {
|
|
int32_t* value_4 = &(c->kernel.budget);
|
|
(*value_4) = (int32_t)((uint32_t)((*value_4)) - 1u);
|
|
if (c->kernel.budget >= 0) {
|
|
value_2 = !c->kernel.exhausted;
|
|
goto value_3;
|
|
}
|
|
}
|
|
bool* value_5 = &(c->kernel.exhausted);
|
|
(*value_5) = true;
|
|
value_2 = false;
|
|
value_3: ;
|
|
}
|
|
if (!value_2) {
|
|
return -1;
|
|
}
|
|
bool value_6 = fn->checked == 0 || fn->is_extern != 0 || fn->uses_host != 0;
|
|
bool value_7 = value_6;
|
|
if (!value_7) {
|
|
Slice value_8 = {fn->effect_class, 12};
|
|
bool value_9 = !StringEqual(compiler_proof_Name(value_8), StringLiteral("pure"));
|
|
value_7 = value_9;
|
|
}
|
|
if (value_7) {
|
|
Context* value_10 = c;
|
|
String value_11 = StringLiteral("proofs cannot unfold foreign, observing, or mutating procedures");
|
|
int32_t value_12 = 0;
|
|
{
|
|
Context* c = value_10;
|
|
String reason = value_11;
|
|
bool* value_14 = &(c->unsupported);
|
|
(*value_14) = true;
|
|
String* value_15 = &(c->reason);
|
|
(*value_15) = reason;
|
|
value_12 = -1;
|
|
}
|
|
return value_12;
|
|
}
|
|
{
|
|
int32_t range_first_6 = 0;
|
|
int32_t range_last_6 = (int32_t)((uint32_t)(c->active_count) - 1u);
|
|
int32_t i = range_first_6;
|
|
if (i <= range_last_6) for (;;) {
|
|
if (ZIRAN_INDEX(c->active, 64, i) == fn) {
|
|
Context* value_16 = c;
|
|
String value_17 = StringLiteral("recursive procedures are outside the scalar proof fragment");
|
|
int32_t value_18 = 0;
|
|
{
|
|
Context* c = value_16;
|
|
String reason = value_17;
|
|
bool* value_20 = &(c->unsupported);
|
|
(*value_20) = true;
|
|
String* value_21 = &(c->reason);
|
|
(*value_21) = reason;
|
|
value_18 = -1;
|
|
}
|
|
return value_18;
|
|
}
|
|
if (i == range_last_6) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
if (c->active_count == 64) {
|
|
bool* value_22 = &(c->kernel.exhausted);
|
|
(*value_22) = true;
|
|
return -1;
|
|
}
|
|
Signature p = {0};
|
|
ZirFunction* value_23 = fn;
|
|
String value_24 = StringView(NULL, 0);
|
|
{
|
|
ZirFunction* fn = value_23;
|
|
value_24 = compiler_ir_CText((uint8_t*)fn->args_text);
|
|
}
|
|
bool value_26 = compiler_proof_ParseSignature(value_24, &(p));
|
|
if (!value_26 || (int64_t)(args).length != (int64_t)(p.count)) {
|
|
Context* value_27 = c;
|
|
String value_28 = StringLiteral("proof calls require explicit scalar parameters");
|
|
int32_t value_29 = 0;
|
|
{
|
|
Context* c = value_27;
|
|
String reason = value_28;
|
|
bool* value_31 = &(c->unsupported);
|
|
(*value_31) = true;
|
|
String* value_32 = &(c->reason);
|
|
(*value_32) = reason;
|
|
value_29 = -1;
|
|
}
|
|
return value_29;
|
|
}
|
|
Environment env = {0};
|
|
bool ok = true;
|
|
{
|
|
int32_t range_first_21 = 0;
|
|
int32_t range_last_21 = (int32_t)((uint32_t)(p.count) - 1u);
|
|
int32_t i = range_first_21;
|
|
if (i <= range_last_21) for (;;) {
|
|
int32_t value_33 = 0;
|
|
if (ok) {
|
|
int32_t value_34 = compiler_proof_ScalarType(c, m, ZIRAN_INDEX(p.types, 16, i));
|
|
value_33 = value_34;
|
|
} else {
|
|
value_33 = -1;
|
|
}
|
|
int32_t type = value_33;
|
|
bool value_35 = ok && ((int32_t *)args.data)[SliceIndex(args, (int64_t)i)] >= 0 && type >= 0;
|
|
bool value_36 = value_35;
|
|
if (value_36) {
|
|
Context* value_37 = c;
|
|
int32_t value_38 = ((int32_t *)args.data)[SliceIndex(args, (int64_t)i)];
|
|
int32_t value_39 = 0;
|
|
{
|
|
Context* c = value_37;
|
|
int32_t term = value_38;
|
|
value_39 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_36 = (value_39 == type);
|
|
}
|
|
bool value_41 = value_36;
|
|
bool value_42 = value_41;
|
|
if (value_42) {
|
|
Context* value_43 = c;
|
|
Environment* value_44 = &(env);
|
|
String value_45 = ZIRAN_INDEX(p.names, 16, i);
|
|
int32_t value_46 = ((int32_t *)args.data)[SliceIndex(args, (int64_t)i)];
|
|
bool value_47 = false;
|
|
{
|
|
Context* c = value_43;
|
|
Environment* e = value_44;
|
|
String name = value_45;
|
|
int32_t value = value_46;
|
|
if (value < 0) {
|
|
value_47 = false;
|
|
goto value_48;
|
|
}
|
|
if (e->count == 64) {
|
|
bool* value_49 = &(c->kernel.exhausted);
|
|
(*value_49) = true;
|
|
value_47 = false;
|
|
goto value_48;
|
|
}
|
|
Binding* value_50 = &(ZIRAN_INDEX(e->bindings, sizeof(e->bindings) / sizeof(e->bindings[0]), e->count));
|
|
(*value_50) = (Binding){.name = name, .value = value};
|
|
int32_t* value_51 = &(e->count);
|
|
(*value_51) = (int32_t)((uint32_t)((*value_51)) + 1u);
|
|
value_47 = true;
|
|
value_48: ;
|
|
}
|
|
value_42 = value_47;
|
|
}
|
|
ok = value_42;
|
|
if (i == range_last_21) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
Context* value_52 = c;
|
|
ZirModule* value_53 = m;
|
|
Slice value_54 = {fn->return_type, 128};
|
|
int32_t type = compiler_proof_ScalarType(value_52, value_53, compiler_proof_Name(value_54));
|
|
if (!ok || type < 0) {
|
|
Context* value_55 = c;
|
|
String value_56 = StringLiteral("procedure arguments do not match their declared scalar types");
|
|
int32_t value_57 = 0;
|
|
{
|
|
Context* c = value_55;
|
|
String reason = value_56;
|
|
bool* value_59 = &(c->unsupported);
|
|
(*value_59) = true;
|
|
String* value_60 = &(c->reason);
|
|
(*value_60) = reason;
|
|
value_57 = -1;
|
|
}
|
|
return value_57;
|
|
}
|
|
ZirFunction** value_61 = &(ZIRAN_INDEX(c->active, sizeof(c->active) / sizeof(c->active[0]), c->active_count));
|
|
(*value_61) = fn;
|
|
int32_t* value_62 = &(c->active_count);
|
|
(*value_62) = (int32_t)((uint32_t)((*value_62)) + 1u);
|
|
int32_t result = compiler_proof_Sequence(c, m, fn, &(env), 0, fn->stmt_count, (void *)0, type, (int32_t)((uint32_t)depth + 1u));
|
|
int32_t* value_63 = &(c->active_count);
|
|
(*value_63) = (int32_t)((uint32_t)((*value_63)) - 1u);
|
|
return result;
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Tag(Context* c, ZirFunction* fn, int32_t index, int32_t result)
|
|
{
|
|
if (result < 0 || fn->checked != 0) {
|
|
return result;
|
|
}
|
|
Context* value_0 = c;
|
|
int32_t value_1 = 0;
|
|
{
|
|
Context* c = value_0;
|
|
int32_t term = result;
|
|
value_1 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
ProofType type = ZIRAN_INDEX(c->kernel.types, 32, value_1);
|
|
String name = StringLiteral("bool");
|
|
if (type.identity != 0ULL) {
|
|
Slice value_3 = {((ZirType*)(type.identity))->name, 128};
|
|
name = compiler_proof_Name(value_3);
|
|
} else {
|
|
Context* value_4 = c;
|
|
int32_t value_5 = 0;
|
|
{
|
|
Context* c = value_4;
|
|
int32_t term = result;
|
|
value_5 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
if (value_5 != 0) {
|
|
uint32_t value_7 = type.width;
|
|
bool value_8 = type.is_unsigned;
|
|
String value_9 = StringView(NULL, 0);
|
|
{
|
|
uint32_t width = value_7;
|
|
bool ziran_keyword_unsigned_0 = value_8;
|
|
if (width == 8) {
|
|
String value_11 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_11 = StringLiteral("u8");
|
|
} else {
|
|
value_11 = StringLiteral("s8");
|
|
}
|
|
value_9 = value_11;
|
|
goto value_10;
|
|
}
|
|
if (width == 16) {
|
|
String value_12 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_12 = StringLiteral("u16");
|
|
} else {
|
|
value_12 = StringLiteral("s16");
|
|
}
|
|
value_9 = value_12;
|
|
goto value_10;
|
|
}
|
|
if (width == 32) {
|
|
String value_13 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_13 = StringLiteral("u32");
|
|
} else {
|
|
value_13 = StringLiteral("s32");
|
|
}
|
|
value_9 = value_13;
|
|
goto value_10;
|
|
}
|
|
String value_14 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_14 = StringLiteral("u64");
|
|
} else {
|
|
value_14 = StringLiteral("s64");
|
|
}
|
|
value_9 = value_14;
|
|
value_10: ;
|
|
}
|
|
name = value_9;
|
|
}
|
|
}
|
|
const char ** value_15 = &((fn->exprs[index]).type);
|
|
uint8_t* value_16 = compiler_services_KeepName(name);
|
|
(*value_15) = (const char *)(value_16);
|
|
return result;
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Expression(Context* c, ZirModule* m, ZirFunction* fn, int32_t index, Environment* env, int32_t expected, int32_t depth)
|
|
{
|
|
Context* value_0 = c;
|
|
int32_t value_1 = depth;
|
|
bool value_2 = false;
|
|
{
|
|
Context* c = value_0;
|
|
int32_t depth = value_1;
|
|
if (depth <= 64) {
|
|
int32_t* value_4 = &(c->kernel.budget);
|
|
(*value_4) = (int32_t)((uint32_t)((*value_4)) - 1u);
|
|
if (c->kernel.budget >= 0) {
|
|
value_2 = !c->kernel.exhausted;
|
|
goto value_3;
|
|
}
|
|
}
|
|
bool* value_5 = &(c->kernel.exhausted);
|
|
(*value_5) = true;
|
|
value_2 = false;
|
|
value_3: ;
|
|
}
|
|
bool value_6 = !value_2;
|
|
if (!value_6) {
|
|
ZirFunction* value_7 = fn;
|
|
bool value_8 = false;
|
|
{
|
|
ZirFunction* fn = value_7;
|
|
int32_t at = index;
|
|
value_8 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
value_6 = !value_8;
|
|
}
|
|
if (value_6) {
|
|
return -1;
|
|
}
|
|
ZirExpr* e = &(fn->exprs[index]);
|
|
Slice value_10 = {e->op, 8};
|
|
String op = compiler_proof_Name(value_10);
|
|
int32_t result = -1;
|
|
if (((ZirExprKind)(e->kind)) == ((ZirExprKind)(2))) {
|
|
LiteralBits literal = compiler_text_IntegerLiteral(compiler_ir_CText((uint8_t*)e->text));
|
|
if (!literal.valid) {
|
|
Context* value_11 = c;
|
|
String value_12 = StringLiteral("invalid integer literal in proof");
|
|
int32_t value_13 = 0;
|
|
{
|
|
Context* c = value_11;
|
|
String reason = value_12;
|
|
bool* value_15 = &(c->unsupported);
|
|
(*value_15) = true;
|
|
String* value_16 = &(c->reason);
|
|
(*value_16) = reason;
|
|
value_13 = -1;
|
|
}
|
|
return value_13;
|
|
}
|
|
int32_t value_17 = 0;
|
|
if (expected > 0) {
|
|
value_17 = expected;
|
|
} else {
|
|
String value_18 = StringView(NULL, 0);
|
|
if (literal.value > 9223372036854775807ULL) {
|
|
value_18 = StringLiteral("u64");
|
|
} else {
|
|
value_18 = StringLiteral("s64");
|
|
}
|
|
int32_t value_19 = compiler_proof_ScalarType(c, m, value_18);
|
|
value_17 = value_19;
|
|
}
|
|
int32_t type = value_17;
|
|
if (type < 0) {
|
|
return -1;
|
|
}
|
|
Context* value_20 = c;
|
|
int32_t value_21 = type;
|
|
uint64_t value_22 = literal.value;
|
|
int32_t value_23 = 0;
|
|
{
|
|
Context* c = value_20;
|
|
int32_t type = value_21;
|
|
uint64_t value = value_22;
|
|
value_23 = compiler_proof_kernel_Node(&(c->kernel), (ProofOp)(0), type, -1, -1, -1, value);
|
|
}
|
|
result = value_23;
|
|
} else if (((ZirExprKind)(e->kind)) == ((ZirExprKind)(1))) {
|
|
String name = compiler_ir_CText((uint8_t*)e->name);
|
|
int32_t at = compiler_proof_Find(env, name);
|
|
if (at >= 0) {
|
|
result = (ZIRAN_INDEX(env->bindings, sizeof(env->bindings) / sizeof(env->bindings[0]), at)).value;
|
|
} else if (StringEqual(name, StringLiteral("true")) || StringEqual(name, StringLiteral("false"))) {
|
|
Context* value_25 = c;
|
|
uint64_t value_26 = 0;
|
|
if (StringEqual(name, StringLiteral("true"))) {
|
|
value_26 = 1;
|
|
}
|
|
int32_t value_27 = 0;
|
|
{
|
|
Context* c = value_25;
|
|
int32_t type = 0;
|
|
uint64_t value = value_26;
|
|
value_27 = compiler_proof_kernel_Node(&(c->kernel), (ProofOp)(0), type, -1, -1, -1, value);
|
|
}
|
|
result = value_27;
|
|
} else {
|
|
ZirDefine* define = (void *)0;
|
|
{
|
|
int32_t range_first_28 = 0;
|
|
int32_t range_last_28 = (int32_t)((uint32_t)(m->define_count) - 1u);
|
|
int32_t i = range_first_28;
|
|
if (i <= range_last_28) for (;;) {
|
|
Slice value_29 = {(m->defines[i]).name, 128};
|
|
String value_30 = compiler_proof_Name(value_29);
|
|
if (StringEqual(value_30, name)) {
|
|
define = &(m->defines[i]);
|
|
}
|
|
if (i == range_last_28) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
if (define == ((void *)0)) {
|
|
Context* value_31 = c;
|
|
String value_32 = StringLiteral("proof expressions cannot read runtime globals or unresolved names");
|
|
int32_t value_33 = 0;
|
|
{
|
|
Context* c = value_31;
|
|
String reason = value_32;
|
|
bool* value_35 = &(c->unsupported);
|
|
(*value_35) = true;
|
|
String* value_36 = &(c->reason);
|
|
(*value_36) = reason;
|
|
value_33 = -1;
|
|
}
|
|
return value_33;
|
|
}
|
|
ZirFunction probe = {0};
|
|
Environment empty = {0};
|
|
Context* value_37 = c;
|
|
ZirModule* value_38 = m;
|
|
int32_t value_39 = zir_f_5116a9a569c28f15_ParseExpr(&(probe), m, (uint8_t*)define->value, define->span);
|
|
result = compiler_proof_Expression(value_37, value_38, &(probe), value_39, &(empty), expected, (int32_t)((uint32_t)depth + 1u));
|
|
zir_f_5116a9a569c28f15_free((uint8_t*)(probe.exprs));
|
|
}
|
|
} else if (((ZirExprKind)(e->kind)) == ((ZirExprKind)(8))) {
|
|
ZirFunction* value_40 = fn;
|
|
int32_t value_41 = e->left;
|
|
bool value_42 = false;
|
|
{
|
|
ZirFunction* fn = value_40;
|
|
int32_t at = value_41;
|
|
value_42 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
if (!value_42 || ((ZirExprKind)((fn->exprs[e->left]).kind)) != ((ZirExprKind)(1))) {
|
|
Context* value_44 = c;
|
|
String value_45 = StringLiteral("record and pointer members are outside scalar proofs");
|
|
int32_t value_46 = 0;
|
|
{
|
|
Context* c = value_44;
|
|
String reason = value_45;
|
|
bool* value_48 = &(c->unsupported);
|
|
(*value_48) = true;
|
|
String* value_49 = &(c->reason);
|
|
(*value_49) = reason;
|
|
value_46 = -1;
|
|
}
|
|
return value_46;
|
|
}
|
|
uint8_t* alias = (uint8_t*)(fn->exprs[e->left]).name;
|
|
ZirType* t = zir_f_5116a9a569c28f15_FindType(m, alias, (void *)0);
|
|
int64_t value = 0;
|
|
bool value_50 = t == ((void *)0) || t->is_enum == 0;
|
|
if (value_50 || zir_f_5116a9a569c28f15_EnumMemberValue(t, (uint8_t*)e->name, &(value)) == 0) {
|
|
Context* value_51 = c;
|
|
String value_52 = StringLiteral("unresolved enum member in proof");
|
|
int32_t value_53 = 0;
|
|
{
|
|
Context* c = value_51;
|
|
String reason = value_52;
|
|
bool* value_55 = &(c->unsupported);
|
|
(*value_55) = true;
|
|
String* value_56 = &(c->reason);
|
|
(*value_56) = reason;
|
|
value_53 = -1;
|
|
}
|
|
return value_53;
|
|
}
|
|
Context* value_57 = c;
|
|
Context* value_58 = c;
|
|
ZirModule* value_59 = m;
|
|
int32_t value_60 = compiler_proof_ScalarType(value_58, value_59, compiler_ir_CText(alias));
|
|
uint64_t value_61 = (uint64_t)(value);
|
|
int32_t value_62 = 0;
|
|
{
|
|
Context* c = value_57;
|
|
int32_t type = value_60;
|
|
uint64_t value = value_61;
|
|
value_62 = compiler_proof_kernel_Node(&(c->kernel), (ProofOp)(0), type, -1, -1, -1, value);
|
|
}
|
|
result = value_62;
|
|
} else if (((ZirExprKind)(e->kind)) == ((ZirExprKind)(11))) {
|
|
Context* value_64 = c;
|
|
ZirModule* value_65 = m;
|
|
int32_t type = compiler_proof_ScalarType(value_64, value_65, compiler_ir_CText((uint8_t*)e->name));
|
|
int32_t operand = compiler_proof_Expression(c, m, fn, e->right, env, -1, (int32_t)((uint32_t)depth + 1u));
|
|
if (type < 0 || operand < 0) {
|
|
return -1;
|
|
}
|
|
ProofTerm t = ZIRAN_INDEX(c->kernel.terms, 4096, operand);
|
|
if (t.type == type) {
|
|
result = operand;
|
|
} else if (((ProofOp)(t.op)) == ((ProofOp)(0))) {
|
|
uint64_t bits = t.value;
|
|
ProofType from = ZIRAN_INDEX(c->kernel.types, 32, t.type);
|
|
uint64_t sign = ZiShl64(1ULL, (uint64_t)((uint64_t)(((uint32_t)((uint32_t)(from.width) - 1u)))), 64);
|
|
if (t.type != 0 && !from.is_unsigned && ((uint64_t)((uint64_t)bits & (uint64_t)sign)) != 0ULL) {
|
|
bits = (uint64_t)((uint64_t)bits | (uint64_t)(((uint64_t)~((uint64_t)sign | ((uint64_t)sign - UINT64_C(1))))));
|
|
}
|
|
Context* value_66 = c;
|
|
int32_t value_67 = type;
|
|
uint64_t value_68 = 0;
|
|
if (type != 0) {
|
|
value_68 = bits;
|
|
} else {
|
|
uint64_t value_69 = 0;
|
|
if (bits != 0ULL) {
|
|
value_69 = 1;
|
|
}
|
|
value_68 = value_69;
|
|
}
|
|
int32_t value_70 = 0;
|
|
{
|
|
Context* c = value_66;
|
|
int32_t type = value_67;
|
|
uint64_t value = value_68;
|
|
value_70 = compiler_proof_kernel_Node(&(c->kernel), (ProofOp)(0), type, -1, -1, -1, value);
|
|
}
|
|
result = value_70;
|
|
} else {
|
|
Context* value_72 = c;
|
|
String value_73 = StringLiteral("symbolic conversions between scalar types need a separate proof rule");
|
|
int32_t value_74 = 0;
|
|
{
|
|
Context* c = value_72;
|
|
String reason = value_73;
|
|
bool* value_76 = &(c->unsupported);
|
|
(*value_76) = true;
|
|
String* value_77 = &(c->reason);
|
|
(*value_77) = reason;
|
|
value_74 = -1;
|
|
}
|
|
return value_74;
|
|
}
|
|
} else if (((ZirExprKind)(e->kind)) == ((ZirExprKind)(7))) {
|
|
String declared = compiler_ir_CText((uint8_t*)e->type);
|
|
int32_t value_78 = 0;
|
|
if ((int64_t)(declared).length > 0LL && fn->checked != 0) {
|
|
int32_t value_79 = compiler_proof_ScalarType(c, m, declared);
|
|
value_78 = value_79;
|
|
} else {
|
|
value_78 = expected;
|
|
}
|
|
int32_t type = value_78;
|
|
int32_t value_80 = 0;
|
|
if (StringEqual(op, StringLiteral("!"))) {
|
|
value_80 = 0;
|
|
} else {
|
|
value_80 = type;
|
|
}
|
|
int32_t operand = compiler_proof_Expression(c, m, fn, e->right, env, value_80, (int32_t)((uint32_t)depth + 1u));
|
|
if (operand < 0) {
|
|
return -1;
|
|
}
|
|
Context* value_81 = c;
|
|
int32_t value_82 = 0;
|
|
{
|
|
Context* c = value_81;
|
|
int32_t term = operand;
|
|
value_82 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
type = value_82;
|
|
bool value_84 = type != 0;
|
|
if (value_84) {
|
|
uint64_t value_85 = (ZIRAN_INDEX(c->kernel.types, sizeof(c->kernel.types) / sizeof(c->kernel.types[0]), type)).identity;
|
|
value_84 = (value_85 != 0ULL);
|
|
}
|
|
if (value_84) {
|
|
Context* value_86 = c;
|
|
String value_87 = StringLiteral("enum proofs currently support equality only");
|
|
int32_t value_88 = 0;
|
|
{
|
|
Context* c = value_86;
|
|
String reason = value_87;
|
|
bool* value_90 = &(c->unsupported);
|
|
(*value_90) = true;
|
|
String* value_91 = &(c->reason);
|
|
(*value_91) = reason;
|
|
value_88 = -1;
|
|
}
|
|
return value_88;
|
|
}
|
|
if (StringEqual(op, StringLiteral("+")) && type != 0) {
|
|
result = operand;
|
|
} else if (StringEqual(op, StringLiteral("!")) && type == 0) {
|
|
Context* value_92 = c;
|
|
ProofOp value_93 = (ProofOp)((ProofOp)(10));
|
|
int32_t value_94 = 0;
|
|
{
|
|
Context* c = value_92;
|
|
ProofOp op = (ProofOp)(value_93);
|
|
int32_t type = 0;
|
|
int32_t a = operand;
|
|
int32_t b = -1;
|
|
value_94 = compiler_proof_kernel_Node(&(c->kernel), op, type, a, b, -1, 0ULL);
|
|
}
|
|
result = value_94;
|
|
} else if (StringEqual(op, StringLiteral("-")) && type != 0) {
|
|
Context* value_96 = c;
|
|
ProofOp value_97 = (ProofOp)((ProofOp)(3));
|
|
int32_t value_98 = type;
|
|
Context* value_99 = c;
|
|
int32_t value_100 = type;
|
|
int32_t value_101 = 0;
|
|
{
|
|
Context* c = value_99;
|
|
int32_t type = value_100;
|
|
uint64_t value = 0ULL;
|
|
value_101 = compiler_proof_kernel_Node(&(c->kernel), (ProofOp)(0), type, -1, -1, -1, value);
|
|
}
|
|
int32_t value_103 = 0;
|
|
{
|
|
Context* c = value_96;
|
|
ProofOp op = (ProofOp)(value_97);
|
|
int32_t type = value_98;
|
|
int32_t a = value_101;
|
|
int32_t b = operand;
|
|
value_103 = compiler_proof_kernel_Node(&(c->kernel), op, type, a, b, -1, 0ULL);
|
|
}
|
|
result = value_103;
|
|
} else {
|
|
Context* value_105 = c;
|
|
String value_106 = StringLiteral("unsupported unary operation in scalar proof");
|
|
int32_t value_107 = 0;
|
|
{
|
|
Context* c = value_105;
|
|
String reason = value_106;
|
|
bool* value_109 = &(c->unsupported);
|
|
(*value_109) = true;
|
|
String* value_110 = &(c->reason);
|
|
(*value_110) = reason;
|
|
value_107 = -1;
|
|
}
|
|
return value_107;
|
|
}
|
|
} else if (((ZirExprKind)(e->kind)) == ((ZirExprKind)(6))) {
|
|
result = compiler_proof_Binary(c, m, fn, e, env, expected, depth);
|
|
if (result < 0) {
|
|
return -1;
|
|
}
|
|
} else if (((ZirExprKind)(e->kind)) == ((ZirExprKind)(14))) {
|
|
int32_t cond = compiler_proof_Expression(c, m, fn, e->left, env, 0, (int32_t)((uint32_t)depth + 1u));
|
|
int32_t a = compiler_proof_Expression(c, m, fn, e->right, env, expected, (int32_t)((uint32_t)depth + 1u));
|
|
int32_t value_111 = 0;
|
|
if (a >= 0) {
|
|
Context* value_112 = c;
|
|
ZirModule* value_113 = m;
|
|
ZirFunction* value_114 = fn;
|
|
int32_t value_115 = e->third;
|
|
Environment* value_116 = env;
|
|
Context* value_117 = c;
|
|
int32_t value_118 = 0;
|
|
{
|
|
Context* c = value_117;
|
|
int32_t term = a;
|
|
value_118 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
int32_t value_120 = compiler_proof_Expression(value_112, value_113, value_114, value_115, value_116, value_118, (int32_t)((uint32_t)depth + 1u));
|
|
value_111 = value_120;
|
|
} else {
|
|
value_111 = -1;
|
|
}
|
|
int32_t b = value_111;
|
|
bool value_121 = cond < 0 || a < 0 || b < 0;
|
|
bool value_122 = value_121;
|
|
if (!value_122) {
|
|
Context* value_123 = c;
|
|
int32_t value_124 = 0;
|
|
{
|
|
Context* c = value_123;
|
|
int32_t term = cond;
|
|
value_124 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_122 = (value_124 != 0);
|
|
}
|
|
bool value_126 = value_122;
|
|
bool value_127 = value_126;
|
|
if (!value_127) {
|
|
Context* value_128 = c;
|
|
int32_t value_129 = a;
|
|
int32_t value_130 = b;
|
|
bool value_131 = false;
|
|
{
|
|
Context* c = value_128;
|
|
int32_t a = value_129;
|
|
int32_t b = value_130;
|
|
bool value_133 = a >= 0 && b >= 0;
|
|
if (value_133) {
|
|
Context* value_134 = c;
|
|
int32_t value_135 = 0;
|
|
{
|
|
Context* c = value_134;
|
|
int32_t term = a;
|
|
value_135 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
Context* value_137 = c;
|
|
int32_t value_138 = 0;
|
|
{
|
|
Context* c = value_137;
|
|
int32_t term = b;
|
|
value_138 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_133 = (value_135 == value_138);
|
|
}
|
|
value_131 = value_133;
|
|
}
|
|
value_127 = !value_131;
|
|
}
|
|
if (value_127) {
|
|
Context* value_140 = c;
|
|
String value_141 = StringLiteral("ill-typed conditional in proof");
|
|
int32_t value_142 = 0;
|
|
{
|
|
Context* c = value_140;
|
|
String reason = value_141;
|
|
bool* value_144 = &(c->unsupported);
|
|
(*value_144) = true;
|
|
String* value_145 = &(c->reason);
|
|
(*value_145) = reason;
|
|
value_142 = -1;
|
|
}
|
|
return value_142;
|
|
}
|
|
Context* value_146 = c;
|
|
int32_t value_147 = 0;
|
|
{
|
|
Context* c = value_146;
|
|
int32_t term = a;
|
|
value_147 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
result = compiler_proof_kernel_Node(&(c->kernel), (ProofOp)(11), value_147, cond, a, b, 0ULL);
|
|
} else if (((ZirExprKind)(e->kind)) == ((ZirExprKind)(5))) {
|
|
result = compiler_proof_Call(c, m, fn, e, env, depth);
|
|
if (result < 0) {
|
|
return -1;
|
|
}
|
|
} else {
|
|
Context* value_149 = c;
|
|
String value_150 = StringLiteral("expression is outside the pure scalar proof fragment");
|
|
int32_t value_151 = 0;
|
|
{
|
|
Context* c = value_149;
|
|
String reason = value_150;
|
|
bool* value_153 = &(c->unsupported);
|
|
(*value_153) = true;
|
|
String* value_154 = &(c->reason);
|
|
(*value_154) = reason;
|
|
value_151 = -1;
|
|
}
|
|
return value_151;
|
|
}
|
|
Context* value_155 = c;
|
|
ZirFunction* value_156 = fn;
|
|
int32_t value_157 = index;
|
|
int32_t value_158 = result;
|
|
int32_t value_159 = 0;
|
|
{
|
|
Context* c = value_155;
|
|
ZirFunction* fn = value_156;
|
|
int32_t index = value_157;
|
|
int32_t result = value_158;
|
|
if (result < 0 || fn->checked != 0) {
|
|
value_159 = result;
|
|
goto value_160;
|
|
}
|
|
Context* value_161 = c;
|
|
int32_t value_162 = 0;
|
|
{
|
|
Context* c = value_161;
|
|
int32_t term = result;
|
|
value_162 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
ProofType type = ZIRAN_INDEX(c->kernel.types, 32, value_162);
|
|
String name = StringLiteral("bool");
|
|
if (type.identity != 0ULL) {
|
|
Slice value_164 = {((ZirType*)(type.identity))->name, 128};
|
|
name = compiler_proof_Name(value_164);
|
|
} else {
|
|
Context* value_165 = c;
|
|
int32_t value_166 = 0;
|
|
{
|
|
Context* c = value_165;
|
|
int32_t term = result;
|
|
value_166 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
if (value_166 != 0) {
|
|
uint32_t value_168 = type.width;
|
|
bool value_169 = type.is_unsigned;
|
|
String value_170 = StringView(NULL, 0);
|
|
{
|
|
uint32_t width = value_168;
|
|
bool ziran_keyword_unsigned_0 = value_169;
|
|
if (width == 8) {
|
|
String value_172 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_172 = StringLiteral("u8");
|
|
} else {
|
|
value_172 = StringLiteral("s8");
|
|
}
|
|
value_170 = value_172;
|
|
goto value_171;
|
|
}
|
|
if (width == 16) {
|
|
String value_173 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_173 = StringLiteral("u16");
|
|
} else {
|
|
value_173 = StringLiteral("s16");
|
|
}
|
|
value_170 = value_173;
|
|
goto value_171;
|
|
}
|
|
if (width == 32) {
|
|
String value_174 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_174 = StringLiteral("u32");
|
|
} else {
|
|
value_174 = StringLiteral("s32");
|
|
}
|
|
value_170 = value_174;
|
|
goto value_171;
|
|
}
|
|
String value_175 = StringView(NULL, 0);
|
|
if (ziran_keyword_unsigned_0) {
|
|
value_175 = StringLiteral("u64");
|
|
} else {
|
|
value_175 = StringLiteral("s64");
|
|
}
|
|
value_170 = value_175;
|
|
value_171: ;
|
|
}
|
|
name = value_170;
|
|
}
|
|
}
|
|
const char ** value_176 = &((fn->exprs[index]).type);
|
|
uint8_t* value_177 = compiler_services_KeepName(name);
|
|
(*value_176) = (const char *)(value_177);
|
|
value_159 = result;
|
|
value_160: ;
|
|
}
|
|
return value_159;
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Binary(Context* c, ZirModule* m, ZirFunction* fn, ZirExpr* e, Environment* env, int32_t expected, int32_t depth)
|
|
{
|
|
ZirFunction* value_0 = fn;
|
|
int32_t value_1 = e->left;
|
|
bool value_2 = false;
|
|
{
|
|
ZirFunction* fn = value_0;
|
|
int32_t at = value_1;
|
|
value_2 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
bool value_4 = !value_2;
|
|
if (!value_4) {
|
|
ZirFunction* value_5 = fn;
|
|
int32_t value_6 = e->right;
|
|
bool value_7 = false;
|
|
{
|
|
ZirFunction* fn = value_5;
|
|
int32_t at = value_6;
|
|
value_7 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
value_4 = !value_7;
|
|
}
|
|
if (value_4) {
|
|
Context* value_9 = c;
|
|
String value_10 = StringLiteral("malformed proof expression graph");
|
|
int32_t value_11 = 0;
|
|
{
|
|
Context* c = value_9;
|
|
String reason = value_10;
|
|
bool* value_13 = &(c->unsupported);
|
|
(*value_13) = true;
|
|
String* value_14 = &(c->reason);
|
|
(*value_14) = reason;
|
|
value_11 = -1;
|
|
}
|
|
return value_11;
|
|
}
|
|
int32_t value_15 = 0;
|
|
if (expected > 0) {
|
|
value_15 = expected;
|
|
} else {
|
|
value_15 = -1;
|
|
}
|
|
int32_t numeric = value_15;
|
|
String declared = compiler_ir_CText((uint8_t*)e->type);
|
|
if (fn->checked != 0 && (int64_t)(declared).length > 0LL && !StringEqual(declared, StringLiteral("bool"))) {
|
|
numeric = compiler_proof_ScalarType(c, m, declared);
|
|
}
|
|
ZirExpr* left = &(fn->exprs[e->left]);
|
|
bool reverse = ((ZirExprKind)(left->kind)) == ((ZirExprKind)(2)) || (((ZirExprKind)(left->kind)) == ((ZirExprKind)(7)) && left->right >= 0 && ((ZirExprKind)((fn->exprs[left->right]).kind)) == ((ZirExprKind)(2)));
|
|
int32_t a = -1;
|
|
int32_t b = -1;
|
|
if (reverse) {
|
|
b = compiler_proof_Expression(c, m, fn, e->right, env, numeric, (int32_t)((uint32_t)depth + 1u));
|
|
if (b >= 0) {
|
|
Context* value_16 = c;
|
|
ZirModule* value_17 = m;
|
|
ZirFunction* value_18 = fn;
|
|
int32_t value_19 = e->left;
|
|
Environment* value_20 = env;
|
|
Context* value_21 = c;
|
|
int32_t value_22 = 0;
|
|
{
|
|
Context* c = value_21;
|
|
int32_t term = b;
|
|
value_22 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
a = compiler_proof_Expression(value_16, value_17, value_18, value_19, value_20, value_22, (int32_t)((uint32_t)depth + 1u));
|
|
}
|
|
} else {
|
|
a = compiler_proof_Expression(c, m, fn, e->left, env, numeric, (int32_t)((uint32_t)depth + 1u));
|
|
if (a >= 0) {
|
|
Context* value_24 = c;
|
|
ZirModule* value_25 = m;
|
|
ZirFunction* value_26 = fn;
|
|
int32_t value_27 = e->right;
|
|
Environment* value_28 = env;
|
|
Context* value_29 = c;
|
|
int32_t value_30 = 0;
|
|
{
|
|
Context* c = value_29;
|
|
int32_t term = a;
|
|
value_30 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
b = compiler_proof_Expression(value_24, value_25, value_26, value_27, value_28, value_30, (int32_t)((uint32_t)depth + 1u));
|
|
}
|
|
}
|
|
if (a < 0 || b < 0) {
|
|
return -1;
|
|
}
|
|
Context* value_32 = c;
|
|
int32_t value_33 = a;
|
|
int32_t value_34 = b;
|
|
bool value_35 = false;
|
|
{
|
|
Context* c = value_32;
|
|
int32_t a = value_33;
|
|
int32_t b = value_34;
|
|
bool value_37 = a >= 0 && b >= 0;
|
|
if (value_37) {
|
|
Context* value_38 = c;
|
|
int32_t value_39 = 0;
|
|
{
|
|
Context* c = value_38;
|
|
int32_t term = a;
|
|
value_39 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
Context* value_41 = c;
|
|
int32_t value_42 = 0;
|
|
{
|
|
Context* c = value_41;
|
|
int32_t term = b;
|
|
value_42 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_37 = (value_39 == value_42);
|
|
}
|
|
value_35 = value_37;
|
|
}
|
|
if (!value_35) {
|
|
Context* value_44 = c;
|
|
String value_45 = StringLiteral("scalar proof operands require identical types");
|
|
int32_t value_46 = 0;
|
|
{
|
|
Context* c = value_44;
|
|
String reason = value_45;
|
|
bool* value_48 = &(c->unsupported);
|
|
(*value_48) = true;
|
|
String* value_49 = &(c->reason);
|
|
(*value_49) = reason;
|
|
value_46 = -1;
|
|
}
|
|
return value_46;
|
|
}
|
|
Context* value_50 = c;
|
|
int32_t value_51 = 0;
|
|
{
|
|
Context* c = value_50;
|
|
int32_t term = a;
|
|
value_51 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
int32_t type = value_51;
|
|
Slice value_53 = {e->op, 8};
|
|
String op = compiler_proof_Name(value_53);
|
|
ProofOp kind = (ProofOp)((ProofOp)(0));
|
|
if (type != 0) {
|
|
if (StringEqual(op, StringLiteral("+"))) {
|
|
kind = (ProofOp)(2);
|
|
} else if (StringEqual(op, StringLiteral("-"))) {
|
|
kind = (ProofOp)(3);
|
|
} else if (StringEqual(op, StringLiteral("*"))) {
|
|
kind = (ProofOp)(4);
|
|
} else if (StringEqual(op, StringLiteral("<")) || StringEqual(op, StringLiteral(">"))) {
|
|
kind = (ProofOp)(6);
|
|
} else if (StringEqual(op, StringLiteral("<=")) || StringEqual(op, StringLiteral(">="))) {
|
|
kind = (ProofOp)(7);
|
|
}
|
|
} else if (StringEqual(op, StringLiteral("&&"))) {
|
|
kind = (ProofOp)(8);
|
|
} else if (StringEqual(op, StringLiteral("||"))) {
|
|
kind = (ProofOp)(9);
|
|
}
|
|
if (StringEqual(op, StringLiteral("==")) || StringEqual(op, StringLiteral("!="))) {
|
|
kind = (ProofOp)(5);
|
|
}
|
|
if (kind == ((ProofOp)(0))) {
|
|
Context* value_54 = c;
|
|
String value_55 = StringLiteral("unsupported binary operation in scalar proof");
|
|
int32_t value_56 = 0;
|
|
{
|
|
Context* c = value_54;
|
|
String reason = value_55;
|
|
bool* value_58 = &(c->unsupported);
|
|
(*value_58) = true;
|
|
String* value_59 = &(c->reason);
|
|
(*value_59) = reason;
|
|
value_56 = -1;
|
|
}
|
|
return value_56;
|
|
}
|
|
bool value_60 = type != 0;
|
|
if (value_60) {
|
|
uint64_t value_61 = (ZIRAN_INDEX(c->kernel.types, sizeof(c->kernel.types) / sizeof(c->kernel.types[0]), type)).identity;
|
|
value_60 = (value_61 != 0ULL);
|
|
}
|
|
if (value_60 && kind != ((ProofOp)(5))) {
|
|
Context* value_62 = c;
|
|
String value_63 = StringLiteral("enum proofs currently support equality only");
|
|
int32_t value_64 = 0;
|
|
{
|
|
Context* c = value_62;
|
|
String reason = value_63;
|
|
bool* value_66 = &(c->unsupported);
|
|
(*value_66) = true;
|
|
String* value_67 = &(c->reason);
|
|
(*value_67) = reason;
|
|
value_64 = -1;
|
|
}
|
|
return value_64;
|
|
}
|
|
if (StringEqual(op, StringLiteral(">")) || StringEqual(op, StringLiteral(">="))) {
|
|
int32_t swap = a;
|
|
a = b;
|
|
b = swap;
|
|
}
|
|
bool ring = kind == ((ProofOp)(2)) || kind == ((ProofOp)(3)) || kind == ((ProofOp)(4));
|
|
Context* value_68 = c;
|
|
int32_t value_69 = 0;
|
|
if (ring) {
|
|
value_69 = type;
|
|
} else {
|
|
value_69 = 0;
|
|
}
|
|
int32_t value_70 = a;
|
|
int32_t value_71 = b;
|
|
int32_t value_72 = 0;
|
|
{
|
|
Context* c = value_68;
|
|
ProofOp op = (ProofOp)(kind);
|
|
int32_t type = value_69;
|
|
int32_t a = value_70;
|
|
int32_t b = value_71;
|
|
value_72 = compiler_proof_kernel_Node(&(c->kernel), op, type, a, b, -1, 0ULL);
|
|
}
|
|
int32_t result = value_72;
|
|
int32_t value_74 = 0;
|
|
if (StringEqual(op, StringLiteral("!="))) {
|
|
Context* value_75 = c;
|
|
ProofOp value_76 = (ProofOp)((ProofOp)(10));
|
|
int32_t value_77 = 0;
|
|
{
|
|
Context* c = value_75;
|
|
ProofOp op = (ProofOp)(value_76);
|
|
int32_t type = 0;
|
|
int32_t a = result;
|
|
int32_t b = -1;
|
|
value_77 = compiler_proof_kernel_Node(&(c->kernel), op, type, a, b, -1, 0ULL);
|
|
}
|
|
value_74 = value_77;
|
|
} else {
|
|
value_74 = result;
|
|
}
|
|
return value_74;
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Call(Context* c, ZirModule* m, ZirFunction* fn, ZirExpr* e, Environment* env, int32_t depth)
|
|
{
|
|
ZirModule* owner = (void *)0;
|
|
ZirFunction* callee = (void *)0;
|
|
Spelled name = {0};
|
|
Slice value_0 = {name.bytes, 128};
|
|
bool value_1 = compiler_proof_CallName(fn, e, value_0);
|
|
bool value_2 = !value_1;
|
|
if (!value_2) {
|
|
ZirModule* value_3 = m;
|
|
bool value_4 = compiler_services_ResolveFunction(value_3, &(name.bytes[0]), compiler_services_SpanPath(e->span), &(owner), &(callee)) != 1;
|
|
value_2 = value_4;
|
|
}
|
|
if (value_2) {
|
|
Context* value_5 = c;
|
|
String value_6 = StringLiteral("unresolved or indirect procedure in proof");
|
|
int32_t value_7 = 0;
|
|
{
|
|
Context* c = value_5;
|
|
String reason = value_6;
|
|
bool* value_9 = &(c->unsupported);
|
|
(*value_9) = true;
|
|
String* value_10 = &(c->reason);
|
|
(*value_10) = reason;
|
|
value_7 = -1;
|
|
}
|
|
return value_7;
|
|
}
|
|
bool allowed = c->unfold.all || c->active_count > 0;
|
|
{
|
|
int32_t range_first_7 = 0;
|
|
int32_t range_last_7 = (int32_t)((uint32_t)(c->unfold.count) - 1u);
|
|
int32_t i = range_first_7;
|
|
if (i <= range_last_7) for (;;) {
|
|
if (ZIRAN_INDEX(c->unfold.functions, 64, i) == callee) {
|
|
allowed = true;
|
|
}
|
|
if (i == range_last_7) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
if (!allowed) {
|
|
Context* value_11 = c;
|
|
String value_12 = StringLiteral("procedure calls need an unfold step");
|
|
int32_t value_13 = 0;
|
|
{
|
|
Context* c = value_11;
|
|
String reason = value_12;
|
|
bool* value_15 = &(c->unsupported);
|
|
(*value_15) = true;
|
|
String* value_16 = &(c->reason);
|
|
(*value_16) = reason;
|
|
value_13 = -1;
|
|
}
|
|
return value_13;
|
|
}
|
|
Signature p = {0};
|
|
String value_17 = StringView(NULL, 0);
|
|
{
|
|
ZirFunction* fn = callee;
|
|
value_17 = compiler_ir_CText((uint8_t*)fn->args_text);
|
|
}
|
|
bool value_19 = compiler_proof_ParseSignature(value_17, &(p));
|
|
if (!value_19) {
|
|
Context* value_20 = c;
|
|
String value_21 = StringLiteral("unsupported procedure signature in proof");
|
|
int32_t value_22 = 0;
|
|
{
|
|
Context* c = value_20;
|
|
String reason = value_21;
|
|
bool* value_24 = &(c->unsupported);
|
|
(*value_24) = true;
|
|
String* value_25 = &(c->reason);
|
|
(*value_25) = reason;
|
|
value_22 = -1;
|
|
}
|
|
return value_22;
|
|
}
|
|
int32_t args[16] = {0};
|
|
int32_t count = 0;
|
|
uint32_t used = 0;
|
|
int32_t at = e->first_child;
|
|
while (at >= 0) {
|
|
Context* value_26 = c;
|
|
int32_t value_27 = depth;
|
|
bool value_28 = false;
|
|
{
|
|
Context* c = value_26;
|
|
int32_t depth = value_27;
|
|
if (depth <= 64) {
|
|
int32_t* value_30 = &(c->kernel.budget);
|
|
(*value_30) = (int32_t)((uint32_t)((*value_30)) - 1u);
|
|
if (c->kernel.budget >= 0) {
|
|
value_28 = !c->kernel.exhausted;
|
|
goto value_29;
|
|
}
|
|
}
|
|
bool* value_31 = &(c->kernel.exhausted);
|
|
(*value_31) = true;
|
|
value_28 = false;
|
|
value_29: ;
|
|
}
|
|
if (!value_28 || at >= fn->expr_count || count == 16) {
|
|
Context* value_32 = c;
|
|
String value_33 = StringLiteral("malformed proof call arguments");
|
|
int32_t value_34 = 0;
|
|
{
|
|
Context* c = value_32;
|
|
String reason = value_33;
|
|
bool* value_36 = &(c->unsupported);
|
|
(*value_36) = true;
|
|
String* value_37 = &(c->reason);
|
|
(*value_37) = reason;
|
|
value_34 = -1;
|
|
}
|
|
return value_34;
|
|
}
|
|
ZirExpr* argument = &(fn->exprs[at]);
|
|
int32_t value_38 = 0;
|
|
if (fn->checked != 0) {
|
|
value_38 = argument->argument_index;
|
|
} else {
|
|
value_38 = count;
|
|
}
|
|
int32_t position = value_38;
|
|
bool value_39 = position < 0 || position >= p.count || ((uint32_t)((uint32_t)used & (uint32_t)((ZiShl32(1, (uint64_t)((uint32_t)(position)), 32))))) != 0;
|
|
bool value_40 = value_39;
|
|
bool value_41 = value_40;
|
|
if (!value_41) {
|
|
bool value_42 = fn->checked == 0;
|
|
bool value_43 = value_42;
|
|
if (value_43) {
|
|
String value_44 = compiler_ir_CText((uint8_t*)argument->argument_name);
|
|
int64_t value_45 = (int64_t)(value_44).length;
|
|
value_43 = (value_45 > 0LL);
|
|
}
|
|
value_41 = value_43;
|
|
}
|
|
if (value_41) {
|
|
Context* value_46 = c;
|
|
String value_47 = StringLiteral("proof expressions use positional arguments");
|
|
int32_t value_48 = 0;
|
|
{
|
|
Context* c = value_46;
|
|
String reason = value_47;
|
|
bool* value_50 = &(c->unsupported);
|
|
(*value_50) = true;
|
|
String* value_51 = &(c->reason);
|
|
(*value_51) = reason;
|
|
value_48 = -1;
|
|
}
|
|
return value_48;
|
|
}
|
|
used = (uint32_t)((uint32_t)used | (uint32_t)((ZiShl32(1, (uint64_t)((uint32_t)(position)), 32))));
|
|
int32_t* value_52 = &(ZIRAN_INDEX(args, sizeof(args) / sizeof(args[0]), position));
|
|
Context* value_53 = c;
|
|
ZirModule* value_54 = m;
|
|
ZirFunction* value_55 = fn;
|
|
int32_t value_56 = at;
|
|
Environment* value_57 = env;
|
|
int32_t value_58 = compiler_proof_ScalarType(c, owner, ZIRAN_INDEX(p.types, 16, position));
|
|
int32_t value_59 = compiler_proof_Expression(value_53, value_54, value_55, value_56, value_57, value_58, (int32_t)((uint32_t)depth + 1u));
|
|
(*value_52) = value_59;
|
|
if (ZIRAN_INDEX(args, 16, position) < 0) {
|
|
return -1;
|
|
}
|
|
count = (int32_t)((uint32_t)count + 1u);
|
|
at = argument->next_sibling;
|
|
}
|
|
if (count != p.count) {
|
|
Context* value_60 = c;
|
|
String value_61 = StringLiteral("proof calls require all procedure arguments");
|
|
int32_t value_62 = 0;
|
|
{
|
|
Context* c = value_60;
|
|
String reason = value_61;
|
|
bool* value_64 = &(c->unsupported);
|
|
(*value_64) = true;
|
|
String* value_65 = &(c->reason);
|
|
(*value_65) = reason;
|
|
value_62 = -1;
|
|
}
|
|
return value_62;
|
|
}
|
|
Slice value_66 = {args, 16};
|
|
return compiler_proof_FunctionValue(c, owner, callee, SliceRange(value_66, (int64_t)0LL, (int64_t)count, sizeof(int32_t)), (int32_t)((uint32_t)depth + 1u));
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Arms(Context* c, ZirModule* m, ZirFunction* fn, Environment* env, int32_t at, int32_t after, Continuation* rest, int32_t result, int32_t depth)
|
|
{
|
|
Context* value_0 = c;
|
|
int32_t value_1 = depth;
|
|
bool value_2 = false;
|
|
{
|
|
Context* c = value_0;
|
|
int32_t depth = value_1;
|
|
if (depth <= 64) {
|
|
int32_t* value_4 = &(c->kernel.budget);
|
|
(*value_4) = (int32_t)((uint32_t)((*value_4)) - 1u);
|
|
if (c->kernel.budget >= 0) {
|
|
value_2 = !c->kernel.exhausted;
|
|
goto value_3;
|
|
}
|
|
}
|
|
bool* value_5 = &(c->kernel.exhausted);
|
|
(*value_5) = true;
|
|
value_2 = false;
|
|
value_3: ;
|
|
}
|
|
if (!value_2) {
|
|
return -1;
|
|
}
|
|
if (at == after) {
|
|
return compiler_proof_Sequence(c, m, fn, env, rest->start, rest->stop, rest->next, result, (int32_t)((uint32_t)depth + 1u));
|
|
}
|
|
int32_t close = compiler_proof_BlockClose(fn, at, after);
|
|
if (close < 0) {
|
|
Context* value_6 = c;
|
|
String value_7 = StringLiteral("malformed conditional body in proof");
|
|
int32_t value_8 = 0;
|
|
{
|
|
Context* c = value_6;
|
|
String reason = value_7;
|
|
bool* value_10 = &(c->unsupported);
|
|
(*value_10) = true;
|
|
String* value_11 = &(c->reason);
|
|
(*value_11) = reason;
|
|
value_8 = -1;
|
|
}
|
|
return value_8;
|
|
}
|
|
Environment yes = *(env);
|
|
int32_t a = compiler_proof_Sequence(c, m, fn, &(yes), (int32_t)((uint32_t)at + 1u), close, rest, result, (int32_t)((uint32_t)depth + 1u));
|
|
if (a < 0) {
|
|
return -1;
|
|
}
|
|
if ((fn->stmts[at]).is_else != 0 && (fn->stmts[at]).expr_root < 0) {
|
|
return a;
|
|
}
|
|
int32_t cond = compiler_proof_Expression(c, m, fn, (fn->stmts[at]).expr_root, env, 0, (int32_t)((uint32_t)depth + 1u));
|
|
bool value_12 = cond < 0;
|
|
bool value_13 = value_12;
|
|
if (!value_13) {
|
|
Context* value_14 = c;
|
|
int32_t value_15 = 0;
|
|
{
|
|
Context* c = value_14;
|
|
int32_t term = cond;
|
|
value_15 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_13 = (value_15 != 0);
|
|
}
|
|
if (value_13) {
|
|
Context* value_17 = c;
|
|
String value_18 = StringLiteral("proof branch condition must be boolean");
|
|
int32_t value_19 = 0;
|
|
{
|
|
Context* c = value_17;
|
|
String reason = value_18;
|
|
bool* value_21 = &(c->unsupported);
|
|
(*value_21) = true;
|
|
String* value_22 = &(c->reason);
|
|
(*value_22) = reason;
|
|
value_19 = -1;
|
|
}
|
|
return value_19;
|
|
}
|
|
int32_t b = compiler_proof_Arms(c, m, fn, env, (int32_t)((uint32_t)close + 1u), after, rest, result, (int32_t)((uint32_t)depth + 1u));
|
|
bool value_23 = b < 0;
|
|
bool value_24 = value_23;
|
|
if (!value_24) {
|
|
Context* value_25 = c;
|
|
int32_t value_26 = a;
|
|
int32_t value_27 = b;
|
|
bool value_28 = false;
|
|
{
|
|
Context* c = value_25;
|
|
int32_t a = value_26;
|
|
int32_t b = value_27;
|
|
bool value_30 = a >= 0 && b >= 0;
|
|
if (value_30) {
|
|
Context* value_31 = c;
|
|
int32_t value_32 = 0;
|
|
{
|
|
Context* c = value_31;
|
|
int32_t term = a;
|
|
value_32 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
Context* value_34 = c;
|
|
int32_t value_35 = 0;
|
|
{
|
|
Context* c = value_34;
|
|
int32_t term = b;
|
|
value_35 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_30 = (value_32 == value_35);
|
|
}
|
|
value_28 = value_30;
|
|
}
|
|
value_24 = !value_28;
|
|
}
|
|
if (value_24) {
|
|
return -1;
|
|
}
|
|
return compiler_proof_kernel_Node(&(c->kernel), (ProofOp)(11), result, cond, a, b, 0ULL);
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Sequence(Context* c, ZirModule* m, ZirFunction* fn, Environment* env, int32_t start, int32_t stop, Continuation* next, int32_t result, int32_t depth)
|
|
{
|
|
Context* value_0 = c;
|
|
int32_t value_1 = depth;
|
|
bool value_2 = false;
|
|
{
|
|
Context* c = value_0;
|
|
int32_t depth = value_1;
|
|
if (depth <= 64) {
|
|
int32_t* value_4 = &(c->kernel.budget);
|
|
(*value_4) = (int32_t)((uint32_t)((*value_4)) - 1u);
|
|
if (c->kernel.budget >= 0) {
|
|
value_2 = !c->kernel.exhausted;
|
|
goto value_3;
|
|
}
|
|
}
|
|
bool* value_5 = &(c->kernel.exhausted);
|
|
(*value_5) = true;
|
|
value_2 = false;
|
|
value_3: ;
|
|
}
|
|
if (!value_2) {
|
|
return -1;
|
|
}
|
|
{
|
|
int32_t range_first_3 = start;
|
|
int32_t range_last_3 = (int32_t)((uint32_t)stop - 1u);
|
|
int32_t i = range_first_3;
|
|
if (i <= range_last_3) for (;;) {
|
|
Context* value_6 = c;
|
|
int32_t value_7 = depth;
|
|
bool value_8 = false;
|
|
{
|
|
Context* c = value_6;
|
|
int32_t depth = value_7;
|
|
if (depth <= 64) {
|
|
int32_t* value_10 = &(c->kernel.budget);
|
|
(*value_10) = (int32_t)((uint32_t)((*value_10)) - 1u);
|
|
if (c->kernel.budget >= 0) {
|
|
value_8 = !c->kernel.exhausted;
|
|
goto value_9;
|
|
}
|
|
}
|
|
bool* value_11 = &(c->kernel.exhausted);
|
|
(*value_11) = true;
|
|
value_8 = false;
|
|
value_9: ;
|
|
}
|
|
if (!value_8) {
|
|
return -1;
|
|
}
|
|
ZirStmt* s = &(fn->stmts[i]);
|
|
if (((ZirStmtKind)(s->kind)) == ((ZirStmtKind)(10))) {
|
|
int32_t value = compiler_proof_Expression(c, m, fn, s->expr_root, env, result, (int32_t)((uint32_t)depth + 1u));
|
|
bool value_12 = value >= 0;
|
|
bool value_13 = value_12;
|
|
if (value_13) {
|
|
Context* value_14 = c;
|
|
int32_t value_15 = 0;
|
|
{
|
|
Context* c = value_14;
|
|
int32_t term = value;
|
|
value_15 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_13 = (value_15 == result);
|
|
}
|
|
if (value_13) {
|
|
return value;
|
|
}
|
|
Context* value_17 = c;
|
|
String value_18 = StringLiteral("proof return type differs from its declared type");
|
|
int32_t value_19 = 0;
|
|
{
|
|
Context* c = value_17;
|
|
String reason = value_18;
|
|
bool* value_21 = &(c->unsupported);
|
|
(*value_21) = true;
|
|
String* value_22 = &(c->reason);
|
|
(*value_22) = reason;
|
|
value_19 = -1;
|
|
}
|
|
return value_19;
|
|
} else if (((ZirStmtKind)(s->kind)) == ((ZirStmtKind)(3))) {
|
|
Context* value_23 = c;
|
|
ZirModule* value_24 = m;
|
|
int32_t type = compiler_proof_ScalarType(value_23, value_24, compiler_ir_CText((uint8_t*)s->type));
|
|
int32_t value_25 = 0;
|
|
if (s->expr_root >= 0) {
|
|
int32_t value_26 = compiler_proof_Expression(c, m, fn, s->expr_root, env, type, (int32_t)((uint32_t)depth + 1u));
|
|
value_25 = value_26;
|
|
} else {
|
|
Context* value_27 = c;
|
|
int32_t value_28 = type;
|
|
int32_t value_29 = 0;
|
|
{
|
|
Context* c = value_27;
|
|
int32_t type = value_28;
|
|
uint64_t value = 0ULL;
|
|
value_29 = compiler_proof_kernel_Node(&(c->kernel), (ProofOp)(0), type, -1, -1, -1, value);
|
|
}
|
|
value_25 = value_29;
|
|
}
|
|
int32_t value = value_25;
|
|
bool value_31 = type < 0 || value < 0;
|
|
bool value_32 = value_31;
|
|
if (!value_32) {
|
|
Context* value_33 = c;
|
|
int32_t value_34 = 0;
|
|
{
|
|
Context* c = value_33;
|
|
int32_t term = value;
|
|
value_34 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_32 = (value_34 != type);
|
|
}
|
|
bool value_36 = value_32;
|
|
bool value_37 = value_36;
|
|
if (!value_37) {
|
|
Context* value_38 = c;
|
|
Environment* value_39 = env;
|
|
String value_40 = compiler_ir_CText((uint8_t*)s->names.name);
|
|
int32_t value_41 = value;
|
|
bool value_42 = false;
|
|
{
|
|
Context* c = value_38;
|
|
Environment* e = value_39;
|
|
String name = value_40;
|
|
int32_t value = value_41;
|
|
if (value < 0) {
|
|
value_42 = false;
|
|
goto value_43;
|
|
}
|
|
if (e->count == 64) {
|
|
bool* value_44 = &(c->kernel.exhausted);
|
|
(*value_44) = true;
|
|
value_42 = false;
|
|
goto value_43;
|
|
}
|
|
Binding* value_45 = &(ZIRAN_INDEX(e->bindings, sizeof(e->bindings) / sizeof(e->bindings[0]), e->count));
|
|
(*value_45) = (Binding){.name = name, .value = value};
|
|
int32_t* value_46 = &(e->count);
|
|
(*value_46) = (int32_t)((uint32_t)((*value_46)) + 1u);
|
|
value_42 = true;
|
|
value_43: ;
|
|
}
|
|
value_37 = !value_42;
|
|
}
|
|
if (value_37) {
|
|
return -1;
|
|
}
|
|
} else if (((ZirStmtKind)(s->kind)) == ((ZirStmtKind)(4))) {
|
|
ZirFunction* value_47 = fn;
|
|
int32_t value_48 = s->lhs_root;
|
|
bool value_49 = false;
|
|
{
|
|
ZirFunction* fn = value_47;
|
|
int32_t at = value_48;
|
|
value_49 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
if (!value_49 || ((ZirExprKind)((fn->exprs[s->lhs_root]).kind)) != ((ZirExprKind)(1))) {
|
|
Context* value_51 = c;
|
|
String value_52 = StringLiteral("proof procedures can assign only scalar locals");
|
|
int32_t value_53 = 0;
|
|
{
|
|
Context* c = value_51;
|
|
String reason = value_52;
|
|
bool* value_55 = &(c->unsupported);
|
|
(*value_55) = true;
|
|
String* value_56 = &(c->reason);
|
|
(*value_56) = reason;
|
|
value_53 = -1;
|
|
}
|
|
return value_53;
|
|
}
|
|
Environment* value_57 = env;
|
|
int32_t local = compiler_proof_Find(value_57, compiler_ir_CText((uint8_t*)(fn->exprs[s->lhs_root]).name));
|
|
if (local < 0) {
|
|
Context* value_58 = c;
|
|
String value_59 = StringLiteral("proof procedure writes outside its local scope");
|
|
int32_t value_60 = 0;
|
|
{
|
|
Context* c = value_58;
|
|
String reason = value_59;
|
|
bool* value_62 = &(c->unsupported);
|
|
(*value_62) = true;
|
|
String* value_63 = &(c->reason);
|
|
(*value_63) = reason;
|
|
value_60 = -1;
|
|
}
|
|
return value_60;
|
|
}
|
|
int32_t old = (ZIRAN_INDEX(env->bindings, sizeof(env->bindings) / sizeof(env->bindings[0]), local)).value;
|
|
Context* value_64 = c;
|
|
int32_t value_65 = 0;
|
|
{
|
|
Context* c = value_64;
|
|
int32_t term = old;
|
|
value_65 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
int32_t type = value_65;
|
|
int32_t value = compiler_proof_Expression(c, m, fn, s->expr_root, env, type, (int32_t)((uint32_t)depth + 1u));
|
|
bool value_67 = value < 0;
|
|
bool value_68 = value_67;
|
|
if (!value_68) {
|
|
Context* value_69 = c;
|
|
int32_t value_70 = 0;
|
|
{
|
|
Context* c = value_69;
|
|
int32_t term = value;
|
|
value_70 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_68 = (value_70 != type);
|
|
}
|
|
if (value_68) {
|
|
return -1;
|
|
}
|
|
Slice value_72 = {s->assignment_op, 4};
|
|
String assignment = compiler_proof_Name(value_72);
|
|
if (StringEqual(assignment, StringLiteral("+="))) {
|
|
Context* value_73 = c;
|
|
ProofOp value_74 = (ProofOp)((ProofOp)(2));
|
|
int32_t value_75 = type;
|
|
int32_t value_76 = 0;
|
|
{
|
|
Context* c = value_73;
|
|
ProofOp op = (ProofOp)(value_74);
|
|
int32_t type = value_75;
|
|
int32_t a = old;
|
|
int32_t b = value;
|
|
value_76 = compiler_proof_kernel_Node(&(c->kernel), op, type, a, b, -1, 0ULL);
|
|
}
|
|
value = value_76;
|
|
} else if (StringEqual(assignment, StringLiteral("-="))) {
|
|
Context* value_78 = c;
|
|
ProofOp value_79 = (ProofOp)((ProofOp)(3));
|
|
int32_t value_80 = type;
|
|
int32_t value_81 = 0;
|
|
{
|
|
Context* c = value_78;
|
|
ProofOp op = (ProofOp)(value_79);
|
|
int32_t type = value_80;
|
|
int32_t a = old;
|
|
int32_t b = value;
|
|
value_81 = compiler_proof_kernel_Node(&(c->kernel), op, type, a, b, -1, 0ULL);
|
|
}
|
|
value = value_81;
|
|
} else if (StringEqual(assignment, StringLiteral("*="))) {
|
|
Context* value_83 = c;
|
|
ProofOp value_84 = (ProofOp)((ProofOp)(4));
|
|
int32_t value_85 = type;
|
|
int32_t value_86 = 0;
|
|
{
|
|
Context* c = value_83;
|
|
ProofOp op = (ProofOp)(value_84);
|
|
int32_t type = value_85;
|
|
int32_t a = old;
|
|
int32_t b = value;
|
|
value_86 = compiler_proof_kernel_Node(&(c->kernel), op, type, a, b, -1, 0ULL);
|
|
}
|
|
value = value_86;
|
|
} else if ((int64_t)(assignment).length > 0LL && !StringEqual(assignment, StringLiteral("="))) {
|
|
Context* value_88 = c;
|
|
String value_89 = StringLiteral("unsupported scalar assignment in proof");
|
|
int32_t value_90 = 0;
|
|
{
|
|
Context* c = value_88;
|
|
String reason = value_89;
|
|
bool* value_92 = &(c->unsupported);
|
|
(*value_92) = true;
|
|
String* value_93 = &(c->reason);
|
|
(*value_93) = reason;
|
|
value_90 = -1;
|
|
}
|
|
return value_90;
|
|
}
|
|
int32_t* value_94 = &((ZIRAN_INDEX(env->bindings, sizeof(env->bindings) / sizeof(env->bindings[0]), local)).value);
|
|
(*value_94) = value;
|
|
} else if (((ZirStmtKind)(s->kind)) == ((ZirStmtKind)(6)) || ((ZirStmtKind)(s->kind)) == ((ZirStmtKind)(1))) {
|
|
int32_t after = i;
|
|
while (true) {
|
|
bool value_95 = after == i;
|
|
if (!value_95) {
|
|
bool value_96 = ((ZirStmtKind)(s->kind)) == ((ZirStmtKind)(6)) && after < stop && ((ZirStmtKind)((fn->stmts[after]).kind)) == ((ZirStmtKind)(6));
|
|
value_95 = (value_96 && (fn->stmts[after]).is_else != 0);
|
|
}
|
|
if (!value_95) { break; }
|
|
int32_t close = compiler_proof_BlockClose(fn, after, stop);
|
|
if (close < 0) {
|
|
Context* value_97 = c;
|
|
String value_98 = StringView(NULL, 0);
|
|
if (((ZirStmtKind)(s->kind)) == ((ZirStmtKind)(6))) {
|
|
value_98 = StringLiteral("malformed branch in proof procedure");
|
|
} else {
|
|
value_98 = StringLiteral("malformed scope in proof procedure");
|
|
}
|
|
int32_t value_99 = 0;
|
|
{
|
|
Context* c = value_97;
|
|
String reason = value_98;
|
|
bool* value_101 = &(c->unsupported);
|
|
(*value_101) = true;
|
|
String* value_102 = &(c->reason);
|
|
(*value_102) = reason;
|
|
value_99 = -1;
|
|
}
|
|
return value_99;
|
|
}
|
|
after = (int32_t)((uint32_t)close + 1u);
|
|
}
|
|
Continuation rest = {.start = after, .stop = stop, .scope = env->count, .next = next};
|
|
if (((ZirStmtKind)(s->kind)) == ((ZirStmtKind)(6))) {
|
|
return compiler_proof_Arms(c, m, fn, env, i, after, &(rest), result, (int32_t)((uint32_t)depth + 1u));
|
|
}
|
|
return compiler_proof_Sequence(c, m, fn, env, (int32_t)((uint32_t)i + 1u), (int32_t)((uint32_t)after - 1u), &(rest), result, (int32_t)((uint32_t)depth + 1u));
|
|
} else if (((ZirStmtKind)(s->kind)) == ((ZirStmtKind)(5))) {
|
|
if (compiler_proof_Expression(c, m, fn, s->expr_root, env, -1, (int32_t)((uint32_t)depth + 1u)) < 0) {
|
|
return -1;
|
|
}
|
|
} else if (((ZirStmtKind)(s->kind)) != ((ZirStmtKind)(14))) {
|
|
Context* value_103 = c;
|
|
String value_104 = StringLiteral("loops, pointers, and effects are outside scalar proofs");
|
|
int32_t value_105 = 0;
|
|
{
|
|
Context* c = value_103;
|
|
String reason = value_104;
|
|
bool* value_107 = &(c->unsupported);
|
|
(*value_107) = true;
|
|
String* value_108 = &(c->reason);
|
|
(*value_108) = reason;
|
|
value_105 = -1;
|
|
}
|
|
return value_105;
|
|
}
|
|
if (i == range_last_3) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
if (next == ((void *)0)) {
|
|
Context* value_109 = c;
|
|
String value_110 = StringLiteral("proof procedures must return on every branch");
|
|
int32_t value_111 = 0;
|
|
{
|
|
Context* c = value_109;
|
|
String reason = value_110;
|
|
bool* value_113 = &(c->unsupported);
|
|
(*value_113) = true;
|
|
String* value_114 = &(c->reason);
|
|
(*value_114) = reason;
|
|
value_111 = -1;
|
|
}
|
|
return value_111;
|
|
}
|
|
int32_t* value_115 = &(env->count);
|
|
(*value_115) = next->scope;
|
|
return compiler_proof_Sequence(c, m, fn, env, next->start, next->stop, next->next, result, (int32_t)((uint32_t)depth + 1u));
|
|
}
|
|
|
|
static ZirLaw*
|
|
compiler_proof_FindLaw(ZirModule* m, String name, int32_t depth, ZirModule** owner)
|
|
{
|
|
if (depth > 16) {
|
|
return (void *)0;
|
|
}
|
|
int64_t dot = compiler_proof_Index(name, 46);
|
|
if (dot < (int64_t)(name).length) {
|
|
{
|
|
int32_t range_first_5 = 0;
|
|
int32_t range_last_5 = (int32_t)((uint32_t)(m->import_count) - 1u);
|
|
int32_t i = range_first_5;
|
|
if (i <= range_last_5) for (;;) {
|
|
ZirImport* import = &(m->imports[i]);
|
|
bool value_0 = ((ZirModule*)import->resolved_module) != ((void *)0);
|
|
bool value_1 = value_0;
|
|
if (value_1) {
|
|
Slice value_2 = {import->name, 128};
|
|
String value_3 = compiler_proof_Name(value_2);
|
|
value_1 = (StringEqual(value_3, StringRange(name, (int64_t)0LL, (int64_t)dot)));
|
|
}
|
|
if (value_1) {
|
|
String value_4 = StringRange(name, (int64_t)((int64_t)((uint64_t)dot + UINT64_C(1))), (int64_t)(int64_t)(name).length);
|
|
return compiler_proof_FindLaw((ZirModule*)import->resolved_module, value_4, (int32_t)((uint32_t)depth + 1u), owner);
|
|
}
|
|
if (i == range_last_5) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
return (void *)0;
|
|
}
|
|
{
|
|
int32_t range_first_13 = 0;
|
|
int32_t range_last_13 = (int32_t)((uint32_t)(m->law_count) - 1u);
|
|
int32_t i = range_first_13;
|
|
if (i <= range_last_13) for (;;) {
|
|
Slice value_5 = {(m->laws[i]).name, 128};
|
|
String value_6 = compiler_proof_Name(value_5);
|
|
if (StringEqual(value_6, name)) {
|
|
ZirModule** value_7 = &((*(owner)));
|
|
(*value_7) = m;
|
|
return &(m->laws[i]);
|
|
}
|
|
if (i == range_last_13) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
ZirLaw* found = (void *)0;
|
|
{
|
|
int32_t range_first_20 = 0;
|
|
int32_t range_last_20 = (int32_t)((uint32_t)(m->import_count) - 1u);
|
|
int32_t i = range_first_20;
|
|
if (i <= range_last_20) for (;;) {
|
|
ZirImport* import = &(m->imports[i]);
|
|
if (((ZirImportKind)(import->kind)) == ((ZirImportKind)(1)) && ((ZirModule*)import->resolved_module) != ((void *)0)) {
|
|
ZirModule* candidate_owner = (void *)0;
|
|
ZirLaw* candidate = compiler_proof_FindLaw((ZirModule*)import->resolved_module, name, (int32_t)((uint32_t)depth + 1u), &(candidate_owner));
|
|
if (candidate != ((void *)0) && found != ((void *)0) && found != candidate) {
|
|
return (void *)0;
|
|
}
|
|
if (candidate != ((void *)0)) {
|
|
found = candidate;
|
|
ZirModule** value_8 = &((*(owner)));
|
|
(*value_8) = candidate_owner;
|
|
}
|
|
}
|
|
if (i == range_last_20) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
return found;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_GraphVisit(ZirFunction* fn, int32_t at, Slice seen, int32_t depth)
|
|
{
|
|
if (at == -1) {
|
|
return true;
|
|
}
|
|
ZirFunction* value_0 = fn;
|
|
int32_t value_1 = at;
|
|
bool value_2 = false;
|
|
{
|
|
ZirFunction* fn = value_0;
|
|
int32_t at = value_1;
|
|
value_2 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
if (!value_2 || depth > 64 || ((uint8_t *)seen.data)[SliceIndex(seen, (int64_t)at)] == 1) {
|
|
return false;
|
|
}
|
|
if (((uint8_t *)seen.data)[SliceIndex(seen, (int64_t)at)] == 2) {
|
|
return true;
|
|
}
|
|
uint8_t* value_4 = &(((uint8_t *)seen.data)[SliceIndex(seen, (int64_t)at)]);
|
|
(*value_4) = 1;
|
|
ZirExpr* e = &(fn->exprs[at]);
|
|
bool value_5 = compiler_proof_GraphVisit(fn, e->left, seen, (int32_t)((uint32_t)depth + 1u));
|
|
bool value_6 = !value_5;
|
|
if (!value_6) {
|
|
bool value_7 = compiler_proof_GraphVisit(fn, e->right, seen, (int32_t)((uint32_t)depth + 1u));
|
|
value_6 = !value_7;
|
|
}
|
|
bool value_8 = value_6;
|
|
if (!value_8) {
|
|
bool value_9 = compiler_proof_GraphVisit(fn, e->third, seen, (int32_t)((uint32_t)depth + 1u));
|
|
value_8 = !value_9;
|
|
}
|
|
bool value_10 = value_8;
|
|
if (!value_10) {
|
|
bool value_11 = compiler_proof_GraphVisit(fn, e->first_child, seen, (int32_t)((uint32_t)depth + 1u));
|
|
value_10 = !value_11;
|
|
}
|
|
bool value_12 = value_10;
|
|
if (!value_12) {
|
|
bool value_13 = compiler_proof_GraphVisit(fn, e->next_sibling, seen, (int32_t)((uint32_t)depth + 1u));
|
|
value_12 = !value_13;
|
|
}
|
|
if (value_12) {
|
|
return false;
|
|
}
|
|
uint8_t* value_14 = &(((uint8_t *)seen.data)[SliceIndex(seen, (int64_t)at)]);
|
|
(*value_14) = 2;
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_GraphValid(ZirFunction* fn)
|
|
{
|
|
__type_838711075b90279a seen = {0};
|
|
__type_838711075b90279a* value_0 = &seen;
|
|
bool value_1 = fn->expr_count < 0 || fn->expr_count > 4096 || fn->checked != 0;
|
|
bool value_2 = value_1;
|
|
if (!value_2) {
|
|
int64_t value_4 = (int64_t)((uint64_t)(fn->expr_count) + UINT64_C(1));
|
|
bool value_5 = false;
|
|
if (value_4 >= 0) {
|
|
value_5 = value_4 <= (seen).capacity;
|
|
if (!value_5) {
|
|
void *value_6 = ZirVecReserve((void *)(seen).data, &(seen).capacity, (seen).count, value_4 - (seen).count, sizeof(*(seen).data));
|
|
if (value_6 != NULL) { (seen).data = (uint8_t *)value_6; value_5 = true; }
|
|
}
|
|
if (value_5) {
|
|
if (value_4 > (seen).count) memset((seen).data + (seen).count, 0, (size_t)(value_4 - (seen).count) * sizeof(*(seen).data));
|
|
(seen).count = value_4;
|
|
}
|
|
}
|
|
value_2 = !value_5;
|
|
}
|
|
if (value_2) {
|
|
bool value_8 = false;
|
|
free((*value_0).data);
|
|
(*value_0).data = NULL;
|
|
(*value_0).capacity = 0;
|
|
(*value_0).count = 0;
|
|
return value_8;
|
|
}
|
|
{
|
|
int32_t range_first_4 = 0;
|
|
int32_t range_last_4 = (int32_t)((uint32_t)(fn->expr_count) - 1u);
|
|
int32_t i = range_first_4;
|
|
if (i <= range_last_4) for (;;) {
|
|
ZirExpr* e = &(fn->exprs[i]);
|
|
bool value_9 = ((ZirExprKind)(e->kind)) <= ((ZirExprKind)(0)) || ((ZirExprKind)(e->kind)) > ((ZirExprKind)(17)) || (e->is_function_value != 0 && e->is_function_value != 1);
|
|
bool value_10 = value_9 || (e->is_this != 0 && e->is_this != 1) || e->argument_index < -1 || e->argument_index >= 64;
|
|
bool value_11 = value_10;
|
|
bool value_12 = value_11;
|
|
if (!value_12) {
|
|
ZirFunction* value_13 = fn;
|
|
int32_t value_14 = i;
|
|
Slice value_15 = {(seen).data, (seen).count};
|
|
bool value_16 = compiler_proof_GraphVisit(value_13, value_14, SliceRange(value_15, 0LL, seen.count, sizeof(*(seen).data)), 0);
|
|
value_12 = !value_16;
|
|
}
|
|
if (value_12) {
|
|
bool value_17 = false;
|
|
free((*value_0).data);
|
|
(*value_0).data = NULL;
|
|
(*value_0).capacity = 0;
|
|
(*value_0).count = 0;
|
|
return value_17;
|
|
}
|
|
if (i == range_last_4) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
bool value_18 = true;
|
|
free((*value_0).data);
|
|
(*value_0).data = NULL;
|
|
(*value_0).capacity = 0;
|
|
(*value_0).count = 0;
|
|
return value_18;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_ParseSteps(ZirProof* p, ZirModule* m)
|
|
{
|
|
Slice value_0 = {p->source, 4096};
|
|
String source = compiler_proof_Name(value_0);
|
|
int64_t at = compiler_text_SkipSpace(source, 0LL, false);
|
|
bool closed = false;
|
|
while (at < (int64_t)(source).length) {
|
|
int64_t value_1 = at;
|
|
int64_t end = (int64_t)((uint64_t)value_1 + (uint64_t)(compiler_proof_Index(StringRange(source, (int64_t)at, (int64_t)(int64_t)(source).length), 59)));
|
|
if (end == (int64_t)(source).length || (int64_t)((uint64_t)end - (uint64_t)at) >= 4096LL || closed) {
|
|
return false;
|
|
}
|
|
String value_2 = StringRange(source, (int64_t)at, (int64_t)end);
|
|
String value_3 = StringView(NULL, 0);
|
|
{
|
|
String text = value_2;
|
|
SourceRange range = compiler_text_TrimRange(text);
|
|
value_3 = StringRange(text, (int64_t)range.begin, (int64_t)range.end);
|
|
}
|
|
String text = value_3;
|
|
int64_t length = 0LL;
|
|
while (true) {
|
|
bool value_5 = length < (int64_t)(text).length && ((uint8_t)((uint32_t)((uint8_t)ZIRAN_INDEX(text.data, text.length, length)) | 32u)) >= 97;
|
|
if (!(value_5 && ((uint8_t)((uint32_t)((uint8_t)ZIRAN_INDEX(text.data, text.length, length)) | 32u)) <= 122)) { break; }
|
|
length = (int64_t)((uint64_t)length + UINT64_C(1));
|
|
}
|
|
String word = StringRange(text, (int64_t)0LL, (int64_t)length);
|
|
String value_6 = text;
|
|
int64_t value_7 = compiler_text_SkipSpace(text, length, false);
|
|
String operand = StringRange(value_6, (int64_t)value_7, (int64_t)(int64_t)(text).length);
|
|
ZirProofStep step = {0};
|
|
int32_t* value_8 = &(step.term_root);
|
|
(*value_8) = -1;
|
|
ZirSourceSpan* value_9 = &(step.span);
|
|
(*value_9) = p->span;
|
|
String words[7] = {StringLiteral("unfold"), StringLiteral("cases"), StringLiteral("rewrite"), StringLiteral("use"), StringLiteral("refl"), StringLiteral("ring"), StringLiteral("order")};
|
|
for (int64_t i = 0LL; i <= 6LL; i++) {
|
|
if (StringEqual((words)[i], word)) {
|
|
ZirProofStepKind* value_10 = &(step.kind);
|
|
(*value_10) = (ZirProofStepKind)((int32_t)(((int64_t)((uint64_t)i + UINT64_C(1)))));
|
|
}
|
|
}
|
|
if ((int32_t)(((ZirProofStepKind)(step.kind))) == 0) {
|
|
return false;
|
|
}
|
|
closed = ((ZirProofStepKind)(step.kind)) >= ((ZirProofStepKind)(4));
|
|
if (((ZirProofStepKind)(step.kind)) == ((ZirProofStepKind)(3)) || ((ZirProofStepKind)(step.kind)) == ((ZirProofStepKind)(4))) {
|
|
Long spelled = compiler_proof_CLong(operand);
|
|
int32_t* value_11 = &(step.term_root);
|
|
int32_t value_12 = zir_f_5116a9a569c28f15_ParseExpr(&(p->terms), m, &(spelled.bytes[0]), step.span);
|
|
(*value_11) = value_12;
|
|
bool value_13 = step.term_root < 0 || ((ZirExprKind)((p->terms.exprs[step.term_root]).kind)) != ((ZirExprKind)(5));
|
|
bool value_14 = value_13;
|
|
bool value_15 = value_14;
|
|
if (!value_15) {
|
|
Slice value_16 = {step.target, 128};
|
|
bool value_17 = compiler_proof_CallName(&(p->terms), &(p->terms.exprs[step.term_root]), value_16);
|
|
value_15 = !value_17;
|
|
}
|
|
if (value_15) {
|
|
return false;
|
|
}
|
|
} else if (((ZirProofStepKind)(step.kind)) == ((ZirProofStepKind)(1))) {
|
|
Slice value_18 = {step.target, 128};
|
|
bool value_19 = compiler_ir_CopyText(value_18, operand);
|
|
if (!value_19) {
|
|
return false;
|
|
}
|
|
} else if ((int64_t)(operand).length > 0LL) {
|
|
return false;
|
|
}
|
|
uint8_t* value_20 = zir_f_5116a9a569c28f15_realloc((uint8_t*)(p->steps), (size_t)(((int32_t)((uint32_t)(p->step_count) + 1u))) * sizeof(ZirProofStep));
|
|
ZirProofStep* steps = (ZirProofStep*)(value_20);
|
|
if (steps == ((void *)0)) {
|
|
return false;
|
|
}
|
|
ZirProofStep** value_21 = &(p->steps);
|
|
(*value_21) = steps;
|
|
ZirProofStep* value_22 = &(p->steps[p->step_count]);
|
|
(*value_22) = step;
|
|
int32_t* value_23 = &(p->step_count);
|
|
(*value_23) = (int32_t)((uint32_t)((*value_23)) + 1u);
|
|
at = compiler_text_SkipSpace(source, (int64_t)((uint64_t)end + UINT64_C(1)), false);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_PrepareClaim(ZirModule* module, ZirLaw* law)
|
|
{
|
|
Slice value_0 = {law->payload, 4096};
|
|
String payload = compiler_proof_Name(value_0);
|
|
int64_t arrow = 0LL;
|
|
while ((int64_t)((uint64_t)arrow + UINT64_C(1)) < (int64_t)(payload).length && ((uint8_t)ZIRAN_INDEX(payload.data, payload.length, arrow) != 61 || (uint8_t)ZIRAN_INDEX(payload.data, payload.length, ((int64_t)((uint64_t)arrow + UINT64_C(1)))) != 62)) {
|
|
arrow = (int64_t)((uint64_t)arrow + UINT64_C(1));
|
|
}
|
|
String value_1 = StringView(NULL, 0);
|
|
if ((int64_t)((uint64_t)arrow + UINT64_C(1)) < (int64_t)(payload).length) {
|
|
String value_2 = payload;
|
|
int64_t value_3 = compiler_text_SkipSpace(payload, (int64_t)((uint64_t)arrow + UINT64_C(2)), false);
|
|
value_1 = StringRange(value_2, (int64_t)value_3, (int64_t)(int64_t)(payload).length);
|
|
} else {
|
|
value_1 = StringLiteral("");
|
|
}
|
|
String proposition = value_1;
|
|
if ((int64_t)(proposition).length == 0LL) {
|
|
ZirSourceSpan value_4 = law->span;
|
|
String value_5 = StringLiteral("proof.claim");
|
|
String value_6 = StringLiteral("theorem requires typed bindings => boolean proposition");
|
|
String value_7 = StringLiteral("");
|
|
String value_8 = StringLiteral("");
|
|
bool value_9 = false;
|
|
{
|
|
ZirSourceSpan span = value_4;
|
|
String code = value_5;
|
|
String message = value_6;
|
|
String name = value_7;
|
|
String tail = value_8;
|
|
compiler_services_Diagnose__overload_2(span, code, message, name, tail);
|
|
value_9 = false;
|
|
}
|
|
return value_9;
|
|
}
|
|
String value_11 = StringRange(payload, (int64_t)0LL, (int64_t)arrow);
|
|
String value_12 = StringView(NULL, 0);
|
|
{
|
|
String text = value_11;
|
|
SourceRange range = compiler_text_TrimRange(text);
|
|
value_12 = StringRange(text, (int64_t)range.begin, (int64_t)range.end);
|
|
}
|
|
String args = value_12;
|
|
Signature bindings = {0};
|
|
bool ok = compiler_proof_ParseSignature(args, &(bindings));
|
|
if (law->claim == ((void *)0) && ok) {
|
|
ZirFunction** value_14 = &(law->claim);
|
|
uint8_t* value_15 = zir_f_5116a9a569c28f15_calloc(1, sizeof(ZirFunction));
|
|
(*value_14) = (ZirFunction*)(value_15);
|
|
if (law->claim == ((void *)0)) {
|
|
return false;
|
|
}
|
|
const char ** value_16 = &(law->claim->args_text);
|
|
uint8_t* value_17 = compiler_services_KeepParameters(args);
|
|
(*value_16) = (const char *)(value_17);
|
|
Slice value_18 = {law->claim->return_type, 128};
|
|
compiler_ir_CopyText(value_18, StringLiteral("bool"));
|
|
ZirSourceSpan* value_19 = &(law->claim->span);
|
|
(*value_19) = law->span;
|
|
Long text = compiler_proof_CLong(proposition);
|
|
int32_t root = zir_f_5116a9a569c28f15_ParseExpr(law->claim, module, &(text.bytes[0]), law->span);
|
|
ZirStmt* s = zir_f_5116a9a569c28f15_FunctionAddStmt(law->claim, (ZirStmtKind)(10), &(text.bytes[0]), law->span);
|
|
if (s != ((void *)0)) {
|
|
int32_t* value_20 = &(s->expr_root);
|
|
(*value_20) = root;
|
|
}
|
|
ok = root >= 0 && s != ((void *)0);
|
|
}
|
|
ZirFunction* claim = law->claim;
|
|
bool value_21 = !ok || claim == ((void *)0);
|
|
bool value_22 = value_21;
|
|
if (!value_22) {
|
|
String value_23 = StringView(NULL, 0);
|
|
{
|
|
ZirFunction* fn = claim;
|
|
value_23 = compiler_ir_CText((uint8_t*)fn->args_text);
|
|
}
|
|
value_22 = (!StringEqual(value_23, args));
|
|
}
|
|
bool value_25 = value_22;
|
|
bool value_26 = value_25;
|
|
if (!value_26) {
|
|
Slice value_27 = {claim->return_type, 128};
|
|
bool value_28 = !StringEqual(compiler_proof_Name(value_27), StringLiteral("bool"));
|
|
value_26 = value_28;
|
|
}
|
|
bool value_29 = value_26 || claim->stmt_count != 1 || ((ZirStmtKind)((claim->stmts[0]).kind)) != ((ZirStmtKind)(10));
|
|
bool value_30 = value_29;
|
|
bool value_31 = value_30;
|
|
if (!value_31) {
|
|
int32_t value_32 = (claim->stmts[0]).expr_root;
|
|
bool value_33 = false;
|
|
{
|
|
ZirFunction* fn = claim;
|
|
int32_t at = value_32;
|
|
value_33 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
value_31 = !value_33;
|
|
}
|
|
bool value_35 = value_31;
|
|
bool value_36 = value_35;
|
|
if (!value_36) {
|
|
bool value_37 = compiler_proof_GraphValid(claim);
|
|
value_36 = !value_37;
|
|
}
|
|
if (value_36) {
|
|
ZirSourceSpan value_38 = law->span;
|
|
String value_39 = StringLiteral("proof.claim");
|
|
String value_40 = StringLiteral("malformed theorem proposition");
|
|
String value_41 = StringLiteral("");
|
|
String value_42 = StringLiteral("");
|
|
bool value_43 = false;
|
|
{
|
|
ZirSourceSpan span = value_38;
|
|
String code = value_39;
|
|
String message = value_40;
|
|
String name = value_41;
|
|
String tail = value_42;
|
|
compiler_services_Diagnose__overload_2(span, code, message, name, tail);
|
|
value_43 = false;
|
|
}
|
|
return value_43;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
static bool
|
|
compiler_proof_PrepareProof(ZirModule* module, ZirProof* proof)
|
|
{
|
|
ZirModule* owner = (void *)0;
|
|
ZirModule* value_0 = module;
|
|
Slice value_1 = {proof->name, 128};
|
|
ZirLaw* law = compiler_proof_FindLaw(value_0, compiler_proof_Name(value_1), 0, &(owner));
|
|
bool value_2 = law == ((void *)0);
|
|
bool value_3 = value_2;
|
|
if (!value_3) {
|
|
Slice value_4 = {law->kind, 16};
|
|
bool value_5 = !StringEqual(compiler_proof_Name(value_4), StringLiteral("theorem"));
|
|
value_3 = value_5;
|
|
}
|
|
if (value_3 || ((ZirProof*)law->proof) != ((void *)0)) {
|
|
ZirSourceSpan value_6 = proof->span;
|
|
String value_7 = StringLiteral("proof.identity");
|
|
String value_8 = StringLiteral("proof ");
|
|
Slice value_9 = {proof->name, 128};
|
|
String value_10 = compiler_proof_Name(value_9);
|
|
String value_11 = StringLiteral(" must name one visible, unproved theorem");
|
|
bool value_12 = false;
|
|
{
|
|
ZirSourceSpan span = value_6;
|
|
String code = value_7;
|
|
String message = value_8;
|
|
String name = value_10;
|
|
String tail = value_11;
|
|
compiler_services_Diagnose__overload_2(span, code, message, name, tail);
|
|
value_12 = false;
|
|
}
|
|
return value_12;
|
|
}
|
|
const struct ZirModule ** value_14 = &(proof->owner);
|
|
(*value_14) = (const struct ZirModule *)(module);
|
|
bool value_15 = proof->step_count == 0;
|
|
bool value_16 = value_15;
|
|
if (value_16) {
|
|
bool value_17 = compiler_proof_ParseSteps(proof, owner);
|
|
value_16 = !value_17;
|
|
}
|
|
if (value_16) {
|
|
ZirSourceSpan value_18 = proof->span;
|
|
String value_19 = StringLiteral("proof.syntax");
|
|
String value_20 = StringLiteral("invalid proof steps for ");
|
|
Slice value_21 = {proof->name, 128};
|
|
String value_22 = compiler_proof_Name(value_21);
|
|
String value_23 = StringLiteral("");
|
|
bool value_24 = false;
|
|
{
|
|
ZirSourceSpan span = value_18;
|
|
String code = value_19;
|
|
String message = value_20;
|
|
String name = value_22;
|
|
String tail = value_23;
|
|
compiler_services_Diagnose__overload_2(span, code, message, name, tail);
|
|
value_24 = false;
|
|
}
|
|
return value_24;
|
|
}
|
|
bool value_26 = proof->step_count > 4096 || proof->terms.stmt_count != 0;
|
|
bool value_27 = value_26;
|
|
if (!value_27) {
|
|
bool value_28 = compiler_proof_GraphValid(&(proof->terms));
|
|
value_27 = !value_28;
|
|
}
|
|
if (value_27) {
|
|
ZirSourceSpan value_29 = proof->span;
|
|
String value_30 = StringLiteral("proof.graph");
|
|
String value_31 = StringLiteral("invalid proof expression graph");
|
|
String value_32 = StringLiteral("");
|
|
String value_33 = StringLiteral("");
|
|
bool value_34 = false;
|
|
{
|
|
ZirSourceSpan span = value_29;
|
|
String code = value_30;
|
|
String message = value_31;
|
|
String name = value_32;
|
|
String tail = value_33;
|
|
compiler_services_Diagnose__overload_2(span, code, message, name, tail);
|
|
value_34 = false;
|
|
}
|
|
return value_34;
|
|
}
|
|
{
|
|
int32_t range_first_12 = 0;
|
|
int32_t range_last_12 = (int32_t)((uint32_t)(proof->step_count) - 1u);
|
|
int32_t s = range_first_12;
|
|
if (s <= range_last_12) for (;;) {
|
|
ZirProofStep* step = &(proof->steps[s]);
|
|
bool valid = ((ZirProofStepKind)(step->kind)) >= ((ZirProofStepKind)(1)) && ((ZirProofStepKind)(step->kind)) <= ((ZirProofStepKind)(7));
|
|
if (((ZirProofStepKind)(step->kind)) == ((ZirProofStepKind)(3)) || ((ZirProofStepKind)(step->kind)) == ((ZirProofStepKind)(4))) {
|
|
bool value_36 = valid;
|
|
bool value_37 = value_36;
|
|
if (value_37) {
|
|
ZirFunction* value_38 = &(proof->terms);
|
|
int32_t value_39 = step->term_root;
|
|
bool value_40 = false;
|
|
{
|
|
ZirFunction* fn = value_38;
|
|
int32_t at = value_39;
|
|
value_40 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
value_37 = value_40;
|
|
}
|
|
valid = value_37;
|
|
} else {
|
|
valid = valid && step->term_root == -1 && (((ZirProofStepKind)(step->kind)) == ((ZirProofStepKind)(1)) || (step->target)[0] == 0);
|
|
}
|
|
if (!valid) {
|
|
ZirSourceSpan value_42 = proof->span;
|
|
String value_43 = StringLiteral("proof.graph");
|
|
String value_44 = StringLiteral("invalid proof step");
|
|
String value_45 = StringLiteral("");
|
|
String value_46 = StringLiteral("");
|
|
bool value_47 = false;
|
|
{
|
|
ZirSourceSpan span = value_42;
|
|
String code = value_43;
|
|
String message = value_44;
|
|
String name = value_45;
|
|
String tail = value_46;
|
|
compiler_services_Diagnose__overload_2(span, code, message, name, tail);
|
|
value_47 = false;
|
|
}
|
|
return value_47;
|
|
}
|
|
if (s == range_last_12) {
|
|
break;
|
|
}
|
|
s = (int32_t)((uint32_t)s + 1u);
|
|
}
|
|
}
|
|
const ZirProof ** value_49 = &(law->proof);
|
|
(*value_49) = (const ZirProof *)(proof);
|
|
return true;
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Application(Context* c, ZirModule* m, ZirProof* proof, ZirProofStep* step, Environment* env, int32_t depth)
|
|
{
|
|
ZirModule* owner = (void *)0;
|
|
Slice value_0 = {step->target, 128};
|
|
String target = compiler_proof_Name(value_0);
|
|
ZirLaw* law = compiler_proof_FindLaw((ZirModule*)proof->owner, target, 0, &(owner));
|
|
if (law == ((void *)0)) {
|
|
law = compiler_proof_FindLaw(m, target, 0, &(owner));
|
|
}
|
|
bool value_1 = law == ((void *)0);
|
|
bool value_2 = value_1;
|
|
if (!value_2) {
|
|
Slice value_3 = {law->kind, 16};
|
|
bool value_4 = !StringEqual(compiler_proof_Name(value_3), StringLiteral("theorem"));
|
|
value_2 = value_4;
|
|
}
|
|
if (value_2 || law->claim == ((void *)0)) {
|
|
Context* value_5 = c;
|
|
String value_6 = StringLiteral("proof step names no visible theorem");
|
|
int32_t value_7 = 0;
|
|
{
|
|
Context* c = value_5;
|
|
String reason = value_6;
|
|
bool* value_9 = &(c->unsupported);
|
|
(*value_9) = true;
|
|
String* value_10 = &(c->reason);
|
|
(*value_10) = reason;
|
|
value_7 = -1;
|
|
}
|
|
return value_7;
|
|
}
|
|
ZirFunction* terms = &(proof->terms);
|
|
Spelled name = {0};
|
|
Signature p = {0};
|
|
int32_t value_11 = step->term_root;
|
|
bool value_12 = false;
|
|
{
|
|
ZirFunction* fn = terms;
|
|
int32_t at = value_11;
|
|
value_12 = at >= 0 && at < fn->expr_count;
|
|
}
|
|
bool value_14 = !value_12 || ((ZirExprKind)((terms->exprs[step->term_root]).kind)) != ((ZirExprKind)(5));
|
|
bool value_15 = value_14;
|
|
if (!value_15) {
|
|
Slice value_16 = {name.bytes, 128};
|
|
bool value_17 = compiler_proof_CallName(terms, &(terms->exprs[step->term_root]), value_16);
|
|
value_15 = !value_17;
|
|
}
|
|
bool value_18 = value_15;
|
|
bool value_19 = value_18;
|
|
if (!value_19) {
|
|
Slice value_20 = {name.bytes, 128};
|
|
String value_21 = compiler_proof_Name(value_20);
|
|
value_19 = (!StringEqual(value_21, target));
|
|
}
|
|
bool value_22 = value_19;
|
|
bool value_23 = value_22;
|
|
if (!value_23) {
|
|
ZirFunction* value_24 = law->claim;
|
|
String value_25 = StringView(NULL, 0);
|
|
{
|
|
ZirFunction* fn = value_24;
|
|
value_25 = compiler_ir_CText((uint8_t*)fn->args_text);
|
|
}
|
|
bool value_27 = compiler_proof_ParseSignature(value_25, &(p));
|
|
value_23 = !value_27;
|
|
}
|
|
if (value_23) {
|
|
return -1;
|
|
}
|
|
int32_t args[16] = {0};
|
|
int32_t count = 0;
|
|
int32_t at = (terms->exprs[step->term_root]).first_child;
|
|
while (at >= 0) {
|
|
Context* value_28 = c;
|
|
int32_t value_29 = depth;
|
|
bool value_30 = false;
|
|
{
|
|
Context* c = value_28;
|
|
int32_t depth = value_29;
|
|
if (depth <= 64) {
|
|
int32_t* value_32 = &(c->kernel.budget);
|
|
(*value_32) = (int32_t)((uint32_t)((*value_32)) - 1u);
|
|
if (c->kernel.budget >= 0) {
|
|
value_30 = !c->kernel.exhausted;
|
|
goto value_31;
|
|
}
|
|
}
|
|
bool* value_33 = &(c->kernel.exhausted);
|
|
(*value_33) = true;
|
|
value_30 = false;
|
|
value_31: ;
|
|
}
|
|
bool value_34 = !value_30 || at >= terms->expr_count || count >= p.count;
|
|
bool value_35 = value_34;
|
|
if (!value_35) {
|
|
String value_36 = compiler_ir_CText((uint8_t*)(terms->exprs[at]).argument_name);
|
|
int64_t value_37 = (int64_t)(value_36).length;
|
|
value_35 = (value_37 > 0LL);
|
|
}
|
|
if (value_35) {
|
|
return -1;
|
|
}
|
|
int32_t* value_38 = &(ZIRAN_INDEX(args, sizeof(args) / sizeof(args[0]), count));
|
|
Context* value_39 = c;
|
|
ZirModule* value_40 = m;
|
|
ZirFunction* value_41 = terms;
|
|
int32_t value_42 = at;
|
|
Environment* value_43 = env;
|
|
int32_t value_44 = compiler_proof_ScalarType(c, owner, ZIRAN_INDEX(p.types, 16, count));
|
|
int32_t value_45 = compiler_proof_Expression(value_39, value_40, value_41, value_42, value_43, value_44, (int32_t)((uint32_t)depth + 1u));
|
|
(*value_38) = value_45;
|
|
if (ZIRAN_INDEX(args, 16, count) < 0) {
|
|
return -1;
|
|
}
|
|
count = (int32_t)((uint32_t)count + 1u);
|
|
at = (terms->exprs[at]).next_sibling;
|
|
}
|
|
if (count != p.count) {
|
|
return -1;
|
|
}
|
|
ProofFact value_46[128] = {0};
|
|
memmove(value_46, c->kernel.facts, sizeof(value_46));
|
|
ProofFact facts[128] = {0};
|
|
memmove(facts, value_46, sizeof(facts));
|
|
int32_t fact_count = c->kernel.fact_count;
|
|
Unfolds unfold = c->unfold;
|
|
int32_t* value_47 = &(c->kernel.fact_count);
|
|
(*value_47) = 0;
|
|
Slice value_48 = {args, 16};
|
|
int32_t proved = compiler_proof_Theorem(c, owner, law, SliceRange(value_48, (int64_t)0LL, (int64_t)count, sizeof(int32_t)), (int32_t)((uint32_t)depth + 1u));
|
|
ProofFact (*value_49)[128] = &(c->kernel.facts);
|
|
ProofFact value_50[128] = {0};
|
|
memmove(value_50, facts, sizeof(value_50));
|
|
memmove((*value_49), value_50, sizeof((*value_49)));
|
|
int32_t* value_51 = &(c->kernel.fact_count);
|
|
(*value_51) = fact_count;
|
|
Unfolds* value_52 = &(c->unfold);
|
|
(*value_52) = unfold;
|
|
return proved;
|
|
}
|
|
|
|
static int32_t
|
|
compiler_proof_Theorem(Context* c, ZirModule* m, ZirLaw* law, Slice args, int32_t depth)
|
|
{
|
|
Context* value_0 = c;
|
|
int32_t value_1 = depth;
|
|
bool value_2 = false;
|
|
{
|
|
Context* c = value_0;
|
|
int32_t depth = value_1;
|
|
if (depth <= 64) {
|
|
int32_t* value_4 = &(c->kernel.budget);
|
|
(*value_4) = (int32_t)((uint32_t)((*value_4)) - 1u);
|
|
if (c->kernel.budget >= 0) {
|
|
value_2 = !c->kernel.exhausted;
|
|
goto value_3;
|
|
}
|
|
}
|
|
bool* value_5 = &(c->kernel.exhausted);
|
|
(*value_5) = true;
|
|
value_2 = false;
|
|
value_3: ;
|
|
}
|
|
if (!value_2) {
|
|
return -1;
|
|
}
|
|
{
|
|
int32_t range_first_3 = 0;
|
|
int32_t range_last_3 = (int32_t)((uint32_t)(c->law_count) - 1u);
|
|
int32_t i = range_first_3;
|
|
if (i <= range_last_3) for (;;) {
|
|
if (ZIRAN_INDEX(c->laws, 64, i) == law) {
|
|
bool* value_6 = &(c->invalid);
|
|
(*value_6) = true;
|
|
Context* value_7 = c;
|
|
String value_8 = StringLiteral("circular theorem dependency");
|
|
int32_t value_9 = 0;
|
|
{
|
|
Context* c = value_7;
|
|
String reason = value_8;
|
|
bool* value_11 = &(c->unsupported);
|
|
(*value_11) = true;
|
|
String* value_12 = &(c->reason);
|
|
(*value_12) = reason;
|
|
value_9 = -1;
|
|
}
|
|
return value_9;
|
|
}
|
|
if (i == range_last_3) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
if (c->law_count == 64) {
|
|
bool* value_13 = &(c->kernel.exhausted);
|
|
(*value_13) = true;
|
|
return -1;
|
|
}
|
|
ZirProof* proof = (ZirProof*)law->proof;
|
|
if (proof == ((void *)0) || proof->step_count == 0) {
|
|
Context* value_14 = c;
|
|
String value_15 = StringLiteral("theorem has no complete proof certificate");
|
|
int32_t value_16 = 0;
|
|
{
|
|
Context* c = value_14;
|
|
String reason = value_15;
|
|
bool* value_18 = &(c->unsupported);
|
|
(*value_18) = true;
|
|
String* value_19 = &(c->reason);
|
|
(*value_19) = reason;
|
|
value_16 = -1;
|
|
}
|
|
return value_16;
|
|
}
|
|
ZirLaw** value_20 = &(ZIRAN_INDEX(c->laws, sizeof(c->laws) / sizeof(c->laws[0]), c->law_count));
|
|
(*value_20) = law;
|
|
int32_t* value_21 = &(c->law_count);
|
|
(*value_21) = (int32_t)((uint32_t)((*value_21)) + 1u);
|
|
Signature params = {0};
|
|
Environment env = {0};
|
|
int32_t goal = -1;
|
|
int32_t original = -1;
|
|
ZirFunction* value_22 = law->claim;
|
|
String value_23 = StringView(NULL, 0);
|
|
{
|
|
ZirFunction* fn = value_22;
|
|
value_23 = compiler_ir_CText((uint8_t*)fn->args_text);
|
|
}
|
|
bool value_25 = compiler_proof_ParseSignature(value_23, &(params));
|
|
bool ok = value_25 && (int64_t)(args).length == (int64_t)(params.count);
|
|
bool cases = false;
|
|
bool closed = false;
|
|
int32_t* value_26 = &(c->unfold.count);
|
|
(*value_26) = 0;
|
|
bool* value_27 = &(c->unfold.all);
|
|
(*value_27) = false;
|
|
{
|
|
int32_t range_first_28 = 0;
|
|
int32_t range_last_28 = (int32_t)((uint32_t)(params.count) - 1u);
|
|
int32_t i = range_first_28;
|
|
if (i <= range_last_28) for (;;) {
|
|
int32_t value_28 = 0;
|
|
if (ok) {
|
|
int32_t value_29 = compiler_proof_ScalarType(c, m, ZIRAN_INDEX(params.types, 16, i));
|
|
value_28 = value_29;
|
|
} else {
|
|
value_28 = -1;
|
|
}
|
|
int32_t type = value_28;
|
|
bool value_30 = ok && ((int32_t *)args.data)[SliceIndex(args, (int64_t)i)] >= 0 && type >= 0;
|
|
bool value_31 = value_30;
|
|
if (value_31) {
|
|
Context* value_32 = c;
|
|
int32_t value_33 = ((int32_t *)args.data)[SliceIndex(args, (int64_t)i)];
|
|
int32_t value_34 = 0;
|
|
{
|
|
Context* c = value_32;
|
|
int32_t term = value_33;
|
|
value_34 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_31 = (value_34 == type);
|
|
}
|
|
bool value_36 = value_31;
|
|
bool value_37 = value_36;
|
|
if (value_37) {
|
|
Context* value_38 = c;
|
|
Environment* value_39 = &(env);
|
|
String value_40 = ZIRAN_INDEX(params.names, 16, i);
|
|
int32_t value_41 = ((int32_t *)args.data)[SliceIndex(args, (int64_t)i)];
|
|
bool value_42 = false;
|
|
{
|
|
Context* c = value_38;
|
|
Environment* e = value_39;
|
|
String name = value_40;
|
|
int32_t value = value_41;
|
|
if (value < 0) {
|
|
value_42 = false;
|
|
goto value_43;
|
|
}
|
|
if (e->count == 64) {
|
|
bool* value_44 = &(c->kernel.exhausted);
|
|
(*value_44) = true;
|
|
value_42 = false;
|
|
goto value_43;
|
|
}
|
|
Binding* value_45 = &(ZIRAN_INDEX(e->bindings, sizeof(e->bindings) / sizeof(e->bindings[0]), e->count));
|
|
(*value_45) = (Binding){.name = name, .value = value};
|
|
int32_t* value_46 = &(e->count);
|
|
(*value_46) = (int32_t)((uint32_t)((*value_46)) + 1u);
|
|
value_42 = true;
|
|
value_43: ;
|
|
}
|
|
value_37 = value_42;
|
|
}
|
|
ok = value_37;
|
|
if (i == range_last_28) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
{
|
|
int32_t range_first_32 = 0;
|
|
int32_t range_last_32 = (int32_t)((uint32_t)(proof->step_count) - 1u);
|
|
int32_t i = range_first_32;
|
|
if (i <= range_last_32) for (;;) {
|
|
ZirProofStep* step = &(proof->steps[i]);
|
|
if (!ok || closed) {
|
|
ok = false;
|
|
break;
|
|
}
|
|
if (((ZirProofStepKind)(step->kind)) == ((ZirProofStepKind)(1))) {
|
|
if (goal >= 0) {
|
|
ok = false;
|
|
break;
|
|
}
|
|
if ((step->target)[0] == 0) {
|
|
bool* value_47 = &(c->unfold.all);
|
|
(*value_47) = true;
|
|
if (i == range_last_32) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
continue;
|
|
}
|
|
ZirFunction* fn = (void *)0;
|
|
ZirModule* owner = (void *)0;
|
|
int32_t found = zir_f_5116a9a569c28f15_ResolveFunction(m, &(step->target[0]), &(owner), &(fn));
|
|
if (found != 1) {
|
|
found = zir_f_5116a9a569c28f15_ResolveFunction((ZirModule*)proof->owner, &(step->target[0]), &(owner), &(fn));
|
|
}
|
|
if (found != 1 || c->unfold.count == 64) {
|
|
ok = false;
|
|
break;
|
|
}
|
|
ZirFunction** value_48 = &(ZIRAN_INDEX(c->unfold.functions, sizeof(c->unfold.functions) / sizeof(c->unfold.functions[0]), c->unfold.count));
|
|
(*value_48) = fn;
|
|
int32_t* value_49 = &(c->unfold.count);
|
|
(*value_49) = (int32_t)((uint32_t)((*value_49)) + 1u);
|
|
if (i == range_last_32) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
continue;
|
|
}
|
|
if (goal < 0) {
|
|
goal = compiler_proof_Expression(c, m, law->claim, (law->claim->stmts[0]).expr_root, &(env), 0, (int32_t)((uint32_t)depth + 1u));
|
|
original = goal;
|
|
bool value_50 = goal < 0;
|
|
bool value_51 = value_50;
|
|
if (!value_51) {
|
|
Context* value_52 = c;
|
|
int32_t value_53 = 0;
|
|
{
|
|
Context* c = value_52;
|
|
int32_t term = goal;
|
|
value_53 = (ZIRAN_INDEX(c->kernel.terms, sizeof(c->kernel.terms) / sizeof(c->kernel.terms[0]), term)).type;
|
|
}
|
|
value_51 = (value_53 != 0);
|
|
}
|
|
if (value_51) {
|
|
ok = false;
|
|
break;
|
|
}
|
|
}
|
|
if (((ZirProofStepKind)(step->kind)) == ((ZirProofStepKind)(2))) {
|
|
cases = true;
|
|
} else if (((ZirProofStepKind)(step->kind)) == ((ZirProofStepKind)(3)) || ((ZirProofStepKind)(step->kind)) == ((ZirProofStepKind)(4))) {
|
|
int32_t lemma = compiler_proof_Application(c, m, proof, step, &(env), (int32_t)((uint32_t)depth + 1u));
|
|
if (lemma < 0) {
|
|
ok = false;
|
|
break;
|
|
}
|
|
ProofTerm equation = ZIRAN_INDEX(c->kernel.terms, 4096, lemma);
|
|
closed = ((ZirProofStepKind)(step->kind)) == ((ZirProofStepKind)(4));
|
|
if (closed) {
|
|
ok = compiler_proof_kernel_Equal(&(c->kernel), goal, lemma, false);
|
|
} else if (((ProofOp)(equation.op)) != ((ProofOp)(5))) {
|
|
ok = false;
|
|
break;
|
|
} else {
|
|
goal = compiler_proof_kernel_Rewrite(&(c->kernel), goal, equation.a, equation.b, 0);
|
|
ok = goal >= 0;
|
|
}
|
|
} else {
|
|
ok = compiler_proof_kernel_Close(&(c->kernel), goal, ((ZirProofStepKind)(step->kind)) != ((ZirProofStepKind)(5)), ((ZirProofStepKind)(step->kind)) == ((ZirProofStepKind)(7)), cases);
|
|
closed = true;
|
|
}
|
|
if (i == range_last_32) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
int32_t* value_55 = &(c->law_count);
|
|
(*value_55) = (int32_t)((uint32_t)((*value_55)) - 1u);
|
|
if (!closed && !c->unsupported && !c->kernel.exhausted) {
|
|
Context* value_56 = c;
|
|
String value_57 = StringLiteral("proof certificate has no closing step");
|
|
int32_t value_58 = 0;
|
|
{
|
|
Context* c = value_56;
|
|
String reason = value_57;
|
|
bool* value_60 = &(c->unsupported);
|
|
(*value_60) = true;
|
|
String* value_61 = &(c->reason);
|
|
(*value_61) = reason;
|
|
value_58 = -1;
|
|
}
|
|
(void)value_58;
|
|
}
|
|
int32_t value_62 = 0;
|
|
if (ok && closed && !c->unsupported && !c->kernel.exhausted) {
|
|
value_62 = original;
|
|
} else {
|
|
value_62 = -1;
|
|
}
|
|
return value_62;
|
|
}
|
|
|
|
ZirLaw*
|
|
FindVisibleLaw(ZirModule* m, uint8_t* name, ZirModule** owner)
|
|
{
|
|
return compiler_proof_FindLaw(m, compiler_ir_CText(name), 0, owner);
|
|
}
|
|
|
|
int32_t
|
|
ParseProofDeclaration(ZirModule* m, uint8_t* source, ZirSourceSpan span)
|
|
{
|
|
String text = compiler_ir_CText(source);
|
|
__type_838711075b90279a clean = {0};
|
|
__type_838711075b90279a* value_0 = &clean;
|
|
int64_t value_2 = (int64_t)(text).length;
|
|
bool value_3 = false;
|
|
if (value_2 >= 0) {
|
|
value_3 = value_2 <= (clean).capacity;
|
|
if (!value_3) {
|
|
void *value_4 = ZirVecReserve((void *)(clean).data, &(clean).capacity, (clean).count, value_2 - (clean).count, sizeof(*(clean).data));
|
|
if (value_4 != NULL) { (clean).data = (uint8_t *)value_4; value_3 = true; }
|
|
}
|
|
if (value_3) {
|
|
if (value_2 > (clean).count) memset((clean).data + (clean).count, 0, (size_t)(value_2 - (clean).count) * sizeof(*(clean).data));
|
|
(clean).count = value_2;
|
|
}
|
|
}
|
|
if (!value_3) {
|
|
int32_t value_6 = 0;
|
|
free((*value_0).data);
|
|
(*value_0).data = NULL;
|
|
(*value_0).capacity = 0;
|
|
(*value_0).count = 0;
|
|
return value_6;
|
|
}
|
|
Slice value_7 = {(clean).data, (clean).count};
|
|
CommentScan value_8 = compiler_source_StripComments(text, SliceRange(value_7, 0LL, clean.count, sizeof(*(clean).data)), 0);
|
|
Slice value_9 = {(clean).data, (clean).count};
|
|
Slice value_10 = SliceRange(value_9, 0LL, value_8.count, sizeof(*(clean).data));
|
|
String body = StringView((const char *)(value_10).data, (size_t)(value_10).length);
|
|
int64_t at = compiler_text_SkipSpace(body, 6LL, false);
|
|
int64_t start = at;
|
|
while (true) {
|
|
bool value_11 = at < (int64_t)(body).length;
|
|
if (value_11) {
|
|
bool value_12 = compiler_text_IdentifierByte((uint8_t)ZIRAN_INDEX(body.data, body.length, at));
|
|
value_11 = (value_12 || (uint8_t)ZIRAN_INDEX(body.data, body.length, at) == 46);
|
|
}
|
|
if (!value_11) { break; }
|
|
at = (int64_t)((uint64_t)at + UINT64_C(1));
|
|
}
|
|
Spelled name = compiler_proof_C(StringRange(body, (int64_t)start, (int64_t)at));
|
|
int64_t open = compiler_text_SkipSpace(body, at, false);
|
|
int64_t close = (int64_t)((uint64_t)((int64_t)(body).length) - UINT64_C(1));
|
|
while (close > open && (uint8_t)ZIRAN_INDEX(body.data, body.length, close) != 125) {
|
|
close = (int64_t)((uint64_t)close - UINT64_C(1));
|
|
}
|
|
String value_13 = StringRange(body, (int64_t)((int64_t)((uint64_t)close + UINT64_C(1))), (int64_t)(int64_t)(body).length);
|
|
String value_14 = StringView(NULL, 0);
|
|
{
|
|
String text = value_13;
|
|
SourceRange range = compiler_text_TrimRange(text);
|
|
value_14 = StringRange(text, (int64_t)range.begin, (int64_t)range.end);
|
|
}
|
|
String tail = value_14;
|
|
bool value_16 = at == start || (int64_t)((uint64_t)at - (uint64_t)start) >= 128LL || open == (int64_t)(body).length;
|
|
bool value_17 = value_16 || (uint8_t)ZIRAN_INDEX(body.data, body.length, open) != 123 || close == open || ((int64_t)(tail).length > 0LL && !StringEqual(tail, StringLiteral(";")));
|
|
if (value_17 || (int64_t)(((uint64_t)close - (uint64_t)open) - UINT64_C(1)) >= 4096LL) {
|
|
int32_t value_18 = 0;
|
|
free((*value_0).data);
|
|
(*value_0).data = NULL;
|
|
(*value_0).capacity = 0;
|
|
(*value_0).count = 0;
|
|
return value_18;
|
|
}
|
|
Long steps = compiler_proof_CLong(StringRange(body, (int64_t)((int64_t)((uint64_t)open + UINT64_C(1))), (int64_t)close));
|
|
int32_t value_19 = zir_f_5116a9a569c28f15_ModuleAddProof(m, &(name.bytes[0]), &(steps.bytes[0]), span);
|
|
free((*value_0).data);
|
|
(*value_0).data = NULL;
|
|
(*value_0).capacity = 0;
|
|
(*value_0).count = 0;
|
|
return value_19;
|
|
}
|
|
|
|
int32_t
|
|
PrepareLawProofs(ZirProgram** programs, int32_t count)
|
|
{
|
|
for (int64_t pass = 0LL; pass <= 1LL; pass++) {
|
|
{
|
|
int32_t range_first_1 = 0;
|
|
int32_t range_last_1 = (int32_t)((uint32_t)count - 1u);
|
|
int32_t p = range_first_1;
|
|
if (p <= range_last_1) for (;;) {
|
|
{
|
|
int32_t range_first_2 = 0;
|
|
int32_t range_last_2 = (int32_t)((uint32_t)((programs[p])->module_count) - 1u);
|
|
int32_t i = range_first_2;
|
|
if (i <= range_last_2) for (;;) {
|
|
ZirModule* module = &(((programs[p])->modules)[i]);
|
|
{
|
|
int32_t range_first_4 = 0;
|
|
int32_t range_last_4 = (int32_t)((uint32_t)(module->law_count) - 1u);
|
|
int32_t l = range_first_4;
|
|
if (l <= range_last_4) for (;;) {
|
|
if (pass == 1LL) {
|
|
break;
|
|
}
|
|
ZirLaw* law = &(module->laws[l]);
|
|
const ZirProof ** value_0 = &(law->proof);
|
|
(*value_0) = (const ZirProof *)(((void *)0));
|
|
Slice value_1 = {law->kind, 16};
|
|
if (StringEqual(compiler_proof_Name(value_1), StringLiteral("theorem"))) {
|
|
bool value_2 = compiler_proof_PrepareClaim(module, law);
|
|
if (!value_2) {
|
|
return 0;
|
|
}
|
|
} else if (law->claim != ((void *)0)) {
|
|
ZirSourceSpan value_3 = law->span;
|
|
String value_4 = StringLiteral("proof.claim");
|
|
String value_5 = StringLiteral("non-theorem law has a proposition graph");
|
|
String value_6 = StringLiteral("");
|
|
String value_7 = StringLiteral("");
|
|
bool value_8 = false;
|
|
{
|
|
ZirSourceSpan span = value_3;
|
|
String code = value_4;
|
|
String message = value_5;
|
|
String name = value_6;
|
|
String tail = value_7;
|
|
compiler_services_Diagnose__overload_2(span, code, message, name, tail);
|
|
value_8 = false;
|
|
}
|
|
(void)value_8;
|
|
return 0;
|
|
}
|
|
if (l == range_last_4) {
|
|
break;
|
|
}
|
|
l = (int32_t)((uint32_t)l + 1u);
|
|
}
|
|
}
|
|
{
|
|
int32_t range_first_20 = 0;
|
|
int32_t range_last_20 = (int32_t)((uint32_t)(module->proof_count) - 1u);
|
|
int32_t n = range_first_20;
|
|
if (n <= range_last_20) for (;;) {
|
|
bool value_10 = pass == 1LL;
|
|
bool value_11 = value_10;
|
|
if (value_11) {
|
|
bool value_12 = compiler_proof_PrepareProof(module, &(module->proofs[n]));
|
|
value_11 = !value_12;
|
|
}
|
|
if (value_11) {
|
|
return 0;
|
|
}
|
|
if (n == range_last_20) {
|
|
break;
|
|
}
|
|
n = (int32_t)((uint32_t)n + 1u);
|
|
}
|
|
}
|
|
if (i == range_last_2) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
if (p == range_last_1) {
|
|
break;
|
|
}
|
|
p = (int32_t)((uint32_t)p + 1u);
|
|
}
|
|
}
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
int32_t
|
|
EvaluateTheorem(ZirModule* module, ZirLaw* law, uint8_t* detail, size_t size)
|
|
{
|
|
Slice out = compiler_ir_CBuffer(detail, size);
|
|
if (law->claim == ((void *)0) || ((ZirProof*)law->proof) == ((void *)0)) {
|
|
compiler_ir_CopyText(out, StringLiteral("theorem has no proof certificate"));
|
|
return 2;
|
|
}
|
|
uint8_t* value_0 = zir_f_5116a9a569c28f15_calloc(1, sizeof(Context));
|
|
Context* c = (Context*)(value_0);
|
|
if (c == ((void *)0)) {
|
|
compiler_ir_CopyText(out, StringLiteral("out of memory checking theorem"));
|
|
return 2;
|
|
}
|
|
compiler_proof_kernel_Init(&(c->kernel));
|
|
Signature p = {0};
|
|
int32_t args[16] = {0};
|
|
ZirFunction* value_1 = law->claim;
|
|
String value_2 = StringView(NULL, 0);
|
|
{
|
|
ZirFunction* fn = value_1;
|
|
value_2 = compiler_ir_CText((uint8_t*)fn->args_text);
|
|
}
|
|
bool ok = compiler_proof_ParseSignature(value_2, &(p));
|
|
{
|
|
int32_t range_first_14 = 0;
|
|
int32_t range_last_14 = (int32_t)((uint32_t)(p.count) - 1u);
|
|
int32_t i = range_first_14;
|
|
if (i <= range_last_14) for (;;) {
|
|
int32_t* value_4 = &(ZIRAN_INDEX(args, sizeof(args) / sizeof(args[0]), i));
|
|
int32_t value_5 = 0;
|
|
if (ok) {
|
|
int32_t value_6 = compiler_proof_ScalarType(c, module, ZIRAN_INDEX(p.types, 16, i));
|
|
int32_t value_7 = compiler_proof_kernel_Node(&(c->kernel), (ProofOp)(1), value_6, -1, -1, -1, (uint64_t)(i));
|
|
value_5 = value_7;
|
|
} else {
|
|
value_5 = -1;
|
|
}
|
|
(*value_4) = value_5;
|
|
ok = ZIRAN_INDEX(args, 16, i) >= 0;
|
|
if (i == range_last_14) {
|
|
break;
|
|
}
|
|
i = (int32_t)((uint32_t)i + 1u);
|
|
}
|
|
}
|
|
int32_t status = 3;
|
|
String reason = StringLiteral("invalid proof: a step did not establish its goal");
|
|
bool value_8 = ok;
|
|
bool value_9 = value_8;
|
|
if (value_9) {
|
|
Slice value_10 = {args, 16};
|
|
bool value_11 = compiler_proof_Theorem(c, module, law, SliceRange(value_10, (int64_t)0LL, (int64_t)p.count, sizeof(int32_t)), 0) >= 0;
|
|
value_9 = value_11;
|
|
}
|
|
if (value_9) {
|
|
status = 0;
|
|
reason = StringLiteral("kernel checked proof over the full typed domain");
|
|
} else if (c->invalid) {
|
|
compiler_ir_CopyText(out, StringLiteral("invalid proof: "));
|
|
Slice value_12 = out;
|
|
out = SliceRange(value_12, (int64_t)15LL, (int64_t)(int64_t)(out).length, sizeof(uint8_t));
|
|
reason = c->reason;
|
|
} else if (c->kernel.exhausted) {
|
|
status = 2;
|
|
reason = StringLiteral("scalar proof exceeds its deterministic budget");
|
|
} else if (c->unsupported) {
|
|
status = 2;
|
|
reason = c->reason;
|
|
}
|
|
compiler_ir_CopyText(out, reason);
|
|
int32_t cleanup_return_0 = status;
|
|
zir_f_5116a9a569c28f15_free((uint8_t*)(c));
|
|
return cleanup_return_0;
|
|
}
|