Files
waozi 94324c179a Scan C sources for backend cache hazards in one pass
TextHazards replaces UnsafeText, FileDigest's NUL loop and its __has_include search with one scan that keeps the original probe order, and Normalized jumps between output and alias matches instead of testing every byte. Cache entry names and produced binaries are unchanged.
2026-12-01 14:23:53 -03:00

5796 lines
222 KiB
C

/* Generated by zi2c from compiler_backend_cache.zi. */
#define ZIRAN_COMPILER_BACKEND_CACHE_H_SOURCE 1
#include <stdbool.h>
#include "zir_string.h"
#include "zir_vec.h"
#include "compiler_backend_cache.h"
#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_ZiShrU32
#define ZIRAN_HELPER_ZiShrU32
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__)
#define ZiShrU32(a, s, w) __extension__ ({ uint32_t __zi_a = (a); uint64_t __zi_s = (s); if(__zi_s >= (uint64_t)(w)) abort(); __zi_a >> __zi_s; })
#else
static inline uint32_t ZiShrU32(uint32_t a, uint64_t s, int w) {
if(s >= (uint64_t)w) abort();
return a >> s;
}
#endif
#endif
#ifndef ZIRAN_HELPER_ZiShrU64
#define ZIRAN_HELPER_ZiShrU64
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__OPTIMIZE__)
#define ZiShrU64(a, s, w) __extension__ ({ uint64_t __zi_a = (a); uint64_t __zi_s = (s); if(__zi_s >= (uint64_t)(w)) abort(); __zi_a >> __zi_s; })
#else
static inline uint64_t ZiShrU64(uint64_t a, uint64_t s, int w) {
if(s >= (uint64_t)w) abort();
return a >> s;
}
#endif
#endif
#include "compiler_foreign.h"
#ifdef __APPLE__
void zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_15(void* hash, uint8_t* bytes, size_t count) __asm__("_Sha256Add");
#else
void zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_15(void* hash, uint8_t* bytes, size_t count) __asm__("Sha256Add");
#endif
#ifdef __APPLE__
void zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_16(uint8_t* name) __asm__("_ProfileCount");
#else
void zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_16(uint8_t* name) __asm__("ProfileCount");
#endif
#ifdef __APPLE__
void* zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_17(size_t count, size_t size) __asm__("_calloc");
#else
void* zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_17(size_t count, size_t size) __asm__("calloc");
#endif
#ifdef __APPLE__
void zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_18(void* memory) __asm__("_free");
#else
void zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_18(void* memory) __asm__("free");
#endif
#ifdef __APPLE__
uint8_t* zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_19(uint8_t* output, size_t size) __asm__("_getcwd");
#else
uint8_t* zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_19(uint8_t* output, size_t size) __asm__("getcwd");
#endif
#ifdef __APPLE__
int32_t zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_20(void) __asm__("_getpid");
#else
int32_t zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_20(void) __asm__("getpid");
#endif
#ifdef __APPLE__
int32_t zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_21(int32_t directory, uint8_t* path, void* times, int32_t flags) __asm__("_utimensat");
#else
int32_t zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_21(int32_t directory, uint8_t* path, void* times, int32_t flags) __asm__("utimensat");
#endif
#ifdef __APPLE__
int32_t zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_22(uint8_t* path, int32_t flags, uint32_t mode) __asm__("_open");
#else
int32_t zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_22(uint8_t* path, int32_t flags, uint32_t mode) __asm__("open");
#endif
__type_9f828aa1372cb21a ProfileNames = {0};
HashState
compiler_backend_cache_HashNew(void)
{
HashState result = {0};
zir_foreign_compiler_backend_cache__ShaBegin((void*)(&(result)));
return result;
}
void
compiler_backend_cache_HashBytes(HashState* hash, String value)
{
if ((int64_t)(value).length == 0LL) {
return;
}
View* descriptor = (View*)(&(value));
zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_15((void*)(hash), descriptor->data, (size_t)((int64_t)(value).length));
}
void
compiler_backend_cache_HashInteger(HashState* hash, uint64_t value)
{
uint8_t bytes[8];
for (int64_t index = 0LL; index <= 7LL; index++) {
uint8_t* value_0 = &(bytes[index]);
uint8_t value_1 = (uint8_t)((ZiShrU64(value, (uint64_t)((uint64_t)(((int64_t)(UINT64_C(8) * (uint64_t)index)))), 64)));
(*value_0) = value_1;
}
Slice value_2 = {bytes, 8};
Slice value_3 = value_2;
compiler_backend_cache_HashBytes(hash, StringView((const char *)(value_3).data, (size_t)(value_3).length));
}
void
compiler_backend_cache_HashText(HashState* hash, String value)
{
compiler_backend_cache_HashInteger(hash, (uint64_t)((int64_t)(value).length));
compiler_backend_cache_HashBytes(hash, value);
}
void
compiler_backend_cache_HashFinish(HashState* hash, Digest* output)
{
zir_foreign_compiler_backend_cache__ShaEnd((void*)(hash), output->bytes);
}
void
compiler_backend_cache_ProfileCount(String name)
{
uint8_t* pointer = compiler_backend_cache_ProfileName(name);
if (pointer != ((void *)0)) {
zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_16(pointer);
}
}
uint8_t*
compiler_backend_cache_ProfileName(String name)
{
for (int64_t it_index = 0LL; it_index < ProfileNames.count; it_index++) {
String value = (ProfileNames).data[it_index];
if (StringEqual(value, name)) {
View* descriptor = (View*)(&(value));
return descriptor->data;
}
}
void* value = zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_17(1, (size_t)(((int64_t)((uint64_t)((int64_t)(name).length) + UINT64_C(1)))));
if (value == ((void *)0)) {
return (void *)0;
}
uint8_t* pointer = (uint8_t*)(value);
bool value_0 = CopyCString(name, compiler_backend_cache_BytesFromPointer(pointer, (uint64_t)(((int64_t)((uint64_t)((int64_t)(name).length) + UINT64_C(1))))));
if (!value_0) {
zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_18(value);
return (void *)0;
}
String stored = StringLiteral("");
View* descriptor = (View*)(&(stored));
uint8_t** value_1 = &(descriptor->data);
(*value_1) = pointer;
size_t* value_2 = &(descriptor->count);
(*value_2) = (size_t)((int64_t)(name).length);
String value_3 = stored;
bool value_4 = false;
void *value_5 = ZirVecGrow((void *)(ProfileNames).data, &(ProfileNames).capacity, (ProfileNames).count, sizeof(*(ProfileNames).data));
if (value_5 != NULL) {
(ProfileNames).data = value_5;
(ProfileNames).data[(ProfileNames).count++] = value_3;
value_4 = true;
}
if (!value_4) {
zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_18(value);
return (void *)0;
}
return pointer;
}
Slice
compiler_backend_cache_BytesFromPointer(uint8_t* data, uint64_t count)
{
Slice result = {0};
if (data == ((void *)0)) {
return result;
}
ByteView* descriptor = (ByteView*)(&(result));
uint8_t** value_0 = &(descriptor->data);
(*value_0) = data;
int64_t* value_1 = &(descriptor->count);
(*value_1) = (int64_t)(count);
return result;
}
String
compiler_backend_cache_Owned(String value)
{
return vec_TextDetach(vec_TextCopy(value));
}
void
compiler_backend_cache_Release(String value)
{
if ((int64_t)(value).length == 0LL) {
return;
}
View* descriptor = (View*)(&(value));
zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_18((void*)(descriptor->data));
}
bool
compiler_backend_cache_SameText(String left, String right)
{
return StringEqual(left, right);
}
bool
compiler_backend_cache_HasPrefix(String value, String prefix)
{
return text_tools_TextHasPrefix(value, prefix);
}
bool
compiler_backend_cache_HasSuffix(String value, String suffix)
{
return text_tools_TextHasSuffix(value, suffix);
}
bool
compiler_backend_cache_Contains(String value, String piece)
{
return text_tools_TextContains(value, piece);
}
String
compiler_backend_cache_TextName(String value)
{
int64_t at = (int64_t)(value).length;
while (at > 0LL && (uint8_t)value.data[((int64_t)((uint64_t)at - UINT64_C(1)))] != 47) {
at = (int64_t)((uint64_t)at - UINT64_C(1));
}
return StringRangeAt(value, (int64_t)at, (int64_t)(int64_t)(value).length);
}
String
compiler_backend_cache_JoinTemporary(String left, String right)
{
__type_131eebaaeb761e42 builder = {0};
__type_131eebaaeb761e42* value_0 = &builder;
bool value_1 = false;
if ((left).length == 0) {
value_1 = true;
} else {
void *value_2 = ZirVecReserve((void *)(builder).data, &(builder).capacity, (builder).count, (int64_t)(left).length, sizeof(*(builder).data));
if (value_2 != NULL) {
(builder).data = (uint8_t *)value_2;
memcpy((builder).data + (builder).count, (left).data, (size_t)(left).length);
(builder).count += (int64_t)(left).length;
value_1 = true;
}
}
bool value_3 = !value_1;
if (!value_3) {
bool value_4 = false;
if ((right).length == 0) {
value_4 = true;
} else {
void *value_5 = ZirVecReserve((void *)(builder).data, &(builder).capacity, (builder).count, (int64_t)(right).length, sizeof(*(builder).data));
if (value_5 != NULL) {
(builder).data = (uint8_t *)value_5;
memcpy((builder).data + (builder).count, (right).data, (size_t)(right).length);
(builder).count += (int64_t)(right).length;
value_4 = true;
}
}
value_3 = !value_4;
}
if (value_3) {
free((builder).data);
(builder).data = NULL;
builder.capacity = 0;
builder.count = 0;
String value_6 = StringLiteral("");
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_6;
}
Slice value_7 = {(builder).data, (builder).count};
Slice value_8 = SliceRangeAt(value_7, 0LL, builder.count, sizeof(*(builder).data));
String value_9 = vec_TextDetach(vec_TextCopy(StringView((const char *)(value_8).data, (size_t)(value_8).length)));
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_9;
}
String
compiler_backend_cache_JoinPath(String left, String right)
{
__type_131eebaaeb761e42 builder = {0};
__type_131eebaaeb761e42* value_0 = &builder;
bool value_1 = false;
if ((left).length == 0) {
value_1 = true;
} else {
void *value_2 = ZirVecReserve((void *)(builder).data, &(builder).capacity, (builder).count, (int64_t)(left).length, sizeof(*(builder).data));
if (value_2 != NULL) {
(builder).data = (uint8_t *)value_2;
memcpy((builder).data + (builder).count, (left).data, (size_t)(left).length);
(builder).count += (int64_t)(left).length;
value_1 = true;
}
}
if (!value_1) {
free((builder).data);
(builder).data = NULL;
builder.capacity = 0;
builder.count = 0;
String value_3 = StringLiteral("");
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_3;
}
if ((int64_t)(left).length > 0LL && (uint8_t)left.data[((int64_t)((uint64_t)((int64_t)(left).length) - UINT64_C(1)))] != 47) {
uint8_t value_4 = 47;
bool value_5 = false;
void *value_6 = ZirVecGrow((void *)(builder).data, &(builder).capacity, (builder).count, sizeof(*(builder).data));
if (value_6 != NULL) {
(builder).data = value_6;
(builder).data[(builder).count++] = value_4;
value_5 = true;
}
if (!value_5) {
free((builder).data);
(builder).data = NULL;
builder.capacity = 0;
builder.count = 0;
String value_7 = StringLiteral("");
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_7;
}
}
bool value_8 = false;
if ((right).length == 0) {
value_8 = true;
} else {
void *value_9 = ZirVecReserve((void *)(builder).data, &(builder).capacity, (builder).count, (int64_t)(right).length, sizeof(*(builder).data));
if (value_9 != NULL) {
(builder).data = (uint8_t *)value_9;
memcpy((builder).data + (builder).count, (right).data, (size_t)(right).length);
(builder).count += (int64_t)(right).length;
value_8 = true;
}
}
if (!value_8) {
free((builder).data);
(builder).data = NULL;
builder.capacity = 0;
builder.count = 0;
String value_10 = StringLiteral("");
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_10;
}
Slice value_11 = {(builder).data, (builder).count};
Slice value_12 = SliceRangeAt(value_11, 0LL, builder.count, sizeof(*(builder).data));
String value_13 = vec_TextDetach(vec_TextCopy(StringView((const char *)(value_12).data, (size_t)(value_12).length)));
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_13;
}
bool
compiler_backend_cache_AppendOwned(__type_9f828aa1372cb21a* values, String value)
{
String owned = compiler_backend_cache_Owned(value);
if ((int64_t)(owned).length == 0LL && (int64_t)(value).length != 0LL) {
return false;
}
String value_0 = owned;
bool value_1 = false;
void *value_2 = ZirVecGrow((void *)((*(values))).data, &((*(values))).capacity, ((*(values))).count, sizeof(*((*(values))).data));
if (value_2 != NULL) {
((*(values))).data = value_2;
((*(values))).data[((*(values))).count++] = value_0;
value_1 = true;
}
if (!value_1) {
compiler_backend_cache_Release(owned);
return false;
}
return true;
}
void
compiler_backend_cache_ClearNames(__type_9f828aa1372cb21a* values)
{
__type_9f828aa1372cb21a owned = {0};
__type_9f828aa1372cb21a* value_0 = &owned;
__type_9f828aa1372cb21a value_1 = owned;
owned = (*(values));
(*(values)) = value_1;
for (int64_t it_index = 0LL; it_index < owned.count; it_index++) {
String value = (owned).data[it_index];
compiler_backend_cache_Release(value);
}
__type_9f828aa1372cb21a value_2 = owned;
owned = (*(values));
(*(values)) = value_2;
free(((*(values))).data);
((*(values))).data = NULL;
(*(values)).capacity = 0;
(*(values)).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
}
String
compiler_backend_cache_Executable(String command)
{
String value_0 = StringLiteral("/");
bool value_1 = false;
{
String value_3 = command;
String value_4 = value_0;
value_1 = text_tools_TextContains(value_3, value_4);
}
if (value_1) {
return compiler_backend_cache_Resolved(command);
}
String search = environment_linux_EnvironmentText(StringLiteral("PATH"));
String value_5 = StringView(NULL, 0);
if ((int64_t)(search).length == 0LL) {
value_5 = StringLiteral("/bin:/usr/bin");
} else {
value_5 = search;
}
String paths = value_5;
__type_9f828aa1372cb21a pieces = text_tools_TextSplit(paths, StringLiteral(":"));
__type_9f828aa1372cb21a* value_6 = &pieces;
String result = StringLiteral("");
for (int64_t it_index = 0LL; it_index < pieces.count; it_index++) {
String piece = (pieces).data[it_index];
String value_7 = StringView(NULL, 0);
if ((int64_t)(piece).length == 0LL) {
value_7 = StringLiteral(".");
} else {
value_7 = piece;
}
String directory = value_7;
String candidate = compiler_backend_cache_JoinPath(directory, command);
bool value_8 = (int64_t)(candidate).length > 0LL;
if (value_8) {
bool value_9 = false;
{
String value_11 = candidate;
PathInfo value_12 = file_tree_linux_PathStatus(value_11, true);
value_9 = ((PathKind)(value_12.kind)) == ((PathKind)(1)) && ((int32_t)((uint32_t)(value_12.mode) & 73u)) != 0;
}
value_8 = value_9;
}
if (value_8) {
result = compiler_backend_cache_Resolved(candidate);
compiler_backend_cache_Release(candidate);
break;
}
compiler_backend_cache_Release(candidate);
}
String value_13 = result;
free((*value_6).data);
(*value_6).data = NULL;
(*value_6).capacity = 0;
(*value_6).count = 0;
return value_13;
}
bool
compiler_backend_cache_Runnable(String path)
{
PathInfo info = file_tree_linux_PathStatus(path, true);
return ((PathKind)(info.kind)) == ((PathKind)(1)) && ((int32_t)((uint32_t)(info.mode) & 73u)) != 0;
}
String
compiler_backend_cache_Resolved(String path)
{
Text resolved = file_tree_linux_ResolvePath(path);
String result = vec_TextDetach(vec_TextCopy(StringView((resolved.bytes).count > 0 ? (const char *)(resolved.bytes).data : "", (size_t)(resolved.bytes).count)));
if ((int64_t)(result).length == 0LL) {
String value_0 = StringLiteral("");
free((resolved).bytes.data);
(resolved).bytes.data = NULL;
(resolved).bytes.capacity = 0;
(resolved).bytes.count = 0;
return value_0;
}
String value_1 = result;
free((resolved).bytes.data);
(resolved).bytes.data = NULL;
(resolved).bytes.capacity = 0;
(resolved).bytes.count = 0;
return value_1;
}
bool
compiler_backend_cache_NativeImage(String path)
{
FileHandle file = OpenRead(path);
if (!file.valid) {
return false;
}
uint8_t bytes[4] = {0};
Slice value_0 = {bytes, 4};
int64_t count = ReadAt(file, value_0, 0LL);
bool value_1 = CloseFile(file);
if (!value_1 || count != 4LL) {
return false;
}
bool value_2 = ((bytes)[0] == 127 && (bytes)[1] == 69 && (bytes)[2] == 76 && (bytes)[3] == 70) || ((bytes)[0] == 207 && (bytes)[1] == 250 && (bytes)[2] == 237 && (bytes)[3] == 254);
return value_2 || ((bytes)[0] == 254 && (bytes)[1] == 237 && (bytes)[2] == 250 && (bytes)[3] == 207) || ((bytes)[0] == 202 && (bytes)[1] == 254 && (bytes)[2] == 186 && (bytes)[3] == 190);
}
bool
compiler_backend_cache_PairedArgument(String value)
{
String values[15] = {StringLiteral("-I"), StringLiteral("-isystem"), StringLiteral("-iquote"), StringLiteral("-idirafter"), StringLiteral("-include"), StringLiteral("-imacros"), StringLiteral("-isysroot"), StringLiteral("--sysroot"), StringLiteral("-target"), StringLiteral("--target"), StringLiteral("-x"), StringLiteral("-D"), StringLiteral("-U"), StringLiteral("-B"), StringLiteral("-Xlinker")};
for (int64_t it_index = 0LL; it_index < 15; it_index++) {
String candidate = (values)[it_index];
if (StringEqual(value, candidate)) {
return true;
}
}
return false;
}
bool
compiler_backend_cache_RequestedPipe(Slice arguments)
{
int64_t index = 1LL;
while (index < (int64_t)(arguments).length) {
if (compiler_backend_cache_PairedArgument(((String *)(arguments).data)[index])) {
index = (int64_t)((uint64_t)index + UINT64_C(2));
continue;
}
if (StringEqual(((String *)(arguments).data)[index], StringLiteral("-pipe"))) {
return true;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
return false;
}
bool
compiler_backend_cache_UnsupportedEffects(void)
{
String names[6] = {StringLiteral("DEPENDENCIES_OUTPUT"), StringLiteral("SUNPRO_DEPENDENCIES"), StringLiteral("GCC_DIAGNOSTICS_LOG"), StringLiteral("GCC_COMPARE_DEBUG"), StringLiteral("GCC_EXTRA_DIAGNOSTIC_OUTPUT"), StringLiteral("EXPERIMENTAL_SARIF_SOCKET")};
for (int64_t it_index = 0LL; it_index < 6; it_index++) {
String name = (names)[it_index];
String value_0 = environment_linux_EnvironmentText(name);
int64_t value_1 = (int64_t)(value_0).length;
if (value_1 > 0LL) {
return true;
}
}
return false;
}
bool
compiler_backend_cache_SupportedArguments(Slice arguments)
{
if (compiler_backend_cache_UnsupportedEffects()) {
return false;
}
int64_t index = 1LL;
while (index < (int64_t)(arguments).length) {
String value = ((String *)(arguments).data)[index];
String value_0 = value;
String value_1 = StringLiteral("__DATE__");
bool value_2 = false;
{
String value_4 = value_0;
String value_5 = value_1;
value_2 = text_tools_TextContains(value_4, value_5);
}
bool value_6 = value_2;
if (!value_6) {
String value_7 = value;
String value_8 = StringLiteral("__TIME__");
bool value_9 = false;
{
String value_11 = value_7;
String value_12 = value_8;
value_9 = text_tools_TextContains(value_11, value_12);
}
value_6 = value_9;
}
bool value_13 = value_6;
if (!value_13) {
String value_14 = value;
String value_15 = StringLiteral("__TIMESTAMP__");
bool value_16 = false;
{
String value_18 = value_14;
String value_19 = value_15;
value_16 = text_tools_TextContains(value_18, value_19);
}
value_13 = value_16;
}
bool value_20 = value_13;
if (!value_20) {
String value_21 = value;
String value_22 = StringLiteral("__has_include");
bool value_23 = false;
{
String value_25 = value_21;
String value_26 = value_22;
value_23 = text_tools_TextContains(value_25, value_26);
}
value_20 = value_23;
}
bool value_27 = value_20 || StringEqual(value, StringLiteral("-march=native")) || StringEqual(value, StringLiteral("-mcpu=native"));
if (value_27 || StringEqual(value, StringLiteral("-mtune=native"))) {
return false;
}
if (compiler_backend_cache_PairedArgument(value)) {
index = (int64_t)((uint64_t)index + UINT64_C(1));
if (index >= (int64_t)(arguments).length || (StringEqual(value, StringLiteral("-x")) && !StringEqual(((String *)(arguments).data)[index], StringLiteral("c")))) {
return false;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
continue;
}
bool value_28 = compiler_backend_cache_SupportedOption(value);
if (!value_28) {
return false;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
return true;
}
bool
compiler_backend_cache_SupportedOption(String value)
{
String value_0 = value;
String value_1 = StringLiteral("-D");
bool value_2 = false;
{
String value_4 = value_0;
String value_5 = value_1;
value_2 = text_tools_TextHasPrefix(value_4, value_5);
}
bool value_6 = value_2;
if (!value_6) {
String value_7 = value;
String value_8 = StringLiteral("-U");
bool value_9 = false;
{
String value_11 = value_7;
String value_12 = value_8;
value_9 = text_tools_TextHasPrefix(value_11, value_12);
}
value_6 = value_9;
}
bool value_13 = value_6;
if (!value_13) {
String value_14 = value;
String value_15 = StringLiteral("-I");
bool value_16 = false;
{
String value_18 = value_14;
String value_19 = value_15;
value_16 = text_tools_TextHasPrefix(value_18, value_19);
}
value_13 = value_16;
}
bool value_20 = value_13;
if (!value_20) {
String value_21 = value;
String value_22 = StringLiteral("-std=");
bool value_23 = false;
{
String value_25 = value_21;
String value_26 = value_22;
value_23 = text_tools_TextHasPrefix(value_25, value_26);
}
value_20 = value_23;
}
bool value_27 = value_20;
if (!value_27) {
String value_28 = value;
String value_29 = StringLiteral("--sysroot=");
bool value_30 = false;
{
String value_32 = value_28;
String value_33 = value_29;
value_30 = text_tools_TextHasPrefix(value_32, value_33);
}
value_27 = value_30;
}
bool value_34 = value_27;
if (!value_34) {
String value_35 = value;
String value_36 = StringLiteral("--target=");
bool value_37 = false;
{
String value_39 = value_35;
String value_40 = value_36;
value_37 = text_tools_TextHasPrefix(value_39, value_40);
}
value_34 = value_37;
}
if (value_34) {
return true;
}
String value_41 = value;
String value_42 = StringLiteral("-Wl,");
bool value_43 = false;
{
String value_45 = value_41;
String value_46 = value_42;
value_43 = text_tools_TextHasPrefix(value_45, value_46);
}
bool value_47 = value_43;
if (!value_47) {
String value_48 = value;
String value_49 = StringLiteral("-fuse-ld=");
bool value_50 = false;
{
String value_52 = value_48;
String value_53 = value_49;
value_50 = text_tools_TextHasPrefix(value_52, value_53);
}
value_47 = (value_50 && (int64_t)(value).length > 9LL);
}
bool value_54 = value_47;
if (!value_54) {
String value_55 = value;
String value_56 = StringLiteral("-B");
bool value_57 = false;
{
String value_59 = value_55;
String value_60 = value_56;
value_57 = text_tools_TextHasPrefix(value_59, value_60);
}
value_54 = (value_57 && (int64_t)(value).length > 2LL);
}
if (value_54) {
return true;
}
String value_61 = value;
String value_62 = StringLiteral("-W");
bool value_63 = false;
{
String value_65 = value_61;
String value_66 = value_62;
value_63 = text_tools_TextHasPrefix(value_65, value_66);
}
bool value_67 = value_63;
if (value_67) {
String value_68 = value;
String value_69 = StringLiteral("-Wa,");
bool value_70 = false;
{
String value_72 = value_68;
String value_73 = value_69;
value_70 = text_tools_TextHasPrefix(value_72, value_73);
}
value_67 = !value_70;
}
bool value_74 = value_67;
if (value_74) {
String value_75 = value;
String value_76 = StringLiteral("-Wp,");
bool value_77 = false;
{
String value_79 = value_75;
String value_80 = value_76;
value_77 = text_tools_TextHasPrefix(value_79, value_80);
}
value_74 = !value_77;
}
bool value_81 = value_74;
if (value_81) {
String value_82 = value;
String value_83 = StringLiteral("-Wl,");
bool value_84 = false;
{
String value_86 = value_82;
String value_87 = value_83;
value_84 = text_tools_TextHasPrefix(value_86, value_87);
}
value_81 = !value_84;
}
if (value_81) {
return true;
}
String value_88 = value;
String value_89 = StringLiteral("-g");
bool value_90 = false;
{
String value_92 = value_88;
String value_93 = value_89;
value_90 = text_tools_TextHasPrefix(value_92, value_93);
}
bool value_94 = value_90;
if (value_94) {
String value_95 = value;
String value_96 = StringLiteral("-gsplit");
bool value_97 = false;
{
String value_99 = value_95;
String value_100 = value_96;
value_97 = text_tools_TextHasPrefix(value_99, value_100);
}
value_94 = !value_97;
}
if (value_94) {
return true;
}
String optimizations[8] = {StringLiteral("-O0"), StringLiteral("-O1"), StringLiteral("-O2"), StringLiteral("-O3"), StringLiteral("-Os"), StringLiteral("-Oz"), StringLiteral("-Og"), StringLiteral("-Ofast")};
for (int64_t it_index = 0LL; it_index < 8; it_index++) {
String known = (optimizations)[it_index];
if (StringEqual(value, known)) {
return true;
}
}
String value_101 = value;
String value_102 = StringLiteral("-m");
bool value_103 = false;
{
String value_105 = value_101;
String value_106 = value_102;
value_103 = text_tools_TextHasPrefix(value_105, value_106);
}
if (value_103 && !StringEqual(value, StringLiteral("-mllvm"))) {
return true;
}
String plain[29] = {StringLiteral("-pthread"), StringLiteral("-pipe"), StringLiteral("-pedantic"), StringLiteral("-pedantic-errors"), StringLiteral("-ansi"), StringLiteral("-nostdinc"), StringLiteral("-nostdlib"), StringLiteral("-static"), StringLiteral("-shared"), StringLiteral("-s"), StringLiteral("-fPIC"), StringLiteral("-fpic"), StringLiteral("-fPIE"), StringLiteral("-fpie"), StringLiteral("-fno-plt"), StringLiteral("-fomit-frame-pointer"), StringLiteral("-fno-omit-frame-pointer"), StringLiteral("-ffast-math"), StringLiteral("-fno-fast-math"), StringLiteral("-fstrict-aliasing"), StringLiteral("-fno-strict-aliasing"), StringLiteral("-fwrapv"), StringLiteral("-fno-wrapv"), StringLiteral("-fcommon"), StringLiteral("-fno-common"), StringLiteral("-fsigned-char"), StringLiteral("-funsigned-char"), StringLiteral("-fexceptions"), StringLiteral("-fno-exceptions")};
for (int64_t it_index = 0LL; it_index < 29; it_index++) {
String known = (plain)[it_index];
if (StringEqual(value, known)) {
return true;
}
}
String value_107 = value;
String value_108 = StringLiteral("-flto");
bool value_109 = false;
{
String value_111 = value_107;
String value_112 = value_108;
value_109 = text_tools_TextHasPrefix(value_111, value_112);
}
bool value_113 = value_109;
if (!value_113) {
String value_114 = value;
String value_115 = StringLiteral("-fvisibility=");
bool value_116 = false;
{
String value_118 = value_114;
String value_119 = value_115;
value_116 = text_tools_TextHasPrefix(value_118, value_119);
}
value_113 = value_116;
}
return value_113;
}
int64_t
compiler_backend_cache_FileFind(BuildCache* cache, String path, bool directory)
{
if (directory) {
return compiler_backend_cache_IndexFind(&(cache->candidate_index), &(cache->candidates), path);
}
return compiler_backend_cache_IndexFind(&(cache->file_index), &(cache->files), path);
}
uint64_t
compiler_backend_cache_PathHash(String path)
{
uint64_t hash = 14695981039346656037ULL;
for (int64_t it_index = 0LL; it_index < (int64_t)(path).length; it_index++) {
uint8_t byte = (uint8_t)path.data[it_index];
hash = (uint64_t)(((uint64_t)hash ^ (uint64_t)(byte)) * UINT64_C(1099511628211));
}
return hash;
}
int64_t
compiler_backend_cache_IndexFind(PathIndex* index, __type_c555612ad40905fa* items, String path)
{
int64_t value_0 = index->slots.count;
if (value_0 == 0LL) {
return -1LL;
}
int64_t mask = (int64_t)((uint64_t)(index->slots.count) - UINT64_C(1));
uint64_t value_1 = (uint64_t)((uint64_t)(compiler_backend_cache_PathHash(path)) & (uint64_t)(mask));
int64_t slot = (int64_t)(value_1);
while (true) {
int64_t value_2 = (index->slots).data[slot];
if (!(value_2 != 0LL)) { break; }
int64_t item = (int64_t)((uint64_t)((index->slots).data[slot]) - UINT64_C(1));
if (StringEqual(((*(items)).data[item]).path, path)) {
return item;
}
slot = (int64_t)(((uint64_t)slot + UINT64_C(1)) & (uint64_t)mask);
}
return -1LL;
}
void
compiler_backend_cache_IndexPlace(PathIndex* index, __type_c555612ad40905fa* items, int64_t item)
{
int64_t mask = (int64_t)((uint64_t)(index->slots.count) - UINT64_C(1));
uint64_t value_0 = (uint64_t)((uint64_t)(compiler_backend_cache_PathHash(((*(items)).data[item]).path)) & (uint64_t)(mask));
int64_t slot = (int64_t)(value_0);
while (true) {
int64_t value_1 = (index->slots).data[slot];
if (!(value_1 != 0LL)) { break; }
slot = (int64_t)(((uint64_t)slot + UINT64_C(1)) & (uint64_t)mask);
}
int64_t* value_2 = &(ZIRAN_VEC_INDEX((index->slots).data, (index->slots).count, slot));
(*value_2) = (int64_t)((uint64_t)item + UINT64_C(1));
int64_t* value_3 = &(index->count);
(*value_3) = (int64_t)((uint64_t)((*value_3)) + UINT64_C(1));
}
bool
compiler_backend_cache_IndexAdd(PathIndex* index, __type_c555612ad40905fa* items, int64_t item)
{
int64_t value_0 = (int64_t)(((uint64_t)(index->count) + UINT64_C(1)) * UINT64_C(2));
int64_t value_1 = index->slots.count;
if (value_0 > value_1) {
__type_03c9bb6e22816916 grown = {0};
__type_03c9bb6e22816916* value_2 = &grown;
int64_t value_3 = index->slots.count;
int64_t value_4 = 0;
if (value_3 == 0LL) {
value_4 = 64LL;
} else {
value_4 = (int64_t)((uint64_t)(index->slots.count) * UINT64_C(2));
}
int64_t value_6 = value_4;
bool value_7 = false;
if (value_6 >= 0) {
value_7 = value_6 <= (grown).capacity;
if (!value_7) {
void *value_8 = ZirVecReserve((void *)(grown).data, &(grown).capacity, (grown).count, value_6 - (grown).count, sizeof(*(grown).data));
if (value_8 != NULL) { (grown).data = value_8; value_7 = true; }
}
if (value_7) {
if (value_6 > (grown).count) memset((grown).data + (grown).count, 0, (size_t)(value_6 - (grown).count) * sizeof(*(grown).data));
(grown).count = value_6;
}
}
if (!value_7) {
free((grown).data);
(grown).data = NULL;
grown.capacity = 0;
grown.count = 0;
bool value_10 = false;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_10;
}
__type_03c9bb6e22816916 value_11 = grown;
grown = index->slots;
index->slots = value_11;
int64_t* value_12 = &(index->count);
(*value_12) = 0LL;
for (int64_t it_index = 0LL; it_index < grown.count; it_index++) {
int64_t value = (grown).data[it_index];
if (value != 0LL) {
compiler_backend_cache_IndexPlace(index, items, (int64_t)((uint64_t)value - UINT64_C(1)));
}
}
free((grown).data);
(grown).data = NULL;
grown.capacity = 0;
grown.count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
}
compiler_backend_cache_IndexPlace(index, items, item);
return true;
}
int64_t
compiler_backend_cache_FileAdd(BuildCache* cache, String path, bool directory)
{
int64_t value_0 = (int64_t)((uint64_t)(cache->files.count) + (uint64_t)(cache->candidates.count));
if (value_0 >= 262144LL || (int64_t)(path).length >= 4096LL) {
return -1LL;
}
Fingerprint item = {0};
bool* value_1 = &(item.directory);
(*value_1) = directory;
if (directory) {
Fingerprint value_2 = item;
for (size_t value_3 = 0; value_3 < sizeof(((item).digest).bytes) / sizeof((((item).digest).bytes)[0]); ++value_3) {
}
(item).probes.data = NULL;
(item).probes.capacity = 0;
(item).probes.count = 0;
Fingerprint value_4 = value_2;
bool value_5 = false;
void *value_6 = ZirVecGrow((void *)(cache->candidates).data, &(cache->candidates).capacity, (cache->candidates).count, sizeof(*(cache->candidates).data));
if (value_6 != NULL) {
(cache->candidates).data = value_6;
(cache->candidates).data[(cache->candidates).count++] = value_4;
value_5 = true;
}
if (!value_5) {
for (size_t value_7 = 0; value_7 < sizeof(((value_4).digest).bytes) / sizeof((((value_4).digest).bytes)[0]); ++value_7) {
}
free((value_4).probes.data);
(value_4).probes.data = NULL;
(value_4).probes.capacity = 0;
(value_4).probes.count = 0;
}
if (!value_5) {
int64_t value_8 = -1LL;
for (size_t value_9 = 0; value_9 < sizeof(((item).digest).bytes) / sizeof((((item).digest).bytes)[0]); ++value_9) {
}
free((item).probes.data);
(item).probes.data = NULL;
(item).probes.capacity = 0;
(item).probes.count = 0;
return value_8;
}
int64_t index = (int64_t)((uint64_t)(cache->candidates.count) - UINT64_C(1));
String* value_10 = &((ZIRAN_VEC_INDEX((cache->candidates).data, (cache->candidates).count, index)).path);
String value_11 = compiler_backend_cache_Owned(path);
(*value_10) = value_11;
int64_t value_12 = (int64_t)(((cache->candidates).data[index]).path).length;
if (value_12 == 0LL && (int64_t)(path).length != 0LL) {
int64_t value_13 = -1LL;
for (size_t value_14 = 0; value_14 < sizeof(((item).digest).bytes) / sizeof((((item).digest).bytes)[0]); ++value_14) {
}
free((item).probes.data);
(item).probes.data = NULL;
(item).probes.capacity = 0;
(item).probes.count = 0;
return value_13;
}
bool value_15 = compiler_backend_cache_IndexAdd(&(cache->candidate_index), &(cache->candidates), index);
if (!value_15) {
int64_t value_16 = -1LL;
for (size_t value_17 = 0; value_17 < sizeof(((item).digest).bytes) / sizeof((((item).digest).bytes)[0]); ++value_17) {
}
free((item).probes.data);
(item).probes.data = NULL;
(item).probes.capacity = 0;
(item).probes.count = 0;
return value_16;
}
int64_t value_18 = index;
for (size_t value_19 = 0; value_19 < sizeof(((item).digest).bytes) / sizeof((((item).digest).bytes)[0]); ++value_19) {
}
free((item).probes.data);
(item).probes.data = NULL;
(item).probes.capacity = 0;
(item).probes.count = 0;
return value_18;
}
Fingerprint value_20 = item;
for (size_t value_21 = 0; value_21 < sizeof(((item).digest).bytes) / sizeof((((item).digest).bytes)[0]); ++value_21) {
}
(item).probes.data = NULL;
(item).probes.capacity = 0;
(item).probes.count = 0;
Fingerprint value_22 = value_20;
bool value_23 = false;
void *value_24 = ZirVecGrow((void *)(cache->files).data, &(cache->files).capacity, (cache->files).count, sizeof(*(cache->files).data));
if (value_24 != NULL) {
(cache->files).data = value_24;
(cache->files).data[(cache->files).count++] = value_22;
value_23 = true;
}
if (!value_23) {
for (size_t value_25 = 0; value_25 < sizeof(((value_22).digest).bytes) / sizeof((((value_22).digest).bytes)[0]); ++value_25) {
}
free((value_22).probes.data);
(value_22).probes.data = NULL;
(value_22).probes.capacity = 0;
(value_22).probes.count = 0;
}
if (!value_23) {
int64_t value_26 = -1LL;
for (size_t value_27 = 0; value_27 < sizeof(((item).digest).bytes) / sizeof((((item).digest).bytes)[0]); ++value_27) {
}
free((item).probes.data);
(item).probes.data = NULL;
(item).probes.capacity = 0;
(item).probes.count = 0;
return value_26;
}
int64_t index = (int64_t)((uint64_t)(cache->files.count) - UINT64_C(1));
String* value_28 = &((ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, index)).path);
String value_29 = compiler_backend_cache_Owned(path);
(*value_28) = value_29;
int64_t value_30 = (int64_t)(((cache->files).data[index]).path).length;
if (value_30 == 0LL && (int64_t)(path).length != 0LL) {
int64_t value_31 = -1LL;
for (size_t value_32 = 0; value_32 < sizeof(((item).digest).bytes) / sizeof((((item).digest).bytes)[0]); ++value_32) {
}
free((item).probes.data);
(item).probes.data = NULL;
(item).probes.capacity = 0;
(item).probes.count = 0;
return value_31;
}
bool value_33 = compiler_backend_cache_IndexAdd(&(cache->file_index), &(cache->files), index);
if (!value_33) {
int64_t value_34 = -1LL;
for (size_t value_35 = 0; value_35 < sizeof(((item).digest).bytes) / sizeof((((item).digest).bytes)[0]); ++value_35) {
}
free((item).probes.data);
(item).probes.data = NULL;
(item).probes.capacity = 0;
(item).probes.count = 0;
return value_34;
}
int64_t value_36 = index;
for (size_t value_37 = 0; value_37 < sizeof(((item).digest).bytes) / sizeof((((item).digest).bytes)[0]); ++value_37) {
}
free((item).probes.data);
(item).probes.data = NULL;
(item).probes.capacity = 0;
(item).probes.count = 0;
return value_36;
}
int64_t
compiler_backend_cache_ProbeLiteral(String text, int64_t start, String* name)
{
int64_t at = start;
String value_0 = text;
int64_t value_1 = (int64_t)((uint64_t)at + UINT64_C(5));
int64_t value_2 = (int64_t)(text).length;
int64_t value_3 = 0;
{
int64_t value_5 = value_1;
int64_t value_6 = value_2;
int64_t value_7 = 0;
if (value_5 < value_6) {
value_7 = value_5;
} else {
value_7 = value_6;
}
value_3 = value_7;
}
String value_8 = StringRangeAt(value_0, (int64_t)at, (int64_t)value_3);
String value_9 = StringLiteral("_next");
bool value_10 = false;
{
String value_12 = value_8;
String value_13 = value_9;
value_10 = text_tools_TextHasPrefix(value_12, value_13);
}
if (value_10) {
at = (int64_t)((uint64_t)at + UINT64_C(5));
}
while (at < (int64_t)(text).length && text_tools_TextIsSpace((uint8_t)text.data[at])) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (at >= (int64_t)(text).length || (uint8_t)text.data[at] != 40) {
return -1LL;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
while (at < (int64_t)(text).length && text_tools_TextIsSpace((uint8_t)text.data[at])) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (at >= (int64_t)(text).length) {
return -1LL;
}
int64_t value_14 = 0;
if ((uint8_t)text.data[at] == 34) {
value_14 = 34LL;
} else {
int64_t value_15 = 0;
if ((uint8_t)text.data[at] == 60) {
value_15 = 62LL;
} else {
value_15 = 0LL;
}
value_14 = value_15;
}
int64_t end = value_14;
if (end == 0LL) {
return -1LL;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
int64_t first = at;
while (true) {
bool value_16 = at < (int64_t)(text).length;
if (value_16) {
int64_t value_17 = (int64_t)((uint8_t)text.data[at]);
value_16 = (value_17 != end);
}
if (!value_16) { break; }
if ((uint8_t)text.data[at] == 47 || (uint8_t)text.data[at] == 10) {
return -1LL;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (at >= (int64_t)(text).length || at == first || (int64_t)((uint64_t)at - (uint64_t)first) >= 4096LL) {
return -1LL;
}
String literal = compiler_backend_cache_Owned(StringRangeAt(text, (int64_t)first, (int64_t)at));
if ((int64_t)(literal).length == 0LL) {
return -1LL;
}
String* value_18 = &((*(name)));
(*value_18) = literal;
at = (int64_t)((uint64_t)at + UINT64_C(1));
while (at < (int64_t)(text).length && text_tools_TextIsSpace((uint8_t)text.data[at])) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (at < (int64_t)(text).length && (uint8_t)text.data[at] == 41) {
return (int64_t)((uint64_t)at + UINT64_C(1));
}
return -1LL;
}
int64_t
compiler_backend_cache_Minimum(int64_t left, int64_t right)
{
int64_t value_0 = 0;
if (left < right) {
value_0 = left;
} else {
value_0 = right;
}
return value_0;
}
Results__bool__bool
compiler_backend_cache_TextHazards(String text)
{
bool probing = false;
int64_t probe_from = 0LL;
int64_t at = 0LL;
while (at < (int64_t)(text).length) {
uint8_t byte = (uint8_t)text.data[at];
if (byte == 0) {
return (Results__bool__bool){.value_0 = true, .value_1 = probing};
}
if (byte == 95 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(text).length && (uint8_t)text.data[((int64_t)((uint64_t)at + UINT64_C(1)))] == 95) {
String rest = StringRangeAt(text, (int64_t)at, (int64_t)(int64_t)(text).length);
String value_2 = StringLiteral("__DATE__");
bool value_3 = false;
{
String value_5 = rest;
String value_6 = value_2;
value_3 = text_tools_TextHasPrefix(value_5, value_6);
}
bool value_7 = value_3;
if (!value_7) {
String value_8 = StringLiteral("__TIME__");
bool value_9 = false;
{
String value_11 = rest;
String value_12 = value_8;
value_9 = text_tools_TextHasPrefix(value_11, value_12);
}
value_7 = value_9;
}
bool value_13 = value_7;
if (!value_13) {
String value_14 = StringLiteral("__TIMESTAMP__");
bool value_15 = false;
{
String value_17 = rest;
String value_18 = value_14;
value_15 = text_tools_TextHasPrefix(value_17, value_18);
}
value_13 = value_15;
}
if (value_13) {
return (Results__bool__bool){.value_0 = true, .value_1 = probing};
}
String value_19 = StringLiteral("__has_include");
bool value_20 = false;
{
String value_22 = rest;
String value_23 = value_19;
value_20 = text_tools_TextHasPrefix(value_22, value_23);
}
if (value_20) {
probing = true;
if (at >= probe_from) {
String name = StringLiteral("");
probe_from = compiler_backend_cache_ProbeLiteral(text, (int64_t)((uint64_t)at + UINT64_C(13)), &(name));
compiler_backend_cache_Release(name);
if (probe_from < 0LL) {
return (Results__bool__bool){.value_0 = true, .value_1 = probing};
}
}
}
} else if (byte == 46) {
String rest = StringRangeAt(text, (int64_t)at, (int64_t)(int64_t)(text).length);
String value_24 = StringLiteral(".incbin");
bool value_25 = false;
{
String value_27 = rest;
String value_28 = value_24;
value_25 = text_tools_TextHasPrefix(value_27, value_28);
}
bool value_29 = value_25;
if (!value_29) {
String value_30 = StringLiteral(".include");
bool value_31 = false;
{
String value_33 = rest;
String value_34 = value_30;
value_31 = text_tools_TextHasPrefix(value_33, value_34);
}
value_29 = value_31;
}
bool value_35 = value_29;
if (!value_35) {
String value_36 = StringLiteral("../");
bool value_37 = false;
{
String value_39 = rest;
String value_40 = value_36;
value_37 = text_tools_TextHasPrefix(value_39, value_40);
}
value_35 = value_37;
}
if (value_35) {
return (Results__bool__bool){.value_0 = true, .value_1 = probing};
}
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
return (Results__bool__bool){.value_0 = false, .value_1 = probing};
}
bool
compiler_backend_cache_ProbeNames(String text, __type_9f828aa1372cb21a* names)
{
int64_t at = text_tools_TextFind(text, StringLiteral("__has_include"), 0LL);
while (at >= 0LL) {
String name = StringLiteral("");
at = compiler_backend_cache_ProbeLiteral(text, (int64_t)((uint64_t)at + UINT64_C(13)), &(name));
bool value_0 = at < 0LL;
if (!value_0) {
bool value_1 = compiler_backend_cache_AppendOwned(names, name);
value_0 = !value_1;
}
if (value_0) {
compiler_backend_cache_Release(name);
return false;
}
compiler_backend_cache_Release(name);
at = text_tools_TextFind(text, StringLiteral("__has_include"), at);
}
return true;
}
int64_t
compiler_backend_cache_FileDigest(BuildCache* cache, String path)
{
PathInfo before = file_tree_linux_PathStatus(path, true);
if (((PathKind)(before.kind)) != ((PathKind)(1))) {
return -1LL;
}
BuildCache* value_2 = cache;
String value_3 = path;
int64_t value_4 = 0;
{
BuildCache* value_6 = value_2;
String value_7 = value_3;
bool value_8 = false;
if (value_8) {
value_4 = compiler_backend_cache_IndexFind(&(value_6->candidate_index), &(value_6->candidates), value_7);
goto value_5;
}
value_4 = compiler_backend_cache_IndexFind(&(value_6->file_index), &(value_6->files), value_7);
value_5: ;
}
int64_t found = value_4;
bool value_9 = found >= 0LL;
if (value_9 && file_tree_linux_SameFileSnapshot(((cache->files).data[found]).info, before)) {
return found;
}
__type_131eebaaeb761e42 bytes = {0};
__type_131eebaaeb761e42* value_10 = &bytes;
bool value_11 = file_ReadFileInto(path, &(bytes));
if (!value_11) {
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
int64_t value_12 = -1LL;
free((*value_10).data);
(*value_10).data = NULL;
(*value_10).capacity = 0;
(*value_10).count = 0;
return value_12;
}
Slice value_13 = {(bytes).data, (bytes).count};
Slice value_14 = SliceRangeAt(value_13, 0LL, bytes.count, sizeof(*(bytes).data));
String text = StringView((const char *)(value_14).data, (size_t)(value_14).length);
HashState hash = compiler_backend_cache_HashNew();
compiler_backend_cache_HashBytes(&(hash), text);
Results__bool__bool results_1_ = compiler_backend_cache_TextHazards(text);
bool unsafe = results_1_.value_0;
bool probing = results_1_.value_1;
__type_9f828aa1372cb21a probes = {0};
__type_9f828aa1372cb21a* value_15 = &probes;
bool value_16 = probing && !unsafe;
bool value_17 = value_16;
if (value_17) {
bool value_18 = compiler_backend_cache_ProbeNames(text, &(probes));
value_17 = !value_18;
}
if (value_17) {
compiler_backend_cache_ClearNames(&(probes));
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
int64_t value_19 = -1LL;
free((*value_15).data);
(*value_15).data = NULL;
(*value_15).capacity = 0;
(*value_15).count = 0;
free((*value_10).data);
(*value_10).data = NULL;
(*value_10).capacity = 0;
(*value_10).count = 0;
return value_19;
}
PathInfo after = file_tree_linux_PathStatus(path, true);
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
bool value_20 = file_tree_linux_SameFileSnapshot(before, after);
if (!value_20) {
compiler_backend_cache_ClearNames(&(probes));
int64_t value_21 = -1LL;
free((*value_15).data);
(*value_15).data = NULL;
(*value_15).capacity = 0;
(*value_15).count = 0;
free((*value_10).data);
(*value_10).data = NULL;
(*value_10).capacity = 0;
(*value_10).count = 0;
return value_21;
}
if (found < 0LL) {
found = compiler_backend_cache_FileAdd(cache, path, false);
if (found < 0LL) {
compiler_backend_cache_ClearNames(&(probes));
int64_t value_22 = -1LL;
free((*value_15).data);
(*value_15).data = NULL;
(*value_15).capacity = 0;
(*value_15).count = 0;
free((*value_10).data);
(*value_10).data = NULL;
(*value_10).capacity = 0;
(*value_10).count = 0;
return value_22;
}
} else {
compiler_backend_cache_ClearNames(&((ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, found)).probes));
}
__type_9f828aa1372cb21a value_23 = probes;
probes = (ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, found)).probes;
(ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, found)).probes = value_23;
PathInfo* value_24 = &((ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, found)).info);
(*value_24) = after;
bool* value_25 = &((ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, found)).unsafe);
(*value_25) = unsafe;
String* value_26 = &((ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, found)).parent);
(*value_26) = StringLiteral("");
bool* value_27 = &((ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, found)).recent);
(*value_27) = false;
compiler_backend_cache_HashFinish(&(hash), &((ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, found)).digest));
int64_t value_28 = found;
free((*value_15).data);
(*value_15).data = NULL;
(*value_15).capacity = 0;
(*value_15).count = 0;
free((*value_10).data);
(*value_10).data = NULL;
(*value_10).capacity = 0;
(*value_10).count = 0;
return value_28;
}
bool
compiler_backend_cache_OlderThanBuild(BuildCache* cache, PathInfo info, bool changed)
{
int64_t value_0 = 0;
if (changed) {
value_0 = info.changed;
} else {
value_0 = info.modified;
}
int64_t seconds = value_0;
uint32_t value_1 = 0;
if (changed) {
value_1 = info.changed_nanoseconds;
} else {
value_1 = info.modified_nanoseconds;
}
uint32_t nanoseconds = value_1;
int64_t value_2 = cache->started_seconds;
if (seconds != value_2) {
int64_t value_3 = cache->started_seconds;
return seconds < value_3;
}
int64_t value_4 = (int64_t)(nanoseconds);
int64_t value_5 = cache->started_nanoseconds;
return value_4 < value_5;
}
int64_t
compiler_backend_cache_SpellingDigest(BuildCache* cache, String spelling, String root)
{
String value_0 = StringLiteral("\n");
bool value_1 = false;
{
String value_3 = spelling;
String value_4 = value_0;
value_1 = text_tools_TextContains(value_3, value_4);
}
bool value_5 = value_1;
if (!value_5) {
String value_6 = StringLiteral("\n");
bool value_7 = false;
{
String value_9 = root;
String value_10 = value_6;
value_7 = text_tools_TextContains(value_9, value_10);
}
value_5 = value_7;
}
if (value_5) {
return -1LL;
}
String value_11 = compiler_backend_cache_JoinTemporary(root, StringLiteral("\n"));
String key = compiler_backend_cache_JoinTemporary(value_11, spelling);
if ((int64_t)(key).length == 0LL) {
return -1LL;
}
BuildCache* value_12 = cache;
int64_t value_13 = 0;
{
BuildCache* value_15 = value_12;
String value_16 = key;
bool value_17 = true;
if (value_17) {
value_13 = compiler_backend_cache_IndexFind(&(value_15->candidate_index), &(value_15->candidates), value_16);
goto value_14;
}
value_13 = compiler_backend_cache_IndexFind(&(value_15->file_index), &(value_15->files), value_16);
value_14: ;
}
int64_t found = value_13;
if (found >= 0LL) {
compiler_backend_cache_Release(key);
if (((cache->candidates).data[found]).unsafe) {
return -1LL;
}
return found;
}
found = compiler_backend_cache_FileAdd(cache, key, true);
compiler_backend_cache_Release(key);
if (found < 0LL) {
return -1LL;
}
bool* value_18 = &((ZIRAN_VEC_INDEX((cache->candidates).data, (cache->candidates).count, found)).unsafe);
(*value_18) = true;
HashState hash = compiler_backend_cache_HashNew();
int64_t roots = cache->roots.count;
bool use_root = (int64_t)(root).length > 0LL;
if (use_root) {
roots = 1LL;
}
{
int64_t range_first_27 = 0LL;
int64_t range_last_27 = (int64_t)((uint64_t)roots - UINT64_C(1));
int64_t root_index = range_first_27;
if (root_index <= range_last_27) for (;;) {
String value_19 = StringView(NULL, 0);
if (use_root) {
value_19 = root;
} else {
value_19 = (cache->roots).data[root_index];
}
String directory = value_19;
int64_t at = 0LL;
while (at < (int64_t)(spelling).length && (uint8_t)spelling.data[at] == 47) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
while (at < (int64_t)(spelling).length && at > -1LL) {
String candidate = compiler_backend_cache_JoinPath(directory, StringRangeAt(spelling, (int64_t)at, (int64_t)(int64_t)(spelling).length));
if ((int64_t)(candidate).length == 0LL) {
return -1LL;
}
String portable = compiler_backend_cache_Normalized(cache, candidate);
HashState* value_20 = &(hash);
{
HashState* value_22 = value_20;
String value_23 = portable;
compiler_backend_cache_HashInteger(value_22, (uint64_t)((int64_t)(value_23).length));
compiler_backend_cache_HashBytes(value_22, value_23);
}
compiler_backend_cache_Release(portable);
PathInfo info = file_tree_linux_PathStatus(candidate, true);
compiler_backend_cache_Release(candidate);
if (info.identity_valid) {
int64_t value_24 = 0;
if (((PathKind)(info.kind)) == ((PathKind)(1))) {
value_24 = 32768LL;
} else {
int64_t value_25 = 0;
if (((PathKind)(info.kind)) == ((PathKind)(2))) {
value_25 = 16384LL;
} else {
value_25 = 0LL;
}
value_24 = value_25;
}
int64_t kind = value_24;
compiler_backend_cache_HashInteger(&(hash), (uint64_t)(kind));
BuildCache* value_26 = cache;
PathInfo value_27 = info;
bool value_28 = false;
{
BuildCache* value_30 = value_26;
PathInfo value_31 = value_27;
bool value_32 = true;
int64_t value_33 = 0;
if (value_32) {
value_33 = value_31.changed;
} else {
value_33 = value_31.modified;
}
int64_t value_34 = value_33;
uint32_t value_35 = 0;
if (value_32) {
value_35 = value_31.changed_nanoseconds;
} else {
value_35 = value_31.modified_nanoseconds;
}
uint32_t value_36 = value_35;
int64_t value_37 = value_30->started_seconds;
if (value_34 != value_37) {
int64_t value_38 = value_30->started_seconds;
value_28 = value_34 < value_38;
goto value_29;
}
int64_t value_39 = (int64_t)(value_36);
int64_t value_40 = value_30->started_nanoseconds;
value_28 = value_39 < value_40;
value_29: ;
}
if (!value_28) {
bool* value_41 = &((ZIRAN_VEC_INDEX((cache->candidates).data, (cache->candidates).count, found)).recent);
(*value_41) = true;
}
} else {
compiler_backend_cache_HashInteger(&(hash), 0ULL);
}
int64_t slash = text_tools_TextFind(spelling, StringLiteral("/"), at);
if (slash < 0LL) {
break;
}
at = (int64_t)((uint64_t)slash + UINT64_C(1));
while (at < (int64_t)(spelling).length && (uint8_t)spelling.data[at] == 47) {
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
if (at >= (int64_t)(spelling).length) {
break;
}
}
if (root_index == range_last_27) {
break;
}
root_index = (int64_t)((uint64_t)root_index + UINT64_C(1));
}
}
compiler_backend_cache_HashFinish(&(hash), &((ZIRAN_VEC_INDEX((cache->candidates).data, (cache->candidates).count, found)).digest));
bool* value_42 = &((ZIRAN_VEC_INDEX((cache->candidates).data, (cache->candidates).count, found)).unsafe);
(*value_42) = false;
return found;
}
bool
compiler_backend_cache_EnvironmentEntries(Slice bytes, __type_9f828aa1372cb21a* entries)
{
int64_t start = 0LL;
{
int64_t range_first_1 = 0LL;
int64_t range_last_1 = (int64_t)((uint64_t)((int64_t)(bytes).length) - UINT64_C(1));
int64_t index = range_first_1;
if (index <= range_last_1) for (;;) {
if (((uint8_t *)(bytes).data)[index] != 0) {
if (index == range_last_1) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
continue;
}
bool value_0 = index > start;
if (value_0) {
Slice value_1 = bytes;
Slice value_2 = SliceRangeAt(value_1, (int64_t)start, (int64_t)index, sizeof(uint8_t));
String value_3 = StringView((const char *)(value_2).data, (size_t)(value_2).length);
bool value_4 = false;
void *value_5 = ZirVecGrow((void *)((*(entries))).data, &((*(entries))).capacity, ((*(entries))).count, sizeof(*((*(entries))).data));
if (value_5 != NULL) {
((*(entries))).data = value_5;
((*(entries))).data[((*(entries))).count++] = value_3;
value_4 = true;
}
value_0 = !value_4;
}
if (value_0) {
return false;
}
start = (int64_t)((uint64_t)index + UINT64_C(1));
if (index == range_last_1) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
bool value_6 = start == (int64_t)(bytes).length;
bool value_7 = value_6;
if (!value_7) {
bool value_8 = start < (int64_t)(bytes).length;
bool value_9 = value_8;
if (value_9) {
Slice value_10 = bytes;
Slice value_11 = SliceRangeAt(value_10, (int64_t)start, (int64_t)(int64_t)(bytes).length, sizeof(uint8_t));
String value_12 = StringView((const char *)(value_11).data, (size_t)(value_11).length);
bool value_13 = false;
void *value_14 = ZirVecGrow((void *)((*(entries))).data, &((*(entries))).capacity, ((*(entries))).count, sizeof(*((*(entries))).data));
if (value_14 != NULL) {
((*(entries))).data = value_14;
((*(entries))).data[((*(entries))).count++] = value_12;
value_13 = true;
}
value_9 = value_13;
}
value_7 = value_9;
}
return value_7;
}
bool
compiler_backend_cache_CompilerEnvironment(String entry)
{
String names[13] = {StringLiteral("PATH"), StringLiteral("CPATH"), StringLiteral("C_INCLUDE_PATH"), StringLiteral("CPLUS_INCLUDE_PATH"), StringLiteral("OBJC_INCLUDE_PATH"), StringLiteral("OBJCPLUS_INCLUDE_PATH"), StringLiteral("COMPILER_PATH"), StringLiteral("LIBRARY_PATH"), StringLiteral("SOURCE_DATE_EPOCH"), StringLiteral("SDKROOT"), StringLiteral("DEVELOPER_DIR"), StringLiteral("ZERO_AR_DATE"), StringLiteral("LANG")};
int64_t equals = text_tools_TextFind(entry, StringLiteral("="), 0LL);
String value_0 = StringView(NULL, 0);
if (equals >= 0LL) {
value_0 = StringRangeAt(entry, (int64_t)0LL, (int64_t)equals);
} else {
value_0 = entry;
}
String name = value_0;
for (int64_t it_index = 0LL; it_index < 13; it_index++) {
String known = (names)[it_index];
if (StringEqual(name, known)) {
return true;
}
}
String prefixes[10] = {StringLiteral("LC_"), StringLiteral("GCC_"), StringLiteral("COLLECT_"), StringLiteral("CC_"), StringLiteral("CCC_"), StringLiteral("CLANG_"), StringLiteral("LLVM_"), StringLiteral("RC_"), StringLiteral("LD_"), StringLiteral("DYLD_")};
for (int64_t it_index = 0LL; it_index < 10; it_index++) {
String prefix = (prefixes)[it_index];
String value_1 = prefix;
bool value_2 = false;
{
String value_4 = entry;
String value_5 = value_1;
value_2 = text_tools_TextHasPrefix(value_4, value_5);
}
if (value_2) {
return true;
}
}
String value_6 = StringLiteral("_DEPLOYMENT_TARGET");
bool value_7 = false;
{
String value_9 = name;
String value_10 = value_6;
value_7 = text_tools_TextHasSuffix(value_9, value_10);
}
return value_7;
}
bool
compiler_backend_cache_HashEnvironment(HashState* hash, HashState* shared)
{
__type_131eebaaeb761e42 bytes = {0};
__type_131eebaaeb761e42* value_0 = &bytes;
bool value_1 = file_ReadFileInto(StringLiteral("/proc/self/environ"), &(bytes));
if (!value_1) {
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
bool value_2 = false;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_2;
}
__type_9f828aa1372cb21a entries = {0};
__type_9f828aa1372cb21a* value_3 = &entries;
Slice value_4 = {(bytes).data, (bytes).count};
bool ok = compiler_backend_cache_EnvironmentEntries(SliceRangeAt(value_4, 0LL, bytes.count, sizeof(*(bytes).data)), &(entries));
if (ok) {
Slice value_5 = {(entries).data, (entries).count};
sort_SortText(SliceRangeAt(value_5, 0LL, entries.count, sizeof(*(entries).data)));
{
Slice value_6 = {(entries).data, (entries).count};
Slice value_7 = SliceRangeAt(value_6, 0LL, entries.count, sizeof(*(entries).data));
Slice loop_view_9 = value_7;
int64_t loop_count_9 = (int64_t)(loop_view_9).length;
int64_t loop_cursor_9 = 0LL;
while (loop_cursor_9 < loop_count_9) {
int64_t loop_index_9 = loop_cursor_9;
String entry = ((String *)(loop_view_9).data)[loop_index_9];
if (compiler_backend_cache_CompilerEnvironment(entry)) {
HashState* value_8 = hash;
{
HashState* value_10 = value_8;
String value_11 = entry;
compiler_backend_cache_HashInteger(value_10, (uint64_t)((int64_t)(value_11).length));
compiler_backend_cache_HashBytes(value_10, value_11);
}
{
HashState* value_13 = shared;
String value_14 = entry;
compiler_backend_cache_HashInteger(value_13, (uint64_t)((int64_t)(value_14).length));
compiler_backend_cache_HashBytes(value_13, value_14);
}
}
loop_cursor_9 = (int64_t)((uint64_t)loop_cursor_9 + UINT64_C(1));
}
}
}
free((entries).data);
(entries).data = NULL;
entries.capacity = 0;
entries.count = 0;
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
bool value_15 = ok;
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_15;
}
__type_131eebaaeb761e42
compiler_backend_cache_Probe(Slice arguments, bool piped)
{
__type_9f828aa1372cb21a command = {0};
__type_9f828aa1372cb21a* value_0 = &command;
for (int64_t it_index = 0LL; it_index < (int64_t)(arguments).length; it_index++) {
String value = ((String *)(arguments).data)[it_index];
String value_1 = value;
bool value_2 = false;
void *value_3 = ZirVecGrow((void *)(command).data, &(command).capacity, (command).count, sizeof(*(command).data));
if (value_3 != NULL) {
(command).data = value_3;
(command).data[(command).count++] = value_1;
value_2 = true;
}
(void)value_2;
}
bool value_4 = piped;
if (value_4) {
bool value_5 = compiler_backend_cache_RequestedPipe(arguments);
value_4 = !value_5;
}
if (value_4) {
String value_6 = StringLiteral("-pipe");
bool value_7 = false;
void *value_8 = ZirVecGrow((void *)(command).data, &(command).capacity, (command).count, sizeof(*(command).data));
if (value_8 != NULL) {
(command).data = value_8;
(command).data[(command).count++] = value_6;
value_7 = true;
}
(void)value_7;
}
String value_9 = StringLiteral("-v");
bool value_10 = false;
void *value_11 = ZirVecGrow((void *)(command).data, &(command).capacity, (command).count, sizeof(*(command).data));
if (value_11 != NULL) {
(command).data = value_11;
(command).data[(command).count++] = value_9;
value_10 = true;
}
(void)value_10;
String value_12 = StringLiteral("-x");
bool value_13 = false;
void *value_14 = ZirVecGrow((void *)(command).data, &(command).capacity, (command).count, sizeof(*(command).data));
if (value_14 != NULL) {
(command).data = value_14;
(command).data[(command).count++] = value_12;
value_13 = true;
}
(void)value_13;
String value_15 = StringLiteral("c");
bool value_16 = false;
void *value_17 = ZirVecGrow((void *)(command).data, &(command).capacity, (command).count, sizeof(*(command).data));
if (value_17 != NULL) {
(command).data = value_17;
(command).data[(command).count++] = value_15;
value_16 = true;
}
(void)value_16;
String value_18 = StringLiteral("-c");
bool value_19 = false;
void *value_20 = ZirVecGrow((void *)(command).data, &(command).capacity, (command).count, sizeof(*(command).data));
if (value_20 != NULL) {
(command).data = value_20;
(command).data[(command).count++] = value_18;
value_19 = true;
}
(void)value_19;
String value_21 = StringLiteral("/dev/null");
bool value_22 = false;
void *value_23 = ZirVecGrow((void *)(command).data, &(command).capacity, (command).count, sizeof(*(command).data));
if (value_23 != NULL) {
(command).data = value_23;
(command).data[(command).count++] = value_21;
value_22 = true;
}
(void)value_22;
String value_24 = StringLiteral("-o");
bool value_25 = false;
void *value_26 = ZirVecGrow((void *)(command).data, &(command).capacity, (command).count, sizeof(*(command).data));
if (value_26 != NULL) {
(command).data = value_26;
(command).data[(command).count++] = value_24;
value_25 = true;
}
(void)value_25;
String value_27 = StringLiteral("/dev/null");
bool value_28 = false;
void *value_29 = ZirVecGrow((void *)(command).data, &(command).capacity, (command).count, sizeof(*(command).data));
if (value_29 != NULL) {
(command).data = value_29;
(command).data[(command).count++] = value_27;
value_28 = true;
}
(void)value_28;
__type_131eebaaeb761e42 result = {0};
__type_131eebaaeb761e42* value_30 = &result;
ProcessOptions value_31 = {0};
Slice value_32 = {(command).data, (command).count};
value_31.arguments = SliceRangeAt(value_32, 0LL, command.count, sizeof(*(command).data));
value_31.capture_output = true;
value_31.merge_error = true;
ProcessOptions options = value_31;
ProcessRun run = {0};
bool value_33 = process_run_linux_RunProcess(options, &(run));
if (value_33 && run.code == 0) {
{
Slice value_34 = {(run.output).data, (run.output).count};
Slice loop_view_18 = SliceRangeAt(value_34, 0LL, run.output.count, sizeof(*(run.output).data));
int64_t loop_count_18 = (int64_t)(loop_view_18).length;
int64_t loop_cursor_18 = 0LL;
while (loop_cursor_18 < loop_count_18) {
int64_t loop_index_18 = loop_cursor_18;
uint8_t byte = ((uint8_t *)(loop_view_18).data)[loop_index_18];
uint8_t value_35 = byte;
bool value_36 = false;
void *value_37 = ZirVecGrow((void *)(result).data, &(result).capacity, (result).count, sizeof(*(result).data));
if (value_37 != NULL) {
(result).data = value_37;
(result).data[(result).count++] = value_35;
value_36 = true;
}
(void)value_36;
loop_cursor_18 = (int64_t)((uint64_t)loop_cursor_18 + UINT64_C(1));
}
}
}
String value_38 = StringView(NULL, 0);
if (piped) {
value_38 = StringLiteral("native_probe_pipe");
} else {
value_38 = StringLiteral("native_probe_compile");
}
compiler_backend_cache_ProfileCount(value_38);
free((run.output).data);
(run.output).data = NULL;
run.output.capacity = 0;
run.output.count = 0;
free((command).data);
(command).data = NULL;
command.capacity = 0;
command.count = 0;
if (result.count > 65536LL) {
free((result).data);
(result).data = NULL;
result.capacity = 0;
result.count = 0;
__type_131eebaaeb761e42 value_39 = (__type_131eebaaeb761e42){0};
free((run).output.data);
(run).output.data = NULL;
(run).output.capacity = 0;
(run).output.count = 0;
free((*value_30).data);
(*value_30).data = NULL;
(*value_30).capacity = 0;
(*value_30).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_39;
}
for (int64_t it_index = 0LL; it_index < result.count; it_index++) {
uint8_t byte = (result).data[it_index];
if (byte == 0) {
free((result).data);
(result).data = NULL;
result.capacity = 0;
result.count = 0;
__type_131eebaaeb761e42 value_40 = (__type_131eebaaeb761e42){0};
free((run).output.data);
(run).output.data = NULL;
(run).output.capacity = 0;
(run).output.count = 0;
free((*value_30).data);
(*value_30).data = NULL;
(*value_30).capacity = 0;
(*value_30).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_40;
}
}
__type_131eebaaeb761e42 value_41 = result;
result.data = NULL;
result.capacity = 0;
result.count = 0;
__type_131eebaaeb761e42 value_42 = value_41;
free((run).output.data);
(run).output.data = NULL;
(run).output.capacity = 0;
(run).output.count = 0;
free((*value_30).data);
(*value_30).data = NULL;
(*value_30).capacity = 0;
(*value_30).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_42;
}
bool
compiler_backend_cache_HashProbeOutput(HashState* hash, String text)
{
__type_9f828aa1372cb21a lines = text_tools_TextLines(text);
__type_9f828aa1372cb21a* value_0 = &lines;
if (lines.count == 0LL || lines.count > 16384LL) {
free((lines).data);
(lines).data = NULL;
lines.capacity = 0;
lines.count = 0;
bool value_1 = false;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_1;
}
bool value_2 = compiler_backend_cache_JoinProbeVersions(&(lines));
if (!value_2) {
free((lines).data);
(lines).data = NULL;
lines.capacity = 0;
lines.count = 0;
bool value_3 = false;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_3;
}
Slice value_4 = {(lines).data, (lines).count};
sort_SortText(SliceRangeAt(value_4, 0LL, lines.count, sizeof(*(lines).data)));
compiler_backend_cache_HashInteger(hash, (uint64_t)(lines.count));
{
Slice value_5 = {(lines).data, (lines).count};
Slice value_6 = SliceRangeAt(value_5, 0LL, lines.count, sizeof(*(lines).data));
Slice loop_view_11 = value_6;
int64_t loop_count_11 = (int64_t)(loop_view_11).length;
int64_t loop_cursor_11 = 0LL;
while (loop_cursor_11 < loop_count_11) {
int64_t loop_index_11 = loop_cursor_11;
String line = ((String *)(loop_view_11).data)[loop_index_11];
HashState* value_7 = hash;
{
HashState* value_9 = value_7;
String value_10 = line;
compiler_backend_cache_HashInteger(value_9, (uint64_t)((int64_t)(value_10).length));
compiler_backend_cache_HashBytes(value_9, value_10);
}
loop_cursor_11 = (int64_t)((uint64_t)loop_cursor_11 + UINT64_C(1));
}
}
free((lines).data);
(lines).data = NULL;
lines.capacity = 0;
lines.count = 0;
bool value_11 = true;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_11;
}
bool
compiler_backend_cache_JoinProbeVersions(__type_9f828aa1372cb21a* lines)
{
String prefix = StringLiteral("\tcompiled by GNU C version ");
String checksum_label = StringLiteral("Compiler executable checksum: ");
String assembler_label = StringLiteral("GNU assembler version ");
String gmp_label = StringLiteral("GMP version ");
String bfd_label = StringLiteral(" using BFD version ");
{
int64_t range_first_5 = 0LL;
int64_t range_last_5 = (int64_t)((uint64_t)(lines->count) - UINT64_C(2));
int64_t index = range_first_5;
if (index <= range_last_5) for (;;) {
int64_t banner_at = -1LL;
bool value_0 = text_tools_TextHasPrefix((*(lines)).data[index], prefix);
if (value_0 && text_tools_TextHasPrefix((*(lines)).data[((int64_t)((uint64_t)index + UINT64_C(1)))], gmp_label)) {
banner_at = text_tools_TextFind((*(lines)).data[index], assembler_label, (int64_t)(prefix).length);
if (banner_at <= (int64_t)(prefix).length) {
if (index == range_last_5) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
continue;
}
if ((uint8_t)((*(lines)).data[index]).data[((int64_t)((uint64_t)banner_at - UINT64_C(2)))] != 44 || (uint8_t)((*(lines)).data[index]).data[((int64_t)((uint64_t)banner_at - UINT64_C(1)))] != 32) {
if (index == range_last_5) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
continue;
}
} else if (text_tools_TextHasPrefix((*(lines)).data[index], checksum_label)) {
banner_at = text_tools_TextFind((*(lines)).data[index], assembler_label, (int64_t)(checksum_label).length);
if (banner_at < 0LL) {
if (index == range_last_5) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
continue;
}
int64_t before = (int64_t)((uint64_t)banner_at - (uint64_t)((int64_t)(checksum_label).length));
int64_t after = 0LL;
while (true) {
int64_t value_1 = (int64_t)((*(lines)).data[((int64_t)((uint64_t)index + UINT64_C(1)))]).length;
if (!(after < value_1 && (uint8_t)((*(lines)).data[((int64_t)((uint64_t)index + UINT64_C(1)))]).data[after] != 13)) { break; }
after = (int64_t)((uint64_t)after + UINT64_C(1));
}
if ((int64_t)((uint64_t)before + (uint64_t)after) != 32LL) {
if (index == range_last_5) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
continue;
}
bool digits = true;
{
int64_t range_first_30 = 0LL;
int64_t range_last_30 = (int64_t)((uint64_t)before - UINT64_C(1));
int64_t at = range_first_30;
if (at <= range_last_30) for (;;) {
uint8_t byte = (uint8_t)((*(lines)).data[index]).data[((int64_t)((uint64_t)((int64_t)(checksum_label).length) + (uint64_t)at))];
bool hex = (byte >= 48 && byte <= 57) || (byte >= 97 && byte <= 102);
if (!hex) {
digits = false;
}
if (at == range_last_30) {
break;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
{
int64_t range_first_37 = 0LL;
int64_t range_last_37 = (int64_t)((uint64_t)after - UINT64_C(1));
int64_t at = range_first_37;
if (at <= range_last_37) for (;;) {
uint8_t next_byte = (uint8_t)((*(lines)).data[((int64_t)((uint64_t)index + UINT64_C(1)))]).data[at];
bool next_hex = (next_byte >= 48 && next_byte <= 57) || (next_byte >= 97 && next_byte <= 102);
if (!next_hex) {
digits = false;
}
if (at == range_last_37) {
break;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
if (!digits) {
if (index == range_last_5) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
continue;
}
} else {
if (index == range_last_5) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
continue;
}
String value_2 = (*(lines)).data[index];
String value_3 = StringRangeAt(value_2, (int64_t)banner_at, (int64_t)value_2.length);
bool value_4 = false;
{
String value_6 = value_3;
String value_7 = bfd_label;
value_4 = text_tools_TextContains(value_6, value_7);
}
if (!value_4) {
if (index == range_last_5) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
continue;
}
String value_8 = (*(lines)).data[index];
Text saved = vec_TextCopy(StringRangeAt(value_8, (int64_t)banner_at, (int64_t)value_8.length));
if (saved.bytes.count == 0LL) {
bool value_9 = false;
free((saved).bytes.data);
(saved).bytes.data = NULL;
(saved).bytes.capacity = 0;
(saved).bytes.count = 0;
return value_9;
}
String value_10 = (*(lines)).data[index];
Text rebuilt = vec_TextCopy(StringRangeAt(value_10, (int64_t)0LL, (int64_t)banner_at));
bool value_11 = false;
if (((*(lines)).data[((int64_t)((uint64_t)index + UINT64_C(1)))]).length == 0) {
value_11 = true;
} else {
void *value_12 = ZirVecReserve((void *)(rebuilt.bytes).data, &(rebuilt.bytes).capacity, (rebuilt.bytes).count, (int64_t)((*(lines)).data[((int64_t)((uint64_t)index + UINT64_C(1)))]).length, sizeof(*(rebuilt.bytes).data));
if (value_12 != NULL) {
(rebuilt.bytes).data = (uint8_t *)value_12;
memcpy((rebuilt.bytes).data + (rebuilt.bytes).count, ((*(lines)).data[((int64_t)((uint64_t)index + UINT64_C(1)))]).data, (size_t)((*(lines)).data[((int64_t)((uint64_t)index + UINT64_C(1)))]).length);
(rebuilt.bytes).count += (int64_t)((*(lines)).data[((int64_t)((uint64_t)index + UINT64_C(1)))]).length;
value_11 = true;
}
}
(void)value_11;
__type_9f828aa1372cb21a merged = {0};
__type_9f828aa1372cb21a* value_13 = &merged;
Text value_14 = rebuilt;
(rebuilt).bytes.data = NULL;
(rebuilt).bytes.capacity = 0;
(rebuilt).bytes.count = 0;
String value_15 = vec_TextDetach(value_14);
String value_16 = value_15;
bool value_17 = false;
void *value_18 = ZirVecGrow((void *)(merged).data, &(merged).capacity, (merged).count, sizeof(*(merged).data));
if (value_18 != NULL) {
(merged).data = value_18;
(merged).data[(merged).count++] = value_16;
value_17 = true;
}
(void)value_17;
Text value_19 = saved;
(saved).bytes.data = NULL;
(saved).bytes.capacity = 0;
(saved).bytes.count = 0;
String value_20 = vec_TextDetach(value_19);
String value_21 = value_20;
bool value_22 = false;
void *value_23 = ZirVecGrow((void *)(merged).data, &(merged).capacity, (merged).count, sizeof(*(merged).data));
if (value_23 != NULL) {
(merged).data = value_23;
(merged).data[(merged).count++] = value_21;
value_22 = true;
}
(void)value_22;
__type_9f828aa1372cb21a tail = {0};
__type_9f828aa1372cb21a* value_24 = &tail;
__type_9f828aa1372cb21a value_25 = merged;
merged = tail;
tail = value_25;
__type_9f828aa1372cb21a head = {0};
__type_9f828aa1372cb21a* value_26 = &head;
{
int64_t range_first_66 = 0LL;
int64_t range_last_66 = (int64_t)((uint64_t)index - UINT64_C(1));
int64_t at = range_first_66;
if (at <= range_last_66) for (;;) {
String value_27 = (*(lines)).data[at];
bool value_28 = false;
void *value_29 = ZirVecGrow((void *)(head).data, &(head).capacity, (head).count, sizeof(*(head).data));
if (value_29 != NULL) {
(head).data = value_29;
(head).data[(head).count++] = value_27;
value_28 = true;
}
(void)value_28;
if (at == range_last_66) {
break;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
String value_30 = (tail).data[0];
bool value_31 = false;
void *value_32 = ZirVecGrow((void *)(head).data, &(head).capacity, (head).count, sizeof(*(head).data));
if (value_32 != NULL) {
(head).data = value_32;
(head).data[(head).count++] = value_30;
value_31 = true;
}
(void)value_31;
String value_33 = (tail).data[1];
bool value_34 = false;
void *value_35 = ZirVecGrow((void *)(head).data, &(head).capacity, (head).count, sizeof(*(head).data));
if (value_35 != NULL) {
(head).data = value_35;
(head).data[(head).count++] = value_33;
value_34 = true;
}
(void)value_34;
{
int64_t range_first_71 = (int64_t)((uint64_t)index + UINT64_C(2));
int64_t range_last_71 = (int64_t)((uint64_t)(lines->count) - UINT64_C(1));
int64_t at = range_first_71;
if (at <= range_last_71) for (;;) {
String value_36 = (*(lines)).data[at];
bool value_37 = false;
void *value_38 = ZirVecGrow((void *)(head).data, &(head).capacity, (head).count, sizeof(*(head).data));
if (value_38 != NULL) {
(head).data = value_38;
(head).data[(head).count++] = value_36;
value_37 = true;
}
(void)value_37;
if (at == range_last_71) {
break;
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
}
__type_9f828aa1372cb21a value_39 = head;
head = (*(lines));
(*(lines)) = value_39;
free((head).data);
(head).data = NULL;
head.capacity = 0;
head.count = 0;
free((tail).data);
(tail).data = NULL;
tail.capacity = 0;
tail.count = 0;
if (index == range_last_5) {
free((*value_26).data);
(*value_26).data = NULL;
(*value_26).capacity = 0;
(*value_26).count = 0;
free((*value_24).data);
(*value_24).data = NULL;
(*value_24).capacity = 0;
(*value_24).count = 0;
free((*value_13).data);
(*value_13).data = NULL;
(*value_13).capacity = 0;
(*value_13).count = 0;
free((rebuilt).bytes.data);
(rebuilt).bytes.data = NULL;
(rebuilt).bytes.capacity = 0;
(rebuilt).bytes.count = 0;
free((saved).bytes.data);
(saved).bytes.data = NULL;
(saved).bytes.capacity = 0;
(saved).bytes.count = 0;
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
free((*value_26).data);
(*value_26).data = NULL;
(*value_26).capacity = 0;
(*value_26).count = 0;
free((*value_24).data);
(*value_24).data = NULL;
(*value_24).capacity = 0;
(*value_24).count = 0;
free((*value_13).data);
(*value_13).data = NULL;
(*value_13).capacity = 0;
(*value_13).count = 0;
free((rebuilt).bytes.data);
(rebuilt).bytes.data = NULL;
(rebuilt).bytes.capacity = 0;
(rebuilt).bytes.count = 0;
free((saved).bytes.data);
(saved).bytes.data = NULL;
(saved).bytes.capacity = 0;
(saved).bytes.count = 0;
}
}
return true;
}
BuildCache*
compiler_backend_cache_Open(Slice arguments, String output, String executable)
{
if ((int64_t)(arguments).length == 0LL) {
return (void *)0;
}
bool value_0 = compiler_backend_cache_SupportedArguments(arguments);
if (!value_0) {
return (void *)0;
}
String compiler = compiler_backend_cache_Executable(((String *)(arguments).data)[0]);
if ((int64_t)(compiler).length == 0LL) {
compiler_backend_cache_Release(compiler);
return (void *)0;
}
bool value_1 = compiler_backend_cache_NativeImage(compiler);
if (!value_1) {
compiler_backend_cache_Release(compiler);
return (void *)0;
}
String name = compiler_backend_cache_TextName(compiler);
String value_2 = StringLiteral("gcc");
bool value_3 = false;
{
String value_5 = name;
String value_6 = value_2;
value_3 = text_tools_TextContains(value_5, value_6);
}
bool value_7 = !value_3;
if (value_7) {
String value_8 = StringLiteral("clang");
bool value_9 = false;
{
String value_11 = name;
String value_12 = value_8;
value_9 = text_tools_TextContains(value_11, value_12);
}
value_7 = !value_9;
}
if (value_7 && !StringEqual(name, StringLiteral("cc"))) {
compiler_backend_cache_Release(compiler);
return (void *)0;
}
String value_13 = StringLiteral("clang");
bool value_14 = false;
{
String value_16 = name;
String value_17 = value_13;
value_14 = text_tools_TextContains(value_16, value_17);
}
bool piped = !value_14;
void* value_18 = zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_17(1, sizeof(BuildCache));
BuildCache* cache = (BuildCache*)(value_18);
if (cache == ((void *)0)) {
compiler_backend_cache_Release(compiler);
return (void *)0;
}
bool* value_19 = &(cache->piped);
(*value_19) = piped;
String resolved_output = compiler_backend_cache_Resolved(output);
if ((int64_t)(resolved_output).length == 0LL) {
compiler_backend_cache_Close(cache);
compiler_backend_cache_Release(compiler);
return (void *)0;
}
String* value_20 = &(cache->output);
(*value_20) = resolved_output;
String* value_21 = &(cache->alias);
String value_22 = compiler_backend_cache_Owned(output);
(*value_21) = value_22;
bool* value_23 = &(cache->portable);
bool value_24 = compiler_backend_cache_DebugArguments(arguments);
(*value_23) = !value_24;
String* value_25 = &(cache->executable);
String value_26 = compiler_backend_cache_Owned(executable);
(*value_25) = value_26;
ClockValue clock = {0};
int64_t value_27 = (int64_t)(cache->executable).length;
bool value_28 = value_27 == 0LL;
if (!value_28) {
int64_t value_29 = (int64_t)(cache->alias).length;
value_28 = (value_29 == 0LL);
}
if (value_28) {
compiler_backend_cache_Close(cache);
compiler_backend_cache_Release(compiler);
return (void *)0;
}
if (zir_foreign_compiler_backend_cache__ClockRaw(0, &(clock)) != 0) {
compiler_backend_cache_Close(cache);
compiler_backend_cache_Release(compiler);
return (void *)0;
}
int64_t* value_30 = &(cache->started_seconds);
(*value_30) = (int64_t)(clock.seconds);
int64_t* value_31 = &(cache->started_nanoseconds);
(*value_31) = (int64_t)(clock.nanoseconds);
HashState hash = compiler_backend_cache_HashNew();
HashState shared = compiler_backend_cache_HashNew();
HashState* value_32 = &(hash);
String value_33 = StringLiteral("Ziran native object cache 5");
{
HashState* value_35 = value_32;
String value_36 = value_33;
compiler_backend_cache_HashInteger(value_35, (uint64_t)((int64_t)(value_36).length));
compiler_backend_cache_HashBytes(value_35, value_36);
}
HashState* value_37 = &(shared);
String value_38 = StringLiteral("Ziran object store 1\n");
{
HashState* value_40 = value_37;
String value_41 = value_38;
compiler_backend_cache_HashInteger(value_40, (uint64_t)((int64_t)(value_41).length));
compiler_backend_cache_HashBytes(value_40, value_41);
}
uint64_t value_42 = 0;
if (piped) {
value_42 = 1ULL;
} else {
value_42 = 0ULL;
}
compiler_backend_cache_HashInteger(&(hash), value_42);
uint64_t value_43 = 0;
if (piped) {
value_43 = 1ULL;
} else {
value_43 = 0ULL;
}
compiler_backend_cache_HashInteger(&(shared), value_43);
uint8_t directory[4096] = {0};
uint8_t* working_pointer = zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_19(&(directory[0]), 4096);
int64_t working_length = 0LL;
if (working_pointer != ((void *)0)) {
while ((directory)[working_length] != 0) {
working_length = (int64_t)((uint64_t)working_length + UINT64_C(1));
}
}
if (working_length == 0LL) {
compiler_backend_cache_Close(cache);
compiler_backend_cache_Release(compiler);
return (void *)0;
}
HashState* value_44 = &(hash);
Slice value_45 = {directory, 4096};
Slice value_46 = SliceRangeAt(value_45, (int64_t)0LL, (int64_t)working_length, sizeof(uint8_t));
String value_47 = StringView((const char *)(value_46).data, (size_t)(value_46).length);
{
HashState* value_49 = value_44;
String value_50 = value_47;
compiler_backend_cache_HashInteger(value_49, (uint64_t)((int64_t)(value_50).length));
compiler_backend_cache_HashBytes(value_49, value_50);
}
bool value_51 = !cache->portable;
if (value_51 || compiler_backend_cache_RelativeArguments(arguments)) {
HashState* value_52 = &(shared);
Slice value_53 = {directory, 4096};
Slice value_54 = SliceRangeAt(value_53, (int64_t)0LL, (int64_t)working_length, sizeof(uint8_t));
String value_55 = StringView((const char *)(value_54).data, (size_t)(value_54).length);
{
HashState* value_57 = value_52;
String value_58 = value_55;
compiler_backend_cache_HashInteger(value_57, (uint64_t)((int64_t)(value_58).length));
compiler_backend_cache_HashBytes(value_57, value_58);
}
}
for (int64_t it_index = 0LL; it_index < (int64_t)(arguments).length; it_index++) {
String argument = ((String *)(arguments).data)[it_index];
BuildCache* value_59 = cache;
HashState* value_60 = &(hash);
HashState* value_61 = &(shared);
{
BuildCache* value_63 = value_59;
HashState* value_64 = value_60;
HashState* value_65 = value_61;
String value_66 = argument;
{
HashState* value_68 = value_64;
String value_69 = value_66;
compiler_backend_cache_HashInteger(value_68, (uint64_t)((int64_t)(value_69).length));
compiler_backend_cache_HashBytes(value_68, value_69);
}
String value_70 = compiler_backend_cache_Normalized(value_63, value_66);
{
HashState* value_72 = value_65;
String value_73 = value_70;
compiler_backend_cache_HashInteger(value_72, (uint64_t)((int64_t)(value_73).length));
compiler_backend_cache_HashBytes(value_72, value_73);
}
compiler_backend_cache_Release(value_70);
}
}
bool value_74 = compiler_backend_cache_HashEnvironment(&(hash), &(shared));
if (!value_74) {
compiler_backend_cache_Close(cache);
compiler_backend_cache_Release(compiler);
return (void *)0;
}
PathInfo info = file_tree_linux_PathStatus(compiler, true);
HashState* value_75 = &(hash);
{
HashState* value_77 = value_75;
String value_78 = compiler;
compiler_backend_cache_HashInteger(value_77, (uint64_t)((int64_t)(value_78).length));
compiler_backend_cache_HashBytes(value_77, value_78);
}
HashState* value_79 = &(shared);
{
HashState* value_81 = value_79;
String value_82 = compiler;
compiler_backend_cache_HashInteger(value_81, (uint64_t)((int64_t)(value_82).length));
compiler_backend_cache_HashBytes(value_81, value_82);
}
HashState* value_83 = &(hash);
PathInfo value_84 = info;
{
HashState* value_86 = value_83;
PathInfo value_87 = value_84;
compiler_backend_cache_HashInteger(value_86, (uint64_t)(value_87.device_major));
compiler_backend_cache_HashInteger(value_86, (uint64_t)(value_87.device_minor));
compiler_backend_cache_HashInteger(value_86, value_87.inode);
compiler_backend_cache_HashInteger(value_86, (uint64_t)(value_87.mode));
compiler_backend_cache_HashInteger(value_86, (uint64_t)(value_87.size));
compiler_backend_cache_HashInteger(value_86, (uint64_t)(value_87.modified));
compiler_backend_cache_HashInteger(value_86, (uint64_t)(value_87.modified_nanoseconds));
compiler_backend_cache_HashInteger(value_86, (uint64_t)(value_87.changed));
compiler_backend_cache_HashInteger(value_86, (uint64_t)(value_87.changed_nanoseconds));
}
HashState* value_88 = &(shared);
PathInfo value_89 = info;
{
HashState* value_91 = value_88;
PathInfo value_92 = value_89;
compiler_backend_cache_HashInteger(value_91, (uint64_t)(value_92.device_major));
compiler_backend_cache_HashInteger(value_91, (uint64_t)(value_92.device_minor));
compiler_backend_cache_HashInteger(value_91, value_92.inode);
compiler_backend_cache_HashInteger(value_91, (uint64_t)(value_92.mode));
compiler_backend_cache_HashInteger(value_91, (uint64_t)(value_92.size));
compiler_backend_cache_HashInteger(value_91, (uint64_t)(value_92.modified));
compiler_backend_cache_HashInteger(value_91, (uint64_t)(value_92.modified_nanoseconds));
compiler_backend_cache_HashInteger(value_91, (uint64_t)(value_92.changed));
compiler_backend_cache_HashInteger(value_91, (uint64_t)(value_92.changed_nanoseconds));
}
compiler_backend_cache_Release(compiler);
__type_131eebaaeb761e42 probe = compiler_backend_cache_Probe(arguments, piped);
__type_131eebaaeb761e42* value_93 = &probe;
Slice value_94 = {(probe).data, (probe).count};
Slice value_95 = SliceRangeAt(value_94, 0LL, probe.count, sizeof(*(probe).data));
String probe_text = StringView((const char *)(value_95).data, (size_t)(value_95).length);
String portable_probe = compiler_backend_cache_Normalized(cache, probe_text);
bool value_96 = probe.count == 0LL;
bool value_97 = value_96;
if (!value_97) {
bool value_98 = piped;
bool value_99 = value_98;
if (value_99) {
bool value_100 = compiler_backend_cache_HashProbeOutput(&(hash), probe_text);
bool value_101 = !value_100;
if (!value_101) {
bool value_102 = compiler_backend_cache_HashProbeOutput(&(shared), portable_probe);
value_101 = !value_102;
}
value_99 = value_101;
}
value_97 = value_99;
}
if (value_97) {
compiler_backend_cache_Release(portable_probe);
free((probe).data);
(probe).data = NULL;
probe.capacity = 0;
probe.count = 0;
compiler_backend_cache_Close(cache);
BuildCache* value_103 = (void *)0;
free((*value_93).data);
(*value_93).data = NULL;
(*value_93).capacity = 0;
(*value_93).count = 0;
return value_103;
}
compiler_backend_cache_Release(portable_probe);
bool value_104 = compiler_backend_cache_ParseProbe(cache, &(hash), &(shared), probe_text, piped);
if (!value_104) {
free((probe).data);
(probe).data = NULL;
probe.capacity = 0;
probe.count = 0;
compiler_backend_cache_Close(cache);
BuildCache* value_105 = (void *)0;
free((*value_93).data);
(*value_93).data = NULL;
(*value_93).capacity = 0;
(*value_93).count = 0;
return value_105;
}
free((probe).data);
(probe).data = NULL;
probe.capacity = 0;
probe.count = 0;
bool value_106 = compiler_backend_cache_AppendOwned(&(cache->roots), cache->output);
if (!value_106) {
compiler_backend_cache_Close(cache);
BuildCache* value_107 = (void *)0;
free((*value_93).data);
(*value_93).data = NULL;
(*value_93).capacity = 0;
(*value_93).count = 0;
return value_107;
}
compiler_backend_cache_HashFinish(&(hash), &(cache->identity));
compiler_backend_cache_HashFinish(&(shared), &(cache->shared));
compiler_backend_cache_StoreOpen(cache);
BuildCache* value_108 = cache;
free((*value_93).data);
(*value_93).data = NULL;
(*value_93).capacity = 0;
(*value_93).count = 0;
return value_108;
}
void
compiler_backend_cache_HashPair(BuildCache* cache, HashState* hash, HashState* shared, String value)
{
HashState* value_0 = hash;
String value_1 = value;
{
HashState* value_3 = value_0;
String value_4 = value_1;
compiler_backend_cache_HashInteger(value_3, (uint64_t)((int64_t)(value_4).length));
compiler_backend_cache_HashBytes(value_3, value_4);
}
String portable = compiler_backend_cache_Normalized(cache, value);
{
HashState* value_6 = shared;
String value_7 = portable;
compiler_backend_cache_HashInteger(value_6, (uint64_t)((int64_t)(value_7).length));
compiler_backend_cache_HashBytes(value_6, value_7);
}
compiler_backend_cache_Release(portable);
}
bool
compiler_backend_cache_DebugArguments(Slice arguments)
{
for (int64_t it_index = 0LL; it_index < (int64_t)(arguments).length; it_index++) {
String argument = ((String *)(arguments).data)[it_index];
String value_0 = StringLiteral("-g");
bool value_1 = false;
{
String value_3 = argument;
String value_4 = value_0;
value_1 = text_tools_TextHasPrefix(value_3, value_4);
}
if (value_1 && !StringEqual(argument, StringLiteral("-g0"))) {
return true;
}
}
return false;
}
bool
compiler_backend_cache_PathOption(String value)
{
String options[9] = {StringLiteral("-I"), StringLiteral("-isystem"), StringLiteral("-iquote"), StringLiteral("-idirafter"), StringLiteral("-include"), StringLiteral("-imacros"), StringLiteral("-isysroot"), StringLiteral("--sysroot"), StringLiteral("-B")};
for (int64_t it_index = 0LL; it_index < 9; it_index++) {
String option = (options)[it_index];
if (StringEqual(value, option)) {
return true;
}
}
return false;
}
bool
compiler_backend_cache_RelativeArguments(Slice arguments)
{
int64_t index = 1LL;
while (index < (int64_t)(arguments).length) {
String value = ((String *)(arguments).data)[index];
if (compiler_backend_cache_PairedArgument(value)) {
bool value_0 = compiler_backend_cache_PathOption(value);
bool value_1 = value_0 && (int64_t)((uint64_t)index + UINT64_C(1)) < (int64_t)(arguments).length;
if (value_1) {
String value_2 = ((String *)(arguments).data)[((int64_t)((uint64_t)index + UINT64_C(1)))];
String value_3 = StringLiteral("/");
bool value_4 = false;
{
String value_6 = value_2;
String value_7 = value_3;
value_4 = text_tools_TextHasPrefix(value_6, value_7);
}
value_1 = !value_4;
}
if (value_1) {
return true;
}
index = (int64_t)((uint64_t)index + UINT64_C(2));
continue;
}
String joined[4] = {StringLiteral("-I"), StringLiteral("-B"), StringLiteral("--sysroot="), StringLiteral("-fuse-ld=")};
for (int64_t it_index = 0LL; it_index < 4; it_index++) {
String prefix = (joined)[it_index];
String value_8 = value;
String value_9 = prefix;
bool value_10 = false;
{
String value_12 = value_8;
String value_13 = value_9;
value_10 = text_tools_TextHasPrefix(value_12, value_13);
}
bool value_14 = value_10 && (int64_t)(value).length > (int64_t)(prefix).length && (uint8_t)value.data[(int64_t)(prefix).length] != 47;
if (value_14 && !StringEqual(prefix, StringLiteral("-fuse-ld="))) {
return true;
}
}
if ((int64_t)(value).length > 0LL && (uint8_t)value.data[0] != 45 && (uint8_t)value.data[0] != 47) {
return true;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
return false;
}
int64_t
compiler_backend_cache_OutputLength(BuildCache* cache, String value, int64_t at)
{
String candidates[2] = {cache->output, cache->alias};
for (int64_t it_index = 0LL; it_index < 2; it_index++) {
String candidate = (candidates)[it_index];
if ((int64_t)(candidate).length == 0LL || (int64_t)((uint64_t)at + (uint64_t)((int64_t)(candidate).length)) > (int64_t)(value).length) {
continue;
}
if (!StringEqual(StringRangeAt(value, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + (uint64_t)((int64_t)(candidate).length)))), candidate)) {
continue;
}
int64_t end = (int64_t)((uint64_t)at + (uint64_t)((int64_t)(candidate).length));
bool value_0 = end == (int64_t)(value).length || (uint8_t)value.data[end] == 47;
bool value_1 = value_0 || text_tools_TextIsSpace((uint8_t)value.data[end]);
if (value_1 || (uint8_t)value.data[end] == 34 || (uint8_t)value.data[end] == 39) {
return (int64_t)(candidate).length;
}
}
return 0LL;
}
int64_t
compiler_backend_cache_NextCandidate(String value, String candidate, int64_t from, int64_t known)
{
if ((int64_t)(candidate).length == 0LL || known == -1LL || known >= from) {
int64_t value_0 = 0;
if ((int64_t)(candidate).length == 0LL) {
value_0 = -1LL;
} else {
value_0 = known;
}
return value_0;
}
return text_tools_TextFind(value, candidate, from);
}
String
compiler_backend_cache_Normalized(BuildCache* cache, String value)
{
if (!cache->portable) {
return compiler_backend_cache_Owned(value);
}
__type_131eebaaeb761e42 builder = {0};
__type_131eebaaeb761e42* value_0 = &builder;
int64_t start = 0LL;
int64_t at = 0LL;
int64_t output_at = -2LL;
int64_t alias_at = -2LL;
while (at < (int64_t)(value).length) {
String value_1 = value;
String value_2 = cache->output;
int64_t value_3 = 0;
{
String value_5 = value_1;
String value_6 = value_2;
int64_t value_7 = at;
int64_t value_8 = output_at;
if ((int64_t)(value_6).length == 0LL || value_8 == -1LL || value_8 >= value_7) {
int64_t value_9 = 0;
if ((int64_t)(value_6).length == 0LL) {
value_9 = -1LL;
} else {
value_9 = value_8;
}
value_3 = value_9;
goto value_4;
}
value_3 = text_tools_TextFind(value_5, value_6, value_7);
value_4: ;
}
output_at = value_3;
String value_10 = value;
String value_11 = cache->alias;
int64_t value_12 = 0;
{
String value_14 = value_10;
String value_15 = value_11;
int64_t value_16 = at;
int64_t value_17 = alias_at;
if ((int64_t)(value_15).length == 0LL || value_17 == -1LL || value_17 >= value_16) {
int64_t value_18 = 0;
if ((int64_t)(value_15).length == 0LL) {
value_18 = -1LL;
} else {
value_18 = value_17;
}
value_12 = value_18;
goto value_13;
}
value_12 = text_tools_TextFind(value_14, value_15, value_16);
value_13: ;
}
alias_at = value_12;
int64_t value_19 = 0;
if (output_at < 0LL || (alias_at >= 0LL && alias_at < output_at)) {
value_19 = alias_at;
} else {
value_19 = output_at;
}
int64_t next = value_19;
if (next < 0LL) {
break;
}
int64_t length = compiler_backend_cache_OutputLength(cache, value, next);
if (length == 0LL) {
at = (int64_t)((uint64_t)next + UINT64_C(1));
continue;
}
bool value_20 = false;
if ((StringRangeAt(value, (int64_t)start, (int64_t)next)).length == 0) {
value_20 = true;
} else {
void *value_21 = ZirVecReserve((void *)(builder).data, &(builder).capacity, (builder).count, (int64_t)(StringRangeAt(value, (int64_t)start, (int64_t)next)).length, sizeof(*(builder).data));
if (value_21 != NULL) {
(builder).data = (uint8_t *)value_21;
memcpy((builder).data + (builder).count, (StringRangeAt(value, (int64_t)start, (int64_t)next)).data, (size_t)(StringRangeAt(value, (int64_t)start, (int64_t)next)).length);
(builder).count += (int64_t)(StringRangeAt(value, (int64_t)start, (int64_t)next)).length;
value_20 = true;
}
}
bool value_22 = !value_20;
if (!value_22) {
bool value_23 = false;
if ((StringLiteral("\001output\001")).length == 0) {
value_23 = true;
} else {
void *value_24 = ZirVecReserve((void *)(builder).data, &(builder).capacity, (builder).count, (int64_t)(StringLiteral("\001output\001")).length, sizeof(*(builder).data));
if (value_24 != NULL) {
(builder).data = (uint8_t *)value_24;
memcpy((builder).data + (builder).count, (StringLiteral("\001output\001")).data, (size_t)(StringLiteral("\001output\001")).length);
(builder).count += (int64_t)(StringLiteral("\001output\001")).length;
value_23 = true;
}
}
value_22 = !value_23;
}
if (value_22) {
free((builder).data);
(builder).data = NULL;
builder.capacity = 0;
builder.count = 0;
String value_25 = StringLiteral("");
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_25;
}
at = (int64_t)((uint64_t)next + (uint64_t)length);
start = at;
}
bool value_26 = false;
if ((StringRangeAt(value, (int64_t)start, (int64_t)(int64_t)(value).length)).length == 0) {
value_26 = true;
} else {
void *value_27 = ZirVecReserve((void *)(builder).data, &(builder).capacity, (builder).count, (int64_t)(StringRangeAt(value, (int64_t)start, (int64_t)(int64_t)(value).length)).length, sizeof(*(builder).data));
if (value_27 != NULL) {
(builder).data = (uint8_t *)value_27;
memcpy((builder).data + (builder).count, (StringRangeAt(value, (int64_t)start, (int64_t)(int64_t)(value).length)).data, (size_t)(StringRangeAt(value, (int64_t)start, (int64_t)(int64_t)(value).length)).length);
(builder).count += (int64_t)(StringRangeAt(value, (int64_t)start, (int64_t)(int64_t)(value).length)).length;
value_26 = true;
}
}
if (!value_26) {
free((builder).data);
(builder).data = NULL;
builder.capacity = 0;
builder.count = 0;
String value_28 = StringLiteral("");
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_28;
}
Slice value_29 = {(builder).data, (builder).count};
Slice value_30 = SliceRangeAt(value_29, 0LL, builder.count, sizeof(*(builder).data));
String value_31 = vec_TextDetach(vec_TextCopy(StringView((const char *)(value_30).data, (size_t)(value_30).length)));
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_31;
}
String
compiler_backend_cache_Denormalized(BuildCache* cache, String value)
{
__type_131eebaaeb761e42 builder = {0};
__type_131eebaaeb761e42* value_0 = &builder;
int64_t start = 0LL;
int64_t at = text_tools_TextFind(value, StringLiteral("\001output\001"), 0LL);
while (at >= 0LL) {
bool value_1 = false;
if ((StringRangeAt(value, (int64_t)start, (int64_t)at)).length == 0) {
value_1 = true;
} else {
void *value_2 = ZirVecReserve((void *)(builder).data, &(builder).capacity, (builder).count, (int64_t)(StringRangeAt(value, (int64_t)start, (int64_t)at)).length, sizeof(*(builder).data));
if (value_2 != NULL) {
(builder).data = (uint8_t *)value_2;
memcpy((builder).data + (builder).count, (StringRangeAt(value, (int64_t)start, (int64_t)at)).data, (size_t)(StringRangeAt(value, (int64_t)start, (int64_t)at)).length);
(builder).count += (int64_t)(StringRangeAt(value, (int64_t)start, (int64_t)at)).length;
value_1 = true;
}
}
bool value_3 = !value_1;
if (!value_3) {
bool value_4 = false;
if ((cache->output).length == 0) {
value_4 = true;
} else {
void *value_5 = ZirVecReserve((void *)(builder).data, &(builder).capacity, (builder).count, (int64_t)(cache->output).length, sizeof(*(builder).data));
if (value_5 != NULL) {
(builder).data = (uint8_t *)value_5;
memcpy((builder).data + (builder).count, (cache->output).data, (size_t)(cache->output).length);
(builder).count += (int64_t)(cache->output).length;
value_4 = true;
}
}
value_3 = !value_4;
}
if (value_3) {
free((builder).data);
(builder).data = NULL;
builder.capacity = 0;
builder.count = 0;
String value_6 = StringLiteral("");
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_6;
}
start = (int64_t)((uint64_t)at + (uint64_t)((int64_t)(StringLiteral("\001output\001")).length));
at = text_tools_TextFind(value, StringLiteral("\001output\001"), start);
}
bool value_7 = false;
if ((StringRangeAt(value, (int64_t)start, (int64_t)(int64_t)(value).length)).length == 0) {
value_7 = true;
} else {
void *value_8 = ZirVecReserve((void *)(builder).data, &(builder).capacity, (builder).count, (int64_t)(StringRangeAt(value, (int64_t)start, (int64_t)(int64_t)(value).length)).length, sizeof(*(builder).data));
if (value_8 != NULL) {
(builder).data = (uint8_t *)value_8;
memcpy((builder).data + (builder).count, (StringRangeAt(value, (int64_t)start, (int64_t)(int64_t)(value).length)).data, (size_t)(StringRangeAt(value, (int64_t)start, (int64_t)(int64_t)(value).length)).length);
(builder).count += (int64_t)(StringRangeAt(value, (int64_t)start, (int64_t)(int64_t)(value).length)).length;
value_7 = true;
}
}
if (!value_7) {
free((builder).data);
(builder).data = NULL;
builder.capacity = 0;
builder.count = 0;
String value_9 = StringLiteral("");
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_9;
}
Slice value_10 = {(builder).data, (builder).count};
Slice value_11 = SliceRangeAt(value_10, 0LL, builder.count, sizeof(*(builder).data));
String value_12 = vec_TextDetach(vec_TextCopy(StringView((const char *)(value_11).data, (size_t)(value_11).length)));
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_12;
}
void
compiler_backend_cache_HashSnapshot(HashState* hash, PathInfo info)
{
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.device_major));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.device_minor));
compiler_backend_cache_HashInteger(hash, info.inode);
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.mode));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.size));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.modified));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.modified_nanoseconds));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.changed));
compiler_backend_cache_HashInteger(hash, (uint64_t)(info.changed_nanoseconds));
}
String
compiler_backend_cache_ToolFromLine(String line)
{
String value = text_tools_TextTrim(line);
if ((int64_t)(value).length == 0LL) {
return StringLiteral("");
}
if ((uint8_t)value.data[0] == 34) {
int64_t end = text_tools_TextFind(value, StringLiteral("\""), 1LL);
if (end < 0LL) {
return StringLiteral("");
}
return StringRangeAt(value, (int64_t)1LL, (int64_t)end);
}
int64_t at = 0LL;
while (true) {
bool value_0 = at < (int64_t)(value).length;
if (value_0) {
bool value_1 = text_tools_TextIsSpace((uint8_t)value.data[at]);
value_0 = !value_1;
}
if (!value_0) { break; }
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
return StringRangeAt(value, (int64_t)0LL, (int64_t)at);
}
bool
compiler_backend_cache_ParseProbe(BuildCache* cache, HashState* hash, HashState* shared, String text, bool piped)
{
__type_9f828aa1372cb21a programs = {0};
__type_9f828aa1372cb21a* value_0 = &programs;
bool searching = false;
bool ended = false;
int64_t tools = 0LL;
bool ok = true;
__type_9f828aa1372cb21a lines = text_tools_TextLines(text);
__type_9f828aa1372cb21a* value_1 = &lines;
for (int64_t it_index = 0LL; it_index < lines.count; it_index++) {
String line = (lines).data[it_index];
if (!ok) {
break;
}
String value_2 = StringLiteral("COLLECT_GCC=");
bool value_3 = false;
{
String value_5 = line;
String value_6 = value_2;
value_3 = text_tools_TextHasPrefix(value_5, value_6);
}
if (value_3) {
String resolved = compiler_backend_cache_Executable(StringRangeAt(line, (int64_t)12LL, (int64_t)(int64_t)(line).length));
if ((int64_t)(resolved).length == 0LL) {
ok = false;
} else {
PathInfo value_7 = file_tree_linux_PathStatus(resolved, true);
if (((PathKind)(value_7.kind)) != ((PathKind)(1))) {
ok = false;
} else {
bool value_8 = compiler_backend_cache_AppendOwned(&(programs), resolved);
if (!value_8) {
ok = false;
}
}
}
compiler_backend_cache_Release(resolved);
} else {
String value_9 = StringLiteral("#include ");
bool value_10 = false;
{
String value_12 = line;
String value_13 = value_9;
value_10 = text_tools_TextHasPrefix(value_12, value_13);
}
if (value_10) {
searching = true;
} else if (StringEqual(line, StringLiteral("End of search list."))) {
searching = false;
ended = true;
} else if (searching && (int64_t)(line).length > 0LL && (uint8_t)line.data[0] == 32) {
String path = text_tools_TextTrim(line);
int64_t framework = text_tools_TextFind(path, StringLiteral(" (framework directory)"), 0LL);
if (framework >= 0LL) {
path = StringRangeAt(path, (int64_t)0LL, (int64_t)framework);
}
bool value_14 = piped;
bool value_15 = value_14;
if (value_15) {
PathInfo value_16 = file_tree_linux_PathStatus(path, true);
value_15 = (((PathKind)(value_16.kind)) != ((PathKind)(2)));
}
if (value_15) {
ok = false;
}
bool value_17 = ok;
if (value_17 && compiler_backend_cache_AppendOwned(&(cache->roots), path)) {
BuildCache* value_18 = cache;
HashState* value_19 = hash;
HashState* value_20 = shared;
{
BuildCache* value_22 = value_18;
HashState* value_23 = value_19;
HashState* value_24 = value_20;
String value_25 = path;
{
HashState* value_27 = value_23;
String value_28 = value_25;
compiler_backend_cache_HashInteger(value_27, (uint64_t)((int64_t)(value_28).length));
compiler_backend_cache_HashBytes(value_27, value_28);
}
String value_29 = compiler_backend_cache_Normalized(value_22, value_25);
{
HashState* value_31 = value_24;
String value_32 = value_29;
compiler_backend_cache_HashInteger(value_31, (uint64_t)((int64_t)(value_32).length));
compiler_backend_cache_HashBytes(value_31, value_32);
}
compiler_backend_cache_Release(value_29);
}
} else {
ok = false;
}
} else {
bool value_33 = searching && piped;
bool value_34 = value_33;
if (value_34) {
String value_35 = StringLiteral("GNU assembler version ");
bool value_36 = false;
{
String value_38 = line;
String value_39 = value_35;
value_36 = text_tools_TextHasPrefix(value_38, value_39);
}
value_34 = value_36;
}
bool value_40 = value_34;
bool value_41 = value_40;
if (value_41) {
String value_42 = StringLiteral(" using BFD version ");
bool value_43 = false;
{
String value_45 = line;
String value_46 = value_42;
value_43 = text_tools_TextContains(value_45, value_46);
}
value_41 = value_43;
}
if (value_41) {
} else if (searching && piped) {
ok = false;
} else {
String value_47 = StringLiteral("ignoring nonexistent directory \"");
bool value_48 = false;
{
String value_50 = line;
String value_51 = value_47;
value_48 = text_tools_TextHasPrefix(value_50, value_51);
}
if (value_48) {
int64_t first = text_tools_TextFind(line, StringLiteral("\""), 0LL);
int64_t last = text_tools_TextFindLast(line, StringLiteral("\""));
if (first >= 0LL && last > first) {
String path = StringRangeAt(line, (int64_t)((int64_t)((uint64_t)first + UINT64_C(1))), (int64_t)last);
if (compiler_backend_cache_AppendOwned(&(cache->roots), path)) {
BuildCache* value_52 = cache;
HashState* value_53 = hash;
HashState* value_54 = shared;
{
BuildCache* value_56 = value_52;
HashState* value_57 = value_53;
HashState* value_58 = value_54;
String value_59 = path;
{
HashState* value_61 = value_57;
String value_62 = value_59;
compiler_backend_cache_HashInteger(value_61, (uint64_t)((int64_t)(value_62).length));
compiler_backend_cache_HashBytes(value_61, value_62);
}
String value_63 = compiler_backend_cache_Normalized(value_56, value_59);
{
HashState* value_65 = value_58;
String value_66 = value_63;
compiler_backend_cache_HashInteger(value_65, (uint64_t)((int64_t)(value_66).length));
compiler_backend_cache_HashBytes(value_65, value_66);
}
compiler_backend_cache_Release(value_63);
}
} else {
ok = false;
}
}
} else if (StringEqual(line, StringLiteral(" (in-process)"))) {
} else {
bool value_67 = (int64_t)(line).length > 1LL && (uint8_t)line.data[0] == 32;
bool value_68 = value_67;
if (value_68) {
bool value_69 = text_tools_TextIsSpace((uint8_t)line.data[1]);
value_68 = !value_69;
}
if (value_68) {
String tool = compiler_backend_cache_ToolFromLine(line);
if ((int64_t)(tool).length > 0LL) {
String resolved = compiler_backend_cache_Executable(tool);
if ((int64_t)(resolved).length == 0LL) {
ok = false;
} else {
bool value_70 = compiler_backend_cache_NativeImage(resolved);
if (!value_70) {
ok = false;
} else {
PathInfo value_71 = file_tree_linux_PathStatus(resolved, true);
if (((PathKind)(value_71.kind)) != ((PathKind)(1))) {
ok = false;
} else if (compiler_backend_cache_AppendOwned(&(programs), resolved)) {
tools = (int64_t)((uint64_t)tools + UINT64_C(1));
} else {
ok = false;
}
}
}
compiler_backend_cache_Release(resolved);
}
} else {
bool value_72 = !piped;
bool value_73 = value_72;
if (value_73) {
String value_74 = StringLiteral("Compiler executable checksum:");
bool value_75 = false;
{
String value_77 = line;
String value_78 = value_74;
value_75 = text_tools_TextHasPrefix(value_77, value_78);
}
bool value_79 = value_75;
if (!value_79) {
String value_80 = StringLiteral(" version ");
bool value_81 = false;
{
String value_83 = line;
String value_84 = value_80;
value_81 = text_tools_TextContains(value_83, value_84);
}
value_79 = value_81;
}
value_73 = value_79;
}
if (value_73) {
BuildCache* value_85 = cache;
HashState* value_86 = hash;
HashState* value_87 = shared;
{
BuildCache* value_89 = value_85;
HashState* value_90 = value_86;
HashState* value_91 = value_87;
String value_92 = line;
{
HashState* value_94 = value_90;
String value_95 = value_92;
compiler_backend_cache_HashInteger(value_94, (uint64_t)((int64_t)(value_95).length));
compiler_backend_cache_HashBytes(value_94, value_95);
}
String value_96 = compiler_backend_cache_Normalized(value_89, value_92);
{
HashState* value_98 = value_91;
String value_99 = value_96;
compiler_backend_cache_HashInteger(value_98, (uint64_t)((int64_t)(value_99).length));
compiler_backend_cache_HashBytes(value_98, value_99);
}
compiler_backend_cache_Release(value_96);
}
}
}
}
}
}
}
}
free((lines).data);
(lines).data = NULL;
lines.capacity = 0;
lines.count = 0;
if (!ok) {
compiler_backend_cache_ClearNames(&(programs));
bool value_100 = false;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_100;
}
if (!ended) {
compiler_backend_cache_ClearNames(&(programs));
bool value_101 = false;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_101;
}
if (tools < 1LL) {
compiler_backend_cache_ClearNames(&(programs));
bool value_102 = false;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_102;
}
if (piped && tools < 2LL) {
compiler_backend_cache_ClearNames(&(programs));
bool value_103 = false;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_103;
}
Slice value_104 = {(programs).data, (programs).count};
sort_SortText(SliceRangeAt(value_104, 0LL, programs.count, sizeof(*(programs).data)));
compiler_backend_cache_HashInteger(hash, (uint64_t)(programs.count));
compiler_backend_cache_HashInteger(shared, (uint64_t)(programs.count));
{
int64_t range_first_112 = 0LL;
int64_t range_last_112 = (int64_t)((uint64_t)(programs.count) - UINT64_C(1));
int64_t index = range_first_112;
if (index <= range_last_112) for (;;) {
String path = (programs).data[index];
PathInfo info = file_tree_linux_PathStatus(path, true);
if (((PathKind)(info.kind)) != ((PathKind)(1))) {
compiler_backend_cache_ClearNames(&(programs));
bool value_105 = false;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_105;
}
HashState* value_106 = hash;
{
HashState* value_108 = value_106;
String value_109 = path;
compiler_backend_cache_HashInteger(value_108, (uint64_t)((int64_t)(value_109).length));
compiler_backend_cache_HashBytes(value_108, value_109);
}
{
HashState* value_111 = shared;
String value_112 = path;
compiler_backend_cache_HashInteger(value_111, (uint64_t)((int64_t)(value_112).length));
compiler_backend_cache_HashBytes(value_111, value_112);
}
HashState* value_113 = hash;
PathInfo value_114 = info;
{
HashState* value_116 = value_113;
PathInfo value_117 = value_114;
compiler_backend_cache_HashInteger(value_116, (uint64_t)(value_117.device_major));
compiler_backend_cache_HashInteger(value_116, (uint64_t)(value_117.device_minor));
compiler_backend_cache_HashInteger(value_116, value_117.inode);
compiler_backend_cache_HashInteger(value_116, (uint64_t)(value_117.mode));
compiler_backend_cache_HashInteger(value_116, (uint64_t)(value_117.size));
compiler_backend_cache_HashInteger(value_116, (uint64_t)(value_117.modified));
compiler_backend_cache_HashInteger(value_116, (uint64_t)(value_117.modified_nanoseconds));
compiler_backend_cache_HashInteger(value_116, (uint64_t)(value_117.changed));
compiler_backend_cache_HashInteger(value_116, (uint64_t)(value_117.changed_nanoseconds));
}
PathInfo value_118 = info;
{
HashState* value_120 = shared;
PathInfo value_121 = value_118;
compiler_backend_cache_HashInteger(value_120, (uint64_t)(value_121.device_major));
compiler_backend_cache_HashInteger(value_120, (uint64_t)(value_121.device_minor));
compiler_backend_cache_HashInteger(value_120, value_121.inode);
compiler_backend_cache_HashInteger(value_120, (uint64_t)(value_121.mode));
compiler_backend_cache_HashInteger(value_120, (uint64_t)(value_121.size));
compiler_backend_cache_HashInteger(value_120, (uint64_t)(value_121.modified));
compiler_backend_cache_HashInteger(value_120, (uint64_t)(value_121.modified_nanoseconds));
compiler_backend_cache_HashInteger(value_120, (uint64_t)(value_121.changed));
compiler_backend_cache_HashInteger(value_120, (uint64_t)(value_121.changed_nanoseconds));
}
if (index == range_last_112) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
compiler_backend_cache_ClearNames(&(programs));
__type_9f828aa1372cb21a resolved_roots = {0};
__type_9f828aa1372cb21a* value_122 = &resolved_roots;
{
Slice value_123 = {(cache->roots).data, (cache->roots).count};
Slice value_124 = SliceRangeAt(value_123, 0LL, cache->roots.count, sizeof(*(cache->roots).data));
Slice loop_view_126 = value_124;
int64_t loop_count_126 = (int64_t)(loop_view_126).length;
int64_t loop_cursor_126 = 0LL;
while (loop_cursor_126 < loop_count_126) {
int64_t loop_index_126 = loop_cursor_126;
String root = ((String *)(loop_view_126).data)[loop_index_126];
String resolved = compiler_backend_cache_Resolved(root);
if ((int64_t)(resolved).length > 0LL) {
bool value_125 = compiler_backend_cache_AppendOwned(&(resolved_roots), resolved);
if (!value_125) {
compiler_backend_cache_Release(resolved);
compiler_backend_cache_ClearNames(&(resolved_roots));
bool value_126 = false;
free((*value_122).data);
(*value_122).data = NULL;
(*value_122).capacity = 0;
(*value_122).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_126;
}
} else {
bool value_127 = compiler_backend_cache_AppendOwned(&(resolved_roots), root);
if (!value_127) {
compiler_backend_cache_ClearNames(&(resolved_roots));
bool value_128 = false;
free((*value_122).data);
(*value_122).data = NULL;
(*value_122).capacity = 0;
(*value_122).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_128;
}
}
compiler_backend_cache_Release(resolved);
loop_cursor_126 = (int64_t)((uint64_t)loop_cursor_126 + UINT64_C(1));
}
}
__type_9f828aa1372cb21a value_129 = resolved_roots;
resolved_roots = cache->roots;
cache->roots = value_129;
free((resolved_roots).data);
(resolved_roots).data = NULL;
resolved_roots.capacity = 0;
resolved_roots.count = 0;
bool value_130 = true;
free((*value_122).data);
(*value_122).data = NULL;
(*value_122).capacity = 0;
(*value_122).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_130;
}
String
compiler_backend_cache_OutputRelative(BuildCache* cache, String path)
{
String candidates[2] = {cache->output, cache->alias};
for (int64_t it_index = 0LL; it_index < 2; it_index++) {
String candidate = (candidates)[it_index];
bool value_0 = (int64_t)(candidate).length > 0LL && (int64_t)(path).length > (int64_t)((uint64_t)((int64_t)(candidate).length) + UINT64_C(1));
bool value_1 = value_0;
if (value_1) {
bool value_2 = false;
{
String value_4 = path;
String value_5 = candidate;
value_2 = text_tools_TextHasPrefix(value_4, value_5);
}
value_1 = value_2;
}
if (value_1 && (uint8_t)path.data[(int64_t)(candidate).length] == 47) {
return StringRangeAt(path, (int64_t)((int64_t)((uint64_t)((int64_t)(candidate).length) + UINT64_C(1))), (int64_t)(int64_t)(path).length);
}
}
return path;
}
bool
compiler_backend_cache_SpellingKey(BuildCache* cache, HashState* hash, String written, __type_9f828aa1372cb21a* parents, bool* recordable)
{
String spelling = compiler_backend_cache_OutputRelative(cache, written);
int64_t item = compiler_backend_cache_SpellingDigest(cache, spelling, StringLiteral(""));
if (item < 0LL) {
return false;
}
HashState* value_0 = hash;
Slice value_1 = {((ZIRAN_VEC_INDEX((cache->candidates).data, (cache->candidates).count, item)).digest).bytes, 32};
Slice value_2 = value_1;
compiler_backend_cache_HashBytes(value_0, StringView((const char *)(value_2).data, (size_t)(value_2).length));
if (((cache->candidates).data[item]).recent) {
bool* value_3 = &((*(recordable)));
(*value_3) = false;
}
__type_9f828aa1372cb21a parent_values = {0};
__type_9f828aa1372cb21a* value_4 = &parent_values;
__type_9f828aa1372cb21a value_5 = parent_values;
parent_values = (*(parents));
(*(parents)) = value_5;
for (int64_t it_index = 0LL; it_index < parent_values.count; it_index++) {
String parent = (parent_values).data[it_index];
int64_t value_6 = compiler_backend_cache_SpellingDigest(cache, spelling, parent);
if (value_6 < 0LL) {
__type_9f828aa1372cb21a value_7 = parent_values;
parent_values = (*(parents));
(*(parents)) = value_7;
bool value_8 = false;
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
return value_8;
}
HashState* value_9 = hash;
Slice value_10 = {((ZIRAN_VEC_INDEX((cache->candidates).data, (cache->candidates).count, value_6)).digest).bytes, 32};
Slice value_11 = value_10;
compiler_backend_cache_HashBytes(value_9, StringView((const char *)(value_11).data, (size_t)(value_11).length));
if (((cache->candidates).data[value_6]).recent) {
bool* value_12 = &((*(recordable)));
(*value_12) = false;
}
}
__type_9f828aa1372cb21a value_13 = parent_values;
parent_values = (*(parents));
(*(parents)) = value_13;
bool value_14 = true;
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
return value_14;
}
bool
compiler_backend_cache_LookupDigest(BuildCache* cache, __type_9f828aa1372cb21a* dependencies, Digest* output, bool recording)
{
__type_9f828aa1372cb21a parents = {0};
__type_9f828aa1372cb21a* value_0 = &parents;
__type_9f828aa1372cb21a pending = {0};
__type_9f828aa1372cb21a* value_1 = &pending;
__type_9f828aa1372cb21a value_2 = pending;
pending = (*(dependencies));
(*(dependencies)) = value_2;
HashState hash = compiler_backend_cache_HashNew();
bool recordable = true;
bool ok = true;
for (int64_t it_index = 0LL; it_index < pending.count; it_index++) {
String dependency = (pending).data[it_index];
BuildCache* value_3 = cache;
int64_t value_4 = 0;
{
BuildCache* value_6 = value_3;
String value_7 = dependency;
bool value_8 = false;
if (value_8) {
value_4 = compiler_backend_cache_IndexFind(&(value_6->candidate_index), &(value_6->candidates), value_7);
goto value_5;
}
value_4 = compiler_backend_cache_IndexFind(&(value_6->file_index), &(value_6->files), value_7);
value_5: ;
}
int64_t item = value_4;
if (item < 0LL) {
ok = false;
break;
}
int64_t value_9 = (int64_t)(((cache->files).data[item]).parent).length;
if (value_9 == 0LL) {
String resolved = compiler_backend_cache_Resolved(dependency);
bool value_10 = (int64_t)(resolved).length > 0LL;
if (value_10) {
String value_11 = StringLiteral("/.objects/");
bool value_12 = false;
{
String value_14 = resolved;
String value_15 = value_11;
value_12 = text_tools_TextContains(value_14, value_15);
}
value_10 = !value_12;
}
if (value_10) {
int64_t slash = text_tools_TextFindLast(resolved, StringLiteral("/"));
if (slash > 0LL) {
String directory = compiler_backend_cache_Owned(StringRangeAt(resolved, (int64_t)0LL, (int64_t)slash));
String* value_16 = &((ZIRAN_VEC_INDEX((cache->files).data, (cache->files).count, item)).parent);
(*value_16) = directory;
}
}
compiler_backend_cache_Release(resolved);
}
int64_t value_17 = (int64_t)(((cache->files).data[item]).parent).length;
bool value_18 = value_17 == 0LL;
bool value_19 = value_18;
if (!value_19) {
bool value_20 = compiler_backend_cache_AppendOwned(&(parents), ((cache->files).data[item]).parent);
value_19 = !value_20;
}
if (value_19) {
ok = false;
break;
}
}
for (int64_t it_index = 0LL; it_index < pending.count; it_index++) {
String dependency = (pending).data[it_index];
if (!ok) {
break;
}
BuildCache* value_21 = cache;
int64_t value_22 = 0;
{
BuildCache* value_24 = value_21;
String value_25 = dependency;
bool value_26 = false;
if (value_26) {
value_22 = compiler_backend_cache_IndexFind(&(value_24->candidate_index), &(value_24->candidates), value_25);
goto value_23;
}
value_22 = compiler_backend_cache_IndexFind(&(value_24->file_index), &(value_24->files), value_25);
value_23: ;
}
int64_t item = value_22;
bool value_27 = item < 0LL;
if (!value_27) {
bool value_28 = compiler_backend_cache_SpellingKey(cache, &(hash), dependency, &(parents), &(recordable));
value_27 = !value_28;
}
if (value_27) {
ok = false;
break;
}
{
int64_t range_first_37 = 0LL;
int64_t range_last_37 = (int64_t)((uint64_t)((((cache->files).data[item]).probes).count) - UINT64_C(1));
int64_t probe_index = range_first_37;
if (probe_index <= range_last_37) for (;;) {
String probe = (((cache->files).data[item]).probes).data[probe_index];
bool value_29 = compiler_backend_cache_SpellingKey(cache, &(hash), probe, &(parents), &(recordable));
if (!value_29) {
ok = false;
break;
}
if (probe_index == range_last_37) {
break;
}
probe_index = (int64_t)((uint64_t)probe_index + UINT64_C(1));
}
}
}
__type_9f828aa1372cb21a value_30 = pending;
pending = (*(dependencies));
(*(dependencies)) = value_30;
compiler_backend_cache_ClearNames(&(parents));
if (ok) {
compiler_backend_cache_HashFinish(&(hash), output);
}
bool value_31 = ok && (!recording || recordable);
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_31;
}
bool
compiler_backend_cache_ReadDependencies(String object, __type_9f828aa1372cb21a* dependencies)
{
String path = compiler_backend_cache_JoinTemporary(object, StringLiteral(".d"));
if ((int64_t)(path).length == 0LL) {
return false;
}
__type_131eebaaeb761e42 bytes = {0};
__type_131eebaaeb761e42* value_0 = &bytes;
bool value_1 = file_ReadFileInto(path, &(bytes));
if (!value_1) {
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
bool cleanup_return_0 = false;
{
compiler_backend_cache_Release(path);
}
bool value_2 = cleanup_return_0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_2;
}
Slice value_3 = {(bytes).data, (bytes).count};
Slice value_4 = SliceRangeAt(value_3, 0LL, bytes.count, sizeof(*(bytes).data));
String text = StringView((const char *)(value_4).data, (size_t)(value_4).length);
int64_t colon = text_tools_TextFind(text, StringLiteral(":"), 0LL);
if (colon < 0LL) {
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
bool cleanup_return_1 = false;
{
compiler_backend_cache_Release(path);
}
bool value_5 = cleanup_return_1;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_5;
}
int64_t at = (int64_t)((uint64_t)colon + UINT64_C(1));
__type_131eebaaeb761e42 word = {0};
__type_131eebaaeb761e42* value_6 = &word;
bool ok = true;
while (at <= (int64_t)(text).length) {
uint8_t value_7 = 0;
if (at < (int64_t)(text).length) {
value_7 = (uint8_t)text.data[at];
} else {
value_7 = 32;
}
uint8_t byte = value_7;
if (byte == 92 && (int64_t)((uint64_t)at + UINT64_C(1)) < (int64_t)(text).length) {
uint8_t next = (uint8_t)text.data[((int64_t)((uint64_t)at + UINT64_C(1)))];
if (next == 10) {
at = (int64_t)((uint64_t)at + UINT64_C(2));
continue;
}
if (next == 32 || next == 9 || next == 35 || next == 92) {
uint8_t value_8 = next;
bool value_9 = false;
void *value_10 = ZirVecGrow((void *)(word).data, &(word).capacity, (word).count, sizeof(*(word).data));
if (value_10 != NULL) {
(word).data = value_10;
(word).data[(word).count++] = value_8;
value_9 = true;
}
if (!value_9) {
ok = false;
break;
}
at = (int64_t)((uint64_t)at + UINT64_C(2));
continue;
}
} else if (byte == 36) {
if ((int64_t)((uint64_t)at + UINT64_C(1)) >= (int64_t)(text).length || (uint8_t)text.data[((int64_t)((uint64_t)at + UINT64_C(1)))] != 36) {
ok = false;
break;
}
uint8_t value_11 = byte;
bool value_12 = false;
void *value_13 = ZirVecGrow((void *)(word).data, &(word).capacity, (word).count, sizeof(*(word).data));
if (value_13 != NULL) {
(word).data = value_13;
(word).data[(word).count++] = value_11;
value_12 = true;
}
if (!value_12) {
ok = false;
break;
}
at = (int64_t)((uint64_t)at + UINT64_C(2));
continue;
}
if (text_tools_TextIsSpace(byte)) {
if (word.count > 0LL) {
Slice value_14 = {(word).data, (word).count};
Slice value_15 = SliceRangeAt(value_14, 0LL, word.count, sizeof(*(word).data));
String owned = compiler_backend_cache_Owned(StringView((const char *)(value_15).data, (size_t)(value_15).length));
if ((int64_t)(owned).length == 0LL) {
ok = false;
} else {
String value_16 = owned;
bool value_17 = false;
void *value_18 = ZirVecGrow((void *)((*(dependencies))).data, &((*(dependencies))).capacity, ((*(dependencies))).count, sizeof(*((*(dependencies))).data));
if (value_18 != NULL) {
((*(dependencies))).data = value_18;
((*(dependencies))).data[((*(dependencies))).count++] = value_16;
value_17 = true;
}
if (!value_17) {
compiler_backend_cache_Release(owned);
ok = false;
}
}
if (!ok) {
break;
}
word.count = 0;
}
if (byte == 10) {
break;
}
} else {
uint8_t value_19 = byte;
bool value_20 = false;
void *value_21 = ZirVecGrow((void *)(word).data, &(word).capacity, (word).count, sizeof(*(word).data));
if (value_21 != NULL) {
(word).data = value_21;
(word).data[(word).count++] = value_19;
value_20 = true;
}
if (!value_20) {
ok = false;
break;
}
}
at = (int64_t)((uint64_t)at + UINT64_C(1));
}
free((word).data);
(word).data = NULL;
word.capacity = 0;
word.count = 0;
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
bool value_22 = ok;
if (value_22) {
int64_t value_23 = dependencies->count;
value_22 = (value_23 > 0LL);
}
bool cleanup_return_2 = value_22;
{
compiler_backend_cache_Release(path);
}
bool value_24 = cleanup_return_2;
free((*value_6).data);
(*value_6).data = NULL;
(*value_6).capacity = 0;
(*value_6).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_24;
}
bool
compiler_backend_cache_ReadInteger(Slice bytes, int64_t* offset, uint32_t* output)
{
int64_t value_0 = (int64_t)((uint64_t)(*(offset)) + UINT64_C(4));
int64_t value_1 = (int64_t)(bytes).length;
if (value_0 > value_1) {
return false;
}
uint32_t value = 0;
for (int64_t index = 0LL; index <= 3LL; index++) {
uint32_t value_2 = ZiShl32((uint32_t)(((uint8_t *)(bytes).data)[((int64_t)((uint64_t)(*(offset)) + (uint64_t)index))]), (uint64_t)((uint32_t)(((int64_t)(UINT64_C(8) * (uint64_t)index)))), 32);
value = (uint32_t)((uint32_t)value | (uint32_t)value_2);
}
int64_t* value_3 = &((*(offset)));
(*value_3) = (int64_t)((uint64_t)((*value_3)) + UINT64_C(4));
uint32_t* value_4 = &((*(output)));
(*value_4) = value;
return true;
}
bool
compiler_backend_cache_ReadDigest(Slice bytes, int64_t* offset, Digest* output)
{
int64_t value_0 = (int64_t)((uint64_t)(*(offset)) + UINT64_C(32));
int64_t value_1 = (int64_t)(bytes).length;
if (value_0 > value_1) {
return false;
}
for (int64_t index = 0LL; index <= 31LL; index++) {
uint8_t* value_2 = &(output->bytes[index]);
(*value_2) = ((uint8_t *)(bytes).data)[((int64_t)((uint64_t)(*(offset)) + (uint64_t)index))];
}
int64_t* value_3 = &((*(offset)));
(*value_3) = (int64_t)((uint64_t)((*value_3)) + UINT64_C(32));
return true;
}
bool
compiler_backend_cache_SameDigest(Digest left, Digest right)
{
for (int64_t index = 0LL; index <= 31LL; index++) {
if ((left.bytes)[index] != (right.bytes)[index]) {
return false;
}
}
return true;
}
bool
compiler_backend_cache_Piped(BuildCache* cache)
{
return cache != ((void *)0) && cache->piped;
}
bool
compiler_backend_cache_Hit(BuildCache* cache, String object)
{
if (cache == ((void *)0)) {
return false;
}
String path = compiler_backend_cache_JoinTemporary(object, StringLiteral(".inputs"));
if ((int64_t)(path).length == 0LL) {
return false;
}
__type_131eebaaeb761e42 bytes = {0};
__type_131eebaaeb761e42* value_0 = &bytes;
bool value_1 = file_ReadFileInto(path, &(bytes));
if (!value_1) {
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
bool cleanup_return_0 = false;
{
compiler_backend_cache_Release(path);
}
bool value_2 = cleanup_return_0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_2;
}
Slice value_3 = {(bytes).data, (bytes).count};
Slice value_4 = SliceRangeAt(value_3, 0LL, bytes.count, sizeof(*(bytes).data));
String data = StringView((const char *)(value_4).data, (size_t)(value_4).length);
int64_t at = 0LL;
if ((int64_t)(data).length < 16LL || !StringEqual(StringRangeAt(data, (int64_t)0LL, (int64_t)16LL), StringLiteral("Ziran C cache 1\n"))) {
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
bool cleanup_return_1 = false;
{
compiler_backend_cache_Release(path);
}
bool value_5 = cleanup_return_1;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_5;
}
at = 16LL;
Digest identity = {0};
Digest object_digest = {0};
Digest lookup = {0};
uint32_t count = 0;
Slice value_6 = {(bytes).data, (bytes).count};
bool value_7 = compiler_backend_cache_ReadDigest(SliceRangeAt(value_6, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(identity));
bool value_8 = value_7;
if (value_8) {
Slice value_9 = {(bytes).data, (bytes).count};
bool value_10 = compiler_backend_cache_ReadDigest(SliceRangeAt(value_9, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(object_digest));
value_8 = value_10;
}
bool value_11 = value_8;
if (value_11) {
Slice value_12 = {(bytes).data, (bytes).count};
bool value_13 = compiler_backend_cache_ReadDigest(SliceRangeAt(value_12, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(lookup));
value_11 = value_13;
}
bool value_14 = value_11;
if (value_14) {
Slice value_15 = {(bytes).data, (bytes).count};
bool value_16 = compiler_backend_cache_ReadInteger(SliceRangeAt(value_15, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(count));
value_14 = value_16;
}
bool ok = value_14 && count > 0 && count <= 16384;
if (ok) {
ok = compiler_backend_cache_SameDigest(identity, cache->identity);
}
__type_9f828aa1372cb21a dependencies = {0};
__type_9f828aa1372cb21a* value_17 = &dependencies;
if (ok) {
int64_t compiled = compiler_backend_cache_FileDigest(cache, object);
bool value_18 = compiled < 0LL;
if (!value_18) {
bool value_19 = compiler_backend_cache_SameDigest(((cache->files).data[compiled]).digest, object_digest);
value_18 = !value_19;
}
if (value_18) {
ok = false;
}
}
{
int64_t range_first_42 = 0LL;
int64_t range_last_42 = (int64_t)((uint64_t)(count) - UINT64_C(1));
int64_t index = range_first_42;
if (index <= range_last_42) for (;;) {
if (!ok) {
break;
}
uint32_t length = 0;
Slice value_20 = {(bytes).data, (bytes).count};
bool value_21 = compiler_backend_cache_ReadInteger(SliceRangeAt(value_20, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(length));
if (!value_21 || length == 0 || (int64_t)((uint64_t)at + (uint64_t)(length)) > (int64_t)(data).length) {
ok = false;
break;
}
String dependency = StringRangeAt(data, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + (uint64_t)(length))));
at = (int64_t)((uint64_t)at + (uint64_t)(length));
Digest saved = {0};
String value_22 = StringLiteral("\000");
bool value_23 = false;
{
String value_25 = dependency;
String value_26 = value_22;
value_23 = text_tools_TextContains(value_25, value_26);
}
bool value_27 = value_23;
if (!value_27) {
Slice value_28 = {(bytes).data, (bytes).count};
bool value_29 = compiler_backend_cache_ReadDigest(SliceRangeAt(value_28, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(saved));
value_27 = !value_29;
}
if (value_27) {
ok = false;
break;
}
int64_t item = compiler_backend_cache_FileDigest(cache, dependency);
bool value_30 = item < 0LL || ((cache->files).data[item]).unsafe;
bool value_31 = value_30;
if (!value_31) {
bool value_32 = compiler_backend_cache_SameDigest(((cache->files).data[item]).digest, saved);
value_31 = !value_32;
}
bool value_33 = value_31;
bool value_34 = value_33;
if (!value_34) {
bool value_35 = compiler_backend_cache_AppendOwned(&(dependencies), dependency);
value_34 = !value_35;
}
if (value_34) {
ok = false;
break;
}
if (index == range_last_42) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
if (ok) {
Digest current = {0};
bool value_36 = at == (int64_t)(data).length;
bool value_37 = value_36 && compiler_backend_cache_LookupDigest(cache, &(dependencies), &(current), false);
bool value_38 = value_37;
ok = value_38 && compiler_backend_cache_SameDigest(current, lookup);
}
compiler_backend_cache_ClearNames(&(dependencies));
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
bool cleanup_return_2 = ok;
{
compiler_backend_cache_Release(path);
}
bool value_39 = cleanup_return_2;
free((*value_17).data);
(*value_17).data = NULL;
(*value_17).capacity = 0;
(*value_17).count = 0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_39;
}
bool
compiler_backend_cache_AppendBytes(__type_131eebaaeb761e42* output, Slice bytes)
{
for (int64_t it_index = 0LL; it_index < (int64_t)(bytes).length; it_index++) {
uint8_t byte = ((uint8_t *)(bytes).data)[it_index];
uint8_t value_0 = byte;
bool value_1 = false;
void *value_2 = ZirVecGrow((void *)((*(output))).data, &((*(output))).capacity, ((*(output))).count, sizeof(*((*(output))).data));
if (value_2 != NULL) {
((*(output))).data = value_2;
((*(output))).data[((*(output))).count++] = value_0;
value_1 = true;
}
if (!value_1) {
return false;
}
}
return true;
}
bool
compiler_backend_cache_AppendText(__type_131eebaaeb761e42* output, String value)
{
for (int64_t it_index = 0LL; it_index < (int64_t)(value).length; it_index++) {
uint8_t byte = (uint8_t)value.data[it_index];
uint8_t value_0 = byte;
bool value_1 = false;
void *value_2 = ZirVecGrow((void *)((*(output))).data, &((*(output))).capacity, ((*(output))).count, sizeof(*((*(output))).data));
if (value_2 != NULL) {
((*(output))).data = value_2;
((*(output))).data[((*(output))).count++] = value_0;
value_1 = true;
}
if (!value_1) {
return false;
}
}
return true;
}
bool
compiler_backend_cache_AppendDigest(__type_131eebaaeb761e42* output, Digest value)
{
Slice value_0 = {value.bytes, 32};
return compiler_backend_cache_AppendBytes(output, value_0);
}
bool
compiler_backend_cache_AppendCount(__type_131eebaaeb761e42* output, uint32_t value)
{
uint8_t bytes[4];
for (int64_t index = 0LL; index <= 3LL; index++) {
uint8_t* value_0 = &(bytes[index]);
uint8_t value_1 = (uint8_t)((ZiShrU32(value, (uint64_t)((uint32_t)(((int64_t)(UINT64_C(8) * (uint64_t)index)))), 32)));
(*value_0) = value_1;
}
Slice value_2 = {bytes, 4};
return compiler_backend_cache_AppendBytes(output, value_2);
}
bool
compiler_backend_cache_AppendNumber(__type_131eebaaeb761e42* output, int64_t value)
{
if (value == 0LL) {
uint8_t value_0 = 48;
bool value_1 = false;
void *value_2 = ZirVecGrow((void *)((*(output))).data, &((*(output))).capacity, ((*(output))).count, sizeof(*((*(output))).data));
if (value_2 != NULL) {
((*(output))).data = value_2;
((*(output))).data[((*(output))).count++] = value_0;
value_1 = true;
}
return value_1;
}
uint8_t digits[24] = {0};
int64_t at = 24LL;
int64_t positive = value;
while (positive > 0LL) {
at = (int64_t)((uint64_t)at - UINT64_C(1));
uint8_t* value_3 = &(digits[at]);
(*value_3) = (uint8_t)(((int64_t)(UINT64_C(48) + (uint64_t)((positive % 10LL)))));
positive = positive / 10LL;
}
Slice value_4 = {digits, 24};
return compiler_backend_cache_AppendBytes(output, SliceRangeAt(value_4, (int64_t)at, (int64_t)24LL, sizeof(uint8_t)));
}
void
compiler_backend_cache_Record(BuildCache* cache, String object, String source)
{
bool value_0 = cache == ((void *)0) || (int64_t)(object).length == 0LL || (int64_t)(object).length >= 4096LL || (int64_t)(source).length == 0LL;
if (value_0 || (int64_t)(source).length >= 4096LL) {
return;
}
__type_9f828aa1372cb21a dependencies = {0};
__type_9f828aa1372cb21a* value_1 = &dependencies;
bool value_2 = compiler_backend_cache_ReadDependencies(object, &(dependencies));
if (!value_2) {
compiler_backend_cache_ClearNames(&(dependencies));
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
return;
}
bool source_present = false;
bool ok = dependencies.count > 0LL && dependencies.count <= 16384LL;
{
int64_t range_first_10 = 0LL;
int64_t range_last_10 = (int64_t)((uint64_t)(dependencies.count) - UINT64_C(1));
int64_t index = range_first_10;
if (index <= range_last_10) for (;;) {
if (!ok) {
break;
}
int64_t value_3 = (int64_t)((dependencies).data[index]).length;
bool value_4 = value_3 == 0LL;
if (!value_4) {
int64_t value_5 = (int64_t)((dependencies).data[index]).length;
value_4 = (value_5 >= 4096LL);
}
if (value_4) {
ok = false;
break;
}
if (StringEqual((dependencies).data[index], source)) {
source_present = true;
}
int64_t item = compiler_backend_cache_FileDigest(cache, (dependencies).data[index]);
bool value_6 = item < 0LL || ((cache->files).data[item]).unsafe;
bool value_7 = value_6;
if (!value_7) {
BuildCache* value_8 = cache;
PathInfo value_9 = ((cache->files).data[item]).info;
bool value_10 = false;
{
BuildCache* value_12 = value_8;
PathInfo value_13 = value_9;
bool value_14 = false;
int64_t value_15 = 0;
if (value_14) {
value_15 = value_13.changed;
} else {
value_15 = value_13.modified;
}
int64_t value_16 = value_15;
uint32_t value_17 = 0;
if (value_14) {
value_17 = value_13.changed_nanoseconds;
} else {
value_17 = value_13.modified_nanoseconds;
}
uint32_t value_18 = value_17;
int64_t value_19 = value_12->started_seconds;
if (value_16 != value_19) {
int64_t value_20 = value_12->started_seconds;
value_10 = value_16 < value_20;
goto value_11;
}
int64_t value_21 = (int64_t)(value_18);
int64_t value_22 = value_12->started_nanoseconds;
value_10 = value_21 < value_22;
value_11: ;
}
value_7 = !value_10;
}
bool value_23 = value_7;
bool value_24 = value_23;
if (!value_24) {
BuildCache* value_25 = cache;
PathInfo value_26 = ((cache->files).data[item]).info;
bool value_27 = false;
{
BuildCache* value_29 = value_25;
PathInfo value_30 = value_26;
bool value_31 = true;
int64_t value_32 = 0;
if (value_31) {
value_32 = value_30.changed;
} else {
value_32 = value_30.modified;
}
int64_t value_33 = value_32;
uint32_t value_34 = 0;
if (value_31) {
value_34 = value_30.changed_nanoseconds;
} else {
value_34 = value_30.modified_nanoseconds;
}
uint32_t value_35 = value_34;
int64_t value_36 = value_29->started_seconds;
if (value_33 != value_36) {
int64_t value_37 = value_29->started_seconds;
value_27 = value_33 < value_37;
goto value_28;
}
int64_t value_38 = (int64_t)(value_35);
int64_t value_39 = value_29->started_nanoseconds;
value_27 = value_38 < value_39;
value_28: ;
}
value_24 = !value_27;
}
if (value_24) {
ok = false;
break;
}
if (index == range_last_10) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
Digest lookup = {0};
if (ok && source_present) {
ok = compiler_backend_cache_LookupDigest(cache, &(dependencies), &(lookup), true);
} else {
ok = false;
}
int64_t value_40 = 0;
if (ok) {
int64_t value_41 = compiler_backend_cache_FileDigest(cache, object);
value_40 = value_41;
} else {
value_40 = -1LL;
}
int64_t compiled = value_40;
if (compiled < 0LL) {
ok = false;
}
if (ok) {
ok = compiler_backend_cache_WriteInputs(cache, object, &(dependencies), lookup, ((cache->files).data[compiled]).digest);
}
if (ok) {
compiler_backend_cache_Publish(cache, object, source, &(dependencies), lookup, ((cache->files).data[compiled]).digest);
}
compiler_backend_cache_ClearNames(&(dependencies));
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
}
bool
compiler_backend_cache_WriteInputs(BuildCache* cache, String object, __type_9f828aa1372cb21a* dependencies, Digest lookup, Digest compiled)
{
__type_131eebaaeb761e42 bytes = {0};
__type_131eebaaeb761e42* value_0 = &bytes;
bool value_1 = compiler_backend_cache_AppendText(&(bytes), StringLiteral("Ziran C cache 1\n"));
bool value_2 = !value_1;
if (!value_2) {
bool value_3 = compiler_backend_cache_AppendDigest(&(bytes), cache->identity);
value_2 = !value_3;
}
bool value_4 = value_2;
if (!value_4) {
bool value_5 = compiler_backend_cache_AppendDigest(&(bytes), compiled);
value_4 = !value_5;
}
bool value_6 = value_4;
if (!value_6) {
bool value_7 = compiler_backend_cache_AppendDigest(&(bytes), lookup);
value_6 = !value_7;
}
bool value_8 = value_6;
if (!value_8) {
bool value_9 = compiler_backend_cache_AppendCount(&(bytes), (uint32_t)(dependencies->count));
value_8 = !value_9;
}
if (value_8) {
bool cleanup_return_0 = false;
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
bool value_10 = cleanup_return_0;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_10;
}
{
int64_t range_first_8 = 0LL;
int64_t range_last_8 = (int64_t)((uint64_t)(dependencies->count) - UINT64_C(1));
int64_t index = range_first_8;
if (index <= range_last_8) for (;;) {
int64_t item = compiler_backend_cache_FileDigest(cache, (*(dependencies)).data[index]);
bool value_11 = item < 0LL || ((cache->files).data[item]).unsafe;
bool value_12 = value_11;
if (!value_12) {
bool value_13 = compiler_backend_cache_AppendCount(&(bytes), (uint32_t)((int64_t)((*(dependencies)).data[index]).length));
value_12 = !value_13;
}
bool value_14 = value_12;
bool value_15 = value_14;
if (!value_15) {
bool value_16 = compiler_backend_cache_AppendText(&(bytes), (*(dependencies)).data[index]);
value_15 = !value_16;
}
bool value_17 = value_15;
bool value_18 = value_17;
if (!value_18) {
bool value_19 = compiler_backend_cache_AppendDigest(&(bytes), ((cache->files).data[item]).digest);
value_18 = !value_19;
}
if (value_18) {
bool cleanup_return_1 = false;
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
bool value_20 = cleanup_return_1;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_20;
}
if (index == range_last_8) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
String final = compiler_backend_cache_JoinTemporary(object, StringLiteral(".inputs"));
if ((int64_t)(final).length == 0LL) {
bool cleanup_return_2 = false;
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
bool value_21 = cleanup_return_2;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_21;
}
Slice value_22 = {(bytes).data, (bytes).count};
bool cleanup_return_3 = compiler_backend_cache_PlaceFile(object, StringLiteral(".inputs."), final, SliceRangeAt(value_22, 0LL, bytes.count, sizeof(*(bytes).data)));
{
compiler_backend_cache_Release(final);
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
bool value_23 = cleanup_return_3;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_23;
}
bool
compiler_backend_cache_PlaceFile(String near, String marker, String final, Slice bytes)
{
int64_t attempt = 0LL;
while (attempt < 128LL) {
attempt = (int64_t)((uint64_t)attempt + UINT64_C(1));
int32_t value_0 = (int32_t)((uint32_t)(zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_20()) * 128u);
String temporary = compiler_backend_cache_TemporaryPath(near, marker, (int64_t)((uint64_t)(value_0) + (uint64_t)attempt));
if ((int64_t)(temporary).length == 0LL) {
return false;
}
FileHandle file = OpenExclusivePrivate(temporary);
if (!file.valid) {
compiler_backend_cache_Release(temporary);
continue;
}
int64_t written = WriteAt(file, bytes, 0LL);
bool closed = CloseFile(file);
bool placed = written == (int64_t)(bytes).length && closed && RenamePath(temporary, final);
if (!placed) {
RemoveFile(temporary);
}
compiler_backend_cache_Release(temporary);
return placed;
}
return false;
}
String
compiler_backend_cache_TemporaryPath(String near, String marker, int64_t attempt)
{
__type_131eebaaeb761e42 bytes = {0};
__type_131eebaaeb761e42* value_0 = &bytes;
bool value_1 = compiler_backend_cache_AppendText(&(bytes), near);
bool value_2 = !value_1;
if (!value_2) {
bool value_3 = compiler_backend_cache_AppendText(&(bytes), marker);
value_2 = !value_3;
}
bool value_4 = value_2;
if (!value_4) {
bool value_5 = compiler_backend_cache_AppendNumber(&(bytes), attempt);
value_4 = !value_5;
}
if (value_4) {
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
String value_6 = StringLiteral("");
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_6;
}
Slice value_7 = {(bytes).data, (bytes).count};
Slice value_8 = SliceRangeAt(value_7, 0LL, bytes.count, sizeof(*(bytes).data));
String value_9 = vec_TextDetach(vec_TextCopy(StringView((const char *)(value_8).data, (size_t)(value_8).length)));
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_9;
}
bool
compiler_backend_cache_ReadWhole(String path, __type_131eebaaeb761e42* bytes, int64_t maximum)
{
FileHandle file = OpenRead(path);
if (!file.valid) {
return false;
}
int64_t size = FileSize(file);
__type_131eebaaeb761e42 buffer = {0};
__type_131eebaaeb761e42* value_0 = &buffer;
bool value_1 = size < 0LL || size > maximum;
if (!value_1) {
int64_t value_3 = size;
bool value_4 = false;
if (value_3 >= 0) {
value_4 = value_3 <= (buffer).capacity;
if (!value_4) {
void *value_5 = ZirVecReserve((void *)(buffer).data, &(buffer).capacity, (buffer).count, value_3 - (buffer).count, sizeof(*(buffer).data));
if (value_5 != NULL) { (buffer).data = value_5; value_4 = true; }
}
if (value_4) {
if (value_3 > (buffer).count) memset((buffer).data + (buffer).count, 0, (size_t)(value_3 - (buffer).count) * sizeof(*(buffer).data));
(buffer).count = value_3;
}
}
value_1 = !value_4;
}
if (value_1) {
free((buffer).data);
(buffer).data = NULL;
buffer.capacity = 0;
buffer.count = 0;
CloseFile(file);
bool value_7 = false;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_7;
}
int64_t offset = 0LL;
while (offset < size) {
Slice value_8 = {(buffer).data, (buffer).count};
int64_t count = ReadAt(file, SliceRangeAt(value_8, offset, size, sizeof(*(buffer).data)), offset);
if (count <= 0LL) {
break;
}
offset = (int64_t)((uint64_t)offset + (uint64_t)count);
}
__type_131eebaaeb761e42 value_9 = buffer;
buffer = (*(bytes));
(*(bytes)) = value_9;
free((buffer).data);
(buffer).data = NULL;
buffer.capacity = 0;
buffer.count = 0;
bool value_10 = CloseFile(file);
bool value_11 = value_10 && offset == size;
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
return value_11;
}
void
compiler_backend_cache_StoreOpen(BuildCache* cache)
{
String limit = environment_linux_EnvironmentText(StringLiteral("ZIRAN_OBJECT_CACHE_MAX_BYTES"));
int64_t* value_0 = &(cache->budget);
(*value_0) = 2147483648LL;
if ((int64_t)(limit).length > 0LL) {
int64_t value = 0LL;
for (int64_t it_index = 0LL; it_index < (int64_t)(limit).length; it_index++) {
uint8_t byte = (uint8_t)limit.data[it_index];
if (byte < 48 || byte > 57 || value > 92233720368547758LL) {
value = -1LL;
break;
}
value = (int64_t)(((uint64_t)value * UINT64_C(10)) + (uint64_t)(((uint8_t)((uint32_t)byte - 48u))));
}
if (value <= 0LL) {
String* value_1 = &(cache->problem);
(*value_1) = StringLiteral("ZIRAN_OBJECT_CACHE_MAX_BYTES must be a whole number of bytes above zero");
return;
}
int64_t* value_2 = &(cache->budget);
(*value_2) = value;
}
String directory = environment_linux_EnvironmentText(StringLiteral("ZIRAN_OBJECT_CACHE_DIR"));
String owned = StringLiteral("");
if ((int64_t)(directory).length == 0LL) {
String base = environment_linux_EnvironmentText(StringLiteral("XDG_CACHE_HOME"));
if ((int64_t)(base).length > 0LL) {
owned = compiler_backend_cache_JoinPath(base, StringLiteral("ziran/objects"));
} else {
String home = environment_linux_EnvironmentText(StringLiteral("HOME"));
if ((int64_t)(home).length == 0LL) {
return;
}
owned = compiler_backend_cache_JoinPath(home, StringLiteral(".cache/ziran/objects"));
}
directory = owned;
}
bool value_3 = (int64_t)(directory).length == 0LL;
if (!value_3) {
bool value_4 = file_tree_linux_CreateDirectories(directory, 448);
value_3 = !value_4;
}
if (value_3) {
String* value_5 = &(cache->problem);
(*value_5) = StringLiteral("cannot create the native object cache directory");
compiler_backend_cache_Release(owned);
return;
}
String* value_6 = &(cache->store);
String value_7 = compiler_backend_cache_Owned(directory);
(*value_6) = value_7;
compiler_backend_cache_Release(owned);
}
String
compiler_backend_cache_Problem(BuildCache* cache)
{
if (cache == ((void *)0)) {
return StringLiteral("");
}
return cache->problem;
}
String
compiler_backend_cache_StorePath(BuildCache* cache, String source, Digest digest)
{
HashState hash = compiler_backend_cache_HashNew();
HashState* value_0 = &(hash);
String value_1 = StringLiteral(".zo");
{
HashState* value_3 = value_0;
String value_4 = value_1;
compiler_backend_cache_HashInteger(value_3, (uint64_t)((int64_t)(value_4).length));
compiler_backend_cache_HashBytes(value_3, value_4);
}
Slice value_5 = {cache->shared.bytes, 32};
Slice value_6 = value_5;
compiler_backend_cache_HashBytes(&(hash), StringView((const char *)(value_6).data, (size_t)(value_6).length));
String portable = compiler_backend_cache_Normalized(cache, source);
HashState* value_7 = &(hash);
{
HashState* value_9 = value_7;
String value_10 = portable;
compiler_backend_cache_HashInteger(value_9, (uint64_t)((int64_t)(value_10).length));
compiler_backend_cache_HashBytes(value_9, value_10);
}
compiler_backend_cache_Release(portable);
Slice value_11 = {digest.bytes, 32};
Slice value_12 = value_11;
compiler_backend_cache_HashBytes(&(hash), StringView((const char *)(value_12).data, (size_t)(value_12).length));
Digest key = {0};
compiler_backend_cache_HashFinish(&(hash), &(key));
String alphabet = StringLiteral("0123456789abcdef");
uint8_t name[67];
for (int64_t index = 0LL; index <= 31LL; index++) {
uint8_t* value_13 = &(name[((int64_t)((uint64_t)index * UINT64_C(2)))]);
(*value_13) = (uint8_t)alphabet.data[(int64_t)(((uint8_t)((key.bytes)[index] >> 4)))];
uint8_t* value_14 = &(name[((int64_t)(((uint64_t)index * UINT64_C(2)) + UINT64_C(1)))]);
(*value_14) = (uint8_t)alphabet.data[(int64_t)(((uint8_t)((uint32_t)((key.bytes)[index]) & 15u)))];
}
for (int64_t index = 0LL; index <= 2LL; index++) {
uint8_t* value_15 = &(name[((int64_t)(UINT64_C(64) + (uint64_t)index))]);
(*value_15) = (uint8_t)StringLiteral(".zo").data[index];
}
String value_16 = cache->store;
Slice value_17 = {name, 67};
Slice value_18 = value_17;
return compiler_backend_cache_JoinPath(value_16, StringView((const char *)(value_18).data, (size_t)(value_18).length));
}
bool
compiler_backend_cache_Fetch(BuildCache* cache, String object, String source)
{
bool value_0 = cache == ((void *)0);
if (!value_0) {
int64_t value_1 = (int64_t)(cache->store).length;
value_0 = (value_1 == 0LL);
}
if (value_0) {
return false;
}
int64_t item = compiler_backend_cache_FileDigest(cache, source);
if (item < 0LL || ((cache->files).data[item]).unsafe) {
return false;
}
String path = compiler_backend_cache_StorePath(cache, source, ((cache->files).data[item]).digest);
if ((int64_t)(path).length == 0LL) {
return false;
}
__type_131eebaaeb761e42 bytes = {0};
__type_131eebaaeb761e42* value_2 = &bytes;
bool value_3 = compiler_backend_cache_ReadWhole(path, &(bytes), 268435456LL);
if (!value_3) {
bool cleanup_return_0 = false;
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_4 = cleanup_return_0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_4;
}
Slice value_5 = {(bytes).data, (bytes).count};
Slice value_6 = SliceRangeAt(value_5, 0LL, bytes.count, sizeof(*(bytes).data));
String data = StringView((const char *)(value_6).data, (size_t)(value_6).length);
int64_t value_7 = (int64_t)(data).length;
int64_t value_8 = (int64_t)(StringLiteral("Ziran object store 1\n")).length;
if (value_7 < value_8 || !StringEqual(StringRangeAt(data, (int64_t)0LL, (int64_t)(int64_t)(StringLiteral("Ziran object store 1\n")).length), StringLiteral("Ziran object store 1\n"))) {
bool cleanup_return_1 = false;
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_9 = cleanup_return_1;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_9;
}
int64_t at = (int64_t)(StringLiteral("Ziran object store 1\n")).length;
Digest identity = {0};
Digest lookup = {0};
uint32_t count = 0;
Slice value_10 = {(bytes).data, (bytes).count};
bool value_11 = compiler_backend_cache_ReadDigest(SliceRangeAt(value_10, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(identity));
bool value_12 = !value_11;
if (!value_12) {
bool value_13 = compiler_backend_cache_SameDigest(identity, cache->shared);
value_12 = !value_13;
}
bool value_14 = value_12;
if (!value_14) {
Slice value_15 = {(bytes).data, (bytes).count};
bool value_16 = compiler_backend_cache_ReadDigest(SliceRangeAt(value_15, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(lookup));
value_14 = !value_16;
}
bool value_17 = value_14;
if (!value_17) {
Slice value_18 = {(bytes).data, (bytes).count};
bool value_19 = compiler_backend_cache_ReadInteger(SliceRangeAt(value_18, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(count));
value_17 = !value_19;
}
if (value_17 || count == 0 || count > 16384) {
bool cleanup_return_2 = false;
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_20 = cleanup_return_2;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_20;
}
__type_9f828aa1372cb21a dependencies = {0};
__type_9f828aa1372cb21a* value_21 = &dependencies;
{
int64_t range_first_48 = 0LL;
int64_t range_last_48 = (int64_t)((uint64_t)(count) - UINT64_C(1));
int64_t index = range_first_48;
if (index <= range_last_48) for (;;) {
uint32_t length = 0;
Slice value_22 = {(bytes).data, (bytes).count};
bool value_23 = compiler_backend_cache_ReadInteger(SliceRangeAt(value_22, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(length));
if (!value_23 || length == 0 || (int64_t)((uint64_t)at + (uint64_t)(length)) > (int64_t)(data).length) {
bool cleanup_return_3 = false;
{
compiler_backend_cache_ClearNames(&(dependencies));
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_24 = cleanup_return_3;
free((*value_21).data);
(*value_21).data = NULL;
(*value_21).capacity = 0;
(*value_21).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_24;
}
String dependency = compiler_backend_cache_Denormalized(cache, StringRangeAt(data, (int64_t)at, (int64_t)((int64_t)((uint64_t)at + (uint64_t)(length)))));
at = (int64_t)((uint64_t)at + (uint64_t)(length));
Digest saved = {0};
bool value_25 = (int64_t)(dependency).length == 0LL;
if (!value_25) {
String value_26 = dependency;
bool value_27 = false;
void *value_28 = ZirVecGrow((void *)(dependencies).data, &(dependencies).capacity, (dependencies).count, sizeof(*(dependencies).data));
if (value_28 != NULL) {
(dependencies).data = value_28;
(dependencies).data[(dependencies).count++] = value_26;
value_27 = true;
}
value_25 = !value_27;
}
if (value_25) {
compiler_backend_cache_Release(dependency);
bool cleanup_return_4 = false;
{
compiler_backend_cache_ClearNames(&(dependencies));
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_29 = cleanup_return_4;
free((*value_21).data);
(*value_21).data = NULL;
(*value_21).capacity = 0;
(*value_21).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_29;
}
Slice value_30 = {(bytes).data, (bytes).count};
bool value_31 = compiler_backend_cache_ReadDigest(SliceRangeAt(value_30, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(saved));
if (!value_31) {
bool cleanup_return_5 = false;
{
compiler_backend_cache_ClearNames(&(dependencies));
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_32 = cleanup_return_5;
free((*value_21).data);
(*value_21).data = NULL;
(*value_21).capacity = 0;
(*value_21).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_32;
}
int64_t found = compiler_backend_cache_FileDigest(cache, dependency);
bool value_33 = found < 0LL || ((cache->files).data[found]).unsafe;
bool value_34 = value_33;
if (!value_34) {
bool value_35 = compiler_backend_cache_SameDigest(((cache->files).data[found]).digest, saved);
value_34 = !value_35;
}
if (value_34) {
bool cleanup_return_6 = false;
{
compiler_backend_cache_ClearNames(&(dependencies));
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_36 = cleanup_return_6;
free((*value_21).data);
(*value_21).data = NULL;
(*value_21).capacity = 0;
(*value_21).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_36;
}
if (index == range_last_48) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
Digest compiled = {0};
uint32_t size = 0;
Slice value_37 = {(bytes).data, (bytes).count};
bool value_38 = compiler_backend_cache_ReadDigest(SliceRangeAt(value_37, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(compiled));
bool value_39 = !value_38;
if (!value_39) {
Slice value_40 = {(bytes).data, (bytes).count};
bool value_41 = compiler_backend_cache_ReadInteger(SliceRangeAt(value_40, 0LL, bytes.count, sizeof(*(bytes).data)), &(at), &(size));
value_39 = !value_41;
}
if (value_39 || (int64_t)((uint64_t)at + (uint64_t)(size)) != (int64_t)(data).length) {
bool cleanup_return_7 = false;
{
compiler_backend_cache_ClearNames(&(dependencies));
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_42 = cleanup_return_7;
free((*value_21).data);
(*value_21).data = NULL;
(*value_21).capacity = 0;
(*value_21).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_42;
}
Digest current = {0};
bool value_43 = compiler_backend_cache_LookupDigest(cache, &(dependencies), &(current), false);
bool value_44 = !value_43;
if (!value_44) {
bool value_45 = compiler_backend_cache_SameDigest(current, lookup);
value_44 = !value_45;
}
if (value_44) {
bool cleanup_return_8 = false;
{
compiler_backend_cache_ClearNames(&(dependencies));
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_46 = cleanup_return_8;
free((*value_21).data);
(*value_21).data = NULL;
(*value_21).capacity = 0;
(*value_21).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_46;
}
HashState hash = compiler_backend_cache_HashNew();
compiler_backend_cache_HashBytes(&(hash), StringRangeAt(data, (int64_t)at, (int64_t)(int64_t)(data).length));
Digest observed = {0};
compiler_backend_cache_HashFinish(&(hash), &(observed));
bool value_47 = compiler_backend_cache_SameDigest(observed, compiled);
bool value_48 = !value_47;
if (!value_48) {
Slice value_49 = {(bytes).data, (bytes).count};
bool value_50 = compiler_backend_cache_PlaceFile(object, StringLiteral(".fetch."), object, SliceRangeAt(value_49, at, (int64_t)(data).length, sizeof(*(bytes).data)));
value_48 = !value_50;
}
if (value_48) {
bool cleanup_return_9 = false;
{
compiler_backend_cache_ClearNames(&(dependencies));
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_51 = cleanup_return_9;
free((*value_21).data);
(*value_21).data = NULL;
(*value_21).capacity = 0;
(*value_21).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_51;
}
int64_t placed = compiler_backend_cache_FileDigest(cache, object);
bool value_52 = placed < 0LL;
if (!value_52) {
bool value_53 = compiler_backend_cache_SameDigest(((cache->files).data[placed]).digest, compiled);
value_52 = !value_53;
}
if (value_52) {
bool cleanup_return_10 = false;
{
compiler_backend_cache_ClearNames(&(dependencies));
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_54 = cleanup_return_10;
free((*value_21).data);
(*value_21).data = NULL;
(*value_21).capacity = 0;
(*value_21).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_54;
}
compiler_backend_cache_WriteInputs(cache, object, &(dependencies), lookup, compiled);
compiler_backend_cache_StoreTouch(path);
compiler_backend_cache_ProfileCount(StringLiteral("native_object_shared"));
bool cleanup_return_11 = true;
{
compiler_backend_cache_ClearNames(&(dependencies));
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
compiler_backend_cache_Release(path);
}
bool value_55 = cleanup_return_11;
free((*value_21).data);
(*value_21).data = NULL;
(*value_21).capacity = 0;
(*value_21).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return value_55;
}
void
compiler_backend_cache_Publish(BuildCache* cache, String object, String source, __type_9f828aa1372cb21a* dependencies, Digest lookup, Digest compiled)
{
int64_t value_0 = (int64_t)(cache->store).length;
if (value_0 == 0LL) {
return;
}
int64_t item = compiler_backend_cache_FileDigest(cache, source);
if (item < 0LL) {
return;
}
String path = compiler_backend_cache_StorePath(cache, source, ((cache->files).data[item]).digest);
if ((int64_t)(path).length == 0LL) {
return;
}
__type_131eebaaeb761e42 contents = {0};
__type_131eebaaeb761e42* value_1 = &contents;
bool value_2 = compiler_backend_cache_ReadWhole(object, &(contents), 268435456LL);
if (!value_2) {
{
free((contents).data);
(contents).data = NULL;
contents.capacity = 0;
contents.count = 0;
}
{
compiler_backend_cache_Release(path);
}
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
return;
}
__type_131eebaaeb761e42 bytes = {0};
__type_131eebaaeb761e42* value_3 = &bytes;
bool value_4 = compiler_backend_cache_AppendText(&(bytes), StringLiteral("Ziran object store 1\n"));
bool value_5 = !value_4;
if (!value_5) {
bool value_6 = compiler_backend_cache_AppendDigest(&(bytes), cache->shared);
value_5 = !value_6;
}
bool value_7 = value_5;
if (!value_7) {
bool value_8 = compiler_backend_cache_AppendDigest(&(bytes), lookup);
value_7 = !value_8;
}
bool value_9 = value_7;
if (!value_9) {
bool value_10 = compiler_backend_cache_AppendCount(&(bytes), (uint32_t)(dependencies->count));
value_9 = !value_10;
}
if (value_9) {
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
free((contents).data);
(contents).data = NULL;
contents.capacity = 0;
contents.count = 0;
}
{
compiler_backend_cache_Release(path);
}
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
return;
}
{
int64_t range_first_34 = 0LL;
int64_t range_last_34 = (int64_t)((uint64_t)(dependencies->count) - UINT64_C(1));
int64_t index = range_first_34;
if (index <= range_last_34) for (;;) {
String dependency = (*(dependencies)).data[index];
int64_t found = compiler_backend_cache_FileDigest(cache, dependency);
String portable = compiler_backend_cache_Normalized(cache, dependency);
bool value_11 = found >= 0LL && (int64_t)(portable).length > 0LL && compiler_backend_cache_AppendCount(&(bytes), (uint32_t)((int64_t)(portable).length));
bool value_12 = value_11 && compiler_backend_cache_AppendText(&(bytes), portable);
bool ok = value_12 && compiler_backend_cache_AppendDigest(&(bytes), ((cache->files).data[found]).digest);
compiler_backend_cache_Release(portable);
if (!ok) {
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
free((contents).data);
(contents).data = NULL;
contents.capacity = 0;
contents.count = 0;
}
{
compiler_backend_cache_Release(path);
}
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
return;
}
if (index == range_last_34) {
break;
}
index = (int64_t)((uint64_t)index + UINT64_C(1));
}
}
bool value_13 = compiler_backend_cache_AppendDigest(&(bytes), compiled);
bool value_14 = !value_13;
if (!value_14) {
bool value_15 = compiler_backend_cache_AppendCount(&(bytes), (uint32_t)(contents.count));
value_14 = !value_15;
}
bool value_16 = value_14;
if (!value_16) {
Slice value_17 = {(contents).data, (contents).count};
bool value_18 = compiler_backend_cache_AppendBytes(&(bytes), SliceRangeAt(value_17, 0LL, contents.count, sizeof(*(contents).data)));
value_16 = !value_18;
}
if (value_16) {
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
free((contents).data);
(contents).data = NULL;
contents.capacity = 0;
contents.count = 0;
}
{
compiler_backend_cache_Release(path);
}
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
return;
}
String marker = compiler_backend_cache_JoinTemporary(cache->store, StringLiteral("/.tmp-"));
if ((int64_t)(marker).length == 0LL) {
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
free((contents).data);
(contents).data = NULL;
contents.capacity = 0;
contents.count = 0;
}
{
compiler_backend_cache_Release(path);
}
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
return;
}
Slice value_19 = {(bytes).data, (bytes).count};
if (compiler_backend_cache_PlaceFile(marker, StringLiteral(""), path, SliceRangeAt(value_19, 0LL, bytes.count, sizeof(*(bytes).data)))) {
bool* value_20 = &(cache->published);
(*value_20) = true;
}
{
compiler_backend_cache_Release(marker);
}
{
free((bytes).data);
(bytes).data = NULL;
bytes.capacity = 0;
bytes.count = 0;
}
{
free((contents).data);
(contents).data = NULL;
contents.capacity = 0;
contents.count = 0;
}
{
compiler_backend_cache_Release(path);
}
free((*value_3).data);
(*value_3).data = NULL;
(*value_3).capacity = 0;
(*value_3).count = 0;
free((*value_1).data);
(*value_1).data = NULL;
(*value_1).capacity = 0;
(*value_1).count = 0;
}
void
compiler_backend_cache_StoreTouch(String path)
{
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
if (CopyCString(path, value_0)) {
zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_21(-100, &(name[0]), (void *)0, 0);
}
}
void
compiler_backend_cache_StoreSweep(BuildCache* cache)
{
String marker = compiler_backend_cache_JoinPath(cache->store, StringLiteral(".swept"));
String lock = compiler_backend_cache_JoinPath(cache->store, StringLiteral(".lock"));
int64_t now = cache->started_seconds;
PathInfo swept = file_tree_linux_PathStatus(marker, false);
if (((PathKind)(swept.kind)) == ((PathKind)(1)) && swept.modified <= now && swept.modified > (int64_t)((uint64_t)now - UINT64_C(300))) {
{
compiler_backend_cache_Release(marker);
compiler_backend_cache_Release(lock);
}
return;
}
uint8_t name[4096] = {0};
Slice value_0 = {name, 4096};
bool value_1 = CopyCString(lock, value_0);
if (!value_1) {
{
compiler_backend_cache_Release(marker);
compiler_backend_cache_Release(lock);
}
return;
}
int32_t descriptor = zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_22(&(name[0]), 524354, 384);
if (descriptor < 0) {
{
compiler_backend_cache_Release(marker);
compiler_backend_cache_Release(lock);
}
return;
}
if (zir_foreign_compiler_backend_cache__LockRaw(descriptor, 6) != 0) {
{
zir_foreign_compiler_backend_cache__CloseRaw(descriptor);
}
{
compiler_backend_cache_Release(marker);
compiler_backend_cache_Release(lock);
}
return;
}
__type_9f828aa1372cb21a names = {0};
__type_9f828aa1372cb21a* value_2 = &names;
bool value_3 = file_tree_linux_ListDirectory(cache->store, &(names));
if (!value_3) {
file_tree_linux_FreeDirectoryNames(&(names));
{
zir_foreign_compiler_backend_cache__CloseRaw(descriptor);
}
{
compiler_backend_cache_Release(marker);
compiler_backend_cache_Release(lock);
}
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
return;
}
__type_b92b5008b0f9f374 items = {0};
__type_b92b5008b0f9f374* value_4 = &items;
__type_03c9bb6e22816916 keys = {0};
__type_03c9bb6e22816916* value_5 = &keys;
int64_t total = 0LL;
for (int64_t it_index = 0LL; it_index < names.count; it_index++) {
String entry = (names).data[it_index];
String full = compiler_backend_cache_JoinPath(cache->store, entry);
if ((int64_t)(full).length == 0LL) {
continue;
}
PathInfo info = file_tree_linux_PathStatus(full, false);
String value_6 = StringLiteral(".tmp-");
bool value_7 = false;
{
String value_9 = entry;
String value_10 = value_6;
value_7 = text_tools_TextHasPrefix(value_9, value_10);
}
if (value_7) {
if (((PathKind)(info.kind)) == ((PathKind)(1)) && info.modified < (int64_t)((uint64_t)now - UINT64_C(3600))) {
RemoveFile(full);
}
} else {
String value_11 = StringLiteral(".zo");
bool value_12 = false;
{
String value_14 = entry;
String value_15 = value_11;
value_12 = text_tools_TextHasSuffix(value_14, value_15);
}
if (value_12 && ((PathKind)(info.kind)) == ((PathKind)(1)) && items.count < 1048575LL) {
StoreItem value_16 = (StoreItem){.name = full, .size = info.size, .used = info.modified};
bool value_17 = false;
void *value_18 = ZirVecGrow((void *)(items).data, &(items).capacity, (items).count, sizeof(*(items).data));
if (value_18 != NULL) {
(items).data = value_18;
(items).data[(items).count++] = value_16;
value_17 = true;
}
if (value_17) {
total = (int64_t)((uint64_t)total + (uint64_t)(info.size));
full = StringLiteral("");
}
}
}
compiler_backend_cache_Release(full);
}
int64_t value_19 = cache->budget;
if (total > value_19) {
{
Slice value_20 = {(items).data, (items).count};
Slice value_21 = SliceRangeAt(value_20, 0LL, items.count, sizeof(*(items).data));
Slice loop_view_72 = value_21;
int64_t loop_count_72 = (int64_t)(loop_view_72).length;
int64_t loop_cursor_72 = 0LL;
while (loop_cursor_72 < loop_count_72) {
int64_t loop_index_72 = loop_cursor_72;
StoreItem item = ((StoreItem *)(loop_view_72).data)[loop_index_72];
int64_t index = loop_index_72;
int64_t value_22 = (int64_t)(((uint64_t)(item.used) << 20) | (uint64_t)index);
bool value_23 = false;
void *value_24 = ZirVecGrow((void *)(keys).data, &(keys).capacity, (keys).count, sizeof(*(keys).data));
if (value_24 != NULL) {
(keys).data = value_24;
(keys).data[(keys).count++] = value_22;
value_23 = true;
}
(void)value_23;
loop_cursor_72 = (int64_t)((uint64_t)loop_cursor_72 + UINT64_C(1));
}
}
Slice value_25 = {(keys).data, (keys).count};
sort_sort_Sort_for_s64(SliceRangeAt(value_25, 0LL, keys.count, sizeof(*(keys).data)));
int64_t target = (int64_t)((uint64_t)(cache->budget) - (uint64_t)((cache->budget / 10LL)));
{
Slice value_26 = {(keys).data, (keys).count};
Slice value_27 = SliceRangeAt(value_26, 0LL, keys.count, sizeof(*(keys).data));
Slice loop_view_77 = value_27;
int64_t loop_count_77 = (int64_t)(loop_view_77).length;
int64_t loop_cursor_77 = 0LL;
while (loop_cursor_77 < loop_count_77) {
int64_t loop_index_77 = loop_cursor_77;
int64_t key = ((int64_t *)(loop_view_77).data)[loop_index_77];
if (total <= target) {
break;
}
StoreItem item = (items).data[((int64_t)((uint64_t)key & UINT64_C(1048575)))];
if (RemoveFile(item.name)) {
total = (int64_t)((uint64_t)total - (uint64_t)(item.size));
}
loop_cursor_77 = (int64_t)((uint64_t)loop_cursor_77 + UINT64_C(1));
}
}
}
{
Slice value_28 = {(items).data, (items).count};
Slice value_29 = SliceRangeAt(value_28, 0LL, items.count, sizeof(*(items).data));
Slice loop_view_87 = value_29;
int64_t loop_count_87 = (int64_t)(loop_view_87).length;
int64_t loop_cursor_87 = 0LL;
while (loop_cursor_87 < loop_count_87) {
int64_t loop_index_87 = loop_cursor_87;
StoreItem item = ((StoreItem *)(loop_view_87).data)[loop_index_87];
compiler_backend_cache_Release(item.name);
loop_cursor_87 = (int64_t)((uint64_t)loop_cursor_87 + UINT64_C(1));
}
}
file_tree_linux_ReplaceFile(marker, StringLiteral(""));
{
free((keys).data);
(keys).data = NULL;
keys.capacity = 0;
keys.count = 0;
}
{
free((items).data);
(items).data = NULL;
items.capacity = 0;
items.count = 0;
}
{
file_tree_linux_FreeDirectoryNames(&(names));
}
{
zir_foreign_compiler_backend_cache__CloseRaw(descriptor);
}
{
compiler_backend_cache_Release(marker);
compiler_backend_cache_Release(lock);
}
free((*value_5).data);
(*value_5).data = NULL;
(*value_5).capacity = 0;
(*value_5).count = 0;
free((*value_4).data);
(*value_4).data = NULL;
(*value_4).capacity = 0;
(*value_4).count = 0;
free((*value_2).data);
(*value_2).data = NULL;
(*value_2).capacity = 0;
(*value_2).count = 0;
}
void
compiler_backend_cache_ReleaseFingerprints(__type_c555612ad40905fa* values)
{
__type_c555612ad40905fa owned = {0};
__type_c555612ad40905fa* value_0 = &owned;
__type_c555612ad40905fa value_1 = owned;
owned = (*(values));
(*(values)) = value_1;
{
int64_t it_index = 0LL;
while (it_index < owned.count) {
Fingerprint* it = &(ZIRAN_VEC_INDEX((owned).data, (owned).count, it_index));
compiler_backend_cache_Release(it->path);
compiler_backend_cache_Release(it->parent);
compiler_backend_cache_ClearNames(&(it->probes));
it_index = (int64_t)((uint64_t)it_index + UINT64_C(1));
}
}
__type_c555612ad40905fa value_2 = owned;
owned = (*(values));
(*(values)) = value_2;
for (int64_t value_3 = 0; value_3 < ((*(values))).count; ++value_3) {
for (size_t value_4 = 0; value_4 < sizeof(((((*(values))).data[value_3]).digest).bytes) / sizeof((((((*(values))).data[value_3]).digest).bytes)[0]); ++value_4) {
}
free((((*(values))).data[value_3]).probes.data);
(((*(values))).data[value_3]).probes.data = NULL;
(((*(values))).data[value_3]).probes.capacity = 0;
(((*(values))).data[value_3]).probes.count = 0;
}
free(((*(values))).data);
((*(values))).data = NULL;
(*(values)).capacity = 0;
(*(values)).count = 0;
for (int64_t value_5 = 0; value_5 < ((*value_0)).count; ++value_5) {
for (size_t value_6 = 0; value_6 < sizeof(((((*value_0)).data[value_5]).digest).bytes) / sizeof((((((*value_0)).data[value_5]).digest).bytes)[0]); ++value_6) {
}
free((((*value_0)).data[value_5]).probes.data);
(((*value_0)).data[value_5]).probes.data = NULL;
(((*value_0)).data[value_5]).probes.capacity = 0;
(((*value_0)).data[value_5]).probes.count = 0;
}
free((*value_0).data);
(*value_0).data = NULL;
(*value_0).capacity = 0;
(*value_0).count = 0;
}
void
compiler_backend_cache_Close(BuildCache* cache)
{
if (cache == ((void *)0)) {
return;
}
if (cache->published) {
compiler_backend_cache_StoreSweep(cache);
}
compiler_backend_cache_ClearNames(&(cache->roots));
free((cache->roots).data);
(cache->roots).data = NULL;
cache->roots.capacity = 0;
cache->roots.count = 0;
compiler_backend_cache_Release(cache->output);
compiler_backend_cache_Release(cache->alias);
compiler_backend_cache_Release(cache->store);
compiler_backend_cache_Release(cache->executable);
free((cache->file_index.slots).data);
(cache->file_index.slots).data = NULL;
cache->file_index.slots.capacity = 0;
cache->file_index.slots.count = 0;
free((cache->candidate_index.slots).data);
(cache->candidate_index.slots).data = NULL;
cache->candidate_index.slots.capacity = 0;
cache->candidate_index.slots.count = 0;
compiler_backend_cache_ReleaseFingerprints(&(cache->files));
compiler_backend_cache_ReleaseFingerprints(&(cache->candidates));
zir_encoded_foreign_36a3c20ab8e249b6____ziran_foreign_18((void*)(cache));
}