From 68db9d5074cece234efa3a5352fe6cd36d210455 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 4 Sep 2018 15:28:13 -0400 Subject: add compile error for comptime control flow inside runtime block closes #834 --- src/codegen.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index a15ecbaf6e..5a897517d4 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -678,6 +678,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) { case ScopeIdSuspend: case ScopeIdCompTime: case ScopeIdCoroPrelude: + case ScopeIdRuntime: return get_di_scope(g, scope->parent); } zig_unreachable(); @@ -4869,6 +4870,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, case IrInstructionIdFromBytes: case IrInstructionIdToBytes: case IrInstructionIdEnumToInt: + case IrInstructionIdCheckRuntimeScope: zig_unreachable(); case IrInstructionIdReturn: -- cgit v1.2.3 From 2bf1b6840d33a27614630ddb34f53a859fc87345 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 4 Sep 2018 22:18:04 -0400 Subject: port std.os.path.resolve to stage1 --- src/all_types.hpp | 2 +- src/buffer.hpp | 5 + src/codegen.cpp | 10 +- src/codegen.hpp | 2 +- src/ir.cpp | 7 +- src/link.cpp | 6 +- src/main.cpp | 26 +-- src/os.cpp | 528 +++++++++++++++++++++++++++++++++++++++++++++++++++--- src/os.hpp | 2 +- src/util.hpp | 68 +++++++ 10 files changed, 601 insertions(+), 55 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index 01bf264c99..6615afe0f4 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1763,7 +1763,7 @@ struct CodeGen { ZigList timing_events; - Buf *cache_dir; + Buf cache_dir; Buf *out_h_path; ZigList inline_fns; diff --git a/src/buffer.hpp b/src/buffer.hpp index c12d71956f..501e44b5ac 100644 --- a/src/buffer.hpp +++ b/src/buffer.hpp @@ -173,4 +173,9 @@ static inline void buf_upcase(Buf *buf) { } } +static inline Slice buf_to_slice(Buf *buf) { + return Slice{reinterpret_cast(buf_ptr(buf)), buf_len(buf)}; +} + + #endif diff --git a/src/codegen.cpp b/src/codegen.cpp index 5a897517d4..75465fe80b 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -243,7 +243,7 @@ void codegen_set_out_name(CodeGen *g, Buf *out_name) { g->root_out_name = out_name; } -void codegen_set_cache_dir(CodeGen *g, Buf *cache_dir) { +void codegen_set_cache_dir(CodeGen *g, Buf cache_dir) { g->cache_dir = cache_dir; } @@ -5730,7 +5730,7 @@ static LLVMValueRef build_alloca(CodeGen *g, TypeTableEntry *type_entry, const c static void ensure_cache_dir(CodeGen *g) { int err; - if ((err = os_make_path(g->cache_dir))) { + if ((err = os_make_path(&g->cache_dir))) { zig_panic("unable to make cache dir: %s", err_str(err)); } } @@ -6098,7 +6098,7 @@ static void do_code_gen(CodeGen *g) { } Buf *output_path = buf_alloc(); - os_path_join(g->cache_dir, o_basename, output_path); + os_path_join(&g->cache_dir, o_basename, output_path); ensure_cache_dir(g); bool is_small = g->build_mode == BuildModeSmallRelease; @@ -6860,7 +6860,7 @@ static void define_builtin_compile_vars(CodeGen *g) { const char *builtin_zig_basename = "builtin.zig"; Buf *builtin_zig_path = buf_alloc(); - os_path_join(g->cache_dir, buf_create_from_str(builtin_zig_basename), builtin_zig_path); + os_path_join(&g->cache_dir, buf_create_from_str(builtin_zig_basename), builtin_zig_path); Buf *contents = codegen_generate_builtin_source(g); ensure_cache_dir(g); @@ -6875,7 +6875,7 @@ static void define_builtin_compile_vars(CodeGen *g) { assert(g->root_package); assert(g->std_package); - g->compile_var_package = new_package(buf_ptr(g->cache_dir), builtin_zig_basename); + g->compile_var_package = new_package(buf_ptr(&g->cache_dir), builtin_zig_basename); g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package); g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package); g->compile_var_import = add_source_file(g, g->compile_var_package, abs_full_path, contents); diff --git a/src/codegen.hpp b/src/codegen.hpp index b5f3374ec4..6297c4611b 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -47,7 +47,7 @@ void codegen_set_linker_script(CodeGen *g, const char *linker_script); void codegen_set_test_filter(CodeGen *g, Buf *filter); void codegen_set_test_name_prefix(CodeGen *g, Buf *prefix); void codegen_set_lib_version(CodeGen *g, size_t major, size_t minor, size_t patch); -void codegen_set_cache_dir(CodeGen *g, Buf *cache_dir); +void codegen_set_cache_dir(CodeGen *g, Buf cache_dir); void codegen_set_output_h_path(CodeGen *g, Buf *h_path); void codegen_add_time_event(CodeGen *g, const char *name); void codegen_print_timing_report(CodeGen *g, FILE *f); diff --git a/src/ir.cpp b/src/ir.cpp index bcc5d76774..bbce0af225 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -17974,8 +17974,11 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr Buf source_dir_path = BUF_INIT; os_path_dirname(import->path, &source_dir_path); - Buf file_path = BUF_INIT; - os_path_resolve(&source_dir_path, rel_file_path, &file_path); + Buf *resolve_paths[] = { + &source_dir_path, + rel_file_path, + }; + Buf file_path = os_path_resolve(resolve_paths, 2); // load from file system into const expr Buf *file_contents = buf_alloc(); diff --git a/src/link.cpp b/src/link.cpp index f65c072bac..f44e8b105e 100644 --- a/src/link.cpp +++ b/src/link.cpp @@ -66,7 +66,7 @@ static Buf *build_o_raw(CodeGen *parent_gen, const char *oname, Buf *full_path) const char *o_ext = target_o_file_ext(&child_gen->zig_target); Buf *o_out_name = buf_sprintf("%s%s", oname, o_ext); Buf *output_path = buf_alloc(); - os_path_join(parent_gen->cache_dir, o_out_name, output_path); + os_path_join(&parent_gen->cache_dir, o_out_name, output_path); codegen_link(child_gen, buf_ptr(output_path)); codegen_destroy(child_gen); @@ -587,11 +587,11 @@ static void construct_linker_job_coff(LinkJob *lj) { buf_appendf(def_contents, "\n"); Buf *def_path = buf_alloc(); - os_path_join(g->cache_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path); + os_path_join(&g->cache_dir, buf_sprintf("%s.def", buf_ptr(link_lib->name)), def_path); os_write_file(def_path, def_contents); Buf *generated_lib_path = buf_alloc(); - os_path_join(g->cache_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path); + os_path_join(&g->cache_dir, buf_sprintf("%s.lib", buf_ptr(link_lib->name)), generated_lib_path); gen_lib_args.resize(0); gen_lib_args.append("link"); diff --git a/src/main.cpp b/src/main.cpp index 5f96953f21..4394a1d9ae 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -374,25 +374,26 @@ int main(int argc, char **argv) { CodeGen *g = codegen_create(build_runner_path, nullptr, OutTypeExe, BuildModeDebug, zig_lib_dir_buf); codegen_set_out_name(g, buf_create_from_str("build")); - Buf build_file_abs = BUF_INIT; - os_path_resolve(buf_create_from_str("."), buf_create_from_str(build_file), &build_file_abs); + Buf *build_file_buf = buf_create_from_str(build_file); + Buf build_file_abs = os_path_resolve(&build_file_buf, 1); Buf build_file_basename = BUF_INIT; Buf build_file_dirname = BUF_INIT; os_path_split(&build_file_abs, &build_file_dirname, &build_file_basename); - Buf *full_cache_dir = buf_alloc(); + Buf full_cache_dir = BUF_INIT; if (cache_dir == nullptr) { - os_path_join(&build_file_dirname, buf_create_from_str(default_zig_cache_name), full_cache_dir); + os_path_join(&build_file_dirname, buf_create_from_str(default_zig_cache_name), &full_cache_dir); } else { - os_path_resolve(buf_create_from_str("."), buf_create_from_str(cache_dir), full_cache_dir); + Buf *cache_dir_buf = buf_create_from_str(cache_dir); + full_cache_dir = os_path_resolve(&cache_dir_buf, 1); } Buf *path_to_build_exe = buf_alloc(); - os_path_join(full_cache_dir, buf_create_from_str("build"), path_to_build_exe); + os_path_join(&full_cache_dir, buf_create_from_str("build"), path_to_build_exe); codegen_set_cache_dir(g, full_cache_dir); args.items[1] = buf_ptr(&build_file_dirname); - args.items[2] = buf_ptr(full_cache_dir); + args.items[2] = buf_ptr(&full_cache_dir); bool build_file_exists; if ((err = os_file_exists(&build_file_abs, &build_file_exists))) { @@ -789,7 +790,7 @@ int main(int argc, char **argv) { Buf *zig_root_source_file = (cmd == CmdTranslateC) ? nullptr : in_file_buf; - Buf *full_cache_dir = buf_alloc(); + Buf full_cache_dir = BUF_INIT; Buf *run_exec_path = buf_alloc(); if (cmd == CmdRun) { if (buf_out_name == nullptr) { @@ -799,13 +800,12 @@ int main(int argc, char **argv) { Buf *global_cache_dir = buf_alloc(); os_get_global_cache_directory(global_cache_dir); os_path_join(global_cache_dir, buf_out_name, run_exec_path); - os_path_resolve(buf_create_from_str("."), global_cache_dir, full_cache_dir); + full_cache_dir = os_path_resolve(&global_cache_dir, 1); out_file = buf_ptr(run_exec_path); } else { - os_path_resolve(buf_create_from_str("."), - buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir), - full_cache_dir); + Buf *resolve_paths = buf_create_from_str((cache_dir == nullptr) ? default_zig_cache_name : cache_dir); + full_cache_dir = os_path_resolve(&resolve_paths, 1); } Buf *zig_lib_dir_buf = resolve_zig_lib_dir(); @@ -937,7 +937,7 @@ int main(int argc, char **argv) { Buf *test_exe_name = buf_sprintf("test%s", target_exe_file_ext(non_null_target)); Buf *test_exe_path = buf_alloc(); - os_path_join(full_cache_dir, test_exe_name, test_exe_path); + os_path_join(&full_cache_dir, test_exe_name, test_exe_path); for (size_t i = 0; i < test_exec_args.length; i += 1) { if (test_exec_args.items[i] == nullptr) { diff --git a/src/os.cpp b/src/os.cpp index 91a591a7b6..0e62d84a48 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -57,6 +57,54 @@ static clock_serv_t cclock; #include #include +// Ported from std/mem.zig. +// Coordinate struct fields with memSplit function +struct SplitIterator { + size_t index; + Slice buffer; + Slice split_bytes; +}; + +// Ported from std/mem.zig. +static bool SplitIterator_isSplitByte(SplitIterator *self, uint8_t byte) { + for (size_t i = 0; i < self->split_bytes.len; i += 1) { + if (byte == self->split_bytes.ptr[i]) { + return true; + } + } + return false; +} + +// Ported from std/mem.zig. +static Optional> SplitIterator_next(SplitIterator *self) { + // move to beginning of token + while (self->index < self->buffer.len && + SplitIterator_isSplitByte(self, self->buffer.ptr[self->index])) + { + self->index += 1; + } + size_t start = self->index; + if (start == self->buffer.len) { + return {}; + } + + // move to end of token + while (self->index < self->buffer.len && + !SplitIterator_isSplitByte(self, self->buffer.ptr[self->index])) + { + self->index += 1; + } + size_t end = self->index; + + return Optional>::some(self->buffer.slice(start, end)); +} + +// Ported from std/mem.zig +static SplitIterator memSplit(Slice buffer, Slice split_bytes) { + return SplitIterator{0, buffer, split_bytes}; +} + + #if defined(ZIG_OS_POSIX) static void populate_termination(Termination *term, int status) { if (WIFEXITED(status)) { @@ -266,15 +314,31 @@ int os_path_real(Buf *rel_path, Buf *out_abs_path) { #endif } -bool os_path_is_absolute(Buf *path) { #if defined(ZIG_OS_WINDOWS) - if (buf_starts_with_str(path, "/") || buf_starts_with_str(path, "\\")) +// Ported from std/os/path.zig +static bool isAbsoluteWindows(Slice path) { + if (path.ptr[0] == '/') return true; - if (buf_len(path) >= 3 && buf_ptr(path)[1] == ':') + if (path.ptr[0] == '\\') { return true; - + } + if (path.len < 3) { + return false; + } + if (path.ptr[1] == ':') { + if (path.ptr[2] == '/') + return true; + if (path.ptr[2] == '\\') + return true; + } return false; +} +#endif + +bool os_path_is_absolute(Buf *path) { +#if defined(ZIG_OS_WINDOWS) + return isAbsoluteWindows(buf_to_slice(path)); #elif defined(ZIG_OS_POSIX) return buf_ptr(path)[0] == '/'; #else @@ -282,14 +346,423 @@ bool os_path_is_absolute(Buf *path) { #endif } -void os_path_resolve(Buf *ref_path, Buf *target_path, Buf *out_abs_path) { - if (os_path_is_absolute(target_path)) { - buf_init_from_buf(out_abs_path, target_path); - return; +#if defined(ZIG_OS_WINDOWS) + +enum WindowsPathKind { + WindowsPathKindNone, + WindowsPathKindDrive, + WindowsPathKindNetworkShare, +}; + +struct WindowsPath { + Slice disk_designator; + WindowsPathKind kind; + bool is_abs; +}; + + +// Ported from std/os/path.zig +static WindowsPath windowsParsePath(Slice path) { + if (path.len >= 2 && path.ptr[1] == ':') { + return WindowsPath{ + path.slice(0, 2), + WindowsPathKindDrive, + isAbsoluteWindows(path), + }; + } + if (path.len >= 1 && (path.ptr[0] == '/' || path.ptr[0] == '\\') && + (path.len == 1 || (path.ptr[1] != '/' && path.ptr[1] != '\\'))) + { + return WindowsPath{ + path.slice(0, 0), + WindowsPathKindNone, + true, + }; + } + WindowsPath relative_path = { + str(""), + WindowsPathKindNone, + false, + }; + if (path.len < strlen("//a/b")) { + return relative_path; } - os_path_join(ref_path, target_path, out_abs_path); - return; + { + if (memStartsWith(path, str("//"))) { + if (path.ptr[2] == '/') { + return relative_path; + } + + SplitIterator it = memSplit(path, str("/")); + { + Optional> opt_component = SplitIterator_next(&it); + if (!opt_component.is_some) return relative_path; + } + { + Optional> opt_component = SplitIterator_next(&it); + if (!opt_component.is_some) return relative_path; + } + return WindowsPath{ + path.slice(0, it.index), + WindowsPathKindNetworkShare, + isAbsoluteWindows(path), + }; + } + } + { + if (memStartsWith(path, str("\\\\"))) { + if (path.ptr[2] == '\\') { + return relative_path; + } + + SplitIterator it = memSplit(path, str("\\")); + { + Optional> opt_component = SplitIterator_next(&it); + if (!opt_component.is_some) return relative_path; + } + { + Optional> opt_component = SplitIterator_next(&it); + if (!opt_component.is_some) return relative_path; + } + return WindowsPath{ + path.slice(0, it.index), + WindowsPathKindNetworkShare, + isAbsoluteWindows(path), + }; + } + } + return relative_path; +} + +// Ported from std/os/path.zig +static uint8_t asciiUpper(uint8_t byte) { + if (byte >= 'a' && byte <= 'z') { + return 'A' + (byte - 'a'); + } + return byte; +} + +// Ported from std/os/path.zig +static bool asciiEqlIgnoreCase(Slice s1, Slice s2) { + if (s1.len != s2.len) + return false; + for (size_t i = 0; i < s1.len; i += 1) { + if (asciiUpper(s1.ptr[i]) != asciiUpper(s2.ptr[i])) + return false; + } + return true; +} + +// Ported from std/os/path.zig +static bool compareDiskDesignators(WindowsPathKind kind, Slice p1, Slice p2) { + switch (kind) { + case WindowsPathKindNone: + assert(p1.len == 0); + assert(p2.len == 0); + return true; + case WindowsPathKindDrive: + return asciiUpper(p1.ptr[0]) == asciiUpper(p2.ptr[0]); + case WindowsPathKindNetworkShare: + uint8_t sep1 = p1.ptr[0]; + uint8_t sep2 = p2.ptr[0]; + + SplitIterator it1 = memSplit(p1, {&sep1, 1}); + SplitIterator it2 = memSplit(p2, {&sep2, 1}); + + // TODO ASCII is wrong, we actually need full unicode support to compare paths. + return asciiEqlIgnoreCase(SplitIterator_next(&it1).value, SplitIterator_next(&it2).value) && + asciiEqlIgnoreCase(SplitIterator_next(&it1).value, SplitIterator_next(&it2).value); + } + zig_unreachable(); +} + +// Ported from std/os/path.zig +static Buf os_path_resolve_windows(Buf **paths_ptr, size_t paths_len) { + if (paths_len == 0) { + Buf cwd = BUF_INIT; + int err; + if ((err = os_get_cwd(&cwd))) { + zig_panic("get cwd failed"); + } + return cwd; + } + + // determine which disk designator we will result with, if any + char result_drive_buf[2] = {'_', ':'}; + Slice result_disk_designator = str(""); + WindowsPathKind have_drive_kind = WindowsPathKindNone; + bool have_abs_path = false; + size_t first_index = 0; + size_t max_size = 0; + for (size_t i = 0; i < paths_len; i += 1) { + Slice p = buf_to_slice(paths_ptr[i]); + WindowsPath parsed = windowsParsePath(p); + if (parsed.is_abs) { + have_abs_path = true; + first_index = i; + max_size = result_disk_designator.len; + } + switch (parsed.kind) { + case WindowsPathKindDrive: + result_drive_buf[0] = asciiUpper(parsed.disk_designator.ptr[0]); + result_disk_designator = str(result_drive_buf); + have_drive_kind = WindowsPathKindDrive; + break; + case WindowsPathKindNetworkShare: + result_disk_designator = parsed.disk_designator; + have_drive_kind = WindowsPathKindNetworkShare; + break; + case WindowsPathKindNone: + break; + } + max_size += p.len + 1; + } + + // if we will result with a disk designator, loop again to determine + // which is the last time the disk designator is absolutely specified, if any + // and count up the max bytes for paths related to this disk designator + if (have_drive_kind != WindowsPathKindNone) { + have_abs_path = false; + first_index = 0; + max_size = result_disk_designator.len; + bool correct_disk_designator = false; + + for (size_t i = 0; i < paths_len; i += 1) { + Slice p = buf_to_slice(paths_ptr[i]); + WindowsPath parsed = windowsParsePath(p); + if (parsed.kind != WindowsPathKindNone) { + if (parsed.kind == have_drive_kind) { + correct_disk_designator = compareDiskDesignators(have_drive_kind, result_disk_designator, parsed.disk_designator); + } else { + continue; + } + } + if (!correct_disk_designator) { + continue; + } + if (parsed.is_abs) { + first_index = i; + max_size = result_disk_designator.len; + have_abs_path = true; + } + max_size += p.len + 1; + } + } + + // Allocate result and fill in the disk designator, calling getCwd if we have to. + Slice result; + size_t result_index = 0; + + if (have_abs_path) { + switch (have_drive_kind) { + case WindowsPathKindDrive: { + result = Slice::alloc(max_size); + + memCopy(result, result_disk_designator); + result_index += result_disk_designator.len; + break; + } + case WindowsPathKindNetworkShare: { + result = Slice::alloc(max_size); + SplitIterator it = memSplit(buf_to_slice(paths_ptr[first_index]), str("/\\")); + Slice server_name = SplitIterator_next(&it).value; + Slice other_name = SplitIterator_next(&it).value; + + result.ptr[result_index] = '\\'; + result_index += 1; + result.ptr[result_index] = '\\'; + result_index += 1; + memCopy(result.sliceFrom(result_index), server_name); + result_index += server_name.len; + result.ptr[result_index] = '\\'; + result_index += 1; + memCopy(result.sliceFrom(result_index), other_name); + result_index += other_name.len; + + result_disk_designator = result.slice(0, result_index); + break; + } + case WindowsPathKindNone: { + Buf cwd = BUF_INIT; + int err; + if ((err = os_get_cwd(&cwd))) { + zig_panic("get cwd failed"); + } + WindowsPath parsed_cwd = windowsParsePath(buf_to_slice(&cwd)); + result = Slice::alloc(max_size + parsed_cwd.disk_designator.len + 1); + memCopy(result, parsed_cwd.disk_designator); + result_index += parsed_cwd.disk_designator.len; + result_disk_designator = result.slice(0, parsed_cwd.disk_designator.len); + if (parsed_cwd.kind == WindowsPathKindDrive) { + result.ptr[0] = asciiUpper(result.ptr[0]); + } + have_drive_kind = parsed_cwd.kind; + break; + } + } + } else { + // TODO call get cwd for the result_disk_designator instead of the global one + Buf cwd = BUF_INIT; + int err; + if ((err = os_get_cwd(&cwd))) { + zig_panic("get cwd failed"); + } + result = Slice::alloc(max_size + buf_len(&cwd) + 1); + + memCopy(result, buf_to_slice(&cwd)); + result_index += buf_len(&cwd); + WindowsPath parsed_cwd = windowsParsePath(result.slice(0, result_index)); + result_disk_designator = parsed_cwd.disk_designator; + if (parsed_cwd.kind == WindowsPathKindDrive) { + result.ptr[0] = asciiUpper(result.ptr[0]); + } + have_drive_kind = parsed_cwd.kind; + } + + // Now we know the disk designator to use, if any, and what kind it is. And our result + // is big enough to append all the paths to. + bool correct_disk_designator = true; + for (size_t i = 0; i < paths_len; i += 1) { + Slice p = buf_to_slice(paths_ptr[i]); + WindowsPath parsed = windowsParsePath(p); + + if (parsed.kind != WindowsPathKindNone) { + if (parsed.kind == have_drive_kind) { + correct_disk_designator = compareDiskDesignators(have_drive_kind, result_disk_designator, parsed.disk_designator); + } else { + continue; + } + } + if (!correct_disk_designator) { + continue; + } + SplitIterator it = memSplit(p.sliceFrom(parsed.disk_designator.len), str("/\\")); + while (true) { + Optional> opt_component = SplitIterator_next(&it); + if (!opt_component.is_some) break; + Slice component = opt_component.value; + if (memEql(component, str("."))) { + continue; + } else if (memEql(component, str(".."))) { + while (true) { + if (result_index == 0 || result_index == result_disk_designator.len) + break; + result_index -= 1; + if (result.ptr[result_index] == '\\' || result.ptr[result_index] == '/') + break; + } + } else { + result.ptr[result_index] = '\\'; + result_index += 1; + memCopy(result.sliceFrom(result_index), component); + result_index += component.len; + } + } + } + + if (result_index == result_disk_designator.len) { + result.ptr[result_index] = '\\'; + result_index += 1; + } + + Buf return_value = BUF_INIT; + buf_init_from_mem(&return_value, (char *)result.ptr, result_index); + return return_value; +} +#endif + +#if defined(ZIG_OS_POSIX) +// Ported from std/os/path.zig +static Buf os_path_resolve_posix(Buf **paths_ptr, size_t paths_len) { + if (paths_len == 0) { + Buf cwd = BUF_INIT; + int err; + if ((err = os_get_cwd(&cwd))) { + zig_panic("get cwd failed"); + } + return cwd; + } + + size_t first_index = 0; + bool have_abs = false; + size_t max_size = 0; + for (size_t i = 0; i < paths_len; i += 1) { + Buf *p = paths_ptr[i]; + if (os_path_is_absolute(p)) { + first_index = i; + have_abs = true; + max_size = 0; + } + max_size += buf_len(p) + 1; + } + + uint8_t *result_ptr; + size_t result_len; + size_t result_index = 0; + + if (have_abs) { + result_len = max_size; + result_ptr = allocate_nonzero(result_len); + } else { + Buf cwd = BUF_INIT; + int err; + if ((err = os_get_cwd(&cwd))) { + zig_panic("get cwd failed"); + } + result_len = max_size + buf_len(&cwd) + 1; + result_ptr = allocate_nonzero(result_len); + memcpy(result_ptr, buf_ptr(&cwd), buf_len(&cwd)); + result_index += buf_len(&cwd); + } + + for (size_t i = first_index; i < paths_len; i += 1) { + Buf *p = paths_ptr[i]; + SplitIterator it = memSplit(buf_to_slice(p), str("/")); + while (true) { + Optional> opt_component = SplitIterator_next(&it); + if (!opt_component.is_some) break; + Slice component = opt_component.value; + + if (memEql(component, str("."))) { + continue; + } else if (memEql(component, str(".."))) { + while (true) { + if (result_index == 0) + break; + result_index -= 1; + if (result_ptr[result_index] == '/') + break; + } + } else { + result_ptr[result_index] = '/'; + result_index += 1; + memcpy(result_ptr + result_index, component.ptr, component.len); + result_index += component.len; + } + } + } + + if (result_index == 0) { + result_ptr[0] = '/'; + result_index += 1; + } + + Buf return_value = BUF_INIT; + buf_init_from_mem(&return_value, (char *)result_ptr, result_index); + return return_value; +} +#endif + +// Ported from std/os/path.zig +Buf os_path_resolve(Buf **paths_ptr, size_t paths_len) { +#if defined(ZIG_OS_WINDOWS) + return os_path_resolve_windows(paths_ptr, paths_len); +#elif defined(ZIG_OS_POSIX) + return os_path_resolve_posix(paths_ptr, paths_len); +#else +#error "missing os_path_resolve implementation" +#endif } int os_fetch_file(FILE *f, Buf *out_buf, bool skip_shebang) { @@ -558,7 +1031,7 @@ int os_exec_process(const char *exe, ZigList &args, void os_write_file(Buf *full_path, Buf *contents) { FILE *f = fopen(buf_ptr(full_path), "wb"); if (!f) { - zig_panic("open failed"); + zig_panic("os_write_file failed for %s", buf_ptr(full_path)); } size_t amt_written = fwrite(buf_ptr(contents), 1, buf_len(contents), f); if (amt_written != (size_t)buf_len(contents)) @@ -645,21 +1118,19 @@ int os_fetch_file_path(Buf *full_path, Buf *out_contents, bool skip_shebang) { int os_get_cwd(Buf *out_cwd) { #if defined(ZIG_OS_WINDOWS) - buf_resize(out_cwd, 4096); - if (GetCurrentDirectory(buf_len(out_cwd), buf_ptr(out_cwd)) == 0) { + char buf[4096]; + if (GetCurrentDirectory(4096, buf) == 0) { zig_panic("GetCurrentDirectory failed"); } + buf_init_from_str(out_cwd, buf); return 0; #elif defined(ZIG_OS_POSIX) - int err = ERANGE; - buf_resize(out_cwd, 512); - while (err == ERANGE) { - buf_resize(out_cwd, buf_len(out_cwd) * 2); - err = getcwd(buf_ptr(out_cwd), buf_len(out_cwd)) ? 0 : errno; + char buf[PATH_MAX]; + char *res = getcwd(buf, PATH_MAX); + if (res == nullptr) { + zig_panic("unable to get cwd: %s", strerror(errno)); } - if (err) - zig_panic("unable to get cwd: %s", strerror(err)); - + buf_init_from_str(out_cwd, res); return 0; #else #error "missing os_get_cwd implementation" @@ -898,21 +1369,20 @@ double os_get_time(void) { } int os_make_path(Buf *path) { - Buf *resolved_path = buf_alloc(); - os_path_resolve(buf_create_from_str("."), path, resolved_path); + Buf resolved_path = os_path_resolve(&path, 1); - size_t end_index = buf_len(resolved_path); + size_t end_index = buf_len(&resolved_path); int err; while (true) { - if ((err = os_make_dir(buf_slice(resolved_path, 0, end_index)))) { + if ((err = os_make_dir(buf_slice(&resolved_path, 0, end_index)))) { if (err == ErrorPathAlreadyExists) { - if (end_index == buf_len(resolved_path)) + if (end_index == buf_len(&resolved_path)) return 0; } else if (err == ErrorFileNotFound) { // march end_index backward until next path component while (true) { end_index -= 1; - if (os_is_sep(buf_ptr(resolved_path)[end_index])) + if (os_is_sep(buf_ptr(&resolved_path)[end_index])) break; } continue; @@ -920,12 +1390,12 @@ int os_make_path(Buf *path) { return err; } } - if (end_index == buf_len(resolved_path)) + if (end_index == buf_len(&resolved_path)) return 0; // march end_index forward until next path component while (true) { end_index += 1; - if (end_index == buf_len(resolved_path) || os_is_sep(buf_ptr(resolved_path)[end_index])) + if (end_index == buf_len(&resolved_path) || os_is_sep(buf_ptr(&resolved_path)[end_index])) break; } } diff --git a/src/os.hpp b/src/os.hpp index cfe4e8f3a2..a44fa8160e 100644 --- a/src/os.hpp +++ b/src/os.hpp @@ -49,7 +49,7 @@ void os_path_split(Buf *full_path, Buf *out_dirname, Buf *out_basename); void os_path_extname(Buf *full_path, Buf *out_basename, Buf *out_extname); void os_path_join(Buf *dirname, Buf *basename, Buf *out_full_path); int os_path_real(Buf *rel_path, Buf *out_abs_path); -void os_path_resolve(Buf *ref_path, Buf *target_path, Buf *out_abs_path); +Buf os_path_resolve(Buf **paths_ptr, size_t paths_len); bool os_path_is_absolute(Buf *path); int os_get_global_cache_directory(Buf *out_tmp_path); diff --git a/src/util.hpp b/src/util.hpp index 41f8feb591..1e02e3043c 100644 --- a/src/util.hpp +++ b/src/util.hpp @@ -186,4 +186,72 @@ static inline double zig_f16_to_double(float16_t x) { return z; } +template +struct Optional { + T value; + bool is_some; + + static inline Optional some(T x) { + return {x, true}; + } +}; + +template +struct Slice { + T *ptr; + size_t len; + + inline Slice slice(size_t start, size_t end) { + assert(end <= len); + assert(end >= start); + return { + ptr + start, + end - start, + }; + } + + inline Slice sliceFrom(size_t start) { + assert(start <= len); + return { + ptr + start, + len - start, + }; + } + + static inline Slice alloc(size_t n) { + return {allocate_nonzero(n), n}; + } +}; + +static inline Slice str(const char *literal) { + return {(uint8_t*)(literal), strlen(literal)}; +} + +// Ported from std/mem.zig +template +static inline bool memEql(Slice a, Slice b) { + if (a.len != b.len) + return false; + for (size_t i = 0; i < a.len; i += 1) { + if (a.ptr[i] != b.ptr[i]) + return false; + } + return true; +} + +// Ported from std/mem.zig +template +static inline bool memStartsWith(Slice haystack, Slice needle) { + if (needle.len > haystack.len) + return false; + return memEql(haystack.slice(0, needle.len), needle); +} + +// Ported from std/mem.zig +template +static inline void memCopy(Slice dest, Slice src) { + assert(dest.len >= src.len); + memcpy(dest.ptr, src.ptr, src.len * sizeof(T)); +} + #endif -- cgit v1.2.3 From b35c74ea4c9d93d6a8d90812d2066a78b9abb64e Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 4 Sep 2018 23:17:38 -0400 Subject: stage1: use os_path_resolve instead of os_path_real to canonicalize imports. This means that softlinks can represent different files, but referencing the same absolute path different ways still references the same import. --- src/analyze.cpp | 12 ++++++------ src/codegen.cpp | 37 ++++++++++++++++--------------------- src/ir.cpp | 25 ++++++++----------------- 3 files changed, 30 insertions(+), 44 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index 99cd496fd9..ff7dac1abf 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -4236,9 +4236,9 @@ void preview_use_decl(CodeGen *g, AstNode *node) { node->data.use.value = result; } -ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code) { +ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *resolved_path, Buf *source_code) { if (g->verbose_tokenize) { - fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(abs_full_path)); + fprintf(stderr, "\nOriginal Source (%s):\n", buf_ptr(resolved_path)); fprintf(stderr, "----------------\n"); fprintf(stderr, "%s\n", buf_ptr(source_code)); @@ -4250,7 +4250,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a tokenize(source_code, &tokenization); if (tokenization.err) { - ErrorMsg *err = err_msg_create_with_line(abs_full_path, tokenization.err_line, tokenization.err_column, + ErrorMsg *err = err_msg_create_with_line(resolved_path, tokenization.err_line, tokenization.err_column, source_code, tokenization.line_offsets, tokenization.err); print_err_msg(err, g->err_color); @@ -4268,7 +4268,7 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a import_entry->package = package; import_entry->source_code = source_code; import_entry->line_offsets = tokenization.line_offsets; - import_entry->path = abs_full_path; + import_entry->path = resolved_path; import_entry->root = ast_parse(source_code, tokenization.tokens, import_entry, g->err_color); assert(import_entry->root); @@ -4278,10 +4278,10 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a Buf *src_dirname = buf_alloc(); Buf *src_basename = buf_alloc(); - os_path_split(abs_full_path, src_dirname, src_basename); + os_path_split(resolved_path, src_dirname, src_basename); import_entry->di_file = ZigLLVMCreateFile(g->dbuilder, buf_ptr(src_basename), buf_ptr(src_dirname)); - g->import_table.put(abs_full_path, import_entry); + g->import_table.put(resolved_path, import_entry); g->import_queue.append(import_entry); import_entry->decls_scope = create_decls_scope(import_entry->root, nullptr, nullptr, import_entry); diff --git a/src/codegen.cpp b/src/codegen.cpp index 75465fe80b..3e54e1573f 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -6866,19 +6866,16 @@ static void define_builtin_compile_vars(CodeGen *g) { ensure_cache_dir(g); os_write_file(builtin_zig_path, contents); - int err; - Buf *abs_full_path = buf_alloc(); - if ((err = os_path_real(builtin_zig_path, abs_full_path))) { - fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(builtin_zig_path), err_str(err)); - exit(1); - } + Buf *resolved_path = buf_alloc(); + Buf *resolve_paths[] = {builtin_zig_path}; + *resolved_path = os_path_resolve(resolve_paths, 1); assert(g->root_package); assert(g->std_package); g->compile_var_package = new_package(buf_ptr(&g->cache_dir), builtin_zig_basename); g->root_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package); g->std_package->package_table.put(buf_create_from_str("builtin"), g->compile_var_package); - g->compile_var_import = add_source_file(g, g->compile_var_package, abs_full_path, contents); + g->compile_var_import = add_source_file(g, g->compile_var_package, resolved_path, contents); scan_import(g, g->compile_var_import); } @@ -7034,17 +7031,17 @@ static ImportTableEntry *add_special_code(CodeGen *g, PackageTableEntry *package Buf *code_basename = buf_create_from_str(basename); Buf path_to_code_src = BUF_INIT; os_path_join(g->zig_std_special_dir, code_basename, &path_to_code_src); - Buf *abs_full_path = buf_alloc(); - int err; - if ((err = os_path_real(&path_to_code_src, abs_full_path))) { - zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err)); - } + + Buf *resolve_paths[] = {&path_to_code_src}; + Buf *resolved_path = buf_alloc(); + *resolved_path = os_path_resolve(resolve_paths, 1); Buf *import_code = buf_alloc(); - if ((err = os_fetch_file_path(abs_full_path, import_code, false))) { + int err; + if ((err = os_fetch_file_path(resolved_path, import_code, false))) { zig_panic("unable to open '%s': %s\n", buf_ptr(&path_to_code_src), err_str(err)); } - return add_source_file(g, package, abs_full_path, import_code); + return add_source_file(g, package, resolved_path, import_code); } static PackageTableEntry *create_bootstrap_pkg(CodeGen *g, PackageTableEntry *pkg_with_main) { @@ -7122,20 +7119,18 @@ static void gen_root_source(CodeGen *g) { Buf *rel_full_path = buf_alloc(); os_path_join(&g->root_package->root_src_dir, &g->root_package->root_src_path, rel_full_path); - Buf *abs_full_path = buf_alloc(); - int err; - if ((err = os_path_real(rel_full_path, abs_full_path))) { - fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(rel_full_path), err_str(err)); - exit(1); - } + Buf *resolved_path = buf_alloc(); + Buf *resolve_paths[] = {rel_full_path}; + *resolved_path = os_path_resolve(resolve_paths, 1); Buf *source_code = buf_alloc(); + int err; if ((err = os_fetch_file_path(rel_full_path, source_code, true))) { fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(rel_full_path), err_str(err)); exit(1); } - g->root_import = add_source_file(g, g->root_package, abs_full_path, source_code); + g->root_import = add_source_file(g, g->root_package, resolved_path, source_code); assert(g->root_out_name); assert(g->out_type != OutTypeUnknown); diff --git a/src/ir.cpp b/src/ir.cpp index bbce0af225..1b7bf8aa08 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -16131,29 +16131,20 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi os_path_join(search_dir, import_target_path, &full_path); Buf *import_code = buf_alloc(); - Buf *abs_full_path = buf_alloc(); - int err; - if ((err = os_path_real(&full_path, abs_full_path))) { - if (err == ErrorFileNotFound) { - ir_add_error_node(ira, source_node, - buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); - return ira->codegen->builtin_types.entry_invalid; - } else { - ira->codegen->error_during_imports = true; - ir_add_error_node(ira, source_node, - buf_sprintf("unable to open '%s': %s", buf_ptr(&full_path), err_str(err))); - return ira->codegen->builtin_types.entry_invalid; - } - } + Buf *resolved_path = buf_alloc(); + + Buf *resolve_paths[] = { &full_path, }; + *resolved_path = os_path_resolve(resolve_paths, 1); - auto import_entry = ira->codegen->import_table.maybe_get(abs_full_path); + auto import_entry = ira->codegen->import_table.maybe_get(resolved_path); if (import_entry) { ConstExprValue *out_val = ir_build_const_from(ira, &import_instruction->base); out_val->data.x_import = import_entry->value; return ira->codegen->builtin_types.entry_namespace; } - if ((err = os_fetch_file_path(abs_full_path, import_code, true))) { + int err; + if ((err = os_fetch_file_path(resolved_path, import_code, true))) { if (err == ErrorFileNotFound) { ir_add_error_node(ira, source_node, buf_sprintf("unable to find '%s'", buf_ptr(import_target_path))); @@ -16164,7 +16155,7 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi return ira->codegen->builtin_types.entry_invalid; } } - ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, abs_full_path, import_code); + ImportTableEntry *target_import = add_source_file(ira->codegen, target_package, resolved_path, import_code); scan_import(ira->codegen, target_import); -- cgit v1.2.3 From 3e94650ef7bd2407fb0aca11ad19a93b90a14b7c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Sep 2018 10:28:08 -0400 Subject: stage1: fix emit asm with explicit output file closes #1473 --- src/codegen.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 3e54e1573f..2f7a25cf93 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -6121,6 +6121,7 @@ static void do_code_gen(CodeGen *g) { zig_panic("unable to write assembly file %s: %s", buf_ptr(output_path), err_msg); } validate_inline_fns(g); + g->link_objects.append(output_path); break; case EmitFileTypeLLVMIr: @@ -6130,6 +6131,7 @@ static void do_code_gen(CodeGen *g) { zig_panic("unable to write llvm-ir file %s: %s", buf_ptr(output_path), err_msg); } validate_inline_fns(g); + g->link_objects.append(output_path); break; default: -- cgit v1.2.3 From ffb3b1576b1c02942bce89ef05eaf05fe2f026ac Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Sep 2018 16:19:58 -0400 Subject: stage1: fix tagged union with no payloads closes #1478 --- src/codegen.cpp | 2 +- test/cases/union.zig | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 2f7a25cf93..f5c1019892 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -5490,7 +5490,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref; if (type_entry->data.unionation.gen_field_count == 0) { - if (type_entry->data.unionation.gen_tag_index == SIZE_MAX) { + if (type_entry->data.unionation.tag_type == nullptr) { return nullptr; } else { return bigint_to_llvm_const(type_entry->data.unionation.tag_type->type_ref, diff --git a/test/cases/union.zig b/test/cases/union.zig index 08969e64fe..0c55fb92e7 100644 --- a/test/cases/union.zig +++ b/test/cases/union.zig @@ -311,3 +311,16 @@ fn testTaggedUnionInit(x: var) bool { const y = TaggedUnionWithAVoid{ .A = x }; return @TagType(TaggedUnionWithAVoid)(y) == TaggedUnionWithAVoid.A; } + +pub const UnionEnumNoPayloads = union(enum) { + A, + B, +}; + +test "tagged union with no payloads" { + const a = UnionEnumNoPayloads{ .B = {} }; + switch (a) { + @TagType(UnionEnumNoPayloads).A => @panic("wrong"), + @TagType(UnionEnumNoPayloads).B => {}, + } +} -- cgit v1.2.3 From db882e5d63d2840b1410a2574fd12d973b7f3ee2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Sep 2018 18:33:07 -0400 Subject: stage1: rename TypeTableEntry to ZigType --- src/all_types.hpp | 174 ++++----- src/analyze.cpp | 434 ++++++++++----------- src/analyze.hpp | 170 ++++---- src/codegen.cpp | 384 +++++++++---------- src/ir.cpp | 1106 ++++++++++++++++++++++++++--------------------------- src/ir.hpp | 6 +- 6 files changed, 1137 insertions(+), 1137 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index 6615afe0f4..9317a92d32 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -24,7 +24,7 @@ struct FnTableEntry; struct Scope; struct ScopeBlock; struct ScopeFnDef; -struct TypeTableEntry; +struct ZigType; struct VariableTableEntry; struct ErrorTableEntry; struct BuiltinFnEntry; @@ -251,7 +251,7 @@ struct ConstGlobalRefs { }; struct ConstExprValue { - TypeTableEntry *type; + ZigType *type; ConstValSpecial special; ConstGlobalRefs *global_refs; @@ -265,7 +265,7 @@ struct ConstExprValue { float128_t x_f128; bool x_bool; ConstBoundFnValue x_bound_fn; - TypeTableEntry *x_type; + ZigType *x_type; ConstExprValue *x_optional; ConstErrValue x_err_union; ErrorTableEntry *x_err_set; @@ -353,7 +353,7 @@ struct TldContainer { Tld base; ScopeDecls *decls_scope; - TypeTableEntry *type_entry; + ZigType *type_entry; }; struct TldCompTime { @@ -370,7 +370,7 @@ struct TypeEnumField { struct TypeUnionField { Buf *name; TypeEnumField *enum_field; - TypeTableEntry *type_entry; + ZigType *type_entry; AstNode *decl_node; uint32_t gen_index; }; @@ -973,7 +973,7 @@ struct AstNode { // this struct is allocated with allocate_nonzero struct FnTypeParamInfo { bool is_noalias; - TypeTableEntry *type; + ZigType *type; }; struct GenericFnTypeId { @@ -986,14 +986,14 @@ uint32_t generic_fn_type_id_hash(GenericFnTypeId *id); bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b); struct FnTypeId { - TypeTableEntry *return_type; + ZigType *return_type; FnTypeParamInfo *param_info; size_t param_count; size_t next_param_index; bool is_var_args; CallingConvention cc; uint32_t alignment; - TypeTableEntry *async_allocator_type; + ZigType *async_allocator_type; }; uint32_t fn_type_id_hash(FnTypeId*); @@ -1005,14 +1005,14 @@ enum PtrLen { }; struct TypeTableEntryPointer { - TypeTableEntry *child_type; + ZigType *child_type; PtrLen ptr_len; bool is_const; bool is_volatile; uint32_t alignment; uint32_t bit_offset; uint32_t unaligned_bit_count; - TypeTableEntry *slice_parent; + ZigType *slice_parent; }; struct TypeTableEntryInt { @@ -1025,13 +1025,13 @@ struct TypeTableEntryFloat { }; struct TypeTableEntryArray { - TypeTableEntry *child_type; + ZigType *child_type; uint64_t len; }; struct TypeStructField { Buf *name; - TypeTableEntry *type_entry; + ZigType *type_entry; size_t src_index; size_t gen_index; // offset from the memory at gen_index @@ -1069,12 +1069,12 @@ struct TypeTableEntryStruct { }; struct TypeTableEntryOptional { - TypeTableEntry *child_type; + ZigType *child_type; }; struct TypeTableEntryErrorUnion { - TypeTableEntry *err_set_type; - TypeTableEntry *payload_type; + ZigType *err_set_type; + ZigType *payload_type; }; struct TypeTableEntryErrorSet { @@ -1089,7 +1089,7 @@ struct TypeTableEntryEnum { uint32_t src_field_count; TypeEnumField *fields; bool is_invalid; // true if any fields are invalid - TypeTableEntry *tag_int_type; + ZigType *tag_int_type; ScopeDecls *decls_scope; @@ -1107,8 +1107,8 @@ struct TypeTableEntryEnum { HashMap fields_by_name; }; -uint32_t type_ptr_hash(const TypeTableEntry *ptr); -bool type_ptr_eql(const TypeTableEntry *a, const TypeTableEntry *b); +uint32_t type_ptr_hash(const ZigType *ptr); +bool type_ptr_eql(const ZigType *a, const ZigType *b); struct TypeTableEntryUnion { AstNode *decl_node; @@ -1117,7 +1117,7 @@ struct TypeTableEntryUnion { uint32_t gen_field_count; TypeUnionField *fields; bool is_invalid; // true if any fields are invalid - TypeTableEntry *tag_type; // always an enum or null + ZigType *tag_type; // always an enum or null LLVMTypeRef union_type_ref; ScopeDecls *decls_scope; @@ -1142,7 +1142,7 @@ struct TypeTableEntryUnion { bool have_explicit_tag_type; uint32_t union_size_bytes; - TypeTableEntry *most_aligned_union_member; + ZigType *most_aligned_union_member; HashMap fields_by_name; }; @@ -1151,31 +1151,31 @@ struct FnGenParamInfo { size_t src_index; size_t gen_index; bool is_byval; - TypeTableEntry *type; + ZigType *type; }; struct TypeTableEntryFn { FnTypeId fn_type_id; bool is_generic; - TypeTableEntry *gen_return_type; + ZigType *gen_return_type; size_t gen_param_count; FnGenParamInfo *gen_param_info; LLVMTypeRef raw_type_ref; - TypeTableEntry *bound_fn_parent; + ZigType *bound_fn_parent; }; struct TypeTableEntryBoundFn { - TypeTableEntry *fn_type; + ZigType *fn_type; }; struct TypeTableEntryPromise { // null if `promise` instead of `promise->T` - TypeTableEntry *result_type; + ZigType *result_type; }; -enum TypeTableEntryId { +enum ZigTypeId { TypeTableEntryIdInvalid, TypeTableEntryIdMetaType, TypeTableEntryIdVoid, @@ -1204,8 +1204,8 @@ enum TypeTableEntryId { TypeTableEntryIdPromise, }; -struct TypeTableEntry { - TypeTableEntryId id; +struct ZigType { + ZigTypeId id; Buf name; LLVMTypeRef type_ref; @@ -1232,10 +1232,10 @@ struct TypeTableEntry { } data; // use these fields to make sure we don't duplicate type table entries for the same type - TypeTableEntry *pointer_parent[2]; // [0 - mut, 1 - const] - TypeTableEntry *optional_parent; - TypeTableEntry *promise_parent; - TypeTableEntry *promise_frame_parent; + ZigType *pointer_parent[2]; // [0 - mut, 1 - const] + ZigType *optional_parent; + ZigType *promise_parent; + ZigType *promise_frame_parent; // If we generate a constant name value for this type, we memoize it here. // The type of this is array ConstExprValue *cached_const_name_val; @@ -1291,11 +1291,11 @@ struct FnTableEntry { Scope *child_scope; // parent is scope for last parameter ScopeBlock *def_scope; // parent is child_scope Buf symbol_name; - TypeTableEntry *type_entry; // function type + ZigType *type_entry; // function type // in the case of normal functions this is the implicit return type // in the case of async functions this is the implicit return type according to the // zig source code, not according to zig ir - TypeTableEntry *src_implicit_return_type; + ZigType *src_implicit_return_type; bool is_test; FnInline fn_inline; FnAnalState anal_state; @@ -1445,11 +1445,11 @@ uint32_t fn_eval_hash(Scope*); bool fn_eval_eql(Scope *a, Scope *b); struct TypeId { - TypeTableEntryId id; + ZigTypeId id; union { struct { - TypeTableEntry *child_type; + ZigType *child_type; PtrLen ptr_len; bool is_const; bool is_volatile; @@ -1458,7 +1458,7 @@ struct TypeId { uint32_t unaligned_bit_count; } pointer; struct { - TypeTableEntry *child_type; + ZigType *child_type; uint64_t size; } array; struct { @@ -1466,8 +1466,8 @@ struct TypeId { uint32_t bit_count; } integer; struct { - TypeTableEntry *err_set_type; - TypeTableEntry *payload_type; + ZigType *err_set_type; + ZigType *payload_type; } error_union; } data; }; @@ -1563,9 +1563,9 @@ struct CodeGen { // reminder: hash tables must be initialized before use HashMap import_table; HashMap builtin_fn_table; - HashMap primitive_type_table; - HashMap type_table; - HashMap fn_type_table; + HashMap primitive_type_table; + HashMap type_table; + HashMap fn_type_table; HashMap error_table; HashMap generic_table; HashMap memoized_fn_eval_table; @@ -1573,7 +1573,7 @@ struct CodeGen { HashMap exported_symbol_names; HashMap external_prototypes; HashMap string_literals_table; - HashMap type_info_cache; + HashMap type_info_cache; ZigList import_queue; @@ -1586,38 +1586,38 @@ struct CodeGen { uint32_t next_unresolved_index; struct { - TypeTableEntry *entry_bool; - TypeTableEntry *entry_c_int[CIntTypeCount]; - TypeTableEntry *entry_c_longdouble; - TypeTableEntry *entry_c_void; - TypeTableEntry *entry_u8; - TypeTableEntry *entry_u16; - TypeTableEntry *entry_u32; - TypeTableEntry *entry_u29; - TypeTableEntry *entry_u64; - TypeTableEntry *entry_i8; - TypeTableEntry *entry_i32; - TypeTableEntry *entry_i64; - TypeTableEntry *entry_isize; - TypeTableEntry *entry_usize; - TypeTableEntry *entry_f16; - TypeTableEntry *entry_f32; - TypeTableEntry *entry_f64; - TypeTableEntry *entry_f128; - TypeTableEntry *entry_void; - TypeTableEntry *entry_unreachable; - TypeTableEntry *entry_type; - TypeTableEntry *entry_invalid; - TypeTableEntry *entry_namespace; - TypeTableEntry *entry_block; - TypeTableEntry *entry_num_lit_int; - TypeTableEntry *entry_num_lit_float; - TypeTableEntry *entry_undef; - TypeTableEntry *entry_null; - TypeTableEntry *entry_var; - TypeTableEntry *entry_global_error_set; - TypeTableEntry *entry_arg_tuple; - TypeTableEntry *entry_promise; + ZigType *entry_bool; + ZigType *entry_c_int[CIntTypeCount]; + ZigType *entry_c_longdouble; + ZigType *entry_c_void; + ZigType *entry_u8; + ZigType *entry_u16; + ZigType *entry_u32; + ZigType *entry_u29; + ZigType *entry_u64; + ZigType *entry_i8; + ZigType *entry_i32; + ZigType *entry_i64; + ZigType *entry_isize; + ZigType *entry_usize; + ZigType *entry_f16; + ZigType *entry_f32; + ZigType *entry_f64; + ZigType *entry_f128; + ZigType *entry_void; + ZigType *entry_unreachable; + ZigType *entry_type; + ZigType *entry_invalid; + ZigType *entry_namespace; + ZigType *entry_block; + ZigType *entry_num_lit_int; + ZigType *entry_num_lit_float; + ZigType *entry_undef; + ZigType *entry_null; + ZigType *entry_var; + ZigType *entry_global_error_set; + ZigType *entry_arg_tuple; + ZigType *entry_promise; } builtin_types; EmitFileType emit_file_type; @@ -1735,11 +1735,11 @@ struct CodeGen { size_t llvm_argv_len; ZigList test_fns; - TypeTableEntry *test_fn_type; + ZigType *test_fn_type; bool each_lib_rpath; - TypeTableEntry *err_tag_type; + ZigType *err_tag_type; ZigList err_enumerators; ZigList errors_by_index; bool generate_error_name_table; @@ -1769,9 +1769,9 @@ struct CodeGen { ZigList inline_fns; ZigList tld_ref_source_node_stack; - TypeTableEntry *align_amt_type; - TypeTableEntry *stack_trace_type; - TypeTableEntry *ptr_to_stack_trace_type; + ZigType *align_amt_type; + ZigType *stack_trace_type; + ZigType *ptr_to_stack_trace_type; ZigList error_di_types; @@ -1818,7 +1818,7 @@ struct ErrorTableEntry { Buf name; uint32_t value; AstNode *decl_node; - TypeTableEntry *set_with_only_this_in_it; + ZigType *set_with_only_this_in_it; // If we generate a constant error name value for this error, we memoize it here. // The type of this is array ConstExprValue *cached_error_name_val; @@ -1862,7 +1862,7 @@ struct ScopeDecls { AstNode *fast_math_set_node; ImportTableEntry *import; // If this is a scope from a container, this is the type entry, otherwise null - TypeTableEntry *container_type; + ZigType *container_type; }; // This scope comes from a block expression in user code. @@ -2386,7 +2386,7 @@ struct IrInstructionCast { IrInstruction base; IrInstruction *value; - TypeTableEntry *dest_type; + ZigType *dest_type; CastOp cast_op; LLVMValueRef tmp_ptr; }; @@ -2423,7 +2423,7 @@ struct IrInstructionStructInitField { struct IrInstructionStructInit { IrInstruction base; - TypeTableEntry *struct_type; + ZigType *struct_type; size_t field_count; IrInstructionStructInitField *fields; LLVMValueRef tmp_ptr; @@ -2432,7 +2432,7 @@ struct IrInstructionStructInit { struct IrInstructionUnionInit { IrInstruction base; - TypeTableEntry *union_type; + ZigType *union_type; TypeUnionField *field; IrInstruction *init_value; LLVMValueRef tmp_ptr; @@ -2661,7 +2661,7 @@ struct IrInstructionCmpxchg { IrInstruction *failure_order_value; // if this instruction gets to runtime then we know these values: - TypeTableEntry *type; + ZigType *type; AtomicOrder success_order; AtomicOrder failure_order; @@ -2831,7 +2831,7 @@ struct IrInstructionOverflowOp { IrInstruction *op2; IrInstruction *result_ptr; - TypeTableEntry *result_ptr_type; + ZigType *result_ptr_type; }; struct IrInstructionAlignOf { diff --git a/src/analyze.cpp b/src/analyze.cpp index ff7dac1abf..28dc54f11a 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -19,12 +19,12 @@ static const size_t default_backward_branch_quota = 1000; -static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type); -static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type); +static Error resolve_enum_type(CodeGen *g, ZigType *enum_type); +static Error resolve_struct_type(CodeGen *g, ZigType *struct_type); -static Error ATTRIBUTE_MUST_USE resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type); -static Error ATTRIBUTE_MUST_USE resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type); -static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type); +static Error ATTRIBUTE_MUST_USE resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type); +static Error ATTRIBUTE_MUST_USE resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type); +static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, ZigType *union_type); static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry); ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) { @@ -70,13 +70,13 @@ ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *m return err; } -TypeTableEntry *new_type_table_entry(TypeTableEntryId id) { - TypeTableEntry *entry = allocate(1); +ZigType *new_type_table_entry(ZigTypeId id) { + ZigType *entry = allocate(1); entry->id = id; return entry; } -static ScopeDecls **get_container_scope_ptr(TypeTableEntry *type_entry) { +static ScopeDecls **get_container_scope_ptr(ZigType *type_entry) { if (type_entry->id == TypeTableEntryIdStruct) { return &type_entry->data.structure.decls_scope; } else if (type_entry->id == TypeTableEntryIdEnum) { @@ -87,7 +87,7 @@ static ScopeDecls **get_container_scope_ptr(TypeTableEntry *type_entry) { zig_unreachable(); } -ScopeDecls *get_container_scope(TypeTableEntry *type_entry) { +ScopeDecls *get_container_scope(ZigType *type_entry) { return *get_container_scope_ptr(type_entry); } @@ -97,7 +97,7 @@ void init_scope(Scope *dest, ScopeId id, AstNode *source_node, Scope *parent) { dest->parent = parent; } -ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, TypeTableEntry *container_type, ImportTableEntry *import) { +ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import) { assert(node == nullptr || node->type == NodeTypeRoot || node->type == NodeTypeContainerDecl || node->type == NodeTypeFnCallExpr); ScopeDecls *scope = allocate(1); init_scope(&scope->base, ScopeIdDecls, node, parent); @@ -203,8 +203,8 @@ ImportTableEntry *get_scope_import(Scope *scope) { zig_unreachable(); } -static TypeTableEntry *new_container_type_entry(TypeTableEntryId id, AstNode *source_node, Scope *parent_scope) { - TypeTableEntry *entry = new_type_table_entry(id); +static ZigType *new_container_type_entry(ZigTypeId id, AstNode *source_node, Scope *parent_scope) { + ZigType *entry = new_type_table_entry(id); *get_container_scope_ptr(entry) = create_decls_scope(source_node, parent_scope, entry, get_scope_import(parent_scope)); return entry; } @@ -218,7 +218,7 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) { return (upper >= x) ? base : (base + 1); } -AstNode *type_decl_node(TypeTableEntry *type_entry) { +AstNode *type_decl_node(ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdInvalid: zig_unreachable(); @@ -255,7 +255,7 @@ AstNode *type_decl_node(TypeTableEntry *type_entry) { zig_unreachable(); } -bool type_is_complete(TypeTableEntry *type_entry) { +bool type_is_complete(ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdInvalid: zig_unreachable(); @@ -293,7 +293,7 @@ bool type_is_complete(TypeTableEntry *type_entry) { zig_unreachable(); } -bool type_has_zero_bits_known(TypeTableEntry *type_entry) { +bool type_has_zero_bits_known(ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdInvalid: zig_unreachable(); @@ -331,7 +331,7 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) { } -uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) { +uint64_t type_size(CodeGen *g, ZigType *type_entry) { assert(type_is_complete(type_entry)); if (!type_has_bits(type_entry)) @@ -341,7 +341,7 @@ uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) { uint64_t size_in_bits = type_size_bits(g, type_entry); return (size_in_bits + 7) / 8; } else if (type_entry->id == TypeTableEntryIdArray) { - TypeTableEntry *child_type = type_entry->data.array.child_type; + ZigType *child_type = type_entry->data.array.child_type; if (child_type->id == TypeTableEntryIdStruct && child_type->data.structure.layout == ContainerLayoutPacked) { @@ -353,7 +353,7 @@ uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry) { return LLVMStoreSizeOfType(g->target_data_ref, type_entry->type_ref); } -uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) { +uint64_t type_size_bits(CodeGen *g, ZigType *type_entry) { assert(type_is_complete(type_entry)); if (!type_has_bits(type_entry)) @@ -366,7 +366,7 @@ uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) { } return result; } else if (type_entry->id == TypeTableEntryIdArray) { - TypeTableEntry *child_type = type_entry->data.array.child_type; + ZigType *child_type = type_entry->data.array.child_type; if (child_type->id == TypeTableEntryIdStruct && child_type->data.structure.layout == ContainerLayoutPacked) { @@ -377,7 +377,7 @@ uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry) { return LLVMSizeOfTypeInBits(g->target_data_ref, type_entry->type_ref); } -Result type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) { +Result type_is_copyable(CodeGen *g, ZigType *type_entry) { Error err; if ((err = type_ensure_zero_bits_known(g, type_entry))) return err; @@ -394,23 +394,23 @@ Result type_is_copyable(CodeGen *g, TypeTableEntry *type_entry) { return type_entry->is_copyable; } -static bool is_slice(TypeTableEntry *type) { +static bool is_slice(ZigType *type) { return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice; } -TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) { +ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) { return get_int_type(g, false, bits_needed_for_unsigned(x)); } -TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) { +ZigType *get_promise_type(CodeGen *g, ZigType *result_type) { if (result_type != nullptr && result_type->promise_parent != nullptr) { return result_type->promise_parent; } else if (result_type == nullptr && g->builtin_types.entry_promise != nullptr) { return g->builtin_types.entry_promise; } - TypeTableEntry *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false); - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPromise); + ZigType *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false); + ZigType *entry = new_type_table_entry(TypeTableEntryIdPromise); entry->type_ref = u8_ptr_type->type_ref; entry->zero_bits = false; entry->data.promise.result_type = result_type; @@ -428,14 +428,14 @@ TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type) { return entry; } -TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const, +ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count) { assert(!type_is_invalid(child_type)); assert(ptr_len == PtrLenSingle || child_type->id != TypeTableEntryIdOpaque); TypeId type_id = {}; - TypeTableEntry **parent_pointer = nullptr; + ZigType **parent_pointer = nullptr; uint32_t abi_alignment = get_abi_alignment(g, child_type); if (unaligned_bit_count != 0 || is_volatile || byte_alignment != abi_alignment || ptr_len != PtrLenSingle) { type_id.id = TypeTableEntryIdPointer; @@ -461,7 +461,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type assertNoError(type_ensure_zero_bits_known(g, child_type)); - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdPointer); + ZigType *entry = new_type_table_entry(TypeTableEntryIdPointer); entry->is_copyable = true; const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]"; @@ -487,7 +487,7 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type if (is_const || is_volatile || unaligned_bit_count != 0 || byte_alignment != abi_alignment || ptr_len != PtrLenSingle) { - TypeTableEntry *peer_type = get_pointer_to_type(g, child_type, false); + ZigType *peer_type = get_pointer_to_type(g, child_type, false); entry->type_ref = peer_type->type_ref; entry->di_type = peer_type->di_type; } else { @@ -520,18 +520,18 @@ TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type return entry; } -TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const) { +ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const) { return get_pointer_to_type_extra(g, child_type, is_const, false, PtrLenSingle, get_abi_alignment(g, child_type), 0, 0); } -TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type) { +ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type) { if (return_type->promise_frame_parent != nullptr) { return return_type->promise_frame_parent; } - TypeTableEntry *atomic_state_type = g->builtin_types.entry_usize; - TypeTableEntry *result_ptr_type = get_pointer_to_type(g, return_type, false); + ZigType *atomic_state_type = g->builtin_types.entry_usize; + ZigType *result_ptr_type = get_pointer_to_type(g, return_type, false); ZigList field_names = {}; field_names.append(ATOMIC_STATE_FIELD_NAME); @@ -543,7 +543,7 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type) field_names.append(RETURN_ADDRESSES_FIELD_NAME); } - ZigList field_types = {}; + ZigList field_types = {}; field_types.append(atomic_state_type); field_types.append(return_type); field_types.append(result_ptr_type); @@ -555,20 +555,20 @@ TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type) assert(field_names.length == field_types.length); Buf *name = buf_sprintf("AsyncFramePromise(%s)", buf_ptr(&return_type->name)); - TypeTableEntry *entry = get_struct_type(g, buf_ptr(name), field_names.items, field_types.items, field_names.length); + ZigType *entry = get_struct_type(g, buf_ptr(name), field_names.items, field_types.items, field_names.length); return_type->promise_frame_parent = entry; return entry; } -TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) { +ZigType *get_optional_type(CodeGen *g, ZigType *child_type) { if (child_type->optional_parent) { - TypeTableEntry *entry = child_type->optional_parent; + ZigType *entry = child_type->optional_parent; return entry; } else { assertNoError(ensure_complete_type(g, child_type)); - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOptional); + ZigType *entry = new_type_table_entry(TypeTableEntryIdOptional); assert(child_type->type_ref || child_type->zero_bits); entry->is_copyable = type_is_copyable(g, child_type).unwrap(); @@ -606,7 +606,7 @@ TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) { uint64_t val_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, child_type->type_ref); uint64_t val_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); - TypeTableEntry *bool_type = g->builtin_types.entry_bool; + ZigType *bool_type = g->builtin_types.entry_bool; uint64_t maybe_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, bool_type->type_ref); uint64_t maybe_debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, bool_type->type_ref); uint64_t maybe_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1); @@ -645,7 +645,7 @@ TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type) { } } -TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *payload_type) { +ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type) { assert(err_set_type->id == TypeTableEntryIdErrorSet); assert(!type_is_invalid(payload_type)); @@ -659,7 +659,7 @@ TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, T return existing_entry->value; } - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorUnion); + ZigType *entry = new_type_table_entry(TypeTableEntryIdErrorUnion); entry->is_copyable = true; assert(payload_type->di_type); assertNoError(ensure_complete_type(g, payload_type)); @@ -740,20 +740,20 @@ TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, T return entry; } -TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size) { +ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size) { TypeId type_id = {}; type_id.id = TypeTableEntryIdArray; type_id.data.array.child_type = child_type; type_id.data.array.size = array_size; auto existing_entry = g->type_table.maybe_get(type_id); if (existing_entry) { - TypeTableEntry *entry = existing_entry->value; + ZigType *entry = existing_entry->value; return entry; } assertNoError(ensure_complete_type(g, child_type)); - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArray); + ZigType *entry = new_type_table_entry(TypeTableEntryIdArray); entry->zero_bits = (array_size == 0) || child_type->zero_bits; entry->is_copyable = false; @@ -780,7 +780,7 @@ TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t return entry; } -static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, TypeTableEntry *entry) { +static void slice_type_common_init(CodeGen *g, ZigType *pointer_type, ZigType *entry) { unsigned element_count = 2; Buf *ptr_field_name = buf_create_from_str("ptr"); Buf *len_field_name = buf_create_from_str("len"); @@ -811,16 +811,16 @@ static void slice_type_common_init(CodeGen *g, TypeTableEntry *pointer_type, Typ } } -TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) { +ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { assert(ptr_type->id == TypeTableEntryIdPointer); assert(ptr_type->data.pointer.ptr_len == PtrLenUnknown); - TypeTableEntry **parent_pointer = &ptr_type->data.pointer.slice_parent; + ZigType **parent_pointer = &ptr_type->data.pointer.slice_parent; if (*parent_pointer) { return *parent_pointer; } - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdStruct); + ZigType *entry = new_type_table_entry(TypeTableEntryIdStruct); entry->is_copyable = true; // replace the & with [] to go from a ptr type name to a slice type name @@ -828,14 +828,14 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) { size_t name_offset = (ptr_type->data.pointer.ptr_len == PtrLenSingle) ? 1 : 3; buf_appendf(&entry->name, "[]%s", buf_ptr(&ptr_type->name) + name_offset); - TypeTableEntry *child_type = ptr_type->data.pointer.child_type; + ZigType *child_type = ptr_type->data.pointer.child_type; uint32_t abi_alignment = get_abi_alignment(g, child_type); if (ptr_type->data.pointer.is_const || ptr_type->data.pointer.is_volatile || ptr_type->data.pointer.alignment != abi_alignment) { - TypeTableEntry *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false, + ZigType *peer_ptr_type = get_pointer_to_type_extra(g, child_type, false, false, PtrLenUnknown, abi_alignment, 0, 0); - TypeTableEntry *peer_slice_type = get_slice_type(g, peer_ptr_type); + ZigType *peer_slice_type = get_slice_type(g, peer_ptr_type); slice_type_common_init(g, ptr_type, entry); @@ -852,18 +852,18 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) { // If the child type is []const T then we need to make sure the type ref // and debug info is the same as if the child type were []T. if (is_slice(child_type)) { - TypeTableEntry *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry; assert(child_ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *grand_child_type = child_ptr_type->data.pointer.child_type; + ZigType *grand_child_type = child_ptr_type->data.pointer.child_type; if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile || child_ptr_type->data.pointer.alignment != get_abi_alignment(g, grand_child_type)) { - TypeTableEntry *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false, + ZigType *bland_child_ptr_type = get_pointer_to_type_extra(g, grand_child_type, false, false, PtrLenUnknown, get_abi_alignment(g, grand_child_type), 0, 0); - TypeTableEntry *bland_child_slice = get_slice_type(g, bland_child_ptr_type); - TypeTableEntry *peer_ptr_type = get_pointer_to_type_extra(g, bland_child_slice, false, false, + ZigType *bland_child_slice = get_slice_type(g, bland_child_ptr_type); + ZigType *peer_ptr_type = get_pointer_to_type_extra(g, bland_child_slice, false, false, PtrLenUnknown, get_abi_alignment(g, bland_child_slice), 0, 0); - TypeTableEntry *peer_slice_type = get_slice_type(g, peer_ptr_type); + ZigType *peer_slice_type = get_slice_type(g, peer_ptr_type); entry->type_ref = peer_slice_type->type_ref; entry->di_type = peer_slice_type->di_type; @@ -889,7 +889,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) { }; LLVMStructSetBody(entry->type_ref, element_types, 1, false); - TypeTableEntry *usize_type = g->builtin_types.entry_usize; + ZigType *usize_type = g->builtin_types.entry_usize; uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref); uint64_t len_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, usize_type->type_ref); uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); @@ -928,7 +928,7 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) { uint64_t ptr_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, ptr_type->type_ref); uint64_t ptr_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 0); - TypeTableEntry *usize_type = g->builtin_types.entry_usize; + ZigType *usize_type = g->builtin_types.entry_usize; uint64_t len_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, usize_type->type_ref); uint64_t len_debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, usize_type->type_ref); uint64_t len_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, entry->type_ref, 1); @@ -971,8 +971,8 @@ TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type) { return entry; } -TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdOpaque); +ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) { + ZigType *entry = new_type_table_entry(TypeTableEntryIdOpaque); buf_init_from_str(&entry->name, name); @@ -991,13 +991,13 @@ TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, return entry; } -TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry) { - TypeTableEntry *fn_type = fn_entry->type_entry; +ZigType *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry) { + ZigType *fn_type = fn_entry->type_entry; assert(fn_type->id == TypeTableEntryIdFn); if (fn_type->data.fn.bound_fn_parent) return fn_type->data.fn.bound_fn_parent; - TypeTableEntry *bound_fn_type = new_type_table_entry(TypeTableEntryIdBoundFn); + ZigType *bound_fn_type = new_type_table_entry(TypeTableEntryIdBoundFn); bound_fn_type->is_copyable = false; bound_fn_type->data.bound_fn.fn_type = fn_type; bound_fn_type->zero_bits = true; @@ -1051,7 +1051,7 @@ static bool calling_convention_allows_zig_types(CallingConvention cc) { zig_unreachable(); } -TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g) { +ZigType *get_ptr_to_stack_trace_type(CodeGen *g) { if (g->stack_trace_type == nullptr) { ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace"); assert(stack_trace_type_val->type->id == TypeTableEntryIdMetaType); @@ -1061,7 +1061,7 @@ TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g) { return g->ptr_to_stack_trace_type; } -TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { +ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { Error err; auto table_entry = g->fn_type_table.maybe_get(fn_type_id); if (table_entry) { @@ -1075,7 +1075,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"); } - TypeTableEntry *fn_type = new_type_table_entry(TypeTableEntryIdFn); + ZigType *fn_type = new_type_table_entry(TypeTableEntryIdFn); fn_type->is_copyable = true; fn_type->data.fn.fn_type_id = *fn_type_id; @@ -1094,7 +1094,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { for (size_t i = 0; i < fn_type_id->param_count; i += 1) { FnTypeParamInfo *param_info = &fn_type_id->param_info[i]; - TypeTableEntry *param_type = param_info->type; + ZigType *param_type = param_info->type; const char *comma = (i == 0) ? "" : ", "; const char *noalias_str = param_info->is_noalias ? "noalias " : ""; buf_appendf(&fn_type->name, "%s%s%s", comma, noalias_str, buf_ptr(¶m_type->name)); @@ -1131,13 +1131,13 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { ZigLLVMDIType **param_di_types = allocate(5 + fn_type_id->param_count); param_di_types[0] = fn_type_id->return_type->di_type; size_t gen_param_index = 0; - TypeTableEntry *gen_return_type; + ZigType *gen_return_type; if (is_async) { gen_return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false); } else if (!type_has_bits(fn_type_id->return_type)) { gen_return_type = g->builtin_types.entry_void; } else if (first_arg_return) { - TypeTableEntry *gen_type = get_pointer_to_type(g, fn_type_id->return_type, false); + ZigType *gen_type = get_pointer_to_type(g, fn_type_id->return_type, false); gen_param_types[gen_param_index] = gen_type->type_ref; gen_param_index += 1; // after the gen_param_index += 1 because 0 is the return type @@ -1149,7 +1149,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { fn_type->data.fn.gen_return_type = gen_return_type; if (prefix_arg_error_return_trace) { - TypeTableEntry *gen_type = get_ptr_to_stack_trace_type(g); + ZigType *gen_type = get_ptr_to_stack_trace_type(g); gen_param_types[gen_param_index] = gen_type->type_ref; gen_param_index += 1; // after the gen_param_index += 1 because 0 is the return type @@ -1158,7 +1158,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { if (is_async) { { // async allocator param - TypeTableEntry *gen_type = fn_type_id->async_allocator_type; + ZigType *gen_type = fn_type_id->async_allocator_type; gen_param_types[gen_param_index] = gen_type->type_ref; gen_param_index += 1; // after the gen_param_index += 1 because 0 is the return type @@ -1167,7 +1167,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { { // error code pointer - TypeTableEntry *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false); + ZigType *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false); gen_param_types[gen_param_index] = gen_type->type_ref; gen_param_index += 1; // after the gen_param_index += 1 because 0 is the return type @@ -1178,7 +1178,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { fn_type->data.fn.gen_param_info = allocate(fn_type_id->param_count); for (size_t i = 0; i < fn_type_id->param_count; i += 1) { FnTypeParamInfo *src_param_info = &fn_type->data.fn.fn_type_id.param_info[i]; - TypeTableEntry *type_entry = src_param_info->type; + ZigType *type_entry = src_param_info->type; FnGenParamInfo *gen_param_info = &fn_type->data.fn.gen_param_info[i]; gen_param_info->src_index = i; @@ -1188,7 +1188,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { return g->builtin_types.entry_invalid; if (type_has_bits(type_entry)) { - TypeTableEntry *gen_type; + ZigType *gen_type; if (handle_is_ptr(type_entry)) { gen_type = get_pointer_to_type(g, type_entry, true); gen_param_info->is_byval = true; @@ -1219,7 +1219,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { return fn_type; } -static TypeTableEntryId container_to_type(ContainerKind kind) { +static ZigTypeId container_to_type(ContainerKind kind) { switch (kind) { case ContainerKindStruct: return TypeTableEntryIdStruct; @@ -1231,11 +1231,11 @@ static TypeTableEntryId container_to_type(ContainerKind kind) { zig_unreachable(); } -TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, +ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, AstNode *decl_node, const char *name, ContainerLayout layout) { - TypeTableEntryId type_id = container_to_type(kind); - TypeTableEntry *entry = new_container_type_entry(type_id, decl_node, scope); + ZigTypeId type_id = container_to_type(kind); + ZigType *entry = new_container_type_entry(type_id, decl_node, scope); switch (kind) { case ContainerKindStruct: @@ -1266,14 +1266,14 @@ TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKi return entry; } -static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, TypeTableEntry *type_entry, Buf *type_name) { +static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name) { size_t backward_branch_count = 0; return ir_eval_const_value(g, scope, node, type_entry, &backward_branch_count, default_backward_branch_quota, nullptr, nullptr, node, type_name, nullptr); } -TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { +ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { IrInstruction *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr); if (result->value.type->id == TypeTableEntryIdInvalid) return g->builtin_types.entry_invalid; @@ -1282,8 +1282,8 @@ TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { return result->value.data.x_type; } -TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { - TypeTableEntry *fn_type = new_type_table_entry(TypeTableEntryIdFn); +ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { + ZigType *fn_type = new_type_table_entry(TypeTableEntryIdFn); fn_type->is_copyable = false; buf_resize(&fn_type->name, 0); if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) { @@ -1350,9 +1350,9 @@ static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_ } static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **out_buffer) { - TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, + ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0); - TypeTableEntry *str_type = get_slice_type(g, ptr_type); + ZigType *str_type = get_slice_type(g, ptr_type); IrInstruction *instr = analyze_const_value(g, scope, node, str_type, nullptr); if (type_is_invalid(instr->value.type)) return false; @@ -1382,7 +1382,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf ** return true; } -static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { +static bool type_allowed_in_packed_struct(ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdInvalid: zig_unreachable(); @@ -1415,7 +1415,7 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { return type_entry->data.unionation.layout == ContainerLayoutPacked; case TypeTableEntryIdOptional: { - TypeTableEntry *child_type = type_entry->data.maybe.child_type; + ZigType *child_type = type_entry->data.maybe.child_type; return type_is_codegen_pointer(child_type); } case TypeTableEntryIdEnum: @@ -1424,7 +1424,7 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) { zig_unreachable(); } -static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) { +static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdInvalid: zig_unreachable(); @@ -1471,7 +1471,7 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) { return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked; case TypeTableEntryIdOptional: { - TypeTableEntry *child_type = type_entry->data.maybe.child_type; + ZigType *child_type = type_entry->data.maybe.child_type; if (child_type->id != TypeTableEntryIdPointer && child_type->id != TypeTableEntryIdFn) { return false; } @@ -1485,8 +1485,8 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) { zig_unreachable(); } -TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) { - TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); +ZigType *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) { + ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); buf_resize(&err_set_type->name, 0); buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name)); err_set_type->is_copyable = true; @@ -1501,7 +1501,7 @@ TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) { return err_set_type; } -static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, FnTableEntry *fn_entry) { +static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, FnTableEntry *fn_entry) { assert(proto_node->type == NodeTypeFnProto); AstNodeFnProto *fn_proto = &proto_node->data.fn_proto; Error err; @@ -1524,7 +1524,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c return g->builtin_types.entry_invalid; } if (param_node->data.param_decl.type != nullptr) { - TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type); + ZigType *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type); if (type_is_invalid(type_entry)) { return g->builtin_types.entry_invalid; } @@ -1557,7 +1557,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c return get_generic_fn_type(g, &fn_type_id); } - TypeTableEntry *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type); + ZigType *type_entry = analyze_type_expr(g, child_scope, param_node->data.param_decl.type); if (type_is_invalid(type_entry)) { return g->builtin_types.entry_invalid; } @@ -1645,14 +1645,14 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c //return get_generic_fn_type(g, &fn_type_id); } - TypeTableEntry *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type); + ZigType *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type); if (type_is_invalid(specified_return_type)) { fn_type_id.return_type = g->builtin_types.entry_invalid; return g->builtin_types.entry_invalid; } if (fn_proto->auto_err_set) { - TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(g, fn_entry); + ZigType *inferred_err_set_type = get_auto_err_set_type(g, fn_entry); fn_type_id.return_type = get_error_union_type(g, inferred_err_set_type, specified_return_type); } else { fn_type_id.return_type = specified_return_type; @@ -1723,7 +1723,7 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c return get_fn_type(g, &fn_type_id); } -bool type_is_invalid(TypeTableEntry *type_entry) { +bool type_is_invalid(ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdInvalid: return true; @@ -1740,7 +1740,7 @@ bool type_is_invalid(TypeTableEntry *type_entry) { } -static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) { +static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) { assert(enum_type->id == TypeTableEntryIdEnum); if (enum_type->data.enumeration.is_invalid) @@ -1815,7 +1815,7 @@ static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) { return ErrorNone; } - TypeTableEntry *tag_int_type = enum_type->data.enumeration.tag_int_type; + ZigType *tag_int_type = enum_type->data.enumeration.tag_int_type; // create debug type for tag uint64_t tag_debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, tag_int_type->type_ref); @@ -1834,10 +1834,10 @@ static Error resolve_enum_type(CodeGen *g, TypeTableEntry *enum_type) { } -TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[], - TypeTableEntry *field_types[], size_t field_count) +ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[], + ZigType *field_types[], size_t field_count) { - TypeTableEntry *struct_type = new_type_table_entry(TypeTableEntryIdStruct); + ZigType *struct_type = new_type_table_entry(TypeTableEntryIdStruct); buf_init_from_str(&struct_type->name, type_name); @@ -1881,7 +1881,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f if (type_struct_field->gen_index == SIZE_MAX) { continue; } - TypeTableEntry *field_type = type_struct_field->type_entry; + ZigType *field_type = type_struct_field->type_entry; uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_type->type_ref); uint64_t debug_align_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, field_type->type_ref); uint64_t debug_offset_in_bits = 8*LLVMOffsetOfElement(g->target_data_ref, struct_type->type_ref, type_struct_field->gen_index); @@ -1913,7 +1913,7 @@ TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *f return struct_type; } -static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) { +static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { assert(struct_type->id == TypeTableEntryIdStruct); if (struct_type->data.structure.complete) @@ -1957,7 +1957,7 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) { for (size_t i = 0; i < field_count; i += 1) { TypeStructField *type_struct_field = &struct_type->data.structure.fields[i]; - TypeTableEntry *field_type = type_struct_field->type_entry; + ZigType *field_type = type_struct_field->type_entry; if ((err = ensure_complete_type(g, field_type))) { struct_type->data.structure.is_invalid = true; @@ -2088,12 +2088,12 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) { continue; } - TypeTableEntry *field_type = type_struct_field->type_entry; + ZigType *field_type = type_struct_field->type_entry; // if the field is a function, actually the debug info should be a pointer. ZigLLVMDIType *field_di_type; if (field_type->id == TypeTableEntryIdFn) { - TypeTableEntry *field_ptr_type = get_pointer_to_type(g, field_type, true); + ZigType *field_ptr_type = get_pointer_to_type(g, field_type, true); uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_ptr_type->type_ref); uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_ptr_type->type_ref); field_di_type = ZigLLVMCreateDebugPointerType(g->dbuilder, field_type->di_type, @@ -2147,7 +2147,7 @@ static Error resolve_struct_type(CodeGen *g, TypeTableEntry *struct_type) { return ErrorNone; } -static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { +static Error resolve_union_type(CodeGen *g, ZigType *union_type) { assert(union_type->id == TypeTableEntryIdUnion); if (union_type->data.unionation.complete) @@ -2179,7 +2179,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { uint32_t gen_field_count = union_type->data.unionation.gen_field_count; ZigLLVMDIType **union_inner_di_types = allocate(gen_field_count); - TypeTableEntry *most_aligned_union_member = nullptr; + ZigType *most_aligned_union_member = nullptr; uint64_t size_of_most_aligned_member_in_bits = 0; uint64_t biggest_align_in_bits = 0; uint64_t biggest_size_in_bits = 0; @@ -2194,7 +2194,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { for (uint32_t i = 0; i < field_count; i += 1) { AstNode *field_node = decl_node->data.container_decl.fields.at(i); TypeUnionField *union_field = &union_type->data.unionation.fields[i]; - TypeTableEntry *field_type = union_field->type_entry; + ZigType *field_type = union_field->type_entry; if ((err = ensure_complete_type(g, field_type))) { union_type->data.unionation.is_invalid = true; @@ -2259,13 +2259,13 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { uint64_t padding_in_bits = biggest_size_in_bits - size_of_most_aligned_member_in_bits; - TypeTableEntry *tag_type = union_type->data.unionation.tag_type; + ZigType *tag_type = union_type->data.unionation.tag_type; if (tag_type == nullptr || tag_type->zero_bits) { assert(most_aligned_union_member != nullptr); if (padding_in_bits > 0) { - TypeTableEntry *u8_type = get_int_type(g, false, 8); - TypeTableEntry *padding_array = get_array_type(g, u8_type, padding_in_bits / 8); + ZigType *u8_type = get_int_type(g, false, 8); + ZigType *padding_array = get_array_type(g, u8_type, padding_in_bits / 8); LLVMTypeRef union_element_types[] = { most_aligned_union_member->type_ref, padding_array->type_ref, @@ -2295,8 +2295,8 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { LLVMTypeRef union_type_ref; if (padding_in_bits > 0) { - TypeTableEntry *u8_type = get_int_type(g, false, 8); - TypeTableEntry *padding_array = get_array_type(g, u8_type, padding_in_bits / 8); + ZigType *u8_type = get_int_type(g, false, 8); + ZigType *padding_array = get_array_type(g, u8_type, padding_in_bits / 8); LLVMTypeRef union_element_types[] = { most_aligned_union_member->type_ref, padding_array->type_ref, @@ -2319,7 +2319,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { assert(8*LLVMStoreSizeOfType(g->target_data_ref, union_type_ref) >= biggest_size_in_bits); // create llvm type for root struct - TypeTableEntry *tag_int_type = tag_type->data.enumeration.tag_int_type; + ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type; uint64_t align_of_tag_in_bits = 8*LLVMABIAlignmentOfType(g->target_data_ref, tag_int_type->type_ref); if (align_of_tag_in_bits >= biggest_align_in_bits) { @@ -2387,7 +2387,7 @@ static Error resolve_union_type(CodeGen *g, TypeTableEntry *union_type) { return ErrorNone; } -static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) { +static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { assert(enum_type->id == TypeTableEntryIdEnum); if (enum_type->data.enumeration.zero_bits_known) @@ -2428,7 +2428,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) { HashMap occupied_tag_values = {}; occupied_tag_values.init(field_count); - TypeTableEntry *tag_int_type; + ZigType *tag_int_type; if (enum_type->data.enumeration.layout == ContainerLayoutExtern) { tag_int_type = get_c_int_type(g, CIntTypeInt); } else { @@ -2437,7 +2437,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) { // TODO: Are extern enums allowed to have an init_arg_expr? if (decl_node->data.container_decl.init_arg_expr != nullptr) { - TypeTableEntry *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr); + ZigType *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr); if (type_is_invalid(wanted_tag_int_type)) { enum_type->data.enumeration.is_invalid = true; } else if (wanted_tag_int_type->id != TypeTableEntryIdInt) { @@ -2550,7 +2550,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, TypeTableEntry *enum_type) { return ErrorNone; } -static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) { +static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { assert(struct_type->id == TypeTableEntryIdStruct); Error err; @@ -2614,7 +2614,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) { continue; } - TypeTableEntry *field_type = analyze_type_expr(g, scope, field_node->data.struct_field.type); + ZigType *field_type = analyze_type_expr(g, scope, field_node->data.struct_field.type); type_struct_field->type_entry = field_type; type_struct_field->src_index = i; type_struct_field->gen_index = SIZE_MAX; @@ -2669,7 +2669,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, TypeTableEntry *struct_type) { return ErrorNone; } -static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) { +static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { assert(union_type->id == TypeTableEntryIdUnion); Error err; @@ -2734,7 +2734,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) { enum_type_node != nullptr; bool auto_layout = (union_type->data.unionation.layout == ContainerLayoutAuto); bool want_safety = (field_count >= 2) && (auto_layout || enum_type_node != nullptr); - TypeTableEntry *tag_type; + ZigType *tag_type; bool create_enum_type = decl_node->data.container_decl.auto_enum || (enum_type_node == nullptr && want_safety); bool *covered_enum_fields; ZigLLVMDIEnumerator **di_enumerators; @@ -2744,7 +2744,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) { di_enumerators = allocate(field_count); - TypeTableEntry *tag_int_type; + ZigType *tag_int_type; if (enum_type_node != nullptr) { tag_int_type = analyze_type_expr(g, scope, enum_type_node); if (type_is_invalid(tag_int_type)) { @@ -2779,7 +2779,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) { tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope; tag_type->data.enumeration.complete = true; } else if (enum_type_node != nullptr) { - TypeTableEntry *enum_type = analyze_type_expr(g, scope, enum_type_node); + ZigType *enum_type = analyze_type_expr(g, scope, enum_type_node); if (type_is_invalid(enum_type)) { union_type->data.unionation.is_invalid = true; return ErrorSemanticAnalyzeFail; @@ -2816,7 +2816,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) { continue; } - TypeTableEntry *field_type; + ZigType *field_type; if (field_node->data.struct_field.type == nullptr) { if (decl_node->data.container_decl.auto_enum || decl_node->data.container_decl.init_arg_expr != nullptr) { field_type = g->builtin_types.entry_void; @@ -2860,7 +2860,7 @@ static Error resolve_union_zero_bits(CodeGen *g, TypeTableEntry *union_type) { // In this first pass we resolve explicit tag values. // In a second pass we will fill in the unspecified ones. if (tag_value != nullptr) { - TypeTableEntry *tag_int_type = tag_type->data.enumeration.tag_int_type; + ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type; IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr); if (result_inst->value.type->id == TypeTableEntryIdInvalid) { union_type->data.unionation.is_invalid = true; @@ -3075,7 +3075,7 @@ static bool scope_is_root_decls(Scope *scope) { zig_unreachable(); } -static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntry *fn_type) { +static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, ZigType *fn_type) { add_node_error(g, proto_node, buf_sprintf("expected 'fn([]const u8, ?*builtin.StackTrace) noreturn', found '%s'", buf_ptr(&fn_type->name))); @@ -3084,30 +3084,30 @@ static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, TypeTableEntr static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) { AstNode *proto_node = panic_fn->proto_node; assert(proto_node->type == NodeTypeFnProto); - TypeTableEntry *fn_type = panic_fn->type_entry; + ZigType *fn_type = panic_fn->type_entry; FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; if (fn_type_id->param_count != 2) { return wrong_panic_prototype(g, proto_node, fn_type); } - TypeTableEntry *const_u8_ptr = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, + ZigType *const_u8_ptr = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0); - TypeTableEntry *const_u8_slice = get_slice_type(g, const_u8_ptr); + ZigType *const_u8_slice = get_slice_type(g, const_u8_ptr); if (fn_type_id->param_info[0].type != const_u8_slice) { return wrong_panic_prototype(g, proto_node, fn_type); } - TypeTableEntry *optional_ptr_to_stack_trace_type = get_optional_type(g, get_ptr_to_stack_trace_type(g)); + ZigType *optional_ptr_to_stack_trace_type = get_optional_type(g, get_ptr_to_stack_trace_type(g)); if (fn_type_id->param_info[1].type != optional_ptr_to_stack_trace_type) { return wrong_panic_prototype(g, proto_node, fn_type); } - TypeTableEntry *actual_return_type = fn_type_id->return_type; + ZigType *actual_return_type = fn_type_id->return_type; if (actual_return_type != g->builtin_types.entry_unreachable) { return wrong_panic_prototype(g, proto_node, fn_type); } } -TypeTableEntry *get_test_fn_type(CodeGen *g) { +ZigType *get_test_fn_type(CodeGen *g) { if (g->test_fn_type) return g->test_fn_type; @@ -3280,7 +3280,7 @@ static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) { } { - TypeTableEntry *type = get_primitive_type(g, tld->name); + ZigType *type = get_primitive_type(g, tld->name); if (type != nullptr) { add_node_error(g, tld->source_node, buf_sprintf("declaration shadows type '%s'", buf_ptr(&type->name))); @@ -3444,7 +3444,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) { } static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) { - TypeTableEntry *type_entry = tld_container->type_entry; + ZigType *type_entry = tld_container->type_entry; assert(type_entry); switch (type_entry->id) { @@ -3462,7 +3462,7 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) { } } -TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry) { +ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdInvalid: return g->builtin_types.entry_invalid; @@ -3526,7 +3526,7 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent add_error_note(g, msg, existing_var->decl_node, buf_sprintf("previous declaration is here")); variable_entry->value->type = g->builtin_types.entry_invalid; } else { - TypeTableEntry *type = get_primitive_type(g, name); + ZigType *type = get_primitive_type(g, name); if (type != nullptr) { add_node_error(g, source_node, buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); @@ -3577,9 +3577,9 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) { bool is_extern = var_decl->is_extern; bool is_export = var_decl->is_export; - TypeTableEntry *explicit_type = nullptr; + ZigType *explicit_type = nullptr; if (var_decl->type) { - TypeTableEntry *proposed_type = analyze_type_expr(g, tld_var->base.parent_scope, var_decl->type); + ZigType *proposed_type = analyze_type_expr(g, tld_var->base.parent_scope, var_decl->type); explicit_type = validate_var_type(g, var_decl->type, proposed_type); } @@ -3597,7 +3597,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) { IrInstruction *init_value = nullptr; // TODO more validation for types that can't be used for export/extern variables - TypeTableEntry *implicit_type = nullptr; + ZigType *implicit_type = nullptr; if (explicit_type && explicit_type->id == TypeTableEntryIdInvalid) { implicit_type = explicit_type; } else if (var_decl->expr) { @@ -3627,7 +3627,7 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) { implicit_type = g->builtin_types.entry_invalid; } - TypeTableEntry *type = explicit_type ? explicit_type : implicit_type; + ZigType *type = explicit_type ? explicit_type : implicit_type; assert(type != nullptr); // should have been caught by the parser ConstExprValue *init_val = init_value ? &init_value->value : create_const_runtime(type); @@ -3789,7 +3789,7 @@ FnTableEntry *scope_get_fn_if_root(Scope *scope) { return nullptr; } -TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name) { +TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) { assert(enum_type->id == TypeTableEntryIdEnum); if (enum_type->data.enumeration.src_field_count == 0) return nullptr; @@ -3799,7 +3799,7 @@ TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name) { return entry->value; } -TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) { +TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name) { assert(type_entry->id == TypeTableEntryIdStruct); assert(type_entry->data.structure.complete); if (type_entry->data.structure.src_field_count == 0) @@ -3810,7 +3810,7 @@ TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name) { return entry->value; } -TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) { +TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name) { assert(type_entry->id == TypeTableEntryIdUnion); assert(type_entry->data.unionation.zero_bits_known); if (type_entry->data.unionation.src_field_count == 0) @@ -3821,7 +3821,7 @@ TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name) { return entry->value; } -TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt *tag) { +TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag) { assert(type_entry->id == TypeTableEntryIdUnion); assert(type_entry->data.unionation.zero_bits_known); for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) { @@ -3833,7 +3833,7 @@ TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt return nullptr; } -TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *tag) { +TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag) { assert(enum_type->data.enumeration.zero_bits_known); for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) { TypeEnumField *field = &enum_type->data.enumeration.fields[i]; @@ -3845,7 +3845,7 @@ TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *t } -static bool is_container(TypeTableEntry *type_entry) { +static bool is_container(ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdInvalid: zig_unreachable(); @@ -3880,28 +3880,28 @@ static bool is_container(TypeTableEntry *type_entry) { zig_unreachable(); } -bool is_ref(TypeTableEntry *type_entry) { +bool is_ref(ZigType *type_entry) { return type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle; } -bool is_array_ref(TypeTableEntry *type_entry) { - TypeTableEntry *array = is_ref(type_entry) ? +bool is_array_ref(ZigType *type_entry) { + ZigType *array = is_ref(type_entry) ? type_entry->data.pointer.child_type : type_entry; return array->id == TypeTableEntryIdArray; } -bool is_container_ref(TypeTableEntry *type_entry) { +bool is_container_ref(ZigType *type_entry) { return is_ref(type_entry) ? is_container(type_entry->data.pointer.child_type) : is_container(type_entry); } -TypeTableEntry *container_ref_type(TypeTableEntry *type_entry) { +ZigType *container_ref_type(ZigType *type_entry) { assert(is_container_ref(type_entry)); return is_ref(type_entry) ? type_entry->data.pointer.child_type : type_entry; } -void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) { +void resolve_container_type(CodeGen *g, ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdStruct: resolve_struct_type(g, type_entry); @@ -3939,7 +3939,7 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) { } } -TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) { +ZigType *get_codegen_ptr_type(ZigType *type) { if (type->id == TypeTableEntryIdPointer) return type; if (type->id == TypeTableEntryIdFn) return type; if (type->id == TypeTableEntryIdPromise) return type; @@ -3951,12 +3951,12 @@ TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type) { return nullptr; } -bool type_is_codegen_pointer(TypeTableEntry *type) { +bool type_is_codegen_pointer(ZigType *type) { return get_codegen_ptr_type(type) == type; } -uint32_t get_ptr_align(TypeTableEntry *type) { - TypeTableEntry *ptr_type = get_codegen_ptr_type(type); +uint32_t get_ptr_align(ZigType *type) { + ZigType *ptr_type = get_codegen_ptr_type(type); if (ptr_type->id == TypeTableEntryIdPointer) { return ptr_type->data.pointer.alignment; } else if (ptr_type->id == TypeTableEntryIdFn) { @@ -3968,8 +3968,8 @@ uint32_t get_ptr_align(TypeTableEntry *type) { } } -bool get_ptr_const(TypeTableEntry *type) { - TypeTableEntry *ptr_type = get_codegen_ptr_type(type); +bool get_ptr_const(ZigType *type) { + ZigType *ptr_type = get_codegen_ptr_type(type); if (ptr_type->id == TypeTableEntryIdPointer) { return ptr_type->data.pointer.is_const; } else if (ptr_type->id == TypeTableEntryIdFn) { @@ -3991,7 +3991,7 @@ AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) { } static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry) { - TypeTableEntry *fn_type = fn_table_entry->type_entry; + ZigType *fn_type = fn_table_entry->type_entry; assert(!fn_type->data.fn.is_generic); FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; for (size_t i = 0; i < fn_type_id->param_count; i += 1) { @@ -4008,7 +4008,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr continue; } - TypeTableEntry *param_type = param_info->type; + ZigType *param_type = param_info->type; bool is_noalias = param_info->is_noalias; if (is_noalias && get_codegen_ptr_type(param_type) == nullptr) { @@ -4031,7 +4031,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr } } -bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node) { +bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) { FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn; if (infer_fn != nullptr) { if (infer_fn->anal_state == FnAnalStateInvalid) { @@ -4053,11 +4053,11 @@ bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNod } void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_type_node) { - TypeTableEntry *fn_type = fn_table_entry->type_entry; + ZigType *fn_type = fn_table_entry->type_entry; assert(!fn_type->data.fn.is_generic); FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; - TypeTableEntry *block_return_type = ir_analyze(g, &fn_table_entry->ir_executable, + ZigType *block_return_type = ir_analyze(g, &fn_table_entry->ir_executable, &fn_table_entry->analyzed_executable, fn_type_id->return_type, return_type_node); fn_table_entry->src_implicit_return_type = block_return_type; @@ -4068,9 +4068,9 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ } if (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion) { - TypeTableEntry *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type; + ZigType *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type; if (return_err_set_type->data.error_set.infer_fn != nullptr) { - TypeTableEntry *inferred_err_set_type; + ZigType *inferred_err_set_type; if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorSet) { inferred_err_set_type = fn_table_entry->src_implicit_return_type; } else if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorUnion) { @@ -4129,7 +4129,7 @@ static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { define_local_param_variables(g, fn_table_entry); - TypeTableEntry *fn_type = fn_table_entry->type_entry; + ZigType *fn_type = fn_table_entry->type_entry; assert(!fn_type->data.fn.is_generic); ir_gen_fn(g, fn_table_entry); @@ -4355,7 +4355,7 @@ void semantic_analyze(CodeGen *g) { } } -TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) { +ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) { TypeId type_id = {}; type_id.id = TypeTableEntryIdInt; type_id.data.integer.is_signed = is_signed; @@ -4367,20 +4367,20 @@ TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) return entry->value; } - TypeTableEntry *new_entry = make_int_type(g, is_signed, size_in_bits); + ZigType *new_entry = make_int_type(g, is_signed, size_in_bits); g->type_table.put(type_id, new_entry); return new_entry; } -TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type) { +ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type) { return &g->builtin_types.entry_c_int[c_int_type]; } -TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type) { +ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type) { return *get_c_int_type_ptr(g, c_int_type); } -bool handle_is_ptr(TypeTableEntry *type_entry) { +bool handle_is_ptr(ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdInvalid: case TypeTableEntryIdMetaType: @@ -4916,7 +4916,7 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) { zig_unreachable(); } -static bool return_type_is_cacheable(TypeTableEntry *return_type) { +static bool return_type_is_cacheable(ZigType *return_type) { switch (return_type->id) { case TypeTableEntryIdInvalid: zig_unreachable(); @@ -4958,7 +4958,7 @@ static bool return_type_is_cacheable(TypeTableEntry *return_type) { zig_unreachable(); } -bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type) { +bool fn_eval_cacheable(Scope *scope, ZigType *return_type) { if (!return_type_is_cacheable(return_type)) return false; while (scope) { @@ -5027,14 +5027,14 @@ bool fn_eval_eql(Scope *a, Scope *b) { return false; } -bool type_has_bits(TypeTableEntry *type_entry) { +bool type_has_bits(ZigType *type_entry) { assert(type_entry); assert(type_entry->id != TypeTableEntryIdInvalid); assert(type_has_zero_bits_known(type_entry)); return !type_entry->zero_bits; } -bool type_requires_comptime(TypeTableEntry *type_entry) { +bool type_requires_comptime(ZigType *type_entry) { switch (type_entry->id) { case TypeTableEntryIdInvalid: case TypeTableEntryIdOpaque: @@ -5143,27 +5143,27 @@ ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *str) { return const_val; } -void init_const_bigint(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *bigint) { +void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint) { const_val->special = ConstValSpecialStatic; const_val->type = type; bigint_init_bigint(&const_val->data.x_bigint, bigint); } -ConstExprValue *create_const_bigint(TypeTableEntry *type, const BigInt *bigint) { +ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint) { ConstExprValue *const_val = create_const_vals(1); init_const_bigint(const_val, type, bigint); return const_val; } -void init_const_unsigned_negative(ConstExprValue *const_val, TypeTableEntry *type, uint64_t x, bool negative) { +void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative) { const_val->special = ConstValSpecialStatic; const_val->type = type; bigint_init_unsigned(&const_val->data.x_bigint, x); const_val->data.x_bigint.is_negative = negative; } -ConstExprValue *create_const_unsigned_negative(TypeTableEntry *type, uint64_t x, bool negative) { +ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative) { ConstExprValue *const_val = create_const_vals(1); init_const_unsigned_negative(const_val, type, x, negative); return const_val; @@ -5177,19 +5177,19 @@ ConstExprValue *create_const_usize(CodeGen *g, uint64_t x) { return create_const_unsigned_negative(g->builtin_types.entry_usize, x, false); } -void init_const_signed(ConstExprValue *const_val, TypeTableEntry *type, int64_t x) { +void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x) { const_val->special = ConstValSpecialStatic; const_val->type = type; bigint_init_signed(&const_val->data.x_bigint, x); } -ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x) { +ConstExprValue *create_const_signed(ZigType *type, int64_t x) { ConstExprValue *const_val = create_const_vals(1); init_const_signed(const_val, type, x); return const_val; } -void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value) { +void init_const_float(ConstExprValue *const_val, ZigType *type, double value) { const_val->special = ConstValSpecialStatic; const_val->type = type; if (type->id == TypeTableEntryIdComptimeFloat) { @@ -5216,19 +5216,19 @@ void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double va } } -ConstExprValue *create_const_float(TypeTableEntry *type, double value) { +ConstExprValue *create_const_float(ZigType *type, double value) { ConstExprValue *const_val = create_const_vals(1); init_const_float(const_val, type, value); return const_val; } -void init_const_enum(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *tag) { +void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag) { const_val->special = ConstValSpecialStatic; const_val->type = type; bigint_init_bigint(&const_val->data.x_enum_tag, tag); } -ConstExprValue *create_const_enum(TypeTableEntry *type, const BigInt *tag) { +ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag) { ConstExprValue *const_val = create_const_vals(1); init_const_enum(const_val, type, tag); return const_val; @@ -5247,24 +5247,24 @@ ConstExprValue *create_const_bool(CodeGen *g, bool value) { return const_val; } -void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type) { +void init_const_runtime(ConstExprValue *const_val, ZigType *type) { const_val->special = ConstValSpecialRuntime; const_val->type = type; } -ConstExprValue *create_const_runtime(TypeTableEntry *type) { +ConstExprValue *create_const_runtime(ZigType *type) { ConstExprValue *const_val = create_const_vals(1); init_const_runtime(const_val, type); return const_val; } -void init_const_type(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *type_value) { +void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value) { const_val->special = ConstValSpecialStatic; const_val->type = g->builtin_types.entry_type; const_val->data.x_type = type_value; } -ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value) { +ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) { ConstExprValue *const_val = create_const_vals(1); init_const_type(g, const_val, type_value); return const_val; @@ -5275,7 +5275,7 @@ void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *arr { assert(array_val->type->id == TypeTableEntryIdArray); - TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, array_val->type->data.array.child_type, + ZigType *ptr_type = get_pointer_to_type_extra(g, array_val->type->data.array.child_type, is_const, false, PtrLenUnknown, get_abi_alignment(g, array_val->type->data.array.child_type), 0, 0); @@ -5298,7 +5298,7 @@ void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue size_t elem_index, bool is_const, PtrLen ptr_len) { assert(array_val->type->id == TypeTableEntryIdArray); - TypeTableEntry *child_type = array_val->type->data.array.child_type; + ZigType *child_type = array_val->type->data.array.child_type; const_val->special = ConstValSpecialStatic; const_val->type = get_pointer_to_type_extra(g, child_type, is_const, false, @@ -5329,7 +5329,7 @@ ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bo return const_val; } -void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *pointee_type, +void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type, size_t addr, bool is_const) { const_val->special = ConstValSpecialStatic; @@ -5338,7 +5338,7 @@ void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeT const_val->data.x_ptr.data.hard_coded_addr.addr = addr; } -ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, TypeTableEntry *pointee_type, +ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type, size_t addr, bool is_const) { ConstExprValue *const_val = create_const_vals(1); @@ -5362,7 +5362,7 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_ void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { Error err; - TypeTableEntry *wanted_type = const_val->type; + ZigType *wanted_type = const_val->type; if (wanted_type->id == TypeTableEntryIdArray) { const_val->special = ConstValSpecialStatic; const_val->data.x_array.special = ConstArraySpecialUndef; @@ -5400,7 +5400,7 @@ ConstExprValue *create_const_vals(size_t count) { return vals; } -Error ensure_complete_type(CodeGen *g, TypeTableEntry *type_entry) { +Error ensure_complete_type(CodeGen *g, ZigType *type_entry) { if (type_is_invalid(type_entry)) return ErrorSemanticAnalyzeFail; if (type_entry->id == TypeTableEntryIdStruct) { @@ -5416,7 +5416,7 @@ Error ensure_complete_type(CodeGen *g, TypeTableEntry *type_entry) { return ErrorNone; } -Error type_ensure_zero_bits_known(CodeGen *g, TypeTableEntry *type_entry) { +Error type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry) { if (type_is_invalid(type_entry)) return ErrorSemanticAnalyzeFail; if (type_entry->id == TypeTableEntryIdStruct) { @@ -5591,7 +5591,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { zig_unreachable(); } -void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint, bool is_max) { +void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max) { assert(int_type->id == TypeTableEntryIdInt); if (int_type->data.integral.bit_count == 0) { bigint_init_unsigned(bigint, 0); @@ -5628,7 +5628,7 @@ void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint } } -void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max) { +void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max) { if (type_entry->id == TypeTableEntryIdInt) { const_val->special = ConstValSpecialStatic; eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max); @@ -5642,7 +5642,7 @@ void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue * } } -void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, TypeTableEntry *type_entry) { +void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigType *type_entry) { switch (const_val->data.x_ptr.special) { case ConstPtrSpecialInvalid: zig_unreachable(); @@ -5690,7 +5690,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { } assert(const_val->type); - TypeTableEntry *type_entry = const_val->type; + ZigType *type_entry = const_val->type; switch (type_entry->id) { case TypeTableEntryIdOpaque: zig_unreachable(); @@ -5765,7 +5765,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { } case TypeTableEntryIdArray: { - TypeTableEntry *child_type = type_entry->data.array.child_type; + ZigType *child_type = type_entry->data.array.child_type; uint64_t len = type_entry->data.array.len; if (const_val->data.x_array.special == ConstArraySpecialUndef) { @@ -5878,8 +5878,8 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { zig_unreachable(); } -TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt); +ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) { + ZigType *entry = new_type_table_entry(TypeTableEntryIdInt); entry->is_copyable = true; entry->type_ref = (size_in_bits == 0) ? LLVMVoidType() : LLVMIntType(size_in_bits); entry->zero_bits = (size_in_bits == 0); @@ -6071,7 +6071,7 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) { ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) { assert(value->type); - TypeTableEntry *type_entry = value->type; + ZigType *type_entry = value->type; if (type_entry->id == TypeTableEntryIdArray) { expand_undef_array(g, value); return &value->data.x_array.s_none.parent; @@ -6083,7 +6083,7 @@ ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) { return nullptr; } -static const TypeTableEntryId all_type_ids[] = { +static const ZigTypeId all_type_ids[] = { TypeTableEntryIdMetaType, TypeTableEntryIdVoid, TypeTableEntryIdBool, @@ -6111,7 +6111,7 @@ static const TypeTableEntryId all_type_ids[] = { TypeTableEntryIdPromise, }; -TypeTableEntryId type_id_at_index(size_t index) { +ZigTypeId type_id_at_index(size_t index) { assert(index < array_length(all_type_ids)); return all_type_ids[index]; } @@ -6120,7 +6120,7 @@ size_t type_id_len() { return array_length(all_type_ids); } -size_t type_id_index(TypeTableEntry *entry) { +size_t type_id_index(ZigType *entry) { switch (entry->id) { case TypeTableEntryIdInvalid: zig_unreachable(); @@ -6180,7 +6180,7 @@ size_t type_id_index(TypeTableEntry *entry) { zig_unreachable(); } -const char *type_id_name(TypeTableEntryId id) { +const char *type_id_name(ZigTypeId id) { switch (id) { case TypeTableEntryIdInvalid: zig_unreachable(); @@ -6266,7 +6266,7 @@ LinkLib *add_link_lib(CodeGen *g, Buf *name) { return link_lib; } -uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry) { +uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry) { assertNoError(type_ensure_zero_bits_known(g, type_entry)); if (type_entry->zero_bits) return 0; @@ -6290,7 +6290,7 @@ uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry) { } } -TypeTableEntry *get_align_amt_type(CodeGen *g) { +ZigType *get_align_amt_type(CodeGen *g) { if (g->align_amt_type == nullptr) { // according to LLVM the maximum alignment is 1 << 29. g->align_amt_type = get_int_type(g, false, 29); @@ -6298,11 +6298,11 @@ TypeTableEntry *get_align_amt_type(CodeGen *g) { return g->align_amt_type; } -uint32_t type_ptr_hash(const TypeTableEntry *ptr) { +uint32_t type_ptr_hash(const ZigType *ptr) { return hash_ptr((void*)ptr); } -bool type_ptr_eql(const TypeTableEntry *a, const TypeTableEntry *b) { +bool type_ptr_eql(const ZigType *a, const ZigType *b) { return a == b; } @@ -6316,7 +6316,7 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) { return var_value; } -bool type_is_global_error_set(TypeTableEntry *err_set_type) { +bool type_is_global_error_set(ZigType *err_set_type) { assert(err_set_type->id == TypeTableEntryIdErrorSet); assert(err_set_type->data.error_set.infer_fn == nullptr); return err_set_type->data.error_set.err_count == UINT32_MAX; @@ -6326,7 +6326,7 @@ uint32_t get_coro_frame_align_bytes(CodeGen *g) { return g->pointer_size_bytes * 2; } -bool type_can_fail(TypeTableEntry *type_entry) { +bool type_can_fail(ZigType *type_entry) { return type_entry->id == TypeTableEntryIdErrorUnion || type_entry->id == TypeTableEntryIdErrorSet; } @@ -6334,7 +6334,7 @@ bool fn_type_can_fail(FnTypeId *fn_type_id) { return type_can_fail(fn_type_id->return_type) || fn_type_id->cc == CallingConventionAsync; } -TypeTableEntry *get_primitive_type(CodeGen *g, Buf *name) { +ZigType *get_primitive_type(CodeGen *g, Buf *name) { if (buf_len(name) >= 2) { uint8_t first_c = buf_ptr(name)[0]; if (first_c == 'i' || first_c == 'u') { diff --git a/src/analyze.hpp b/src/analyze.hpp index 316499bf95..58c9636dec 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -14,35 +14,35 @@ void semantic_analyze(CodeGen *g); ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg); ErrorMsg *add_error_note(CodeGen *g, ErrorMsg *parent_msg, AstNode *node, Buf *msg); -TypeTableEntry *new_type_table_entry(TypeTableEntryId id); -TypeTableEntry *get_pointer_to_type(CodeGen *g, TypeTableEntry *child_type, bool is_const); -TypeTableEntry *get_pointer_to_type_extra(CodeGen *g, TypeTableEntry *child_type, bool is_const, +ZigType *new_type_table_entry(ZigTypeId id); +ZigType *get_pointer_to_type(CodeGen *g, ZigType *child_type, bool is_const); +ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_const, bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count); -uint64_t type_size(CodeGen *g, TypeTableEntry *type_entry); -uint64_t type_size_bits(CodeGen *g, TypeTableEntry *type_entry); -TypeTableEntry *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); -TypeTableEntry **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type); -TypeTableEntry *get_c_int_type(CodeGen *g, CIntType c_int_type); -TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id); -TypeTableEntry *get_optional_type(CodeGen *g, TypeTableEntry *child_type); -TypeTableEntry *get_array_type(CodeGen *g, TypeTableEntry *child_type, uint64_t array_size); -TypeTableEntry *get_slice_type(CodeGen *g, TypeTableEntry *ptr_type); -TypeTableEntry *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, +uint64_t type_size(CodeGen *g, ZigType *type_entry); +uint64_t type_size_bits(CodeGen *g, ZigType *type_entry); +ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); +ZigType **get_c_int_type_ptr(CodeGen *g, CIntType c_int_type); +ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type); +ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id); +ZigType *get_optional_type(CodeGen *g, ZigType *child_type); +ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size); +ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type); +ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind, AstNode *decl_node, const char *name, ContainerLayout layout); -TypeTableEntry *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x); -TypeTableEntry *get_error_union_type(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *payload_type); -TypeTableEntry *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry); -TypeTableEntry *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name); -TypeTableEntry *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[], - TypeTableEntry *field_types[], size_t field_count); -TypeTableEntry *get_promise_type(CodeGen *g, TypeTableEntry *result_type); -TypeTableEntry *get_promise_frame_type(CodeGen *g, TypeTableEntry *return_type); -TypeTableEntry *get_test_fn_type(CodeGen *g); -bool handle_is_ptr(TypeTableEntry *type_entry); +ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x); +ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type); +ZigType *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry); +ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name); +ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[], + ZigType *field_types[], size_t field_count); +ZigType *get_promise_type(CodeGen *g, ZigType *result_type); +ZigType *get_promise_frame_type(CodeGen *g, ZigType *return_type); +ZigType *get_test_fn_type(CodeGen *g); +bool handle_is_ptr(ZigType *type_entry); void find_libc_include_path(CodeGen *g); void find_libc_lib_path(CodeGen *g); -bool type_has_bits(TypeTableEntry *type_entry); +bool type_has_bits(ZigType *type_entry); ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code); @@ -51,28 +51,28 @@ ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *a VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name); Tld *find_decl(CodeGen *g, Scope *scope, Buf *name); void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node); -bool type_is_codegen_pointer(TypeTableEntry *type); - -TypeTableEntry *get_codegen_ptr_type(TypeTableEntry *type); -uint32_t get_ptr_align(TypeTableEntry *type); -bool get_ptr_const(TypeTableEntry *type); -TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEntry *type_entry); -TypeTableEntry *container_ref_type(TypeTableEntry *type_entry); -bool type_is_complete(TypeTableEntry *type_entry); -bool type_is_invalid(TypeTableEntry *type_entry); -bool type_is_global_error_set(TypeTableEntry *err_set_type); -bool type_has_zero_bits_known(TypeTableEntry *type_entry); -void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry); -ScopeDecls *get_container_scope(TypeTableEntry *type_entry); -TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *name); -TypeEnumField *find_enum_type_field(TypeTableEntry *enum_type, Buf *name); -TypeUnionField *find_union_type_field(TypeTableEntry *type_entry, Buf *name); -TypeEnumField *find_enum_field_by_tag(TypeTableEntry *enum_type, const BigInt *tag); -TypeUnionField *find_union_field_by_tag(TypeTableEntry *type_entry, const BigInt *tag); - -bool is_ref(TypeTableEntry *type_entry); -bool is_array_ref(TypeTableEntry *type_entry); -bool is_container_ref(TypeTableEntry *type_entry); +bool type_is_codegen_pointer(ZigType *type); + +ZigType *get_codegen_ptr_type(ZigType *type); +uint32_t get_ptr_align(ZigType *type); +bool get_ptr_const(ZigType *type); +ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry); +ZigType *container_ref_type(ZigType *type_entry); +bool type_is_complete(ZigType *type_entry); +bool type_is_invalid(ZigType *type_entry); +bool type_is_global_error_set(ZigType *err_set_type); +bool type_has_zero_bits_known(ZigType *type_entry); +void resolve_container_type(CodeGen *g, ZigType *type_entry); +ScopeDecls *get_container_scope(ZigType *type_entry); +TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name); +TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name); +TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name); +TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag); +TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag); + +bool is_ref(ZigType *type_entry); +bool is_array_ref(ZigType *type_entry); +bool is_container_ref(ZigType *type_entry); void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node); void scan_import(CodeGen *g, ImportTableEntry *import); void preview_use_decl(CodeGen *g, AstNode *node); @@ -82,20 +82,20 @@ ImportTableEntry *get_scope_import(Scope *scope); void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope); VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name, bool is_const, ConstExprValue *init_value, Tld *src_tld); -TypeTableEntry *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node); +ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node); FnTableEntry *create_fn(AstNode *proto_node); FnTableEntry *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage); void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc); AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index); FnTableEntry *scope_get_fn_if_root(Scope *scope); -bool type_requires_comptime(TypeTableEntry *type_entry); -Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, TypeTableEntry *type_entry); -Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, TypeTableEntry *type_entry); -void complete_enum(CodeGen *g, TypeTableEntry *enum_type); +bool type_requires_comptime(ZigType *type_entry); +Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry); +Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry); +void complete_enum(CodeGen *g, ZigType *enum_type); bool ir_get_var_is_comptime(VariableTableEntry *var); bool const_values_equal(ConstExprValue *a, ConstExprValue *b); -void eval_min_max_value(CodeGen *g, TypeTableEntry *type_entry, ConstExprValue *const_val, bool is_max); -void eval_min_max_value_int(CodeGen *g, TypeTableEntry *int_type, BigInt *bigint, bool is_max); +void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max); +void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max); void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val); void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_type_node); @@ -108,7 +108,7 @@ ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent); ScopeLoop *create_loop_scope(AstNode *node, Scope *parent); ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent); ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry); -ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, TypeTableEntry *container_type, ImportTableEntry *import); +ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import); Scope *create_comptime_scope(AstNode *node, Scope *parent); Scope *create_coro_prelude_scope(AstNode *node, Scope *parent); Scope *create_runtime_scope(AstNode *node, Scope *parent, IrInstruction *is_comptime); @@ -119,39 +119,39 @@ ConstExprValue *create_const_str_lit(CodeGen *g, Buf *str); void init_const_c_str_lit(CodeGen *g, ConstExprValue *const_val, Buf *c_str); ConstExprValue *create_const_c_str_lit(CodeGen *g, Buf *c_str); -void init_const_bigint(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *bigint); -ConstExprValue *create_const_bigint(TypeTableEntry *type, const BigInt *bigint); +void init_const_bigint(ConstExprValue *const_val, ZigType *type, const BigInt *bigint); +ConstExprValue *create_const_bigint(ZigType *type, const BigInt *bigint); -void init_const_unsigned_negative(ConstExprValue *const_val, TypeTableEntry *type, uint64_t x, bool negative); -ConstExprValue *create_const_unsigned_negative(TypeTableEntry *type, uint64_t x, bool negative); +void init_const_unsigned_negative(ConstExprValue *const_val, ZigType *type, uint64_t x, bool negative); +ConstExprValue *create_const_unsigned_negative(ZigType *type, uint64_t x, bool negative); -void init_const_signed(ConstExprValue *const_val, TypeTableEntry *type, int64_t x); -ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x); +void init_const_signed(ConstExprValue *const_val, ZigType *type, int64_t x); +ConstExprValue *create_const_signed(ZigType *type, int64_t x); void init_const_usize(CodeGen *g, ConstExprValue *const_val, uint64_t x); ConstExprValue *create_const_usize(CodeGen *g, uint64_t x); -void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value); -ConstExprValue *create_const_float(TypeTableEntry *type, double value); +void init_const_float(ConstExprValue *const_val, ZigType *type, double value); +ConstExprValue *create_const_float(ZigType *type, double value); -void init_const_enum(ConstExprValue *const_val, TypeTableEntry *type, const BigInt *tag); -ConstExprValue *create_const_enum(TypeTableEntry *type, const BigInt *tag); +void init_const_enum(ConstExprValue *const_val, ZigType *type, const BigInt *tag); +ConstExprValue *create_const_enum(ZigType *type, const BigInt *tag); void init_const_bool(CodeGen *g, ConstExprValue *const_val, bool value); ConstExprValue *create_const_bool(CodeGen *g, bool value); -void init_const_type(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *type_value); -ConstExprValue *create_const_type(CodeGen *g, TypeTableEntry *type_value); +void init_const_type(CodeGen *g, ConstExprValue *const_val, ZigType *type_value); +ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value); -void init_const_runtime(ConstExprValue *const_val, TypeTableEntry *type); -ConstExprValue *create_const_runtime(TypeTableEntry *type); +void init_const_runtime(ConstExprValue *const_val, ZigType *type); +ConstExprValue *create_const_runtime(ZigType *type); void init_const_ptr_ref(CodeGen *g, ConstExprValue *const_val, ConstExprValue *pointee_val, bool is_const); ConstExprValue *create_const_ptr_ref(CodeGen *g, ConstExprValue *pointee_val, bool is_const); -void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, TypeTableEntry *pointee_type, +void init_const_ptr_hard_coded_addr(CodeGen *g, ConstExprValue *const_val, ZigType *pointee_type, size_t addr, bool is_const); -ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, TypeTableEntry *pointee_type, +ConstExprValue *create_const_ptr_hard_coded_addr(CodeGen *g, ZigType *pointee_type, size_t addr, bool is_const); void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val, @@ -170,23 +170,23 @@ void init_const_undefined(CodeGen *g, ConstExprValue *const_val); ConstExprValue *create_const_vals(size_t count); -TypeTableEntry *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); +ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits); ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value); void expand_undef_array(CodeGen *g, ConstExprValue *const_val); void update_compile_var(CodeGen *g, Buf *name, ConstExprValue *value); -const char *type_id_name(TypeTableEntryId id); -TypeTableEntryId type_id_at_index(size_t index); +const char *type_id_name(ZigTypeId id); +ZigTypeId type_id_at_index(size_t index); size_t type_id_len(); -size_t type_id_index(TypeTableEntry *entry); -TypeTableEntry *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id); -Result type_is_copyable(CodeGen *g, TypeTableEntry *type_entry); +size_t type_id_index(ZigType *entry); +ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id); +Result type_is_copyable(CodeGen *g, ZigType *type_entry); LinkLib *create_link_lib(Buf *name); bool calling_convention_does_first_arg_return(CallingConvention cc); LinkLib *add_link_lib(CodeGen *codegen, Buf *lib); -uint32_t get_abi_alignment(CodeGen *g, TypeTableEntry *type_entry); -TypeTableEntry *get_align_amt_type(CodeGen *g); +uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry); +ZigType *get_align_amt_type(CodeGen *g); PackageTableEntry *new_anonymous_package(void); Buf *const_value_to_buffer(ConstExprValue *const_val); @@ -194,17 +194,17 @@ void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, G ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name); -TypeTableEntry *get_ptr_to_stack_trace_type(CodeGen *g); -bool resolve_inferred_error_set(CodeGen *g, TypeTableEntry *err_set_type, AstNode *source_node); +ZigType *get_ptr_to_stack_trace_type(CodeGen *g); +bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node); -TypeTableEntry *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry); +ZigType *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry); uint32_t get_coro_frame_align_bytes(CodeGen *g); bool fn_type_can_fail(FnTypeId *fn_type_id); -bool type_can_fail(TypeTableEntry *type_entry); -bool fn_eval_cacheable(Scope *scope, TypeTableEntry *return_type); -AstNode *type_decl_node(TypeTableEntry *type_entry); +bool type_can_fail(ZigType *type_entry); +bool fn_eval_cacheable(Scope *scope, ZigType *return_type); +AstNode *type_decl_node(ZigType *type_entry); -TypeTableEntry *get_primitive_type(CodeGen *g, Buf *name); +ZigType *get_primitive_type(CodeGen *g, Buf *name); #endif diff --git a/src/codegen.cpp b/src/codegen.cpp index f5c1019892..caddc0e898 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -437,11 +437,11 @@ static uint32_t get_err_ret_trace_arg_index(CodeGen *g, FnTableEntry *fn_table_e if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync) { return 0; } - TypeTableEntry *fn_type = fn_table_entry->type_entry; + ZigType *fn_type = fn_table_entry->type_entry; if (!fn_type_can_fail(&fn_type->data.fn.fn_type_id)) { return UINT32_MAX; } - TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type; + ZigType *return_type = fn_type->data.fn.fn_type_id.return_type; bool first_arg_ret = type_has_bits(return_type) && handle_is_ptr(return_type); return first_arg_ret ? 1 : 0; } @@ -474,7 +474,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { } - TypeTableEntry *fn_type = fn_table_entry->type_entry; + ZigType *fn_type = fn_table_entry->type_entry; LLVMTypeRef fn_llvm_type = fn_type->data.fn.raw_type_ref; if (fn_table_entry->body_node == nullptr) { LLVMValueRef existing_llvm_fn = LLVMGetNamedFunction(g->module, buf_ptr(symbol_name)); @@ -532,7 +532,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { LLVMSetUnnamedAddr(fn_table_entry->llvm_value, true); } - TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type; + ZigType *return_type = fn_type->data.fn.fn_type_id.return_type; if (return_type->id == TypeTableEntryIdUnreachable) { addLLVMFnAttr(fn_table_entry->llvm_value, "noreturn"); } @@ -596,7 +596,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[param_i]; - TypeTableEntry *param_type = gen_info->type; + ZigType *param_type = gen_info->type; if (param_info->is_noalias) { addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "noalias"); } @@ -688,7 +688,7 @@ static void clear_debug_source_node(CodeGen *g) { ZigLLVMClearCurrentDebugLocation(g->builder); } -static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_entry, +static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry, const char *signed_name, const char *unsigned_name) { char fn_name[64]; @@ -712,7 +712,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, TypeTableEntry *type_ return fn_val; } -static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry, AddSubMul add_sub_mul) { +static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubMul add_sub_mul) { assert(type_entry->id == TypeTableEntryIdInt); ZigLLVMFnKey key = {}; @@ -742,7 +742,7 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, TypeTableEntry *type_entry, return fn_val; } -static LLVMValueRef get_float_fn(CodeGen *g, TypeTableEntry *type_entry, ZigLLVMFnId fn_id) { +static LLVMValueRef get_float_fn(CodeGen *g, ZigType *type_entry, ZigLLVMFnId fn_id) { assert(type_entry->id == TypeTableEntryIdFloat); ZigLLVMFnKey key = {}; @@ -787,7 +787,7 @@ static LLVMValueRef gen_store_untyped(CodeGen *g, LLVMValueRef value, LLVMValueR return instruction; } -static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, TypeTableEntry *ptr_type) { +static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, ZigType *ptr_type) { assert(ptr_type->id == TypeTableEntryIdPointer); return gen_store_untyped(g, value, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile); } @@ -805,12 +805,12 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alig return result; } -static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *ptr_type, const char *name) { +static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, const char *name) { assert(ptr_type->id == TypeTableEntryIdPointer); return gen_load_untyped(g, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile, name); } -static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *type, TypeTableEntry *ptr_type) { +static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type, ZigType *ptr_type) { if (type_has_bits(type)) { if (handle_is_ptr(type)) { return ptr; @@ -918,9 +918,9 @@ static LLVMValueRef get_panic_msg_ptr_val(CodeGen *g, PanicMsgId msg_id) { assert(val->global_refs->llvm_global); } - TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, + ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0); - TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type); + ZigType *str_type = get_slice_type(g, u8_ptr_type); return LLVMConstBitCast(val->global_refs->llvm_global, LLVMPointerType(str_type->type_ref, 0)); } @@ -929,7 +929,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace LLVMValueRef fn_val = fn_llvm_value(g, g->panic_fn); LLVMCallConv llvm_cc = get_llvm_cc(g, g->panic_fn->type_entry->data.fn.fn_type_id.cc); if (stack_trace_arg == nullptr) { - TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g); + ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g); stack_trace_arg = LLVMConstNull(ptr_to_stack_trace_type->type_ref); } LLVMValueRef args[] = { @@ -1186,7 +1186,7 @@ static LLVMValueRef get_return_address_fn_val(CodeGen *g) { if (g->return_address_fn_val) return g->return_address_fn_val; - TypeTableEntry *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true); + ZigType *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true); LLVMTypeRef fn_type = LLVMFunctionType(return_type->type_ref, &g->builtin_types.entry_i32->type_ref, 1, false); @@ -1237,7 +1237,7 @@ static LLVMValueRef get_add_error_return_trace_addr_fn(CodeGen *g) { size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index; LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, err_ret_trace_ptr, (unsigned)addresses_field_index, ""); - TypeTableEntry *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry; + ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry; size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index; LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, ""); size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index; @@ -1337,7 +1337,7 @@ static LLVMValueRef get_merge_err_ret_traces_fn_val(CodeGen *g) { (unsigned)src_index_field_index, ""); LLVMValueRef src_addresses_field_ptr = LLVMBuildStructGEP(g->builder, src_stack_trace_ptr, (unsigned)src_addresses_field_index, ""); - TypeTableEntry *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry; + ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry; size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index; LLVMValueRef src_ptr_field_ptr = LLVMBuildStructGEP(g->builder, src_addresses_field_ptr, (unsigned)ptr_field_index, ""); size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index; @@ -1479,7 +1479,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) { LLVMSetUnnamedAddr(global_array, true); LLVMSetAlignment(global_array, u8_align_bytes); - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; LLVMValueRef full_buf_ptr_indices[] = { LLVMConstNull(usize->type_ref), LLVMConstNull(usize->type_ref), @@ -1487,9 +1487,9 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) { LLVMValueRef full_buf_ptr = LLVMConstInBoundsGEP(global_array, full_buf_ptr_indices, 2); - TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, + ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0); - TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type); + ZigType *str_type = get_slice_type(g, u8_ptr_type); LLVMValueRef global_slice_fields[] = { full_buf_ptr, LLVMConstNull(usize->type_ref), @@ -1603,7 +1603,7 @@ static void gen_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val, Scope *sc LLVMValueRef safety_crash_err_fn = get_safety_crash_err_fn(g); LLVMValueRef err_ret_trace_val = get_cur_err_ret_trace_val(g, scope); if (err_ret_trace_val == nullptr) { - TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g); + ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g); err_ret_trace_val = LLVMConstNull(ptr_to_stack_trace_type->type_ref); } LLVMValueRef args[] = { @@ -1649,8 +1649,8 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val, LLVMPositionBuilderAtEnd(g->builder, ok_block); } -static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, TypeTableEntry *actual_type, - TypeTableEntry *wanted_type, LLVMValueRef expr_val) +static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, ZigType *actual_type, + ZigType *wanted_type, LLVMValueRef expr_val) { assert(actual_type->id == wanted_type->id); @@ -1729,7 +1729,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, T } } -static LLVMValueRef gen_overflow_op(CodeGen *g, TypeTableEntry *type_entry, AddSubMul op, +static LLVMValueRef gen_overflow_op(CodeGen *g, ZigType *type_entry, AddSubMul op, LLVMValueRef val1, LLVMValueRef val2) { LLVMValueRef fn_val = get_int_overflow_fn(g, type_entry, op); @@ -1789,11 +1789,11 @@ static LLVMRealPredicate cmp_op_to_real_predicate(IrBinOp cmp_op) { } } -static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry *ptr_type, +static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, LLVMValueRef value) { assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *child_type = ptr_type->data.pointer.child_type; + ZigType *child_type = ptr_type->data.pointer.child_type; if (!type_has_bits(child_type)) return nullptr; @@ -1807,7 +1807,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, TypeTableEntry LLVMValueRef src_ptr = LLVMBuildBitCast(g->builder, value, ptr_u8, ""); LLVMValueRef dest_ptr = LLVMBuildBitCast(g->builder, ptr, ptr_u8, ""); - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, child_type->type_ref); uint64_t align_bytes = ptr_type->data.pointer.alignment; assert(size_bytes > 0); @@ -1876,7 +1876,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) { // values are rendered with a type other than the one we expect if (handle_is_ptr(instruction->value.type)) { render_const_val_global(g, &instruction->value, ""); - TypeTableEntry *ptr_type = get_pointer_to_type(g, instruction->value.type, true); + ZigType *ptr_type = get_pointer_to_type(g, instruction->value.type, true); instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_global, ptr_type->type_ref, ""); } else if (instruction->value.type->id == TypeTableEntryIdPointer) { instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value, instruction->value.type->type_ref, ""); @@ -1904,7 +1904,7 @@ static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *execut static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrInstructionReturn *return_instruction) { LLVMValueRef value = ir_llvm_value(g, return_instruction->value); - TypeTableEntry *return_type = return_instruction->value->value.type; + ZigType *return_type = return_instruction->value->value.type; if (handle_is_ptr(return_type)) { if (calling_convention_does_first_arg_return(g->cur_fn->type_entry->data.fn.fn_type_id.cc)) { @@ -1921,7 +1921,7 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns return nullptr; } -static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry, +static LLVMValueRef gen_overflow_shl_op(CodeGen *g, ZigType *type_entry, LLVMValueRef val1, LLVMValueRef val2) { // for unsigned left shifting, we do the lossy shift, then logically shift @@ -1951,7 +1951,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry, return result; } -static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry, +static LLVMValueRef gen_overflow_shr_op(CodeGen *g, ZigType *type_entry, LLVMValueRef val1, LLVMValueRef val2) { assert(type_entry->id == TypeTableEntryIdInt); @@ -1976,7 +1976,7 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry, return result; } -static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, TypeTableEntry *type_entry) { +static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, ZigType *type_entry) { if (type_entry->id == TypeTableEntryIdInt) return val; @@ -1984,7 +1984,7 @@ static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, TypeTableEntry *type return LLVMBuildCall(g->builder, floor_fn, &val, 1, ""); } -static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, TypeTableEntry *type_entry) { +static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, ZigType *type_entry) { if (type_entry->id == TypeTableEntryIdInt) return val; @@ -2018,7 +2018,7 @@ static LLVMValueRef bigint_to_llvm_const(LLVMTypeRef type_ref, BigInt *bigint) { static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast_math, LLVMValueRef val1, LLVMValueRef val2, - TypeTableEntry *type_entry, DivKind div_kind) + ZigType *type_entry, DivKind div_kind) { ZigLLVMSetFastMath(g->builder, want_fast_math); @@ -2177,7 +2177,7 @@ enum RemKind { static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast_math, LLVMValueRef val1, LLVMValueRef val2, - TypeTableEntry *type_entry, RemKind rem_kind) + ZigType *type_entry, RemKind rem_kind) { ZigLLVMSetFastMath(g->builder, want_fast_math); @@ -2246,7 +2246,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, (op_id == IrBinOpAdd || op_id == IrBinOpSub) && op1->value.type->data.pointer.ptr_len == PtrLenUnknown) ); - TypeTableEntry *type_entry = op1->value.type; + ZigType *type_entry = op1->value.type; bool want_runtime_safety = bin_op_instruction->safety_check_on && ir_want_runtime_safety(g, &bin_op_instruction->base); @@ -2421,7 +2421,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, zig_unreachable(); } -static void add_error_range_check(CodeGen *g, TypeTableEntry *err_set_type, TypeTableEntry *int_type, LLVMValueRef target_val) { +static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *int_type, LLVMValueRef target_val) { assert(err_set_type->id == TypeTableEntryIdErrorSet); if (type_is_global_error_set(err_set_type)) { @@ -2472,8 +2472,8 @@ static void add_error_range_check(CodeGen *g, TypeTableEntry *err_set_type, Type static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, IrInstructionCast *cast_instruction) { - TypeTableEntry *actual_type = cast_instruction->value->value.type; - TypeTableEntry *wanted_type = cast_instruction->base.value.type; + ZigType *actual_type = cast_instruction->value->value.type; + ZigType *wanted_type = cast_instruction->base.value.type; LLVMValueRef expr_val = ir_llvm_value(g, cast_instruction->value); assert(expr_val); @@ -2491,10 +2491,10 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, assert(actual_type->id == TypeTableEntryIdStruct); assert(actual_type->data.structure.is_slice); - TypeTableEntry *actual_pointer_type = actual_type->data.structure.fields[0].type_entry; - TypeTableEntry *actual_child_type = actual_pointer_type->data.pointer.child_type; - TypeTableEntry *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry; - TypeTableEntry *wanted_child_type = wanted_pointer_type->data.pointer.child_type; + ZigType *actual_pointer_type = actual_type->data.structure.fields[0].type_entry; + ZigType *actual_child_type = actual_pointer_type->data.pointer.child_type; + ZigType *wanted_pointer_type = wanted_type->data.structure.fields[0].type_entry; + ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type; size_t actual_ptr_index = actual_type->data.structure.fields[slice_ptr_index].gen_index; @@ -2553,8 +2553,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, assert(wanted_type->data.structure.is_slice); assert(actual_type->id == TypeTableEntryIdArray); - TypeTableEntry *wanted_pointer_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; - TypeTableEntry *wanted_child_type = wanted_pointer_type->data.pointer.child_type; + ZigType *wanted_pointer_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type; size_t wanted_ptr_index = wanted_type->data.structure.fields[0].gen_index; @@ -2628,7 +2628,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, case CastOpPtrOfArrayToSlice: { assert(cast_instruction->tmp_ptr); assert(actual_type->id == TypeTableEntryIdPointer); - TypeTableEntry *array_type = actual_type->data.pointer.child_type; + ZigType *array_type = actual_type->data.pointer.child_type; assert(array_type->id == TypeTableEntryIdArray); LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr, @@ -2655,7 +2655,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable, IrInstructionPtrCast *instruction) { - TypeTableEntry *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value.type; if (!type_has_bits(wanted_type)) { return nullptr; } @@ -2666,7 +2666,7 @@ static LLVMValueRef ir_render_ptr_cast(CodeGen *g, IrExecutable *executable, static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable, IrInstructionBitCast *instruction) { - TypeTableEntry *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value.type; LLVMValueRef value = ir_llvm_value(g, instruction->value); return LLVMBuildBitCast(g->builder, value, wanted_type->type_ref, ""); } @@ -2674,10 +2674,10 @@ static LLVMValueRef ir_render_bit_cast(CodeGen *g, IrExecutable *executable, static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executable, IrInstructionWidenOrShorten *instruction) { - TypeTableEntry *actual_type = instruction->target->value.type; + ZigType *actual_type = instruction->target->value.type; // TODO instead of this logic, use the Noop instruction to change the type from // enum_tag to the underlying int type - TypeTableEntry *int_type; + ZigType *int_type; if (actual_type->id == TypeTableEntryIdEnum) { int_type = actual_type->data.enumeration.tag_int_type; } else { @@ -2689,21 +2689,21 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa } static LLVMValueRef ir_render_int_to_ptr(CodeGen *g, IrExecutable *executable, IrInstructionIntToPtr *instruction) { - TypeTableEntry *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value.type; LLVMValueRef target_val = ir_llvm_value(g, instruction->target); return LLVMBuildIntToPtr(g->builder, target_val, wanted_type->type_ref, ""); } static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, IrInstructionPtrToInt *instruction) { - TypeTableEntry *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value.type; LLVMValueRef target_val = ir_llvm_value(g, instruction->target); return LLVMBuildPtrToInt(g->builder, target_val, wanted_type->type_ref, ""); } static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) { - TypeTableEntry *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value.type; assert(wanted_type->id == TypeTableEntryIdEnum); - TypeTableEntry *tag_int_type = wanted_type->data.enumeration.tag_int_type; + ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type; LLVMValueRef target_val = ir_llvm_value(g, instruction->target); LLVMValueRef tag_int_value = gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base), @@ -2728,10 +2728,10 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, } static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) { - TypeTableEntry *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value.type; assert(wanted_type->id == TypeTableEntryIdErrorSet); - TypeTableEntry *actual_type = instruction->target->value.type; + ZigType *actual_type = instruction->target->value.type; assert(actual_type->id == TypeTableEntryIdInt); assert(!actual_type->data.integral.is_signed); @@ -2745,11 +2745,11 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I } static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) { - TypeTableEntry *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value.type; assert(wanted_type->id == TypeTableEntryIdInt); assert(!wanted_type->data.integral.is_signed); - TypeTableEntry *actual_type = instruction->target->value.type; + ZigType *actual_type = instruction->target->value.type; LLVMValueRef target_val = ir_llvm_value(g, instruction->target); if (actual_type->id == TypeTableEntryIdErrorSet) { @@ -2799,7 +2799,7 @@ static LLVMValueRef ir_render_br(CodeGen *g, IrExecutable *executable, IrInstruc static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInstructionUnOp *un_op_instruction) { IrUnOp op_id = un_op_instruction->op_id; LLVMValueRef expr = ir_llvm_value(g, un_op_instruction->value); - TypeTableEntry *expr_type = un_op_instruction->value->value.type; + ZigType *expr_type = un_op_instruction->value->value.type; switch (op_id) { case IrUnOpInvalid: @@ -2880,13 +2880,13 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, if (have_init_expr) { assert(var->value->type == init_value->value.type); - TypeTableEntry *var_ptr_type = get_pointer_to_type_extra(g, var->value->type, false, false, + ZigType *var_ptr_type = get_pointer_to_type_extra(g, var->value->type, false, false, PtrLenSingle, var->align_bytes, 0, 0); gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value)); } else { bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base); if (want_safe) { - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value->type->type_ref); assert(size_bytes > 0); @@ -2915,12 +2915,12 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, } static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrInstructionLoadPtr *instruction) { - TypeTableEntry *child_type = instruction->base.value.type; + ZigType *child_type = instruction->base.value.type; if (!type_has_bits(child_type)) return nullptr; LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr); - TypeTableEntry *ptr_type = instruction->ptr->value.type; + ZigType *ptr_type = instruction->ptr->value.type; assert(ptr_type->id == TypeTableEntryIdPointer); uint32_t unaligned_bit_count = ptr_type->data.pointer.unaligned_bit_count; @@ -2947,7 +2947,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir LLVMValueRef value = ir_llvm_value(g, instruction->value); assert(instruction->ptr->value.type->id == TypeTableEntryIdPointer); - TypeTableEntry *ptr_type = instruction->ptr->value.type; + ZigType *ptr_type = instruction->ptr->value.type; gen_assign_raw(g, ptr, ptr_type, value); @@ -2966,9 +2966,9 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) { LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr); - TypeTableEntry *array_ptr_type = instruction->array_ptr->value.type; + ZigType *array_ptr_type = instruction->array_ptr->value.type; assert(array_ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *array_type = array_ptr_type->data.pointer.child_type; + ZigType *array_type = array_ptr_type->data.pointer.child_type; LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type); LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index); assert(subscript_value); @@ -2993,7 +2993,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI if (array_ptr_type->data.pointer.unaligned_bit_count != 0) { return array_ptr_ptr; } - TypeTableEntry *child_type = array_type->data.array.child_type; + ZigType *child_type = array_type->data.array.child_type; if (child_type->id == TypeTableEntryIdStruct && child_type->data.structure.layout == ContainerLayoutPacked) { @@ -3113,7 +3113,7 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) { static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) { LLVMValueRef fn_val; - TypeTableEntry *fn_type; + ZigType *fn_type; if (instruction->fn_entry) { fn_val = fn_llvm_value(g, instruction->fn_entry); fn_type = instruction->fn_entry->type_entry; @@ -3125,7 +3125,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; - TypeTableEntry *src_return_type = fn_type_id->return_type; + ZigType *src_return_type = fn_type_id->return_type; bool ret_has_bits = type_has_bits(src_return_type); bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type) && @@ -3154,7 +3154,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr } for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) { IrInstruction *param_instruction = instruction->args[call_i]; - TypeTableEntry *param_type = param_instruction->value.type; + ZigType *param_type = param_instruction->value.type; if (is_var_args || type_has_bits(param_type)) { LLVMValueRef param_value = ir_llvm_value(g, param_instruction); assert(param_value); @@ -3222,7 +3222,7 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa { LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr); // not necessarily a pointer. could be TypeTableEntryIdStruct - TypeTableEntry *struct_ptr_type = instruction->struct_ptr->value.type; + ZigType *struct_ptr_type = instruction->struct_ptr->value.type; TypeStructField *field = instruction->field; if (!type_has_bits(field->type_entry)) @@ -3241,9 +3241,9 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executable, IrInstructionUnionFieldPtr *instruction) { - TypeTableEntry *union_ptr_type = instruction->union_ptr->value.type; + ZigType *union_ptr_type = instruction->union_ptr->value.type; assert(union_ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *union_type = union_ptr_type->data.pointer.child_type; + ZigType *union_type = union_ptr_type->data.pointer.child_type; assert(union_type->id == TypeTableEntryIdUnion); TypeUnionField *field = instruction->field; @@ -3411,9 +3411,9 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru return LLVMBuildCall(g->builder, asm_fn, param_values, (unsigned)input_and_output_count, ""); } -static LLVMValueRef gen_non_null_bit(CodeGen *g, TypeTableEntry *maybe_type, LLVMValueRef maybe_handle) { +static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) { assert(maybe_type->id == TypeTableEntryIdOptional); - TypeTableEntry *child_type = maybe_type->data.maybe.child_type; + ZigType *child_type = maybe_type->data.maybe.child_type; if (child_type->zero_bits) { return maybe_handle; } else { @@ -3436,11 +3436,11 @@ static LLVMValueRef ir_render_test_non_null(CodeGen *g, IrExecutable *executable static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapOptional *instruction) { - TypeTableEntry *ptr_type = instruction->value->value.type; + ZigType *ptr_type = instruction->value->value.type; assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *maybe_type = ptr_type->data.pointer.child_type; + ZigType *maybe_type = ptr_type->data.pointer.child_type; assert(maybe_type->id == TypeTableEntryIdOptional); - TypeTableEntry *child_type = maybe_type->data.maybe.child_type; + ZigType *child_type = maybe_type->data.maybe.child_type; LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value); LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type); if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on) { @@ -3467,7 +3467,7 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable, } } -static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, BuiltinFnId fn_id) { +static LLVMValueRef get_int_builtin_fn(CodeGen *g, ZigType *int_type, BuiltinFnId fn_id) { ZigLLVMFnKey key = {}; const char *fn_name; uint32_t n_args; @@ -3510,7 +3510,7 @@ static LLVMValueRef get_int_builtin_fn(CodeGen *g, TypeTableEntry *int_type, Bui } static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstructionClz *instruction) { - TypeTableEntry *int_type = instruction->value->value.type; + ZigType *int_type = instruction->value->value.type; LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdClz); LLVMValueRef operand = ir_llvm_value(g, instruction->value); LLVMValueRef params[] { @@ -3522,7 +3522,7 @@ static LLVMValueRef ir_render_clz(CodeGen *g, IrExecutable *executable, IrInstru } static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstructionCtz *instruction) { - TypeTableEntry *int_type = instruction->value->value.type; + ZigType *int_type = instruction->value->value.type; LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdCtz); LLVMValueRef operand = ir_llvm_value(g, instruction->value); LLVMValueRef params[] { @@ -3534,7 +3534,7 @@ static LLVMValueRef ir_render_ctz(CodeGen *g, IrExecutable *executable, IrInstru } static LLVMValueRef ir_render_pop_count(CodeGen *g, IrExecutable *executable, IrInstructionPopCount *instruction) { - TypeTableEntry *int_type = instruction->value->value.type; + ZigType *int_type = instruction->value->value.type; LLVMValueRef fn_val = get_int_builtin_fn(g, int_type, BuiltinFnIdPopCount); LLVMValueRef operand = ir_llvm_value(g, instruction->value); LLVMValueRef wrong_size_int = LLVMBuildCall(g->builder, fn_val, &operand, 1, ""); @@ -3611,15 +3611,15 @@ static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrI return LLVMBuildInBoundsGEP(g->builder, g->err_name_table, indices, 2, ""); } -static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_type) { +static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) { assert(enum_type->id == TypeTableEntryIdEnum); if (enum_type->data.enumeration.name_function) return enum_type->data.enumeration.name_function; - TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false, + ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false, PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0); - TypeTableEntry *u8_slice_type = get_slice_type(g, u8_ptr_type); - TypeTableEntry *tag_int_type = enum_type->data.enumeration.tag_int_type; + ZigType *u8_slice_type = get_slice_type(g, u8_ptr_type); + ZigType *tag_int_type = enum_type->data.enumeration.tag_int_type; LLVMTypeRef fn_type_ref = LLVMFunctionType(LLVMPointerType(u8_slice_type->type_ref, 0), &tag_int_type->type_ref, 1, false); @@ -3652,7 +3652,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_ LLVMValueRef switch_instr = LLVMBuildSwitch(g->builder, tag_int_value, bad_value_block, field_count); - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; LLVMValueRef array_ptr_indices[] = { LLVMConstNull(usize->type_ref), LLVMConstNull(usize->type_ref), @@ -3709,7 +3709,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, TypeTableEntry *enum_ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable, IrInstructionTagName *instruction) { - TypeTableEntry *enum_type = instruction->target->value.type; + ZigType *enum_type = instruction->target->value.type; assert(enum_type->id == TypeTableEntryIdEnum); LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type); @@ -3722,10 +3722,10 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executable, IrInstructionFieldParentPtr *instruction) { - TypeTableEntry *container_ptr_type = instruction->base.value.type; + ZigType *container_ptr_type = instruction->base.value.type; assert(container_ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *container_type = container_ptr_type->data.pointer.child_type; + ZigType *container_type = container_ptr_type->data.pointer.child_type; size_t byte_offset = LLVMOffsetOfElement(g->target_data_ref, container_type->type_ref, instruction->field->gen_index); @@ -3735,7 +3735,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa if (byte_offset == 0) { return LLVMBuildBitCast(g->builder, field_ptr_val, container_ptr_type->type_ref, ""); } else { - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; LLVMValueRef field_ptr_int = LLVMBuildPtrToInt(g->builder, field_ptr_val, usize->type_ref, ""); @@ -3756,7 +3756,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I return target_val; } - TypeTableEntry *target_type = instruction->base.value.type; + ZigType *target_type = instruction->base.value.type; uint32_t align_bytes; LLVMValueRef ptr_val; @@ -3781,7 +3781,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I { zig_panic("TODO audit this function"); } else if (target_type->id == TypeTableEntryIdStruct && target_type->data.structure.is_slice) { - TypeTableEntry *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; align_bytes = slice_ptr_type->data.pointer.alignment; size_t ptr_index = target_type->data.structure.fields[slice_ptr_index].gen_index; @@ -3793,7 +3793,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I assert(align_bytes != 1); - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; LLVMValueRef ptr_as_int_val = LLVMBuildPtrToInt(g->builder, ptr_val, usize->type_ref, ""); LLVMValueRef alignment_minus_1 = LLVMConstInt(usize->type_ref, align_bytes - 1, false); LLVMValueRef anded_val = LLVMBuildAnd(g->builder, ptr_as_int_val, alignment_minus_1, ""); @@ -3817,7 +3817,7 @@ static LLVMValueRef ir_render_error_return_trace(CodeGen *g, IrExecutable *execu { LLVMValueRef cur_err_ret_trace_val = get_cur_err_ret_trace_val(g, instruction->base.scope); if (cur_err_ret_trace_val == nullptr) { - TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g); + ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(g); return LLVMConstNull(ptr_to_stack_trace_type->type_ref); } return cur_err_ret_trace_val; @@ -3877,9 +3877,9 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn LLVMValueRef result_val = ZigLLVMBuildCmpXchg(g->builder, ptr_val, cmp_val, new_val, success_order, failure_order, instruction->is_weak); - TypeTableEntry *maybe_type = instruction->base.value.type; + ZigType *maybe_type = instruction->base.value.type; assert(maybe_type->id == TypeTableEntryIdOptional); - TypeTableEntry *child_type = maybe_type->data.maybe.child_type; + ZigType *child_type = maybe_type->data.maybe.child_type; if (type_is_codegen_pointer(child_type)) { LLVMValueRef payload_val = LLVMBuildExtractValue(g->builder, result_val, 0, ""); @@ -3909,8 +3909,8 @@ static LLVMValueRef ir_render_fence(CodeGen *g, IrExecutable *executable, IrInst static LLVMValueRef ir_render_truncate(CodeGen *g, IrExecutable *executable, IrInstructionTruncate *instruction) { LLVMValueRef target_val = ir_llvm_value(g, instruction->target); - TypeTableEntry *dest_type = instruction->base.value.type; - TypeTableEntry *src_type = instruction->target->value.type; + ZigType *dest_type = instruction->base.value.type; + ZigType *src_type = instruction->target->value.type; if (dest_type == src_type) { // no-op return target_val; @@ -3931,7 +3931,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); - TypeTableEntry *ptr_type = instruction->dest_ptr->value.type; + ZigType *ptr_type = instruction->dest_ptr->value.type; assert(ptr_type->id == TypeTableEntryIdPointer); LLVMValueRef is_volatile = ptr_type->data.pointer.is_volatile ? @@ -3961,8 +3961,8 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); LLVMValueRef src_ptr_casted = LLVMBuildBitCast(g->builder, src_ptr, ptr_u8, ""); - TypeTableEntry *dest_ptr_type = instruction->dest_ptr->value.type; - TypeTableEntry *src_ptr_type = instruction->src_ptr->value.type; + ZigType *dest_ptr_type = instruction->dest_ptr->value.type; + ZigType *src_ptr_type = instruction->src_ptr->value.type; assert(dest_ptr_type->id == TypeTableEntryIdPointer); assert(src_ptr_type->id == TypeTableEntryIdPointer); @@ -3989,9 +3989,9 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst assert(instruction->tmp_ptr); LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr); - TypeTableEntry *array_ptr_type = instruction->ptr->value.type; + ZigType *array_ptr_type = instruction->ptr->value.type; assert(array_ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *array_type = array_ptr_type->data.pointer.child_type; + ZigType *array_type = array_ptr_type->data.pointer.child_type; LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type); LLVMValueRef tmp_struct_ptr = instruction->tmp_ptr; @@ -4140,7 +4140,7 @@ static LLVMValueRef get_frame_address_fn_val(CodeGen *g) { if (g->frame_address_fn_val) return g->frame_address_fn_val; - TypeTableEntry *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true); + ZigType *return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, true); LLVMTypeRef fn_type = LLVMFunctionType(return_type->type_ref, &g->builtin_types.entry_i32->type_ref, 1, false); @@ -4178,7 +4178,7 @@ static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable, } static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) { - TypeTableEntry *int_type = instruction->result_ptr_type; + ZigType *int_type = instruction->result_ptr_type; assert(int_type->id == TypeTableEntryIdInt); LLVMValueRef op1 = ir_llvm_value(g, instruction->op1); @@ -4218,7 +4218,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable, return render_shl_with_overflow(g, instruction); } - TypeTableEntry *int_type = instruction->result_ptr_type; + ZigType *int_type = instruction->result_ptr_type; assert(int_type->id == TypeTableEntryIdInt); LLVMValueRef fn_val = get_int_overflow_fn(g, int_type, add_sub_mul); @@ -4241,8 +4241,8 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable, } static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrInstructionTestErr *instruction) { - TypeTableEntry *err_union_type = instruction->value->value.type; - TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type; + ZigType *err_union_type = instruction->value->value.type; + ZigType *payload_type = err_union_type->data.error_union.payload_type; LLVMValueRef err_union_handle = ir_llvm_value(g, instruction->value); LLVMValueRef err_val; @@ -4258,10 +4258,10 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI } static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) { - TypeTableEntry *ptr_type = instruction->value->value.type; + ZigType *ptr_type = instruction->value->value.type; assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type; - TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type; + ZigType *err_union_type = ptr_type->data.pointer.child_type; + ZigType *payload_type = err_union_type->data.error_union.payload_type; LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value); LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type); @@ -4274,10 +4274,10 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab } static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) { - TypeTableEntry *ptr_type = instruction->value->value.type; + ZigType *ptr_type = instruction->value->value.type; assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *err_union_type = ptr_type->data.pointer.child_type; - TypeTableEntry *payload_type = err_union_type->data.error_union.payload_type; + ZigType *err_union_type = ptr_type->data.pointer.child_type; + ZigType *payload_type = err_union_type->data.error_union.payload_type; LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value); LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type); @@ -4313,11 +4313,11 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu } static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) { - TypeTableEntry *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value.type; assert(wanted_type->id == TypeTableEntryIdOptional); - TypeTableEntry *child_type = wanted_type->data.maybe.child_type; + ZigType *child_type = wanted_type->data.maybe.child_type; if (child_type->zero_bits) { return LLVMConstInt(LLVMInt1Type(), 1, false); @@ -4340,12 +4340,12 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I } static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) { - TypeTableEntry *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value.type; assert(wanted_type->id == TypeTableEntryIdErrorUnion); - TypeTableEntry *payload_type = wanted_type->data.error_union.payload_type; - TypeTableEntry *err_set_type = wanted_type->data.error_union.err_set_type; + ZigType *payload_type = wanted_type->data.error_union.payload_type; + ZigType *err_set_type = wanted_type->data.error_union.err_set_type; LLVMValueRef err_val = ir_llvm_value(g, instruction->value); @@ -4361,12 +4361,12 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable } static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) { - TypeTableEntry *wanted_type = instruction->base.value.type; + ZigType *wanted_type = instruction->base.value.type; assert(wanted_type->id == TypeTableEntryIdErrorUnion); - TypeTableEntry *payload_type = wanted_type->data.error_union.payload_type; - TypeTableEntry *err_set_type = wanted_type->data.error_union.err_set_type; + ZigType *payload_type = wanted_type->data.error_union.payload_type; + ZigType *err_set_type = wanted_type->data.error_union.err_set_type; if (!type_has_bits(err_set_type)) { return ir_llvm_value(g, instruction->value); @@ -4391,10 +4391,10 @@ static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executa } static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, IrInstructionUnionTag *instruction) { - TypeTableEntry *union_type = instruction->value->value.type; + ZigType *union_type = instruction->value->value.type; assert(union_type->data.unionation.gen_tag_index != SIZE_MAX); - TypeTableEntry *tag_type = union_type->data.unionation.tag_type; + ZigType *tag_type = union_type->data.unionation.tag_type; if (!type_has_bits(tag_type)) return nullptr; @@ -4404,7 +4404,7 @@ static LLVMValueRef ir_render_union_tag(CodeGen *g, IrExecutable *executable, Ir LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_val, union_type->data.unionation.gen_tag_index, ""); - TypeTableEntry *ptr_type = get_pointer_to_type(g, tag_type, false); + ZigType *ptr_type = get_pointer_to_type(g, tag_type, false); return get_handle_value(g, tag_field_ptr, tag_type, ptr_type); } @@ -4421,7 +4421,7 @@ static LLVMValueRef ir_render_struct_init(CodeGen *g, IrExecutable *executable, uint32_t field_align_bytes = get_abi_alignment(g, type_struct_field->type_entry); - TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_struct_field->type_entry, + ZigType *ptr_type = get_pointer_to_type_extra(g, type_struct_field->type_entry, false, false, PtrLenSingle, field_align_bytes, (uint32_t)type_struct_field->packed_bits_offset, (uint32_t)type_struct_field->unaligned_bit_count); @@ -4437,14 +4437,14 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I return nullptr; uint32_t field_align_bytes = get_abi_alignment(g, type_union_field->type_entry); - TypeTableEntry *ptr_type = get_pointer_to_type_extra(g, type_union_field->type_entry, + ZigType *ptr_type = get_pointer_to_type_extra(g, type_union_field->type_entry, false, false, PtrLenSingle, field_align_bytes, 0, 0); LLVMValueRef uncasted_union_ptr; // Even if safety is off in this block, if the union type has the safety field, we have to populate it // correctly. Otherwise safety code somewhere other than here could fail. - TypeTableEntry *union_type = instruction->union_type; + ZigType *union_type = instruction->union_type; if (union_type->data.unionation.gen_tag_index != SIZE_MAX) { LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, union_type->data.unionation.gen_tag_index, ""); @@ -4470,14 +4470,14 @@ static LLVMValueRef ir_render_union_init(CodeGen *g, IrExecutable *executable, I static LLVMValueRef ir_render_container_init_list(CodeGen *g, IrExecutable *executable, IrInstructionContainerInitList *instruction) { - TypeTableEntry *array_type = instruction->base.value.type; + ZigType *array_type = instruction->base.value.type; assert(array_type->id == TypeTableEntryIdArray); LLVMValueRef tmp_array_ptr = instruction->tmp_ptr; assert(tmp_array_ptr); size_t field_count = instruction->item_count; - TypeTableEntry *child_type = array_type->data.array.child_type; + ZigType *child_type = array_type->data.array.child_type; for (size_t i = 0; i < field_count; i += 1) { LLVMValueRef elem_val = ir_llvm_value(g, instruction->items[i]); LLVMValueRef indices[] = { @@ -4601,13 +4601,13 @@ static LLVMValueRef ir_render_coro_promise(CodeGen *g, IrExecutable *executable, return LLVMBuildBitCast(g->builder, uncasted_result, instruction->base.value.type->type_ref, ""); } -static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_fn_type_ref, TypeTableEntry *fn_type) { +static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_fn_type_ref, ZigType *fn_type) { if (g->coro_alloc_helper_fn_val != nullptr) return g->coro_alloc_helper_fn_val; assert(fn_type->id == TypeTableEntryIdFn); - TypeTableEntry *ptr_to_err_code_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false); + ZigType *ptr_to_err_code_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false); LLVMTypeRef alloc_raw_fn_type_ref = LLVMGetElementType(alloc_fn_type_ref); LLVMTypeRef *alloc_fn_arg_types = allocate(LLVMCountParamTypes(alloc_raw_fn_type_ref)); @@ -4686,9 +4686,9 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f LLVMPositionBuilderAtEnd(g->builder, ok_block); LLVMValueRef payload_ptr = LLVMBuildStructGEP(g->builder, sret_ptr, err_union_payload_index, ""); - TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false, + ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, false, false, PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0); - TypeTableEntry *slice_type = get_slice_type(g, u8_ptr_type); + ZigType *slice_type = get_slice_type(g, u8_ptr_type); size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index; LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, payload_ptr, ptr_field_index, ""); LLVMValueRef ptr_val = LLVMBuildLoad(g->builder, ptr_field_ptr, ""); @@ -4733,7 +4733,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable, IrInstructionAtomicRmw *instruction) { bool is_signed; - TypeTableEntry *operand_type = instruction->operand->value.type; + ZigType *operand_type = instruction->operand->value.type; if (operand_type->id == TypeTableEntryIdInt) { is_signed = operand_type->data.integral.is_signed; } else { @@ -5090,14 +5090,14 @@ static LLVMValueRef gen_const_ptr_array_recursive(CodeGen *g, ConstExprValue *ar LLVMTypeKind el_type = LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(base_ptr))); if (el_type == LLVMArrayTypeKind) { - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; LLVMValueRef indices[] = { LLVMConstNull(usize->type_ref), LLVMConstInt(usize->type_ref, index, false), }; return LLVMConstInBoundsGEP(base_ptr, indices, 2); } else if (el_type == LLVMStructTypeKind) { - TypeTableEntry *u32 = g->builtin_types.entry_u32; + ZigType *u32 = g->builtin_types.entry_u32; LLVMValueRef indices[] = { LLVMConstNull(u32->type_ref), LLVMConstInt(u32->type_ref, index, false), @@ -5113,7 +5113,7 @@ static LLVMValueRef gen_const_ptr_struct_recursive(CodeGen *g, ConstExprValue *s ConstParent *parent = &struct_const_val->data.x_struct.parent; LLVMValueRef base_ptr = gen_parent_ptr(g, struct_const_val, parent); - TypeTableEntry *u32 = g->builtin_types.entry_u32; + ZigType *u32 = g->builtin_types.entry_u32; LLVMValueRef indices[] = { LLVMConstNull(u32->type_ref), LLVMConstInt(u32->type_ref, field_index, false), @@ -5125,7 +5125,7 @@ static LLVMValueRef gen_const_ptr_union_recursive(CodeGen *g, ConstExprValue *un ConstParent *parent = &union_const_val->data.x_union.parent; LLVMValueRef base_ptr = gen_parent_ptr(g, union_const_val, parent); - TypeTableEntry *u32 = g->builtin_types.entry_u32; + ZigType *u32 = g->builtin_types.entry_u32; LLVMValueRef indices[] = { LLVMConstNull(u32->type_ref), LLVMConstInt(u32->type_ref, 0, false), // TODO test const union with more aligned tag type than payload @@ -5143,7 +5143,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con break; } - TypeTableEntry *type_entry = const_val->type; + ZigType *type_entry = const_val->type; assert(!type_entry->zero_bits); switch (type_entry->id) { case TypeTableEntryIdInvalid: @@ -5228,7 +5228,7 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con // We have this because union constants can't be represented by the official union type, // and this property bubbles up in whatever aggregate type contains a union constant -static bool is_llvm_value_unnamed_type(TypeTableEntry *type_entry, LLVMValueRef val) { +static bool is_llvm_value_unnamed_type(ZigType *type_entry, LLVMValueRef val) { return LLVMTypeOf(val) != type_entry->type_ref; } @@ -5256,7 +5256,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con assert(array_const_val->type->id == TypeTableEntryIdArray); if (array_const_val->type->zero_bits) { // make this a null pointer - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref), const_val->type->type_ref); render_const_val_global(g, const_val, ""); @@ -5276,7 +5276,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con assert(struct_const_val->type->id == TypeTableEntryIdStruct); if (struct_const_val->type->zero_bits) { // make this a null pointer - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstNull(usize->type_ref), const_val->type->type_ref); render_const_val_global(g, const_val, ""); @@ -5296,7 +5296,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con { render_const_val_global(g, const_val, name); uint64_t addr_value = const_val->data.x_ptr.data.hard_coded_addr.addr; - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; const_val->global_refs->llvm_value = LLVMConstIntToPtr(LLVMConstInt(usize->type_ref, addr_value, false), const_val->type->type_ref); render_const_val_global(g, const_val, ""); @@ -5309,7 +5309,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con } static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const char *name) { - TypeTableEntry *type_entry = const_val->type; + ZigType *type_entry = const_val->type; assert(!type_entry->zero_bits); switch (const_val->special) { @@ -5356,7 +5356,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c } case TypeTableEntryIdOptional: { - TypeTableEntry *child_type = type_entry->data.maybe.child_type; + ZigType *child_type = type_entry->data.maybe.child_type; if (child_type->zero_bits) { return LLVMConstInt(LLVMInt1Type(), const_val->data.x_optional ? 1 : 0, false); } else if (type_is_codegen_pointer(child_type)) { @@ -5559,8 +5559,8 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c return gen_const_val_ptr(g, const_val, name); case TypeTableEntryIdErrorUnion: { - TypeTableEntry *payload_type = type_entry->data.error_union.payload_type; - TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type; + ZigType *payload_type = type_entry->data.error_union.payload_type; + ZigType *err_set_type = type_entry->data.error_union.err_set_type; if (!type_has_bits(payload_type)) { assert(type_has_bits(err_set_type)); uint64_t value = const_val->data.x_err_union.err ? const_val->data.x_err_union.err->value : 0; @@ -5650,9 +5650,9 @@ static void generate_error_name_table(CodeGen *g) { assert(g->errors_by_index.length > 0); - TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, + ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0); - TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type); + ZigType *str_type = get_slice_type(g, u8_ptr_type); LLVMValueRef *values = allocate(g->errors_by_index.length); values[0] = LLVMGetUndef(str_type->type_ref); @@ -5700,7 +5700,7 @@ static void build_all_basic_blocks(CodeGen *g, FnTableEntry *fn) { } static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef init_val, - TypeTableEntry *type_entry) + ZigType *type_entry) { if (g->strip_debug_symbols) { return; @@ -5721,7 +5721,7 @@ static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef ini // TODO ^^ make an actual global variable } -static LLVMValueRef build_alloca(CodeGen *g, TypeTableEntry *type_entry, const char *name, uint32_t alignment) { +static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) { assert(alignment > 0); LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name); LLVMSetAlignment(result, alignment); @@ -5794,7 +5794,7 @@ static void do_code_gen(CodeGen *g) { // Generate debug info for it but that's it. ConstExprValue *const_val = var->value; assert(const_val->special != ConstValSpecialRuntime); - TypeTableEntry *var_type = g->builtin_types.entry_f128; + ZigType *var_type = g->builtin_types.entry_f128; ConstExprValue coerced_value; coerced_value.special = ConstValSpecialStatic; coerced_value.type = var_type; @@ -5812,7 +5812,7 @@ static void do_code_gen(CodeGen *g) { if (bits_needed < 8) { bits_needed = 8; } - TypeTableEntry *var_type = get_int_type(g, const_val->data.x_bigint.is_negative, bits_needed); + ZigType *var_type = get_int_type(g, const_val->data.x_bigint.is_negative, bits_needed); LLVMValueRef init_val = bigint_to_llvm_const(var_type->type_ref, &const_val->data.x_bigint); gen_global_var(g, var, init_val, var_type); continue; @@ -5869,7 +5869,7 @@ static void do_code_gen(CodeGen *g) { LLVMValueRef fn = fn_llvm_value(g, fn_table_entry); g->cur_fn = fn_table_entry; g->cur_fn_val = fn; - TypeTableEntry *return_type = fn_table_entry->type_entry->data.fn.fn_type_id.return_type; + ZigType *return_type = fn_table_entry->type_entry->data.fn.fn_type_id.return_type; if (handle_is_ptr(return_type)) { g->cur_ret_ptr = LLVMGetParam(fn, 0); } else { @@ -5892,7 +5892,7 @@ static void do_code_gen(CodeGen *g) { bool have_err_ret_trace_stack = g->have_err_ret_tracing && fn_table_entry->calls_or_awaits_errorable_fn && !is_async && !have_err_ret_trace_arg; LLVMValueRef err_ret_array_val = nullptr; if (have_err_ret_trace_stack) { - TypeTableEntry *array_type = get_array_type(g, g->builtin_types.entry_usize, stack_trace_ptr_count); + ZigType *array_type = get_array_type(g, g->builtin_types.entry_usize, stack_trace_ptr_count); err_ret_array_val = build_alloca(g, array_type, "error_return_trace_addresses", get_abi_alignment(g, array_type)); g->cur_err_ret_trace_val_stack = build_alloca(g, g->stack_trace_type, "error_return_trace", get_abi_alignment(g, g->stack_trace_type)); } else { @@ -5903,7 +5903,7 @@ static void do_code_gen(CodeGen *g) { for (size_t alloca_i = 0; alloca_i < fn_table_entry->alloca_list.length; alloca_i += 1) { IrInstruction *instruction = fn_table_entry->alloca_list.at(alloca_i); LLVMValueRef *slot; - TypeTableEntry *slot_type = instruction->value.type; + ZigType *slot_type = instruction->value.type; if (instruction->id == IrInstructionIdCast) { IrInstructionCast *cast_instruction = (IrInstructionCast *)instruction; slot = &cast_instruction->tmp_ptr; @@ -5968,7 +5968,7 @@ static void do_code_gen(CodeGen *g) { } else { assert(var->gen_arg_index != SIZE_MAX); - TypeTableEntry *gen_type; + ZigType *gen_type; FnGenParamInfo *gen_info = &fn_table_entry->type_entry->data.fn.gen_param_info[var->src_arg_index]; if (handle_is_ptr(var->value->type)) { @@ -5994,7 +5994,7 @@ static void do_code_gen(CodeGen *g) { // finishing error return trace setup. we have to do this after all the allocas. if (have_err_ret_trace_stack) { - TypeTableEntry *usize = g->builtin_types.entry_usize; + ZigType *usize = g->builtin_types.entry_usize; size_t index_field_index = g->stack_trace_type->data.structure.fields[0].gen_index; LLVMValueRef index_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)index_field_index, ""); gen_store_untyped(g, LLVMConstNull(usize->type_ref), index_field_ptr, 0, false); @@ -6002,14 +6002,14 @@ static void do_code_gen(CodeGen *g) { size_t addresses_field_index = g->stack_trace_type->data.structure.fields[1].gen_index; LLVMValueRef addresses_field_ptr = LLVMBuildStructGEP(g->builder, g->cur_err_ret_trace_val_stack, (unsigned)addresses_field_index, ""); - TypeTableEntry *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry; + ZigType *slice_type = g->stack_trace_type->data.structure.fields[1].type_entry; size_t ptr_field_index = slice_type->data.structure.fields[slice_ptr_index].gen_index; LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, addresses_field_ptr, (unsigned)ptr_field_index, ""); LLVMValueRef zero = LLVMConstNull(usize->type_ref); LLVMValueRef indices[] = {zero, zero}; LLVMValueRef err_ret_array_val_elem0_ptr = LLVMBuildInBoundsGEP(g->builder, err_ret_array_val, indices, 2, ""); - TypeTableEntry *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false); + ZigType *ptr_ptr_usize_type = get_pointer_to_type(g, get_pointer_to_type(g, usize, false), false); gen_store(g, err_ret_array_val_elem0_ptr, ptr_field_ptr, ptr_ptr_usize_type); size_t len_field_index = slice_type->data.structure.fields[slice_len_index].gen_index; @@ -6173,51 +6173,51 @@ static const GlobalLinkageValue global_linkage_values[] = { static void define_builtin_types(CodeGen *g) { { // if this type is anywhere in the AST, we should never hit codegen. - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInvalid); + ZigType *entry = new_type_table_entry(TypeTableEntryIdInvalid); buf_init_from_str(&entry->name, "(invalid)"); entry->zero_bits = true; g->builtin_types.entry_invalid = entry; } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNamespace); + ZigType *entry = new_type_table_entry(TypeTableEntryIdNamespace); buf_init_from_str(&entry->name, "(namespace)"); entry->zero_bits = true; g->builtin_types.entry_namespace = entry; } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdBlock); + ZigType *entry = new_type_table_entry(TypeTableEntryIdBlock); buf_init_from_str(&entry->name, "(block)"); entry->zero_bits = true; g->builtin_types.entry_block = entry; } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdComptimeFloat); + ZigType *entry = new_type_table_entry(TypeTableEntryIdComptimeFloat); buf_init_from_str(&entry->name, "comptime_float"); entry->zero_bits = true; g->builtin_types.entry_num_lit_float = entry; g->primitive_type_table.put(&entry->name, entry); } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdComptimeInt); + ZigType *entry = new_type_table_entry(TypeTableEntryIdComptimeInt); buf_init_from_str(&entry->name, "comptime_int"); entry->zero_bits = true; g->builtin_types.entry_num_lit_int = entry; g->primitive_type_table.put(&entry->name, entry); } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUndefined); + ZigType *entry = new_type_table_entry(TypeTableEntryIdUndefined); buf_init_from_str(&entry->name, "(undefined)"); entry->zero_bits = true; g->builtin_types.entry_undef = entry; } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNull); + ZigType *entry = new_type_table_entry(TypeTableEntryIdNull); buf_init_from_str(&entry->name, "(null)"); entry->zero_bits = true; g->builtin_types.entry_null = entry; } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdArgTuple); + ZigType *entry = new_type_table_entry(TypeTableEntryIdArgTuple); buf_init_from_str(&entry->name, "(args)"); entry->zero_bits = true; g->builtin_types.entry_arg_tuple = entry; @@ -6228,7 +6228,7 @@ static void define_builtin_types(CodeGen *g) { uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id); bool is_signed = info->is_signed; - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt); + ZigType *entry = new_type_table_entry(TypeTableEntryIdInt); entry->type_ref = LLVMIntType(size_in_bits); buf_init_from_str(&entry->name, info->name); @@ -6245,7 +6245,7 @@ static void define_builtin_types(CodeGen *g) { } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdBool); + ZigType *entry = new_type_table_entry(TypeTableEntryIdBool); entry->type_ref = LLVMInt1Type(); buf_init_from_str(&entry->name, "bool"); uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref); @@ -6259,7 +6259,7 @@ static void define_builtin_types(CodeGen *g) { for (size_t sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) { bool is_signed = is_signed_list[sign_i]; - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdInt); + ZigType *entry = new_type_table_entry(TypeTableEntryIdInt); entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8); const char u_or_i = is_signed ? 'i' : 'u'; @@ -6286,8 +6286,8 @@ static void define_builtin_types(CodeGen *g) { const char *name, uint32_t bit_count, LLVMTypeRef type_ref, - TypeTableEntry **field) { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdFloat); + ZigType **field) { + ZigType *entry = new_type_table_entry(TypeTableEntryIdFloat); entry->type_ref = type_ref; buf_init_from_str(&entry->name, name); entry->data.floating.bit_count = bit_count; @@ -6306,7 +6306,7 @@ static void define_builtin_types(CodeGen *g) { add_fp_entry(g, "c_longdouble", 80, LLVMX86FP80Type(), &g->builtin_types.entry_c_longdouble); { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdVoid); + ZigType *entry = new_type_table_entry(TypeTableEntryIdVoid); entry->type_ref = LLVMVoidType(); entry->zero_bits = true; buf_init_from_str(&entry->name, "void"); @@ -6317,7 +6317,7 @@ static void define_builtin_types(CodeGen *g) { g->primitive_type_table.put(&entry->name, entry); } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUnreachable); + ZigType *entry = new_type_table_entry(TypeTableEntryIdUnreachable); entry->type_ref = LLVMVoidType(); entry->zero_bits = true; buf_init_from_str(&entry->name, "noreturn"); @@ -6326,7 +6326,7 @@ static void define_builtin_types(CodeGen *g) { g->primitive_type_table.put(&entry->name, entry); } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdMetaType); + ZigType *entry = new_type_table_entry(TypeTableEntryIdMetaType); buf_init_from_str(&entry->name, "type"); entry->zero_bits = true; g->builtin_types.entry_type = entry; @@ -6348,7 +6348,7 @@ static void define_builtin_types(CodeGen *g) { } { - TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *entry = new_type_table_entry(TypeTableEntryIdErrorSet); buf_init_from_str(&entry->name, "error"); entry->data.error_set.err_count = UINT32_MAX; @@ -6370,7 +6370,7 @@ static void define_builtin_types(CodeGen *g) { g->primitive_type_table.put(&entry->name, entry); } { - TypeTableEntry *entry = get_promise_type(g, nullptr); + ZigType *entry = get_promise_type(g, nullptr); g->primitive_type_table.put(&entry->name, entry); } @@ -6623,7 +6623,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { buf_appendf(contents, "pub const TypeId = enum {\n"); size_t field_count = type_id_len(); for (size_t i = 0; i < field_count; i += 1) { - const TypeTableEntryId id = type_id_at_index(i); + const ZigTypeId id = type_id_at_index(i); buf_appendf(contents, " %s,\n", type_id_name(id)); } buf_appendf(contents, "};\n\n"); @@ -7068,14 +7068,14 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) { exit(0); } - TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, + ZigType *u8_ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(g, g->builtin_types.entry_u8), 0, 0); - TypeTableEntry *str_type = get_slice_type(g, u8_ptr_type); - TypeTableEntry *fn_type = get_test_fn_type(g); + ZigType *str_type = get_slice_type(g, u8_ptr_type); + ZigType *fn_type = get_test_fn_type(g); const char *field_names[] = { "name", "func", }; - TypeTableEntry *field_types[] = { str_type, fn_type, }; - TypeTableEntry *struct_type = get_struct_type(g, "ZigTestFn", field_names, field_types, 2); + ZigType *field_types[] = { str_type, fn_type, }; + ZigType *struct_type = get_struct_type(g, "ZigTestFn", field_names, field_types, 2); ConstExprValue *test_fn_array = create_const_vals(1); test_fn_array->type = get_array_type(g, struct_type, g->test_fns.length); @@ -7217,10 +7217,10 @@ static const char *c_int_type_names[] = { }; struct GenH { - ZigList types_to_declare; + ZigList types_to_declare; }; -static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry) { +static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_entry) { if (type_entry->gen_h_loop_flag) return; type_entry->gen_h_loop_flag = true; @@ -7285,7 +7285,7 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry } } -static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf *out_buf) { +static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_buf) { assert(type_entry); for (size_t i = 0; i < array_length(c_int_type_names); i += 1) { @@ -7354,7 +7354,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf case TypeTableEntryIdPointer: { Buf child_buf = BUF_INIT; - TypeTableEntry *child_type = type_entry->data.pointer.child_type; + ZigType *child_type = type_entry->data.pointer.child_type; get_c_type(g, gen_h, child_type, &child_buf); const char *const_str = type_entry->data.pointer.is_const ? "const " : ""; @@ -7364,7 +7364,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf } case TypeTableEntryIdOptional: { - TypeTableEntry *child_type = type_entry->data.maybe.child_type; + ZigType *child_type = type_entry->data.maybe.child_type; if (child_type->zero_bits) { buf_init_from_str(out_buf, "bool"); return; @@ -7555,7 +7555,7 @@ static void gen_h_file(CodeGen *g) { fprintf(out_h, "\n"); for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) { - TypeTableEntry *type_entry = gen_h->types_to_declare.at(type_i); + ZigType *type_entry = gen_h->types_to_declare.at(type_i); switch (type_entry->id) { case TypeTableEntryIdInvalid: case TypeTableEntryIdMetaType: diff --git a/src/ir.cpp b/src/ir.cpp index 8c44363bbe..95bea43dab 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -33,7 +33,7 @@ struct IrAnalyze { IrExecContext exec_context; size_t old_bb_index; size_t instruction_index; - TypeTableEntry *explicit_return_type; + ZigType *explicit_return_type; ZigList src_implicit_return_type_list; IrBasicBlock *const_predecessor_bb; }; @@ -99,38 +99,38 @@ struct ConstCastOnly { }; struct ConstCastTypeMismatch { - TypeTableEntry *wanted_type; - TypeTableEntry *actual_type; + ZigType *wanted_type; + ZigType *actual_type; }; struct ConstCastOptionalMismatch { ConstCastOnly child; - TypeTableEntry *wanted_child; - TypeTableEntry *actual_child; + ZigType *wanted_child; + ZigType *actual_child; }; struct ConstCastPointerMismatch { ConstCastOnly child; - TypeTableEntry *wanted_child; - TypeTableEntry *actual_child; + ZigType *wanted_child; + ZigType *actual_child; }; struct ConstCastSliceMismatch { ConstCastOnly child; - TypeTableEntry *wanted_child; - TypeTableEntry *actual_child; + ZigType *wanted_child; + ZigType *actual_child; }; struct ConstCastErrUnionErrSetMismatch { ConstCastOnly child; - TypeTableEntry *wanted_err_set; - TypeTableEntry *actual_err_set; + ZigType *wanted_err_set; + ZigType *actual_err_set; }; struct ConstCastErrUnionPayloadMismatch { ConstCastOnly child; - TypeTableEntry *wanted_payload; - TypeTableEntry *actual_payload; + ZigType *wanted_payload; + ZigType *actual_payload; }; struct ConstCastErrSetMismatch { @@ -139,17 +139,17 @@ struct ConstCastErrSetMismatch { static IrInstruction *ir_gen_node(IrBuilder *irb, AstNode *node, Scope *scope); static IrInstruction *ir_gen_node_extra(IrBuilder *irb, AstNode *node, Scope *scope, LVal lval); -static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction); -static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type); +static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction); +static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type); static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr); static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, - IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type); + IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var); -static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); +static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval); -static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align); -static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type, uint32_t new_align); +static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); +static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align); static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val); static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val); @@ -183,7 +183,7 @@ static ConstExprValue *const_ptr_pointee_unchecked(CodeGen *g, ConstExprValue *c return result; } -static bool types_have_same_zig_comptime_repr(TypeTableEntry *a, TypeTableEntry *b) { +static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) { if (a == b) return true; @@ -878,7 +878,7 @@ static T *ir_build_instruction(IrBuilder *irb, Scope *scope, AstNode *source_nod return special_instruction; } -static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, TypeTableEntry *dest_type, +static IrInstruction *ir_build_cast(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigType *dest_type, IrInstruction *value, CastOp cast_op) { IrInstructionCast *cast_instruction = ir_build_instruction(irb, scope, source_node); @@ -931,7 +931,7 @@ static IrInstruction *ir_build_return(IrBuilder *irb, Scope *scope, AstNode *sou } static IrInstruction *ir_create_const(IrBuilder *irb, Scope *scope, AstNode *source_node, - TypeTableEntry *type_entry) + ZigType *type_entry) { assert(type_entry); IrInstructionConst *const_instruction = ir_create_instruction(irb, scope, source_node); @@ -1002,7 +1002,7 @@ static IrInstruction *ir_build_const_u8(IrBuilder *irb, Scope *scope, AstNode *s } static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, - TypeTableEntry *type_entry) + ZigType *type_entry) { IrInstructionConst *const_instruction = ir_create_instruction(irb, scope, source_node); const_instruction->base.value.type = irb->codegen->builtin_types.entry_type; @@ -1012,7 +1012,7 @@ static IrInstruction *ir_create_const_type(IrBuilder *irb, Scope *scope, AstNode } static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode *source_node, - TypeTableEntry *type_entry) + ZigType *type_entry) { IrInstruction *instruction = ir_create_const_type(irb, scope, source_node, type_entry); ir_instruction_append(irb->current_basic_block, instruction); @@ -1376,7 +1376,7 @@ static IrInstruction *ir_build_container_init_fields(IrBuilder *irb, Scope *scop } static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode *source_node, - TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields) + ZigType *struct_type, size_t field_count, IrInstructionStructInitField *fields) { IrInstructionStructInit *struct_init_instruction = ir_build_instruction(irb, scope, source_node); struct_init_instruction->struct_type = struct_type; @@ -1390,7 +1390,7 @@ static IrInstruction *ir_build_struct_init(IrBuilder *irb, Scope *scope, AstNode } static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *old_instruction, - TypeTableEntry *struct_type, size_t field_count, IrInstructionStructInitField *fields) + ZigType *struct_type, size_t field_count, IrInstructionStructInitField *fields) { IrInstruction *new_instruction = ir_build_struct_init(irb, old_instruction->scope, old_instruction->source_node, struct_type, field_count, fields); @@ -1399,7 +1399,7 @@ static IrInstruction *ir_build_struct_init_from(IrBuilder *irb, IrInstruction *o } static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode *source_node, - TypeTableEntry *union_type, TypeUnionField *field, IrInstruction *init_value) + ZigType *union_type, TypeUnionField *field, IrInstruction *init_value) { IrInstructionUnionInit *union_init_instruction = ir_build_instruction(irb, scope, source_node); union_init_instruction->union_type = union_type; @@ -1412,7 +1412,7 @@ static IrInstruction *ir_build_union_init(IrBuilder *irb, Scope *scope, AstNode } static IrInstruction *ir_build_union_init_from(IrBuilder *irb, IrInstruction *old_instruction, - TypeTableEntry *union_type, TypeUnionField *field, IrInstruction *init_value) + ZigType *union_type, TypeUnionField *field, IrInstruction *init_value) { IrInstruction *new_instruction = ir_build_union_init(irb, old_instruction->scope, old_instruction->source_node, union_type, field, init_value); @@ -1973,7 +1973,7 @@ static IrInstruction *ir_build_cmpxchg(IrBuilder *irb, Scope *scope, AstNode *so IrInstruction *ptr, IrInstruction *cmp_value, IrInstruction *new_value, IrInstruction *success_order_value, IrInstruction *failure_order_value, bool is_weak, - TypeTableEntry *type, AtomicOrder success_order, AtomicOrder failure_order) + ZigType *type, AtomicOrder success_order, AtomicOrder failure_order) { IrInstructionCmpxchg *instruction = ir_build_instruction(irb, scope, source_node); instruction->type_value = type_value; @@ -2286,7 +2286,7 @@ static IrInstruction *ir_build_handle_from(IrBuilder *irb, IrInstruction *old_in static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode *source_node, IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, - IrInstruction *result_ptr, TypeTableEntry *result_ptr_type) + IrInstruction *result_ptr, ZigType *result_ptr_type) { IrInstructionOverflowOp *instruction = ir_build_instruction(irb, scope, source_node); instruction->op = op; @@ -2306,7 +2306,7 @@ static IrInstruction *ir_build_overflow_op(IrBuilder *irb, Scope *scope, AstNode static IrInstruction *ir_build_overflow_op_from(IrBuilder *irb, IrInstruction *old_instruction, IrOverflowOp op, IrInstruction *type_value, IrInstruction *op1, IrInstruction *op2, - IrInstruction *result_ptr, TypeTableEntry *result_ptr_type) + IrInstruction *result_ptr, ZigType *result_ptr_type) { IrInstruction *new_instruction = ir_build_overflow_op(irb, old_instruction->scope, old_instruction->source_node, op, type_value, op1, op2, result_ptr, result_ptr_type); @@ -3343,7 +3343,7 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco add_error_note(codegen, msg, existing_var->decl_node, buf_sprintf("previous declaration is here")); variable_entry->value->type = codegen->builtin_types.entry_invalid; } else { - TypeTableEntry *type = get_primitive_type(codegen, name); + ZigType *type = get_primitive_type(codegen, name); if (type != nullptr) { add_node_error(codegen, node, buf_sprintf("variable shadows type '%s'", buf_ptr(&type->name))); @@ -3789,7 +3789,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, return &const_instruction->base; } - TypeTableEntry *primitive_type = get_primitive_type(irb->codegen, variable_name); + ZigType *primitive_type = get_primitive_type(irb->codegen, variable_name); if (primitive_type != nullptr) { IrInstruction *value = ir_build_const_type(irb, scope, node, primitive_type); if (lval == LValPtr) { @@ -5696,7 +5696,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode if (scope->id == ScopeIdDecls) { ScopeDecls *decls_scope = (ScopeDecls *)scope; - TypeTableEntry *container_type = decls_scope->container_type; + ZigType *container_type = decls_scope->container_type; assert(container_type); return ir_build_const_type(irb, scope, node, container_type); } @@ -6566,7 +6566,7 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, init_tld(&tld_container->base, TldIdContainer, name, visib_mod, node, parent_scope); ContainerLayout layout = node->data.container_decl.layout; - TypeTableEntry *container_type = get_partial_container_type(irb->codegen, parent_scope, + ZigType *container_type = get_partial_container_type(irb->codegen, parent_scope, kind, node, buf_ptr(name), layout); ScopeDecls *child_scope = get_container_scope(container_type); @@ -6586,11 +6586,11 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, } // errors should be populated with set1's values -static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, TypeTableEntry *set1, TypeTableEntry *set2) { +static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2) { assert(set1->id == TypeTableEntryIdErrorSet); assert(set2->id == TypeTableEntryIdErrorSet); - TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); buf_resize(&err_set_type->name, 0); buf_appendf(&err_set_type->name, "error{"); @@ -6639,10 +6639,10 @@ static TypeTableEntry *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, } -static TypeTableEntry *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node, +static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node, ErrorTableEntry *err_entry) { - TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); buf_resize(&err_set_type->name, 0); buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name)); err_set_type->is_copyable = true; @@ -6664,7 +6664,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A uint32_t err_count = node->data.err_set_decl.decls.length; Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node); - TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); buf_init_from_buf(&err_set_type->name, type_name); err_set_type->is_copyable = true; err_set_type->data.error_set.err_count = err_count; @@ -7386,7 +7386,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec IrInstruction *const_bool_false; IrInstruction *coro_promise_ptr; IrInstruction *err_ret_trace_ptr; - TypeTableEntry *return_type; + ZigType *return_type; Buf *result_ptr_field_name; VariableTableEntry *coro_size_var; if (is_async) { @@ -7397,7 +7397,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node); - TypeTableEntry *coro_frame_type = get_promise_frame_type(irb->codegen, return_type); + ZigType *coro_frame_type = get_promise_frame_type(irb->codegen, return_type); IrInstruction *coro_frame_type_value = ir_build_const_type(irb, coro_scope, node, coro_frame_type); // TODO mark this var decl as "no safety" e.g. disable initializing the undef value to 0xaa ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef); @@ -7629,7 +7629,7 @@ static ConstExprValue *ir_const_ptr_pointee(IrAnalyze *ira, ConstExprValue *cons ConstExprValue *val = const_ptr_pointee_unchecked(ira->codegen, const_val); assert(val != nullptr); assert(const_val->type->id == TypeTableEntryIdPointer); - TypeTableEntry *expected_type = const_val->type->data.pointer.child_type; + ZigType *expected_type = const_val->type->data.pointer.child_type; if (!types_have_same_zig_comptime_repr(val->type, expected_type)) { ir_add_error_node(ira, source_node, buf_sprintf("TODO handle comptime reinterpreted pointer. See https://github.com/ziglang/zig/issues/955")); @@ -7668,7 +7668,7 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so return true; } -static bool const_val_fits_in_num_lit(ConstExprValue *const_val, TypeTableEntry *num_lit_type) { +static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) { return ((num_lit_type->id == TypeTableEntryIdComptimeFloat && (const_val->type->id == TypeTableEntryIdFloat || const_val->type->id == TypeTableEntryIdComptimeFloat)) || (num_lit_type->id == TypeTableEntryIdComptimeInt && @@ -8365,7 +8365,7 @@ void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) { } } -static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *other_type, +static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, ZigType *other_type, bool explicit_cast) { if (type_is_invalid(other_type)) { @@ -8399,7 +8399,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc } else if (const_val_fits_in_num_lit(const_val, other_type)) { return true; } else if (other_type->id == TypeTableEntryIdOptional) { - TypeTableEntry *child_type = other_type->data.maybe.child_type; + ZigType *child_type = other_type->data.maybe.child_type; if (const_val_fits_in_num_lit(const_val, child_type)) { return true; } else if (child_type->id == TypeTableEntryIdInt && const_val_is_int) { @@ -8467,16 +8467,16 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc return false; } -static bool is_slice(TypeTableEntry *type) { +static bool is_slice(ZigType *type) { return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice; } -static bool slice_is_const(TypeTableEntry *type) { +static bool slice_is_const(ZigType *type) { assert(is_slice(type)); return type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; } -static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry *set1, TypeTableEntry *set2, +static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigType *set2, AstNode *source_node) { assert(set1->id == TypeTableEntryIdErrorSet); @@ -8502,7 +8502,7 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry } ZigList intersection_list = {}; - TypeTableEntry *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); buf_resize(&err_set_type->name, 0); buf_appendf(&err_set_type->name, "error{"); @@ -8531,8 +8531,8 @@ static TypeTableEntry *get_error_set_intersection(IrAnalyze *ira, TypeTableEntry } -static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry *wanted_type, - TypeTableEntry *actual_type, AstNode *source_node, bool wanted_is_mutable) +static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted_type, + ZigType *actual_type, AstNode *source_node, bool wanted_is_mutable) { CodeGen *g = ira->codegen; ConstCastOnly result = {}; @@ -8595,8 +8595,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry // slice const if (is_slice(wanted_type) && is_slice(actual_type)) { - TypeTableEntry *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry; - TypeTableEntry *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *actual_ptr_type = actual_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *wanted_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; if ((!actual_ptr_type->data.pointer.is_const || wanted_ptr_type->data.pointer.is_const) && (!actual_ptr_type->data.pointer.is_volatile || wanted_ptr_type->data.pointer.is_volatile) && actual_ptr_type->data.pointer.bit_offset == wanted_ptr_type->data.pointer.bit_offset && @@ -8657,8 +8657,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry // error set if (wanted_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) { - TypeTableEntry *contained_set = actual_type; - TypeTableEntry *container_set = wanted_type; + ZigType *contained_set = actual_type; + ZigType *container_set = wanted_type; // if the container set is inferred, then this will always work. if (container_set->data.error_set.infer_fn != nullptr) { @@ -8797,7 +8797,7 @@ static void update_errors_helper(CodeGen *g, ErrorTableEntry ***errors, size_t * *errors = reallocate(*errors, old_errors_count, *errors_count); } -static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, TypeTableEntry *expected_type, IrInstruction **instructions, size_t instruction_count) { +static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigType *expected_type, IrInstruction **instructions, size_t instruction_count) { Error err; assert(instruction_count >= 1); IrInstruction *prev_inst = instructions[0]; @@ -8806,7 +8806,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod } ErrorTableEntry **errors = nullptr; size_t errors_count = 0; - TypeTableEntry *err_set_type = nullptr; + ZigType *err_set_type = nullptr; if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) { if (type_is_global_error_set(prev_inst->value.type)) { err_set_type = ira->codegen->builtin_types.entry_global_error_set; @@ -8829,8 +8829,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod bool convert_to_const_slice = false; for (size_t i = 1; i < instruction_count; i += 1) { IrInstruction *cur_inst = instructions[i]; - TypeTableEntry *cur_type = cur_inst->value.type; - TypeTableEntry *prev_type = prev_inst->value.type; + ZigType *cur_type = cur_inst->value.type; + ZigType *prev_type = prev_inst->value.type; if (type_is_invalid(cur_type)) { return cur_type; @@ -8916,7 +8916,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod prev_inst = cur_inst; continue; } - TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; + ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } @@ -9021,8 +9021,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod } if (prev_type->id == TypeTableEntryIdErrorUnion && cur_type->id == TypeTableEntryIdErrorUnion) { - TypeTableEntry *prev_payload_type = prev_type->data.error_union.payload_type; - TypeTableEntry *cur_payload_type = cur_type->data.error_union.payload_type; + ZigType *prev_payload_type = prev_type->data.error_union.payload_type; + ZigType *cur_payload_type = cur_type->data.error_union.payload_type; bool const_cast_prev = types_match_const_cast_only(ira, prev_payload_type, cur_payload_type, source_node, false).id == ConstCastResultIdOk; @@ -9034,8 +9034,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod prev_inst = cur_inst; } - TypeTableEntry *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type; - TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; + ZigType *prev_err_set_type = (err_set_type == nullptr) ? prev_type->data.error_union.err_set_type : err_set_type; + ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; if (!resolve_inferred_error_set(ira->codegen, prev_err_set_type, cur_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; @@ -9152,7 +9152,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod source_node, false).id == ConstCastResultIdOk) { if (err_set_type != nullptr) { - TypeTableEntry *cur_err_set_type = cur_type->data.error_union.err_set_type; + ZigType *cur_err_set_type = cur_type->data.error_union.err_set_type; if (!resolve_inferred_error_set(ira->codegen, cur_err_set_type, cur_inst->source_node)) { return ira->codegen->builtin_types.entry_invalid; } @@ -9293,12 +9293,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod if (convert_to_const_slice) { assert(prev_inst->value.type->id == TypeTableEntryIdArray); - TypeTableEntry *ptr_type = get_pointer_to_type_extra( + ZigType *ptr_type = get_pointer_to_type_extra( ira->codegen, prev_inst->value.type->data.array.child_type, true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, prev_inst->value.type->data.array.child_type), 0, 0); - TypeTableEntry *slice_type = get_slice_type(ira->codegen, ptr_type); + ZigType *slice_type = get_slice_type(ira->codegen, ptr_type); if (err_set_type != nullptr) { return get_error_union_type(ira->codegen, err_set_type, slice_type); } else { @@ -9343,7 +9343,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod } } -static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *type_entry) { +static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, ZigType *type_entry) { if (type_has_bits(type_entry) && handle_is_ptr(type_entry)) { FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); if (fn_entry != nullptr) { @@ -9366,8 +9366,8 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_instr, CastOp cast_op, - ConstExprValue *other_val, TypeTableEntry *other_type, - ConstExprValue *const_val, TypeTableEntry *new_type) + ConstExprValue *other_val, ZigType *other_type, + ConstExprValue *const_val, ZigType *new_type) { const_val->special = other_val->special; @@ -9467,7 +9467,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ return true; } static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, - TypeTableEntry *wanted_type, CastOp cast_op, bool need_alloca) + ZigType *wanted_type, CastOp cast_op, bool need_alloca) { if ((instr_is_comptime(value) || !type_has_bits(wanted_type)) && cast_op != CastOpResizeSlice && cast_op != CastOpBytesToSlice) @@ -9491,7 +9491,7 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst } static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *value, TypeTableEntry *wanted_type) + IrInstruction *value, ZigType *wanted_type) { assert(value->value.type->id == TypeTableEntryIdPointer); wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); @@ -9520,7 +9520,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, } static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *value, TypeTableEntry *wanted_type) + IrInstruction *value, ZigType *wanted_type) { wanted_type = adjust_slice_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); @@ -9530,7 +9530,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc return ira->codegen->invalid_instruction; if (pointee->special != ConstValSpecialRuntime) { assert(value->value.type->id == TypeTableEntryIdPointer); - TypeTableEntry *array_type = value->value.type->data.pointer.child_type; + ZigType *array_type = value->value.type->data.pointer.child_type; assert(is_slice(wanted_type)); bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; @@ -9551,7 +9551,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc return result; } -static bool is_container(TypeTableEntry *type) { +static bool is_container(ZigType *type) { return type->id == TypeTableEntryIdStruct || type->id == TypeTableEntryIdEnum || type->id == TypeTableEntryIdUnion; @@ -9630,7 +9630,7 @@ static void ir_finish_bb(IrAnalyze *ira) { } } -static TypeTableEntry *ir_unreach_error(IrAnalyze *ira) { +static ZigType *ir_unreach_error(IrAnalyze *ira) { ira->old_bb_index = SIZE_MAX; ira->new_irb.exec->invalid = true; return ira->codegen->builtin_types.entry_unreachable; @@ -9653,7 +9653,7 @@ static bool ir_emit_backward_branch(IrAnalyze *ira, IrInstruction *source_instru return true; } -static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) { +static ZigType *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, IrBasicBlock *old_bb) { if (old_bb->debug_id <= ira->old_irb.current_basic_block->debug_id) { if (!ir_emit_backward_branch(ira, source_instruction)) return ir_unreach_error(ira); @@ -9664,7 +9664,7 @@ static TypeTableEntry *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instru return ira->codegen->builtin_types.entry_unreachable; } -static TypeTableEntry *ir_finish_anal(IrAnalyze *ira, TypeTableEntry *result_type) { +static ZigType *ir_finish_anal(IrAnalyze *ira, ZigType *result_type) { if (result_type->id == TypeTableEntryIdUnreachable) ir_finish_bb(ira); return result_type; @@ -9684,16 +9684,16 @@ static ConstExprValue *ir_build_const_from(IrAnalyze *ira, IrInstruction *old_in return &new_instruction->value; } -static TypeTableEntry *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) { +static ZigType *ir_analyze_void(IrAnalyze *ira, IrInstruction *instruction) { ir_build_const_from(ira, instruction); return ira->codegen->builtin_types.entry_void; } static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instruction, - ConstExprValue *pointee, TypeTableEntry *pointee_type, + ConstExprValue *pointee, ZigType *pointee_type, ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile, uint32_t ptr_align) { - TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, + ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, pointee_type, ptr_is_const, ptr_is_volatile, PtrLenSingle, ptr_align, 0, 0); IrInstruction *const_instr = ir_get_const(ira, instruction); ConstExprValue *const_val = &const_instr->value; @@ -9704,8 +9704,8 @@ static IrInstruction *ir_get_const_ptr(IrAnalyze *ira, IrInstruction *instructio return const_instr; } -static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, - ConstExprValue *pointee, TypeTableEntry *pointee_type, +static ZigType *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instruction, + ConstExprValue *pointee, ZigType *pointee_type, ConstPtrMut ptr_mut, bool ptr_is_const, bool ptr_is_volatile) { IrInstruction *const_instr = ir_get_const_ptr(ira, instruction, pointee, @@ -9715,7 +9715,7 @@ static TypeTableEntry *ir_analyze_const_ptr(IrAnalyze *ira, IrInstruction *instr return const_instr->value.type; } -static TypeTableEntry *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value) { +static ZigType *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *instruction, uint64_t value) { ConstExprValue *const_val = ir_build_const_from(ira, instruction); bigint_init_unsigned(&const_val->data.x_bigint, value); return ira->codegen->builtin_types.entry_usize; @@ -9748,7 +9748,7 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un } IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, - TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, + ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, IrExecutable *parent_exec) { @@ -9786,7 +9786,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node analyzed_executable->backward_branch_count = backward_branch_count; analyzed_executable->backward_branch_quota = backward_branch_quota; analyzed_executable->begin_scope = scope; - TypeTableEntry *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, node); + ZigType *result_type = ir_analyze(codegen, ir_executable, analyzed_executable, expected_type, node); if (type_is_invalid(result_type)) return codegen->invalid_instruction; @@ -9799,7 +9799,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node return ir_exec_const_result(codegen, analyzed_executable); } -static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { +static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { if (type_is_invalid(type_value->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -9837,11 +9837,11 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { return const_val->data.x_ptr.data.fn.fn_entry; } -static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) { +static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { assert(wanted_type->id == TypeTableEntryIdOptional); if (instr_is_comptime(value)) { - TypeTableEntry *payload_type = wanted_type->data.maybe.child_type; + ZigType *payload_type = wanted_type->data.maybe.child_type; IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); if (type_is_invalid(casted_payload->value.type)) return ira->codegen->invalid_instruction; @@ -9870,12 +9870,12 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc } static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *value, TypeTableEntry *wanted_type) + IrInstruction *value, ZigType *wanted_type) { assert(wanted_type->id == TypeTableEntryIdErrorUnion); if (instr_is_comptime(value)) { - TypeTableEntry *payload_type = wanted_type->data.error_union.payload_type; + ZigType *payload_type = wanted_type->data.error_union.payload_type; IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type); if (type_is_invalid(casted_payload->value.type)) return ira->codegen->invalid_instruction; @@ -9901,7 +9901,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction } static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, - TypeTableEntry *wanted_type) + ZigType *wanted_type) { assert(value->value.type->id == TypeTableEntryIdErrorSet); assert(wanted_type->id == TypeTableEntryIdErrorSet); @@ -9943,7 +9943,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou return result; } -static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) { +static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { assert(wanted_type->id == TypeTableEntryIdErrorUnion); IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); @@ -9970,7 +9970,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so } static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *value, TypeTableEntry *wanted_type) + IrInstruction *value, ZigType *wanted_type) { if (instr_is_comptime(value)) { ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); @@ -9994,7 +9994,7 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ source_instr->source_node, value, true, false); new_instruction->value.type = wanted_type; - TypeTableEntry *child_type = wanted_type->data.pointer.child_type; + ZigType *child_type = wanted_type->data.pointer.child_type; if (type_has_bits(child_type)) { FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); assert(fn_entry); @@ -10005,7 +10005,7 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ } } -static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, TypeTableEntry *wanted_type) { +static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { assert(wanted_type->id == TypeTableEntryIdOptional); assert(instr_is_comptime(value)); @@ -10039,7 +10039,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi get_abi_alignment(ira->codegen, value->value.type)); } - TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, + ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, value->value.type, is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, value->value.type), 0, 0); IrInstruction *new_instruction = ir_build_ref(&ira->new_irb, source_instruction->scope, source_instruction->source_node, value, is_const, is_volatile); @@ -10054,7 +10054,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi } static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *array_arg, TypeTableEntry *wanted_type) + IrInstruction *array_arg, ZigType *wanted_type) { assert(is_slice(wanted_type)); // In this function we honor the const-ness of wanted_type, because @@ -10068,7 +10068,7 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s } else { array = array_arg; } - TypeTableEntry *array_type = array->value.type; + ZigType *array_type = array->value.type; assert(array_type->id == TypeTableEntryIdArray); if (instr_is_comptime(array)) { @@ -10100,12 +10100,12 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s } static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *target, TypeTableEntry *wanted_type) + IrInstruction *target, ZigType *wanted_type) { Error err; assert(wanted_type->id == TypeTableEntryIdInt); - TypeTableEntry *actual_type = target->value.type; + ZigType *actual_type = target->value.type; if ((err = ensure_complete_type(ira->codegen, actual_type))) return ira->codegen->invalid_instruction; @@ -10136,7 +10136,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour } static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *target, TypeTableEntry *wanted_type) + IrInstruction *target, ZigType *wanted_type) { assert(target->value.type->id == TypeTableEntryIdUnion); assert(wanted_type->id == TypeTableEntryIdEnum); @@ -10161,7 +10161,7 @@ static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *sou } static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *target, TypeTableEntry *wanted_type) + IrInstruction *target, ZigType *wanted_type) { IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type); @@ -10170,7 +10170,7 @@ static IrInstruction *ir_analyze_undefined_to_anything(IrAnalyze *ira, IrInstruc } static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *target, TypeTableEntry *wanted_type) + IrInstruction *target, ZigType *wanted_type) { Error err; assert(wanted_type->id == TypeTableEntryIdUnion); @@ -10229,7 +10229,7 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so } static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *target, TypeTableEntry *wanted_type) + IrInstruction *target, ZigType *wanted_type) { assert(wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdFloat); @@ -10270,12 +10270,12 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction } static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *target, TypeTableEntry *wanted_type) + IrInstruction *target, ZigType *wanted_type) { Error err; assert(wanted_type->id == TypeTableEntryIdEnum); - TypeTableEntry *actual_type = target->value.type; + ZigType *actual_type = target->value.type; if ((err = ensure_complete_type(ira->codegen, wanted_type))) return ira->codegen->invalid_instruction; @@ -10320,7 +10320,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour } static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction *source_instr, - IrInstruction *target, TypeTableEntry *wanted_type) + IrInstruction *target, ZigType *wanted_type) { ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) @@ -10339,7 +10339,7 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction } static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, - TypeTableEntry *wanted_type) + ZigType *wanted_type) { assert(target->value.type->id == TypeTableEntryIdInt); assert(!target->value.type->data.integral.is_signed); @@ -10404,11 +10404,11 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc } static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, - TypeTableEntry *wanted_type) + ZigType *wanted_type) { assert(wanted_type->id == TypeTableEntryIdInt); - TypeTableEntry *err_type = target->value.type; + ZigType *err_type = target->value.type; if (instr_is_comptime(target)) { ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); @@ -10442,7 +10442,7 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc return result; } - TypeTableEntry *err_set_type; + ZigType *err_set_type; if (err_type->id == TypeTableEntryIdErrorUnion) { err_set_type = err_type->data.error_union.err_set_type; } else if (err_type->id == TypeTableEntryIdErrorSet) { @@ -10484,11 +10484,11 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc } static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, - TypeTableEntry *wanted_type) + ZigType *wanted_type) { assert(wanted_type->id == TypeTableEntryIdPointer); wanted_type = adjust_ptr_align(ira->codegen, wanted_type, target->value.type->data.pointer.alignment); - TypeTableEntry *array_type = wanted_type->data.pointer.child_type; + ZigType *array_type = wanted_type->data.pointer.child_type; assert(array_type->id == TypeTableEntryIdArray); assert(array_type->data.array.len == 1); @@ -10620,10 +10620,10 @@ static void report_recursive_error(IrAnalyze *ira, AstNode *source_node, ConstCa } static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_instr, - TypeTableEntry *wanted_type, IrInstruction *value) + ZigType *wanted_type, IrInstruction *value) { Error err; - TypeTableEntry *actual_type = value->value.type; + ZigType *actual_type = value->value.type; AstNode *source_node = source_instr->source_node; if (type_is_invalid(wanted_type) || type_is_invalid(actual_type)) { @@ -10665,7 +10665,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // cast from [N]T to []const T if (is_slice(wanted_type) && actual_type->id == TypeTableEntryIdArray) { - TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; assert(ptr_type->id == TypeTableEntryIdPointer); if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, @@ -10681,10 +10681,10 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst actual_type->data.pointer.is_const && actual_type->data.pointer.child_type->id == TypeTableEntryIdArray) { - TypeTableEntry *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *array_type = actual_type->data.pointer.child_type; + ZigType *array_type = actual_type->data.pointer.child_type; if ((ptr_type->data.pointer.is_const || array_type->data.array.len == 0) && types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, array_type->data.array.child_type, @@ -10700,7 +10700,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst is_slice(wanted_type->data.pointer.child_type) && actual_type->id == TypeTableEntryIdArray) { - TypeTableEntry *ptr_type = + ZigType *ptr_type = wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; assert(ptr_type->id == TypeTableEntryIdPointer); if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && @@ -10724,7 +10724,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst is_slice(wanted_type->data.maybe.child_type) && actual_type->id == TypeTableEntryIdArray) { - TypeTableEntry *ptr_type = + ZigType *ptr_type = wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; assert(ptr_type->id == TypeTableEntryIdPointer); if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && @@ -10763,7 +10763,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst actual_type->data.pointer.ptr_len == PtrLenSingle && actual_type->data.pointer.child_type->id == TypeTableEntryIdArray) { - TypeTableEntry *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; assert(slice_ptr_type->id == TypeTableEntryIdPointer); if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type, actual_type->data.pointer.child_type->data.array.child_type, source_node, @@ -10777,7 +10777,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // cast from T to ?T // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism if (wanted_type->id == TypeTableEntryIdOptional) { - TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type; + ZigType *wanted_child_type = wanted_type->data.maybe.child_type; if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk) { @@ -10850,7 +10850,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst is_slice(wanted_type->data.error_union.payload_type) && actual_type->id == TypeTableEntryIdArray) { - TypeTableEntry *ptr_type = + ZigType *ptr_type = wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; assert(ptr_type->id == TypeTableEntryIdPointer); if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && @@ -10881,7 +10881,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst wanted_type->data.error_union.payload_type->id == TypeTableEntryIdOptional && actual_type->id != TypeTableEntryIdOptional) { - TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; + ZigType *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk || actual_type->id == TypeTableEntryIdNull || actual_type->id == TypeTableEntryIdComptimeInt || @@ -10983,7 +10983,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // enum to &const union which has the enum as the tag type if (actual_type->id == TypeTableEntryIdEnum && wanted_type->id == TypeTableEntryIdPointer) { - TypeTableEntry *union_type = wanted_type->data.pointer.child_type; + ZigType *union_type = wanted_type->data.pointer.child_type; if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr) { @@ -11008,7 +11008,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && actual_type->id == TypeTableEntryIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle) { - TypeTableEntry *array_type = wanted_type->data.pointer.child_type; + ZigType *array_type = wanted_type->data.pointer.child_type; if (array_type->id == TypeTableEntryIdArray && array_type->data.array.len == 1 && types_match_const_cast_only(ira, array_type->data.array.child_type, actual_type->data.pointer.child_type, source_node, @@ -11049,7 +11049,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // cast from something to const pointer of it if (!type_requires_comptime(actual_type)) { - TypeTableEntry *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); + ZigType *const_ptr_actual = get_pointer_to_type(ira->codegen, actual_type, true); if (types_match_const_cast_only(ira, wanted_type, const_ptr_actual, source_node, false).id == ConstCastResultIdOk) { return ir_analyze_cast_ref(ira, source_instr, value, wanted_type); } @@ -11063,7 +11063,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst return ira->codegen->invalid_instruction; } -static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type) { +static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, ZigType *expected_type) { assert(value); assert(value != ira->codegen->invalid_instruction); assert(!expected_type || !type_is_invalid(expected_type)); @@ -11080,11 +11080,11 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ } static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) { - TypeTableEntry *type_entry = ptr->value.type; + ZigType *type_entry = ptr->value.type; if (type_is_invalid(type_entry)) { return ira->codegen->invalid_instruction; } else if (type_entry->id == TypeTableEntryIdPointer) { - TypeTableEntry *child_type = type_entry->data.pointer.child_type; + ZigType *child_type = type_entry->data.pointer.child_type; if (instr_is_comptime(ptr)) { if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst || ptr->value.data.x_ptr.mut == ConstPtrMutComptimeVar) @@ -11114,7 +11114,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc } } -static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, +static ZigType *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value, bool is_const, bool is_volatile) { IrInstruction *result = ir_get_ref(ira, source_instruction, value, is_const, is_volatile); @@ -11149,7 +11149,7 @@ static bool ir_resolve_align(IrAnalyze *ira, IrInstruction *value, uint32_t *out return true; } -static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *int_type, uint64_t *out) { +static bool ir_resolve_unsigned(IrAnalyze *ira, IrInstruction *value, ZigType *int_type, uint64_t *out) { if (type_is_invalid(value->value.type)) return false; @@ -11199,7 +11199,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); assert(atomic_order_val->type->id == TypeTableEntryIdMetaType); - TypeTableEntry *atomic_order_type = atomic_order_val->data.x_type; + ZigType *atomic_order_type = atomic_order_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); if (type_is_invalid(casted_value->value.type)) @@ -11219,7 +11219,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp"); assert(atomic_rmw_op_val->type->id == TypeTableEntryIdMetaType); - TypeTableEntry *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type; + ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); if (type_is_invalid(casted_value->value.type)) @@ -11239,7 +11239,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); assert(global_linkage_val->type->id == TypeTableEntryIdMetaType); - TypeTableEntry *global_linkage_type = global_linkage_val->data.x_type; + ZigType *global_linkage_type = global_linkage_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); if (type_is_invalid(casted_value->value.type)) @@ -11259,7 +11259,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode"); assert(float_mode_val->type->id == TypeTableEntryIdMetaType); - TypeTableEntry *float_mode_type = float_mode_val->data.x_type; + ZigType *float_mode_type = float_mode_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type); if (type_is_invalid(casted_value->value.type)) @@ -11278,10 +11278,10 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { if (type_is_invalid(value->value.type)) return nullptr; - TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, + ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); - TypeTableEntry *str_type = get_slice_type(ira->codegen, ptr_type); + ZigType *str_type = get_slice_type(ira->codegen, ptr_type); IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type); if (type_is_invalid(casted_value->value.type)) return nullptr; @@ -11314,7 +11314,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) { return result; } -static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_add_implicit_return_type(IrAnalyze *ira, IrInstructionAddImplicitReturnType *instruction) { IrInstruction *value = instruction->value->other; @@ -11328,7 +11328,7 @@ static TypeTableEntry *ir_analyze_instruction_add_implicit_return_type(IrAnalyze return out_val->type; } -static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_return(IrAnalyze *ira, IrInstructionReturn *return_instruction) { IrInstruction *value = return_instruction->value->other; @@ -11353,13 +11353,13 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira, return ir_finish_anal(ira, result->value.type); } -static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) { +static ZigType *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructionConst *const_instruction) { ConstExprValue *out_val = ir_build_const_from(ira, &const_instruction->base); *out_val = const_instruction->base.value; return const_instruction->base.value.type; } -static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { +static ZigType *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { IrInstruction *op1 = bin_op_instruction->op1->other; if (type_is_invalid(op1->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -11368,7 +11368,7 @@ static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp if (type_is_invalid(op2->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool; + ZigType *bool_type = ira->codegen->builtin_types.entry_bool; IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, bool_type); if (casted_op1 == ira->codegen->invalid_instruction) @@ -11433,7 +11433,7 @@ static bool optional_value_is_null(ConstExprValue *val) { } } -static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { +static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { Error err; IrInstruction *op1 = bin_op_instruction->op1->other; IrInstruction *op2 = bin_op_instruction->op2->other; @@ -11486,7 +11486,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); + ZigType *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); if (type_is_invalid(intersect_type)) { return ira->codegen->builtin_types.entry_invalid; } @@ -11567,7 +11567,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp } IrInstruction *instructions[] = {op1, op2}; - TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); + ZigType *resolved_type = ir_resolve_peer_types(ira, source_node, nullptr, instructions, 2); if (type_is_invalid(resolved_type)) return resolved_type; if ((err = type_ensure_zero_bits_known(ira->codegen, resolved_type))) @@ -11705,7 +11705,7 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp return ira->codegen->builtin_types.entry_bool; } -static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, +static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val, IrBinOp op_id, ConstExprValue *op2_val, ConstExprValue *out_val) { bool is_int; @@ -11885,7 +11885,7 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val, return 0; } -static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { +static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { IrInstruction *op1 = bin_op_instruction->op1->other; if (type_is_invalid(op1->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -11917,7 +11917,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * return ira->codegen->builtin_types.entry_invalid; } } else { - TypeTableEntry *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, + ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, op1->value.type->data.integral.bit_count - 1); if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy && op2->value.type->id == TypeTableEntryIdComptimeInt) { @@ -11985,7 +11985,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp * return op1->value.type; } -static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { +static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { IrInstruction *op1 = bin_op_instruction->op1->other; if (type_is_invalid(op1->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -12012,7 +12012,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp } IrInstruction *instructions[] = {op1, op2}; - TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2); + ZigType *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, nullptr, instructions, 2); if (type_is_invalid(resolved_type)) return resolved_type; @@ -12206,14 +12206,14 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp } -static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { +static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) { IrInstruction *op1 = instruction->op1->other; - TypeTableEntry *op1_type = op1->value.type; + ZigType *op1_type = op1->value.type; if (type_is_invalid(op1_type)) return ira->codegen->builtin_types.entry_invalid; IrInstruction *op2 = instruction->op2->other; - TypeTableEntry *op2_type = op2->value.type; + ZigType *op2_type = op2->value.type; if (type_is_invalid(op2_type)) return ira->codegen->builtin_types.entry_invalid; @@ -12228,7 +12228,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * ConstExprValue *op1_array_val; size_t op1_array_index; size_t op1_array_end; - TypeTableEntry *child_type; + ZigType *child_type; if (op1_type->id == TypeTableEntryIdArray) { child_type = op1_type->data.array.child_type; op1_array_val = op1_val; @@ -12244,7 +12244,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * op1_array_index = op1_val->data.x_ptr.data.base_array.elem_index; op1_array_end = op1_array_val->type->data.array.len - 1; } else if (is_slice(op1_type)) { - TypeTableEntry *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *ptr_type = op1_type->data.structure.fields[slice_ptr_index].type_entry; child_type = ptr_type->data.pointer.child_type; ConstExprValue *ptr_val = &op1_val->data.x_struct.fields[slice_ptr_index]; assert(ptr_val->data.x_ptr.special == ConstPtrSpecialBaseArray); @@ -12285,7 +12285,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * op2_array_index = op2_val->data.x_ptr.data.base_array.elem_index; op2_array_end = op2_array_val->type->data.array.len - 1; } else if (is_slice(op2_type)) { - TypeTableEntry *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *ptr_type = op2_type->data.structure.fields[slice_ptr_index].type_entry; if (ptr_type->data.pointer.child_type != child_type) { ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", buf_ptr(&child_type->name), @@ -12305,7 +12305,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); - TypeTableEntry *result_type; + ZigType *result_type; ConstExprValue *out_array_val; size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); if (op1_type->id == TypeTableEntryIdArray || op2_type->id == TypeTableEntryIdArray) { @@ -12313,7 +12313,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * out_array_val = out_val; } else if (is_slice(op1_type) || is_slice(op2_type)) { - TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, + ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, child_type), 0, 0); result_type = get_slice_type(ira->codegen, ptr_type); out_array_val = create_const_vals(1); @@ -12374,7 +12374,7 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp * return result_type; } -static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { +static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) { IrInstruction *op1 = instruction->op1->other; if (type_is_invalid(op1->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -12391,7 +12391,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp if (!ir_resolve_usize(ira, op2, &mult_amt)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *array_type = op1->value.type; + ZigType *array_type = op1->value.type; if (array_type->id != TypeTableEntryIdArray) { ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -12410,7 +12410,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp if (array_val->data.x_array.special == ConstArraySpecialUndef) { out_val->data.x_array.special = ConstArraySpecialUndef; - TypeTableEntry *child_type = array_type->data.array.child_type; + ZigType *child_type = array_type->data.array.child_type; return get_array_type(ira->codegen, child_type, new_array_len); } @@ -12425,16 +12425,16 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp } assert(i == new_array_len); - TypeTableEntry *child_type = array_type->data.array.child_type; + ZigType *child_type = array_type->data.array.child_type; return get_array_type(ira->codegen, child_type, new_array_len); } -static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) { - TypeTableEntry *op1_type = ir_resolve_type(ira, instruction->op1->other); +static ZigType *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstructionBinOp *instruction) { + ZigType *op1_type = ir_resolve_type(ira, instruction->op1->other); if (type_is_invalid(op1_type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *op2_type = ir_resolve_type(ira, instruction->op2->other); + ZigType *op2_type = ir_resolve_type(ira, instruction->op2->other); if (type_is_invalid(op2_type)) return ira->codegen->builtin_types.entry_invalid; @@ -12460,7 +12460,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction assert(errors[error_entry->value] == nullptr); errors[error_entry->value] = error_entry; } - TypeTableEntry *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type); + ZigType *result_type = get_error_set_union(ira->codegen, errors, op1_type, op2_type); free(errors); @@ -12469,7 +12469,7 @@ static TypeTableEntry *ir_analyze_merge_error_sets(IrAnalyze *ira, IrInstruction return ira->codegen->builtin_types.entry_type; } -static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { +static ZigType *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) { IrBinOp op_id = bin_op_instruction->op_id; switch (op_id) { case IrBinOpInvalid: @@ -12516,7 +12516,7 @@ static TypeTableEntry *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructi zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) { +static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) { Error err; VariableTableEntry *var = decl_var_instruction->var; @@ -12526,11 +12526,11 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc return var->value->type; } - TypeTableEntry *explicit_type = nullptr; + ZigType *explicit_type = nullptr; IrInstruction *var_type = nullptr; if (decl_var_instruction->var_type != nullptr) { var_type = decl_var_instruction->var_type->other; - TypeTableEntry *proposed_type = ir_resolve_type(ira, var_type); + ZigType *proposed_type = ir_resolve_type(ira, var_type); explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type); if (type_is_invalid(explicit_type)) { var->value->type = ira->codegen->builtin_types.entry_invalid; @@ -12545,7 +12545,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc bool var_class_requires_const = false; - TypeTableEntry *result_type = casted_init_value->value.type; + ZigType *result_type = casted_init_value->value.type; if (type_is_invalid(result_type)) { result_type = ira->codegen->builtin_types.entry_invalid; } else { @@ -12651,7 +12651,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) { +static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExport *instruction) { IrInstruction *name = instruction->name->other; Buf *symbol_name = ir_resolve_str(ira, name); if (symbol_name == nullptr) { @@ -12731,7 +12731,7 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi } break; case TypeTableEntryIdMetaType: { - TypeTableEntry *type_value = target->value.data.x_type; + ZigType *type_value = target->value.data.x_type; switch (type_value->id) { case TypeTableEntryIdInvalid: zig_unreachable(); @@ -12826,12 +12826,12 @@ static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) { return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing; } -static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, IrInstructionErrorReturnTrace *instruction) { if (instruction->optional == IrInstructionErrorReturnTrace::Null) { - TypeTableEntry *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen); - TypeTableEntry *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); + ZigType *ptr_to_stack_trace_type = get_ptr_to_stack_trace_type(ira->codegen); + ZigType *optional_type = get_optional_type(ira->codegen, ptr_to_stack_trace_type); if (!exec_has_err_ret_trace(ira->codegen, ira->new_irb.exec)) { ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); assert(get_codegen_ptr_type(optional_type) != nullptr); @@ -12852,14 +12852,14 @@ static TypeTableEntry *ir_analyze_instruction_error_return_trace(IrAnalyze *ira, } } -static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_error_union(IrAnalyze *ira, IrInstructionErrorUnion *instruction) { - TypeTableEntry *err_set_type = ir_resolve_type(ira, instruction->err_set->other); + ZigType *err_set_type = ir_resolve_type(ira, instruction->err_set->other); if (type_is_invalid(err_set_type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *payload_type = ir_resolve_type(ira, instruction->payload->other); + ZigType *payload_type = ir_resolve_type(ira, instruction->payload->other); if (type_is_invalid(payload_type)) return ira->codegen->builtin_types.entry_invalid; @@ -12870,7 +12870,7 @@ static TypeTableEntry *ir_analyze_instruction_error_union(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type); + ZigType *result_type = get_error_union_type(ira->codegen, err_set_type, payload_type); ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); out_val->data.x_type = result_type; @@ -12913,38 +12913,38 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i zig_unreachable(); } -static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, FnTableEntry *fn_entry, TypeTableEntry *fn_type, +static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, FnTableEntry *fn_entry, ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst) { Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME); //Buf *free_field_name = buf_create_from_str("freeFn"); assert(async_allocator_inst->value.type->id == TypeTableEntryIdPointer); - TypeTableEntry *container_type = async_allocator_inst->value.type->data.pointer.child_type; + ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type; IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base, async_allocator_inst, container_type); if (type_is_invalid(field_ptr_inst->value.type)) { return ira->codegen->invalid_instruction; } - TypeTableEntry *ptr_to_alloc_fn_type = field_ptr_inst->value.type; + ZigType *ptr_to_alloc_fn_type = field_ptr_inst->value.type; assert(ptr_to_alloc_fn_type->id == TypeTableEntryIdPointer); - TypeTableEntry *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type; + ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type; if (alloc_fn_type->id != TypeTableEntryIdFn) { ir_add_error(ira, &call_instruction->base, buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name))); return ira->codegen->invalid_instruction; } - TypeTableEntry *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type; + ZigType *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type; if (alloc_fn_return_type->id != TypeTableEntryIdErrorUnion) { ir_add_error(ira, fn_ref, buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name))); return ira->codegen->invalid_instruction; } - TypeTableEntry *alloc_fn_error_set_type = alloc_fn_return_type->data.error_union.err_set_type; - TypeTableEntry *return_type = fn_type->data.fn.fn_type_id.return_type; - TypeTableEntry *promise_type = get_promise_type(ira->codegen, return_type); - TypeTableEntry *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type); + ZigType *alloc_fn_error_set_type = alloc_fn_return_type->data.error_union.err_set_type; + ZigType *return_type = fn_type->data.fn.fn_type_id.return_type; + ZigType *promise_type = get_promise_type(ira->codegen, return_type); + ZigType *async_return_type = get_error_union_type(ira->codegen, alloc_fn_error_set_type, promise_type); IrInstruction *result = ir_build_call(&ira->new_irb, call_instruction->base.scope, call_instruction->base.source_node, fn_entry, fn_ref, arg_count, casted_args, false, FnInlineAuto, true, async_allocator_inst, nullptr); @@ -12961,7 +12961,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node IrInstruction *casted_arg; if (param_decl_node->data.param_decl.var_token == nullptr) { AstNode *param_type_node = param_decl_node->data.param_decl.type; - TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node); + ZigType *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node); if (type_is_invalid(param_type)) return false; @@ -13001,7 +13001,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod } else { if (param_decl_node->data.param_decl.var_token == nullptr) { AstNode *param_type_node = param_decl_node->data.param_decl.type; - TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node); + ZigType *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node); if (type_is_invalid(param_type)) return false; @@ -13156,8 +13156,8 @@ no_mem_slot: return var_ptr_instruction; } -static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction, - FnTableEntry *fn_entry, TypeTableEntry *fn_type, IrInstruction *fn_ref, +static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction, + FnTableEntry *fn_entry, ZigType *fn_type, IrInstruction *fn_ref, IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline) { Error err; @@ -13249,7 +13249,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal bool first_arg_known_bare = false; if (fn_type_id->next_param_index >= 1) { - TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type; + ZigType *param_type = fn_type_id->param_info[next_proto_i].type; if (type_is_invalid(param_type)) return ira->codegen->builtin_types.entry_invalid; first_arg_known_bare = param_type->id != TypeTableEntryIdPointer; @@ -13285,11 +13285,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal } AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; - TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node); + ZigType *specified_return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node); if (type_is_invalid(specified_return_type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *return_type; - TypeTableEntry *inferred_err_set_type = nullptr; + ZigType *return_type; + ZigType *inferred_err_set_type = nullptr; if (fn_proto_node->data.fn_proto.auto_err_set) { inferred_err_set_type = get_auto_err_set_type(ira->codegen, fn_entry); return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); @@ -13320,7 +13320,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal inferred_err_set_type->data.error_set.errors = allocate(1); inferred_err_set_type->data.error_set.errors[0] = result->value.data.x_err_union.err; } - TypeTableEntry *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type; + ZigType *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type; inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count; inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors; } else if (result->value.type->id == TypeTableEntryIdErrorSet) { @@ -13344,10 +13344,10 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal IrInstruction *casted_new_stack = nullptr; if (call_instruction->new_stack != nullptr) { - TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, + ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, false, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); - TypeTableEntry *u8_slice = get_slice_type(ira->codegen, u8_ptr); + ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); IrInstruction *new_stack = call_instruction->new_stack->other; if (type_is_invalid(new_stack->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -13405,7 +13405,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal bool first_arg_known_bare = false; if (fn_type_id->next_param_index >= 1) { - TypeTableEntry *param_type = fn_type_id->param_info[next_proto_i].type; + ZigType *param_type = fn_type_id->param_info[next_proto_i].type; if (type_is_invalid(param_type)) return ira->codegen->builtin_types.entry_invalid; first_arg_known_bare = param_type->id != TypeTableEntryIdPointer; @@ -13515,11 +13515,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal if (fn_proto_node->data.fn_proto.return_var_token == nullptr) { AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type; - TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node); + ZigType *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node); if (type_is_invalid(specified_return_type)) return ira->codegen->builtin_types.entry_invalid; if (fn_proto_node->data.fn_proto.auto_err_set) { - TypeTableEntry *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn); + ZigType *inferred_err_set_type = get_auto_err_set_type(ira->codegen, impl_fn); inst_fn_type_id.return_type = get_error_union_type(ira->codegen, inferred_err_set_type, specified_return_type); } else { inst_fn_type_id.return_type = specified_return_type; @@ -13537,7 +13537,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal if (call_instruction->is_async) { AstNode *async_allocator_type_node = fn_proto_node->data.fn_proto.async_allocator_type; if (async_allocator_type_node != nullptr) { - TypeTableEntry *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node); + ZigType *async_allocator_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, async_allocator_type_node); if (type_is_invalid(async_allocator_type)) return ira->codegen->builtin_types.entry_invalid; inst_fn_type_id.async_allocator_type = async_allocator_type; @@ -13581,7 +13581,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal ira->codegen->fn_defs.append(impl_fn); } - TypeTableEntry *return_type = impl_fn->type_entry->data.fn.fn_type_id.return_type; + ZigType *return_type = impl_fn->type_entry->data.fn.fn_type_id.return_type; if (fn_type_can_fail(&impl_fn->type_entry->data.fn.fn_type_id)) { parent_fn_entry->calls_or_awaits_errorable_fn = true; } @@ -13618,7 +13618,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal if (first_arg_ptr) { assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer); - TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type; + ZigType *param_type = fn_type_id->param_info[next_arg_index].type; if (type_is_invalid(param_type)) return ira->codegen->builtin_types.entry_invalid; @@ -13646,7 +13646,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal return ira->codegen->builtin_types.entry_invalid; IrInstruction *casted_arg; if (next_arg_index < src_param_count) { - TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type; + ZigType *param_type = fn_type_id->param_info[next_arg_index].type; if (type_is_invalid(param_type)) return ira->codegen->builtin_types.entry_invalid; casted_arg = ir_implicit_cast(ira, old_arg, param_type); @@ -13662,7 +13662,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal assert(next_arg_index == call_param_count); - TypeTableEntry *return_type = fn_type_id->return_type; + ZigType *return_type = fn_type_id->return_type; if (type_is_invalid(return_type)) return ira->codegen->builtin_types.entry_invalid; @@ -13703,7 +13703,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal return ir_finish_anal(ira, return_type); } -static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) { +static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) { IrInstruction *fn_ref = call_instruction->fn_ref->other; if (type_is_invalid(fn_ref->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -13713,7 +13713,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction if (is_comptime || instr_is_comptime(fn_ref)) { if (fn_ref->value.type->id == TypeTableEntryIdMetaType) { - TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref); + ZigType *dest_type = ir_resolve_type(ira, fn_ref); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -13793,12 +13793,12 @@ static Error ir_read_const_ptr(IrAnalyze *ira, AstNode *source_node, return ErrorNone; } -static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { +static ZigType *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { Error err; IrInstruction *value = un_op_instruction->value->other; - TypeTableEntry *ptr_type = value->value.type; - TypeTableEntry *child_type; + ZigType *ptr_type = value->value.type; + ZigType *child_type; if (type_is_invalid(ptr_type)) { return ira->codegen->builtin_types.entry_invalid; } else if (ptr_type->id == TypeTableEntryIdPointer) { @@ -13835,10 +13835,10 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp return child_type; } -static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { +static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { Error err; IrInstruction *value = un_op_instruction->value->other; - TypeTableEntry *type_entry = ir_resolve_type(ira, value); + ZigType *type_entry = ir_resolve_type(ira, value); if (type_is_invalid(type_entry)) return ira->codegen->builtin_types.entry_invalid; if ((err = ensure_complete_type(ira->codegen, type_entry))) @@ -13884,9 +13884,9 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op zig_unreachable(); } -static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { +static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { IrInstruction *value = un_op_instruction->value->other; - TypeTableEntry *expr_type = value->value.type; + ZigType *expr_type = value->value.type; if (type_is_invalid(expr_type)) return ira->codegen->builtin_types.entry_invalid; @@ -13931,9 +13931,9 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un return ira->codegen->builtin_types.entry_invalid; } -static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { +static ZigType *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) { IrInstruction *value = instruction->value->other; - TypeTableEntry *expr_type = value->value.type; + ZigType *expr_type = value->value.type; if (type_is_invalid(expr_type)) return ira->codegen->builtin_types.entry_invalid; @@ -13958,7 +13958,7 @@ static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *ins return ira->codegen->builtin_types.entry_invalid; } -static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { +static ZigType *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) { IrUnOp op_id = un_op_instruction->op_id; switch (op_id) { case IrUnOpInvalid: @@ -13976,7 +13976,7 @@ static TypeTableEntry *ir_analyze_instruction_un_op(IrAnalyze *ira, IrInstructio zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) { +static ZigType *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr *br_instruction) { IrBasicBlock *old_dest_block = br_instruction->dest_block; bool is_comptime; @@ -13994,7 +13994,7 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); } -static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { +static ZigType *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) { IrInstruction *condition = cond_br_instruction->condition->other; if (type_is_invalid(condition->value.type)) return ir_unreach_error(ira); @@ -14022,7 +14022,7 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); } - TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool; + ZigType *bool_type = ira->codegen->builtin_types.entry_bool; IrInstruction *casted_condition = ir_implicit_cast(ira, condition, bool_type); if (casted_condition == ira->codegen->invalid_instruction) return ir_unreach_error(ira); @@ -14041,14 +14041,14 @@ static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstruct return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); } -static TypeTableEntry *ir_analyze_instruction_unreachable(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_unreachable(IrAnalyze *ira, IrInstructionUnreachable *unreachable_instruction) { ir_build_unreachable_from(&ira->new_irb, &unreachable_instruction->base); return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); } -static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) { +static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi_instruction) { if (ira->const_predecessor_bb) { for (size_t i = 0; i < phi_instruction->incoming_count; i += 1) { IrBasicBlock *predecessor = phi_instruction->incoming_blocks[i]; @@ -14105,7 +14105,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP return first_value->value.type; } - TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr, + ZigType *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node, nullptr, new_incoming_values.items, new_incoming_values.length); if (type_is_invalid(resolved_type)) return resolved_type; @@ -14157,7 +14157,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP return resolved_type; } -static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, +static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var) { IrInstruction *result = ir_get_var_ptr(ira, instruction, var); @@ -14165,12 +14165,12 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) { +static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) { VariableTableEntry *var = var_ptr_instruction->var; return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var); } -static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, uint32_t new_align) { +static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align) { assert(ptr_type->id == TypeTableEntryIdPointer); return get_pointer_to_type_extra(g, ptr_type->data.pointer.child_type, @@ -14180,14 +14180,14 @@ static TypeTableEntry *adjust_ptr_align(CodeGen *g, TypeTableEntry *ptr_type, ui ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count); } -static TypeTableEntry *adjust_slice_align(CodeGen *g, TypeTableEntry *slice_type, uint32_t new_align) { +static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new_align) { assert(is_slice(slice_type)); - TypeTableEntry *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index].type_entry, + ZigType *ptr_type = adjust_ptr_align(g, slice_type->data.structure.fields[slice_ptr_index].type_entry, new_align); return get_slice_type(g, ptr_type); } -static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrLen ptr_len) { +static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { assert(ptr_type->id == TypeTableEntryIdPointer); return get_pointer_to_type_extra(g, ptr_type->data.pointer.child_type, @@ -14197,7 +14197,7 @@ static TypeTableEntry *adjust_ptr_len(CodeGen *g, TypeTableEntry *ptr_type, PtrL ptr_type->data.pointer.bit_offset, ptr_type->data.pointer.unaligned_bit_count); } -static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { +static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) { Error err; IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other; if (type_is_invalid(array_ptr->value.type)) @@ -14209,14 +14209,14 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc if (type_is_invalid(elem_index->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *ptr_type = orig_array_ptr_val->type; + ZigType *ptr_type = orig_array_ptr_val->type; assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *array_type = ptr_type->data.pointer.child_type; + ZigType *array_type = ptr_type->data.pointer.child_type; // At first return_type will be the pointer type we want to return, except with an optimistic alignment. // We will adjust return_type's alignment before returning it. - TypeTableEntry *return_type; + ZigType *return_type; if (type_is_invalid(array_type)) { return array_type; @@ -14240,7 +14240,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc buf_sprintf("index 0 outside array of size 0")); return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *child_type = array_type->data.array.child_type; + ZigType *child_type = array_type->data.array.child_type; if (ptr_type->data.pointer.unaligned_bit_count == 0) { return_type = get_pointer_to_type_extra(ira->codegen, child_type, ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, @@ -14306,7 +14306,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; + ZigType *usize = ira->codegen->builtin_types.entry_usize; IrInstruction *casted_elem_index = ir_implicit_cast(ira, elem_index, usize); if (casted_elem_index == ira->codegen->invalid_instruction) return ira->codegen->builtin_types.entry_invalid; @@ -14496,8 +14496,8 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc } static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, - TypeTableEntry *bare_struct_type, Buf *field_name, IrInstruction *source_instr, - IrInstruction *container_ptr, TypeTableEntry *container_type) + ZigType *bare_struct_type, Buf *field_name, IrInstruction *source_instr, + IrInstruction *container_ptr, ZigType *container_type) { if (!is_slice(bare_struct_type)) { ScopeDecls *container_scope = get_container_scope(bare_struct_type); @@ -14536,11 +14536,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, } static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, - IrInstruction *source_instr, IrInstruction *container_ptr, TypeTableEntry *container_type) + IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type) { Error err; - TypeTableEntry *bare_type = container_ref_type(container_type); + ZigType *bare_type = container_ref_type(container_type); if ((err = ensure_complete_type(ira->codegen, bare_type))) return ira->codegen->invalid_instruction; @@ -14568,7 +14568,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ if (type_is_invalid(struct_val->type)) return ira->codegen->invalid_instruction; ConstExprValue *field_val = &struct_val->data.x_struct.fields[field->src_index]; - TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type, + ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_val->type, is_const, is_volatile, PtrLenSingle, align_bytes, (uint32_t)(ptr_bit_offset + field->packed_bits_offset), (uint32_t)unaligned_bit_count_for_result_type); @@ -14625,7 +14625,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ ConstExprValue *payload_val = union_val->data.x_union.payload; - TypeTableEntry *field_type = field->type_entry; + ZigType *field_type = field->type_entry; if (field_type->id == TypeTableEntryIdVoid) { assert(payload_val == nullptr); payload_val = create_const_vals(1); @@ -14633,7 +14633,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ payload_val->type = field_type; } - TypeTableEntry *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, + ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, field_type, is_const, is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, field_type), 0, 0); @@ -14680,7 +14680,7 @@ static void add_link_lib_symbol(IrAnalyze *ira, Buf *lib_name, Buf *symbol_name, } -static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { +static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instruction, Tld *tld) { bool pointer_only = false; resolve_top_level_decl(ira->codegen, tld, pointer_only, source_instruction->source_node); if (tld->resolution == TldResolutionInvalid) @@ -14731,7 +14731,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source zig_unreachable(); } -static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf *field_name) { +static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_name) { assert(err_set_type->id == TypeTableEntryIdErrorSet); for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i]; @@ -14742,13 +14742,13 @@ static ErrorTableEntry *find_err_table_entry(TypeTableEntry *err_set_type, Buf * return nullptr; } -static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { +static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) { Error err; IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other; if (type_is_invalid(container_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *container_type = container_ptr->value.type->data.pointer.child_type; + ZigType *container_type = container_ptr->value.type->data.pointer.child_type; assert(container_ptr->value.type->id == TypeTableEntryIdPointer); Buf *field_name = field_ptr_instruction->field_name_buffer; @@ -14767,7 +14767,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru } else if (is_container_ref(container_type)) { assert(container_ptr->value.type->id == TypeTableEntryIdPointer); if (container_type->id == TypeTableEntryIdPointer) { - TypeTableEntry *bare_type = container_ref_type(container_type); + ZigType *bare_type = container_ref_type(container_type); IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr); IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type); ir_link_new_instruction(result, &field_ptr_instruction->base); @@ -14786,7 +14786,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru init_const_usize(ira->codegen, len_val, container_type->data.array.len); } - TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; + ZigType *usize = ira->codegen->builtin_types.entry_usize; bool ptr_is_const = true; bool ptr_is_volatile = false; return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val, @@ -14812,7 +14812,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru size_t len = child_val->data.x_arg_tuple.end_index - child_val->data.x_arg_tuple.start_index; init_const_usize(ira->codegen, len_val, len); - TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; + ZigType *usize = ira->codegen->builtin_types.entry_usize; bool ptr_is_const = true; bool ptr_is_volatile = false; return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, len_val, @@ -14832,7 +14832,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node); if (child_val == nullptr) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *child_type = child_val->data.x_type; + ZigType *child_type = child_val->data.x_type; if (type_is_invalid(child_type)) { return ira->codegen->builtin_types.entry_invalid; @@ -14842,7 +14842,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru bool ptr_is_volatile = false; TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index]; assert(ptr_field->type_entry->id == TypeTableEntryIdPointer); - TypeTableEntry *child_type = ptr_field->type_entry->data.pointer.child_type; + ZigType *child_type = ptr_field->type_entry->data.pointer.child_type; return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, create_const_type(ira->codegen, child_type), ira->codegen->builtin_types.entry_type, @@ -14877,7 +14877,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru return ira->codegen->builtin_types.entry_invalid; TypeUnionField *field = find_union_type_field(child_type, field_name); if (field) { - TypeTableEntry *enum_type = child_type->data.unionation.tag_type; + ZigType *enum_type = child_type->data.unionation.tag_type; bool ptr_is_const = true; bool ptr_is_volatile = false; return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, @@ -14891,7 +14891,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru return ira->codegen->builtin_types.entry_invalid; } else if (child_type->id == TypeTableEntryIdErrorSet) { ErrorTableEntry *err_entry; - TypeTableEntry *err_set_type; + ZigType *err_set_type; if (type_is_global_error_set(child_type)) { auto existing_entry = ira->codegen->error_table.maybe_get(field_name); if (existing_entry) { @@ -15131,7 +15131,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru } } -static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *load_ptr_instruction) { +static ZigType *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstructionLoadPtr *load_ptr_instruction) { IrInstruction *ptr = load_ptr_instruction->ptr->other; if (type_is_invalid(ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -15142,7 +15142,7 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) { +static ZigType *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) { IrInstruction *ptr = store_ptr_instruction->ptr->other; if (type_is_invalid(ptr->value.type)) return ptr->value.type; @@ -15166,7 +15166,7 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type; + ZigType *child_type = ptr->value.type->data.pointer.child_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, child_type); if (casted_value == ira->codegen->invalid_instruction) return ira->codegen->builtin_types.entry_invalid; @@ -15202,9 +15202,9 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { +static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) { IrInstruction *expr_value = typeof_instruction->value->other; - TypeTableEntry *type_entry = expr_value->value.type; + ZigType *type_entry = expr_value->value.type; if (type_is_invalid(type_entry)) return ira->codegen->builtin_types.entry_invalid; switch (type_entry->id) { @@ -15246,15 +15246,15 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, IrInstructionToPtrType *to_ptr_type_instruction) { IrInstruction *value = to_ptr_type_instruction->value->other; - TypeTableEntry *type_entry = value->value.type; + ZigType *type_entry = value->value.type; if (type_is_invalid(type_entry)) return type_entry; - TypeTableEntry *ptr_type; + ZigType *ptr_type; if (type_entry->id == TypeTableEntryIdArray) { ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false); } else if (is_slice(type_entry)) { @@ -15275,11 +15275,11 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, return ira->codegen->builtin_types.entry_type; } -static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, IrInstructionPtrTypeChild *ptr_type_child_instruction) { IrInstruction *type_value = ptr_type_child_instruction->value->other; - TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); + ZigType *type_entry = ir_resolve_type(ira, type_value); if (type_is_invalid(type_entry)) return type_entry; @@ -15294,7 +15294,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, return ira->codegen->builtin_types.entry_type; } -static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) { +static ZigType *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSetCold *instruction) { if (ira->new_irb.exec->is_inline) { // ignore setCold when running functions at compile time ir_build_const_from(ira, &instruction->base); @@ -15324,7 +15324,7 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc ir_build_const_from(ira, &instruction->base); return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, IrInstructionSetRuntimeSafety *set_runtime_safety_instruction) { if (ira->new_irb.exec->is_inline) { @@ -15381,11 +15381,11 @@ static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, IrInstructionSetFloatMode *instruction) { IrInstruction *target_instruction = instruction->scope_value->other; - TypeTableEntry *target_type = target_instruction->value.type; + ZigType *target_type = target_instruction->value.type; if (type_is_invalid(target_type)) return ira->codegen->builtin_types.entry_invalid; ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad); @@ -15412,7 +15412,7 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node; } else if (target_type->id == TypeTableEntryIdMetaType) { ScopeDecls *decls_scope; - TypeTableEntry *type_arg = target_val->data.x_type; + ZigType *type_arg = target_val->data.x_type; if (type_arg->id == TypeTableEntryIdStruct) { decls_scope = type_arg->data.structure.decls_scope; } else if (type_arg->id == TypeTableEntryIdEnum) { @@ -15452,7 +15452,7 @@ static TypeTableEntry *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, IrInstructionSliceType *slice_type_instruction) { Error err; @@ -15462,7 +15462,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->other); + ZigType *child_type = ir_resolve_type(ira, slice_type_instruction->child_type->other); if (type_is_invalid(child_type)) return ira->codegen->builtin_types.entry_invalid; @@ -15509,9 +15509,9 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, { if ((err = type_ensure_zero_bits_known(ira->codegen, child_type))) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, + ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, child_type, is_const, is_volatile, PtrLenUnknown, align_bytes, 0, 0); - TypeTableEntry *result_type = get_slice_type(ira->codegen, slice_ptr_type); + ZigType *result_type = get_slice_type(ira->codegen, slice_ptr_type); ConstExprValue *out_val = ir_build_const_from(ira, &slice_type_instruction->base); out_val->data.x_type = result_type; return ira->codegen->builtin_types.entry_type; @@ -15520,7 +15520,7 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira, zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) { +static ZigType *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionAsm *asm_instruction) { assert(asm_instruction->base.source_node->type == NodeTypeAsmExpr); AstNodeAsmExpr *asm_expr = &asm_instruction->base.source_node->data.asm_expr; @@ -15550,7 +15550,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA IrInstruction **input_list = allocate(asm_expr->input_list.length); IrInstruction **output_types = allocate(asm_expr->output_list.length); - TypeTableEntry *return_type = ira->codegen->builtin_types.entry_void; + ZigType *return_type = ira->codegen->builtin_types.entry_void; for (size_t i = 0; i < asm_expr->output_list.length; i += 1) { AsmOutput *asm_output = asm_expr->output_list.at(i); if (asm_output->return_type) { @@ -15572,7 +15572,7 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA return return_type; } -static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira, IrInstructionArrayType *array_type_instruction) { Error err; @@ -15583,7 +15583,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; IrInstruction *child_type_value = array_type_instruction->child_type->other; - TypeTableEntry *child_type = ir_resolve_type(ira, child_type_value); + ZigType *child_type = ir_resolve_type(ira, child_type_value); if (type_is_invalid(child_type)) return ira->codegen->builtin_types.entry_invalid; switch (child_type->id) { @@ -15620,7 +15620,7 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, { if ((err = ensure_complete_type(ira->codegen, child_type))) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *result_type = get_array_type(ira->codegen, child_type, size); + ZigType *result_type = get_array_type(ira->codegen, child_type, size); ConstExprValue *out_val = ir_build_const_from(ira, &array_type_instruction->base); out_val->data.x_type = result_type; return ira->codegen->builtin_types.entry_type; @@ -15629,13 +15629,13 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira, zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) { - TypeTableEntry *promise_type; +static ZigType *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrInstructionPromiseType *instruction) { + ZigType *promise_type; if (instruction->payload_type == nullptr) { promise_type = ira->codegen->builtin_types.entry_promise; } else { - TypeTableEntry *payload_type = ir_resolve_type(ira, instruction->payload_type->other); + ZigType *payload_type = ir_resolve_type(ira, instruction->payload_type->other); if (type_is_invalid(payload_type)) return ira->codegen->builtin_types.entry_invalid; @@ -15647,12 +15647,12 @@ static TypeTableEntry *ir_analyze_instruction_promise_type(IrAnalyze *ira, IrIns return ira->codegen->builtin_types.entry_type; } -static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira, IrInstructionSizeOf *size_of_instruction) { Error err; IrInstruction *type_value = size_of_instruction->type_value->other; - TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); + ZigType *type_entry = ir_resolve_type(ira, type_value); if ((err = ensure_complete_type(ira->codegen, type_entry))) return ira->codegen->builtin_types.entry_invalid; @@ -15698,12 +15698,12 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira, zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { +static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) { IrInstruction *value = instruction->value->other; if (type_is_invalid(value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *type_entry = value->value.type; + ZigType *type_entry = value->value.type; if (type_entry->id == TypeTableEntryIdOptional) { if (instr_is_comptime(value)) { @@ -15729,17 +15729,17 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn } } -static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, IrInstructionUnwrapOptional *unwrap_maybe_instruction) { IrInstruction *value = unwrap_maybe_instruction->value->other; if (type_is_invalid(value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *ptr_type = value->value.type; + ZigType *ptr_type = value->value.type; assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; + ZigType *type_entry = ptr_type->data.pointer.child_type; if (type_is_invalid(type_entry)) { return ira->codegen->builtin_types.entry_invalid; } else if (type_entry->id != TypeTableEntryIdOptional) { @@ -15747,8 +15747,8 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name))); return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *child_type = type_entry->data.maybe.child_type; - TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, child_type, + ZigType *child_type = type_entry->data.maybe.child_type; + ZigType *result_type = get_pointer_to_type_extra(ira->codegen, child_type, ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, child_type), 0, 0); @@ -15783,12 +15783,12 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, return result_type; } -static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) { +static ZigType *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) { IrInstruction *value = ctz_instruction->value->other; if (type_is_invalid(value->value.type)) { return ira->codegen->builtin_types.entry_invalid; } else if (value->value.type->id == TypeTableEntryIdInt) { - TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen, + ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, value->value.type->data.integral.bit_count); if (value->value.special != ConstValSpecialRuntime) { size_t result = bigint_ctz(&value->value.data.x_bigint, @@ -15807,12 +15807,12 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC } } -static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) { +static ZigType *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) { IrInstruction *value = clz_instruction->value->other; if (type_is_invalid(value->value.type)) { return ira->codegen->builtin_types.entry_invalid; } else if (value->value.type->id == TypeTableEntryIdInt) { - TypeTableEntry *return_type = get_smallest_unsigned_int_type(ira->codegen, + ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, value->value.type->data.integral.bit_count); if (value->value.special != ConstValSpecialRuntime) { size_t result = bigint_clz(&value->value.data.x_bigint, @@ -15831,7 +15831,7 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC } } -static TypeTableEntry *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) { +static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPopCount *instruction) { IrInstruction *value = instruction->value->other; if (type_is_invalid(value->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -15895,7 +15895,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source return ira->codegen->invalid_instruction; } - TypeTableEntry *tag_type = value->value.type->data.unionation.tag_type; + ZigType *tag_type = value->value.type->data.unionation.tag_type; assert(tag_type->id == TypeTableEntryIdEnum); if (instr_is_comptime(value)) { @@ -15916,7 +15916,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source return result; } -static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira, IrInstructionSwitchBr *switch_br_instruction) { IrInstruction *target_value = switch_br_instruction->target_value->other; @@ -16024,7 +16024,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira, return ir_finish_anal(ira, ira->codegen->builtin_types.entry_unreachable); } -static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, IrInstructionSwitchTarget *switch_target_instruction) { Error err; @@ -16034,7 +16034,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, if (target_value_ptr->value.type->id == TypeTableEntryIdMetaType) { assert(instr_is_comptime(target_value_ptr)); - TypeTableEntry *ptr_type = target_value_ptr->value.data.x_type; + ZigType *ptr_type = target_value_ptr->value.data.x_type; assert(ptr_type->id == TypeTableEntryIdPointer); ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); out_val->type = ira->codegen->builtin_types.entry_type; @@ -16047,7 +16047,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type; + ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; ConstExprValue *pointee_val = nullptr; if (instr_is_comptime(target_value_ptr)) { pointee_val = ir_const_ptr_pointee(ira, &target_value_ptr->value, target_value_ptr->source_node); @@ -16095,7 +16095,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, buf_sprintf("consider 'union(enum)' here")); return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *tag_type = target_type->data.unionation.tag_type; + ZigType *tag_type = target_type->data.unionation.tag_type; assert(tag_type != nullptr); assert(tag_type->id == TypeTableEntryIdEnum); if (pointee_val) { @@ -16160,7 +16160,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { +static ZigType *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) { IrInstruction *target_value_ptr = instruction->target_value_ptr->other; if (type_is_invalid(target_value_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -16170,7 +16170,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr return ira->codegen->builtin_types.entry_invalid; assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer); - TypeTableEntry *target_type = target_value_ptr->value.type->data.pointer.child_type; + ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; if (target_type->id == TypeTableEntryIdUnion) { ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad); if (!prong_val) @@ -16205,14 +16205,14 @@ static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstr } } -static TypeTableEntry *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) { +static ZigType *ir_analyze_instruction_union_tag(IrAnalyze *ira, IrInstructionUnionTag *instruction) { IrInstruction *value = instruction->value->other; IrInstruction *new_instruction = ir_analyze_union_tag(ira, &instruction->base, value); ir_link_new_instruction(new_instruction, &instruction->base); return new_instruction->value.type; } -static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) { +static ZigType *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructionImport *import_instruction) { IrInstruction *name_value = import_instruction->name->other; Buf *import_target_str = ir_resolve_str(ira, name_value); if (!import_target_str) @@ -16278,11 +16278,11 @@ static TypeTableEntry *ir_analyze_instruction_import(IrAnalyze *ira, IrInstructi } -static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_array_len(IrAnalyze *ira, IrInstructionArrayLen *array_len_instruction) { IrInstruction *array_value = array_len_instruction->array_value->other; - TypeTableEntry *type_entry = array_value->value.type; + ZigType *type_entry = array_value->value.type; if (type_is_invalid(type_entry)) { return ira->codegen->builtin_types.entry_invalid; } else if (type_entry->id == TypeTableEntryIdArray) { @@ -16309,13 +16309,13 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira, } } -static TypeTableEntry *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { +static ZigType *ir_analyze_instruction_ref(IrAnalyze *ira, IrInstructionRef *ref_instruction) { IrInstruction *value = ref_instruction->value->other; return ir_analyze_ref(ira, &ref_instruction->base, value, ref_instruction->is_const, ref_instruction->is_volatile); } -static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction, - TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) +static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruction *instruction, + ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) { Error err; assert(container_type->id == TypeTableEntryIdUnion); @@ -16380,8 +16380,8 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir return container_type; } -static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction, - TypeTableEntry *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) +static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction *instruction, + ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) { Error err; if (container_type->id == TypeTableEntryIdUnion) { @@ -16500,7 +16500,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru return container_type; } -static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, IrInstructionContainerInitList *instruction) { IrInstruction *container_type_value = instruction->container_type->other; @@ -16509,7 +16509,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira size_t elem_count = instruction->item_count; if (container_type_value->value.type->id == TypeTableEntryIdMetaType) { - TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value); + ZigType *container_type = ir_resolve_type(ira, container_type_value); if (type_is_invalid(container_type)) return ira->codegen->builtin_types.entry_invalid; @@ -16518,11 +16518,11 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira 0, nullptr); } else if (is_slice(container_type) || container_type->id == TypeTableEntryIdArray) { // array is same as slice init but we make a compile error if the length is wrong - TypeTableEntry *child_type; + ZigType *child_type; if (container_type->id == TypeTableEntryIdArray) { child_type = container_type->data.array.child_type; if (container_type->data.array.len != elem_count) { - TypeTableEntry *literal_type = get_array_type(ira->codegen, child_type, elem_count); + ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count); ir_add_error(ira, &instruction->base, buf_sprintf("expected %s literal, found %s literal", @@ -16530,12 +16530,12 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira return ira->codegen->builtin_types.entry_invalid; } } else { - TypeTableEntry *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; assert(pointer_type->id == TypeTableEntryIdPointer); child_type = pointer_type->data.pointer.child_type; } - TypeTableEntry *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count); + ZigType *fixed_size_array_type = get_array_type(ira->codegen, child_type, elem_count); ConstExprValue const_val = {}; const_val.special = ConstValSpecialStatic; @@ -16618,9 +16618,9 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira } } -static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) { +static ZigType *ir_analyze_instruction_container_init_fields(IrAnalyze *ira, IrInstructionContainerInitFields *instruction) { IrInstruction *container_type_value = instruction->container_type->other; - TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value); + ZigType *container_type = ir_resolve_type(ira, container_type_value); if (type_is_invalid(container_type)) return ira->codegen->builtin_types.entry_invalid; @@ -16628,10 +16628,10 @@ static TypeTableEntry *ir_analyze_instruction_container_init_fields(IrAnalyze *i instruction->field_count, instruction->fields); } -static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction, +static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *target_type_value, bool is_max) { - TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value); + ZigType *target_type = ir_resolve_type(ira, target_type_value); if (type_is_invalid(target_type)) return ira->codegen->builtin_types.entry_invalid; switch (target_type->id) { @@ -16684,19 +16684,19 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_ zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_min_value(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_min_value(IrAnalyze *ira, IrInstructionMinValue *instruction) { return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, false); } -static TypeTableEntry *ir_analyze_instruction_max_value(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_max_value(IrAnalyze *ira, IrInstructionMaxValue *instruction) { return ir_analyze_min_max(ira, &instruction->base, instruction->value->other, true); } -static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_compile_err(IrAnalyze *ira, IrInstructionCompileErr *instruction) { IrInstruction *msg_value = instruction->msg->other; @@ -16720,7 +16720,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_err(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; } -static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) { +static ZigType *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInstructionCompileLog *instruction) { Buf buf = BUF_INIT; fprintf(stderr, "| "); for (size_t i = 0; i < instruction->msg_count; i += 1) { @@ -16740,7 +16740,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { +static ZigType *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) { IrInstruction *value = instruction->value->other; if (type_is_invalid(value->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -16749,9 +16749,9 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc if (type_is_invalid(casted_value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, + ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); - TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type); + ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); if (casted_value->value.special == ConstValSpecialStatic) { ErrorTableEntry *err = casted_value->value.data.x_err_set; if (!err->cached_error_name_val) { @@ -16768,7 +16768,7 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc return str_type; } -static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { +static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructionTagName *instruction) { Error err; IrInstruction *target = instruction->target->other; if (type_is_invalid(target->value.type)) @@ -16789,7 +16789,7 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn IrInstruction *result = ir_build_tag_name(&ira->new_irb, instruction->base.scope, instruction->base.source_node, target); ir_link_new_instruction(result, &instruction->base); - TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra( + ZigType *u8_ptr_type = get_pointer_to_type_extra( ira->codegen, ira->codegen->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), @@ -16798,12 +16798,12 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrIn return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, IrInstructionFieldParentPtr *instruction) { Error err; IrInstruction *type_value = instruction->type_value->other; - TypeTableEntry *container_type = ir_resolve_type(ira, type_value); + ZigType *container_type = ir_resolve_type(ira, type_value); if (type_is_invalid(container_type)) return ira->codegen->builtin_types.entry_invalid; @@ -16843,7 +16843,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, uint32_t field_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, field->type_entry); uint32_t parent_ptr_align = is_packed ? 1 : get_abi_alignment(ira->codegen, container_type); - TypeTableEntry *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry, + ZigType *field_ptr_type = get_pointer_to_type_extra(ira->codegen, field->type_entry, field_ptr->value.type->data.pointer.is_const, field_ptr->value.type->data.pointer.is_volatile, PtrLenSingle, @@ -16852,7 +16852,7 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, if (type_is_invalid(casted_field_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, container_type, + ZigType *result_type = get_pointer_to_type_extra(ira->codegen, container_type, casted_field_ptr->value.type->data.pointer.is_const, casted_field_ptr->value.type->data.pointer.is_volatile, PtrLenSingle, @@ -16891,12 +16891,12 @@ static TypeTableEntry *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, return result_type; } -static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_offset_of(IrAnalyze *ira, IrInstructionOffsetOf *instruction) { Error err; IrInstruction *type_value = instruction->type_value->other; - TypeTableEntry *container_type = ir_resolve_type(ira, type_value); + ZigType *container_type = ir_resolve_type(ira, type_value); if (type_is_invalid(container_type)) return ira->codegen->builtin_types.entry_invalid; @@ -16934,7 +16934,7 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira, return ira->codegen->builtin_types.entry_num_lit_int; } -static void ensure_field_index(TypeTableEntry *type, const char *field_name, size_t index) +static void ensure_field_index(ZigType *type, const char *field_name, size_t index) { Buf *field_name_buf; @@ -16945,10 +16945,10 @@ static void ensure_field_index(TypeTableEntry *type, const char *field_name, siz (buf_deinit(field_name_buf), true)); } -static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, TypeTableEntry *root) { +static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, ZigType *root) { Error err; static ConstExprValue *type_info_var = nullptr; - static TypeTableEntry *type_info_type = nullptr; + static ZigType *type_info_type = nullptr; if (type_info_var == nullptr) { type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); assert(type_info_var->type->id == TypeTableEntryIdMetaType); @@ -16963,7 +16963,7 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na else if (type_name == nullptr) return root; - TypeTableEntry *root_type = (root == nullptr) ? type_info_type : root; + ZigType *root_type = (root == nullptr) ? type_info_type : root; ScopeDecls *type_info_scope = get_container_scope(root_type); assert(type_info_scope != nullptr); @@ -16986,7 +16986,7 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope) { Error err; - TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr); + ZigType *type_info_definition_type = ir_type_info_get_type(ira, "Definition", nullptr); if ((err = ensure_complete_type(ira->codegen, type_info_definition_type))) return err; @@ -16994,15 +16994,15 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco ensure_field_index(type_info_definition_type, "is_pub", 1); ensure_field_index(type_info_definition_type, "data", 2); - TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type); + ZigType *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type); if ((err = ensure_complete_type(ira->codegen, type_info_definition_data_type))) return err; - TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type); + ZigType *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type); if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_type))) return err; - TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type); + ZigType *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type); if ((err = ensure_complete_type(ira->codegen, type_info_fn_def_inline_type))) return err; @@ -17153,7 +17153,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco // lib_name: ?[]const u8 ensure_field_index(fn_def_val->type, "lib_name", 6); fn_def_fields[6].special = ConstValSpecialStatic; - TypeTableEntry *u8_ptr = get_pointer_to_type_extra( + ZigType *u8_ptr = get_pointer_to_type_extra( ira->codegen, ira->codegen->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), @@ -17205,7 +17205,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco } case TldIdContainer: { - TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry; + ZigType *type_entry = ((TldContainer *)curr_entry->value)->type_entry; if ((err = ensure_complete_type(ira->codegen, type_entry))) return ErrorSemanticAnalyzeFail; @@ -17232,8 +17232,8 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco return ErrorNone; } -static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry *ptr_type_entry) { - TypeTableEntry *attrs_type; +static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_type_entry) { + ZigType *attrs_type; uint32_t size_enum_index; if (is_slice(ptr_type_entry)) { attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry; @@ -17245,7 +17245,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry zig_unreachable(); } - TypeTableEntry *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); + ZigType *type_info_pointer_type = ir_type_info_get_type(ira, "Pointer", nullptr); assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_type)); ConstExprValue *result = create_const_vals(1); @@ -17257,7 +17257,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry // size: Size ensure_field_index(result->type, "size", 0); - TypeTableEntry *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type); + ZigType *type_info_pointer_size_type = ir_type_info_get_type(ira, "Size", type_info_pointer_type); assertNoError(ensure_complete_type(ira->codegen, type_info_pointer_size_type)); fields[0].special = ConstValSpecialStatic; fields[0].type = type_info_pointer_size_type; @@ -17288,7 +17288,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, TypeTableEntry }; static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, TypeEnumField *enum_field, - TypeTableEntry *type_info_enum_field_type) + ZigType *type_info_enum_field_type) { enum_field_val->special = ConstValSpecialStatic; enum_field_val->type = type_info_enum_field_type; @@ -17305,7 +17305,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, enum_field_val->data.x_struct.fields = inner_fields; } -static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, ConstExprValue **out) { +static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstExprValue **out) { Error err; assert(type_entry != nullptr); assert(!type_is_invalid(type_entry)); @@ -17478,7 +17478,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, // fields: []TypeInfo.EnumField ensure_field_index(result->type, "fields", 2); - TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr); + ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr); uint32_t enum_field_count = type_entry->data.enumeration.src_field_count; ConstExprValue *enum_field_array = create_const_vals(1); @@ -17518,7 +17518,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, // errors: []TypeInfo.Error ensure_field_index(result->type, "errors", 0); - TypeTableEntry *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr); + ZigType *type_info_error_type = ir_type_info_get_type(ira, "Error", nullptr); uint32_t error_count = type_entry->data.error_set.err_count; ConstExprValue *error_array = create_const_vals(1); error_array->special = ConstValSpecialStatic; @@ -17612,7 +17612,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, // fields: []TypeInfo.UnionField ensure_field_index(result->type, "fields", 2); - TypeTableEntry *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr); + ZigType *type_info_union_field_type = ir_type_info_get_type(ira, "UnionField", nullptr); uint32_t union_field_count = type_entry->data.unionation.src_field_count; ConstExprValue *union_field_array = create_const_vals(1); @@ -17624,7 +17624,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, init_const_slice(ira->codegen, &fields[2], union_field_array, 0, union_field_count, false); - TypeTableEntry *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr); + ZigType *type_info_enum_field_type = ir_type_info_get_type(ira, "EnumField", nullptr); for (uint32_t union_field_index = 0; union_field_index < union_field_count; union_field_index++) { TypeUnionField *union_field = &type_entry->data.unionation.fields[union_field_index]; @@ -17685,7 +17685,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, // fields: []TypeInfo.StructField ensure_field_index(result->type, "fields", 1); - TypeTableEntry *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr); + ZigType *type_info_struct_field_type = ir_type_info_get_type(ira, "StructField", nullptr); uint32_t struct_field_count = type_entry->data.structure.src_field_count; ConstExprValue *struct_field_array = create_const_vals(1); @@ -17790,7 +17790,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, fields[4].data.x_optional = async_alloc_type; } // args: []TypeInfo.FnArg - TypeTableEntry *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr); + ZigType *type_info_fn_arg_type = ir_type_info_get_type(ira, "FnArg", nullptr); size_t fn_arg_count = type_entry->data.fn.fn_type_id.param_count - (is_varargs && type_entry->data.fn.fn_type_id.cc != CallingConventionC); @@ -17844,7 +17844,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, } case TypeTableEntryIdBoundFn: { - TypeTableEntry *fn_type = type_entry->data.bound_fn.fn_type; + ZigType *fn_type = type_entry->data.bound_fn.fn_type; assert(fn_type->id == TypeTableEntryIdFn); if ((err = ir_make_type_info_value(ira, fn_type, &result))) return err; @@ -17859,16 +17859,16 @@ static Error ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry, return ErrorNone; } -static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_type_info(IrAnalyze *ira, IrInstructionTypeInfo *instruction) { Error err; IrInstruction *type_value = instruction->type_value->other; - TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); + ZigType *type_entry = ir_resolve_type(ira, type_value); if (type_is_invalid(type_entry)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *result_type = ir_type_info_get_type(ira, nullptr, nullptr); + ZigType *result_type = ir_type_info_get_type(ira, nullptr, nullptr); ConstExprValue *payload; if ((err = ir_make_type_info_value(ira, type_entry, &payload))) @@ -17888,24 +17888,24 @@ static TypeTableEntry *ir_analyze_instruction_type_info(IrAnalyze *ira, return result_type; } -static TypeTableEntry *ir_analyze_instruction_type_id(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_type_id(IrAnalyze *ira, IrInstructionTypeId *instruction) { IrInstruction *type_value = instruction->type_value->other; - TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); + ZigType *type_entry = ir_resolve_type(ira, type_value); if (type_is_invalid(type_entry)) return ira->codegen->builtin_types.entry_invalid; ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId"); assert(var_value->type->id == TypeTableEntryIdMetaType); - TypeTableEntry *result_type = var_value->data.x_type; + ZigType *result_type = var_value->data.x_type; ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); bigint_init_unsigned(&out_val->data.x_enum_tag, type_id_index(type_entry)); return result_type; } -static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *ira, IrInstructionSetEvalBranchQuota *instruction) { if (ira->new_irb.exec->parent_exec != nullptr && !ira->new_irb.exec->is_generic_instantiation) { @@ -17926,9 +17926,9 @@ static TypeTableEntry *ir_analyze_instruction_set_eval_branch_quota(IrAnalyze *i return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) { +static ZigType *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) { IrInstruction *type_value = instruction->type_value->other; - TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); + ZigType *type_entry = ir_resolve_type(ira, type_value); if (type_is_invalid(type_entry)) return ira->codegen->builtin_types.entry_invalid; @@ -17940,7 +17940,7 @@ static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstru return out_val->type; } -static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) { +static ZigType *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstructionCImport *instruction) { AstNode *node = instruction->base.source_node; assert(node->type == NodeTypeFnCallExpr); AstNode *block_node = node->data.fn_call_expr.params.at(0); @@ -17948,7 +17948,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc ScopeCImport *cimport_scope = create_cimport_scope(node, instruction->base.scope); // Execute the C import block like an inline function - TypeTableEntry *void_type = ira->codegen->builtin_types.entry_void; + ZigType *void_type = ira->codegen->builtin_types.entry_void; IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type, ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, &cimport_scope->buf, block_node, nullptr, nullptr); @@ -17999,7 +17999,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_namespace; } -static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { +static ZigType *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) { IrInstruction *name_value = instruction->name->other; if (type_is_invalid(name_value->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18018,7 +18018,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { +static ZigType *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) { IrInstruction *name = instruction->name->other; if (type_is_invalid(name->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18045,7 +18045,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { +static ZigType *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) { IrInstruction *name = instruction->name->other; if (type_is_invalid(name->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18064,7 +18064,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { +static ZigType *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) { IrInstruction *name = instruction->name->other; if (type_is_invalid(name->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18106,8 +18106,8 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr return get_array_type(ira->codegen, ira->codegen->builtin_types.entry_u8, buf_len(file_contents)); } -static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) { - TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other); +static ZigType *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) { + ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->type_value->other); if (type_is_invalid(operand_type)) return ira->codegen->builtin_types.entry_invalid; @@ -18116,7 +18116,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct return ira->codegen->builtin_types.entry_invalid; // TODO let this be volatile - TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); + ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr, ptr_type); if (type_is_invalid(casted_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18187,7 +18187,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { +static ZigType *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) { IrInstruction *order_value = instruction->order_value->other; if (type_is_invalid(order_value->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18200,9 +18200,9 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) { +static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTruncate *instruction) { IrInstruction *dest_type_value = instruction->dest_type->other; - TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); + ZigType *dest_type = ir_resolve_type(ira, dest_type_value); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -18214,7 +18214,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc } IrInstruction *target = instruction->target->other; - TypeTableEntry *src_type = target->value.type; + ZigType *src_type = target->value.type; if (type_is_invalid(src_type)) return ira->codegen->builtin_types.entry_invalid; @@ -18248,8 +18248,8 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc return dest_type; } -static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) { - TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); +static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionIntCast *instruction) { + ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -18289,8 +18289,8 @@ static TypeTableEntry *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstruc return dest_type; } -static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) { - TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); +static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionFloatCast *instruction) { + ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -18337,8 +18337,8 @@ static TypeTableEntry *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstr return dest_type; } -static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) { - TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); +static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructionErrSetCast *instruction) { + ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -18365,8 +18365,8 @@ static TypeTableEntry *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrIns return dest_type; } -static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { - TypeTableEntry *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other); +static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionFromBytes *instruction) { + ZigType *dest_child_type = ir_resolve_type(ira, instruction->dest_child_type->other); if (type_is_invalid(dest_child_type)) return ira->codegen->builtin_types.entry_invalid; @@ -18382,7 +18382,7 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr src_ptr_volatile = target->value.type->data.pointer.is_volatile; src_ptr_align = target->value.type->data.pointer.alignment; } else if (is_slice(target->value.type)) { - TypeTableEntry *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; src_ptr_const = src_ptr_type->data.pointer.is_const; src_ptr_volatile = src_ptr_type->data.pointer.is_volatile; src_ptr_align = src_ptr_type->data.pointer.alignment; @@ -18392,15 +18392,15 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr src_ptr_align = get_abi_alignment(ira->codegen, target->value.type); } - TypeTableEntry *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type, + ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_child_type, src_ptr_const, src_ptr_volatile, PtrLenUnknown, src_ptr_align, 0, 0); - TypeTableEntry *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); + ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); - TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, + ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, src_ptr_const, src_ptr_volatile, PtrLenUnknown, src_ptr_align, 0, 0); - TypeTableEntry *u8_slice = get_slice_type(ira->codegen, u8_ptr); + ZigType *u8_slice = get_slice_type(ira->codegen, u8_ptr); IrInstruction *casted_value = ir_implicit_cast(ira, target, u8_slice); if (type_is_invalid(casted_value->value.type)) @@ -18445,7 +18445,7 @@ static TypeTableEntry *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstr return dest_slice_type; } -static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { +static ZigType *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstructionToBytes *instruction) { IrInstruction *target = instruction->target->other; if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18456,20 +18456,20 @@ static TypeTableEntry *ir_analyze_instruction_to_bytes(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *src_ptr_type = target->value.type->data.structure.fields[slice_ptr_index].type_entry; - TypeTableEntry *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, + ZigType *dest_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, src_ptr_type->data.pointer.is_const, src_ptr_type->data.pointer.is_volatile, PtrLenUnknown, src_ptr_type->data.pointer.alignment, 0, 0); - TypeTableEntry *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); + ZigType *dest_slice_type = get_slice_type(ira->codegen, dest_ptr_type); IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_slice_type, CastOpResizeSlice, true); ir_link_new_instruction(result, &instruction->base); return dest_slice_type; } -static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) { - TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); +static ZigType *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructionIntToFloat *instruction) { + ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -18488,8 +18488,8 @@ static TypeTableEntry *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrIns return dest_type; } -static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) { - TypeTableEntry *dest_type = ir_resolve_type(ira, instruction->dest_type->other); +static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructionFloatToInt *instruction) { + ZigType *dest_type = ir_resolve_type(ira, instruction->dest_type->other); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -18516,7 +18516,7 @@ static TypeTableEntry *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrIns return dest_type; } -static TypeTableEntry *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { +static ZigType *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionErrToInt *instruction) { IrInstruction *target = instruction->target->other; if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18535,7 +18535,7 @@ static TypeTableEntry *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstr return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { +static ZigType *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstructionIntToErr *instruction) { IrInstruction *target = instruction->target->other; if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18549,7 +18549,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_err(IrAnalyze *ira, IrInstr return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { +static ZigType *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstructionBoolToInt *instruction) { IrInstruction *target = instruction->target->other; if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18570,13 +18570,13 @@ static TypeTableEntry *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInst return ira->codegen->builtin_types.entry_num_lit_int; } - TypeTableEntry *u1_type = get_int_type(ira->codegen, false, 1); + ZigType *u1_type = get_int_type(ira->codegen, false, 1); IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, u1_type, CastOpBoolToInt, false); ir_link_new_instruction(result, &instruction->base); return u1_type; } -static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) { +static ZigType *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstructionIntType *instruction) { IrInstruction *is_signed_value = instruction->is_signed->other; bool is_signed; if (!ir_resolve_bool(ira, is_signed_value, &is_signed)) @@ -18592,12 +18592,12 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_type; } -static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { +static ZigType *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) { IrInstruction *value = instruction->value->other; if (type_is_invalid(value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool; + ZigType *bool_type = ira->codegen->builtin_types.entry_bool; IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type); if (type_is_invalid(casted_value->value.type)) @@ -18617,7 +18617,7 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc return bool_type; } -static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { +static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) { IrInstruction *dest_ptr = instruction->dest_ptr->other; if (type_is_invalid(dest_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18630,15 +18630,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi if (type_is_invalid(count_value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *dest_uncasted_type = dest_ptr->value.type; + ZigType *dest_uncasted_type = dest_ptr->value.type; bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) && dest_uncasted_type->data.pointer.is_volatile; - TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; - TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; + ZigType *usize = ira->codegen->builtin_types.entry_usize; + ZigType *u8 = ira->codegen->builtin_types.entry_u8; uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ? dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); - TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, + ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, PtrLenUnknown, dest_align, 0, 0); IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr); @@ -18709,7 +18709,7 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { +static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) { IrInstruction *dest_ptr = instruction->dest_ptr->other; if (type_is_invalid(dest_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18722,9 +18722,9 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi if (type_is_invalid(count_value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; - TypeTableEntry *dest_uncasted_type = dest_ptr->value.type; - TypeTableEntry *src_uncasted_type = src_ptr->value.type; + ZigType *u8 = ira->codegen->builtin_types.entry_u8; + ZigType *dest_uncasted_type = dest_ptr->value.type; + ZigType *src_uncasted_type = src_ptr->value.type; bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) && dest_uncasted_type->data.pointer.is_volatile; bool src_is_volatile = (src_uncasted_type->id == TypeTableEntryIdPointer) && @@ -18734,10 +18734,10 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi uint32_t src_align = (src_uncasted_type->id == TypeTableEntryIdPointer) ? src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); - TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; - TypeTableEntry *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, + ZigType *usize = ira->codegen->builtin_types.entry_usize; + ZigType *u8_ptr_mut = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, PtrLenUnknown, dest_align, 0, 0); - TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, + ZigType *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, PtrLenUnknown, src_align, 0, 0); IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut); @@ -18844,20 +18844,20 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) { +static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) { IrInstruction *ptr_ptr = instruction->ptr->other; if (type_is_invalid(ptr_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *ptr_type = ptr_ptr->value.type; + ZigType *ptr_type = ptr_ptr->value.type; assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *array_type = ptr_type->data.pointer.child_type; + ZigType *array_type = ptr_type->data.pointer.child_type; IrInstruction *start = instruction->start->other; if (type_is_invalid(start->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; + ZigType *usize = ira->codegen->builtin_types.entry_usize; IrInstruction *casted_start = ir_implicit_cast(ira, start, usize); if (type_is_invalid(casted_start->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18874,7 +18874,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio end = nullptr; } - TypeTableEntry *return_type; + ZigType *return_type; if (array_type->id == TypeTableEntryIdArray) { uint32_t byte_alignment = ptr_type->data.pointer.alignment; @@ -18883,7 +18883,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio } bool is_comptime_const = ptr_ptr->value.special == ConstValSpecialStatic && ptr_ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst; - TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, + ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.array.child_type, ptr_type->data.pointer.is_const || is_comptime_const, ptr_type->data.pointer.is_volatile, PtrLenUnknown, @@ -18891,9 +18891,9 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio return_type = get_slice_type(ira->codegen, slice_ptr_type); } else if (array_type->id == TypeTableEntryIdPointer) { if (array_type->data.pointer.ptr_len == PtrLenSingle) { - TypeTableEntry *main_type = array_type->data.pointer.child_type; + ZigType *main_type = array_type->data.pointer.child_type; if (main_type->id == TypeTableEntryIdArray) { - TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, + ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, main_type->data.pointer.child_type, array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, PtrLenUnknown, @@ -18904,7 +18904,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio return ira->codegen->builtin_types.entry_invalid; } } else { - TypeTableEntry *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type, + ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, array_type->data.pointer.child_type, array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, PtrLenUnknown, array_type->data.pointer.alignment, 0, 0); @@ -18915,7 +18915,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio } } } else if (is_slice(array_type)) { - TypeTableEntry *ptr_type = array_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *ptr_type = array_type->data.structure.fields[slice_ptr_index].type_entry; return_type = get_slice_type(ira->codegen, ptr_type); } else { ir_add_error(ira, &instruction->base, @@ -18936,7 +18936,7 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) { if (array_type->id == TypeTableEntryIdPointer) { - TypeTableEntry *child_array_type = array_type->data.pointer.child_type; + ZigType *child_array_type = array_type->data.pointer.child_type; assert(child_array_type->id == TypeTableEntryIdArray); parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); if (parent_ptr == nullptr) @@ -19109,12 +19109,12 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio return return_type; } -static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { +static ZigType *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) { Error err; IrInstruction *container = instruction->container->other; if (type_is_invalid(container->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *container_type = ir_resolve_type(ira, container); + ZigType *container_type = ir_resolve_type(ira, container); if ((err = ensure_complete_type(ira->codegen, container_type))) return ira->codegen->builtin_types.entry_invalid; @@ -19147,10 +19147,10 @@ static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrIns return ira->codegen->builtin_types.entry_num_lit_int; } -static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) { +static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstructionMemberType *instruction) { Error err; IrInstruction *container_type_value = instruction->container_type->other; - TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value); + ZigType *container_type = ir_resolve_type(ira, container_type_value); if (type_is_invalid(container_type)) return ira->codegen->builtin_types.entry_invalid; @@ -19194,10 +19194,10 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst } } -static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) { +static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstructionMemberName *instruction) { Error err; IrInstruction *container_type_value = instruction->container_type->other; - TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value); + ZigType *container_type = ir_resolve_type(ira, container_type_value); if (type_is_invalid(container_type)) return ira->codegen->builtin_types.entry_invalid; @@ -19252,28 +19252,28 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst } } -static TypeTableEntry *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { +static ZigType *ir_analyze_instruction_breakpoint(IrAnalyze *ira, IrInstructionBreakpoint *instruction) { ir_build_breakpoint_from(&ira->new_irb, &instruction->base); return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { +static ZigType *ir_analyze_instruction_return_address(IrAnalyze *ira, IrInstructionReturnAddress *instruction) { ir_build_return_address_from(&ira->new_irb, &instruction->base); - TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; - TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); + ZigType *u8 = ira->codegen->builtin_types.entry_u8; + ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); return u8_ptr_const; } -static TypeTableEntry *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { +static ZigType *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructionFrameAddress *instruction) { ir_build_frame_address_from(&ira->new_irb, &instruction->base); - TypeTableEntry *u8 = ira->codegen->builtin_types.entry_u8; - TypeTableEntry *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); + ZigType *u8 = ira->codegen->builtin_types.entry_u8; + ZigType *u8_ptr_const = get_pointer_to_type(ira->codegen, u8, true); return u8_ptr_const; } -static TypeTableEntry *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) { +static ZigType *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) { ir_build_handle_from(&ira->new_irb, &instruction->base); FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); @@ -19281,12 +19281,12 @@ static TypeTableEntry *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructi return get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type); } -static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) { +static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAlignOf *instruction) { Error err; IrInstruction *type_value = instruction->type_value->other; if (type_is_invalid(type_value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *type_entry = ir_resolve_type(ira, type_value); + ZigType *type_entry = ir_resolve_type(ira, type_value); if ((err = type_ensure_zero_bits_known(ira->codegen, type_entry))) return ira->codegen->builtin_types.entry_invalid; @@ -19332,12 +19332,12 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { +static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) { IrInstruction *type_value = instruction->type_value->other; if (type_is_invalid(type_value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *dest_type = ir_resolve_type(ira, type_value); + ZigType *dest_type = ir_resolve_type(ira, type_value); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -19361,7 +19361,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst IrInstruction *casted_op2; if (instruction->op == IrOverflowOpShl) { - TypeTableEntry *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, + ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, dest_type->data.integral.bit_count - 1); casted_op2 = ir_implicit_cast(ira, op2, shift_amt_type); } else { @@ -19374,7 +19374,7 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst if (type_is_invalid(result_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *expected_ptr_type; + ZigType *expected_ptr_type; if (result_ptr->value.type->id == TypeTableEntryIdPointer) { expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, false, result_ptr->value.type->data.pointer.is_volatile, @@ -19431,12 +19431,12 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst return ira->codegen->builtin_types.entry_bool; } -static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) { +static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) { IrInstruction *value = instruction->value->other; if (type_is_invalid(value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *type_entry = value->value.type; + ZigType *type_entry = value->value.type; if (type_is_invalid(type_entry)) { return ira->codegen->builtin_types.entry_invalid; } else if (type_entry->id == TypeTableEntryIdErrorUnion) { @@ -19452,7 +19452,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc } } - TypeTableEntry *err_set_type = type_entry->data.error_union.err_set_type; + ZigType *err_set_type = type_entry->data.error_union.err_set_type; if (!resolve_inferred_error_set(ira->codegen, err_set_type, instruction->base.source_node)) { return ira->codegen->builtin_types.entry_invalid; } @@ -19478,18 +19478,18 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc } } -static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, IrInstructionUnwrapErrCode *instruction) { IrInstruction *value = instruction->value->other; if (type_is_invalid(value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *ptr_type = value->value.type; + ZigType *ptr_type = value->value.type; // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; + ZigType *type_entry = ptr_type->data.pointer.child_type; if (type_is_invalid(type_entry)) { return ira->codegen->builtin_types.entry_invalid; } else if (type_entry->id == TypeTableEntryIdErrorUnion) { @@ -19519,27 +19519,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, } } -static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, IrInstructionUnwrapErrPayload *instruction) { assert(instruction->value->other); IrInstruction *value = instruction->value->other; if (type_is_invalid(value->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *ptr_type = value->value.type; + ZigType *ptr_type = value->value.type; // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. assert(ptr_type->id == TypeTableEntryIdPointer); - TypeTableEntry *type_entry = ptr_type->data.pointer.child_type; + ZigType *type_entry = ptr_type->data.pointer.child_type; if (type_is_invalid(type_entry)) { return ira->codegen->builtin_types.entry_invalid; } else if (type_entry->id == TypeTableEntryIdErrorUnion) { - TypeTableEntry *payload_type = type_entry->data.error_union.payload_type; + ZigType *payload_type = type_entry->data.error_union.payload_type; if (type_is_invalid(payload_type)) { return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, + ZigType *result_type = get_pointer_to_type_extra(ira->codegen, payload_type, ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, PtrLenSingle, get_abi_alignment(ira->codegen, payload_type), 0, 0); @@ -19575,7 +19575,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, } -static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) { +static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnProto *instruction) { AstNode *proto_node = instruction->base.source_node; assert(proto_node->type == NodeTypeFnProto); @@ -19656,7 +19656,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_type; } -static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { +static ZigType *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) { IrInstruction *value = instruction->value->other; if (type_is_invalid(value->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -19666,11 +19666,11 @@ static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrIn return ira->codegen->builtin_types.entry_bool; } -static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, IrInstructionCheckSwitchProngs *instruction) { IrInstruction *target_value = instruction->target_value->other; - TypeTableEntry *switch_type = target_value->value.type; + ZigType *switch_type = target_value->value.type; if (type_is_invalid(switch_type)) return ira->codegen->builtin_types.entry_invalid; @@ -19846,11 +19846,11 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, IrInstructionCheckStatementIsVoid *instruction) { IrInstruction *statement_value = instruction->statement_value->other; - TypeTableEntry *statement_type = statement_value->value.type; + ZigType *statement_type = statement_value->value.type; if (type_is_invalid(statement_type)) return ira->codegen->builtin_types.entry_invalid; @@ -19862,7 +19862,7 @@ static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { +static ZigType *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) { IrInstruction *msg = instruction->msg->other; if (type_is_invalid(msg->value.type)) return ir_unreach_error(ira); @@ -19872,9 +19872,9 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio return ir_unreach_error(ira); } - TypeTableEntry *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, + ZigType *u8_ptr_type = get_pointer_to_type_extra(ira->codegen, ira->codegen->builtin_types.entry_u8, true, false, PtrLenUnknown, get_abi_alignment(ira->codegen, ira->codegen->builtin_types.entry_u8), 0, 0); - TypeTableEntry *str_type = get_slice_type(ira->codegen, u8_ptr_type); + ZigType *str_type = get_slice_type(ira->codegen, u8_ptr_type); IrInstruction *casted_msg = ir_implicit_cast(ira, msg, str_type); if (type_is_invalid(casted_msg->value.type)) return ir_unreach_error(ira); @@ -19886,10 +19886,10 @@ static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructio } static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint32_t align_bytes, bool safety_check_on) { - TypeTableEntry *target_type = target->value.type; + ZigType *target_type = target->value.type; assert(!type_is_invalid(target_type)); - TypeTableEntry *result_type; + ZigType *result_type; uint32_t old_align_bytes; if (target_type->id == TypeTableEntryIdPointer) { @@ -19903,9 +19903,9 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 } else if (target_type->id == TypeTableEntryIdOptional && target_type->data.maybe.child_type->id == TypeTableEntryIdPointer) { - TypeTableEntry *ptr_type = target_type->data.maybe.child_type; + ZigType *ptr_type = target_type->data.maybe.child_type; old_align_bytes = ptr_type->data.pointer.alignment; - TypeTableEntry *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes); + ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes); result_type = get_optional_type(ira->codegen, better_ptr_type); } else if (target_type->id == TypeTableEntryIdOptional && @@ -19914,12 +19914,12 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id; old_align_bytes = fn_type_id.alignment; fn_type_id.alignment = align_bytes; - TypeTableEntry *fn_type = get_fn_type(ira->codegen, &fn_type_id); + ZigType *fn_type = get_fn_type(ira->codegen, &fn_type_id); result_type = get_optional_type(ira->codegen, fn_type); } else if (is_slice(target_type)) { - TypeTableEntry *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; + ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; old_align_bytes = slice_ptr_type->data.pointer.alignment; - TypeTableEntry *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); + ZigType *result_ptr_type = adjust_ptr_align(ira->codegen, slice_ptr_type, align_bytes); result_type = get_slice_type(ira->codegen, result_ptr_type); } else { ir_add_error(ira, target, @@ -19957,16 +19957,16 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 return result; } -static TypeTableEntry *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) { +static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtrCast *instruction) { Error err; IrInstruction *dest_type_value = instruction->dest_type->other; - TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); + ZigType *dest_type = ir_resolve_type(ira, dest_type_value); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; IrInstruction *ptr = instruction->ptr->other; - TypeTableEntry *src_type = ptr->value.type; + ZigType *src_type = ptr->value.type; if (type_is_invalid(src_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20155,15 +20155,15 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) { +static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBitCast *instruction) { Error err; IrInstruction *dest_type_value = instruction->dest_type->other; - TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); + ZigType *dest_type = ir_resolve_type(ira, dest_type_value); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; IrInstruction *value = instruction->value->other; - TypeTableEntry *src_type = value->value.type; + ZigType *src_type = value->value.type; if (type_is_invalid(src_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20255,10 +20255,10 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc return dest_type; } -static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) { +static ZigType *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstructionIntToPtr *instruction) { Error err; IrInstruction *dest_type_value = instruction->dest_type->other; - TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); + ZigType *dest_type = ir_resolve_type(ira, dest_type_value); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20300,7 +20300,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_ptr(IrAnalyze *ira, IrInstr return dest_type; } -static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira, IrInstructionDeclRef *instruction) { Tld *tld = instruction->tld; @@ -20361,12 +20361,12 @@ static TypeTableEntry *ir_analyze_instruction_decl_ref(IrAnalyze *ira, zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { +static ZigType *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionPtrToInt *instruction) { IrInstruction *target = instruction->target->other; if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize; + ZigType *usize = ira->codegen->builtin_types.entry_usize; if (get_codegen_ptr_type(target->value.type) == nullptr) { ir_add_error(ira, target, @@ -20400,9 +20400,9 @@ static TypeTableEntry *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstr return usize; } -static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { +static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtrType *instruction) { Error err; - TypeTableEntry *child_type = ir_resolve_type(ira, instruction->child_type->other); + ZigType *child_type = ir_resolve_type(ira, instruction->child_type->other); if (type_is_invalid(child_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20433,7 +20433,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_type; } -static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { +static ZigType *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstructionAlignCast *instruction) { uint32_t align_bytes; IrInstruction *align_bytes_inst = instruction->align_bytes->other; if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) @@ -20451,7 +20451,7 @@ static TypeTableEntry *ir_analyze_instruction_align_cast(IrAnalyze *ira, IrInstr return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { +static ZigType *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInstructionOpaqueType *instruction) { Buf *name = get_anon_type_name(ira->codegen, ira->new_irb.exec, "opaque", instruction->base.source_node); ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); out_val->data.x_type = get_opaque_type(ira->codegen, instruction->base.scope, instruction->base.source_node, @@ -20459,7 +20459,7 @@ static TypeTableEntry *ir_analyze_instruction_opaque_type(IrAnalyze *ira, IrInst return ira->codegen->builtin_types.entry_type; } -static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) { +static ZigType *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstructionSetAlignStack *instruction) { uint32_t align_bytes; IrInstruction *align_bytes_inst = instruction->align_bytes->other; if (!ir_resolve_align(ira, align_bytes_inst, &align_bytes)) @@ -20499,9 +20499,9 @@ static TypeTableEntry *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, Ir return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) { +static ZigType *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArgType *instruction) { IrInstruction *fn_type_inst = instruction->fn_type->other; - TypeTableEntry *fn_type = ir_resolve_type(ira, fn_type_inst); + ZigType *fn_type = ir_resolve_type(ira, fn_type_inst); if (type_is_invalid(fn_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20538,10 +20538,10 @@ static TypeTableEntry *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_type; } -static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) { +static ZigType *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTagType *instruction) { Error err; IrInstruction *target_inst = instruction->target->other; - TypeTableEntry *enum_type = ir_resolve_type(ira, target_inst); + ZigType *enum_type = ir_resolve_type(ira, target_inst); if (type_is_invalid(enum_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20576,7 +20576,7 @@ static TypeTableEntry *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstruc } } -static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) { +static ZigType *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructionCancel *instruction) { IrInstruction *target_inst = instruction->target->other; if (type_is_invalid(target_inst->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20591,7 +20591,7 @@ static TypeTableEntry *ir_analyze_instruction_cancel(IrAnalyze *ira, IrInstructi return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) { +static ZigType *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstructionCoroId *instruction) { IrInstruction *promise_ptr = instruction->promise_ptr->other; if (type_is_invalid(promise_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20603,7 +20603,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_id(IrAnalyze *ira, IrInstruct return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) { +static ZigType *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstructionCoroAlloc *instruction) { IrInstruction *coro_id = instruction->coro_id->other; if (type_is_invalid(coro_id->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20615,14 +20615,14 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc(IrAnalyze *ira, IrInstr return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) { +static ZigType *ir_analyze_instruction_coro_size(IrAnalyze *ira, IrInstructionCoroSize *instruction) { IrInstruction *result = ir_build_coro_size(&ira->new_irb, instruction->base.scope, instruction->base.source_node); ir_link_new_instruction(result, &instruction->base); result->value.type = ira->codegen->builtin_types.entry_usize; return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) { +static ZigType *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionCoroBegin *instruction) { IrInstruction *coro_id = instruction->coro_id->other; if (type_is_invalid(coro_id->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20640,13 +20640,13 @@ static TypeTableEntry *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstr return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) { +static ZigType *ir_analyze_instruction_get_implicit_allocator(IrAnalyze *ira, IrInstructionGetImplicitAllocator *instruction) { IrInstruction *result = ir_get_implicit_allocator(ira, &instruction->base, instruction->id); ir_link_new_instruction(result, &instruction->base); return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) { +static ZigType *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, IrInstructionCoroAllocFail *instruction) { IrInstruction *err_val = instruction->err_val->other; if (type_is_invalid(err_val->value.type)) return ir_unreach_error(ira); @@ -20657,7 +20657,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_fail(IrAnalyze *ira, Ir return ir_finish_anal(ira, result->value.type); } -static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) { +static ZigType *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrInstructionCoroSuspend *instruction) { IrInstruction *save_point = nullptr; if (instruction->save_point != nullptr) { save_point = instruction->save_point->other; @@ -20676,7 +20676,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_suspend(IrAnalyze *ira, IrIns return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) { +static ZigType *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstructionCoroEnd *instruction) { IrInstruction *result = ir_build_coro_end(&ira->new_irb, instruction->base.scope, instruction->base.source_node); ir_link_new_instruction(result, &instruction->base); @@ -20684,7 +20684,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_end(IrAnalyze *ira, IrInstruc return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) { +static ZigType *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstructionCoroFree *instruction) { IrInstruction *coro_id = instruction->coro_id->other; if (type_is_invalid(coro_id->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20696,12 +20696,12 @@ static TypeTableEntry *ir_analyze_instruction_coro_free(IrAnalyze *ira, IrInstru IrInstruction *result = ir_build_coro_free(&ira->new_irb, instruction->base.scope, instruction->base.source_node, coro_id, coro_handle); ir_link_new_instruction(result, &instruction->base); - TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false); + ZigType *ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false); result->value.type = get_optional_type(ira->codegen, ptr_type); return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) { +static ZigType *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInstructionCoroResume *instruction) { IrInstruction *awaiter_handle = instruction->awaiter_handle->other; if (type_is_invalid(awaiter_handle->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20717,7 +20717,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_resume(IrAnalyze *ira, IrInst return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) { +static ZigType *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstructionCoroSave *instruction) { IrInstruction *coro_handle = instruction->coro_handle->other; if (type_is_invalid(coro_handle->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20729,7 +20729,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_save(IrAnalyze *ira, IrInstru return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) { +static ZigType *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructionCoroPromise *instruction) { IrInstruction *coro_handle = instruction->coro_handle->other; if (type_is_invalid(coro_handle->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20742,7 +20742,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns return ira->codegen->builtin_types.entry_invalid; } - TypeTableEntry *coro_frame_type = get_promise_frame_type(ira->codegen, + ZigType *coro_frame_type = get_promise_frame_type(ira->codegen, coro_handle->value.type->data.promise.result_type); IrInstruction *result = ir_build_coro_promise(&ira->new_irb, instruction->base.scope, @@ -20752,7 +20752,7 @@ static TypeTableEntry *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrIns return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) { +static ZigType *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstructionCoroAllocHelper *instruction) { IrInstruction *alloc_fn = instruction->alloc_fn->other; if (type_is_invalid(alloc_fn->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20764,13 +20764,13 @@ static TypeTableEntry *ir_analyze_instruction_coro_alloc_helper(IrAnalyze *ira, IrInstruction *result = ir_build_coro_alloc_helper(&ira->new_irb, instruction->base.scope, instruction->base.source_node, alloc_fn, coro_size); ir_link_new_instruction(result, &instruction->base); - TypeTableEntry *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false); + ZigType *u8_ptr_type = get_pointer_to_type(ira->codegen, ira->codegen->builtin_types.entry_u8, false); result->value.type = get_optional_type(ira->codegen, u8_ptr_type); return result->value.type; } -static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) { - TypeTableEntry *operand_type = ir_resolve_type(ira, op); +static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op) { + ZigType *operand_type = ir_resolve_type(ira, op); if (type_is_invalid(operand_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20801,8 +20801,8 @@ static TypeTableEntry *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruct return operand_type; } -static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) { - TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); +static ZigType *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstructionAtomicRmw *instruction) { + ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); if (type_is_invalid(operand_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20811,7 +20811,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr return ira->codegen->builtin_types.entry_invalid; // TODO let this be volatile - TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); + ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, false); IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); if (type_is_invalid(casted_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20859,8 +20859,8 @@ static TypeTableEntry *ir_analyze_instruction_atomic_rmw(IrAnalyze *ira, IrInstr return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) { - TypeTableEntry *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); +static ZigType *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInstructionAtomicLoad *instruction) { + ZigType *operand_type = ir_resolve_atomic_operand_type(ira, instruction->operand_type->other); if (type_is_invalid(operand_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20868,7 +20868,7 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst if (type_is_invalid(ptr_inst->value.type)) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true); + ZigType *ptr_type = get_pointer_to_type(ira->codegen, operand_type, true); IrInstruction *casted_ptr = ir_implicit_cast(ira, ptr_inst, ptr_type); if (type_is_invalid(casted_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20902,8 +20902,8 @@ static TypeTableEntry *ir_analyze_instruction_atomic_load(IrAnalyze *ira, IrInst return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) { - TypeTableEntry *promise_type = ir_resolve_type(ira, instruction->promise_type->other); +static ZigType *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrInstructionPromiseResultType *instruction) { + ZigType *promise_type = ir_resolve_type(ira, instruction->promise_type->other); if (type_is_invalid(promise_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20918,8 +20918,8 @@ static TypeTableEntry *ir_analyze_instruction_promise_result_type(IrAnalyze *ira return ira->codegen->builtin_types.entry_type; } -static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) { - TypeTableEntry *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other); +static ZigType *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstructionAwaitBookkeeping *instruction) { + ZigType *promise_result_type = ir_resolve_type(ira, instruction->promise_result_type->other); if (type_is_invalid(promise_result_type)) return ira->codegen->builtin_types.entry_invalid; @@ -20935,7 +20935,7 @@ static TypeTableEntry *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, return out_val->type; } -static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira, +static ZigType *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira, IrInstructionMergeErrRetTraces *instruction) { IrInstruction *coro_promise_ptr = instruction->coro_promise_ptr->other; @@ -20943,9 +20943,9 @@ static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ir return ira->codegen->builtin_types.entry_invalid; assert(coro_promise_ptr->value.type->id == TypeTableEntryIdPointer); - TypeTableEntry *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type; + ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type; assert(promise_frame_type->id == TypeTableEntryIdStruct); - TypeTableEntry *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry; + ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry; if (!type_can_fail(promise_result_type)) { ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); @@ -20968,7 +20968,7 @@ static TypeTableEntry *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ir return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { +static ZigType *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, IrInstructionSaveErrRetAddr *instruction) { IrInstruction *result = ir_build_save_err_ret_addr(&ira->new_irb, instruction->base.scope, instruction->base.source_node); ir_link_new_instruction(result, &instruction->base); @@ -20976,7 +20976,7 @@ static TypeTableEntry *ir_analyze_instruction_save_err_ret_addr(IrAnalyze *ira, return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *ira, IrInstructionMarkErrRetTracePtr *instruction) { +static ZigType *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze *ira, IrInstructionMarkErrRetTracePtr *instruction) { IrInstruction *err_ret_trace_ptr = instruction->err_ret_trace_ptr->other; if (type_is_invalid(err_ret_trace_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -20988,8 +20988,8 @@ static TypeTableEntry *ir_analyze_instruction_mark_err_ret_trace_ptr(IrAnalyze * return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) { - TypeTableEntry *float_type = ir_resolve_type(ira, instruction->type->other); +static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *instruction) { + ZigType *float_type = ir_resolve_type(ira, instruction->type->other); if (type_is_invalid(float_type)) return ira->codegen->builtin_types.entry_invalid; @@ -21055,7 +21055,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { +static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstructionEnumToInt *instruction) { Error err; IrInstruction *target = instruction->target->other; if (type_is_invalid(target->value.type)) @@ -21070,17 +21070,17 @@ static TypeTableEntry *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInst if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type))) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *tag_type = target->value.type->data.enumeration.tag_int_type; + ZigType *tag_type = target->value.type->data.enumeration.tag_int_type; IrInstruction *result = ir_analyze_enum_to_int(ira, &instruction->base, target, tag_type); ir_link_new_instruction(result, &instruction->base); return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) { +static ZigType *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstructionIntToEnum *instruction) { Error err; IrInstruction *dest_type_value = instruction->dest_type->other; - TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value); + ZigType *dest_type = ir_resolve_type(ira, dest_type_value); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -21093,7 +21093,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst if ((err = type_ensure_zero_bits_known(ira->codegen, dest_type))) return ira->codegen->builtin_types.entry_invalid; - TypeTableEntry *tag_type = dest_type->data.enumeration.tag_int_type; + ZigType *tag_type = dest_type->data.enumeration.tag_int_type; IrInstruction *target = instruction->target->other; if (type_is_invalid(target->value.type)) @@ -21108,7 +21108,7 @@ static TypeTableEntry *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInst return result->value.type; } -static TypeTableEntry *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) { +static ZigType *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira, IrInstructionCheckRuntimeScope *instruction) { IrInstruction *block_comptime_inst = instruction->scope_is_comptime->other; bool scope_is_comptime; if (!ir_resolve_bool(ira, block_comptime_inst, &scope_is_comptime)) @@ -21131,7 +21131,7 @@ static TypeTableEntry *ir_analyze_instruction_check_runtime_scope(IrAnalyze *ira return ira->codegen->builtin_types.entry_void; } -static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { +static ZigType *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstruction *instruction) { switch (instruction->id) { case IrInstructionIdInvalid: case IrInstructionIdWidenOrShorten: @@ -21413,8 +21413,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi zig_unreachable(); } -static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) { - TypeTableEntry *instruction_type = ir_analyze_instruction_nocast(ira, instruction); +static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instruction) { + ZigType *instruction_type = ir_analyze_instruction_nocast(ira, instruction); instruction->value.type = instruction_type; if (instruction->other) { @@ -21430,8 +21430,8 @@ static TypeTableEntry *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *ins // This function attempts to evaluate IR code while doing type checking and other analysis. // It emits a new IrExecutable which is partially evaluated IR code. -TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, - TypeTableEntry *expected_type, AstNode *expected_type_source_node) +ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_exec, + ZigType *expected_type, AstNode *expected_type_source_node) { assert(!old_exec->invalid); assert(expected_type == nullptr || !type_is_invalid(expected_type)); @@ -21472,7 +21472,7 @@ TypeTableEntry *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutabl continue; } - TypeTableEntry *return_type = ir_analyze_instruction(ira, old_instruction); + ZigType *return_type = ir_analyze_instruction(ira, old_instruction); if (type_is_invalid(return_type) && ir_should_inline(new_exec, old_instruction->scope)) { return ira->codegen->builtin_types.entry_invalid; } diff --git a/src/ir.hpp b/src/ir.hpp index d8dfc3dcfa..a519ed2958 100644 --- a/src/ir.hpp +++ b/src/ir.hpp @@ -14,12 +14,12 @@ bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable bool ir_gen_fn(CodeGen *g, FnTableEntry *fn_entry); IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, - TypeTableEntry *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, + ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, IrExecutable *parent_exec); -TypeTableEntry *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable, - TypeTableEntry *expected_type, AstNode *expected_type_source_node); +ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable, + ZigType *expected_type, AstNode *expected_type_source_node); bool ir_has_side_effects(IrInstruction *instruction); ConstExprValue *const_ptr_pointee(CodeGen *codegen, ConstExprValue *const_val); -- cgit v1.2.3 From 3500d32db52eaf485b5cff2a26d382b37cfb85a3 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Sep 2018 18:34:33 -0400 Subject: stage1: rename FnTableEntry to ZigFn --- src/all_types.hpp | 40 +++++++++++------------ src/analyze.cpp | 52 +++++++++++++++--------------- src/analyze.hpp | 20 ++++++------ src/codegen.cpp | 22 ++++++------- src/ir.cpp | 96 +++++++++++++++++++++++++++---------------------------- src/ir.hpp | 4 +-- 6 files changed, 117 insertions(+), 117 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index 9317a92d32..7b728cae99 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -20,7 +20,7 @@ struct AstNode; struct ImportTableEntry; -struct FnTableEntry; +struct ZigFn; struct Scope; struct ScopeBlock; struct ScopeFnDef; @@ -43,7 +43,7 @@ struct IrAnalyze; struct IrExecutable { ZigList basic_block_list; Buf *name; - FnTableEntry *name_fn; + ZigFn *name_fn; size_t mem_slot_count; size_t next_debug_id; size_t *backward_branch_count; @@ -51,7 +51,7 @@ struct IrExecutable { bool invalid; bool is_inline; bool is_generic_instantiation; - FnTableEntry *fn_entry; + ZigFn *fn_entry; Buf *c_import_buf; AstNode *source_node; IrExecutable *parent_exec; @@ -191,7 +191,7 @@ struct ConstPtrValue { uint64_t addr; } hard_coded_addr; struct { - FnTableEntry *fn_entry; + ZigFn *fn_entry; } fn; } data; }; @@ -202,7 +202,7 @@ struct ConstErrValue { }; struct ConstBoundFnValue { - FnTableEntry *fn; + ZigFn *fn; IrInstruction *first_arg; }; @@ -345,7 +345,7 @@ struct TldVar { struct TldFn { Tld base; - FnTableEntry *fn_entry; + ZigFn *fn_entry; Buf *extern_lib_name; }; @@ -977,7 +977,7 @@ struct FnTypeParamInfo { }; struct GenericFnTypeId { - FnTableEntry *fn_entry; + ZigFn *fn_entry; ConstExprValue *params; size_t param_count; }; @@ -1080,7 +1080,7 @@ struct TypeTableEntryErrorUnion { struct TypeTableEntryErrorSet { uint32_t err_count; ErrorTableEntry **errors; - FnTableEntry *infer_fn; + ZigFn *infer_fn; }; struct TypeTableEntryEnum { @@ -1282,7 +1282,7 @@ struct FnExport { GlobalLinkageId linkage; }; -struct FnTableEntry { +struct ZigFn { LLVMValueRef llvm_value; const char *llvm_name; AstNode *proto_node; @@ -1323,8 +1323,8 @@ struct FnTableEntry { bool calls_or_awaits_errorable_fn; }; -uint32_t fn_table_entry_hash(FnTableEntry*); -bool fn_table_entry_eql(FnTableEntry *a, FnTableEntry *b); +uint32_t fn_table_entry_hash(ZigFn*); +bool fn_table_entry_eql(ZigFn *a, ZigFn *b); enum BuiltinFnId { BuiltinFnIdInvalid, @@ -1567,7 +1567,7 @@ struct CodeGen { HashMap type_table; HashMap fn_type_table; HashMap error_table; - HashMap generic_table; + HashMap generic_table; HashMap memoized_fn_eval_table; HashMap llvm_fn_table; HashMap exported_symbol_names; @@ -1672,14 +1672,14 @@ struct CodeGen { const char *linker_script; // The function definitions this module includes. - ZigList fn_defs; + ZigList fn_defs; size_t fn_defs_index; ZigList global_vars; OutType out_type; - FnTableEntry *cur_fn; - FnTableEntry *main_fn; - FnTableEntry *panic_fn; + ZigFn *cur_fn; + ZigFn *main_fn; + ZigFn *panic_fn; LLVMValueRef cur_ret_ptr; LLVMValueRef cur_fn_val; LLVMValueRef cur_err_ret_trace_val_arg; @@ -1734,7 +1734,7 @@ struct CodeGen { const char **llvm_argv; size_t llvm_argv_len; - ZigList test_fns; + ZigList test_fns; ZigType *test_fn_type; bool each_lib_rpath; @@ -1766,7 +1766,7 @@ struct CodeGen { Buf cache_dir; Buf *out_h_path; - ZigList inline_fns; + ZigList inline_fns; ZigList tld_ref_source_node_stack; ZigType *align_amt_type; @@ -1960,7 +1960,7 @@ struct ScopeCompTime { struct ScopeFnDef { Scope base; - FnTableEntry *fn_entry; + ZigFn *fn_entry; }; // This scope is created to indicate that the code in the scope @@ -2356,7 +2356,7 @@ struct IrInstructionCall { IrInstruction base; IrInstruction *fn_ref; - FnTableEntry *fn_entry; + ZigFn *fn_entry; size_t arg_count; IrInstruction **args; bool is_comptime; diff --git a/src/analyze.cpp b/src/analyze.cpp index 28dc54f11a..fbd96a872a 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -25,7 +25,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type); static Error ATTRIBUTE_MUST_USE resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type); static Error ATTRIBUTE_MUST_USE resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type); static Error ATTRIBUTE_MUST_USE resolve_union_zero_bits(CodeGen *g, ZigType *union_type); -static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry); +static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry); ErrorMsg *add_node_error(CodeGen *g, AstNode *node, Buf *msg) { if (node->owner->c_import_node != nullptr) { @@ -171,7 +171,7 @@ ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent) { return scope; } -ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry) { +ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, ZigFn *fn_entry) { ScopeFnDef *scope = allocate(1); init_scope(&scope->base, ScopeIdFnDef, node, parent); scope->fn_entry = fn_entry; @@ -991,7 +991,7 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c return entry; } -ZigType *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry) { +ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) { ZigType *fn_type = fn_entry->type_entry; assert(fn_type->id == TypeTableEntryIdFn); if (fn_type->data.fn.bound_fn_parent) @@ -1485,7 +1485,7 @@ static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) { zig_unreachable(); } -ZigType *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) { +ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) { ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); buf_resize(&err_set_type->name, 0); buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name)); @@ -1501,7 +1501,7 @@ ZigType *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry) { return err_set_type; } -static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, FnTableEntry *fn_entry) { +static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_scope, ZigFn *fn_entry) { assert(proto_node->type == NodeTypeFnProto); AstNodeFnProto *fn_proto = &proto_node->data.fn_proto; Error err; @@ -3038,8 +3038,8 @@ static void get_fully_qualified_decl_name(Buf *buf, Tld *tld, uint8_t sep) { buf_append_buf(buf, tld->name); } -FnTableEntry *create_fn_raw(FnInline inline_value) { - FnTableEntry *fn_entry = allocate(1); +ZigFn *create_fn_raw(FnInline inline_value) { + ZigFn *fn_entry = allocate(1); fn_entry->analyzed_executable.backward_branch_count = &fn_entry->prealloc_bbc; fn_entry->analyzed_executable.backward_branch_quota = default_backward_branch_quota; @@ -3050,12 +3050,12 @@ FnTableEntry *create_fn_raw(FnInline inline_value) { return fn_entry; } -FnTableEntry *create_fn(AstNode *proto_node) { +ZigFn *create_fn(AstNode *proto_node) { assert(proto_node->type == NodeTypeFnProto); AstNodeFnProto *fn_proto = &proto_node->data.fn_proto; FnInline inline_value = fn_proto->is_inline ? FnInlineAlways : FnInlineAuto; - FnTableEntry *fn_entry = create_fn_raw(inline_value); + ZigFn *fn_entry = create_fn_raw(inline_value); fn_entry->proto_node = proto_node; fn_entry->body_node = (proto_node->data.fn_proto.fn_def_node == nullptr) ? nullptr : @@ -3081,7 +3081,7 @@ static void wrong_panic_prototype(CodeGen *g, AstNode *proto_node, ZigType *fn_t buf_ptr(&fn_type->name))); } -static void typecheck_panic_fn(CodeGen *g, FnTableEntry *panic_fn) { +static void typecheck_panic_fn(CodeGen *g, ZigFn *panic_fn) { AstNode *proto_node = panic_fn->proto_node; assert(proto_node->type == NodeTypeFnProto); ZigType *fn_type = panic_fn->type_entry; @@ -3118,7 +3118,7 @@ ZigType *get_test_fn_type(CodeGen *g) { return g->test_fn_type; } -void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc) { +void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc) { if (ccc) { if (buf_eql_str(symbol_name, "main") && g->libc_link_lib != nullptr) { g->have_c_main = true; @@ -3154,7 +3154,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { AstNode *fn_def_node = fn_proto->fn_def_node; - FnTableEntry *fn_table_entry = create_fn(source_node); + ZigFn *fn_table_entry = create_fn(source_node); get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_'); if (fn_proto->is_export) { @@ -3215,7 +3215,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { } } } else if (source_node->type == NodeTypeTestDecl) { - FnTableEntry *fn_table_entry = create_fn_raw(FnInlineAuto); + ZigFn *fn_table_entry = create_fn_raw(FnInlineAuto); get_fully_qualified_decl_name(&fn_table_entry->symbol_name, &tld_fn->base, '_'); @@ -3750,7 +3750,7 @@ VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) { return nullptr; } -FnTableEntry *scope_fn_entry(Scope *scope) { +ZigFn *scope_fn_entry(Scope *scope) { while (scope) { if (scope->id == ScopeIdFnDef) { ScopeFnDef *fn_scope = (ScopeFnDef *)scope; @@ -3761,7 +3761,7 @@ FnTableEntry *scope_fn_entry(Scope *scope) { return nullptr; } -FnTableEntry *scope_get_fn_if_root(Scope *scope) { +ZigFn *scope_get_fn_if_root(Scope *scope) { assert(scope); scope = scope->parent; while (scope) { @@ -3981,7 +3981,7 @@ bool get_ptr_const(ZigType *type) { } } -AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) { +AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index) { if (fn_entry->param_source_nodes) return fn_entry->param_source_nodes[index]; else if (fn_entry->proto_node) @@ -3990,7 +3990,7 @@ AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index) { return nullptr; } -static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entry) { +static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) { ZigType *fn_type = fn_table_entry->type_entry; assert(!fn_type->data.fn.is_generic); FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; @@ -4032,7 +4032,7 @@ static void define_local_param_variables(CodeGen *g, FnTableEntry *fn_table_entr } bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node) { - FnTableEntry *infer_fn = err_set_type->data.error_set.infer_fn; + ZigFn *infer_fn = err_set_type->data.error_set.infer_fn; if (infer_fn != nullptr) { if (infer_fn->anal_state == FnAnalStateInvalid) { return false; @@ -4052,7 +4052,7 @@ bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *sour return true; } -void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_type_node) { +void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node) { ZigType *fn_type = fn_table_entry->type_entry; assert(!fn_type->data.fn.is_generic); FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; @@ -4113,7 +4113,7 @@ void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_typ fn_table_entry->anal_state = FnAnalStateComplete; } -static void analyze_fn_body(CodeGen *g, FnTableEntry *fn_table_entry) { +static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { assert(fn_table_entry->anal_state != FnAnalStateProbing); if (fn_table_entry->anal_state != FnAnalStateReady) return; @@ -4349,7 +4349,7 @@ void semantic_analyze(CodeGen *g) { } for (; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) { - FnTableEntry *fn_entry = g->fn_defs.at(g->fn_defs_index); + ZigFn *fn_entry = g->fn_defs.at(g->fn_defs_index); analyze_fn_body(g, fn_entry); } } @@ -4602,11 +4602,11 @@ static uint32_t hash_size(size_t x) { return (uint32_t)(x % UINT32_MAX); } -uint32_t fn_table_entry_hash(FnTableEntry* value) { +uint32_t fn_table_entry_hash(ZigFn* value) { return ptr_hash(value); } -bool fn_table_entry_eql(FnTableEntry *a, FnTableEntry *b) { +bool fn_table_entry_eql(ZigFn *a, ZigFn *b) { return ptr_eq(a, b); } @@ -5669,7 +5669,7 @@ void render_const_val_ptr(CodeGen *g, Buf *buf, ConstExprValue *const_val, ZigTy return; case ConstPtrSpecialFunction: { - FnTableEntry *fn_entry = const_val->data.x_ptr.data.fn.fn_entry; + ZigFn *fn_entry = const_val->data.x_ptr.data.fn.fn_entry; buf_appendf(buf, "@ptrCast(%s, %s)", buf_ptr(&const_val->type->name), buf_ptr(&fn_entry->symbol_name)); return; } @@ -5751,7 +5751,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { { assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst); assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction); - FnTableEntry *fn_entry = const_val->data.x_ptr.data.fn.fn_entry; + ZigFn *fn_entry = const_val->data.x_ptr.data.fn.fn_entry; buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name)); return; } @@ -5837,7 +5837,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { } case TypeTableEntryIdBoundFn: { - FnTableEntry *fn_entry = const_val->data.x_bound_fn.fn; + ZigFn *fn_entry = const_val->data.x_bound_fn.fn; buf_appendf(buf, "(bound fn %s)", buf_ptr(&fn_entry->symbol_name)); return; } diff --git a/src/analyze.hpp b/src/analyze.hpp index 58c9636dec..38491c9e09 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -31,7 +31,7 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind AstNode *decl_node, const char *name, ContainerLayout layout); ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x); ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type); -ZigType *get_bound_fn_type(CodeGen *g, FnTableEntry *fn_entry); +ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry); ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name); ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[], ZigType *field_types[], size_t field_count); @@ -77,17 +77,17 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node); void scan_import(CodeGen *g, ImportTableEntry *import); void preview_use_decl(CodeGen *g, AstNode *node); void resolve_use_decl(CodeGen *g, AstNode *node); -FnTableEntry *scope_fn_entry(Scope *scope); +ZigFn *scope_fn_entry(Scope *scope); ImportTableEntry *get_scope_import(Scope *scope); void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope); VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name, bool is_const, ConstExprValue *init_value, Tld *src_tld); ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node); -FnTableEntry *create_fn(AstNode *proto_node); -FnTableEntry *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage); +ZigFn *create_fn(AstNode *proto_node); +ZigFn *create_fn_raw(FnInline inline_value, GlobalLinkageId linkage); void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_count_alloc); -AstNode *get_param_decl_node(FnTableEntry *fn_entry, size_t index); -FnTableEntry *scope_get_fn_if_root(Scope *scope); +AstNode *get_param_decl_node(ZigFn *fn_entry, size_t index); +ZigFn *scope_get_fn_if_root(Scope *scope); bool type_requires_comptime(ZigType *type_entry); Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry); Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry); @@ -98,7 +98,7 @@ void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_v void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max); void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val); -void analyze_fn_ir(CodeGen *g, FnTableEntry *fn_table_entry, AstNode *return_type_node); +void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node); ScopeBlock *create_block_scope(AstNode *node, Scope *parent); ScopeDefer *create_defer_scope(AstNode *node, Scope *parent); @@ -107,7 +107,7 @@ Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var); ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent); ScopeLoop *create_loop_scope(AstNode *node, Scope *parent); ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent); -ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, FnTableEntry *fn_entry); +ScopeFnDef *create_fndef_scope(AstNode *node, Scope *parent, ZigFn *fn_entry); ScopeDecls *create_decls_scope(AstNode *node, Scope *parent, ZigType *container_type, ImportTableEntry *import); Scope *create_comptime_scope(AstNode *node, Scope *parent); Scope *create_coro_prelude_scope(AstNode *node, Scope *parent); @@ -190,14 +190,14 @@ ZigType *get_align_amt_type(CodeGen *g); PackageTableEntry *new_anonymous_package(void); Buf *const_value_to_buffer(ConstExprValue *const_val); -void add_fn_export(CodeGen *g, FnTableEntry *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc); +void add_fn_export(CodeGen *g, ZigFn *fn_table_entry, Buf *symbol_name, GlobalLinkageId linkage, bool ccc); ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name); ZigType *get_ptr_to_stack_trace_type(CodeGen *g); bool resolve_inferred_error_set(CodeGen *g, ZigType *err_set_type, AstNode *source_node); -ZigType *get_auto_err_set_type(CodeGen *g, FnTableEntry *fn_entry); +ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry); uint32_t get_coro_frame_align_bytes(CodeGen *g); bool fn_type_can_fail(FnTypeId *fn_type_id); diff --git a/src/codegen.cpp b/src/codegen.cpp index caddc0e898..cfaf05bf96 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -430,7 +430,7 @@ static LLVMLinkage to_llvm_linkage(GlobalLinkageId id) { zig_unreachable(); } -static uint32_t get_err_ret_trace_arg_index(CodeGen *g, FnTableEntry *fn_table_entry) { +static uint32_t get_err_ret_trace_arg_index(CodeGen *g, ZigFn *fn_table_entry) { if (!g->have_err_ret_tracing) { return UINT32_MAX; } @@ -446,7 +446,7 @@ static uint32_t get_err_ret_trace_arg_index(CodeGen *g, FnTableEntry *fn_table_e return first_arg_ret ? 1 : 0; } -static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) { +static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) { if (fn_table_entry->llvm_value) return fn_table_entry->llvm_value; @@ -628,7 +628,7 @@ static ZigLLVMDIScope *get_di_scope(CodeGen *g, Scope *scope) { { assert(scope->parent); ScopeFnDef *fn_scope = (ScopeFnDef *)scope; - FnTableEntry *fn_table_entry = fn_scope->fn_entry; + ZigFn *fn_table_entry = fn_scope->fn_entry; if (!fn_table_entry->proto_node) return get_di_scope(g, scope->parent); unsigned line_number = (unsigned)(fn_table_entry->proto_node->line == 0) ? @@ -3637,7 +3637,7 @@ static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) { LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder); LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder); - FnTableEntry *prev_cur_fn = g->cur_fn; + ZigFn *prev_cur_fn = g->cur_fn; LLVMValueRef prev_cur_fn_val = g->cur_fn_val; LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry"); @@ -4635,7 +4635,7 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f LLVMBasicBlockRef prev_block = LLVMGetInsertBlock(g->builder); LLVMValueRef prev_debug_location = LLVMGetCurrentDebugLocation(g->builder); - FnTableEntry *prev_cur_fn = g->cur_fn; + ZigFn *prev_cur_fn = g->cur_fn; LLVMValueRef prev_cur_fn_val = g->cur_fn_val; LLVMBasicBlockRef entry_block = LLVMAppendBasicBlock(fn_val, "Entry"); @@ -5037,7 +5037,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable, zig_unreachable(); } -static void ir_render(CodeGen *g, FnTableEntry *fn_entry) { +static void ir_render(CodeGen *g, ZigFn *fn_entry) { assert(fn_entry); IrExecutable *executable = &fn_entry->analyzed_executable; @@ -5688,7 +5688,7 @@ static void generate_error_name_table(CodeGen *g) { LLVMSetAlignment(g->err_name_table, LLVMABIAlignmentOfType(g->target_data_ref, LLVMTypeOf(err_name_table_init))); } -static void build_all_basic_blocks(CodeGen *g, FnTableEntry *fn) { +static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) { IrExecutable *executable = &fn->analyzed_executable; assert(executable->basic_block_list.length > 0); for (size_t block_i = 0; block_i < executable->basic_block_list.length; block_i += 1) { @@ -5747,7 +5747,7 @@ static void report_errors_and_maybe_exit(CodeGen *g) { static void validate_inline_fns(CodeGen *g) { for (size_t i = 0; i < g->inline_fns.length; i += 1) { - FnTableEntry *fn_entry = g->inline_fns.at(i); + ZigFn *fn_entry = g->inline_fns.at(i); LLVMValueRef fn_val = LLVMGetNamedFunction(g->module, fn_entry->llvm_name); if (fn_val != nullptr) { add_node_error(g, fn_entry->proto_node, buf_sprintf("unable to inline function")); @@ -5864,7 +5864,7 @@ static void do_code_gen(CodeGen *g) { // Generate function definitions. for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) { - FnTableEntry *fn_table_entry = g->fn_defs.at(fn_i); + ZigFn *fn_table_entry = g->fn_defs.at(fn_i); LLVMValueRef fn = fn_llvm_value(g, fn_table_entry); g->cur_fn = fn_table_entry; @@ -7083,7 +7083,7 @@ static void create_test_compile_var_and_add_test_runner(CodeGen *g) { test_fn_array->data.x_array.s_none.elements = create_const_vals(g->test_fns.length); for (size_t i = 0; i < g->test_fns.length; i += 1) { - FnTableEntry *test_fn_entry = g->test_fns.at(i); + ZigFn *test_fn_entry = g->test_fns.at(i); ConstExprValue *this_val = &test_fn_array->data.x_array.s_none.elements[i]; this_val->special = ConstValSpecialStatic; @@ -7483,7 +7483,7 @@ static void gen_h_file(CodeGen *g) { Buf h_buf = BUF_INIT; buf_resize(&h_buf, 0); for (size_t fn_def_i = 0; fn_def_i < g->fn_defs.length; fn_def_i += 1) { - FnTableEntry *fn_table_entry = g->fn_defs.at(fn_def_i); + ZigFn *fn_table_entry = g->fn_defs.at(fn_def_i); if (fn_table_entry->export_list.length == 0) continue; diff --git a/src/ir.cpp b/src/ir.cpp index 95bea43dab..1d9352f9d6 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -236,7 +236,7 @@ static size_t exec_next_mem_slot(IrExecutable *exec) { return result; } -static FnTableEntry *exec_fn_entry(IrExecutable *exec) { +static ZigFn *exec_fn_entry(IrExecutable *exec) { return exec->fn_entry; } @@ -1019,7 +1019,7 @@ static IrInstruction *ir_build_const_type(IrBuilder *irb, Scope *scope, AstNode return instruction; } -static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) { +static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) { IrInstructionConst *const_instruction = ir_create_instruction(irb, scope, source_node); const_instruction->base.value.type = fn_entry->type_entry; const_instruction->base.value.special = ConstValSpecialStatic; @@ -1029,7 +1029,7 @@ static IrInstruction *ir_create_const_fn(IrBuilder *irb, Scope *scope, AstNode * return &const_instruction->base; } -static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, FnTableEntry *fn_entry) { +static IrInstruction *ir_build_const_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigFn *fn_entry) { IrInstruction *instruction = ir_create_const_fn(irb, scope, source_node, fn_entry); ir_instruction_append(irb->current_basic_block, instruction); return instruction; @@ -1062,7 +1062,7 @@ static IrInstruction *ir_build_const_bool(IrBuilder *irb, Scope *scope, AstNode } static IrInstruction *ir_build_const_bound_fn(IrBuilder *irb, Scope *scope, AstNode *source_node, - FnTableEntry *fn_entry, IrInstruction *first_arg) + ZigFn *fn_entry, IrInstruction *first_arg) { IrInstructionConst *const_instruction = ir_build_instruction(irb, scope, source_node); const_instruction->base.value.type = get_bound_fn_type(irb->codegen, fn_entry); @@ -1199,7 +1199,7 @@ static IrInstruction *ir_build_union_field_ptr_from(IrBuilder *irb, IrInstructio } static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *source_node, - FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, + ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, IrInstruction *new_stack) { @@ -1227,7 +1227,7 @@ static IrInstruction *ir_build_call(IrBuilder *irb, Scope *scope, AstNode *sourc } static IrInstruction *ir_build_call_from(IrBuilder *irb, IrInstruction *old_instruction, - FnTableEntry *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, + ZigFn *fn_entry, IrInstruction *fn_ref, size_t arg_count, IrInstruction **args, bool is_comptime, FnInline fn_inline, bool is_async, IrInstruction *async_allocator, IrInstruction *new_stack) { @@ -3138,7 +3138,7 @@ static ScopeDeferExpr *get_scope_defer_expr(Scope *scope) { } static bool exec_is_async(IrExecutable *exec) { - FnTableEntry *fn_entry = exec_fn_entry(exec); + ZigFn *fn_entry = exec_fn_entry(exec); return fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; } @@ -3200,7 +3200,7 @@ static IrInstruction *ir_gen_async_return(IrBuilder *irb, Scope *scope, AstNode static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, LVal lval) { assert(node->type == NodeTypeReturnExpr); - FnTableEntry *fn_entry = exec_fn_entry(irb->exec); + ZigFn *fn_entry = exec_fn_entry(irb->exec); if (!fn_entry) { add_node_error(irb->codegen, node, buf_sprintf("return expression outside function definition")); return irb->codegen->invalid_instruction; @@ -3224,7 +3224,7 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, IrInstruction *return_value; if (expr_node) { // Temporarily set this so that if we return a type it gets the name of the function - FnTableEntry *prev_name_fn = irb->exec->name_fn; + ZigFn *prev_name_fn = irb->exec->name_fn; irb->exec->name_fn = exec_fn_entry(irb->exec); return_value = ir_gen_node(irb, expr_node, scope); irb->exec->name_fn = prev_name_fn; @@ -3403,7 +3403,7 @@ static IrInstruction *ir_gen_block(IrBuilder *irb, Scope *parent_scope, AstNode Scope *outer_block_scope = &scope_block->base; Scope *child_scope = outer_block_scope; - FnTableEntry *fn_entry = scope_fn_entry(parent_scope); + ZigFn *fn_entry = scope_fn_entry(parent_scope); if (fn_entry && fn_entry->child_scope == parent_scope) { fn_entry->def_scope = scope_block; } @@ -5686,7 +5686,7 @@ static IrInstruction *ir_gen_this_literal(IrBuilder *irb, Scope *scope, AstNode if (!scope->parent) return ir_build_const_import(irb, scope, node, node->owner); - FnTableEntry *fn_entry = scope_get_fn_if_root(scope); + ZigFn *fn_entry = scope_get_fn_if_root(scope); if (fn_entry) return ir_build_const_fn(irb, scope, node, fn_entry); @@ -6913,7 +6913,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n if (target_inst == irb->codegen->invalid_instruction) return irb->codegen->invalid_instruction; - FnTableEntry *fn_entry = exec_fn_entry(irb->exec); + ZigFn *fn_entry = exec_fn_entry(irb->exec); if (!fn_entry) { add_node_error(irb->codegen, node, buf_sprintf("await outside function definition")); return irb->codegen->invalid_instruction; @@ -7090,7 +7090,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n static IrInstruction *ir_gen_suspend(IrBuilder *irb, Scope *parent_scope, AstNode *node) { assert(node->type == NodeTypeSuspend); - FnTableEntry *fn_entry = exec_fn_entry(irb->exec); + ZigFn *fn_entry = exec_fn_entry(irb->exec); if (!fn_entry) { add_node_error(irb->codegen, node, buf_sprintf("suspend outside function definition")); return irb->codegen->invalid_instruction; @@ -7379,7 +7379,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec // Entry block gets a reference because we enter it to begin. ir_ref_bb(irb->current_basic_block); - FnTableEntry *fn_entry = exec_fn_entry(irb->exec); + ZigFn *fn_entry = exec_fn_entry(irb->exec); bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; IrInstruction *coro_id; IrInstruction *u8_ptr_type; @@ -7590,7 +7590,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec return true; } -bool ir_gen_fn(CodeGen *codegen, FnTableEntry *fn_entry) { +bool ir_gen_fn(CodeGen *codegen, ZigFn *fn_entry) { assert(fn_entry); IrExecutable *ir_executable = &fn_entry->ir_executable; @@ -9345,7 +9345,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT static void ir_add_alloca(IrAnalyze *ira, IrInstruction *instruction, ZigType *type_entry) { if (type_has_bits(type_entry) && handle_is_ptr(type_entry)) { - FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); if (fn_entry != nullptr) { fn_entry->alloca_list.append(instruction); } @@ -9749,7 +9749,7 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, - FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, + ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, IrExecutable *parent_exec) { if (expected_type != nullptr && type_is_invalid(expected_type)) @@ -9816,7 +9816,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { return const_val->data.x_type; } -static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { +static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { if (fn_value == ira->codegen->invalid_instruction) return nullptr; @@ -9996,7 +9996,7 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ ZigType *child_type = wanted_type->data.pointer.child_type; if (type_has_bits(child_type)) { - FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); assert(fn_entry); fn_entry->alloca_list.append(new_instruction); } @@ -10046,7 +10046,7 @@ static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instructi new_instruction->value.type = ptr_type; new_instruction->value.data.rh_ptr = RuntimeHintPtrStack; if (type_has_bits(ptr_type)) { - FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); assert(fn_entry); fn_entry->alloca_list.append(new_instruction); } @@ -12644,7 +12644,7 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec ir_build_var_decl_from(&ira->new_irb, &decl_var_instruction->base, var, var_type, nullptr, casted_init_value); - FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); if (fn_entry) fn_entry->variable_list.append(var); @@ -12685,7 +12685,7 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor zig_unreachable(); case TypeTableEntryIdFn: { assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction); - FnTableEntry *fn_entry = target->value.data.x_ptr.data.fn.fn_entry; + ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry; CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; switch (cc) { case CallingConventionUnspecified: { @@ -12822,7 +12822,7 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor } static bool exec_has_err_ret_trace(CodeGen *g, IrExecutable *exec) { - FnTableEntry *fn_entry = exec_fn_entry(exec); + ZigFn *fn_entry = exec_fn_entry(exec); return fn_entry != nullptr && fn_entry->calls_or_awaits_errorable_fn && g->have_err_ret_tracing; } @@ -12878,7 +12878,7 @@ static ZigType *ir_analyze_instruction_error_union(IrAnalyze *ira, } IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_instr, ImplicitAllocatorId id) { - FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); if (parent_fn_entry == nullptr) { ir_add_error(ira, source_instr, buf_sprintf("no implicit allocator available")); return ira->codegen->invalid_instruction; @@ -12913,7 +12913,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i zig_unreachable(); } -static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, FnTableEntry *fn_entry, ZigType *fn_type, +static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *call_instruction, ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref, IrInstruction **casted_args, size_t arg_count, IrInstruction *async_allocator_inst) { Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME); @@ -12988,7 +12988,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_node, IrInstruction *arg, Scope **child_scope, size_t *next_proto_i, GenericFnTypeId *generic_id, FnTypeId *fn_type_id, IrInstruction **casted_args, - FnTableEntry *impl_fn) + ZigFn *impl_fn) { AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(*next_proto_i); assert(param_decl_node->type == NodeTypeParamDecl); @@ -13067,7 +13067,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod return true; } -static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t index) { +static VariableTableEntry *get_fn_var_by_index(ZigFn *fn_entry, size_t index) { size_t next_var_i = 0; FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info; assert(gen_param_info != nullptr); @@ -13157,7 +13157,7 @@ no_mem_slot: } static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instruction, - FnTableEntry *fn_entry, ZigType *fn_type, IrInstruction *fn_ref, + ZigFn *fn_entry, ZigType *fn_type, IrInstruction *fn_ref, IrInstruction *first_arg_ptr, bool comptime_fn_call, FnInline fn_inline) { Error err; @@ -13382,7 +13382,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr // Fork a scope of the function with known values for the parameters. Scope *parent_scope = fn_entry->fndef_scope->base.parent; - FnTableEntry *impl_fn = create_fn(fn_proto_node); + ZigFn *impl_fn = create_fn(fn_proto_node); impl_fn->param_source_nodes = allocate(new_fn_arg_count); buf_init_from_buf(&impl_fn->symbol_name, &fn_entry->symbol_name); impl_fn->fndef_scope = create_fndef_scope(impl_fn->body_node, parent_scope, impl_fn); @@ -13430,7 +13430,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr bool found_first_var_arg = false; size_t first_var_arg; - FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); assert(parent_fn_entry); for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) { IrInstruction *arg = call_instruction->args[call_i]->other; @@ -13605,7 +13605,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr return ir_finish_anal(ira, return_type); } - FnTableEntry *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *parent_fn_entry = exec_fn_entry(ira->new_irb.exec); assert(fn_type_id->return_type != nullptr); assert(parent_fn_entry != nullptr); if (fn_type_can_fail(fn_type_id)) { @@ -13734,14 +13734,14 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c ir_link_new_instruction(cast_instruction, &call_instruction->base); return ir_finish_anal(ira, cast_instruction->value.type); } else if (fn_ref->value.type->id == TypeTableEntryIdFn) { - FnTableEntry *fn_table_entry = ir_resolve_fn(ira, fn_ref); + ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); if (fn_table_entry == nullptr) return ira->codegen->builtin_types.entry_invalid; return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, fn_ref, nullptr, is_comptime, call_instruction->fn_inline); } else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) { assert(fn_ref->value.special == ConstValSpecialStatic); - FnTableEntry *fn_table_entry = fn_ref->value.data.x_bound_fn.fn; + ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn; IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg; return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, fn_ref, first_arg_ptr, is_comptime, call_instruction->fn_inline); @@ -14289,7 +14289,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle return ira->codegen->builtin_types.entry_invalid; } size_t abs_index = start + index; - FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); assert(fn_entry); VariableTableEntry *var = get_fn_var_by_index(fn_entry, abs_index); bool is_const = true; @@ -14509,7 +14509,7 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, if (tld->resolution == TldResolutionInvalid) return ira->codegen->invalid_instruction; TldFn *tld_fn = (TldFn *)tld; - FnTableEntry *fn_entry = tld_fn->fn_entry; + ZigFn *fn_entry = tld_fn->fn_entry; if (type_is_invalid(fn_entry->type_entry)) return ira->codegen->invalid_instruction; @@ -14703,7 +14703,7 @@ static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instru case TldIdFn: { TldFn *tld_fn = (TldFn *)tld; - FnTableEntry *fn_entry = tld_fn->fn_entry; + ZigFn *fn_entry = tld_fn->fn_entry; assert(fn_entry->type_entry); if (type_is_invalid(fn_entry->type_entry)) @@ -15306,7 +15306,7 @@ static ZigType *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstructionSet if (!ir_resolve_bool(ira, is_cold_value, &want_cold)) return ira->codegen->builtin_types.entry_invalid; - FnTableEntry *fn_entry = scope_fn_entry(instruction->base.scope); + ZigFn *fn_entry = scope_fn_entry(instruction->base.scope); if (fn_entry == nullptr) { ir_add_error(ira, &instruction->base, buf_sprintf("@setCold outside function")); return ira->codegen->builtin_types.entry_invalid; @@ -15345,7 +15345,7 @@ static ZigType *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira, break; } else if (scope->id == ScopeIdFnDef) { ScopeFnDef *def_scope = (ScopeFnDef *)scope; - FnTableEntry *target_fn = def_scope->fn_entry; + ZigFn *target_fn = def_scope->fn_entry; assert(target_fn->def_scope != nullptr); safety_off_ptr = &target_fn->def_scope->safety_off; safety_set_node_ptr = &target_fn->def_scope->safety_set_node; @@ -15406,7 +15406,7 @@ static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, fast_math_set_node_ptr = &block_scope->fast_math_set_node; } else if (target_type->id == TypeTableEntryIdFn) { assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction); - FnTableEntry *target_fn = target_val->data.x_ptr.data.fn.fn_entry; + ZigFn *target_fn = target_val->data.x_ptr.data.fn.fn_entry; assert(target_fn->def_scope); fast_math_on_ptr = &target_fn->def_scope->fast_math_on; fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node; @@ -17023,7 +17023,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco // Skip comptime blocks and test functions. if (curr_entry->value->id != TldIdCompTime) { if (curr_entry->value->id == TldIdFn) { - FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; + ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; if (fn_entry->is_test) continue; } @@ -17049,7 +17049,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco if (curr_entry->value->id == TldIdCompTime) { continue; } else if (curr_entry->value->id == TldIdFn) { - FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; + ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; if (fn_entry->is_test) continue; } @@ -17105,7 +17105,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco // 2: Data.Fn: Data.FnDef bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 2); - FnTableEntry *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; + ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry; assert(!fn_entry->is_test); AstNodeFnProto *fn_node = (AstNodeFnProto *)(fn_entry->proto_node); @@ -19276,7 +19276,7 @@ static ZigType *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrInstructi static ZigType *ir_analyze_instruction_handle(IrAnalyze *ira, IrInstructionHandle *instruction) { ir_build_handle_from(&ira->new_irb, &instruction->base); - FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); assert(fn_entry != nullptr); return get_promise_type(ira->codegen, fn_entry->type_entry->data.fn.fn_type_id.return_type); } @@ -20339,7 +20339,7 @@ static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira, case TldIdFn: { TldFn *tld_fn = (TldFn *)tld; - FnTableEntry *fn_entry = tld_fn->fn_entry; + ZigFn *fn_entry = tld_fn->fn_entry; assert(fn_entry->type_entry); if (tld_fn->extern_lib_name != nullptr) { @@ -20470,7 +20470,7 @@ static ZigType *ir_analyze_instruction_set_align_stack(IrAnalyze *ira, IrInstruc return ira->codegen->builtin_types.entry_invalid; } - FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); if (fn_entry == nullptr) { ir_add_error(ira, &instruction->base, buf_sprintf("@setAlignStack outside function")); return ira->codegen->builtin_types.entry_invalid; @@ -20631,7 +20631,7 @@ static ZigType *ir_analyze_instruction_coro_begin(IrAnalyze *ira, IrInstructionC if (type_is_invalid(coro_mem_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; - FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); assert(fn_entry != nullptr); IrInstruction *result = ir_build_coro_begin(&ira->new_irb, instruction->base.scope, instruction->base.source_node, coro_id, coro_mem_ptr); @@ -20923,7 +20923,7 @@ static ZigType *ir_analyze_instruction_await_bookkeeping(IrAnalyze *ira, IrInstr if (type_is_invalid(promise_result_type)) return ira->codegen->builtin_types.entry_invalid; - FnTableEntry *fn_entry = exec_fn_entry(ira->new_irb.exec); + ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); assert(fn_entry != nullptr); if (type_can_fail(promise_result_type)) { @@ -21440,7 +21440,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ old_exec->analysis = ira; ira->codegen = codegen; - FnTableEntry *fn_entry = exec_fn_entry(old_exec); + ZigFn *fn_entry = exec_fn_entry(old_exec); bool is_async = fn_entry != nullptr && fn_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; ira->explicit_return_type = is_async ? get_promise_type(codegen, expected_type) : expected_type; diff --git a/src/ir.hpp b/src/ir.hpp index a519ed2958..b298750dec 100644 --- a/src/ir.hpp +++ b/src/ir.hpp @@ -11,11 +11,11 @@ #include "all_types.hpp" bool ir_gen(CodeGen *g, AstNode *node, Scope *scope, IrExecutable *ir_executable); -bool ir_gen_fn(CodeGen *g, FnTableEntry *fn_entry); +bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry); IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node, ZigType *expected_type, size_t *backward_branch_count, size_t backward_branch_quota, - FnTableEntry *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, + ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name, IrExecutable *parent_exec); ZigType *ir_analyze(CodeGen *g, IrExecutable *old_executable, IrExecutable *new_executable, -- cgit v1.2.3 From 1f5c7ff4d7360f83f83f422adf167df5d756e3b4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Sep 2018 18:35:57 -0400 Subject: stage1: rename VariableTableEntry to ZigVar --- src/all_types.hpp | 20 ++++++------ src/analyze.cpp | 14 ++++----- src/analyze.hpp | 8 ++--- src/codegen.cpp | 16 +++++----- src/ir.cpp | 94 +++++++++++++++++++++++++++---------------------------- 5 files changed, 76 insertions(+), 76 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index 7b728cae99..fd339ff767 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -25,7 +25,7 @@ struct Scope; struct ScopeBlock; struct ScopeFnDef; struct ZigType; -struct VariableTableEntry; +struct ZigVar; struct ErrorTableEntry; struct BuiltinFnEntry; struct TypeStructField; @@ -69,7 +69,7 @@ struct IrExecutable { IrBasicBlock *coro_normal_final; IrBasicBlock *coro_suspend_block; IrBasicBlock *coro_final_cleanup_block; - VariableTableEntry *coro_allocator_var; + ZigVar *coro_allocator_var; }; enum OutType { @@ -337,7 +337,7 @@ struct Tld { struct TldVar { Tld base; - VariableTableEntry *var; + ZigVar *var; Buf *extern_lib_name; Buf *section_name; }; @@ -1310,7 +1310,7 @@ struct ZigFn { AstNode *fn_static_eval_set_node; ZigList alloca_list; - ZigList variable_list; + ZigList variable_list; Buf *section_name; AstNode *set_alignstack_node; @@ -1786,7 +1786,7 @@ enum VarLinkage { VarLinkageExternal, }; -struct VariableTableEntry { +struct ZigVar { Buf name; ConstExprValue *value; LLVMValueRef value_ref; @@ -1811,7 +1811,7 @@ struct VariableTableEntry { // In an inline loop, multiple variables may be created, // In this case, a reference to a variable should follow // this pointer to the redefined variable. - VariableTableEntry *next_var; + ZigVar *next_var; }; struct ErrorTableEntry { @@ -1904,7 +1904,7 @@ struct ScopeVarDecl { Scope base; // The variable that creates this scope - VariableTableEntry *var; + ZigVar *var; }; // This scope is created for a @cImport @@ -2292,7 +2292,7 @@ struct IrInstructionBinOp { struct IrInstructionDeclVar { IrInstruction base; - VariableTableEntry *var; + ZigVar *var; IrInstruction *var_type; IrInstruction *align_value; IrInstruction *init_value; @@ -2349,7 +2349,7 @@ struct IrInstructionElemPtr { struct IrInstructionVarPtr { IrInstruction base; - VariableTableEntry *var; + ZigVar *var; }; struct IrInstructionCall { @@ -2519,7 +2519,7 @@ struct IrInstructionAsm { // Most information on inline assembly comes from the source node. IrInstruction **input_list; IrInstruction **output_types; - VariableTableEntry **output_vars; + ZigVar **output_vars; size_t return_count; bool has_side_effects; }; diff --git a/src/analyze.cpp b/src/analyze.cpp index fbd96a872a..31176df47f 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -129,7 +129,7 @@ ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent) { return scope; } -Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var) { +Scope *create_var_scope(AstNode *node, Scope *parent, ZigVar *var) { ScopeVarDecl *scope = allocate(1); init_scope(&scope->base, ScopeIdVarDecl, node, parent); scope->var = var; @@ -3501,12 +3501,12 @@ ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry // Set name to nullptr to make the variable anonymous (not visible to programmer). // TODO merge with definition of add_local_var in ir.cpp -VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name, +ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name, bool is_const, ConstExprValue *value, Tld *src_tld) { assert(value); - VariableTableEntry *variable_entry = allocate(1); + ZigVar *variable_entry = allocate(1); variable_entry->value = value; variable_entry->parent_scope = parent_scope; variable_entry->shadowable = false; @@ -3519,7 +3519,7 @@ VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent if (!type_is_invalid(value->type)) { variable_entry->align_bytes = get_abi_alignment(g, value->type); - VariableTableEntry *existing_var = find_variable(g, parent_scope, name); + ZigVar *existing_var = find_variable(g, parent_scope, name); if (existing_var && !existing_var->shadowable) { ErrorMsg *msg = add_node_error(g, source_node, buf_sprintf("redeclaration of variable '%s'", buf_ptr(name))); @@ -3726,7 +3726,7 @@ Tld *find_decl(CodeGen *g, Scope *scope, Buf *name) { return nullptr; } -VariableTableEntry *find_variable(CodeGen *g, Scope *scope, Buf *name) { +ZigVar *find_variable(CodeGen *g, Scope *scope, Buf *name) { while (scope) { if (scope->id == ScopeIdVarDecl) { ScopeVarDecl *var_scope = (ScopeVarDecl *)scope; @@ -4015,7 +4015,7 @@ static void define_local_param_variables(CodeGen *g, ZigFn *fn_table_entry) { add_node_error(g, param_decl_node, buf_sprintf("noalias on non-pointer parameter")); } - VariableTableEntry *var = add_variable(g, param_decl_node, fn_table_entry->child_scope, + ZigVar *var = add_variable(g, param_decl_node, fn_table_entry->child_scope, param_name, true, create_const_runtime(param_type), nullptr); var->src_arg_index = i; fn_table_entry->child_scope = var->child_scope; @@ -5429,7 +5429,7 @@ Error type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry) { return ErrorNone; } -bool ir_get_var_is_comptime(VariableTableEntry *var) { +bool ir_get_var_is_comptime(ZigVar *var) { if (!var->is_comptime) return false; if (var->is_comptime->other) diff --git a/src/analyze.hpp b/src/analyze.hpp index 38491c9e09..f31b9b219d 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -48,7 +48,7 @@ bool type_has_bits(ZigType *type_entry); ImportTableEntry *add_source_file(CodeGen *g, PackageTableEntry *package, Buf *abs_full_path, Buf *source_code); -VariableTableEntry *find_variable(CodeGen *g, Scope *orig_context, Buf *name); +ZigVar *find_variable(CodeGen *g, Scope *orig_context, Buf *name); Tld *find_decl(CodeGen *g, Scope *scope, Buf *name); void resolve_top_level_decl(CodeGen *g, Tld *tld, bool pointer_only, AstNode *source_node); bool type_is_codegen_pointer(ZigType *type); @@ -80,7 +80,7 @@ void resolve_use_decl(CodeGen *g, AstNode *node); ZigFn *scope_fn_entry(Scope *scope); ImportTableEntry *get_scope_import(Scope *scope); void init_tld(Tld *tld, TldId id, Buf *name, VisibMod visib_mod, AstNode *source_node, Scope *parent_scope); -VariableTableEntry *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name, +ZigVar *add_variable(CodeGen *g, AstNode *source_node, Scope *parent_scope, Buf *name, bool is_const, ConstExprValue *init_value, Tld *src_tld); ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node); ZigFn *create_fn(AstNode *proto_node); @@ -92,7 +92,7 @@ bool type_requires_comptime(ZigType *type_entry); Error ATTRIBUTE_MUST_USE ensure_complete_type(CodeGen *g, ZigType *type_entry); Error ATTRIBUTE_MUST_USE type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry); void complete_enum(CodeGen *g, ZigType *enum_type); -bool ir_get_var_is_comptime(VariableTableEntry *var); +bool ir_get_var_is_comptime(ZigVar *var); bool const_values_equal(ConstExprValue *a, ConstExprValue *b); void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max); void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max); @@ -103,7 +103,7 @@ void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node) ScopeBlock *create_block_scope(AstNode *node, Scope *parent); ScopeDefer *create_defer_scope(AstNode *node, Scope *parent); ScopeDeferExpr *create_defer_expr_scope(AstNode *node, Scope *parent); -Scope *create_var_scope(AstNode *node, Scope *parent, VariableTableEntry *var); +Scope *create_var_scope(AstNode *node, Scope *parent, ZigVar *var); ScopeCImport *create_cimport_scope(AstNode *node, Scope *parent); ScopeLoop *create_loop_scope(AstNode *node, Scope *parent); ScopeSuspend *create_suspend_scope(AstNode *node, Scope *parent); diff --git a/src/codegen.cpp b/src/codegen.cpp index cfaf05bf96..34cbd5cfad 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1857,7 +1857,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_ty return nullptr; } -static void gen_var_debug_decl(CodeGen *g, VariableTableEntry *var) { +static void gen_var_debug_decl(CodeGen *g, ZigVar *var) { AstNode *source_node = var->decl_node; ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1, (unsigned)source_node->column + 1, get_di_scope(g, var->parent_scope)); @@ -2862,7 +2862,7 @@ static LLVMValueRef get_memset_fn_val(CodeGen *g) { static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable, IrInstructionDeclVar *decl_var_instruction) { - VariableTableEntry *var = decl_var_instruction->var; + ZigVar *var = decl_var_instruction->var; if (!type_has_bits(var->value->type)) return nullptr; @@ -2955,7 +2955,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir } static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrInstructionVarPtr *instruction) { - VariableTableEntry *var = instruction->var; + ZigVar *var = instruction->var; if (type_has_bits(var->value->type)) { assert(var->value_ref); return var->value_ref; @@ -3370,7 +3370,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru } if (!is_return) { - VariableTableEntry *variable = instruction->output_vars[i]; + ZigVar *variable = instruction->output_vars[i]; assert(variable); param_types[param_index] = LLVMTypeOf(variable->value_ref); param_values[param_index] = variable->value_ref; @@ -5699,7 +5699,7 @@ static void build_all_basic_blocks(CodeGen *g, ZigFn *fn) { LLVMPositionBuilderAtEnd(g->builder, entry_bb->llvm_block); } -static void gen_global_var(CodeGen *g, VariableTableEntry *var, LLVMValueRef init_val, +static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val, ZigType *type_entry) { if (g->strip_debug_symbols) { @@ -5788,7 +5788,7 @@ static void do_code_gen(CodeGen *g) { // Generate module level variables for (size_t i = 0; i < g->global_vars.length; i += 1) { TldVar *tld_var = g->global_vars.at(i); - VariableTableEntry *var = tld_var->var; + ZigVar *var = tld_var->var; if (var->value->type->id == TypeTableEntryIdComptimeFloat) { // Generate debug info for it but that's it. @@ -5949,7 +5949,7 @@ static void do_code_gen(CodeGen *g) { // create debug variable declarations for variables and allocate all local variables for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) { - VariableTableEntry *var = fn_table_entry->variable_list.at(var_i); + ZigVar *var = fn_table_entry->variable_list.at(var_i); if (!type_has_bits(var->value->type)) { continue; @@ -6027,7 +6027,7 @@ static void do_code_gen(CodeGen *g) { if (info->gen_index == SIZE_MAX) continue; - VariableTableEntry *variable = fn_table_entry->variable_list.at(next_var_i); + ZigVar *variable = fn_table_entry->variable_list.at(next_var_i); assert(variable->src_arg_index != SIZE_MAX); next_var_i += 1; diff --git a/src/ir.cpp b/src/ir.cpp index 1d9352f9d6..6be1638d5b 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -145,7 +145,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc static ErrorMsg *exec_add_error_node(CodeGen *codegen, IrExecutable *exec, AstNode *source_node, Buf *msg); static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_name, IrInstruction *source_instr, IrInstruction *container_ptr, ZigType *container_type); -static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, VariableTableEntry *var); +static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, ZigVar *var); static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op); static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *value, LVal lval); static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align); @@ -277,7 +277,7 @@ static void ir_ref_instruction(IrInstruction *instruction, IrBasicBlock *cur_bb) ir_ref_bb(instruction->owner_bb); } -static void ir_ref_var(VariableTableEntry *var) { +static void ir_ref_var(ZigVar *var) { var->ref_count += 1; } @@ -1114,7 +1114,7 @@ static IrInstruction *ir_build_bin_op_from(IrBuilder *irb, IrInstruction *old_in return new_instruction; } -static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, VariableTableEntry *var) { +static IrInstruction *ir_build_var_ptr(IrBuilder *irb, Scope *scope, AstNode *source_node, ZigVar *var) { IrInstructionVarPtr *instruction = ir_build_instruction(irb, scope, source_node); instruction->var = var; @@ -1459,7 +1459,7 @@ static IrInstruction *ir_build_store_ptr_from(IrBuilder *irb, IrInstruction *old } static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *source_node, - VariableTableEntry *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value) + ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value) { IrInstructionDeclVar *decl_var_instruction = ir_build_instruction(irb, scope, source_node); decl_var_instruction->base.value.special = ConstValSpecialStatic; @@ -1477,7 +1477,7 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s } static IrInstruction *ir_build_var_decl_from(IrBuilder *irb, IrInstruction *old_instruction, - VariableTableEntry *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value) + ZigVar *var, IrInstruction *var_type, IrInstruction *align_value, IrInstruction *init_value) { IrInstruction *new_instruction = ir_build_var_decl(irb, old_instruction->scope, old_instruction->source_node, var, var_type, align_value, init_value); @@ -1622,7 +1622,7 @@ static IrInstruction *ir_build_slice_type(IrBuilder *irb, Scope *scope, AstNode } static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source_node, IrInstruction **input_list, - IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects) + IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects) { IrInstructionAsm *instruction = ir_build_instruction(irb, scope, source_node); instruction->input_list = input_list; @@ -1646,7 +1646,7 @@ static IrInstruction *ir_build_asm(IrBuilder *irb, Scope *scope, AstNode *source } static IrInstruction *ir_build_asm_from(IrBuilder *irb, IrInstruction *old_instruction, IrInstruction **input_list, - IrInstruction **output_types, VariableTableEntry **output_vars, size_t return_count, bool has_side_effects) + IrInstruction **output_types, ZigVar **output_vars, size_t return_count, bool has_side_effects) { IrInstruction *new_instruction = ir_build_asm(irb, old_instruction->scope, old_instruction->source_node, input_list, output_types, output_vars, return_count, has_side_effects); @@ -3320,11 +3320,11 @@ static IrInstruction *ir_gen_return(IrBuilder *irb, Scope *scope, AstNode *node, zig_unreachable(); } -static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, +static ZigVar *create_local_var(CodeGen *codegen, AstNode *node, Scope *parent_scope, Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime, bool skip_name_check) { - VariableTableEntry *variable_entry = allocate(1); + ZigVar *variable_entry = allocate(1); variable_entry->parent_scope = parent_scope; variable_entry->shadowable = is_shadowable; variable_entry->mem_slot_index = SIZE_MAX; @@ -3336,7 +3336,7 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco buf_init_from_buf(&variable_entry->name, name); if (!skip_name_check) { - VariableTableEntry *existing_var = find_variable(codegen, parent_scope, name); + ZigVar *existing_var = find_variable(codegen, parent_scope, name); if (existing_var && !existing_var->shadowable) { ErrorMsg *msg = add_node_error(codegen, node, buf_sprintf("redeclaration of variable '%s'", buf_ptr(name))); @@ -3377,11 +3377,11 @@ static VariableTableEntry *create_local_var(CodeGen *codegen, AstNode *node, Sco // Set name to nullptr to make the variable anonymous (not visible to programmer). // After you call this function var->child_scope has the variable in scope -static VariableTableEntry *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name, +static ZigVar *ir_create_var(IrBuilder *irb, AstNode *node, Scope *scope, Buf *name, bool src_is_const, bool gen_is_const, bool is_shadowable, IrInstruction *is_comptime) { bool is_underscored = name ? buf_eql_str(name, "_") : false; - VariableTableEntry *var = create_local_var(irb->codegen, node, scope, + ZigVar *var = create_local_var(irb->codegen, node, scope, (is_underscored ? nullptr : name), src_is_const, gen_is_const, (is_underscored ? true : is_shadowable), is_comptime, false); if (is_comptime != nullptr || gen_is_const) { @@ -3799,7 +3799,7 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node, } } - VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name); + ZigVar *var = find_variable(irb->codegen, scope, variable_name); if (var) { IrInstruction *var_ptr = ir_build_var_ptr(irb, scope, node, var); if (lval == LValPtr) @@ -5258,7 +5258,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod IrInstruction *is_comptime = ir_build_const_bool(irb, scope, node, ir_should_inline(irb->exec, scope) || variable_declaration->is_comptime); - VariableTableEntry *var = ir_create_var(irb, node, scope, variable_declaration->symbol, + ZigVar *var = ir_create_var(irb, node, scope, variable_declaration->symbol, is_const, is_const, is_shadowable, is_comptime); // we detect IrInstructionIdDeclVar in gen_block to make sure the next node // is inside var->child_scope @@ -5320,7 +5320,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n Scope *payload_scope; AstNode *symbol_node = node; // TODO make more accurate - VariableTableEntry *payload_var; + ZigVar *payload_var; if (var_symbol) { // TODO make it an error to write to payload variable payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol, @@ -5384,7 +5384,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n // TODO make it an error to write to error variable AstNode *err_symbol_node = else_node; // TODO make more accurate - VariableTableEntry *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol, + ZigVar *err_var = ir_create_var(irb, err_symbol_node, scope, err_symbol, true, false, false, is_comptime); Scope *err_scope = err_var->child_scope; IrInstruction *err_var_value = ir_build_unwrap_err_code(irb, err_scope, err_symbol_node, err_val_ptr); @@ -5413,7 +5413,7 @@ static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *n // TODO make it an error to write to payload variable AstNode *symbol_node = node; // TODO make more accurate - VariableTableEntry *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol, + ZigVar *payload_var = ir_create_var(irb, symbol_node, subexpr_scope, var_symbol, true, false, false, is_comptime); Scope *child_scope = payload_var->child_scope; IrInstruction *maybe_val_ptr = ir_gen_node_extra(irb, node->data.while_expr.condition, subexpr_scope, LValPtr); @@ -5585,7 +5585,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo // TODO make it an error to write to element variable or i variable. Buf *elem_var_name = elem_node->data.symbol_expr.symbol; - VariableTableEntry *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); + ZigVar *elem_var = ir_create_var(irb, elem_node, parent_scope, elem_var_name, true, false, false, is_comptime); Scope *child_scope = elem_var->child_scope; IrInstruction *undefined_value = ir_build_const_undefined(irb, child_scope, elem_node); @@ -5593,7 +5593,7 @@ static IrInstruction *ir_gen_for_expr(IrBuilder *irb, Scope *parent_scope, AstNo IrInstruction *elem_var_ptr = ir_build_var_ptr(irb, child_scope, node, elem_var); AstNode *index_var_source_node; - VariableTableEntry *index_var; + ZigVar *index_var; if (index_node) { index_var_source_node = index_node; Buf *index_var_name = index_node->data.symbol_expr.symbol; @@ -5798,7 +5798,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod IrInstruction **input_list = allocate(node->data.asm_expr.input_list.length); IrInstruction **output_types = allocate(node->data.asm_expr.output_list.length); - VariableTableEntry **output_vars = allocate(node->data.asm_expr.output_list.length); + ZigVar **output_vars = allocate(node->data.asm_expr.output_list.length); size_t return_count = 0; bool is_volatile = node->data.asm_expr.is_volatile; if (!is_volatile && node->data.asm_expr.output_list.length == 0) { @@ -5822,7 +5822,7 @@ static IrInstruction *ir_gen_asm_expr(IrBuilder *irb, Scope *scope, AstNode *nod output_types[i] = return_type; } else { Buf *variable_name = asm_output->variable_name; - VariableTableEntry *var = find_variable(irb->codegen, scope, variable_name); + ZigVar *var = find_variable(irb->codegen, scope, variable_name); if (var) { output_vars[i] = var; } else { @@ -5880,7 +5880,7 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no IrInstruction *var_type = nullptr; bool is_shadowable = false; bool is_const = true; - VariableTableEntry *var = ir_create_var(irb, node, subexpr_scope, + ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_symbol, is_const, is_const, is_shadowable, is_comptime); IrInstruction *var_ptr_value = ir_build_unwrap_maybe(irb, subexpr_scope, node, maybe_val_ptr, false); @@ -5955,7 +5955,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * IrInstruction *var_type = nullptr; bool is_shadowable = false; IrInstruction *var_is_comptime = force_comptime ? ir_build_const_bool(irb, subexpr_scope, node, true) : ir_build_test_comptime(irb, subexpr_scope, node, err_val); - VariableTableEntry *var = ir_create_var(irb, node, subexpr_scope, + ZigVar *var = ir_create_var(irb, node, subexpr_scope, var_symbol, var_is_const, var_is_const, is_shadowable, var_is_comptime); IrInstruction *var_ptr_value = ir_build_unwrap_err_payload(irb, subexpr_scope, node, err_val_ptr, false); @@ -5981,7 +5981,7 @@ static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode * IrInstruction *var_type = nullptr; bool is_shadowable = false; bool is_const = true; - VariableTableEntry *var = ir_create_var(irb, node, subexpr_scope, + ZigVar *var = ir_create_var(irb, node, subexpr_scope, err_symbol, is_const, is_const, is_shadowable, is_comptime); IrInstruction *var_value = ir_build_unwrap_err_code(irb, subexpr_scope, node, err_val_ptr); @@ -6029,7 +6029,7 @@ static bool ir_gen_switch_prong_expr(IrBuilder *irb, Scope *scope, AstNode *swit bool is_shadowable = false; bool is_const = true; - VariableTableEntry *var = ir_create_var(irb, var_symbol_node, scope, + ZigVar *var = ir_create_var(irb, var_symbol_node, scope, var_name, is_const, is_const, is_shadowable, var_is_comptime); child_scope = var->child_scope; IrInstruction *var_value; @@ -6494,7 +6494,7 @@ static IrInstruction *ir_gen_err_ok_or(IrBuilder *irb, Scope *parent_scope, AstN Buf *var_name = var_node->data.symbol_expr.symbol; bool is_const = true; bool is_shadowable = false; - VariableTableEntry *var = ir_create_var(irb, node, parent_scope, var_name, + ZigVar *var = ir_create_var(irb, node, parent_scope, var_name, is_const, is_const, is_shadowable, is_comptime); err_scope = var->child_scope; IrInstruction *err_val = ir_build_unwrap_err_code(irb, err_scope, node, err_union_ptr); @@ -6976,7 +6976,7 @@ static IrInstruction *ir_gen_await_expr(IrBuilder *irb, Scope *scope, AstNode *n IrInstruction *is_canceled_mask = ir_build_const_usize(irb, scope, node, 0x1); // 0b001 IrInstruction *is_suspended_mask = ir_build_const_usize(irb, scope, node, 0x2); // 0b010 - VariableTableEntry *result_var = ir_create_var(irb, node, scope, nullptr, + ZigVar *result_var = ir_create_var(irb, node, scope, nullptr, false, false, true, const_bool_false); IrInstruction *target_promise_type = ir_build_typeof(irb, scope, node, target_inst); IrInstruction *promise_result_type = ir_build_promise_result_type(irb, scope, node, target_promise_type); @@ -7388,12 +7388,12 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec IrInstruction *err_ret_trace_ptr; ZigType *return_type; Buf *result_ptr_field_name; - VariableTableEntry *coro_size_var; + ZigVar *coro_size_var; if (is_async) { // create the coro promise Scope *coro_scope = create_coro_prelude_scope(node, scope); const_bool_false = ir_build_const_bool(irb, coro_scope, node, false); - VariableTableEntry *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); + ZigVar *promise_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); return_type = fn_entry->type_entry->data.fn.fn_type_id.return_type; IrInstruction *undef = ir_build_const_undefined(irb, coro_scope, node); @@ -7403,7 +7403,7 @@ bool ir_gen(CodeGen *codegen, AstNode *node, Scope *scope, IrExecutable *ir_exec ir_build_var_decl(irb, coro_scope, node, promise_var, coro_frame_type_value, nullptr, undef); coro_promise_ptr = ir_build_var_ptr(irb, coro_scope, node, promise_var); - VariableTableEntry *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); + ZigVar *await_handle_var = ir_create_var(irb, node, coro_scope, nullptr, false, false, true, const_bool_false); IrInstruction *null_value = ir_build_const_null(irb, coro_scope, node); IrInstruction *await_handle_type_val = ir_build_const_type(irb, coro_scope, node, get_optional_type(irb->codegen, irb->codegen->builtin_types.entry_promise)); @@ -12518,7 +12518,7 @@ static ZigType *ir_analyze_instruction_bin_op(IrAnalyze *ira, IrInstructionBinOp static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDeclVar *decl_var_instruction) { Error err; - VariableTableEntry *var = decl_var_instruction->var; + ZigVar *var = decl_var_instruction->var; IrInstruction *init_value = decl_var_instruction->init_value->other; if (type_is_invalid(init_value->value.type)) { @@ -12591,7 +12591,7 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec // This means that this is actually a different variable due to, e.g. an inline while loop. // We make a new variable so that it can hold a different type, and so the debug info can // be distinct. - VariableTableEntry *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, + ZigVar *new_var = create_local_var(ira->codegen, var->decl_node, var->child_scope, &var->name, var->src_is_const, var->gen_is_const, var->shadowable, var->is_comptime, true); new_var->owner_exec = var->owner_exec; new_var->align_bytes = var->align_bytes; @@ -12902,7 +12902,7 @@ IrInstruction *ir_get_implicit_allocator(IrAnalyze *ira, IrInstruction *source_i } case ImplicitAllocatorIdLocalVar: { - VariableTableEntry *coro_allocator_var = ira->old_irb.exec->coro_allocator_var; + ZigVar *coro_allocator_var = ira->old_irb.exec->coro_allocator_var; assert(coro_allocator_var != nullptr); IrInstruction *var_ptr_inst = ir_get_var_ptr(ira, source_instr, coro_allocator_var); IrInstruction *result = ir_get_deref(ira, source_instr, var_ptr_inst); @@ -12977,7 +12977,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node return false; Buf *param_name = param_decl_node->data.param_decl.name; - VariableTableEntry *var = add_variable(ira->codegen, param_decl_node, + ZigVar *var = add_variable(ira->codegen, param_decl_node, *exec_scope, param_name, true, arg_val, nullptr); *exec_scope = var->child_scope; *next_proto_i += 1; @@ -13035,7 +13035,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod Buf *param_name = param_decl_node->data.param_decl.name; if (!param_name) return false; if (!is_var_args) { - VariableTableEntry *var = add_variable(ira->codegen, param_decl_node, + ZigVar *var = add_variable(ira->codegen, param_decl_node, *child_scope, param_name, true, arg_val, nullptr); *child_scope = var->child_scope; var->shadowable = !comptime_arg; @@ -13067,7 +13067,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod return true; } -static VariableTableEntry *get_fn_var_by_index(ZigFn *fn_entry, size_t index) { +static ZigVar *get_fn_var_by_index(ZigFn *fn_entry, size_t index) { size_t next_var_i = 0; FnGenParamInfo *gen_param_info = fn_entry->type_entry->data.fn.gen_param_info; assert(gen_param_info != nullptr); @@ -13086,7 +13086,7 @@ static VariableTableEntry *get_fn_var_by_index(ZigFn *fn_entry, size_t index) { } static IrInstruction *ir_get_var_ptr(IrAnalyze *ira, IrInstruction *instruction, - VariableTableEntry *var) + ZigVar *var) { Error err; while (var->next_var != nullptr) { @@ -13449,7 +13449,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr found_first_var_arg = true; } - VariableTableEntry *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i); + ZigVar *arg_var = get_fn_var_by_index(parent_fn_entry, arg_tuple_i); if (arg_var == nullptr) { ir_add_error(ira, arg, buf_sprintf("compiler bug: var args can't handle void. https://github.com/ziglang/zig/issues/557")); @@ -13496,7 +13496,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr ConstExprValue *var_args_val = create_const_arg_tuple(ira->codegen, first_var_arg, inst_fn_type_id.param_count); - VariableTableEntry *var = add_variable(ira->codegen, param_decl_node, + ZigVar *var = add_variable(ira->codegen, param_decl_node, impl_fn->child_scope, param_name, true, var_args_val, nullptr); impl_fn->child_scope = var->child_scope; } @@ -14158,7 +14158,7 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi } static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, - VariableTableEntry *var) + ZigVar *var) { IrInstruction *result = ir_get_var_ptr(ira, instruction, var); ir_link_new_instruction(result, instruction); @@ -14166,7 +14166,7 @@ static ZigType *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruction, } static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarPtr *var_ptr_instruction) { - VariableTableEntry *var = var_ptr_instruction->var; + ZigVar *var = var_ptr_instruction->var; return ir_analyze_var_ptr(ira, &var_ptr_instruction->base, var); } @@ -14291,7 +14291,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle size_t abs_index = start + index; ZigFn *fn_entry = exec_fn_entry(ira->new_irb.exec); assert(fn_entry); - VariableTableEntry *var = get_fn_var_by_index(fn_entry, abs_index); + ZigVar *var = get_fn_var_by_index(fn_entry, abs_index); bool is_const = true; bool is_volatile = false; if (var) { @@ -14693,7 +14693,7 @@ static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instru case TldIdVar: { TldVar *tld_var = (TldVar *)tld; - VariableTableEntry *var = tld_var->var; + ZigVar *var = tld_var->var; if (tld_var->extern_lib_name != nullptr) { add_link_lib_symbol(ira, tld_var->extern_lib_name, &var->name, source_instruction->source_node); } @@ -16976,7 +16976,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig TldVar *tld = (TldVar *)entry; assert(tld->base.id == TldIdVar); - VariableTableEntry *var = tld->var; + ZigVar *var = tld->var; if ((err = ensure_complete_type(ira->codegen, var->value->type))) return ira->codegen->builtin_types.entry_invalid; @@ -17074,7 +17074,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco switch (curr_entry->value->id) { case TldIdVar: { - VariableTableEntry *var = ((TldVar *)curr_entry->value)->var; + ZigVar *var = ((TldVar *)curr_entry->value)->var; if ((err = ensure_complete_type(ira->codegen, var->value->type))) return ErrorSemanticAnalyzeFail; @@ -17191,7 +17191,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) { - VariableTableEntry *arg_var = fn_entry->variable_list.at(fn_arg_index); + ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index); ConstExprValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.s_none.elements[fn_arg_index]; ConstExprValue *arg_name = create_const_str_lit(ira->codegen, &arg_var->name); init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, buf_len(&arg_var->name), true); @@ -20317,7 +20317,7 @@ static ZigType *ir_analyze_instruction_decl_ref(IrAnalyze *ira, case TldIdVar: { TldVar *tld_var = (TldVar *)tld; - VariableTableEntry *var = tld_var->var; + ZigVar *var = tld_var->var; IrInstruction *var_ptr = ir_get_var_ptr(ira, &instruction->base, var); if (type_is_invalid(var_ptr->value.type)) -- cgit v1.2.3 From 8400163e0245f68833e29db22ae3bcc1fb8bf9ae Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 5 Sep 2018 18:42:56 -0400 Subject: stage1: rename more TypeTableEntry types to ZigType --- src/all_types.hpp | 104 ++-- src/analyze.cpp | 1390 ++++++++++++++++++++--------------------- src/codegen.cpp | 554 ++++++++--------- src/ir.cpp | 1792 ++++++++++++++++++++++++++--------------------------- 4 files changed, 1920 insertions(+), 1920 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index fd339ff767..1a01754af5 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -1004,7 +1004,7 @@ enum PtrLen { PtrLenSingle, }; -struct TypeTableEntryPointer { +struct ZigTypePointer { ZigType *child_type; PtrLen ptr_len; bool is_const; @@ -1015,16 +1015,16 @@ struct TypeTableEntryPointer { ZigType *slice_parent; }; -struct TypeTableEntryInt { +struct ZigTypeInt { uint32_t bit_count; bool is_signed; }; -struct TypeTableEntryFloat { +struct ZigTypeFloat { size_t bit_count; }; -struct TypeTableEntryArray { +struct ZigTypeArray { ZigType *child_type; uint64_t len; }; @@ -1040,7 +1040,7 @@ struct TypeStructField { size_t unaligned_bit_count; AstNode *decl_node; }; -struct TypeTableEntryStruct { +struct ZigTypeStruct { AstNode *decl_node; ContainerLayout layout; uint32_t src_field_count; @@ -1068,22 +1068,22 @@ struct TypeTableEntryStruct { HashMap fields_by_name; }; -struct TypeTableEntryOptional { +struct ZigTypeOptional { ZigType *child_type; }; -struct TypeTableEntryErrorUnion { +struct ZigTypeErrorUnion { ZigType *err_set_type; ZigType *payload_type; }; -struct TypeTableEntryErrorSet { +struct ZigTypeErrorSet { uint32_t err_count; ErrorTableEntry **errors; ZigFn *infer_fn; }; -struct TypeTableEntryEnum { +struct ZigTypeEnum { AstNode *decl_node; ContainerLayout layout; uint32_t src_field_count; @@ -1110,7 +1110,7 @@ struct TypeTableEntryEnum { uint32_t type_ptr_hash(const ZigType *ptr); bool type_ptr_eql(const ZigType *a, const ZigType *b); -struct TypeTableEntryUnion { +struct ZigTypeUnion { AstNode *decl_node; ContainerLayout layout; uint32_t src_field_count; @@ -1154,7 +1154,7 @@ struct FnGenParamInfo { ZigType *type; }; -struct TypeTableEntryFn { +struct ZigTypeFn { FnTypeId fn_type_id; bool is_generic; ZigType *gen_return_type; @@ -1166,42 +1166,42 @@ struct TypeTableEntryFn { ZigType *bound_fn_parent; }; -struct TypeTableEntryBoundFn { +struct ZigTypeBoundFn { ZigType *fn_type; }; -struct TypeTableEntryPromise { +struct ZigTypePromise { // null if `promise` instead of `promise->T` ZigType *result_type; }; enum ZigTypeId { - TypeTableEntryIdInvalid, - TypeTableEntryIdMetaType, - TypeTableEntryIdVoid, - TypeTableEntryIdBool, - TypeTableEntryIdUnreachable, - TypeTableEntryIdInt, - TypeTableEntryIdFloat, - TypeTableEntryIdPointer, - TypeTableEntryIdArray, - TypeTableEntryIdStruct, - TypeTableEntryIdComptimeFloat, - TypeTableEntryIdComptimeInt, - TypeTableEntryIdUndefined, - TypeTableEntryIdNull, - TypeTableEntryIdOptional, - TypeTableEntryIdErrorUnion, - TypeTableEntryIdErrorSet, - TypeTableEntryIdEnum, - TypeTableEntryIdUnion, - TypeTableEntryIdFn, - TypeTableEntryIdNamespace, - TypeTableEntryIdBlock, - TypeTableEntryIdBoundFn, - TypeTableEntryIdArgTuple, - TypeTableEntryIdOpaque, - TypeTableEntryIdPromise, + ZigTypeIdInvalid, + ZigTypeIdMetaType, + ZigTypeIdVoid, + ZigTypeIdBool, + ZigTypeIdUnreachable, + ZigTypeIdInt, + ZigTypeIdFloat, + ZigTypeIdPointer, + ZigTypeIdArray, + ZigTypeIdStruct, + ZigTypeIdComptimeFloat, + ZigTypeIdComptimeInt, + ZigTypeIdUndefined, + ZigTypeIdNull, + ZigTypeIdOptional, + ZigTypeIdErrorUnion, + ZigTypeIdErrorSet, + ZigTypeIdEnum, + ZigTypeIdUnion, + ZigTypeIdFn, + ZigTypeIdNamespace, + ZigTypeIdBlock, + ZigTypeIdBoundFn, + ZigTypeIdArgTuple, + ZigTypeIdOpaque, + ZigTypeIdPromise, }; struct ZigType { @@ -1216,19 +1216,19 @@ struct ZigType { bool gen_h_loop_flag; union { - TypeTableEntryPointer pointer; - TypeTableEntryInt integral; - TypeTableEntryFloat floating; - TypeTableEntryArray array; - TypeTableEntryStruct structure; - TypeTableEntryOptional maybe; - TypeTableEntryErrorUnion error_union; - TypeTableEntryErrorSet error_set; - TypeTableEntryEnum enumeration; - TypeTableEntryUnion unionation; - TypeTableEntryFn fn; - TypeTableEntryBoundFn bound_fn; - TypeTableEntryPromise promise; + ZigTypePointer pointer; + ZigTypeInt integral; + ZigTypeFloat floating; + ZigTypeArray array; + ZigTypeStruct structure; + ZigTypeOptional maybe; + ZigTypeErrorUnion error_union; + ZigTypeErrorSet error_set; + ZigTypeEnum enumeration; + ZigTypeUnion unionation; + ZigTypeFn fn; + ZigTypeBoundFn bound_fn; + ZigTypePromise promise; } data; // use these fields to make sure we don't duplicate type table entries for the same type diff --git a/src/analyze.cpp b/src/analyze.cpp index 31176df47f..f511e82253 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -77,11 +77,11 @@ ZigType *new_type_table_entry(ZigTypeId id) { } static ScopeDecls **get_container_scope_ptr(ZigType *type_entry) { - if (type_entry->id == TypeTableEntryIdStruct) { + if (type_entry->id == ZigTypeIdStruct) { return &type_entry->data.structure.decls_scope; - } else if (type_entry->id == TypeTableEntryIdEnum) { + } else if (type_entry->id == ZigTypeIdEnum) { return &type_entry->data.enumeration.decls_scope; - } else if (type_entry->id == TypeTableEntryIdUnion) { + } else if (type_entry->id == ZigTypeIdUnion) { return &type_entry->data.unionation.decls_scope; } zig_unreachable(); @@ -220,36 +220,36 @@ static uint8_t bits_needed_for_unsigned(uint64_t x) { AstNode *type_decl_node(ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: return type_entry->data.structure.decl_node; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: return type_entry->data.enumeration.decl_node; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: return type_entry->data.unionation.decl_node; - case TypeTableEntryIdOpaque: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdPromise: + case ZigTypeIdOpaque: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdPromise: return nullptr; } zig_unreachable(); @@ -257,37 +257,37 @@ AstNode *type_decl_node(ZigType *type_entry) { bool type_is_complete(ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: return type_entry->data.structure.complete; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: return type_entry->data.enumeration.complete; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: return type_entry->data.unionation.complete; - case TypeTableEntryIdOpaque: + case ZigTypeIdOpaque: return false; - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdPromise: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdPromise: return true; } zig_unreachable(); @@ -295,36 +295,36 @@ bool type_is_complete(ZigType *type_entry) { bool type_has_zero_bits_known(ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: return type_entry->data.structure.zero_bits_known; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: return type_entry->data.enumeration.zero_bits_known; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: return type_entry->data.unionation.zero_bits_known; - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdPromise: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: + case ZigTypeIdPromise: return true; } zig_unreachable(); @@ -337,12 +337,12 @@ uint64_t type_size(CodeGen *g, ZigType *type_entry) { if (!type_has_bits(type_entry)) return 0; - if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) { + if (type_entry->id == ZigTypeIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) { uint64_t size_in_bits = type_size_bits(g, type_entry); return (size_in_bits + 7) / 8; - } else if (type_entry->id == TypeTableEntryIdArray) { + } else if (type_entry->id == ZigTypeIdArray) { ZigType *child_type = type_entry->data.array.child_type; - if (child_type->id == TypeTableEntryIdStruct && + if (child_type->id == ZigTypeIdStruct && child_type->data.structure.layout == ContainerLayoutPacked) { uint64_t size_in_bits = type_size_bits(g, type_entry); @@ -359,15 +359,15 @@ uint64_t type_size_bits(CodeGen *g, ZigType *type_entry) { if (!type_has_bits(type_entry)) return 0; - if (type_entry->id == TypeTableEntryIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) { + if (type_entry->id == ZigTypeIdStruct && type_entry->data.structure.layout == ContainerLayoutPacked) { uint64_t result = 0; for (size_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { result += type_size_bits(g, type_entry->data.structure.fields[i].type_entry); } return result; - } else if (type_entry->id == TypeTableEntryIdArray) { + } else if (type_entry->id == ZigTypeIdArray) { ZigType *child_type = type_entry->data.array.child_type; - if (child_type->id == TypeTableEntryIdStruct && + if (child_type->id == ZigTypeIdStruct && child_type->data.structure.layout == ContainerLayoutPacked) { return type_entry->data.array.len * type_size_bits(g, child_type); @@ -395,7 +395,7 @@ Result type_is_copyable(CodeGen *g, ZigType *type_entry) { } static bool is_slice(ZigType *type) { - return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice; + return type->id == ZigTypeIdStruct && type->data.structure.is_slice; } ZigType *get_smallest_unsigned_int_type(CodeGen *g, uint64_t x) { @@ -410,7 +410,7 @@ ZigType *get_promise_type(CodeGen *g, ZigType *result_type) { } ZigType *u8_ptr_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false); - ZigType *entry = new_type_table_entry(TypeTableEntryIdPromise); + ZigType *entry = new_type_table_entry(ZigTypeIdPromise); entry->type_ref = u8_ptr_type->type_ref; entry->zero_bits = false; entry->data.promise.result_type = result_type; @@ -432,13 +432,13 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons bool is_volatile, PtrLen ptr_len, uint32_t byte_alignment, uint32_t bit_offset, uint32_t unaligned_bit_count) { assert(!type_is_invalid(child_type)); - assert(ptr_len == PtrLenSingle || child_type->id != TypeTableEntryIdOpaque); + assert(ptr_len == PtrLenSingle || child_type->id != ZigTypeIdOpaque); TypeId type_id = {}; ZigType **parent_pointer = nullptr; uint32_t abi_alignment = get_abi_alignment(g, child_type); if (unaligned_bit_count != 0 || is_volatile || byte_alignment != abi_alignment || ptr_len != PtrLenSingle) { - type_id.id = TypeTableEntryIdPointer; + type_id.id = ZigTypeIdPointer; type_id.data.pointer.child_type = child_type; type_id.data.pointer.is_const = is_const; type_id.data.pointer.is_volatile = is_volatile; @@ -461,7 +461,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons assertNoError(type_ensure_zero_bits_known(g, child_type)); - ZigType *entry = new_type_table_entry(TypeTableEntryIdPointer); + ZigType *entry = new_type_table_entry(ZigTypeIdPointer); entry->is_copyable = true; const char *star_str = ptr_len == PtrLenSingle ? "*" : "[*]"; @@ -478,7 +478,7 @@ ZigType *get_pointer_to_type_extra(CodeGen *g, ZigType *child_type, bool is_cons bit_offset, bit_offset + unaligned_bit_count, const_str, volatile_str, buf_ptr(&child_type->name)); } - assert(child_type->id != TypeTableEntryIdInvalid); + assert(child_type->id != ZigTypeIdInvalid); entry->zero_bits = !type_has_bits(child_type); @@ -568,7 +568,7 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) { } else { assertNoError(ensure_complete_type(g, child_type)); - ZigType *entry = new_type_table_entry(TypeTableEntryIdOptional); + ZigType *entry = new_type_table_entry(ZigTypeIdOptional); assert(child_type->type_ref || child_type->zero_bits); entry->is_copyable = type_is_copyable(g, child_type).unwrap(); @@ -646,11 +646,11 @@ ZigType *get_optional_type(CodeGen *g, ZigType *child_type) { } ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payload_type) { - assert(err_set_type->id == TypeTableEntryIdErrorSet); + assert(err_set_type->id == ZigTypeIdErrorSet); assert(!type_is_invalid(payload_type)); TypeId type_id = {}; - type_id.id = TypeTableEntryIdErrorUnion; + type_id.id = ZigTypeIdErrorUnion; type_id.data.error_union.err_set_type = err_set_type; type_id.data.error_union.payload_type = payload_type; @@ -659,7 +659,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa return existing_entry->value; } - ZigType *entry = new_type_table_entry(TypeTableEntryIdErrorUnion); + ZigType *entry = new_type_table_entry(ZigTypeIdErrorUnion); entry->is_copyable = true; assert(payload_type->di_type); assertNoError(ensure_complete_type(g, payload_type)); @@ -742,7 +742,7 @@ ZigType *get_error_union_type(CodeGen *g, ZigType *err_set_type, ZigType *payloa ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size) { TypeId type_id = {}; - type_id.id = TypeTableEntryIdArray; + type_id.id = ZigTypeIdArray; type_id.data.array.child_type = child_type; type_id.data.array.size = array_size; auto existing_entry = g->type_table.maybe_get(type_id); @@ -753,7 +753,7 @@ ZigType *get_array_type(CodeGen *g, ZigType *child_type, uint64_t array_size) { assertNoError(ensure_complete_type(g, child_type)); - ZigType *entry = new_type_table_entry(TypeTableEntryIdArray); + ZigType *entry = new_type_table_entry(ZigTypeIdArray); entry->zero_bits = (array_size == 0) || child_type->zero_bits; entry->is_copyable = false; @@ -812,7 +812,7 @@ static void slice_type_common_init(CodeGen *g, ZigType *pointer_type, ZigType *e } ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); assert(ptr_type->data.pointer.ptr_len == PtrLenUnknown); ZigType **parent_pointer = &ptr_type->data.pointer.slice_parent; @@ -820,7 +820,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { return *parent_pointer; } - ZigType *entry = new_type_table_entry(TypeTableEntryIdStruct); + ZigType *entry = new_type_table_entry(ZigTypeIdStruct); entry->is_copyable = true; // replace the & with [] to go from a ptr type name to a slice type name @@ -853,7 +853,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { // and debug info is the same as if the child type were []T. if (is_slice(child_type)) { ZigType *child_ptr_type = child_type->data.structure.fields[slice_ptr_index].type_entry; - assert(child_ptr_type->id == TypeTableEntryIdPointer); + assert(child_ptr_type->id == ZigTypeIdPointer); ZigType *grand_child_type = child_ptr_type->data.pointer.child_type; if (child_ptr_type->data.pointer.is_const || child_ptr_type->data.pointer.is_volatile || child_ptr_type->data.pointer.alignment != get_abi_alignment(g, grand_child_type)) @@ -972,7 +972,7 @@ ZigType *get_slice_type(CodeGen *g, ZigType *ptr_type) { } ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const char *name) { - ZigType *entry = new_type_table_entry(TypeTableEntryIdOpaque); + ZigType *entry = new_type_table_entry(ZigTypeIdOpaque); buf_init_from_str(&entry->name, name); @@ -993,11 +993,11 @@ ZigType *get_opaque_type(CodeGen *g, Scope *scope, AstNode *source_node, const c ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) { ZigType *fn_type = fn_entry->type_entry; - assert(fn_type->id == TypeTableEntryIdFn); + assert(fn_type->id == ZigTypeIdFn); if (fn_type->data.fn.bound_fn_parent) return fn_type->data.fn.bound_fn_parent; - ZigType *bound_fn_type = new_type_table_entry(TypeTableEntryIdBoundFn); + ZigType *bound_fn_type = new_type_table_entry(ZigTypeIdBoundFn); bound_fn_type->is_copyable = false; bound_fn_type->data.bound_fn.fn_type = fn_type; bound_fn_type->zero_bits = true; @@ -1054,7 +1054,7 @@ static bool calling_convention_allows_zig_types(CallingConvention cc) { ZigType *get_ptr_to_stack_trace_type(CodeGen *g) { if (g->stack_trace_type == nullptr) { ConstExprValue *stack_trace_type_val = get_builtin_value(g, "StackTrace"); - assert(stack_trace_type_val->type->id == TypeTableEntryIdMetaType); + assert(stack_trace_type_val->type->id == ZigTypeIdMetaType); g->stack_trace_type = stack_trace_type_val->data.x_type; g->ptr_to_stack_trace_type = get_pointer_to_type(g, g->stack_trace_type, false); } @@ -1070,12 +1070,12 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { if (fn_type_id->return_type != nullptr) { if ((err = ensure_complete_type(g, fn_type_id->return_type))) return g->builtin_types.entry_invalid; - assert(fn_type_id->return_type->id != TypeTableEntryIdOpaque); + assert(fn_type_id->return_type->id != ZigTypeIdOpaque); } else { zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447"); } - ZigType *fn_type = new_type_table_entry(TypeTableEntryIdFn); + ZigType *fn_type = new_type_table_entry(ZigTypeIdFn); fn_type->is_copyable = true; fn_type->data.fn.fn_type_id = *fn_type_id; @@ -1222,11 +1222,11 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { static ZigTypeId container_to_type(ContainerKind kind) { switch (kind) { case ContainerKindStruct: - return TypeTableEntryIdStruct; + return ZigTypeIdStruct; case ContainerKindEnum: - return TypeTableEntryIdEnum; + return ZigTypeIdEnum; case ContainerKindUnion: - return TypeTableEntryIdUnion; + return ZigTypeIdUnion; } zig_unreachable(); } @@ -1275,7 +1275,7 @@ static IrInstruction *analyze_const_value(CodeGen *g, Scope *scope, AstNode *nod ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { IrInstruction *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr); - if (result->value.type->id == TypeTableEntryIdInvalid) + if (result->value.type->id == ZigTypeIdInvalid) return g->builtin_types.entry_invalid; assert(result->value.special != ConstValSpecialRuntime); @@ -1283,7 +1283,7 @@ ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) { } ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id) { - ZigType *fn_type = new_type_table_entry(TypeTableEntryIdFn); + ZigType *fn_type = new_type_table_entry(ZigTypeIdFn); fn_type->is_copyable = false; buf_resize(&fn_type->name, 0); if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) { @@ -1384,41 +1384,41 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf ** static bool type_allowed_in_packed_struct(ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdMetaType: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdPromise: + case ZigTypeIdMetaType: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: + case ZigTypeIdPromise: return false; - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdFn: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdFn: return true; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: return type_entry->data.structure.layout == ContainerLayoutPacked; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: return type_entry->data.unionation.layout == ContainerLayoutPacked; - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: { ZigType *child_type = type_entry->data.maybe.child_type; return type_is_codegen_pointer(child_type); } - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: return type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr; } zig_unreachable(); @@ -1426,27 +1426,27 @@ static bool type_allowed_in_packed_struct(ZigType *type_entry) { static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdMetaType: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdPromise: - case TypeTableEntryIdVoid: + case ZigTypeIdMetaType: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdPromise: + case ZigTypeIdVoid: return false; - case TypeTableEntryIdOpaque: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdBool: + case ZigTypeIdOpaque: + case ZigTypeIdUnreachable: + case ZigTypeIdBool: return true; - case TypeTableEntryIdInt: + case ZigTypeIdInt: switch (type_entry->data.integral.bit_count) { case 8: case 16: @@ -1457,36 +1457,36 @@ static bool type_allowed_in_extern(CodeGen *g, ZigType *type_entry) { default: return false; } - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: return true; - case TypeTableEntryIdArray: + case ZigTypeIdArray: return type_allowed_in_extern(g, type_entry->data.array.child_type); - case TypeTableEntryIdFn: + case ZigTypeIdFn: return type_entry->data.fn.fn_type_id.cc == CallingConventionC; - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: if (type_size(g, type_entry) == 0) return false; return true; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: return type_entry->data.structure.layout == ContainerLayoutExtern || type_entry->data.structure.layout == ContainerLayoutPacked; - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: { ZigType *child_type = type_entry->data.maybe.child_type; - if (child_type->id != TypeTableEntryIdPointer && child_type->id != TypeTableEntryIdFn) { + if (child_type->id != ZigTypeIdPointer && child_type->id != ZigTypeIdFn) { return false; } return type_allowed_in_extern(g, child_type); } - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: return type_entry->data.enumeration.layout == ContainerLayoutExtern || type_entry->data.enumeration.layout == ContainerLayoutPacked; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: return type_entry->data.unionation.layout == ContainerLayoutExtern || type_entry->data.unionation.layout == ContainerLayoutPacked; } zig_unreachable(); } ZigType *get_auto_err_set_type(CodeGen *g, ZigFn *fn_entry) { - ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); buf_resize(&err_set_type->name, 0); buf_appendf(&err_set_type->name, "@typeOf(%s).ReturnType.ErrorSet", buf_ptr(&fn_entry->symbol_name)); err_set_type->is_copyable = true; @@ -1581,36 +1581,36 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc } switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdUnreachable: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: add_node_error(g, param_node->data.param_decl.type, buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); return g->builtin_types.entry_invalid; - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdPromise: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdPromise: if ((err = type_ensure_zero_bits_known(g, type_entry))) return g->builtin_types.entry_invalid; if (type_requires_comptime(type_entry)) { @@ -1659,7 +1659,7 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc } if (!calling_convention_allows_zig_types(fn_type_id.cc) && - fn_type_id.return_type->id != TypeTableEntryIdVoid && + fn_type_id.return_type->id != ZigTypeIdVoid && !type_allowed_in_extern(g, fn_type_id.return_type)) { add_node_error(g, fn_proto->return_type, @@ -1670,38 +1670,38 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc } switch (fn_type_id.return_type->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: add_node_error(g, fn_proto->return_type, buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name))); return g->builtin_types.entry_invalid; - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdPromise: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdMetaType: + case ZigTypeIdUnreachable: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdPromise: if ((err = type_ensure_zero_bits_known(g, fn_type_id.return_type))) return g->builtin_types.entry_invalid; if (type_requires_comptime(fn_type_id.return_type)) { @@ -1725,13 +1725,13 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc bool type_is_invalid(ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: return true; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: return type_entry->data.structure.is_invalid; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: return type_entry->data.enumeration.is_invalid; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: return type_entry->data.unionation.is_invalid; default: return false; @@ -1741,7 +1741,7 @@ bool type_is_invalid(ZigType *type_entry) { static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) { - assert(enum_type->id == TypeTableEntryIdEnum); + assert(enum_type->id == ZigTypeIdEnum); if (enum_type->data.enumeration.is_invalid) return ErrorSemanticAnalyzeFail; @@ -1837,7 +1837,7 @@ static Error resolve_enum_type(CodeGen *g, ZigType *enum_type) { ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_names[], ZigType *field_types[], size_t field_count) { - ZigType *struct_type = new_type_table_entry(TypeTableEntryIdStruct); + ZigType *struct_type = new_type_table_entry(ZigTypeIdStruct); buf_init_from_str(&struct_type->name, type_name); @@ -1914,7 +1914,7 @@ ZigType *get_struct_type(CodeGen *g, const char *type_name, const char *field_na } static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { - assert(struct_type->id == TypeTableEntryIdStruct); + assert(struct_type->id == ZigTypeIdStruct); if (struct_type->data.structure.complete) return ErrorNone; @@ -2092,7 +2092,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { // if the field is a function, actually the debug info should be a pointer. ZigLLVMDIType *field_di_type; - if (field_type->id == TypeTableEntryIdFn) { + if (field_type->id == ZigTypeIdFn) { ZigType *field_ptr_type = get_pointer_to_type(g, field_type, true); uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, field_ptr_type->type_ref); uint64_t debug_align_in_bits = 8*LLVMABISizeOfType(g->target_data_ref, field_ptr_type->type_ref); @@ -2148,7 +2148,7 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { } static Error resolve_union_type(CodeGen *g, ZigType *union_type) { - assert(union_type->id == TypeTableEntryIdUnion); + assert(union_type->id == ZigTypeIdUnion); if (union_type->data.unionation.complete) return ErrorNone; @@ -2388,7 +2388,7 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { } static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { - assert(enum_type->id == TypeTableEntryIdEnum); + assert(enum_type->id == ZigTypeIdEnum); if (enum_type->data.enumeration.zero_bits_known) return ErrorNone; @@ -2440,7 +2440,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { ZigType *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr); if (type_is_invalid(wanted_tag_int_type)) { enum_type->data.enumeration.is_invalid = true; - } else if (wanted_tag_int_type->id != TypeTableEntryIdInt) { + } else if (wanted_tag_int_type->id != ZigTypeIdInt) { enum_type->data.enumeration.is_invalid = true; add_node_error(g, decl_node->data.container_decl.init_arg_expr, buf_sprintf("expected integer, found '%s'", buf_ptr(&wanted_tag_int_type->name))); @@ -2489,12 +2489,12 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { // In a second pass we will fill in the unspecified ones. if (tag_value != nullptr) { IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr); - if (result_inst->value.type->id == TypeTableEntryIdInvalid) { + if (result_inst->value.type->id == ZigTypeIdInvalid) { enum_type->data.enumeration.is_invalid = true; continue; } assert(result_inst->value.special != ConstValSpecialRuntime); - assert(result_inst->value.type->id == TypeTableEntryIdInt); + assert(result_inst->value.type->id == ZigTypeIdInt); auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value); if (entry == nullptr) { bigint_init_bigint(&type_enum_field->value, &result_inst->value.data.x_bigint); @@ -2551,7 +2551,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { } static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { - assert(struct_type->id == TypeTableEntryIdStruct); + assert(struct_type->id == ZigTypeIdStruct); Error err; @@ -2670,7 +2670,7 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { } static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { - assert(union_type->id == TypeTableEntryIdUnion); + assert(union_type->id == ZigTypeIdUnion); Error err; @@ -2751,7 +2751,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { union_type->data.unionation.is_invalid = true; return ErrorSemanticAnalyzeFail; } - if (tag_int_type->id != TypeTableEntryIdInt) { + if (tag_int_type->id != ZigTypeIdInt) { add_node_error(g, enum_type_node, buf_sprintf("expected integer tag type, found '%s'", buf_ptr(&tag_int_type->name))); union_type->data.unionation.is_invalid = true; @@ -2762,7 +2762,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { } abi_alignment_so_far = get_abi_alignment(g, tag_int_type); - tag_type = new_type_table_entry(TypeTableEntryIdEnum); + tag_type = new_type_table_entry(ZigTypeIdEnum); buf_resize(&tag_type->name, 0); buf_appendf(&tag_type->name, "@TagType(%s)", buf_ptr(&union_type->name)); tag_type->is_copyable = true; @@ -2784,7 +2784,7 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { union_type->data.unionation.is_invalid = true; return ErrorSemanticAnalyzeFail; } - if (enum_type->id != TypeTableEntryIdEnum) { + if (enum_type->id != ZigTypeIdEnum) { union_type->data.unionation.is_invalid = true; add_node_error(g, enum_type_node, buf_sprintf("expected enum tag type, found '%s'", buf_ptr(&enum_type->name))); @@ -2862,12 +2862,12 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { if (tag_value != nullptr) { ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type; IrInstruction *result_inst = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr); - if (result_inst->value.type->id == TypeTableEntryIdInvalid) { + if (result_inst->value.type->id == ZigTypeIdInvalid) { union_type->data.unionation.is_invalid = true; continue; } assert(result_inst->value.special != ConstValSpecialRuntime); - assert(result_inst->value.type->id == TypeTableEntryIdInt); + assert(result_inst->value.type->id == ZigTypeIdInt); auto entry = occupied_tag_values.put_unique(result_inst->value.data.x_bigint, tag_value); if (entry == nullptr) { bigint_init_bigint(&union_field->enum_field->value, &result_inst->value.data.x_bigint); @@ -3192,7 +3192,7 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) { } } - if (fn_table_entry->type_entry->id == TypeTableEntryIdInvalid) { + if (fn_table_entry->type_entry->id == ZigTypeIdInvalid) { tld_fn->base.resolution = TldResolutionInvalid; return; } @@ -3448,13 +3448,13 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) { assert(type_entry); switch (type_entry->id) { - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: resolve_struct_type(g, tld_container->type_entry); return; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: resolve_enum_type(g, tld_container->type_entry); return; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: resolve_union_type(g, tld_container->type_entry); return; default: @@ -3464,36 +3464,36 @@ static void resolve_decl_container(CodeGen *g, TldContainer *tld_container) { ZigType *validate_var_type(CodeGen *g, AstNode *source_node, ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: return g->builtin_types.entry_invalid; - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdBlock: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdUnreachable: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdBlock: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed", buf_ptr(&type_entry->name))); return g->builtin_types.entry_invalid; - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdPromise: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdNamespace: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdBoundFn: + case ZigTypeIdPromise: return type_entry; } zig_unreachable(); @@ -3598,30 +3598,30 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) { // TODO more validation for types that can't be used for export/extern variables ZigType *implicit_type = nullptr; - if (explicit_type && explicit_type->id == TypeTableEntryIdInvalid) { + if (explicit_type && explicit_type->id == ZigTypeIdInvalid) { implicit_type = explicit_type; } else if (var_decl->expr) { init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type, var_decl->symbol); assert(init_value); implicit_type = init_value->value.type; - if (implicit_type->id == TypeTableEntryIdUnreachable) { + if (implicit_type->id == ZigTypeIdUnreachable) { add_node_error(g, source_node, buf_sprintf("variable initialization is unreachable")); implicit_type = g->builtin_types.entry_invalid; } else if ((!is_const || linkage == VarLinkageExternal) && - (implicit_type->id == TypeTableEntryIdComptimeFloat || - implicit_type->id == TypeTableEntryIdComptimeInt)) + (implicit_type->id == ZigTypeIdComptimeFloat || + implicit_type->id == ZigTypeIdComptimeInt)) { add_node_error(g, source_node, buf_sprintf("unable to infer variable type")); implicit_type = g->builtin_types.entry_invalid; - } else if (implicit_type->id == TypeTableEntryIdNull) { + } else if (implicit_type->id == ZigTypeIdNull) { add_node_error(g, source_node, buf_sprintf("unable to infer variable type")); implicit_type = g->builtin_types.entry_invalid; - } else if (implicit_type->id == TypeTableEntryIdMetaType && !is_const) { + } else if (implicit_type->id == ZigTypeIdMetaType && !is_const) { add_node_error(g, source_node, buf_sprintf("variable of type 'type' must be constant")); implicit_type = g->builtin_types.entry_invalid; } - assert(implicit_type->id == TypeTableEntryIdInvalid || init_value->value.special != ConstValSpecialRuntime); + assert(implicit_type->id == ZigTypeIdInvalid || init_value->value.special != ConstValSpecialRuntime); } else if (linkage != VarLinkageExternal) { add_node_error(g, source_node, buf_sprintf("variables must be initialized")); implicit_type = g->builtin_types.entry_invalid; @@ -3790,7 +3790,7 @@ ZigFn *scope_get_fn_if_root(Scope *scope) { } TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) { - assert(enum_type->id == TypeTableEntryIdEnum); + assert(enum_type->id == ZigTypeIdEnum); if (enum_type->data.enumeration.src_field_count == 0) return nullptr; auto entry = enum_type->data.enumeration.fields_by_name.maybe_get(name); @@ -3800,7 +3800,7 @@ TypeEnumField *find_enum_type_field(ZigType *enum_type, Buf *name) { } TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name) { - assert(type_entry->id == TypeTableEntryIdStruct); + assert(type_entry->id == ZigTypeIdStruct); assert(type_entry->data.structure.complete); if (type_entry->data.structure.src_field_count == 0) return nullptr; @@ -3811,7 +3811,7 @@ TypeStructField *find_struct_type_field(ZigType *type_entry, Buf *name) { } TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name) { - assert(type_entry->id == TypeTableEntryIdUnion); + assert(type_entry->id == ZigTypeIdUnion); assert(type_entry->data.unionation.zero_bits_known); if (type_entry->data.unionation.src_field_count == 0) return nullptr; @@ -3822,7 +3822,7 @@ TypeUnionField *find_union_type_field(ZigType *type_entry, Buf *name) { } TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag) { - assert(type_entry->id == TypeTableEntryIdUnion); + assert(type_entry->id == ZigTypeIdUnion); assert(type_entry->data.unionation.zero_bits_known); for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) { TypeUnionField *field = &type_entry->data.unionation.fields[i]; @@ -3847,47 +3847,47 @@ TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag) { static bool is_container(ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdStruct: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: + case ZigTypeIdStruct: + case ZigTypeIdEnum: + case ZigTypeIdUnion: return true; - case TypeTableEntryIdPointer: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdArray: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdPromise: + case ZigTypeIdPointer: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdArray: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: + case ZigTypeIdPromise: return false; } zig_unreachable(); } bool is_ref(ZigType *type_entry) { - return type_entry->id == TypeTableEntryIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle; + return type_entry->id == ZigTypeIdPointer && type_entry->data.pointer.ptr_len == PtrLenSingle; } bool is_array_ref(ZigType *type_entry) { ZigType *array = is_ref(type_entry) ? type_entry->data.pointer.child_type : type_entry; - return array->id == TypeTableEntryIdArray; + return array->id == ZigTypeIdArray; } bool is_container_ref(ZigType *type_entry) { @@ -3903,50 +3903,50 @@ ZigType *container_ref_type(ZigType *type_entry) { void resolve_container_type(CodeGen *g, ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: resolve_struct_type(g, type_entry); break; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: resolve_enum_type(g, type_entry); break; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: resolve_union_type(g, type_entry); break; - case TypeTableEntryIdPointer: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdArray: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdInvalid: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdPromise: + case ZigTypeIdPointer: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdArray: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdInvalid: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: + case ZigTypeIdPromise: zig_unreachable(); } } ZigType *get_codegen_ptr_type(ZigType *type) { - if (type->id == TypeTableEntryIdPointer) return type; - if (type->id == TypeTableEntryIdFn) return type; - if (type->id == TypeTableEntryIdPromise) return type; - if (type->id == TypeTableEntryIdOptional) { - if (type->data.maybe.child_type->id == TypeTableEntryIdPointer) return type->data.maybe.child_type; - if (type->data.maybe.child_type->id == TypeTableEntryIdFn) return type->data.maybe.child_type; - if (type->data.maybe.child_type->id == TypeTableEntryIdPromise) return type->data.maybe.child_type; + if (type->id == ZigTypeIdPointer) return type; + if (type->id == ZigTypeIdFn) return type; + if (type->id == ZigTypeIdPromise) return type; + if (type->id == ZigTypeIdOptional) { + if (type->data.maybe.child_type->id == ZigTypeIdPointer) return type->data.maybe.child_type; + if (type->data.maybe.child_type->id == ZigTypeIdFn) return type->data.maybe.child_type; + if (type->data.maybe.child_type->id == ZigTypeIdPromise) return type->data.maybe.child_type; } return nullptr; } @@ -3957,11 +3957,11 @@ bool type_is_codegen_pointer(ZigType *type) { uint32_t get_ptr_align(ZigType *type) { ZigType *ptr_type = get_codegen_ptr_type(type); - if (ptr_type->id == TypeTableEntryIdPointer) { + if (ptr_type->id == ZigTypeIdPointer) { return ptr_type->data.pointer.alignment; - } else if (ptr_type->id == TypeTableEntryIdFn) { + } else if (ptr_type->id == ZigTypeIdFn) { return (ptr_type->data.fn.fn_type_id.alignment == 0) ? 1 : ptr_type->data.fn.fn_type_id.alignment; - } else if (ptr_type->id == TypeTableEntryIdPromise) { + } else if (ptr_type->id == ZigTypeIdPromise) { return 1; } else { zig_unreachable(); @@ -3970,11 +3970,11 @@ uint32_t get_ptr_align(ZigType *type) { bool get_ptr_const(ZigType *type) { ZigType *ptr_type = get_codegen_ptr_type(type); - if (ptr_type->id == TypeTableEntryIdPointer) { + if (ptr_type->id == ZigTypeIdPointer) { return ptr_type->data.pointer.is_const; - } else if (ptr_type->id == TypeTableEntryIdFn) { + } else if (ptr_type->id == ZigTypeIdFn) { return true; - } else if (ptr_type->id == TypeTableEntryIdPromise) { + } else if (ptr_type->id == ZigTypeIdPromise) { return true; } else { zig_unreachable(); @@ -4067,13 +4067,13 @@ void analyze_fn_ir(CodeGen *g, ZigFn *fn_table_entry, AstNode *return_type_node) return; } - if (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion) { + if (fn_type_id->return_type->id == ZigTypeIdErrorUnion) { ZigType *return_err_set_type = fn_type_id->return_type->data.error_union.err_set_type; if (return_err_set_type->data.error_set.infer_fn != nullptr) { ZigType *inferred_err_set_type; - if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorSet) { + if (fn_table_entry->src_implicit_return_type->id == ZigTypeIdErrorSet) { inferred_err_set_type = fn_table_entry->src_implicit_return_type; - } else if (fn_table_entry->src_implicit_return_type->id == TypeTableEntryIdErrorUnion) { + } else if (fn_table_entry->src_implicit_return_type->id == ZigTypeIdErrorUnion) { inferred_err_set_type = fn_table_entry->src_implicit_return_type->data.error_union.err_set_type; } else { add_node_error(g, return_type_node, @@ -4154,7 +4154,7 @@ static void add_symbols_from_import(CodeGen *g, AstNode *src_use_node, AstNode * } IrInstruction *use_target_value = src_use_node->data.use.value; - if (use_target_value->value.type->id == TypeTableEntryIdInvalid) { + if (use_target_value->value.type->id == ZigTypeIdInvalid) { dst_use_node->owner->any_imports_failed = true; return; } @@ -4230,7 +4230,7 @@ void preview_use_decl(CodeGen *g, AstNode *node) { IrInstruction *result = analyze_const_value(g, &node->owner->decls_scope->base, node->data.use.expr, g->builtin_types.entry_namespace, nullptr); - if (result->value.type->id == TypeTableEntryIdInvalid) + if (result->value.type->id == ZigTypeIdInvalid) node->owner->any_imports_failed = true; node->data.use.value = result; @@ -4357,7 +4357,7 @@ void semantic_analyze(CodeGen *g) { ZigType *get_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) { TypeId type_id = {}; - type_id.id = TypeTableEntryIdInt; + type_id.id = ZigTypeIdInt; type_id.data.integer.is_signed = is_signed; type_id.data.integer.bit_count = size_in_bits; @@ -4382,38 +4382,38 @@ ZigType *get_c_int_type(CodeGen *g, CIntType c_int_type) { bool handle_is_ptr(ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: zig_unreachable(); - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdFn: - case TypeTableEntryIdEnum: - case TypeTableEntryIdPromise: + case ZigTypeIdUnreachable: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdErrorSet: + case ZigTypeIdFn: + case ZigTypeIdEnum: + case ZigTypeIdPromise: return false; - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: + case ZigTypeIdArray: + case ZigTypeIdStruct: return type_has_bits(type_entry); - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: return type_has_bits(type_entry->data.error_union.payload_type); - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: return type_has_bits(type_entry->data.maybe.child_type) && !type_is_codegen_pointer(type_entry->data.maybe.child_type); - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: assert(type_entry->data.unionation.complete); if (type_entry->data.unionation.gen_field_count == 0) return false; @@ -4697,16 +4697,16 @@ static uint32_t hash_const_val_ptr(ConstExprValue *const_val) { static uint32_t hash_const_val(ConstExprValue *const_val) { assert(const_val->special == ConstValSpecialStatic); switch (const_val->type->id) { - case TypeTableEntryIdOpaque: + case ZigTypeIdOpaque: zig_unreachable(); - case TypeTableEntryIdBool: + case ZigTypeIdBool: return const_val->data.x_bool ? (uint32_t)127863866 : (uint32_t)215080464; - case TypeTableEntryIdMetaType: + case ZigTypeIdMetaType: return hash_ptr(const_val->data.x_type); - case TypeTableEntryIdVoid: + case ZigTypeIdVoid: return (uint32_t)4149439618; - case TypeTableEntryIdInt: - case TypeTableEntryIdComptimeInt: + case ZigTypeIdInt: + case ZigTypeIdComptimeInt: { uint32_t result = 1331471175; for (size_t i = 0; i < const_val->data.x_bigint.digit_count; i += 1) { @@ -4715,7 +4715,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { } return result; } - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: { uint32_t result = 31643936; for (size_t i = 0; i < const_val->data.x_enum_tag.digit_count; i += 1) { @@ -4724,7 +4724,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { } return result; } - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: switch (const_val->type->data.floating.bit_count) { case 16: { @@ -4754,39 +4754,39 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { default: zig_unreachable(); } - case TypeTableEntryIdComptimeFloat: + case ZigTypeIdComptimeFloat: { float128_t f128 = bigfloat_to_f128(&const_val->data.x_bigfloat); uint32_t ints[4]; memcpy(&ints[0], &f128, 16); return ints[0] ^ ints[1] ^ ints[2] ^ ints[3] ^ 0xed8b3dfb; } - case TypeTableEntryIdArgTuple: + case ZigTypeIdArgTuple: return (uint32_t)const_val->data.x_arg_tuple.start_index * (uint32_t)281907309 + (uint32_t)const_val->data.x_arg_tuple.end_index * (uint32_t)2290442768; - case TypeTableEntryIdFn: + case ZigTypeIdFn: assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst); assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction); return 3677364617 ^ hash_ptr(const_val->data.x_ptr.data.fn.fn_entry); - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: return hash_const_val_ptr(const_val); - case TypeTableEntryIdPromise: + case ZigTypeIdPromise: // TODO better hashing algorithm return 223048345; - case TypeTableEntryIdUndefined: + case ZigTypeIdUndefined: return 162837799; - case TypeTableEntryIdNull: + case ZigTypeIdNull: return 844854567; - case TypeTableEntryIdArray: + case ZigTypeIdArray: // TODO better hashing algorithm return 1166190605; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: // TODO better hashing algorithm return 1532530855; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: // TODO better hashing algorithm return 2709806591; - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: if (get_codegen_ptr_type(const_val->type) != nullptr) { return hash_const_val(const_val) * 1992916303; } else { @@ -4796,19 +4796,19 @@ static uint32_t hash_const_val(ConstExprValue *const_val) { return 4016830364; } } - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: // TODO better hashing algorithm return 3415065496; - case TypeTableEntryIdErrorSet: + case ZigTypeIdErrorSet: assert(const_val->data.x_err_set != nullptr); return const_val->data.x_err_set->value ^ 2630160122; - case TypeTableEntryIdNamespace: + case ZigTypeIdNamespace: return hash_ptr(const_val->data.x_import); - case TypeTableEntryIdBlock: + case ZigTypeIdBlock: return hash_ptr(const_val->data.x_block); - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdInvalid: - case TypeTableEntryIdUnreachable: + case ZigTypeIdBoundFn: + case ZigTypeIdInvalid: + case ZigTypeIdUnreachable: zig_unreachable(); } zig_unreachable(); @@ -4851,32 +4851,32 @@ bool generic_fn_type_id_eql(GenericFnTypeId *a, GenericFnTypeId *b) { static bool can_mutate_comptime_var_state(ConstExprValue *value) { assert(value != nullptr); switch (value->type->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdFn: - case TypeTableEntryIdBlock: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdPromise: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdNamespace: + case ZigTypeIdBoundFn: + case ZigTypeIdFn: + case ZigTypeIdBlock: + case ZigTypeIdOpaque: + case ZigTypeIdPromise: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: return false; - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: return value->data.x_ptr.mut == ConstPtrMutComptimeVar; - case TypeTableEntryIdArray: + case ZigTypeIdArray: if (value->type->data.array.len == 0) return false; if (value->data.x_array.special == ConstArraySpecialUndef) @@ -4887,30 +4887,30 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) { } return false; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: for (uint32_t i = 0; i < value->type->data.structure.src_field_count; i += 1) { if (can_mutate_comptime_var_state(&value->data.x_struct.fields[i])) return true; } return false; - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: if (get_codegen_ptr_type(value->type) != nullptr) return value->data.x_ptr.mut == ConstPtrMutComptimeVar; if (value->data.x_optional == nullptr) return false; return can_mutate_comptime_var_state(value->data.x_optional); - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: if (value->data.x_err_union.err != nullptr) return false; assert(value->data.x_err_union.payload != nullptr); return can_mutate_comptime_var_state(value->data.x_err_union.payload); - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: return can_mutate_comptime_var_state(value->data.x_union.payload); - case TypeTableEntryIdArgTuple: + case ZigTypeIdArgTuple: zig_panic("TODO var args at comptime is currently not supported"); } zig_unreachable(); @@ -4918,41 +4918,41 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) { static bool return_type_is_cacheable(ZigType *return_type) { switch (return_type->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdFn: - case TypeTableEntryIdBlock: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdPromise: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdPointer: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdNamespace: + case ZigTypeIdBoundFn: + case ZigTypeIdFn: + case ZigTypeIdBlock: + case ZigTypeIdOpaque: + case ZigTypeIdPromise: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdPointer: return true; - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdUnion: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdUnion: return false; - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: return return_type_is_cacheable(return_type->data.maybe.child_type); - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: return return_type_is_cacheable(return_type->data.error_union.payload_type); - case TypeTableEntryIdArgTuple: + case ZigTypeIdArgTuple: zig_panic("TODO var args at comptime is currently not supported"); } zig_unreachable(); @@ -5029,54 +5029,54 @@ bool fn_eval_eql(Scope *a, Scope *b) { bool type_has_bits(ZigType *type_entry) { assert(type_entry); - assert(type_entry->id != TypeTableEntryIdInvalid); + assert(type_entry->id != ZigTypeIdInvalid); assert(type_has_zero_bits_known(type_entry)); return !type_entry->zero_bits; } bool type_requires_comptime(ZigType *type_entry) { switch (type_entry->id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdOpaque: + case ZigTypeIdInvalid: + case ZigTypeIdOpaque: zig_unreachable(); - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdMetaType: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: return true; - case TypeTableEntryIdArray: + case ZigTypeIdArray: return type_requires_comptime(type_entry->data.array.child_type); - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: assert(type_has_zero_bits_known(type_entry)); return type_entry->data.structure.requires_comptime; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: assert(type_has_zero_bits_known(type_entry)); return type_entry->data.unionation.requires_comptime; - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: return type_requires_comptime(type_entry->data.maybe.child_type); - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: return type_requires_comptime(type_entry->data.error_union.payload_type); - case TypeTableEntryIdPointer: - if (type_entry->data.pointer.child_type->id == TypeTableEntryIdOpaque) { + case ZigTypeIdPointer: + if (type_entry->data.pointer.child_type->id == ZigTypeIdOpaque) { return false; } else { return type_requires_comptime(type_entry->data.pointer.child_type); } - case TypeTableEntryIdFn: + case ZigTypeIdFn: return type_entry->data.fn.is_generic; - case TypeTableEntryIdEnum: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdVoid: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdPromise: + case ZigTypeIdEnum: + case ZigTypeIdErrorSet: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdVoid: + case ZigTypeIdUnreachable: + case ZigTypeIdPromise: return false; } zig_unreachable(); @@ -5192,9 +5192,9 @@ ConstExprValue *create_const_signed(ZigType *type, int64_t x) { void init_const_float(ConstExprValue *const_val, ZigType *type, double value) { const_val->special = ConstValSpecialStatic; const_val->type = type; - if (type->id == TypeTableEntryIdComptimeFloat) { + if (type->id == ZigTypeIdComptimeFloat) { bigfloat_init_64(&const_val->data.x_bigfloat, value); - } else if (type->id == TypeTableEntryIdFloat) { + } else if (type->id == ZigTypeIdFloat) { switch (type->data.floating.bit_count) { case 16: const_val->data.x_f16 = zig_double_to_f16(value); @@ -5273,7 +5273,7 @@ ConstExprValue *create_const_type(CodeGen *g, ZigType *type_value) { void init_const_slice(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val, size_t start, size_t len, bool is_const) { - assert(array_val->type->id == TypeTableEntryIdArray); + assert(array_val->type->id == ZigTypeIdArray); ZigType *ptr_type = get_pointer_to_type_extra(g, array_val->type->data.array.child_type, is_const, false, PtrLenUnknown, get_abi_alignment(g, array_val->type->data.array.child_type), @@ -5297,7 +5297,7 @@ ConstExprValue *create_const_slice(CodeGen *g, ConstExprValue *array_val, size_t void init_const_ptr_array(CodeGen *g, ConstExprValue *const_val, ConstExprValue *array_val, size_t elem_index, bool is_const, PtrLen ptr_len) { - assert(array_val->type->id == TypeTableEntryIdArray); + assert(array_val->type->id == ZigTypeIdArray); ZigType *child_type = array_val->type->data.array.child_type; const_val->special = ConstValSpecialStatic; @@ -5363,10 +5363,10 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_ void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { Error err; ZigType *wanted_type = const_val->type; - if (wanted_type->id == TypeTableEntryIdArray) { + if (wanted_type->id == ZigTypeIdArray) { const_val->special = ConstValSpecialStatic; const_val->data.x_array.special = ConstArraySpecialUndef; - } else if (wanted_type->id == TypeTableEntryIdStruct) { + } else if (wanted_type->id == ZigTypeIdStruct) { if ((err = ensure_complete_type(g, wanted_type))) { return; } @@ -5403,13 +5403,13 @@ ConstExprValue *create_const_vals(size_t count) { Error ensure_complete_type(CodeGen *g, ZigType *type_entry) { if (type_is_invalid(type_entry)) return ErrorSemanticAnalyzeFail; - if (type_entry->id == TypeTableEntryIdStruct) { + if (type_entry->id == ZigTypeIdStruct) { if (!type_entry->data.structure.complete) return resolve_struct_type(g, type_entry); - } else if (type_entry->id == TypeTableEntryIdEnum) { + } else if (type_entry->id == ZigTypeIdEnum) { if (!type_entry->data.enumeration.complete) return resolve_enum_type(g, type_entry); - } else if (type_entry->id == TypeTableEntryIdUnion) { + } else if (type_entry->id == ZigTypeIdUnion) { if (!type_entry->data.unionation.complete) return resolve_union_type(g, type_entry); } @@ -5419,11 +5419,11 @@ Error ensure_complete_type(CodeGen *g, ZigType *type_entry) { Error type_ensure_zero_bits_known(CodeGen *g, ZigType *type_entry) { if (type_is_invalid(type_entry)) return ErrorSemanticAnalyzeFail; - if (type_entry->id == TypeTableEntryIdStruct) { + if (type_entry->id == ZigTypeIdStruct) { return resolve_struct_zero_bits(g, type_entry); - } else if (type_entry->id == TypeTableEntryIdEnum) { + } else if (type_entry->id == ZigTypeIdEnum) { return resolve_enum_zero_bits(g, type_entry); - } else if (type_entry->id == TypeTableEntryIdUnion) { + } else if (type_entry->id == ZigTypeIdUnion) { return resolve_union_zero_bits(g, type_entry); } return ErrorNone; @@ -5488,11 +5488,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { assert(a->special == ConstValSpecialStatic); assert(b->special == ConstValSpecialStatic); switch (a->type->id) { - case TypeTableEntryIdOpaque: + case ZigTypeIdOpaque: zig_unreachable(); - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: return bigint_cmp(&a->data.x_enum_tag, &b->data.x_enum_tag) == CmpEQ; - case TypeTableEntryIdUnion: { + case ZigTypeIdUnion: { ConstUnionValue *union1 = &a->data.x_union; ConstUnionValue *union2 = &b->data.x_union; @@ -5507,15 +5507,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { } return false; } - case TypeTableEntryIdMetaType: + case ZigTypeIdMetaType: return a->data.x_type == b->data.x_type; - case TypeTableEntryIdVoid: + case ZigTypeIdVoid: return true; - case TypeTableEntryIdErrorSet: + case ZigTypeIdErrorSet: return a->data.x_err_set->value == b->data.x_err_set->value; - case TypeTableEntryIdBool: + case ZigTypeIdBool: return a->data.x_bool == b->data.x_bool; - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: assert(a->type->data.floating.bit_count == b->type->data.floating.bit_count); switch (a->type->data.floating.bit_count) { case 16: @@ -5529,15 +5529,15 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { default: zig_unreachable(); } - case TypeTableEntryIdComptimeFloat: + case ZigTypeIdComptimeFloat: return bigfloat_cmp(&a->data.x_bigfloat, &b->data.x_bigfloat) == CmpEQ; - case TypeTableEntryIdInt: - case TypeTableEntryIdComptimeInt: + case ZigTypeIdInt: + case ZigTypeIdComptimeInt: return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ; - case TypeTableEntryIdPointer: - case TypeTableEntryIdFn: + case ZigTypeIdPointer: + case ZigTypeIdFn: return const_values_equal_ptr(a, b); - case TypeTableEntryIdArray: { + case ZigTypeIdArray: { assert(a->type->data.array.len == b->type->data.array.len); assert(a->data.x_array.special != ConstArraySpecialUndef); assert(b->data.x_array.special != ConstArraySpecialUndef); @@ -5553,7 +5553,7 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { return true; } - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: for (size_t i = 0; i < a->type->data.structure.src_field_count; i += 1) { ConstExprValue *field_a = &a->data.x_struct.fields[i]; ConstExprValue *field_b = &b->data.x_struct.fields[i]; @@ -5561,11 +5561,11 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { return false; } return true; - case TypeTableEntryIdUndefined: + case ZigTypeIdUndefined: zig_panic("TODO"); - case TypeTableEntryIdNull: + case ZigTypeIdNull: zig_panic("TODO"); - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: if (get_codegen_ptr_type(a->type) != nullptr) return const_values_equal_ptr(a, b); if (a->data.x_optional == nullptr || b->data.x_optional == nullptr) { @@ -5573,26 +5573,26 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) { } else { return const_values_equal(a->data.x_optional, b->data.x_optional); } - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: zig_panic("TODO"); - case TypeTableEntryIdNamespace: + case ZigTypeIdNamespace: return a->data.x_import == b->data.x_import; - case TypeTableEntryIdBlock: + case ZigTypeIdBlock: return a->data.x_block == b->data.x_block; - case TypeTableEntryIdArgTuple: + case ZigTypeIdArgTuple: return a->data.x_arg_tuple.start_index == b->data.x_arg_tuple.start_index && a->data.x_arg_tuple.end_index == b->data.x_arg_tuple.end_index; - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdInvalid: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdPromise: + case ZigTypeIdBoundFn: + case ZigTypeIdInvalid: + case ZigTypeIdUnreachable: + case ZigTypeIdPromise: zig_unreachable(); } zig_unreachable(); } void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool is_max) { - assert(int_type->id == TypeTableEntryIdInt); + assert(int_type->id == ZigTypeIdInt); if (int_type->data.integral.bit_count == 0) { bigint_init_unsigned(bigint, 0); return; @@ -5629,13 +5629,13 @@ void eval_min_max_value_int(CodeGen *g, ZigType *int_type, BigInt *bigint, bool } void eval_min_max_value(CodeGen *g, ZigType *type_entry, ConstExprValue *const_val, bool is_max) { - if (type_entry->id == TypeTableEntryIdInt) { + if (type_entry->id == ZigTypeIdInt) { const_val->special = ConstValSpecialStatic; eval_min_max_value_int(g, type_entry, &const_val->data.x_bigint, is_max); - } else if (type_entry->id == TypeTableEntryIdBool) { + } else if (type_entry->id == ZigTypeIdBool) { const_val->special = ConstValSpecialStatic; const_val->data.x_bool = is_max; - } else if (type_entry->id == TypeTableEntryIdVoid) { + } else if (type_entry->id == ZigTypeIdVoid) { // nothing to do } else { zig_unreachable(); @@ -5692,18 +5692,18 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { ZigType *type_entry = const_val->type; switch (type_entry->id) { - case TypeTableEntryIdOpaque: + case ZigTypeIdOpaque: zig_unreachable(); - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: buf_appendf(buf, "(invalid)"); return; - case TypeTableEntryIdVoid: + case ZigTypeIdVoid: buf_appendf(buf, "{}"); return; - case TypeTableEntryIdComptimeFloat: + case ZigTypeIdComptimeFloat: bigfloat_append_buf(buf, &const_val->data.x_bigfloat); return; - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: switch (type_entry->data.floating.bit_count) { case 16: buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16)); @@ -5731,23 +5731,23 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { default: zig_unreachable(); } - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdInt: + case ZigTypeIdComptimeInt: + case ZigTypeIdInt: bigint_append_buf(buf, &const_val->data.x_bigint, 10); return; - case TypeTableEntryIdMetaType: + case ZigTypeIdMetaType: buf_appendf(buf, "%s", buf_ptr(&const_val->data.x_type->name)); return; - case TypeTableEntryIdUnreachable: + case ZigTypeIdUnreachable: buf_appendf(buf, "unreachable"); return; - case TypeTableEntryIdBool: + case ZigTypeIdBool: { const char *value = const_val->data.x_bool ? "true" : "false"; buf_appendf(buf, "%s", value); return; } - case TypeTableEntryIdFn: + case ZigTypeIdFn: { assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst); assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction); @@ -5755,15 +5755,15 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { buf_appendf(buf, "%s", buf_ptr(&fn_entry->symbol_name)); return; } - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: return render_const_val_ptr(g, buf, const_val, type_entry); - case TypeTableEntryIdBlock: + case ZigTypeIdBlock: { AstNode *node = const_val->data.x_block->source_node; buf_appendf(buf, "(scope:%" ZIG_PRI_usize ":%" ZIG_PRI_usize ")", node->line + 1, node->column + 1); return; } - case TypeTableEntryIdArray: + case ZigTypeIdArray: { ZigType *child_type = type_entry->data.array.child_type; uint64_t len = type_entry->data.array.len; @@ -5774,7 +5774,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { } // if it's []u8, assume UTF-8 and output a string - if (child_type->id == TypeTableEntryIdInt && + if (child_type->id == ZigTypeIdInt && child_type->data.integral.bit_count == 8 && !child_type->data.integral.is_signed) { @@ -5804,17 +5804,17 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { buf_appendf(buf, "}"); return; } - case TypeTableEntryIdNull: + case ZigTypeIdNull: { buf_appendf(buf, "null"); return; } - case TypeTableEntryIdUndefined: + case ZigTypeIdUndefined: { buf_appendf(buf, "undefined"); return; } - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: { if (get_codegen_ptr_type(const_val->type) != nullptr) return render_const_val_ptr(g, buf, const_val, type_entry->data.maybe.child_type); @@ -5825,7 +5825,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { } return; } - case TypeTableEntryIdNamespace: + case ZigTypeIdNamespace: { ImportTableEntry *import = const_val->data.x_import; if (import->c_import_node) { @@ -5835,51 +5835,51 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) { } return; } - case TypeTableEntryIdBoundFn: + case ZigTypeIdBoundFn: { ZigFn *fn_entry = const_val->data.x_bound_fn.fn; buf_appendf(buf, "(bound fn %s)", buf_ptr(&fn_entry->symbol_name)); return; } - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: { buf_appendf(buf, "(struct %s constant)", buf_ptr(&type_entry->name)); return; } - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: { TypeEnumField *field = find_enum_field_by_tag(type_entry, &const_val->data.x_enum_tag); buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(field->name)); return; } - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: { buf_appendf(buf, "(error union %s constant)", buf_ptr(&type_entry->name)); return; } - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: { buf_appendf(buf, "(union %s constant)", buf_ptr(&type_entry->name)); return; } - case TypeTableEntryIdErrorSet: + case ZigTypeIdErrorSet: { buf_appendf(buf, "%s.%s", buf_ptr(&type_entry->name), buf_ptr(&const_val->data.x_err_set->name)); return; } - case TypeTableEntryIdArgTuple: + case ZigTypeIdArgTuple: { buf_appendf(buf, "(args value)"); return; } - case TypeTableEntryIdPromise: + case ZigTypeIdPromise: zig_unreachable(); } zig_unreachable(); } ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) { - ZigType *entry = new_type_table_entry(TypeTableEntryIdInt); + ZigType *entry = new_type_table_entry(ZigTypeIdInt); entry->is_copyable = true; entry->type_ref = (size_in_bits == 0) ? LLVMVoidType() : LLVMIntType(size_in_bits); entry->zero_bits = (size_in_bits == 0); @@ -5913,32 +5913,32 @@ ZigType *make_int_type(CodeGen *g, bool is_signed, uint32_t size_in_bits) { uint32_t type_id_hash(TypeId x) { switch (x.id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdFloat: - case TypeTableEntryIdStruct: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdPromise: + case ZigTypeIdInvalid: + case ZigTypeIdOpaque: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdFloat: + case ZigTypeIdStruct: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdPromise: zig_unreachable(); - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: return hash_ptr(x.data.error_union.err_set_type) ^ hash_ptr(x.data.error_union.payload_type); - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: return hash_ptr(x.data.pointer.child_type) + ((x.data.pointer.ptr_len == PtrLenSingle) ? (uint32_t)1120226602 : (uint32_t)3200913342) + (x.data.pointer.is_const ? (uint32_t)2749109194 : (uint32_t)4047371087) + @@ -5946,10 +5946,10 @@ uint32_t type_id_hash(TypeId x) { (((uint32_t)x.data.pointer.alignment) ^ (uint32_t)0x777fbe0e) + (((uint32_t)x.data.pointer.bit_offset) ^ (uint32_t)2639019452) + (((uint32_t)x.data.pointer.unaligned_bit_count) ^ (uint32_t)529908881); - case TypeTableEntryIdArray: + case ZigTypeIdArray: return hash_ptr(x.data.array.child_type) + ((uint32_t)x.data.array.size ^ (uint32_t)2122979968); - case TypeTableEntryIdInt: + case ZigTypeIdInt: return (x.data.integer.is_signed ? (uint32_t)2652528194 : (uint32_t)163929201) + (((uint32_t)x.data.integer.bit_count) ^ (uint32_t)2998081557); } @@ -5960,34 +5960,34 @@ bool type_id_eql(TypeId a, TypeId b) { if (a.id != b.id) return false; switch (a.id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdFloat: - case TypeTableEntryIdStruct: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdPromise: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdFloat: + case ZigTypeIdStruct: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdPromise: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: zig_unreachable(); - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: return a.data.error_union.err_set_type == b.data.error_union.err_set_type && a.data.error_union.payload_type == b.data.error_union.payload_type; - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: return a.data.pointer.child_type == b.data.pointer.child_type && a.data.pointer.ptr_len == b.data.pointer.ptr_len && a.data.pointer.is_const == b.data.pointer.is_const && @@ -5995,10 +5995,10 @@ bool type_id_eql(TypeId a, TypeId b) { a.data.pointer.alignment == b.data.pointer.alignment && a.data.pointer.bit_offset == b.data.pointer.bit_offset && a.data.pointer.unaligned_bit_count == b.data.pointer.unaligned_bit_count; - case TypeTableEntryIdArray: + case ZigTypeIdArray: return a.data.array.child_type == b.data.array.child_type && a.data.array.size == b.data.array.size; - case TypeTableEntryIdInt: + case ZigTypeIdInt: return a.data.integer.is_signed == b.data.integer.is_signed && a.data.integer.bit_count == b.data.integer.bit_count; } @@ -6050,7 +6050,7 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) { } void expand_undef_array(CodeGen *g, ConstExprValue *const_val) { - assert(const_val->type->id == TypeTableEntryIdArray); + assert(const_val->type->id == ZigTypeIdArray); if (const_val->data.x_array.special == ConstArraySpecialUndef) { const_val->data.x_array.special = ConstArraySpecialNone; size_t elem_count = const_val->type->data.array.len; @@ -6072,43 +6072,43 @@ void expand_undef_array(CodeGen *g, ConstExprValue *const_val) { ConstParent *get_const_val_parent(CodeGen *g, ConstExprValue *value) { assert(value->type); ZigType *type_entry = value->type; - if (type_entry->id == TypeTableEntryIdArray) { + if (type_entry->id == ZigTypeIdArray) { expand_undef_array(g, value); return &value->data.x_array.s_none.parent; - } else if (type_entry->id == TypeTableEntryIdStruct) { + } else if (type_entry->id == ZigTypeIdStruct) { return &value->data.x_struct.parent; - } else if (type_entry->id == TypeTableEntryIdUnion) { + } else if (type_entry->id == ZigTypeIdUnion) { return &value->data.x_union.parent; } return nullptr; } static const ZigTypeId all_type_ids[] = { - TypeTableEntryIdMetaType, - TypeTableEntryIdVoid, - TypeTableEntryIdBool, - TypeTableEntryIdUnreachable, - TypeTableEntryIdInt, - TypeTableEntryIdFloat, - TypeTableEntryIdPointer, - TypeTableEntryIdArray, - TypeTableEntryIdStruct, - TypeTableEntryIdComptimeFloat, - TypeTableEntryIdComptimeInt, - TypeTableEntryIdUndefined, - TypeTableEntryIdNull, - TypeTableEntryIdOptional, - TypeTableEntryIdErrorUnion, - TypeTableEntryIdErrorSet, - TypeTableEntryIdEnum, - TypeTableEntryIdUnion, - TypeTableEntryIdFn, - TypeTableEntryIdNamespace, - TypeTableEntryIdBlock, - TypeTableEntryIdBoundFn, - TypeTableEntryIdArgTuple, - TypeTableEntryIdOpaque, - TypeTableEntryIdPromise, + ZigTypeIdMetaType, + ZigTypeIdVoid, + ZigTypeIdBool, + ZigTypeIdUnreachable, + ZigTypeIdInt, + ZigTypeIdFloat, + ZigTypeIdPointer, + ZigTypeIdArray, + ZigTypeIdStruct, + ZigTypeIdComptimeFloat, + ZigTypeIdComptimeInt, + ZigTypeIdUndefined, + ZigTypeIdNull, + ZigTypeIdOptional, + ZigTypeIdErrorUnion, + ZigTypeIdErrorSet, + ZigTypeIdEnum, + ZigTypeIdUnion, + ZigTypeIdFn, + ZigTypeIdNamespace, + ZigTypeIdBlock, + ZigTypeIdBoundFn, + ZigTypeIdArgTuple, + ZigTypeIdOpaque, + ZigTypeIdPromise, }; ZigTypeId type_id_at_index(size_t index) { @@ -6122,59 +6122,59 @@ size_t type_id_len() { size_t type_id_index(ZigType *entry) { switch (entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdMetaType: + case ZigTypeIdMetaType: return 0; - case TypeTableEntryIdVoid: + case ZigTypeIdVoid: return 1; - case TypeTableEntryIdBool: + case ZigTypeIdBool: return 2; - case TypeTableEntryIdUnreachable: + case ZigTypeIdUnreachable: return 3; - case TypeTableEntryIdInt: + case ZigTypeIdInt: return 4; - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: return 5; - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: return 6; - case TypeTableEntryIdArray: + case ZigTypeIdArray: return 7; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: if (entry->data.structure.is_slice) return 6; return 8; - case TypeTableEntryIdComptimeFloat: + case ZigTypeIdComptimeFloat: return 9; - case TypeTableEntryIdComptimeInt: + case ZigTypeIdComptimeInt: return 10; - case TypeTableEntryIdUndefined: + case ZigTypeIdUndefined: return 11; - case TypeTableEntryIdNull: + case ZigTypeIdNull: return 12; - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: return 13; - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: return 14; - case TypeTableEntryIdErrorSet: + case ZigTypeIdErrorSet: return 15; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: return 16; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: return 17; - case TypeTableEntryIdFn: + case ZigTypeIdFn: return 18; - case TypeTableEntryIdNamespace: + case ZigTypeIdNamespace: return 19; - case TypeTableEntryIdBlock: + case ZigTypeIdBlock: return 20; - case TypeTableEntryIdBoundFn: + case ZigTypeIdBoundFn: return 21; - case TypeTableEntryIdArgTuple: + case ZigTypeIdArgTuple: return 22; - case TypeTableEntryIdOpaque: + case ZigTypeIdOpaque: return 23; - case TypeTableEntryIdPromise: + case ZigTypeIdPromise: return 24; } zig_unreachable(); @@ -6182,57 +6182,57 @@ size_t type_id_index(ZigType *entry) { const char *type_id_name(ZigTypeId id) { switch (id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdMetaType: + case ZigTypeIdMetaType: return "Type"; - case TypeTableEntryIdVoid: + case ZigTypeIdVoid: return "Void"; - case TypeTableEntryIdBool: + case ZigTypeIdBool: return "Bool"; - case TypeTableEntryIdUnreachable: + case ZigTypeIdUnreachable: return "NoReturn"; - case TypeTableEntryIdInt: + case ZigTypeIdInt: return "Int"; - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: return "Float"; - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: return "Pointer"; - case TypeTableEntryIdArray: + case ZigTypeIdArray: return "Array"; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: return "Struct"; - case TypeTableEntryIdComptimeFloat: + case ZigTypeIdComptimeFloat: return "ComptimeFloat"; - case TypeTableEntryIdComptimeInt: + case ZigTypeIdComptimeInt: return "ComptimeInt"; - case TypeTableEntryIdUndefined: + case ZigTypeIdUndefined: return "Undefined"; - case TypeTableEntryIdNull: + case ZigTypeIdNull: return "Null"; - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: return "Optional"; - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: return "ErrorUnion"; - case TypeTableEntryIdErrorSet: + case ZigTypeIdErrorSet: return "ErrorSet"; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: return "Enum"; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: return "Union"; - case TypeTableEntryIdFn: + case ZigTypeIdFn: return "Fn"; - case TypeTableEntryIdNamespace: + case ZigTypeIdNamespace: return "Namespace"; - case TypeTableEntryIdBlock: + case ZigTypeIdBlock: return "Block"; - case TypeTableEntryIdBoundFn: + case ZigTypeIdBoundFn: return "BoundFn"; - case TypeTableEntryIdArgTuple: + case ZigTypeIdArgTuple: return "ArgTuple"; - case TypeTableEntryIdOpaque: + case ZigTypeIdOpaque: return "Opaque"; - case TypeTableEntryIdPromise: + case ZigTypeIdPromise: return "Promise"; } zig_unreachable(); @@ -6272,18 +6272,18 @@ uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry) { // We need to make this function work without requiring ensure_complete_type // so that we can have structs with fields that are pointers to their own type. - if (type_entry->id == TypeTableEntryIdStruct) { + if (type_entry->id == ZigTypeIdStruct) { assert(type_entry->data.structure.abi_alignment != 0); return type_entry->data.structure.abi_alignment; - } else if (type_entry->id == TypeTableEntryIdUnion) { + } else if (type_entry->id == ZigTypeIdUnion) { assert(type_entry->data.unionation.abi_alignment != 0); return type_entry->data.unionation.abi_alignment; - } else if (type_entry->id == TypeTableEntryIdOpaque) { + } else if (type_entry->id == ZigTypeIdOpaque) { return 1; } else { uint32_t llvm_alignment = LLVMABIAlignmentOfType(g->target_data_ref, type_entry->type_ref); // promises have at least alignment 8 so that we can have 3 extra bits when doing atomicrmw - if (type_entry->id == TypeTableEntryIdPromise && llvm_alignment < 8) { + if (type_entry->id == ZigTypeIdPromise && llvm_alignment < 8) { return 8; } return llvm_alignment; @@ -6317,7 +6317,7 @@ ConstExprValue *get_builtin_value(CodeGen *codegen, const char *name) { } bool type_is_global_error_set(ZigType *err_set_type) { - assert(err_set_type->id == TypeTableEntryIdErrorSet); + assert(err_set_type->id == ZigTypeIdErrorSet); assert(err_set_type->data.error_set.infer_fn == nullptr); return err_set_type->data.error_set.err_count == UINT32_MAX; } @@ -6327,7 +6327,7 @@ uint32_t get_coro_frame_align_bytes(CodeGen *g) { } bool type_can_fail(ZigType *type_entry) { - return type_entry->id == TypeTableEntryIdErrorUnion || type_entry->id == TypeTableEntryIdErrorSet; + return type_entry->id == ZigTypeIdErrorUnion || type_entry->id == ZigTypeIdErrorSet; } bool fn_type_can_fail(FnTypeId *fn_type_id) { diff --git a/src/codegen.cpp b/src/codegen.cpp index 34cbd5cfad..0300ccca99 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -533,7 +533,7 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) { } ZigType *return_type = fn_type->data.fn.fn_type_id.return_type; - if (return_type->id == TypeTableEntryIdUnreachable) { + if (return_type->id == ZigTypeIdUnreachable) { addLLVMFnAttr(fn_table_entry->llvm_value, "noreturn"); } @@ -600,10 +600,10 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) { if (param_info->is_noalias) { addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "noalias"); } - if ((param_type->id == TypeTableEntryIdPointer && param_type->data.pointer.is_const) || is_byval) { + if ((param_type->id == ZigTypeIdPointer && param_type->data.pointer.is_const) || is_byval) { addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "readonly"); } - if (param_type->id == TypeTableEntryIdPointer) { + if (param_type->id == ZigTypeIdPointer) { addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "nonnull"); } } @@ -693,7 +693,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry, { char fn_name[64]; - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); const char *signed_str = type_entry->data.integral.is_signed ? signed_name : unsigned_name; sprintf(fn_name, "llvm.%s.with.overflow.i%" PRIu32, signed_str, type_entry->data.integral.bit_count); @@ -713,7 +713,7 @@ static LLVMValueRef get_arithmetic_overflow_fn(CodeGen *g, ZigType *type_entry, } static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubMul add_sub_mul) { - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); ZigLLVMFnKey key = {}; key.id = ZigLLVMFnIdOverflowArithmetic; @@ -743,7 +743,7 @@ static LLVMValueRef get_int_overflow_fn(CodeGen *g, ZigType *type_entry, AddSubM } static LLVMValueRef get_float_fn(CodeGen *g, ZigType *type_entry, ZigLLVMFnId fn_id) { - assert(type_entry->id == TypeTableEntryIdFloat); + assert(type_entry->id == ZigTypeIdFloat); ZigLLVMFnKey key = {}; key.id = fn_id; @@ -788,7 +788,7 @@ static LLVMValueRef gen_store_untyped(CodeGen *g, LLVMValueRef value, LLVMValueR } static LLVMValueRef gen_store(CodeGen *g, LLVMValueRef value, LLVMValueRef ptr, ZigType *ptr_type) { - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); return gen_store_untyped(g, value, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile); } @@ -806,7 +806,7 @@ static LLVMValueRef gen_load_untyped(CodeGen *g, LLVMValueRef ptr, uint32_t alig } static LLVMValueRef gen_load(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, const char *name) { - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); return gen_load_untyped(g, ptr, ptr_type->data.pointer.alignment, ptr_type->data.pointer.is_volatile, name); } @@ -815,7 +815,7 @@ static LLVMValueRef get_handle_value(CodeGen *g, LLVMValueRef ptr, ZigType *type if (handle_is_ptr(type)) { return ptr; } else { - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); return gen_load(g, ptr, ptr_type, ""); } } else { @@ -1656,17 +1656,17 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z uint64_t actual_bits; uint64_t wanted_bits; - if (actual_type->id == TypeTableEntryIdFloat) { + if (actual_type->id == ZigTypeIdFloat) { actual_bits = actual_type->data.floating.bit_count; wanted_bits = wanted_type->data.floating.bit_count; - } else if (actual_type->id == TypeTableEntryIdInt) { + } else if (actual_type->id == ZigTypeIdInt) { actual_bits = actual_type->data.integral.bit_count; wanted_bits = wanted_type->data.integral.bit_count; } else { zig_unreachable(); } - if (actual_bits >= wanted_bits && actual_type->id == TypeTableEntryIdInt && + if (actual_bits >= wanted_bits && actual_type->id == ZigTypeIdInt && !wanted_type->data.integral.is_signed && actual_type->data.integral.is_signed && want_runtime_safety) { @@ -1686,9 +1686,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z if (actual_bits == wanted_bits) { return expr_val; } else if (actual_bits < wanted_bits) { - if (actual_type->id == TypeTableEntryIdFloat) { + if (actual_type->id == ZigTypeIdFloat) { return LLVMBuildFPExt(g->builder, expr_val, wanted_type->type_ref, ""); - } else if (actual_type->id == TypeTableEntryIdInt) { + } else if (actual_type->id == ZigTypeIdInt) { if (actual_type->data.integral.is_signed) { return LLVMBuildSExt(g->builder, expr_val, wanted_type->type_ref, ""); } else { @@ -1698,9 +1698,9 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, Z zig_unreachable(); } } else if (actual_bits > wanted_bits) { - if (actual_type->id == TypeTableEntryIdFloat) { + if (actual_type->id == ZigTypeIdFloat) { return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, ""); - } else if (actual_type->id == TypeTableEntryIdInt) { + } else if (actual_type->id == ZigTypeIdInt) { LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, ""); if (!want_runtime_safety) { return trunc_val; @@ -1792,7 +1792,7 @@ static LLVMRealPredicate cmp_op_to_real_predicate(IrBinOp cmp_op) { static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_type, LLVMValueRef value) { - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ZigType *child_type = ptr_type->data.pointer.child_type; if (!type_has_bits(child_type)) @@ -1878,7 +1878,7 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) { render_const_val_global(g, &instruction->value, ""); ZigType *ptr_type = get_pointer_to_type(g, instruction->value.type, true); instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_global, ptr_type->type_ref, ""); - } else if (instruction->value.type->id == TypeTableEntryIdPointer) { + } else if (instruction->value.type->id == ZigTypeIdPointer) { instruction->llvm_value = LLVMBuildBitCast(g->builder, instruction->value.global_refs->llvm_value, instruction->value.type->type_ref, ""); } else { instruction->llvm_value = instruction->value.global_refs->llvm_value; @@ -1929,7 +1929,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, ZigType *type_entry, // if the values don't match, we have an overflow // for signed left shifting we do the same except arithmetic shift right - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); LLVMValueRef result = LLVMBuildShl(g->builder, val1, val2, ""); LLVMValueRef orig_val; @@ -1954,7 +1954,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, ZigType *type_entry, static LLVMValueRef gen_overflow_shr_op(CodeGen *g, ZigType *type_entry, LLVMValueRef val1, LLVMValueRef val2) { - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); LLVMValueRef result; if (type_entry->data.integral.is_signed) { @@ -1977,7 +1977,7 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, ZigType *type_entry, } static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, ZigType *type_entry) { - if (type_entry->id == TypeTableEntryIdInt) + if (type_entry->id == ZigTypeIdInt) return val; LLVMValueRef floor_fn = get_float_fn(g, type_entry, ZigLLVMFnIdFloor); @@ -1985,7 +1985,7 @@ static LLVMValueRef gen_floor(CodeGen *g, LLVMValueRef val, ZigType *type_entry) } static LLVMValueRef gen_ceil(CodeGen *g, LLVMValueRef val, ZigType *type_entry) { - if (type_entry->id == TypeTableEntryIdInt) + if (type_entry->id == ZigTypeIdInt) return val; LLVMValueRef ceil_fn = get_float_fn(g, type_entry, ZigLLVMFnIdCeil); @@ -2023,11 +2023,11 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast ZigLLVMSetFastMath(g->builder, want_fast_math); LLVMValueRef zero = LLVMConstNull(type_entry->type_ref); - if (want_runtime_safety && (want_fast_math || type_entry->id != TypeTableEntryIdFloat)) { + if (want_runtime_safety && (want_fast_math || type_entry->id != ZigTypeIdFloat)) { LLVMValueRef is_zero_bit; - if (type_entry->id == TypeTableEntryIdInt) { + if (type_entry->id == ZigTypeIdInt) { is_zero_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, val2, zero, ""); - } else if (type_entry->id == TypeTableEntryIdFloat) { + } else if (type_entry->id == ZigTypeIdFloat) { is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, ""); } else { zig_unreachable(); @@ -2041,7 +2041,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast LLVMPositionBuilderAtEnd(g->builder, div_zero_ok_block); - if (type_entry->id == TypeTableEntryIdInt && type_entry->data.integral.is_signed) { + if (type_entry->id == ZigTypeIdInt && type_entry->data.integral.is_signed) { LLVMValueRef neg_1_value = LLVMConstInt(type_entry->type_ref, -1, true); BigInt int_min_bi = {0}; eval_min_max_value_int(g, type_entry, &int_min_bi, false); @@ -2060,7 +2060,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast } } - if (type_entry->id == TypeTableEntryIdFloat) { + if (type_entry->id == ZigTypeIdFloat) { LLVMValueRef result = LLVMBuildFDiv(g->builder, val1, val2, ""); switch (div_kind) { case DivKindFloat: @@ -2111,7 +2111,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast zig_unreachable(); } - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); switch (div_kind) { case DivKindFloat: @@ -2184,10 +2184,10 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast LLVMValueRef zero = LLVMConstNull(type_entry->type_ref); if (want_runtime_safety) { LLVMValueRef is_zero_bit; - if (type_entry->id == TypeTableEntryIdInt) { + if (type_entry->id == ZigTypeIdInt) { LLVMIntPredicate pred = type_entry->data.integral.is_signed ? LLVMIntSLE : LLVMIntEQ; is_zero_bit = LLVMBuildICmp(g->builder, pred, val2, zero, ""); - } else if (type_entry->id == TypeTableEntryIdFloat) { + } else if (type_entry->id == ZigTypeIdFloat) { is_zero_bit = LLVMBuildFCmp(g->builder, LLVMRealOEQ, val2, zero, ""); } else { zig_unreachable(); @@ -2202,7 +2202,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast LLVMPositionBuilderAtEnd(g->builder, rem_zero_ok_block); } - if (type_entry->id == TypeTableEntryIdFloat) { + if (type_entry->id == ZigTypeIdFloat) { if (rem_kind == RemKindRem) { return LLVMBuildFRem(g->builder, val1, val2, ""); } else { @@ -2213,7 +2213,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast return LLVMBuildSelect(g->builder, ltz, c, a, ""); } } else { - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); if (type_entry->data.integral.is_signed) { if (rem_kind == RemKindRem) { return LLVMBuildSRem(g->builder, val1, val2, ""); @@ -2241,8 +2241,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, assert(op1->value.type == op2->value.type || op_id == IrBinOpBitShiftLeftLossy || op_id == IrBinOpBitShiftLeftExact || op_id == IrBinOpBitShiftRightLossy || op_id == IrBinOpBitShiftRightExact || - (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) || - (op1->value.type->id == TypeTableEntryIdPointer && + (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) || + (op1->value.type->id == ZigTypeIdPointer && (op_id == IrBinOpAdd || op_id == IrBinOpSub) && op1->value.type->data.pointer.ptr_len == PtrLenUnknown) ); @@ -2272,16 +2272,16 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, case IrBinOpCmpGreaterThan: case IrBinOpCmpLessOrEq: case IrBinOpCmpGreaterOrEq: - if (type_entry->id == TypeTableEntryIdFloat) { + if (type_entry->id == ZigTypeIdFloat) { ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base)); LLVMRealPredicate pred = cmp_op_to_real_predicate(op_id); return LLVMBuildFCmp(g->builder, pred, op1_value, op2_value, ""); - } else if (type_entry->id == TypeTableEntryIdInt) { + } else if (type_entry->id == ZigTypeIdInt) { LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, type_entry->data.integral.is_signed); return LLVMBuildICmp(g->builder, pred, op1_value, op2_value, ""); - } else if (type_entry->id == TypeTableEntryIdEnum || - type_entry->id == TypeTableEntryIdErrorSet || - type_entry->id == TypeTableEntryIdBool || + } else if (type_entry->id == ZigTypeIdEnum || + type_entry->id == ZigTypeIdErrorSet || + type_entry->id == ZigTypeIdBool || get_codegen_ptr_type(type_entry) != nullptr) { LLVMIntPredicate pred = cmp_op_to_int_predicate(op_id, false); @@ -2291,14 +2291,14 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, } case IrBinOpAdd: case IrBinOpAddWrap: - if (type_entry->id == TypeTableEntryIdPointer) { + if (type_entry->id == ZigTypeIdPointer) { assert(type_entry->data.pointer.ptr_len == PtrLenUnknown); // TODO runtime safety return LLVMBuildInBoundsGEP(g->builder, op1_value, &op2_value, 1, ""); - } else if (type_entry->id == TypeTableEntryIdFloat) { + } else if (type_entry->id == ZigTypeIdFloat) { ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base)); return LLVMBuildFAdd(g->builder, op1_value, op2_value, ""); - } else if (type_entry->id == TypeTableEntryIdInt) { + } else if (type_entry->id == ZigTypeIdInt) { bool is_wrapping = (op_id == IrBinOpAddWrap); if (is_wrapping) { return LLVMBuildAdd(g->builder, op1_value, op2_value, ""); @@ -2321,7 +2321,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, case IrBinOpBitShiftLeftLossy: case IrBinOpBitShiftLeftExact: { - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type, type_entry, op2_value); bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy); @@ -2338,7 +2338,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, case IrBinOpBitShiftRightLossy: case IrBinOpBitShiftRightExact: { - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); LLVMValueRef op2_casted = gen_widen_or_shorten(g, false, op2->value.type, type_entry, op2_value); bool is_sloppy = (op_id == IrBinOpBitShiftRightLossy); @@ -2358,15 +2358,15 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, } case IrBinOpSub: case IrBinOpSubWrap: - if (type_entry->id == TypeTableEntryIdPointer) { + if (type_entry->id == ZigTypeIdPointer) { assert(type_entry->data.pointer.ptr_len == PtrLenUnknown); // TODO runtime safety LLVMValueRef subscript_value = LLVMBuildNeg(g->builder, op2_value, ""); return LLVMBuildInBoundsGEP(g->builder, op1_value, &subscript_value, 1, ""); - } else if (type_entry->id == TypeTableEntryIdFloat) { + } else if (type_entry->id == ZigTypeIdFloat) { ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base)); return LLVMBuildFSub(g->builder, op1_value, op2_value, ""); - } else if (type_entry->id == TypeTableEntryIdInt) { + } else if (type_entry->id == ZigTypeIdInt) { bool is_wrapping = (op_id == IrBinOpSubWrap); if (is_wrapping) { return LLVMBuildSub(g->builder, op1_value, op2_value, ""); @@ -2382,10 +2382,10 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, } case IrBinOpMult: case IrBinOpMultWrap: - if (type_entry->id == TypeTableEntryIdFloat) { + if (type_entry->id == ZigTypeIdFloat) { ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &bin_op_instruction->base)); return LLVMBuildFMul(g->builder, op1_value, op2_value, ""); - } else if (type_entry->id == TypeTableEntryIdInt) { + } else if (type_entry->id == ZigTypeIdInt) { bool is_wrapping = (op_id == IrBinOpMultWrap); if (is_wrapping) { return LLVMBuildMul(g->builder, op1_value, op2_value, ""); @@ -2422,7 +2422,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable, } static void add_error_range_check(CodeGen *g, ZigType *err_set_type, ZigType *int_type, LLVMValueRef target_val) { - assert(err_set_type->id == TypeTableEntryIdErrorSet); + assert(err_set_type->id == ZigTypeIdErrorSet); if (type_is_global_error_set(err_set_type)) { LLVMValueRef zero = LLVMConstNull(int_type->type_ref); @@ -2486,9 +2486,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, case CastOpResizeSlice: { assert(cast_instruction->tmp_ptr); - assert(wanted_type->id == TypeTableEntryIdStruct); + assert(wanted_type->id == ZigTypeIdStruct); assert(wanted_type->data.structure.is_slice); - assert(actual_type->id == TypeTableEntryIdStruct); + assert(actual_type->id == ZigTypeIdStruct); assert(actual_type->data.structure.is_slice); ZigType *actual_pointer_type = actual_type->data.structure.fields[0].type_entry; @@ -2549,9 +2549,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, case CastOpBytesToSlice: { assert(cast_instruction->tmp_ptr); - assert(wanted_type->id == TypeTableEntryIdStruct); + assert(wanted_type->id == ZigTypeIdStruct); assert(wanted_type->data.structure.is_slice); - assert(actual_type->id == TypeTableEntryIdArray); + assert(actual_type->id == ZigTypeIdArray); ZigType *wanted_pointer_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; ZigType *wanted_child_type = wanted_pointer_type->data.pointer.child_type; @@ -2573,14 +2573,14 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, return cast_instruction->tmp_ptr; } case CastOpIntToFloat: - assert(actual_type->id == TypeTableEntryIdInt); + assert(actual_type->id == ZigTypeIdInt); if (actual_type->data.integral.is_signed) { return LLVMBuildSIToFP(g->builder, expr_val, wanted_type->type_ref, ""); } else { return LLVMBuildUIToFP(g->builder, expr_val, wanted_type->type_ref, ""); } case CastOpFloatToInt: { - assert(wanted_type->id == TypeTableEntryIdInt); + assert(wanted_type->id == ZigTypeIdInt); ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &cast_instruction->base)); bool want_safety = ir_want_runtime_safety(g, &cast_instruction->base); @@ -2615,8 +2615,8 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, return result; } case CastOpBoolToInt: - assert(wanted_type->id == TypeTableEntryIdInt); - assert(actual_type->id == TypeTableEntryIdBool); + assert(wanted_type->id == ZigTypeIdInt); + assert(actual_type->id == ZigTypeIdBool); return LLVMBuildZExt(g->builder, expr_val, wanted_type->type_ref, ""); case CastOpErrSet: if (ir_want_runtime_safety(g, &cast_instruction->base)) { @@ -2627,9 +2627,9 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable, return LLVMBuildBitCast(g->builder, expr_val, wanted_type->type_ref, ""); case CastOpPtrOfArrayToSlice: { assert(cast_instruction->tmp_ptr); - assert(actual_type->id == TypeTableEntryIdPointer); + assert(actual_type->id == ZigTypeIdPointer); ZigType *array_type = actual_type->data.pointer.child_type; - assert(array_type->id == TypeTableEntryIdArray); + assert(array_type->id == ZigTypeIdArray); LLVMValueRef ptr_field_ptr = LLVMBuildStructGEP(g->builder, cast_instruction->tmp_ptr, slice_ptr_index, ""); @@ -2678,7 +2678,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa // TODO instead of this logic, use the Noop instruction to change the type from // enum_tag to the underlying int type ZigType *int_type; - if (actual_type->id == TypeTableEntryIdEnum) { + if (actual_type->id == ZigTypeIdEnum) { int_type = actual_type->data.enumeration.tag_int_type; } else { int_type = actual_type; @@ -2702,7 +2702,7 @@ static LLVMValueRef ir_render_ptr_to_int(CodeGen *g, IrExecutable *executable, I static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, IrInstructionIntToEnum *instruction) { ZigType *wanted_type = instruction->base.value.type; - assert(wanted_type->id == TypeTableEntryIdEnum); + assert(wanted_type->id == ZigTypeIdEnum); ZigType *tag_int_type = wanted_type->data.enumeration.tag_int_type; LLVMValueRef target_val = ir_llvm_value(g, instruction->target); @@ -2729,10 +2729,10 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable, static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, IrInstructionIntToErr *instruction) { ZigType *wanted_type = instruction->base.value.type; - assert(wanted_type->id == TypeTableEntryIdErrorSet); + assert(wanted_type->id == ZigTypeIdErrorSet); ZigType *actual_type = instruction->target->value.type; - assert(actual_type->id == TypeTableEntryIdInt); + assert(actual_type->id == ZigTypeIdInt); assert(!actual_type->data.integral.is_signed); LLVMValueRef target_val = ir_llvm_value(g, instruction->target); @@ -2746,16 +2746,16 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, IrInstructionErrToInt *instruction) { ZigType *wanted_type = instruction->base.value.type; - assert(wanted_type->id == TypeTableEntryIdInt); + assert(wanted_type->id == ZigTypeIdInt); assert(!wanted_type->data.integral.is_signed); ZigType *actual_type = instruction->target->value.type; LLVMValueRef target_val = ir_llvm_value(g, instruction->target); - if (actual_type->id == TypeTableEntryIdErrorSet) { + if (actual_type->id == ZigTypeIdErrorSet) { return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base), g->err_tag_type, wanted_type, target_val); - } else if (actual_type->id == TypeTableEntryIdErrorUnion) { + } else if (actual_type->id == ZigTypeIdErrorUnion) { // this should have been a compile time constant assert(type_has_bits(actual_type->data.error_union.err_set_type)); @@ -2809,10 +2809,10 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst case IrUnOpNegation: case IrUnOpNegationWrap: { - if (expr_type->id == TypeTableEntryIdFloat) { + if (expr_type->id == ZigTypeIdFloat) { ZigLLVMSetFastMath(g->builder, ir_want_fast_math(g, &un_op_instruction->base)); return LLVMBuildFNeg(g->builder, expr, ""); - } else if (expr_type->id == TypeTableEntryIdInt) { + } else if (expr_type->id == ZigTypeIdInt) { if (op_id == IrUnOpNegationWrap) { return LLVMBuildNeg(g->builder, expr, ""); } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) { @@ -2921,7 +2921,7 @@ static LLVMValueRef ir_render_load_ptr(CodeGen *g, IrExecutable *executable, IrI LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr); ZigType *ptr_type = instruction->ptr->value.type; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); uint32_t unaligned_bit_count = ptr_type->data.pointer.unaligned_bit_count; if (unaligned_bit_count == 0) @@ -2946,7 +2946,7 @@ static LLVMValueRef ir_render_store_ptr(CodeGen *g, IrExecutable *executable, Ir LLVMValueRef ptr = ir_llvm_value(g, instruction->ptr); LLVMValueRef value = ir_llvm_value(g, instruction->value); - assert(instruction->ptr->value.type->id == TypeTableEntryIdPointer); + assert(instruction->ptr->value.type->id == ZigTypeIdPointer); ZigType *ptr_type = instruction->ptr->value.type; gen_assign_raw(g, ptr, ptr_type, value); @@ -2967,7 +2967,7 @@ static LLVMValueRef ir_render_var_ptr(CodeGen *g, IrExecutable *executable, IrIn static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrInstructionElemPtr *instruction) { LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->array_ptr); ZigType *array_ptr_type = instruction->array_ptr->value.type; - assert(array_ptr_type->id == TypeTableEntryIdPointer); + assert(array_ptr_type->id == ZigTypeIdPointer); ZigType *array_type = array_ptr_type->data.pointer.child_type; LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type); LLVMValueRef subscript_value = ir_llvm_value(g, instruction->elem_index); @@ -2978,11 +2978,11 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on; - if (array_type->id == TypeTableEntryIdArray || - (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) + if (array_type->id == ZigTypeIdArray || + (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) { - if (array_type->id == TypeTableEntryIdPointer) { - assert(array_type->data.pointer.child_type->id == TypeTableEntryIdArray); + if (array_type->id == ZigTypeIdPointer) { + assert(array_type->data.pointer.child_type->id == ZigTypeIdArray); array_type = array_type->data.pointer.child_type; } if (safety_check_on) { @@ -2994,7 +2994,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI return array_ptr_ptr; } ZigType *child_type = array_type->data.array.child_type; - if (child_type->id == TypeTableEntryIdStruct && + if (child_type->id == ZigTypeIdStruct && child_type->data.structure.layout == ContainerLayoutPacked) { size_t unaligned_bit_count = instruction->base.value.type->data.pointer.unaligned_bit_count; @@ -3017,13 +3017,13 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI subscript_value }; return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 2, ""); - } else if (array_type->id == TypeTableEntryIdPointer) { + } else if (array_type->id == ZigTypeIdPointer) { assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind); LLVMValueRef indices[] = { subscript_value }; return LLVMBuildInBoundsGEP(g->builder, array_ptr, indices, 1, ""); - } else if (array_type->id == TypeTableEntryIdStruct) { + } else if (array_type->id == ZigTypeIdStruct) { assert(array_type->data.structure.is_slice); if (!type_has_bits(instruction->base.value.type)) { if (safety_check_on) { @@ -3056,8 +3056,8 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI static bool get_prefix_arg_err_ret_stack(CodeGen *g, FnTypeId *fn_type_id) { return g->have_err_ret_tracing && - (fn_type_id->return_type->id == TypeTableEntryIdErrorUnion || - fn_type_id->return_type->id == TypeTableEntryIdErrorSet || + (fn_type_id->return_type->id == ZigTypeIdErrorUnion || + fn_type_id->return_type->id == ZigTypeIdErrorSet || fn_type_id->cc == CallingConventionAsync); } @@ -3201,7 +3201,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr return instruction->tmp_ptr; } - if (src_return_type->id == TypeTableEntryIdUnreachable) { + if (src_return_type->id == ZigTypeIdUnreachable) { return LLVMBuildUnreachable(g->builder); } else if (!ret_has_bits) { return nullptr; @@ -3221,14 +3221,14 @@ static LLVMValueRef ir_render_struct_field_ptr(CodeGen *g, IrExecutable *executa IrInstructionStructFieldPtr *instruction) { LLVMValueRef struct_ptr = ir_llvm_value(g, instruction->struct_ptr); - // not necessarily a pointer. could be TypeTableEntryIdStruct + // not necessarily a pointer. could be ZigTypeIdStruct ZigType *struct_ptr_type = instruction->struct_ptr->value.type; TypeStructField *field = instruction->field; if (!type_has_bits(field->type_entry)) return nullptr; - if (struct_ptr_type->id == TypeTableEntryIdPointer && + if (struct_ptr_type->id == ZigTypeIdPointer && struct_ptr_type->data.pointer.unaligned_bit_count != 0) { return struct_ptr; @@ -3242,9 +3242,9 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab IrInstructionUnionFieldPtr *instruction) { ZigType *union_ptr_type = instruction->union_ptr->value.type; - assert(union_ptr_type->id == TypeTableEntryIdPointer); + assert(union_ptr_type->id == ZigTypeIdPointer); ZigType *union_type = union_ptr_type->data.pointer.child_type; - assert(union_type->id == TypeTableEntryIdUnion); + assert(union_type->id == ZigTypeIdUnion); TypeUnionField *field = instruction->field; @@ -3412,7 +3412,7 @@ static LLVMValueRef ir_render_asm(CodeGen *g, IrExecutable *executable, IrInstru } static LLVMValueRef gen_non_null_bit(CodeGen *g, ZigType *maybe_type, LLVMValueRef maybe_handle) { - assert(maybe_type->id == TypeTableEntryIdOptional); + assert(maybe_type->id == ZigTypeIdOptional); ZigType *child_type = maybe_type->data.maybe.child_type; if (child_type->zero_bits) { return maybe_handle; @@ -3437,9 +3437,9 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapOptional *instruction) { ZigType *ptr_type = instruction->value->value.type; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ZigType *maybe_type = ptr_type->data.pointer.child_type; - assert(maybe_type->id == TypeTableEntryIdOptional); + assert(maybe_type->id == ZigTypeIdOptional); ZigType *child_type = maybe_type->data.maybe.child_type; LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value); LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type); @@ -3612,7 +3612,7 @@ static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrI } static LLVMValueRef get_enum_tag_name_function(CodeGen *g, ZigType *enum_type) { - assert(enum_type->id == TypeTableEntryIdEnum); + assert(enum_type->id == ZigTypeIdEnum); if (enum_type->data.enumeration.name_function) return enum_type->data.enumeration.name_function; @@ -3710,7 +3710,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable IrInstructionTagName *instruction) { ZigType *enum_type = instruction->target->value.type; - assert(enum_type->id == TypeTableEntryIdEnum); + assert(enum_type->id == ZigTypeIdEnum); LLVMValueRef enum_name_function = get_enum_tag_name_function(g, enum_type); @@ -3723,7 +3723,7 @@ static LLVMValueRef ir_render_field_parent_ptr(CodeGen *g, IrExecutable *executa IrInstructionFieldParentPtr *instruction) { ZigType *container_ptr_type = instruction->base.value.type; - assert(container_ptr_type->id == TypeTableEntryIdPointer); + assert(container_ptr_type->id == ZigTypeIdPointer); ZigType *container_type = container_ptr_type->data.pointer.child_type; @@ -3760,27 +3760,27 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I uint32_t align_bytes; LLVMValueRef ptr_val; - if (target_type->id == TypeTableEntryIdPointer) { + if (target_type->id == ZigTypeIdPointer) { align_bytes = target_type->data.pointer.alignment; ptr_val = target_val; - } else if (target_type->id == TypeTableEntryIdFn) { + } else if (target_type->id == ZigTypeIdFn) { align_bytes = target_type->data.fn.fn_type_id.alignment; ptr_val = target_val; - } else if (target_type->id == TypeTableEntryIdOptional && - target_type->data.maybe.child_type->id == TypeTableEntryIdPointer) + } else if (target_type->id == ZigTypeIdOptional && + target_type->data.maybe.child_type->id == ZigTypeIdPointer) { align_bytes = target_type->data.maybe.child_type->data.pointer.alignment; ptr_val = target_val; - } else if (target_type->id == TypeTableEntryIdOptional && - target_type->data.maybe.child_type->id == TypeTableEntryIdFn) + } else if (target_type->id == ZigTypeIdOptional && + target_type->data.maybe.child_type->id == ZigTypeIdFn) { align_bytes = target_type->data.maybe.child_type->data.fn.fn_type_id.alignment; ptr_val = target_val; - } else if (target_type->id == TypeTableEntryIdOptional && - target_type->data.maybe.child_type->id == TypeTableEntryIdPromise) + } else if (target_type->id == ZigTypeIdOptional && + target_type->data.maybe.child_type->id == ZigTypeIdPromise) { zig_panic("TODO audit this function"); - } else if (target_type->id == TypeTableEntryIdStruct && target_type->data.structure.is_slice) { + } else if (target_type->id == ZigTypeIdStruct && target_type->data.structure.is_slice) { ZigType *slice_ptr_type = target_type->data.structure.fields[slice_ptr_index].type_entry; align_bytes = slice_ptr_type->data.pointer.alignment; @@ -3878,7 +3878,7 @@ static LLVMValueRef ir_render_cmpxchg(CodeGen *g, IrExecutable *executable, IrIn success_order, failure_order, instruction->is_weak); ZigType *maybe_type = instruction->base.value.type; - assert(maybe_type->id == TypeTableEntryIdOptional); + assert(maybe_type->id == ZigTypeIdOptional); ZigType *child_type = maybe_type->data.maybe.child_type; if (type_is_codegen_pointer(child_type)) { @@ -3932,7 +3932,7 @@ static LLVMValueRef ir_render_memset(CodeGen *g, IrExecutable *executable, IrIns LLVMValueRef dest_ptr_casted = LLVMBuildBitCast(g->builder, dest_ptr, ptr_u8, ""); ZigType *ptr_type = instruction->dest_ptr->value.type; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); LLVMValueRef is_volatile = ptr_type->data.pointer.is_volatile ? LLVMConstAllOnes(LLVMInt1Type()) : LLVMConstNull(LLVMInt1Type()); @@ -3964,8 +3964,8 @@ static LLVMValueRef ir_render_memcpy(CodeGen *g, IrExecutable *executable, IrIns ZigType *dest_ptr_type = instruction->dest_ptr->value.type; ZigType *src_ptr_type = instruction->src_ptr->value.type; - assert(dest_ptr_type->id == TypeTableEntryIdPointer); - assert(src_ptr_type->id == TypeTableEntryIdPointer); + assert(dest_ptr_type->id == ZigTypeIdPointer); + assert(src_ptr_type->id == ZigTypeIdPointer); LLVMValueRef is_volatile = (dest_ptr_type->data.pointer.is_volatile || src_ptr_type->data.pointer.is_volatile) ? LLVMConstAllOnes(LLVMInt1Type()) : LLVMConstNull(LLVMInt1Type()); @@ -3990,7 +3990,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst LLVMValueRef array_ptr_ptr = ir_llvm_value(g, instruction->ptr); ZigType *array_ptr_type = instruction->ptr->value.type; - assert(array_ptr_type->id == TypeTableEntryIdPointer); + assert(array_ptr_type->id == ZigTypeIdPointer); ZigType *array_type = array_ptr_type->data.pointer.child_type; LLVMValueRef array_ptr = get_handle_value(g, array_ptr_ptr, array_type, array_ptr_type); @@ -3998,10 +3998,10 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst bool want_runtime_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base); - if (array_type->id == TypeTableEntryIdArray || - (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) + if (array_type->id == ZigTypeIdArray || + (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) { - if (array_type->id == TypeTableEntryIdPointer) { + if (array_type->id == ZigTypeIdPointer) { array_type = array_type->data.pointer.child_type; } LLVMValueRef start_val = ir_llvm_value(g, instruction->start); @@ -4042,7 +4042,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst gen_store_untyped(g, len_value, len_field_ptr, 0, false); return tmp_struct_ptr; - } else if (array_type->id == TypeTableEntryIdPointer) { + } else if (array_type->id == ZigTypeIdPointer) { assert(array_type->data.pointer.ptr_len == PtrLenUnknown); LLVMValueRef start_val = ir_llvm_value(g, instruction->start); LLVMValueRef end_val = ir_llvm_value(g, instruction->end); @@ -4064,7 +4064,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst gen_store_untyped(g, len_value, len_field_ptr, 0, false); return tmp_struct_ptr; - } else if (array_type->id == TypeTableEntryIdStruct) { + } else if (array_type->id == ZigTypeIdStruct) { assert(array_type->data.structure.is_slice); assert(LLVMGetTypeKind(LLVMTypeOf(array_ptr)) == LLVMPointerTypeKind); assert(LLVMGetTypeKind(LLVMGetElementType(LLVMTypeOf(array_ptr))) == LLVMStructTypeKind); @@ -4179,7 +4179,7 @@ static LLVMValueRef ir_render_handle(CodeGen *g, IrExecutable *executable, static LLVMValueRef render_shl_with_overflow(CodeGen *g, IrInstructionOverflowOp *instruction) { ZigType *int_type = instruction->result_ptr_type; - assert(int_type->id == TypeTableEntryIdInt); + assert(int_type->id == ZigTypeIdInt); LLVMValueRef op1 = ir_llvm_value(g, instruction->op1); LLVMValueRef op2 = ir_llvm_value(g, instruction->op2); @@ -4219,7 +4219,7 @@ static LLVMValueRef ir_render_overflow_op(CodeGen *g, IrExecutable *executable, } ZigType *int_type = instruction->result_ptr_type; - assert(int_type->id == TypeTableEntryIdInt); + assert(int_type->id == ZigTypeIdInt); LLVMValueRef fn_val = get_int_overflow_fn(g, int_type, add_sub_mul); @@ -4259,7 +4259,7 @@ static LLVMValueRef ir_render_test_err(CodeGen *g, IrExecutable *executable, IrI static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrCode *instruction) { ZigType *ptr_type = instruction->value->value.type; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ZigType *err_union_type = ptr_type->data.pointer.child_type; ZigType *payload_type = err_union_type->data.error_union.payload_type; LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value); @@ -4275,7 +4275,7 @@ static LLVMValueRef ir_render_unwrap_err_code(CodeGen *g, IrExecutable *executab static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *executable, IrInstructionUnwrapErrPayload *instruction) { ZigType *ptr_type = instruction->value->value.type; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ZigType *err_union_type = ptr_type->data.pointer.child_type; ZigType *payload_type = err_union_type->data.error_union.payload_type; LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value); @@ -4315,7 +4315,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, IrInstructionOptionalWrap *instruction) { ZigType *wanted_type = instruction->base.value.type; - assert(wanted_type->id == TypeTableEntryIdOptional); + assert(wanted_type->id == ZigTypeIdOptional); ZigType *child_type = wanted_type->data.maybe.child_type; @@ -4342,7 +4342,7 @@ static LLVMValueRef ir_render_maybe_wrap(CodeGen *g, IrExecutable *executable, I static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapCode *instruction) { ZigType *wanted_type = instruction->base.value.type; - assert(wanted_type->id == TypeTableEntryIdErrorUnion); + assert(wanted_type->id == ZigTypeIdErrorUnion); ZigType *payload_type = wanted_type->data.error_union.payload_type; ZigType *err_set_type = wanted_type->data.error_union.err_set_type; @@ -4363,7 +4363,7 @@ static LLVMValueRef ir_render_err_wrap_code(CodeGen *g, IrExecutable *executable static LLVMValueRef ir_render_err_wrap_payload(CodeGen *g, IrExecutable *executable, IrInstructionErrWrapPayload *instruction) { ZigType *wanted_type = instruction->base.value.type; - assert(wanted_type->id == TypeTableEntryIdErrorUnion); + assert(wanted_type->id == ZigTypeIdErrorUnion); ZigType *payload_type = wanted_type->data.error_union.payload_type; ZigType *err_set_type = wanted_type->data.error_union.err_set_type; @@ -4471,7 +4471,7 @@ static LLVMValueRef ir_render_container_init_list(CodeGen *g, IrExecutable *exec IrInstructionContainerInitList *instruction) { ZigType *array_type = instruction->base.value.type; - assert(array_type->id == TypeTableEntryIdArray); + assert(array_type->id == ZigTypeIdArray); LLVMValueRef tmp_array_ptr = instruction->tmp_ptr; assert(tmp_array_ptr); @@ -4605,7 +4605,7 @@ static LLVMValueRef get_coro_alloc_helper_fn_val(CodeGen *g, LLVMTypeRef alloc_f if (g->coro_alloc_helper_fn_val != nullptr) return g->coro_alloc_helper_fn_val; - assert(fn_type->id == TypeTableEntryIdFn); + assert(fn_type->id == ZigTypeIdFn); ZigType *ptr_to_err_code_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false); @@ -4734,7 +4734,7 @@ static LLVMValueRef ir_render_atomic_rmw(CodeGen *g, IrExecutable *executable, { bool is_signed; ZigType *operand_type = instruction->operand->value.type; - if (operand_type->id == TypeTableEntryIdInt) { + if (operand_type->id == ZigTypeIdInt) { is_signed = operand_type->data.integral.is_signed; } else { is_signed = false; @@ -4789,7 +4789,7 @@ static LLVMValueRef ir_render_mark_err_ret_trace_ptr(CodeGen *g, IrExecutable *e static LLVMValueRef ir_render_sqrt(CodeGen *g, IrExecutable *executable, IrInstructionSqrt *instruction) { LLVMValueRef op = ir_llvm_value(g, instruction->op); - assert(instruction->base.value.type->id == TypeTableEntryIdFloat); + assert(instruction->base.value.type->id == ZigTypeIdFloat); LLVMValueRef fn_val = get_float_fn(g, instruction->base.value.type, ZigLLVMFnIdSqrt); return LLVMBuildCall(g->builder, fn_val, &op, 1, ""); } @@ -5146,56 +5146,56 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con ZigType *type_entry = const_val->type; assert(!type_entry->zero_bits); switch (type_entry->id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdVoid: - case TypeTableEntryIdOpaque: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdVoid: + case ZigTypeIdOpaque: zig_unreachable(); - case TypeTableEntryIdBool: + case ZigTypeIdBool: return LLVMConstInt(big_int_type_ref, const_val->data.x_bool ? 1 : 0, false); - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: { assert(type_entry->data.enumeration.decl_node->data.container_decl.init_arg_expr != nullptr); LLVMValueRef int_val = gen_const_val(g, const_val, ""); return LLVMConstZExt(int_val, big_int_type_ref); } - case TypeTableEntryIdInt: + case ZigTypeIdInt: { LLVMValueRef int_val = gen_const_val(g, const_val, ""); return LLVMConstZExt(int_val, big_int_type_ref); } - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: { LLVMValueRef float_val = gen_const_val(g, const_val, ""); LLVMValueRef int_val = LLVMConstFPToUI(float_val, LLVMIntType((unsigned)type_entry->data.floating.bit_count)); return LLVMConstZExt(int_val, big_int_type_ref); } - case TypeTableEntryIdPointer: - case TypeTableEntryIdFn: - case TypeTableEntryIdOptional: - case TypeTableEntryIdPromise: + case ZigTypeIdPointer: + case ZigTypeIdFn: + case ZigTypeIdOptional: + case ZigTypeIdPromise: { LLVMValueRef ptr_val = gen_const_val(g, const_val, ""); LLVMValueRef ptr_size_int_val = LLVMConstPtrToInt(ptr_val, g->builtin_types.entry_usize->type_ref); return LLVMConstZExt(ptr_size_int_val, big_int_type_ref); } - case TypeTableEntryIdArray: + case ZigTypeIdArray: zig_panic("TODO bit pack an array"); - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: zig_panic("TODO bit pack a union"); - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: { assert(type_entry->data.structure.layout == ContainerLayoutPacked); bool is_big_endian = g->is_big_endian; // TODO get endianness from struct type @@ -5253,7 +5253,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con render_const_val_global(g, const_val, name); ConstExprValue *array_const_val = const_val->data.x_ptr.data.base_array.array_val; size_t elem_index = const_val->data.x_ptr.data.base_array.elem_index; - assert(array_const_val->type->id == TypeTableEntryIdArray); + assert(array_const_val->type->id == ZigTypeIdArray); if (array_const_val->type->zero_bits) { // make this a null pointer ZigType *usize = g->builtin_types.entry_usize; @@ -5273,7 +5273,7 @@ static LLVMValueRef gen_const_val_ptr(CodeGen *g, ConstExprValue *const_val, con { render_const_val_global(g, const_val, name); ConstExprValue *struct_const_val = const_val->data.x_ptr.data.base_struct.struct_val; - assert(struct_const_val->type->id == TypeTableEntryIdStruct); + assert(struct_const_val->type->id == ZigTypeIdStruct); if (struct_const_val->type->zero_bits) { // make this a null pointer ZigType *usize = g->builtin_types.entry_usize; @@ -5322,13 +5322,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c } switch (type_entry->id) { - case TypeTableEntryIdInt: + case ZigTypeIdInt: return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_bigint); - case TypeTableEntryIdErrorSet: + case ZigTypeIdErrorSet: assert(const_val->data.x_err_set != nullptr); return LLVMConstInt(g->builtin_types.entry_global_error_set->type_ref, const_val->data.x_err_set->value, false); - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: switch (type_entry->data.floating.bit_count) { case 16: return LLVMConstReal(type_entry->type_ref, zig_f16_to_double(const_val->data.x_f16)); @@ -5348,13 +5348,13 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c default: zig_unreachable(); } - case TypeTableEntryIdBool: + case ZigTypeIdBool: if (const_val->data.x_bool) { return LLVMConstAllOnes(LLVMInt1Type()); } else { return LLVMConstNull(LLVMInt1Type()); } - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: { ZigType *child_type = type_entry->data.maybe.child_type; if (child_type->zero_bits) { @@ -5387,7 +5387,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c } } } - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: { LLVMValueRef *fields = allocate(type_entry->data.structure.gen_field_count); size_t src_field_count = type_entry->data.structure.src_field_count; @@ -5463,7 +5463,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c return LLVMConstNamedStruct(type_entry->type_ref, fields, type_entry->data.structure.gen_field_count); } } - case TypeTableEntryIdArray: + case ZigTypeIdArray: { uint64_t len = type_entry->data.array.len; if (const_val->data.x_array.special == ConstArraySpecialUndef) { @@ -5485,7 +5485,7 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c return LLVMConstArray(element_type_ref, values, (unsigned)len); } } - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: { LLVMTypeRef union_type_ref = type_entry->data.unionation.union_type_ref; @@ -5549,15 +5549,15 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c } - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: return bigint_to_llvm_const(type_entry->type_ref, &const_val->data.x_enum_tag); - case TypeTableEntryIdFn: + case ZigTypeIdFn: assert(const_val->data.x_ptr.special == ConstPtrSpecialFunction); assert(const_val->data.x_ptr.mut == ConstPtrMutComptimeConst); return fn_llvm_value(g, const_val->data.x_ptr.data.fn.fn_entry); - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: return gen_const_val_ptr(g, const_val, name); - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: { ZigType *payload_type = type_entry->data.error_union.payload_type; ZigType *err_set_type = type_entry->data.error_union.err_set_type; @@ -5593,21 +5593,21 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c } } } - case TypeTableEntryIdVoid: + case ZigTypeIdVoid: return nullptr; - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdPromise: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: + case ZigTypeIdPromise: zig_unreachable(); } @@ -5790,7 +5790,7 @@ static void do_code_gen(CodeGen *g) { TldVar *tld_var = g->global_vars.at(i); ZigVar *var = tld_var->var; - if (var->value->type->id == TypeTableEntryIdComptimeFloat) { + if (var->value->type->id == ZigTypeIdComptimeFloat) { // Generate debug info for it but that's it. ConstExprValue *const_val = var->value; assert(const_val->special != ConstValSpecialRuntime); @@ -5804,7 +5804,7 @@ static void do_code_gen(CodeGen *g) { continue; } - if (var->value->type->id == TypeTableEntryIdComptimeInt) { + if (var->value->type->id == ZigTypeIdComptimeInt) { // Generate debug info for it but that's it. ConstExprValue *const_val = var->value; assert(const_val->special != ConstValSpecialRuntime); @@ -5852,7 +5852,7 @@ static void do_code_gen(CodeGen *g) { LLVMSetAlignment(global_value, var->align_bytes); // TODO debug info for function pointers - if (var->gen_is_const && var->value->type->id != TypeTableEntryIdFn) { + if (var->gen_is_const && var->value->type->id != ZigTypeIdFn) { gen_global_var(g, var, var->value->global_refs->llvm_value, var->value->type); } @@ -5910,7 +5910,7 @@ static void do_code_gen(CodeGen *g) { } else if (instruction->id == IrInstructionIdRef) { IrInstructionRef *ref_instruction = (IrInstructionRef *)instruction; slot = &ref_instruction->tmp_ptr; - assert(instruction->value.type->id == TypeTableEntryIdPointer); + assert(instruction->value.type->id == ZigTypeIdPointer); slot_type = instruction->value.type->data.pointer.child_type; } else if (instruction->id == IrInstructionIdContainerInitList) { IrInstructionContainerInitList *container_init_list_instruction = (IrInstructionContainerInitList *)instruction; @@ -6173,51 +6173,51 @@ static const GlobalLinkageValue global_linkage_values[] = { static void define_builtin_types(CodeGen *g) { { // if this type is anywhere in the AST, we should never hit codegen. - ZigType *entry = new_type_table_entry(TypeTableEntryIdInvalid); + ZigType *entry = new_type_table_entry(ZigTypeIdInvalid); buf_init_from_str(&entry->name, "(invalid)"); entry->zero_bits = true; g->builtin_types.entry_invalid = entry; } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdNamespace); + ZigType *entry = new_type_table_entry(ZigTypeIdNamespace); buf_init_from_str(&entry->name, "(namespace)"); entry->zero_bits = true; g->builtin_types.entry_namespace = entry; } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdBlock); + ZigType *entry = new_type_table_entry(ZigTypeIdBlock); buf_init_from_str(&entry->name, "(block)"); entry->zero_bits = true; g->builtin_types.entry_block = entry; } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdComptimeFloat); + ZigType *entry = new_type_table_entry(ZigTypeIdComptimeFloat); buf_init_from_str(&entry->name, "comptime_float"); entry->zero_bits = true; g->builtin_types.entry_num_lit_float = entry; g->primitive_type_table.put(&entry->name, entry); } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdComptimeInt); + ZigType *entry = new_type_table_entry(ZigTypeIdComptimeInt); buf_init_from_str(&entry->name, "comptime_int"); entry->zero_bits = true; g->builtin_types.entry_num_lit_int = entry; g->primitive_type_table.put(&entry->name, entry); } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdUndefined); + ZigType *entry = new_type_table_entry(ZigTypeIdUndefined); buf_init_from_str(&entry->name, "(undefined)"); entry->zero_bits = true; g->builtin_types.entry_undef = entry; } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdNull); + ZigType *entry = new_type_table_entry(ZigTypeIdNull); buf_init_from_str(&entry->name, "(null)"); entry->zero_bits = true; g->builtin_types.entry_null = entry; } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdArgTuple); + ZigType *entry = new_type_table_entry(ZigTypeIdArgTuple); buf_init_from_str(&entry->name, "(args)"); entry->zero_bits = true; g->builtin_types.entry_arg_tuple = entry; @@ -6228,7 +6228,7 @@ static void define_builtin_types(CodeGen *g) { uint32_t size_in_bits = target_c_type_size_in_bits(&g->zig_target, info->id); bool is_signed = info->is_signed; - ZigType *entry = new_type_table_entry(TypeTableEntryIdInt); + ZigType *entry = new_type_table_entry(ZigTypeIdInt); entry->type_ref = LLVMIntType(size_in_bits); buf_init_from_str(&entry->name, info->name); @@ -6245,7 +6245,7 @@ static void define_builtin_types(CodeGen *g) { } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdBool); + ZigType *entry = new_type_table_entry(ZigTypeIdBool); entry->type_ref = LLVMInt1Type(); buf_init_from_str(&entry->name, "bool"); uint64_t debug_size_in_bits = 8*LLVMStoreSizeOfType(g->target_data_ref, entry->type_ref); @@ -6259,7 +6259,7 @@ static void define_builtin_types(CodeGen *g) { for (size_t sign_i = 0; sign_i < array_length(is_signed_list); sign_i += 1) { bool is_signed = is_signed_list[sign_i]; - ZigType *entry = new_type_table_entry(TypeTableEntryIdInt); + ZigType *entry = new_type_table_entry(ZigTypeIdInt); entry->type_ref = LLVMIntType(g->pointer_size_bytes * 8); const char u_or_i = is_signed ? 'i' : 'u'; @@ -6287,7 +6287,7 @@ static void define_builtin_types(CodeGen *g) { uint32_t bit_count, LLVMTypeRef type_ref, ZigType **field) { - ZigType *entry = new_type_table_entry(TypeTableEntryIdFloat); + ZigType *entry = new_type_table_entry(ZigTypeIdFloat); entry->type_ref = type_ref; buf_init_from_str(&entry->name, name); entry->data.floating.bit_count = bit_count; @@ -6306,7 +6306,7 @@ static void define_builtin_types(CodeGen *g) { add_fp_entry(g, "c_longdouble", 80, LLVMX86FP80Type(), &g->builtin_types.entry_c_longdouble); { - ZigType *entry = new_type_table_entry(TypeTableEntryIdVoid); + ZigType *entry = new_type_table_entry(ZigTypeIdVoid); entry->type_ref = LLVMVoidType(); entry->zero_bits = true; buf_init_from_str(&entry->name, "void"); @@ -6317,7 +6317,7 @@ static void define_builtin_types(CodeGen *g) { g->primitive_type_table.put(&entry->name, entry); } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdUnreachable); + ZigType *entry = new_type_table_entry(ZigTypeIdUnreachable); entry->type_ref = LLVMVoidType(); entry->zero_bits = true; buf_init_from_str(&entry->name, "noreturn"); @@ -6326,7 +6326,7 @@ static void define_builtin_types(CodeGen *g) { g->primitive_type_table.put(&entry->name, entry); } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdMetaType); + ZigType *entry = new_type_table_entry(ZigTypeIdMetaType); buf_init_from_str(&entry->name, "type"); entry->zero_bits = true; g->builtin_types.entry_type = entry; @@ -6348,7 +6348,7 @@ static void define_builtin_types(CodeGen *g) { } { - ZigType *entry = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *entry = new_type_table_entry(ZigTypeIdErrorSet); buf_init_from_str(&entry->name, "error"); entry->data.error_set.err_count = UINT32_MAX; @@ -7226,57 +7226,57 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, ZigType *type_e type_entry->gen_h_loop_flag = true; switch (type_entry->id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdPromise: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdPromise: zig_unreachable(); - case TypeTableEntryIdVoid: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: + case ZigTypeIdVoid: + case ZigTypeIdUnreachable: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: return; - case TypeTableEntryIdOpaque: + case ZigTypeIdOpaque: gen_h->types_to_declare.append(type_entry); return; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) { TypeStructField *field = &type_entry->data.structure.fields[i]; prepend_c_type_to_decl_list(g, gen_h, field->type_entry); } gen_h->types_to_declare.append(type_entry); return; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) { TypeUnionField *field = &type_entry->data.unionation.fields[i]; prepend_c_type_to_decl_list(g, gen_h, field->type_entry); } gen_h->types_to_declare.append(type_entry); return; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: prepend_c_type_to_decl_list(g, gen_h, type_entry->data.enumeration.tag_int_type); gen_h->types_to_declare.append(type_entry); return; - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: prepend_c_type_to_decl_list(g, gen_h, type_entry->data.pointer.child_type); return; - case TypeTableEntryIdArray: + case ZigTypeIdArray: prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type); return; - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type); return; - case TypeTableEntryIdFn: + case ZigTypeIdFn: for (size_t i = 0; i < type_entry->data.fn.fn_type_id.param_count; i += 1) { prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.param_info[i].type); } @@ -7316,17 +7316,17 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu prepend_c_type_to_decl_list(g, gen_h, type_entry); switch (type_entry->id) { - case TypeTableEntryIdVoid: + case ZigTypeIdVoid: buf_init_from_str(out_buf, "void"); break; - case TypeTableEntryIdBool: + case ZigTypeIdBool: buf_init_from_str(out_buf, "bool"); g->c_want_stdbool = true; break; - case TypeTableEntryIdUnreachable: + case ZigTypeIdUnreachable: buf_init_from_str(out_buf, "__attribute__((__noreturn__)) void"); break; - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: switch (type_entry->data.floating.bit_count) { case 32: buf_init_from_str(out_buf, "float"); @@ -7344,14 +7344,14 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu zig_unreachable(); } break; - case TypeTableEntryIdInt: + case ZigTypeIdInt: g->c_want_stdint = true; buf_resize(out_buf, 0); buf_appendf(out_buf, "%sint%" PRIu32 "_t", type_entry->data.integral.is_signed ? "" : "u", type_entry->data.integral.bit_count); break; - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: { Buf child_buf = BUF_INIT; ZigType *child_type = type_entry->data.pointer.child_type; @@ -7362,7 +7362,7 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu buf_appendf(out_buf, "%s%s *", const_str, buf_ptr(&child_buf)); break; } - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: { ZigType *child_type = type_entry->data.maybe.child_type; if (child_type->zero_bits) { @@ -7374,28 +7374,28 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu zig_unreachable(); } } - case TypeTableEntryIdStruct: - case TypeTableEntryIdOpaque: + case ZigTypeIdStruct: + case ZigTypeIdOpaque: { buf_init_from_str(out_buf, "struct "); buf_append_buf(out_buf, &type_entry->name); return; } - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: { buf_init_from_str(out_buf, "union "); buf_append_buf(out_buf, &type_entry->name); return; } - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: { buf_init_from_str(out_buf, "enum "); buf_append_buf(out_buf, &type_entry->name); return; } - case TypeTableEntryIdArray: + case ZigTypeIdArray: { - TypeTableEntryArray *array_data = &type_entry->data.array; + ZigTypeArray *array_data = &type_entry->data.array; Buf *child_buf = buf_alloc(); get_c_type(g, gen_h, array_data->child_type, child_buf); @@ -7404,21 +7404,21 @@ static void get_c_type(CodeGen *g, GenH *gen_h, ZigType *type_entry, Buf *out_bu buf_appendf(out_buf, "%s", buf_ptr(child_buf)); return; } - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdFn: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdFn: zig_panic("TODO implement get_c_type for more types"); - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdPromise: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdBoundFn: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdArgTuple: + case ZigTypeIdPromise: zig_unreachable(); } } @@ -7509,7 +7509,7 @@ static void gen_h_file(CodeGen *g) { const char *restrict_str = param_info->is_noalias ? "restrict" : ""; get_c_type(g, gen_h, param_info->type, ¶m_type_c); - if (param_info->type->id == TypeTableEntryIdArray) { + if (param_info->type->id == ZigTypeIdArray) { // Arrays decay to pointers buf_appendf(&h_buf, "%s%s%s %s[]", comma_str, buf_ptr(¶m_type_c), restrict_str, buf_ptr(param_name)); @@ -7557,30 +7557,30 @@ static void gen_h_file(CodeGen *g) { for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) { ZigType *type_entry = gen_h->types_to_declare.at(type_i); switch (type_entry->id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdArray: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOptional: - case TypeTableEntryIdFn: - case TypeTableEntryIdPromise: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdArray: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOptional: + case ZigTypeIdFn: + case ZigTypeIdPromise: zig_unreachable(); - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: if (type_entry->data.enumeration.layout == ContainerLayoutExtern) { fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name)); for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) { @@ -7598,7 +7598,7 @@ static void gen_h_file(CodeGen *g) { fprintf(out_h, "enum %s;\n", buf_ptr(&type_entry->name)); } break; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: if (type_entry->data.structure.layout == ContainerLayoutExtern) { fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name)); for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) { @@ -7607,7 +7607,7 @@ static void gen_h_file(CodeGen *g) { Buf *type_name_buf = buf_alloc(); get_c_type(g, gen_h, struct_field->type_entry, type_name_buf); - if (struct_field->type_entry->id == TypeTableEntryIdArray) { + if (struct_field->type_entry->id == ZigTypeIdArray) { fprintf(out_h, " %s %s[%" ZIG_PRI_u64 "];\n", buf_ptr(type_name_buf), buf_ptr(struct_field->name), struct_field->type_entry->data.array.len); @@ -7621,7 +7621,7 @@ static void gen_h_file(CodeGen *g) { fprintf(out_h, "struct %s;\n", buf_ptr(&type_entry->name)); } break; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: if (type_entry->data.unionation.layout == ContainerLayoutExtern) { fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name)); for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) { @@ -7636,7 +7636,7 @@ static void gen_h_file(CodeGen *g) { fprintf(out_h, "union %s;\n", buf_ptr(&type_entry->name)); } break; - case TypeTableEntryIdOpaque: + case ZigTypeIdOpaque: fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name)); break; } diff --git a/src/ir.cpp b/src/ir.cpp index 6be1638d5b..c9ce0d3be3 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -198,7 +198,7 @@ static bool types_have_same_zig_comptime_repr(ZigType *a, ZigType *b) { ConstExprValue *const_ptr_pointee(CodeGen *g, ConstExprValue *const_val) { ConstExprValue *result = const_ptr_pointee_unchecked(g, const_val); - if (const_val->type->id == TypeTableEntryIdPointer) { + if (const_val->type->id == ZigTypeIdPointer) { assert(types_have_same_zig_comptime_repr(const_val->type->data.pointer.child_type, result->type)); } return result; @@ -253,7 +253,7 @@ static bool instr_is_comptime(IrInstruction *instruction) { } static bool instr_is_unreachable(IrInstruction *instruction) { - return instruction->value.type && instruction->value.type->id == TypeTableEntryIdUnreachable; + return instruction->value.type && instruction->value.type->id == ZigTypeIdUnreachable; } static void ir_link_new_instruction(IrInstruction *new_instruction, IrInstruction *old_instruction) { @@ -3072,7 +3072,7 @@ static bool ir_gen_defers_for_block(IrBuilder *irb, Scope *inner_scope, Scope *o Scope *defer_expr_scope = defer_node->data.defer.expr_scope; IrInstruction *defer_expr_value = ir_gen_node(irb, defer_expr_node, defer_expr_scope); if (defer_expr_value != irb->codegen->invalid_instruction) { - if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == TypeTableEntryIdUnreachable) { + if (defer_expr_value->value.type != nullptr && defer_expr_value->value.type->id == ZigTypeIdUnreachable) { is_noreturn = true; } else { ir_mark_gen(ir_build_check_statement_is_void(irb, defer_expr_scope, defer_expr_node, defer_expr_value)); @@ -6587,10 +6587,10 @@ static IrInstruction *ir_gen_container_decl(IrBuilder *irb, Scope *parent_scope, // errors should be populated with set1's values static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigType *set1, ZigType *set2) { - assert(set1->id == TypeTableEntryIdErrorSet); - assert(set2->id == TypeTableEntryIdErrorSet); + assert(set1->id == ZigTypeIdErrorSet); + assert(set2->id == ZigTypeIdErrorSet); - ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); buf_resize(&err_set_type->name, 0); buf_appendf(&err_set_type->name, "error{"); @@ -6642,7 +6642,7 @@ static ZigType *get_error_set_union(CodeGen *g, ErrorTableEntry **errors, ZigTyp static ZigType *make_err_set_with_one_item(CodeGen *g, Scope *parent_scope, AstNode *node, ErrorTableEntry *err_entry) { - ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); buf_resize(&err_set_type->name, 0); buf_appendf(&err_set_type->name, "error{%s}", buf_ptr(&err_entry->name)); err_set_type->is_copyable = true; @@ -6664,7 +6664,7 @@ static IrInstruction *ir_gen_err_set_decl(IrBuilder *irb, Scope *parent_scope, A uint32_t err_count = node->data.err_set_decl.decls.length; Buf *type_name = get_anon_type_name(irb->codegen, irb->exec, "error set", node); - ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); buf_init_from_buf(&err_set_type->name, type_name); err_set_type->is_copyable = true; err_set_type->data.error_set.err_count = err_count; @@ -7628,7 +7628,7 @@ static ErrorMsg *ir_add_error(IrAnalyze *ira, IrInstruction *source_instruction, static ConstExprValue *ir_const_ptr_pointee(IrAnalyze *ira, ConstExprValue *const_val, AstNode *source_node) { ConstExprValue *val = const_ptr_pointee_unchecked(ira->codegen, const_val); assert(val != nullptr); - assert(const_val->type->id == TypeTableEntryIdPointer); + assert(const_val->type->id == ZigTypeIdPointer); ZigType *expected_type = const_val->type->data.pointer.child_type; if (!types_have_same_zig_comptime_repr(val->type, expected_type)) { ir_add_error_node(ira, source_node, @@ -7669,16 +7669,16 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so } static bool const_val_fits_in_num_lit(ConstExprValue *const_val, ZigType *num_lit_type) { - return ((num_lit_type->id == TypeTableEntryIdComptimeFloat && - (const_val->type->id == TypeTableEntryIdFloat || const_val->type->id == TypeTableEntryIdComptimeFloat)) || - (num_lit_type->id == TypeTableEntryIdComptimeInt && - (const_val->type->id == TypeTableEntryIdInt || const_val->type->id == TypeTableEntryIdComptimeInt))); + return ((num_lit_type->id == ZigTypeIdComptimeFloat && + (const_val->type->id == ZigTypeIdFloat || const_val->type->id == ZigTypeIdComptimeFloat)) || + (num_lit_type->id == ZigTypeIdComptimeInt && + (const_val->type->id == ZigTypeIdInt || const_val->type->id == ZigTypeIdComptimeInt))); } static bool float_has_fraction(ConstExprValue *const_val) { - if (const_val->type->id == TypeTableEntryIdComptimeFloat) { + if (const_val->type->id == ZigTypeIdComptimeFloat) { return bigfloat_has_fraction(&const_val->data.x_bigfloat); - } else if (const_val->type->id == TypeTableEntryIdFloat) { + } else if (const_val->type->id == ZigTypeIdFloat) { switch (const_val->type->data.floating.bit_count) { case 16: { @@ -7704,9 +7704,9 @@ static bool float_has_fraction(ConstExprValue *const_val) { } static void float_append_buf(Buf *buf, ConstExprValue *const_val) { - if (const_val->type->id == TypeTableEntryIdComptimeFloat) { + if (const_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_append_buf(buf, &const_val->data.x_bigfloat); - } else if (const_val->type->id == TypeTableEntryIdFloat) { + } else if (const_val->type->id == ZigTypeIdFloat) { switch (const_val->type->data.floating.bit_count) { case 16: buf_appendf(buf, "%f", zig_f16_to_double(const_val->data.x_f16)); @@ -7742,9 +7742,9 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) { } static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { - if (const_val->type->id == TypeTableEntryIdComptimeFloat) { + if (const_val->type->id == ZigTypeIdComptimeFloat) { bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat); - } else if (const_val->type->id == TypeTableEntryIdFloat) { + } else if (const_val->type->id == ZigTypeIdFloat) { switch (const_val->type->data.floating.bit_count) { case 16: { @@ -7789,9 +7789,9 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { } static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { - if (dest_val->type->id == TypeTableEntryIdComptimeFloat) { + if (dest_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat); - } else if (dest_val->type->id == TypeTableEntryIdFloat) { + } else if (dest_val->type->id == ZigTypeIdFloat) { switch (dest_val->type->data.floating.bit_count) { case 16: dest_val->data.x_f16 = bigfloat_to_f16(bigfloat); @@ -7814,9 +7814,9 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { } static void float_init_f16(ConstExprValue *dest_val, float16_t x) { - if (dest_val->type->id == TypeTableEntryIdComptimeFloat) { + if (dest_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_init_16(&dest_val->data.x_bigfloat, x); - } else if (dest_val->type->id == TypeTableEntryIdFloat) { + } else if (dest_val->type->id == ZigTypeIdFloat) { switch (dest_val->type->data.floating.bit_count) { case 16: dest_val->data.x_f16 = x; @@ -7839,9 +7839,9 @@ static void float_init_f16(ConstExprValue *dest_val, float16_t x) { } static void float_init_f32(ConstExprValue *dest_val, float x) { - if (dest_val->type->id == TypeTableEntryIdComptimeFloat) { + if (dest_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_init_32(&dest_val->data.x_bigfloat, x); - } else if (dest_val->type->id == TypeTableEntryIdFloat) { + } else if (dest_val->type->id == ZigTypeIdFloat) { switch (dest_val->type->data.floating.bit_count) { case 16: dest_val->data.x_f16 = zig_double_to_f16(x); @@ -7868,9 +7868,9 @@ static void float_init_f32(ConstExprValue *dest_val, float x) { } static void float_init_f64(ConstExprValue *dest_val, double x) { - if (dest_val->type->id == TypeTableEntryIdComptimeFloat) { + if (dest_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_init_64(&dest_val->data.x_bigfloat, x); - } else if (dest_val->type->id == TypeTableEntryIdFloat) { + } else if (dest_val->type->id == ZigTypeIdFloat) { switch (dest_val->type->data.floating.bit_count) { case 16: dest_val->data.x_f16 = zig_double_to_f16(x); @@ -7897,9 +7897,9 @@ static void float_init_f64(ConstExprValue *dest_val, double x) { } static void float_init_f128(ConstExprValue *dest_val, float128_t x) { - if (dest_val->type->id == TypeTableEntryIdComptimeFloat) { + if (dest_val->type->id == ZigTypeIdComptimeFloat) { bigfloat_init_128(&dest_val->data.x_bigfloat, x); - } else if (dest_val->type->id == TypeTableEntryIdFloat) { + } else if (dest_val->type->id == ZigTypeIdFloat) { switch (dest_val->type->data.floating.bit_count) { case 16: dest_val->data.x_f16 = f128M_to_f16(&x); @@ -7930,9 +7930,9 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) { } static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) { - if (src_val->type->id == TypeTableEntryIdComptimeFloat) { + if (src_val->type->id == ZigTypeIdComptimeFloat) { float_init_bigfloat(dest_val, &src_val->data.x_bigfloat); - } else if (src_val->type->id == TypeTableEntryIdFloat) { + } else if (src_val->type->id == ZigTypeIdFloat) { switch (src_val->type->data.floating.bit_count) { case 16: float_init_f16(dest_val, src_val->data.x_f16); @@ -7956,9 +7956,9 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { assert(op1->type == op2->type); - if (op1->type->id == TypeTableEntryIdComptimeFloat) { + if (op1->type->id == ZigTypeIdComptimeFloat) { return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat); - } else if (op1->type->id == TypeTableEntryIdFloat) { + } else if (op1->type->id == ZigTypeIdFloat) { switch (op1->type->data.floating.bit_count) { case 16: if (f16_lt(op1->data.x_f16, op2->data.x_f16)) { @@ -8001,9 +8001,9 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { } static Cmp float_cmp_zero(ConstExprValue *op) { - if (op->type->id == TypeTableEntryIdComptimeFloat) { + if (op->type->id == ZigTypeIdComptimeFloat) { return bigfloat_cmp_zero(&op->data.x_bigfloat); - } else if (op->type->id == TypeTableEntryIdFloat) { + } else if (op->type->id == ZigTypeIdFloat) { switch (op->type->data.floating.bit_count) { case 16: { @@ -8053,9 +8053,9 @@ static Cmp float_cmp_zero(ConstExprValue *op) { static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; - if (op1->type->id == TypeTableEntryIdComptimeFloat) { + if (op1->type->id == ZigTypeIdComptimeFloat) { bigfloat_add(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); - } else if (op1->type->id == TypeTableEntryIdFloat) { + } else if (op1->type->id == ZigTypeIdFloat) { switch (op1->type->data.floating.bit_count) { case 16: out_val->data.x_f16 = f16_add(op1->data.x_f16, op2->data.x_f16); @@ -8080,9 +8080,9 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; - if (op1->type->id == TypeTableEntryIdComptimeFloat) { + if (op1->type->id == ZigTypeIdComptimeFloat) { bigfloat_sub(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); - } else if (op1->type->id == TypeTableEntryIdFloat) { + } else if (op1->type->id == ZigTypeIdFloat) { switch (op1->type->data.floating.bit_count) { case 16: out_val->data.x_f16 = f16_sub(op1->data.x_f16, op2->data.x_f16); @@ -8107,9 +8107,9 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; - if (op1->type->id == TypeTableEntryIdComptimeFloat) { + if (op1->type->id == ZigTypeIdComptimeFloat) { bigfloat_mul(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); - } else if (op1->type->id == TypeTableEntryIdFloat) { + } else if (op1->type->id == ZigTypeIdFloat) { switch (op1->type->data.floating.bit_count) { case 16: out_val->data.x_f16 = f16_mul(op1->data.x_f16, op2->data.x_f16); @@ -8134,9 +8134,9 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; - if (op1->type->id == TypeTableEntryIdComptimeFloat) { + if (op1->type->id == ZigTypeIdComptimeFloat) { bigfloat_div(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); - } else if (op1->type->id == TypeTableEntryIdFloat) { + } else if (op1->type->id == ZigTypeIdFloat) { switch (op1->type->data.floating.bit_count) { case 16: out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16); @@ -8161,9 +8161,9 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; - if (op1->type->id == TypeTableEntryIdComptimeFloat) { + if (op1->type->id == ZigTypeIdComptimeFloat) { bigfloat_div_trunc(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); - } else if (op1->type->id == TypeTableEntryIdFloat) { + } else if (op1->type->id == ZigTypeIdFloat) { switch (op1->type->data.floating.bit_count) { case 16: out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16); @@ -8190,9 +8190,9 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; - if (op1->type->id == TypeTableEntryIdComptimeFloat) { + if (op1->type->id == ZigTypeIdComptimeFloat) { bigfloat_div_floor(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); - } else if (op1->type->id == TypeTableEntryIdFloat) { + } else if (op1->type->id == ZigTypeIdFloat) { switch (op1->type->data.floating.bit_count) { case 16: out_val->data.x_f16 = f16_div(op1->data.x_f16, op2->data.x_f16); @@ -8219,9 +8219,9 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; - if (op1->type->id == TypeTableEntryIdComptimeFloat) { + if (op1->type->id == ZigTypeIdComptimeFloat) { bigfloat_rem(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); - } else if (op1->type->id == TypeTableEntryIdFloat) { + } else if (op1->type->id == ZigTypeIdFloat) { switch (op1->type->data.floating.bit_count) { case 16: out_val->data.x_f16 = f16_rem(op1->data.x_f16, op2->data.x_f16); @@ -8264,9 +8264,9 @@ static void zig_f128M_mod(const float128_t* a, const float128_t* b, float128_t* static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { assert(op1->type == op2->type); out_val->type = op1->type; - if (op1->type->id == TypeTableEntryIdComptimeFloat) { + if (op1->type->id == ZigTypeIdComptimeFloat) { bigfloat_mod(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); - } else if (op1->type->id == TypeTableEntryIdFloat) { + } else if (op1->type->id == ZigTypeIdFloat) { switch (op1->type->data.floating.bit_count) { case 16: out_val->data.x_f16 = zig_f16_mod(op1->data.x_f16, op2->data.x_f16); @@ -8290,9 +8290,9 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { out_val->type = op->type; - if (op->type->id == TypeTableEntryIdComptimeFloat) { + if (op->type->id == ZigTypeIdComptimeFloat) { bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat); - } else if (op->type->id == TypeTableEntryIdFloat) { + } else if (op->type->id == ZigTypeIdFloat) { switch (op->type->data.floating.bit_count) { case 16: { @@ -8320,7 +8320,7 @@ static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { } void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) { - if (op->type->id == TypeTableEntryIdFloat) { + if (op->type->id == ZigTypeIdFloat) { switch (op->type->data.floating.bit_count) { case 16: memcpy(buf, &op->data.x_f16, 2); // TODO wrong when compiler is big endian @@ -8343,7 +8343,7 @@ void float_write_ieee597(ConstExprValue *op, uint8_t *buf, bool is_big_endian) { } void float_read_ieee597(ConstExprValue *val, uint8_t *buf, bool is_big_endian) { - if (val->type->id == TypeTableEntryIdFloat) { + if (val->type->id == ZigTypeIdFloat) { switch (val->type->data.floating.bit_count) { case 16: memcpy(&val->data.x_f16, buf, 2); // TODO wrong when compiler is big endian @@ -8375,13 +8375,13 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc ConstExprValue *const_val = &instruction->value; assert(const_val->special != ConstValSpecialRuntime); - bool const_val_is_int = (const_val->type->id == TypeTableEntryIdInt || - const_val->type->id == TypeTableEntryIdComptimeInt); - bool const_val_is_float = (const_val->type->id == TypeTableEntryIdFloat || - const_val->type->id == TypeTableEntryIdComptimeFloat); - if (other_type->id == TypeTableEntryIdFloat) { + bool const_val_is_int = (const_val->type->id == ZigTypeIdInt || + const_val->type->id == ZigTypeIdComptimeInt); + bool const_val_is_float = (const_val->type->id == ZigTypeIdFloat || + const_val->type->id == ZigTypeIdComptimeFloat); + if (other_type->id == ZigTypeIdFloat) { return true; - } else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) { + } else if (other_type->id == ZigTypeIdInt && const_val_is_int) { if (!other_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { Buf *val_buf = buf_alloc(); bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); @@ -8398,11 +8398,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc } } else if (const_val_fits_in_num_lit(const_val, other_type)) { return true; - } else if (other_type->id == TypeTableEntryIdOptional) { + } else if (other_type->id == ZigTypeIdOptional) { ZigType *child_type = other_type->data.maybe.child_type; if (const_val_fits_in_num_lit(const_val, child_type)) { return true; - } else if (child_type->id == TypeTableEntryIdInt && const_val_is_int) { + } else if (child_type->id == ZigTypeIdInt && const_val_is_int) { if (!child_type->data.integral.is_signed && const_val->data.x_bigint.is_negative) { Buf *val_buf = buf_alloc(); bigint_append_buf(val_buf, &const_val->data.x_bigint, 10); @@ -8418,11 +8418,11 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc { return true; } - } else if (child_type->id == TypeTableEntryIdFloat && const_val_is_float) { + } else if (child_type->id == ZigTypeIdFloat && const_val_is_float) { return true; } } - if (explicit_cast && (other_type->id == TypeTableEntryIdInt || other_type->id == TypeTableEntryIdComptimeInt) && + if (explicit_cast && (other_type->id == ZigTypeIdInt || other_type->id == ZigTypeIdComptimeInt) && const_val_is_float) { if (float_has_fraction(const_val)) { @@ -8435,7 +8435,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc buf_ptr(&other_type->name))); return false; } else { - if (other_type->id == TypeTableEntryIdComptimeInt) { + if (other_type->id == ZigTypeIdComptimeInt) { return true; } else { BigInt bigint; @@ -8468,7 +8468,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc } static bool is_slice(ZigType *type) { - return type->id == TypeTableEntryIdStruct && type->data.structure.is_slice; + return type->id == ZigTypeIdStruct && type->data.structure.is_slice; } static bool slice_is_const(ZigType *type) { @@ -8479,8 +8479,8 @@ static bool slice_is_const(ZigType *type) { static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigType *set2, AstNode *source_node) { - assert(set1->id == TypeTableEntryIdErrorSet); - assert(set2->id == TypeTableEntryIdErrorSet); + assert(set1->id == ZigTypeIdErrorSet); + assert(set2->id == ZigTypeIdErrorSet); if (!resolve_inferred_error_set(ira->codegen, set1, source_node)) { return ira->codegen->builtin_types.entry_invalid; @@ -8502,7 +8502,7 @@ static ZigType *get_error_set_intersection(IrAnalyze *ira, ZigType *set1, ZigTyp } ZigList intersection_list = {}; - ZigType *err_set_type = new_type_table_entry(TypeTableEntryIdErrorSet); + ZigType *err_set_type = new_type_table_entry(ZigTypeIdErrorSet); buf_resize(&err_set_type->name, 0); buf_appendf(&err_set_type->name, "error{"); @@ -8544,9 +8544,9 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted // *T and [*]T may const-cast-only to ?*U and ?[*]U, respectively // but not if we want a mutable pointer // and not if the actual pointer has zero bits - if (!wanted_is_mutable && wanted_type->id == TypeTableEntryIdOptional && - wanted_type->data.maybe.child_type->id == TypeTableEntryIdPointer && - actual_type->id == TypeTableEntryIdPointer && type_has_bits(actual_type)) + if (!wanted_is_mutable && wanted_type->id == ZigTypeIdOptional && + wanted_type->data.maybe.child_type->id == ZigTypeIdPointer && + actual_type->id == ZigTypeIdPointer && type_has_bits(actual_type)) { ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type, actual_type, source_node, wanted_is_mutable); @@ -8559,10 +8559,10 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted } // *T and [*]T can always cast to *c_void - if (wanted_type->id == TypeTableEntryIdPointer && + if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && wanted_type->data.pointer.child_type == g->builtin_types.entry_c_void && - actual_type->id == TypeTableEntryIdPointer && + actual_type->id == ZigTypeIdPointer && (!actual_type->data.pointer.is_const || wanted_type->data.pointer.is_const) && (!actual_type->data.pointer.is_volatile || wanted_type->data.pointer.is_volatile)) { @@ -8571,7 +8571,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted } // pointer const - if (wanted_type->id == TypeTableEntryIdPointer && actual_type->id == TypeTableEntryIdPointer) { + if (wanted_type->id == ZigTypeIdPointer && actual_type->id == ZigTypeIdPointer) { ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const); if (child.id != ConstCastResultIdOk) { @@ -8617,7 +8617,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted } // maybe - if (wanted_type->id == TypeTableEntryIdOptional && actual_type->id == TypeTableEntryIdOptional) { + if (wanted_type->id == ZigTypeIdOptional && actual_type->id == ZigTypeIdOptional) { ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.maybe.child_type, actual_type->data.maybe.child_type, source_node, wanted_is_mutable); if (child.id != ConstCastResultIdOk) { @@ -8631,7 +8631,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted } // error union - if (wanted_type->id == TypeTableEntryIdErrorUnion && actual_type->id == TypeTableEntryIdErrorUnion) { + if (wanted_type->id == ZigTypeIdErrorUnion && actual_type->id == ZigTypeIdErrorUnion) { ConstCastOnly payload_child = types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type->data.error_union.payload_type, source_node, wanted_is_mutable); if (payload_child.id != ConstCastResultIdOk) { @@ -8656,7 +8656,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted } // error set - if (wanted_type->id == TypeTableEntryIdErrorSet && actual_type->id == TypeTableEntryIdErrorSet) { + if (wanted_type->id == ZigTypeIdErrorSet && actual_type->id == ZigTypeIdErrorSet) { ZigType *contained_set = actual_type; ZigType *container_set = wanted_type; @@ -8701,14 +8701,14 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted } if (wanted_type == ira->codegen->builtin_types.entry_promise && - actual_type->id == TypeTableEntryIdPromise) + actual_type->id == ZigTypeIdPromise) { return result; } // fn - if (wanted_type->id == TypeTableEntryIdFn && - actual_type->id == TypeTableEntryIdFn) + if (wanted_type->id == ZigTypeIdFn && + actual_type->id == ZigTypeIdFn) { if (wanted_type->data.fn.fn_type_id.alignment > actual_type->data.fn.fn_type_id.alignment) { result.id = ConstCastResultIdFnAlign; @@ -8727,7 +8727,7 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, ZigType *wanted return result; } if (!wanted_type->data.fn.is_generic && - actual_type->data.fn.fn_type_id.return_type->id != TypeTableEntryIdUnreachable) + actual_type->data.fn.fn_type_id.return_type->id != ZigTypeIdUnreachable) { ConstCastOnly child = types_match_const_cast_only(ira, wanted_type->data.fn.fn_type_id.return_type, actual_type->data.fn.fn_type_id.return_type, source_node, false); @@ -8807,7 +8807,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT ErrorTableEntry **errors = nullptr; size_t errors_count = 0; ZigType *err_set_type = nullptr; - if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) { + if (prev_inst->value.type->id == ZigTypeIdErrorSet) { if (type_is_global_error_set(prev_inst->value.type)) { err_set_type = ira->codegen->builtin_types.entry_global_error_set; } else { @@ -8825,7 +8825,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } } - bool any_are_null = (prev_inst->value.type->id == TypeTableEntryIdNull); + bool any_are_null = (prev_inst->value.type->id == ZigTypeIdNull); bool convert_to_const_slice = false; for (size_t i = 1; i < instruction_count; i += 1) { IrInstruction *cur_inst = instructions[i]; @@ -8836,18 +8836,18 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT return cur_type; } - if (prev_type->id == TypeTableEntryIdUnreachable) { + if (prev_type->id == ZigTypeIdUnreachable) { prev_inst = cur_inst; continue; } - if (cur_type->id == TypeTableEntryIdUnreachable) { + if (cur_type->id == ZigTypeIdUnreachable) { continue; } - if (prev_type->id == TypeTableEntryIdErrorSet) { + if (prev_type->id == ZigTypeIdErrorSet) { assert(err_set_type != nullptr); - if (cur_type->id == TypeTableEntryIdErrorSet) { + if (cur_type->id == ZigTypeIdErrorSet) { if (type_is_global_error_set(err_set_type)) { continue; } @@ -8911,7 +8911,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT err_set_type = get_error_set_union(ira->codegen, errors, cur_type, err_set_type); assert(errors != nullptr); continue; - } else if (cur_type->id == TypeTableEntryIdErrorUnion) { + } else if (cur_type->id == ZigTypeIdErrorUnion) { if (type_is_global_error_set(err_set_type)) { prev_inst = cur_inst; continue; @@ -8969,8 +8969,8 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } } - if (cur_type->id == TypeTableEntryIdErrorSet) { - if (prev_type->id == TypeTableEntryIdArray) { + if (cur_type->id == ZigTypeIdErrorSet) { + if (prev_type->id == ZigTypeIdArray) { convert_to_const_slice = true; } if (type_is_global_error_set(cur_type)) { @@ -8987,7 +8987,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT update_errors_helper(ira->codegen, &errors, &errors_count); if (err_set_type == nullptr) { - if (prev_type->id == TypeTableEntryIdErrorUnion) { + if (prev_type->id == ZigTypeIdErrorUnion) { err_set_type = prev_type->data.error_union.err_set_type; } else { err_set_type = cur_type; @@ -9020,7 +9020,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT continue; } - if (prev_type->id == TypeTableEntryIdErrorUnion && cur_type->id == TypeTableEntryIdErrorUnion) { + if (prev_type->id == ZigTypeIdErrorUnion && cur_type->id == ZigTypeIdErrorUnion) { ZigType *prev_payload_type = prev_type->data.error_union.payload_type; ZigType *cur_payload_type = cur_type->data.error_union.payload_type; @@ -9104,12 +9104,12 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } } - if (prev_type->id == TypeTableEntryIdNull) { + if (prev_type->id == ZigTypeIdNull) { prev_inst = cur_inst; continue; } - if (cur_type->id == TypeTableEntryIdNull) { + if (cur_type->id == ZigTypeIdNull) { any_are_null = true; continue; } @@ -9123,8 +9123,8 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT continue; } - if (prev_type->id == TypeTableEntryIdInt && - cur_type->id == TypeTableEntryIdInt && + if (prev_type->id == ZigTypeIdInt && + cur_type->id == ZigTypeIdInt && prev_type->data.integral.is_signed == cur_type->data.integral.is_signed) { if (cur_type->data.integral.bit_count > prev_type->data.integral.bit_count) { @@ -9133,21 +9133,21 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT continue; } - if (prev_type->id == TypeTableEntryIdFloat && cur_type->id == TypeTableEntryIdFloat) { + if (prev_type->id == ZigTypeIdFloat && cur_type->id == ZigTypeIdFloat) { if (cur_type->data.floating.bit_count > prev_type->data.floating.bit_count) { prev_inst = cur_inst; } continue; } - if (prev_type->id == TypeTableEntryIdErrorUnion && + if (prev_type->id == ZigTypeIdErrorUnion && types_match_const_cast_only(ira, prev_type->data.error_union.payload_type, cur_type, source_node, false).id == ConstCastResultIdOk) { continue; } - if (cur_type->id == TypeTableEntryIdErrorUnion && + if (cur_type->id == ZigTypeIdErrorUnion && types_match_const_cast_only(ira, cur_type->data.error_union.payload_type, prev_type, source_node, false).id == ConstCastResultIdOk) { @@ -9170,14 +9170,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT continue; } - if (prev_type->id == TypeTableEntryIdOptional && + if (prev_type->id == ZigTypeIdOptional && types_match_const_cast_only(ira, prev_type->data.maybe.child_type, cur_type, source_node, false).id == ConstCastResultIdOk) { continue; } - if (cur_type->id == TypeTableEntryIdOptional && + if (cur_type->id == ZigTypeIdOptional && types_match_const_cast_only(ira, cur_type->data.maybe.child_type, prev_type, source_node, false).id == ConstCastResultIdOk) { @@ -9185,17 +9185,17 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT continue; } - if (cur_type->id == TypeTableEntryIdUndefined) { + if (cur_type->id == ZigTypeIdUndefined) { continue; } - if (prev_type->id == TypeTableEntryIdUndefined) { + if (prev_type->id == ZigTypeIdUndefined) { prev_inst = cur_inst; continue; } - if (prev_type->id == TypeTableEntryIdComptimeInt || - prev_type->id == TypeTableEntryIdComptimeFloat) + if (prev_type->id == ZigTypeIdComptimeInt || + prev_type->id == ZigTypeIdComptimeFloat) { if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) { prev_inst = cur_inst; @@ -9205,8 +9205,8 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } } - if (cur_type->id == TypeTableEntryIdComptimeInt || - cur_type->id == TypeTableEntryIdComptimeFloat) + if (cur_type->id == ZigTypeIdComptimeInt || + cur_type->id == ZigTypeIdComptimeFloat) { if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) { continue; @@ -9215,7 +9215,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } } - if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && + if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray && cur_type->data.array.len != prev_type->data.array.len && types_match_const_cast_only(ira, cur_type->data.array.child_type, prev_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) @@ -9225,7 +9225,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT continue; } - if (cur_type->id == TypeTableEntryIdArray && prev_type->id == TypeTableEntryIdArray && + if (cur_type->id == ZigTypeIdArray && prev_type->id == ZigTypeIdArray && cur_type->data.array.len != prev_type->data.array.len && types_match_const_cast_only(ira, prev_type->data.array.child_type, cur_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) @@ -9234,7 +9234,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT continue; } - if (cur_type->id == TypeTableEntryIdArray && is_slice(prev_type) && + if (cur_type->id == ZigTypeIdArray && is_slice(prev_type) && (prev_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || cur_type->data.array.len == 0) && types_match_const_cast_only(ira, @@ -9245,7 +9245,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT continue; } - if (prev_type->id == TypeTableEntryIdArray && is_slice(cur_type) && + if (prev_type->id == ZigTypeIdArray && is_slice(cur_type) && (cur_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const || prev_type->data.array.len == 0) && types_match_const_cast_only(ira, @@ -9257,7 +9257,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT continue; } - if (prev_type->id == TypeTableEntryIdEnum && cur_type->id == TypeTableEntryIdUnion && + if (prev_type->id == ZigTypeIdEnum && cur_type->id == ZigTypeIdUnion && (cur_type->data.unionation.decl_node->data.container_decl.auto_enum || cur_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) { if ((err = type_ensure_zero_bits_known(ira->codegen, cur_type))) @@ -9267,7 +9267,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT } } - if (cur_type->id == TypeTableEntryIdEnum && prev_type->id == TypeTableEntryIdUnion && + if (cur_type->id == ZigTypeIdEnum && prev_type->id == ZigTypeIdUnion && (prev_type->data.unionation.decl_node->data.container_decl.auto_enum || prev_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) { if ((err = type_ensure_zero_bits_known(ira->codegen, prev_type))) @@ -9292,7 +9292,7 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT free(errors); if (convert_to_const_slice) { - assert(prev_inst->value.type->id == TypeTableEntryIdArray); + assert(prev_inst->value.type->id == ZigTypeIdArray); ZigType *ptr_type = get_pointer_to_type_extra( ira->codegen, prev_inst->value.type->data.array.child_type, true, false, PtrLenUnknown, @@ -9305,20 +9305,20 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT return slice_type; } } else if (err_set_type != nullptr) { - if (prev_inst->value.type->id == TypeTableEntryIdErrorSet) { + if (prev_inst->value.type->id == ZigTypeIdErrorSet) { return err_set_type; - } else if (prev_inst->value.type->id == TypeTableEntryIdErrorUnion) { + } else if (prev_inst->value.type->id == ZigTypeIdErrorUnion) { return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type->data.error_union.payload_type); - } else if (expected_type != nullptr && expected_type->id == TypeTableEntryIdErrorUnion) { + } else if (expected_type != nullptr && expected_type->id == ZigTypeIdErrorUnion) { return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type); } else { - if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt || - prev_inst->value.type->id == TypeTableEntryIdComptimeFloat) + if (prev_inst->value.type->id == ZigTypeIdComptimeInt || + prev_inst->value.type->id == ZigTypeIdComptimeFloat) { ir_add_error_node(ira, source_node, buf_sprintf("unable to make error union out of number literal")); return ira->codegen->builtin_types.entry_invalid; - } else if (prev_inst->value.type->id == TypeTableEntryIdNull) { + } else if (prev_inst->value.type->id == ZigTypeIdNull) { ir_add_error_node(ira, source_node, buf_sprintf("unable to make error union out of null literal")); return ira->codegen->builtin_types.entry_invalid; @@ -9326,14 +9326,14 @@ static ZigType *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, ZigT return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type); } } - } else if (any_are_null && prev_inst->value.type->id != TypeTableEntryIdNull) { - if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt || - prev_inst->value.type->id == TypeTableEntryIdComptimeFloat) + } else if (any_are_null && prev_inst->value.type->id != ZigTypeIdNull) { + if (prev_inst->value.type->id == ZigTypeIdComptimeInt || + prev_inst->value.type->id == ZigTypeIdComptimeFloat) { ir_add_error_node(ira, source_node, buf_sprintf("unable to make maybe out of number literal")); return ira->codegen->builtin_types.entry_invalid; - } else if (prev_inst->value.type->id == TypeTableEntryIdOptional) { + } else if (prev_inst->value.type->id == ZigTypeIdOptional) { return prev_inst->value.type; } else { return get_optional_type(ira->codegen, prev_inst->value.type); @@ -9357,7 +9357,7 @@ static void copy_const_val(ConstExprValue *dest, ConstExprValue *src, bool same_ *dest = *src; if (!same_global_refs) { dest->global_refs = global_refs; - if (dest->type->id == TypeTableEntryIdStruct) { + if (dest->type->id == ZigTypeIdStruct) { dest->data.x_struct.fields = allocate_nonzero(dest->type->data.structure.src_field_count); memcpy(dest->data.x_struct.fields, src->data.x_struct.fields, sizeof(ConstExprValue) * dest->type->data.structure.src_field_count); } @@ -9387,8 +9387,8 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ break; } case CastOpNumLitToConcrete: - if (other_val->type->id == TypeTableEntryIdComptimeFloat) { - assert(new_type->id == TypeTableEntryIdFloat); + if (other_val->type->id == ZigTypeIdComptimeFloat) { + assert(new_type->id == ZigTypeIdFloat); switch (new_type->data.floating.bit_count) { case 16: const_val->data.x_f16 = bigfloat_to_f16(&other_val->data.x_bigfloat); @@ -9405,7 +9405,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ default: zig_unreachable(); } - } else if (other_val->type->id == TypeTableEntryIdComptimeInt) { + } else if (other_val->type->id == ZigTypeIdComptimeInt) { bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint); } else { zig_unreachable(); @@ -9418,7 +9418,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ zig_unreachable(); case CastOpIntToFloat: { - assert(new_type->id == TypeTableEntryIdFloat); + assert(new_type->id == ZigTypeIdFloat); BigFloat bigfloat; bigfloat_init_bigint(&bigfloat, &other_val->data.x_bigint); @@ -9443,7 +9443,7 @@ static bool eval_const_expr_implicit_cast(IrAnalyze *ira, IrInstruction *source_ } case CastOpFloatToInt: float_init_bigint(&const_val->data.x_bigint, other_val); - if (new_type->id == TypeTableEntryIdInt) { + if (new_type->id == ZigTypeIdInt) { if (!bigint_fits_in_bits(&const_val->data.x_bigint, new_type->data.integral.bit_count, new_type->data.integral.is_signed)) { @@ -9493,7 +9493,7 @@ static IrInstruction *ir_resolve_cast(IrAnalyze *ira, IrInstruction *source_inst static IrInstruction *ir_resolve_ptr_of_array_to_unknown_len_ptr(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { - assert(value->value.type->id == TypeTableEntryIdPointer); + assert(value->value.type->id == ZigTypeIdPointer); wanted_type = adjust_ptr_align(ira->codegen, wanted_type, value->value.type->data.pointer.alignment); if (instr_is_comptime(value)) { @@ -9529,7 +9529,7 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc if (pointee == nullptr) return ira->codegen->invalid_instruction; if (pointee->special != ConstValSpecialRuntime) { - assert(value->value.type->id == TypeTableEntryIdPointer); + assert(value->value.type->id == ZigTypeIdPointer); ZigType *array_type = value->value.type->data.pointer.child_type; assert(is_slice(wanted_type)); bool is_const = wanted_type->data.structure.fields[slice_ptr_index].type_entry->data.pointer.is_const; @@ -9552,9 +9552,9 @@ static IrInstruction *ir_resolve_ptr_of_array_to_slice(IrAnalyze *ira, IrInstruc } static bool is_container(ZigType *type) { - return type->id == TypeTableEntryIdStruct || - type->id == TypeTableEntryIdEnum || - type->id == TypeTableEntryIdUnion; + return type->id == ZigTypeIdStruct || + type->id == ZigTypeIdEnum || + type->id == ZigTypeIdUnion; } static IrBasicBlock *ir_get_new_bb(IrAnalyze *ira, IrBasicBlock *old_bb, IrInstruction *ref_old_instruction) { @@ -9665,7 +9665,7 @@ static ZigType *ir_inline_bb(IrAnalyze *ira, IrInstruction *source_instruction, } static ZigType *ir_finish_anal(IrAnalyze *ira, ZigType *result_type) { - if (result_type->id == TypeTableEntryIdUnreachable) + if (result_type->id == ZigTypeIdUnreachable) ir_finish_bb(ira); return result_type; } @@ -9803,7 +9803,7 @@ static ZigType *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) { if (type_is_invalid(type_value->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (type_value->value.type->id != TypeTableEntryIdMetaType) { + if (type_value->value.type->id != ZigTypeIdMetaType) { ir_add_error(ira, type_value, buf_sprintf("expected type 'type', found '%s'", buf_ptr(&type_value->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -9823,7 +9823,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { if (type_is_invalid(fn_value->value.type)) return nullptr; - if (fn_value->value.type->id != TypeTableEntryIdFn) { + if (fn_value->value.type->id != ZigTypeIdFn) { ir_add_error_node(ira, fn_value->source_node, buf_sprintf("expected function type, found '%s'", buf_ptr(&fn_value->value.type->name))); return nullptr; @@ -9838,7 +9838,7 @@ static ZigFn *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) { } static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { - assert(wanted_type->id == TypeTableEntryIdOptional); + assert(wanted_type->id == ZigTypeIdOptional); if (instr_is_comptime(value)) { ZigType *payload_type = wanted_type->data.maybe.child_type; @@ -9872,7 +9872,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { - assert(wanted_type->id == TypeTableEntryIdErrorUnion); + assert(wanted_type->id == ZigTypeIdErrorUnion); if (instr_is_comptime(value)) { ZigType *payload_type = wanted_type->data.error_union.payload_type; @@ -9903,8 +9903,8 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { - assert(value->value.type->id == TypeTableEntryIdErrorSet); - assert(wanted_type->id == TypeTableEntryIdErrorSet); + assert(value->value.type->id == ZigTypeIdErrorSet); + assert(wanted_type->id == ZigTypeIdErrorSet); if (instr_is_comptime(value)) { ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); @@ -9944,7 +9944,7 @@ static IrInstruction *ir_analyze_err_set_cast(IrAnalyze *ira, IrInstruction *sou } static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { - assert(wanted_type->id == TypeTableEntryIdErrorUnion); + assert(wanted_type->id == ZigTypeIdErrorUnion); IrInstruction *casted_value = ir_implicit_cast(ira, value, wanted_type->data.error_union.err_set_type); @@ -10006,7 +10006,7 @@ static IrInstruction *ir_analyze_cast_ref(IrAnalyze *ira, IrInstruction *source_ } static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value, ZigType *wanted_type) { - assert(wanted_type->id == TypeTableEntryIdOptional); + assert(wanted_type->id == ZigTypeIdOptional); assert(instr_is_comptime(value)); ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); @@ -10062,14 +10062,14 @@ static IrInstruction *ir_analyze_array_to_slice(IrAnalyze *ira, IrInstruction *s IrInstruction *array_ptr = nullptr; IrInstruction *array; - if (array_arg->value.type->id == TypeTableEntryIdPointer) { + if (array_arg->value.type->id == ZigTypeIdPointer) { array = ir_get_deref(ira, source_instr, array_arg); array_ptr = array_arg; } else { array = array_arg; } ZigType *array_type = array->value.type; - assert(array_type->id == TypeTableEntryIdArray); + assert(array_type->id == ZigTypeIdArray); if (instr_is_comptime(array)) { IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, @@ -10103,7 +10103,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour IrInstruction *target, ZigType *wanted_type) { Error err; - assert(wanted_type->id == TypeTableEntryIdInt); + assert(wanted_type->id == ZigTypeIdInt); ZigType *actual_type = target->value.type; if ((err = ensure_complete_type(ira->codegen, actual_type))) @@ -10117,7 +10117,7 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour return ira->codegen->invalid_instruction; } - assert(actual_type->id == TypeTableEntryIdEnum); + assert(actual_type->id == ZigTypeIdEnum); if (instr_is_comptime(target)) { ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); @@ -10138,8 +10138,8 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour static IrInstruction *ir_analyze_union_to_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, ZigType *wanted_type) { - assert(target->value.type->id == TypeTableEntryIdUnion); - assert(wanted_type->id == TypeTableEntryIdEnum); + assert(target->value.type->id == ZigTypeIdUnion); + assert(wanted_type->id == ZigTypeIdEnum); assert(wanted_type == target->value.type->data.unionation.tag_type); if (instr_is_comptime(target)) { @@ -10173,8 +10173,8 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so IrInstruction *target, ZigType *wanted_type) { Error err; - assert(wanted_type->id == TypeTableEntryIdUnion); - assert(target->value.type->id == TypeTableEntryIdEnum); + assert(wanted_type->id == ZigTypeIdUnion); + assert(target->value.type->id == ZigTypeIdEnum); if (instr_is_comptime(target)) { ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); @@ -10231,13 +10231,13 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, ZigType *wanted_type) { - assert(wanted_type->id == TypeTableEntryIdInt || wanted_type->id == TypeTableEntryIdFloat); + assert(wanted_type->id == ZigTypeIdInt || wanted_type->id == ZigTypeIdFloat); if (instr_is_comptime(target)) { ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->invalid_instruction; - if (wanted_type->id == TypeTableEntryIdInt) { + if (wanted_type->id == ZigTypeIdInt) { if (bigint_cmp_zero(&val->data.x_bigint) == CmpLT && !wanted_type->data.integral.is_signed) { ir_add_error(ira, source_instr, buf_sprintf("attempt to cast negative value to unsigned integer")); @@ -10255,7 +10255,7 @@ static IrInstruction *ir_analyze_widen_or_shorten(IrAnalyze *ira, IrInstruction IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type); result->value.type = wanted_type; - if (wanted_type->id == TypeTableEntryIdInt) { + if (wanted_type->id == ZigTypeIdInt) { bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); } else { float_init_float(&result->value, val); @@ -10273,7 +10273,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour IrInstruction *target, ZigType *wanted_type) { Error err; - assert(wanted_type->id == TypeTableEntryIdEnum); + assert(wanted_type->id == ZigTypeIdEnum); ZigType *actual_type = target->value.type; @@ -10288,7 +10288,7 @@ static IrInstruction *ir_analyze_int_to_enum(IrAnalyze *ira, IrInstruction *sour return ira->codegen->invalid_instruction; } - assert(actual_type->id == TypeTableEntryIdInt); + assert(actual_type->id == ZigTypeIdInt); if (instr_is_comptime(target)) { ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); @@ -10328,9 +10328,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, source_instr->source_node, wanted_type); - if (wanted_type->id == TypeTableEntryIdComptimeFloat) { + if (wanted_type->id == ZigTypeIdComptimeFloat) { float_init_float(&result->value, val); - } else if (wanted_type->id == TypeTableEntryIdComptimeInt) { + } else if (wanted_type->id == ZigTypeIdComptimeInt) { bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); } else { zig_unreachable(); @@ -10341,9 +10341,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, ZigType *wanted_type) { - assert(target->value.type->id == TypeTableEntryIdInt); + assert(target->value.type->id == ZigTypeIdInt); assert(!target->value.type->data.integral.is_signed); - assert(wanted_type->id == TypeTableEntryIdErrorSet); + assert(wanted_type->id == ZigTypeIdErrorSet); if (instr_is_comptime(target)) { ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); @@ -10406,7 +10406,7 @@ static IrInstruction *ir_analyze_int_to_err(IrAnalyze *ira, IrInstruction *sourc static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, ZigType *wanted_type) { - assert(wanted_type->id == TypeTableEntryIdInt); + assert(wanted_type->id == ZigTypeIdInt); ZigType *err_type = target->value.type; @@ -10419,9 +10419,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc source_instr->source_node, wanted_type); ErrorTableEntry *err; - if (err_type->id == TypeTableEntryIdErrorUnion) { + if (err_type->id == ZigTypeIdErrorUnion) { err = val->data.x_err_union.err; - } else if (err_type->id == TypeTableEntryIdErrorSet) { + } else if (err_type->id == ZigTypeIdErrorSet) { err = val->data.x_err_set; } else { zig_unreachable(); @@ -10443,9 +10443,9 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc } ZigType *err_set_type; - if (err_type->id == TypeTableEntryIdErrorUnion) { + if (err_type->id == ZigTypeIdErrorUnion) { err_set_type = err_type->data.error_union.err_set_type; - } else if (err_type->id == TypeTableEntryIdErrorSet) { + } else if (err_type->id == ZigTypeIdErrorSet) { err_set_type = err_type; } else { zig_unreachable(); @@ -10486,10 +10486,10 @@ static IrInstruction *ir_analyze_err_to_int(IrAnalyze *ira, IrInstruction *sourc static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *target, ZigType *wanted_type) { - assert(wanted_type->id == TypeTableEntryIdPointer); + assert(wanted_type->id == ZigTypeIdPointer); wanted_type = adjust_ptr_align(ira->codegen, wanted_type, target->value.type->data.pointer.alignment); ZigType *array_type = wanted_type->data.pointer.child_type; - assert(array_type->id == TypeTableEntryIdArray); + assert(array_type->id == ZigTypeIdArray); assert(array_type->data.array.len == 1); if (instr_is_comptime(target)) { @@ -10497,7 +10497,7 @@ static IrInstruction *ir_analyze_ptr_to_array(IrAnalyze *ira, IrInstruction *sou if (!val) return ira->codegen->invalid_instruction; - assert(val->type->id == TypeTableEntryIdPointer); + assert(val->type->id == ZigTypeIdPointer); ConstExprValue *pointee = ir_const_ptr_pointee(ira, val, source_instr->source_node); if (pointee == nullptr) return ira->codegen->invalid_instruction; @@ -10638,8 +10638,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // widening conversion - if (wanted_type->id == TypeTableEntryIdInt && - actual_type->id == TypeTableEntryIdInt && + if (wanted_type->id == ZigTypeIdInt && + actual_type->id == ZigTypeIdInt && wanted_type->data.integral.is_signed == actual_type->data.integral.is_signed && wanted_type->data.integral.bit_count >= actual_type->data.integral.bit_count) { @@ -10647,16 +10647,16 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // small enough unsigned ints can get casted to large enough signed ints - if (wanted_type->id == TypeTableEntryIdInt && wanted_type->data.integral.is_signed && - actual_type->id == TypeTableEntryIdInt && !actual_type->data.integral.is_signed && + if (wanted_type->id == ZigTypeIdInt && wanted_type->data.integral.is_signed && + actual_type->id == ZigTypeIdInt && !actual_type->data.integral.is_signed && wanted_type->data.integral.bit_count > actual_type->data.integral.bit_count) { return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); } // float widening conversion - if (wanted_type->id == TypeTableEntryIdFloat && - actual_type->id == TypeTableEntryIdFloat && + if (wanted_type->id == ZigTypeIdFloat && + actual_type->id == ZigTypeIdFloat && wanted_type->data.floating.bit_count >= actual_type->data.floating.bit_count) { return ir_analyze_widen_or_shorten(ira, source_instr, value, wanted_type); @@ -10664,9 +10664,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // cast from [N]T to []const T - if (is_slice(wanted_type) && actual_type->id == TypeTableEntryIdArray) { + if (is_slice(wanted_type) && actual_type->id == ZigTypeIdArray) { ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) @@ -10677,12 +10677,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // cast from *const [N]T to []const T if (is_slice(wanted_type) && - actual_type->id == TypeTableEntryIdPointer && + actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.is_const && - actual_type->data.pointer.child_type->id == TypeTableEntryIdArray) + actual_type->data.pointer.child_type->id == ZigTypeIdArray) { ZigType *ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ZigType *array_type = actual_type->data.pointer.child_type; @@ -10695,14 +10695,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // cast from [N]T to *const []const T - if (wanted_type->id == TypeTableEntryIdPointer && + if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.is_const && is_slice(wanted_type->data.pointer.child_type) && - actual_type->id == TypeTableEntryIdArray) + actual_type->id == ZigTypeIdArray) { ZigType *ptr_type = wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) @@ -10720,13 +10720,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // cast from [N]T to ?[]const T - if (wanted_type->id == TypeTableEntryIdOptional && + if (wanted_type->id == ZigTypeIdOptional && is_slice(wanted_type->data.maybe.child_type) && - actual_type->id == TypeTableEntryIdArray) + actual_type->id == ZigTypeIdArray) { ZigType *ptr_type = wanted_type->data.maybe.child_type->data.structure.fields[slice_ptr_index].type_entry; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) @@ -10744,11 +10744,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // *[N]T to [*]T - if (wanted_type->id == TypeTableEntryIdPointer && + if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenUnknown && - actual_type->id == TypeTableEntryIdPointer && + actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle && - actual_type->data.pointer.child_type->id == TypeTableEntryIdArray && + actual_type->data.pointer.child_type->id == ZigTypeIdArray && actual_type->data.pointer.alignment >= wanted_type->data.pointer.alignment && types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, actual_type->data.pointer.child_type->data.array.child_type, source_node, @@ -10759,12 +10759,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // *[N]T to []T if (is_slice(wanted_type) && - actual_type->id == TypeTableEntryIdPointer && + actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle && - actual_type->data.pointer.child_type->id == TypeTableEntryIdArray) + actual_type->data.pointer.child_type->id == ZigTypeIdArray) { ZigType *slice_ptr_type = wanted_type->data.structure.fields[slice_ptr_index].type_entry; - assert(slice_ptr_type->id == TypeTableEntryIdPointer); + assert(slice_ptr_type->id == ZigTypeIdPointer); if (types_match_const_cast_only(ira, slice_ptr_type->data.pointer.child_type, actual_type->data.pointer.child_type->data.array.child_type, source_node, !slice_ptr_type->data.pointer.is_const).id == ConstCastResultIdOk) @@ -10776,23 +10776,23 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // cast from T to ?T // note that the *T to ?*T case is handled via the "ConstCastOnly" mechanism - if (wanted_type->id == TypeTableEntryIdOptional) { + if (wanted_type->id == ZigTypeIdOptional) { ZigType *wanted_child_type = wanted_type->data.maybe.child_type; if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk) { return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); - } else if (actual_type->id == TypeTableEntryIdComptimeInt || - actual_type->id == TypeTableEntryIdComptimeFloat) + } else if (actual_type->id == ZigTypeIdComptimeInt || + actual_type->id == ZigTypeIdComptimeFloat) { if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) { return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); } else { return ira->codegen->invalid_instruction; } - } else if (wanted_child_type->id == TypeTableEntryIdPointer && + } else if (wanted_child_type->id == ZigTypeIdPointer && wanted_child_type->data.pointer.is_const && - (actual_type->id == TypeTableEntryIdPointer || is_container(actual_type))) + (actual_type->id == ZigTypeIdPointer || is_container(actual_type))) { IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_child_type, value); if (type_is_invalid(cast1->value.type)) @@ -10804,11 +10804,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst return cast2; } else if ( - wanted_child_type->id == TypeTableEntryIdPointer && + wanted_child_type->id == ZigTypeIdPointer && wanted_child_type->data.pointer.ptr_len == PtrLenUnknown && - actual_type->id == TypeTableEntryIdPointer && + actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle && - actual_type->data.pointer.child_type->id == TypeTableEntryIdArray && + actual_type->data.pointer.child_type->id == ZigTypeIdArray && actual_type->data.pointer.alignment >= wanted_child_type->data.pointer.alignment && types_match_const_cast_only(ira, wanted_child_type->data.pointer.child_type, actual_type->data.pointer.child_type->data.array.child_type, source_node, @@ -10822,20 +10822,20 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // cast from null literal to maybe type - if (wanted_type->id == TypeTableEntryIdOptional && - actual_type->id == TypeTableEntryIdNull) + if (wanted_type->id == ZigTypeIdOptional && + actual_type->id == ZigTypeIdNull) { return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type); } // cast from child type of error type to error type - if (wanted_type->id == TypeTableEntryIdErrorUnion) { + if (wanted_type->id == ZigTypeIdErrorUnion) { if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, source_node, false).id == ConstCastResultIdOk) { return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); - } else if (actual_type->id == TypeTableEntryIdComptimeInt || - actual_type->id == TypeTableEntryIdComptimeFloat) + } else if (actual_type->id == ZigTypeIdComptimeInt || + actual_type->id == ZigTypeIdComptimeFloat) { if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) { return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); @@ -10846,13 +10846,13 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // cast from [N]T to E![]const T - if (wanted_type->id == TypeTableEntryIdErrorUnion && + if (wanted_type->id == ZigTypeIdErrorUnion && is_slice(wanted_type->data.error_union.payload_type) && - actual_type->id == TypeTableEntryIdArray) + actual_type->id == ZigTypeIdArray) { ZigType *ptr_type = wanted_type->data.error_union.payload_type->data.structure.fields[slice_ptr_index].type_entry; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, source_node, false).id == ConstCastResultIdOk) @@ -10870,22 +10870,22 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // cast from error set to error union type - if (wanted_type->id == TypeTableEntryIdErrorUnion && - actual_type->id == TypeTableEntryIdErrorSet) + if (wanted_type->id == ZigTypeIdErrorUnion && + actual_type->id == ZigTypeIdErrorSet) { return ir_analyze_err_wrap_code(ira, source_instr, value, wanted_type); } // cast from T to E!?T - if (wanted_type->id == TypeTableEntryIdErrorUnion && - wanted_type->data.error_union.payload_type->id == TypeTableEntryIdOptional && - actual_type->id != TypeTableEntryIdOptional) + if (wanted_type->id == ZigTypeIdErrorUnion && + wanted_type->data.error_union.payload_type->id == ZigTypeIdOptional && + actual_type->id != ZigTypeIdOptional) { ZigType *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node, false).id == ConstCastResultIdOk || - actual_type->id == TypeTableEntryIdNull || - actual_type->id == TypeTableEntryIdComptimeInt || - actual_type->id == TypeTableEntryIdComptimeFloat) + actual_type->id == ZigTypeIdNull || + actual_type->id == ZigTypeIdComptimeInt || + actual_type->id == ZigTypeIdComptimeFloat) { IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); if (type_is_invalid(cast1->value.type)) @@ -10901,12 +10901,12 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // cast from number literal to another type // cast from number literal to *const integer - if (actual_type->id == TypeTableEntryIdComptimeFloat || - actual_type->id == TypeTableEntryIdComptimeInt) + if (actual_type->id == ZigTypeIdComptimeFloat || + actual_type->id == ZigTypeIdComptimeInt) { if ((err = ensure_complete_type(ira->codegen, wanted_type))) return ira->codegen->invalid_instruction; - if (wanted_type->id == TypeTableEntryIdEnum) { + if (wanted_type->id == ZigTypeIdEnum) { IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value); if (type_is_invalid(cast1->value.type)) return ira->codegen->invalid_instruction; @@ -10916,7 +10916,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst return ira->codegen->invalid_instruction; return cast2; - } else if (wanted_type->id == TypeTableEntryIdPointer && + } else if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.is_const) { IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); @@ -10930,15 +10930,15 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst return cast2; } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { CastOp op; - if ((actual_type->id == TypeTableEntryIdComptimeFloat && - wanted_type->id == TypeTableEntryIdFloat) || - (actual_type->id == TypeTableEntryIdComptimeInt && - wanted_type->id == TypeTableEntryIdInt)) + if ((actual_type->id == ZigTypeIdComptimeFloat && + wanted_type->id == ZigTypeIdFloat) || + (actual_type->id == ZigTypeIdComptimeInt && + wanted_type->id == ZigTypeIdInt)) { op = CastOpNumLitToConcrete; - } else if (wanted_type->id == TypeTableEntryIdInt) { + } else if (wanted_type->id == ZigTypeIdInt) { op = CastOpFloatToInt; - } else if (wanted_type->id == TypeTableEntryIdFloat) { + } else if (wanted_type->id == ZigTypeIdFloat) { op = CastOpIntToFloat; } else { zig_unreachable(); @@ -10952,14 +10952,14 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // cast from typed number to integer or float literal. // works when the number is known at compile time if (instr_is_comptime(value) && - ((actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdComptimeInt) || - (actual_type->id == TypeTableEntryIdFloat && wanted_type->id == TypeTableEntryIdComptimeFloat))) + ((actual_type->id == ZigTypeIdInt && wanted_type->id == ZigTypeIdComptimeInt) || + (actual_type->id == ZigTypeIdFloat && wanted_type->id == ZigTypeIdComptimeFloat))) { return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type); } // cast from union to the enum type of the union - if (actual_type->id == TypeTableEntryIdUnion && wanted_type->id == TypeTableEntryIdEnum) { + if (actual_type->id == ZigTypeIdUnion && wanted_type->id == ZigTypeIdEnum) { if ((err = type_ensure_zero_bits_known(ira->codegen, actual_type))) return ira->codegen->invalid_instruction; @@ -10969,7 +10969,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // enum to union which has the enum as the tag type - if (wanted_type->id == TypeTableEntryIdUnion && actual_type->id == TypeTableEntryIdEnum && + if (wanted_type->id == ZigTypeIdUnion && actual_type->id == ZigTypeIdEnum && (wanted_type->data.unionation.decl_node->data.container_decl.auto_enum || wanted_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr)) { @@ -10982,7 +10982,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // enum to &const union which has the enum as the tag type - if (actual_type->id == TypeTableEntryIdEnum && wanted_type->id == TypeTableEntryIdPointer) { + if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) { ZigType *union_type = wanted_type->data.pointer.child_type; if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr) @@ -11005,11 +11005,11 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // cast from *T to *[1]T - if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && - actual_type->id == TypeTableEntryIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle) + if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && + actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle) { ZigType *array_type = wanted_type->data.pointer.child_type; - if (array_type->id == TypeTableEntryIdArray && array_type->data.array.len == 1 && + if (array_type->id == ZigTypeIdArray && array_type->data.array.len == 1 && types_match_const_cast_only(ira, array_type->data.array.child_type, actual_type->data.pointer.child_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) @@ -11029,7 +11029,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // cast from T to *T where T is zero bits - if (wanted_type->id == TypeTableEntryIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && + if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && types_match_const_cast_only(ira, wanted_type->data.pointer.child_type, actual_type, source_node, !wanted_type->data.pointer.is_const).id == ConstCastResultIdOk) { @@ -11043,7 +11043,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst // cast from undefined to anything - if (actual_type->id == TypeTableEntryIdUndefined) { + if (actual_type->id == ZigTypeIdUndefined) { return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type); } @@ -11073,7 +11073,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Zig return value; // anything will do if (expected_type == value->value.type) return value; // match - if (value->value.type->id == TypeTableEntryIdUnreachable) + if (value->value.type->id == ZigTypeIdUnreachable) return value; return ir_analyze_cast(ira, value, expected_type, value); @@ -11083,7 +11083,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc ZigType *type_entry = ptr->value.type; if (type_is_invalid(type_entry)) { return ira->codegen->invalid_instruction; - } else if (type_entry->id == TypeTableEntryIdPointer) { + } else if (type_entry->id == ZigTypeIdPointer) { ZigType *child_type = type_entry->data.pointer.child_type; if (instr_is_comptime(ptr)) { if (ptr->value.data.x_ptr.mut == ConstPtrMutComptimeConst || @@ -11198,7 +11198,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic return false; ConstExprValue *atomic_order_val = get_builtin_value(ira->codegen, "AtomicOrder"); - assert(atomic_order_val->type->id == TypeTableEntryIdMetaType); + assert(atomic_order_val->type->id == ZigTypeIdMetaType); ZigType *atomic_order_type = atomic_order_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_order_type); @@ -11218,7 +11218,7 @@ static bool ir_resolve_atomic_rmw_op(IrAnalyze *ira, IrInstruction *value, Atomi return false; ConstExprValue *atomic_rmw_op_val = get_builtin_value(ira->codegen, "AtomicRmwOp"); - assert(atomic_rmw_op_val->type->id == TypeTableEntryIdMetaType); + assert(atomic_rmw_op_val->type->id == ZigTypeIdMetaType); ZigType *atomic_rmw_op_type = atomic_rmw_op_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, atomic_rmw_op_type); @@ -11238,7 +11238,7 @@ static bool ir_resolve_global_linkage(IrAnalyze *ira, IrInstruction *value, Glob return false; ConstExprValue *global_linkage_val = get_builtin_value(ira->codegen, "GlobalLinkage"); - assert(global_linkage_val->type->id == TypeTableEntryIdMetaType); + assert(global_linkage_val->type->id == ZigTypeIdMetaType); ZigType *global_linkage_type = global_linkage_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, global_linkage_type); @@ -11258,7 +11258,7 @@ static bool ir_resolve_float_mode(IrAnalyze *ira, IrInstruction *value, FloatMod return false; ConstExprValue *float_mode_val = get_builtin_value(ira->codegen, "FloatMode"); - assert(float_mode_val->type->id == TypeTableEntryIdMetaType); + assert(float_mode_val->type->id == ZigTypeIdMetaType); ZigType *float_mode_type = float_mode_val->data.x_type; IrInstruction *casted_value = ir_implicit_cast(ira, value, float_mode_type); @@ -11340,7 +11340,7 @@ static ZigType *ir_analyze_instruction_return(IrAnalyze *ira, return ir_unreach_error(ira); if (casted_value->value.special == ConstValSpecialRuntime && - casted_value->value.type->id == TypeTableEntryIdPointer && + casted_value->value.type->id == ZigTypeIdPointer && casted_value->value.data.rh_ptr == RuntimeHintPtrStack) { ir_add_error(ira, casted_value, buf_sprintf("function returns address of local variable")); @@ -11388,8 +11388,8 @@ static ZigType *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_o if (op2_val == nullptr) return ira->codegen->builtin_types.entry_invalid; - assert(casted_op1->value.type->id == TypeTableEntryIdBool); - assert(casted_op2->value.type->id == TypeTableEntryIdBool); + assert(casted_op1->value.type->id == ZigTypeIdBool); + assert(casted_op2->value.type->id == ZigTypeIdBool); if (bin_op_instruction->op_id == IrBinOpBoolOr) { out_val->data.x_bool = op1_val->data.x_bool || op2_val->data.x_bool; } else if (bin_op_instruction->op_id == IrBinOpBoolAnd) { @@ -11442,19 +11442,19 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op IrBinOp op_id = bin_op_instruction->op_id; bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); if (is_equality_cmp && - ((op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdOptional) || - (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdOptional) || - (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull))) + ((op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdOptional) || + (op2->value.type->id == ZigTypeIdNull && op1->value.type->id == ZigTypeIdOptional) || + (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull))) { - if (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull) { + if (op1->value.type->id == ZigTypeIdNull && op2->value.type->id == ZigTypeIdNull) { ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); out_val->data.x_bool = (op_id == IrBinOpCmpEq); return ira->codegen->builtin_types.entry_bool; } IrInstruction *maybe_op; - if (op1->value.type->id == TypeTableEntryIdNull) { + if (op1->value.type->id == ZigTypeIdNull) { maybe_op = op2; - } else if (op2->value.type->id == TypeTableEntryIdNull) { + } else if (op2->value.type->id == ZigTypeIdNull) { maybe_op = op1; } else { zig_unreachable(); @@ -11481,7 +11481,7 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op return ira->codegen->builtin_types.entry_bool; } - if (op1->value.type->id == TypeTableEntryIdErrorSet && op2->value.type->id == TypeTableEntryIdErrorSet) { + if (op1->value.type->id == ZigTypeIdErrorSet && op2->value.type->id == ZigTypeIdErrorSet) { if (!is_equality_cmp) { ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); return ira->codegen->builtin_types.entry_invalid; @@ -11575,42 +11575,42 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op bool operator_allowed; switch (resolved_type->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); // handled above - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdInt: + case ZigTypeIdFloat: operator_allowed = true; break; - case TypeTableEntryIdBool: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdPointer: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdFn: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdPromise: - case TypeTableEntryIdEnum: + case ZigTypeIdBool: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdPointer: + case ZigTypeIdErrorSet: + case ZigTypeIdFn: + case ZigTypeIdOpaque: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdPromise: + case ZigTypeIdEnum: operator_allowed = is_equality_cmp; break; - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdUnion: + case ZigTypeIdUnreachable: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdErrorUnion: + case ZigTypeIdUnion: operator_allowed = false; break; - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: operator_allowed = is_equality_cmp && get_codegen_ptr_type(resolved_type) != nullptr; break; } @@ -11638,10 +11638,10 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op return ira->codegen->builtin_types.entry_invalid; bool answer; - if (resolved_type->id == TypeTableEntryIdComptimeFloat || resolved_type->id == TypeTableEntryIdFloat) { + if (resolved_type->id == ZigTypeIdComptimeFloat || resolved_type->id == ZigTypeIdFloat) { Cmp cmp_result = float_cmp(op1_val, op2_val); answer = resolve_cmp_op_id(op_id, cmp_result); - } else if (resolved_type->id == TypeTableEntryIdComptimeInt || resolved_type->id == TypeTableEntryIdInt) { + } else if (resolved_type->id == ZigTypeIdComptimeInt || resolved_type->id == ZigTypeIdInt) { Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint); answer = resolve_cmp_op_id(op_id, cmp_result); } else { @@ -11661,7 +11661,7 @@ static ZigType *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp *bin_op } // some comparisons with unsigned numbers can be evaluated - if (resolved_type->id == TypeTableEntryIdInt && !resolved_type->data.integral.is_signed) { + if (resolved_type->id == ZigTypeIdInt && !resolved_type->data.integral.is_signed) { ConstExprValue *known_left_val; IrBinOp flipped_op_id; if (instr_is_comptime(casted_op1)) { @@ -11711,12 +11711,12 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val, bool is_int; bool is_float; Cmp op2_zcmp; - if (type_entry->id == TypeTableEntryIdInt || type_entry->id == TypeTableEntryIdComptimeInt) { + if (type_entry->id == ZigTypeIdInt || type_entry->id == ZigTypeIdComptimeInt) { is_int = true; is_float = false; op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint); - } else if (type_entry->id == TypeTableEntryIdFloat || - type_entry->id == TypeTableEntryIdComptimeFloat) + } else if (type_entry->id == ZigTypeIdFloat || + type_entry->id == ZigTypeIdComptimeFloat) { is_int = false; is_float = true; @@ -11766,7 +11766,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val, bigint_shl(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint); break; case IrBinOpBitShiftLeftLossy: - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); bigint_shl_trunc(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); break; @@ -11793,7 +11793,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val, } break; case IrBinOpAddWrap: - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); bigint_add_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); break; @@ -11805,7 +11805,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val, } break; case IrBinOpSubWrap: - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); bigint_sub_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); break; @@ -11817,7 +11817,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val, } break; case IrBinOpMultWrap: - assert(type_entry->id == TypeTableEntryIdInt); + assert(type_entry->id == ZigTypeIdInt); bigint_mul_wrap(&out_val->data.x_bigint, &op1_val->data.x_bigint, &op2_val->data.x_bigint, type_entry->data.integral.bit_count, type_entry->data.integral.is_signed); break; @@ -11872,7 +11872,7 @@ static int ir_eval_math_op(ZigType *type_entry, ConstExprValue *op1_val, break; } - if (type_entry->id == TypeTableEntryIdInt) { + if (type_entry->id == ZigTypeIdInt) { if (!bigint_fits_in_bits(&out_val->data.x_bigint, type_entry->data.integral.bit_count, type_entry->data.integral.is_signed)) { @@ -11890,7 +11890,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_ if (type_is_invalid(op1->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (op1->value.type->id != TypeTableEntryIdInt && op1->value.type->id != TypeTableEntryIdComptimeInt) { + if (op1->value.type->id != ZigTypeIdInt && op1->value.type->id != ZigTypeIdComptimeInt) { ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("bit shifting operation expected integer type, found '%s'", buf_ptr(&op1->value.type->name))); @@ -11903,7 +11903,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_ IrInstruction *casted_op2; IrBinOp op_id = bin_op_instruction->op_id; - if (op1->value.type->id == TypeTableEntryIdComptimeInt) { + if (op1->value.type->id == ZigTypeIdComptimeInt) { casted_op2 = op2; if (op_id == IrBinOpBitShiftLeftLossy) { @@ -11920,7 +11920,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_ ZigType *shift_amt_type = get_smallest_unsigned_int_type(ira->codegen, op1->value.type->data.integral.bit_count - 1); if (bin_op_instruction->op_id == IrBinOpBitShiftLeftLossy && - op2->value.type->id == TypeTableEntryIdComptimeInt) { + op2->value.type->id == ZigTypeIdComptimeInt) { if (!bigint_fits_in_bits(&op2->value.data.x_bigint, shift_amt_type->data.integral.bit_count, op2->value.data.x_bigint.is_negative)) { @@ -11974,7 +11974,7 @@ static ZigType *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *bin_op_ ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false); return op1->value.type; - } else if (op1->value.type->id == TypeTableEntryIdComptimeInt) { + } else if (op1->value.type->id == ZigTypeIdComptimeInt) { ir_add_error(ira, &bin_op_instruction->base, buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); return ira->codegen->builtin_types.entry_invalid; @@ -11997,7 +11997,7 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o IrBinOp op_id = bin_op_instruction->op_id; // look for pointer math - if (op1->value.type->id == TypeTableEntryIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown && + if (op1->value.type->id == ZigTypeIdPointer && op1->value.type->data.pointer.ptr_len == PtrLenUnknown && (op_id == IrBinOpAdd || op_id == IrBinOpSub)) { IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, ira->codegen->builtin_types.entry_usize); @@ -12016,15 +12016,15 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o if (type_is_invalid(resolved_type)) return resolved_type; - bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdComptimeInt; - bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdComptimeFloat; + bool is_int = resolved_type->id == ZigTypeIdInt || resolved_type->id == ZigTypeIdComptimeInt; + bool is_float = resolved_type->id == ZigTypeIdFloat || resolved_type->id == ZigTypeIdComptimeFloat; bool is_signed_div = ( - (resolved_type->id == TypeTableEntryIdInt && resolved_type->data.integral.is_signed) || - resolved_type->id == TypeTableEntryIdFloat || - (resolved_type->id == TypeTableEntryIdComptimeFloat && + (resolved_type->id == ZigTypeIdInt && resolved_type->data.integral.is_signed) || + resolved_type->id == ZigTypeIdFloat || + (resolved_type->id == ZigTypeIdComptimeFloat && ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) != (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) || - (resolved_type->id == TypeTableEntryIdComptimeInt && + (resolved_type->id == ZigTypeIdComptimeInt && ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) != (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT))) ); @@ -12146,7 +12146,7 @@ static ZigType *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp *bin_o return ira->codegen->builtin_types.entry_invalid; } - if (resolved_type->id == TypeTableEntryIdComptimeInt) { + if (resolved_type->id == ZigTypeIdComptimeInt) { if (op_id == IrBinOpAddWrap) { op_id = IrBinOpAdd; } else if (op_id == IrBinOpSubWrap) { @@ -12229,12 +12229,12 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc size_t op1_array_index; size_t op1_array_end; ZigType *child_type; - if (op1_type->id == TypeTableEntryIdArray) { + if (op1_type->id == ZigTypeIdArray) { child_type = op1_type->data.array.child_type; op1_array_val = op1_val; op1_array_index = 0; op1_array_end = op1_type->data.array.len; - } else if (op1_type->id == TypeTableEntryIdPointer && + } else if (op1_type->id == ZigTypeIdPointer && op1_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && op1_val->data.x_ptr.special == ConstPtrSpecialBaseArray && op1_val->data.x_ptr.data.base_array.is_cstr) @@ -12260,7 +12260,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc ConstExprValue *op2_array_val; size_t op2_array_index; size_t op2_array_end; - if (op2_type->id == TypeTableEntryIdArray) { + if (op2_type->id == ZigTypeIdArray) { if (op2_type->data.array.child_type != child_type) { ir_add_error(ira, op2, buf_sprintf("expected array of type '%s', found '%s'", buf_ptr(&child_type->name), @@ -12270,7 +12270,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc op2_array_val = op2_val; op2_array_index = 0; op2_array_end = op2_array_val->type->data.array.len; - } else if (op2_type->id == TypeTableEntryIdPointer && + } else if (op2_type->id == ZigTypeIdPointer && op2_type->data.pointer.child_type == ira->codegen->builtin_types.entry_u8 && op2_val->data.x_ptr.special == ConstPtrSpecialBaseArray && op2_val->data.x_ptr.data.base_array.is_cstr) @@ -12308,7 +12308,7 @@ static ZigType *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruc ZigType *result_type; ConstExprValue *out_array_val; size_t new_len = (op1_array_end - op1_array_index) + (op2_array_end - op2_array_index); - if (op1_type->id == TypeTableEntryIdArray || op2_type->id == TypeTableEntryIdArray) { + if (op1_type->id == ZigTypeIdArray || op2_type->id == ZigTypeIdArray) { result_type = get_array_type(ira->codegen, child_type, new_len); out_array_val = out_val; @@ -12392,7 +12392,7 @@ static ZigType *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instru return ira->codegen->builtin_types.entry_invalid; ZigType *array_type = op1->value.type; - if (array_type->id != TypeTableEntryIdArray) { + if (array_type->id != ZigTypeIdArray) { ir_add_error(ira, op1, buf_sprintf("expected array type, found '%s'", buf_ptr(&op1->value.type->name))); return ira->codegen->builtin_types.entry_invalid; } @@ -12555,8 +12555,8 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec } if (!type_is_invalid(result_type)) { - if (result_type->id == TypeTableEntryIdUnreachable || - result_type->id == TypeTableEntryIdOpaque) + if (result_type->id == ZigTypeIdUnreachable || + result_type->id == ZigTypeIdOpaque) { ir_add_error_node(ira, source_node, buf_sprintf("variable of type '%s' not allowed", buf_ptr(&result_type->name))); @@ -12571,7 +12571,7 @@ static ZigType *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstructionDec } } else { if (casted_init_value->value.special == ConstValSpecialStatic && - casted_init_value->value.type->id == TypeTableEntryIdFn && + casted_init_value->value.type->id == ZigTypeIdFn && casted_init_value->value.data.x_ptr.data.fn.fn_entry->fn_inline == FnInlineAlways) { var_class_requires_const = true; @@ -12680,10 +12680,10 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor } switch (target->value.type->id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdUnreachable: + case ZigTypeIdInvalid: + case ZigTypeIdUnreachable: zig_unreachable(); - case TypeTableEntryIdFn: { + case ZigTypeIdFn: { assert(target->value.data.x_ptr.special == ConstPtrSpecialFunction); ZigFn *fn_entry = target->value.data.x_ptr.data.fn.fn_entry; CallingConvention cc = fn_entry->type_entry->data.fn.fn_type_id.cc; @@ -12706,7 +12706,7 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor break; } } break; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: if (is_slice(target->value.type)) { ir_add_error(ira, target, buf_sprintf("unable to export value of type '%s'", buf_ptr(&target->value.type->name))); @@ -12716,26 +12716,26 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor add_error_note(ira->codegen, msg, target->value.type->data.structure.decl_node, buf_sprintf("declared here")); } break; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: if (target->value.type->data.unionation.layout != ContainerLayoutExtern) { ErrorMsg *msg = ir_add_error(ira, target, buf_sprintf("exported union value must be declared extern")); add_error_note(ira->codegen, msg, target->value.type->data.unionation.decl_node, buf_sprintf("declared here")); } break; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: if (target->value.type->data.enumeration.layout != ContainerLayoutExtern) { ErrorMsg *msg = ir_add_error(ira, target, buf_sprintf("exported enum value must be declared extern")); add_error_note(ira->codegen, msg, target->value.type->data.enumeration.decl_node, buf_sprintf("declared here")); } break; - case TypeTableEntryIdMetaType: { + case ZigTypeIdMetaType: { ZigType *type_value = target->value.data.x_type; switch (type_value->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: if (is_slice(type_value)) { ir_add_error(ira, target, buf_sprintf("unable to export type '%s'", buf_ptr(&type_value->name))); @@ -12745,73 +12745,73 @@ static ZigType *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructionExpor add_error_note(ira->codegen, msg, type_value->data.structure.decl_node, buf_sprintf("declared here")); } break; - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: if (type_value->data.unionation.layout != ContainerLayoutExtern) { ErrorMsg *msg = ir_add_error(ira, target, buf_sprintf("exported union must be declared extern")); add_error_note(ira->codegen, msg, type_value->data.unionation.decl_node, buf_sprintf("declared here")); } break; - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: if (type_value->data.enumeration.layout != ContainerLayoutExtern) { ErrorMsg *msg = ir_add_error(ira, target, buf_sprintf("exported enum must be declared extern")); add_error_note(ira->codegen, msg, type_value->data.enumeration.decl_node, buf_sprintf("declared here")); } break; - case TypeTableEntryIdFn: { + case ZigTypeIdFn: { if (type_value->data.fn.fn_type_id.cc == CallingConventionUnspecified) { ir_add_error(ira, target, buf_sprintf("exported function type must specify calling convention")); } } break; - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdBool: break; - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdPromise: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: + case ZigTypeIdPromise: ir_add_error(ira, target, buf_sprintf("invalid export target '%s'", buf_ptr(&type_value->name))); break; } } break; - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: zig_panic("TODO export const value of type %s", buf_ptr(&target->value.type->name)); - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdPromise: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: + case ZigTypeIdPromise: ir_add_error(ira, target, buf_sprintf("invalid export target type '%s'", buf_ptr(&target->value.type->name))); break; @@ -12863,7 +12863,7 @@ static ZigType *ir_analyze_instruction_error_union(IrAnalyze *ira, if (type_is_invalid(payload_type)) return ira->codegen->builtin_types.entry_invalid; - if (err_set_type->id != TypeTableEntryIdErrorSet) { + if (err_set_type->id != ZigTypeIdErrorSet) { ir_add_error(ira, instruction->err_set->other, buf_sprintf("expected error set type, found type '%s'", buf_ptr(&err_set_type->name))); @@ -12918,7 +12918,7 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c { Buf *alloc_field_name = buf_create_from_str(ASYNC_ALLOC_FIELD_NAME); //Buf *free_field_name = buf_create_from_str("freeFn"); - assert(async_allocator_inst->value.type->id == TypeTableEntryIdPointer); + assert(async_allocator_inst->value.type->id == ZigTypeIdPointer); ZigType *container_type = async_allocator_inst->value.type->data.pointer.child_type; IrInstruction *field_ptr_inst = ir_analyze_container_field_ptr(ira, alloc_field_name, &call_instruction->base, async_allocator_inst, container_type); @@ -12926,17 +12926,17 @@ static IrInstruction *ir_analyze_async_call(IrAnalyze *ira, IrInstructionCall *c return ira->codegen->invalid_instruction; } ZigType *ptr_to_alloc_fn_type = field_ptr_inst->value.type; - assert(ptr_to_alloc_fn_type->id == TypeTableEntryIdPointer); + assert(ptr_to_alloc_fn_type->id == ZigTypeIdPointer); ZigType *alloc_fn_type = ptr_to_alloc_fn_type->data.pointer.child_type; - if (alloc_fn_type->id != TypeTableEntryIdFn) { + if (alloc_fn_type->id != ZigTypeIdFn) { ir_add_error(ira, &call_instruction->base, buf_sprintf("expected allocation function, found '%s'", buf_ptr(&alloc_fn_type->name))); return ira->codegen->invalid_instruction; } ZigType *alloc_fn_return_type = alloc_fn_type->data.fn.fn_type_id.return_type; - if (alloc_fn_return_type->id != TypeTableEntryIdErrorUnion) { + if (alloc_fn_return_type->id != ZigTypeIdErrorUnion) { ir_add_error(ira, fn_ref, buf_sprintf("expected allocation function to return error union, but it returns '%s'", buf_ptr(&alloc_fn_return_type->name))); return ira->codegen->invalid_instruction; @@ -13015,7 +13015,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod } bool comptime_arg = param_decl_node->data.param_decl.is_inline || - casted_arg->value.type->id == TypeTableEntryIdComptimeInt || casted_arg->value.type->id == TypeTableEntryIdComptimeFloat; + casted_arg->value.type->id == ZigTypeIdComptimeInt || casted_arg->value.type->id == ZigTypeIdComptimeFloat; ConstExprValue *arg_val; @@ -13041,8 +13041,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod var->shadowable = !comptime_arg; *next_proto_i += 1; - } else if (casted_arg->value.type->id == TypeTableEntryIdComptimeInt || - casted_arg->value.type->id == TypeTableEntryIdComptimeFloat) + } else if (casted_arg->value.type->id == ZigTypeIdComptimeInt || + casted_arg->value.type->id == ZigTypeIdComptimeFloat) { ir_add_error(ira, casted_arg, buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557")); @@ -13177,7 +13177,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; for (size_t i = 0; i < call_instruction->arg_count; i += 1) { ConstExprValue *arg_tuple_value = &call_instruction->args[i]->other->value; - if (arg_tuple_value->type->id == TypeTableEntryIdArgTuple) { + if (arg_tuple_value->type->id == ZigTypeIdArgTuple) { call_param_count -= 1; call_param_count += arg_tuple_value->data.x_arg_tuple.end_index - arg_tuple_value->data.x_arg_tuple.start_index; @@ -13245,14 +13245,14 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr size_t next_proto_i = 0; if (first_arg_ptr) { - assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer); + assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); bool first_arg_known_bare = false; if (fn_type_id->next_param_index >= 1) { ZigType *param_type = fn_type_id->param_info[next_proto_i].type; if (type_is_invalid(param_type)) return ira->codegen->builtin_types.entry_invalid; - first_arg_known_bare = param_type->id != TypeTableEntryIdPointer; + first_arg_known_bare = param_type->id != ZigTypeIdPointer; } IrInstruction *first_arg; @@ -13314,7 +13314,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr if (inferred_err_set_type != nullptr) { inferred_err_set_type->data.error_set.infer_fn = nullptr; - if (result->value.type->id == TypeTableEntryIdErrorUnion) { + if (result->value.type->id == ZigTypeIdErrorUnion) { if (result->value.data.x_err_union.err != nullptr) { inferred_err_set_type->data.error_set.err_count = 1; inferred_err_set_type->data.error_set.errors = allocate(1); @@ -13323,7 +13323,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr ZigType *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type; inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count; inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors; - } else if (result->value.type->id == TypeTableEntryIdErrorSet) { + } else if (result->value.type->id == ZigTypeIdErrorSet) { inferred_err_set_type->data.error_set.err_count = result->value.type->data.error_set.err_count; inferred_err_set_type->data.error_set.errors = result->value.type->data.error_set.errors; } @@ -13371,7 +13371,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr if (type_is_invalid(arg->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (arg->value.type->id == TypeTableEntryIdArgTuple) { + if (arg->value.type->id == ZigTypeIdArgTuple) { new_fn_arg_count += arg->value.data.x_arg_tuple.end_index - arg->value.data.x_arg_tuple.start_index; } else { new_fn_arg_count += 1; @@ -13401,14 +13401,14 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr size_t next_proto_i = 0; if (first_arg_ptr) { - assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer); + assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); bool first_arg_known_bare = false; if (fn_type_id->next_param_index >= 1) { ZigType *param_type = fn_type_id->param_info[next_proto_i].type; if (type_is_invalid(param_type)) return ira->codegen->builtin_types.entry_invalid; - first_arg_known_bare = param_type->id != TypeTableEntryIdPointer; + first_arg_known_bare = param_type->id != ZigTypeIdPointer; } IrInstruction *first_arg; @@ -13437,7 +13437,7 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr if (type_is_invalid(arg->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (arg->value.type->id == TypeTableEntryIdArgTuple) { + if (arg->value.type->id == ZigTypeIdArgTuple) { for (size_t arg_tuple_i = arg->value.data.x_arg_tuple.start_index; arg_tuple_i < arg->value.data.x_arg_tuple.end_index; arg_tuple_i += 1) { @@ -13616,14 +13616,14 @@ static ZigType *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *call_instr IrInstruction **casted_args = allocate(call_param_count); size_t next_arg_index = 0; if (first_arg_ptr) { - assert(first_arg_ptr->value.type->id == TypeTableEntryIdPointer); + assert(first_arg_ptr->value.type->id == ZigTypeIdPointer); ZigType *param_type = fn_type_id->param_info[next_arg_index].type; if (type_is_invalid(param_type)) return ira->codegen->builtin_types.entry_invalid; IrInstruction *first_arg; - if (param_type->id == TypeTableEntryIdPointer && + if (param_type->id == ZigTypeIdPointer && handle_is_ptr(first_arg_ptr->value.type->data.pointer.child_type)) { first_arg = first_arg_ptr; @@ -13712,7 +13712,7 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c ir_should_inline(ira->new_irb.exec, call_instruction->base.scope); if (is_comptime || instr_is_comptime(fn_ref)) { - if (fn_ref->value.type->id == TypeTableEntryIdMetaType) { + if (fn_ref->value.type->id == ZigTypeIdMetaType) { ZigType *dest_type = ir_resolve_type(ira, fn_ref); if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; @@ -13733,13 +13733,13 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c ir_link_new_instruction(cast_instruction, &call_instruction->base); return ir_finish_anal(ira, cast_instruction->value.type); - } else if (fn_ref->value.type->id == TypeTableEntryIdFn) { + } else if (fn_ref->value.type->id == ZigTypeIdFn) { ZigFn *fn_table_entry = ir_resolve_fn(ira, fn_ref); if (fn_table_entry == nullptr) return ira->codegen->builtin_types.entry_invalid; return ir_analyze_fn_call(ira, call_instruction, fn_table_entry, fn_table_entry->type_entry, fn_ref, nullptr, is_comptime, call_instruction->fn_inline); - } else if (fn_ref->value.type->id == TypeTableEntryIdBoundFn) { + } else if (fn_ref->value.type->id == ZigTypeIdBoundFn) { assert(fn_ref->value.special == ConstValSpecialStatic); ZigFn *fn_table_entry = fn_ref->value.data.x_bound_fn.fn; IrInstruction *first_arg_ptr = fn_ref->value.data.x_bound_fn.first_arg; @@ -13752,7 +13752,7 @@ static ZigType *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *c } } - if (fn_ref->value.type->id == TypeTableEntryIdFn) { + if (fn_ref->value.type->id == ZigTypeIdFn) { return ir_analyze_fn_call(ira, call_instruction, nullptr, fn_ref->value.type, fn_ref, nullptr, false, FnInlineAuto); } else { @@ -13801,7 +13801,7 @@ static ZigType *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp *un_op_ ZigType *child_type; if (type_is_invalid(ptr_type)) { return ira->codegen->builtin_types.entry_invalid; - } else if (ptr_type->id == TypeTableEntryIdPointer) { + } else if (ptr_type->id == ZigTypeIdPointer) { if (ptr_type->data.pointer.ptr_len == PtrLenUnknown) { ir_add_error_node(ira, un_op_instruction->base.source_node, buf_sprintf("index syntax required for unknown-length pointer type '%s'", @@ -13845,38 +13845,38 @@ static ZigType *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op_instru return ira->codegen->builtin_types.entry_invalid; switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdPromise: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdPromise: { ConstExprValue *out_val = ir_build_const_from(ira, &un_op_instruction->base); out_val->data.x_type = get_optional_type(ira->codegen, type_entry); return ira->codegen->builtin_types.entry_type; } - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdOpaque: + case ZigTypeIdUnreachable: + case ZigTypeIdOpaque: ir_add_error_node(ira, un_op_instruction->base.source_node, buf_sprintf("type '%s' not optional", buf_ptr(&type_entry->name))); return ira->codegen->builtin_types.entry_invalid; @@ -13892,10 +13892,10 @@ static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_ins bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap); - bool is_float = (expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdComptimeFloat); + bool is_float = (expr_type->id == ZigTypeIdFloat || expr_type->id == ZigTypeIdComptimeFloat); - if ((expr_type->id == TypeTableEntryIdInt && expr_type->data.integral.is_signed) || - expr_type->id == TypeTableEntryIdComptimeInt || (is_float && !is_wrap_op)) + if ((expr_type->id == ZigTypeIdInt && expr_type->data.integral.is_signed) || + expr_type->id == ZigTypeIdComptimeInt || (is_float && !is_wrap_op)) { if (instr_is_comptime(value)) { ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); @@ -13911,7 +13911,7 @@ static ZigType *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_ins } else { bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint); } - if (is_wrap_op || is_float || expr_type->id == TypeTableEntryIdComptimeInt) { + if (is_wrap_op || is_float || expr_type->id == ZigTypeIdComptimeInt) { return expr_type; } @@ -13937,7 +13937,7 @@ static ZigType *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instructio if (type_is_invalid(expr_type)) return ira->codegen->builtin_types.entry_invalid; - if (expr_type->id == TypeTableEntryIdInt) { + if (expr_type->id == ZigTypeIdInt) { if (instr_is_comptime(value)) { ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); if (target_const_val == nullptr) @@ -14082,7 +14082,7 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi IrInstruction *old_value = phi_instruction->incoming_values[i]; assert(old_value); IrInstruction *new_value = old_value->other; - if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable || predecessor->other == nullptr) + if (!new_value || new_value->value.type->id == ZigTypeIdUnreachable || predecessor->other == nullptr) continue; if (type_is_invalid(new_value->value.type)) @@ -14110,17 +14110,17 @@ static ZigType *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPhi *phi if (type_is_invalid(resolved_type)) return resolved_type; - if (resolved_type->id == TypeTableEntryIdComptimeFloat || - resolved_type->id == TypeTableEntryIdComptimeInt || - resolved_type->id == TypeTableEntryIdNull || - resolved_type->id == TypeTableEntryIdUndefined) + if (resolved_type->id == ZigTypeIdComptimeFloat || + resolved_type->id == ZigTypeIdComptimeInt || + resolved_type->id == ZigTypeIdNull || + resolved_type->id == ZigTypeIdUndefined) { ir_add_error_node(ira, phi_instruction->base.source_node, buf_sprintf("unable to infer expression type")); return ira->codegen->builtin_types.entry_invalid; } - bool all_stack_ptrs = (resolved_type->id == TypeTableEntryIdPointer); + bool all_stack_ptrs = (resolved_type->id == ZigTypeIdPointer); // cast all values to the resolved type. however we can't put cast instructions in front of the phi instruction. // so we go back and insert the casts as the last instruction in the corresponding predecessor blocks, and @@ -14171,7 +14171,7 @@ static ZigType *ir_analyze_instruction_var_ptr(IrAnalyze *ira, IrInstructionVarP } static ZigType *adjust_ptr_align(CodeGen *g, ZigType *ptr_type, uint32_t new_align) { - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); return get_pointer_to_type_extra(g, ptr_type->data.pointer.child_type, ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, @@ -14188,7 +14188,7 @@ static ZigType *adjust_slice_align(CodeGen *g, ZigType *slice_type, uint32_t new } static ZigType *adjust_ptr_len(CodeGen *g, ZigType *ptr_type, PtrLen ptr_len) { - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); return get_pointer_to_type_extra(g, ptr_type->data.pointer.child_type, ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile, @@ -14210,7 +14210,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle return ira->codegen->builtin_types.entry_invalid; ZigType *ptr_type = orig_array_ptr_val->type; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ZigType *array_type = ptr_type->data.pointer.child_type; @@ -14220,12 +14220,12 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle if (type_is_invalid(array_type)) { return array_type; - } else if (array_type->id == TypeTableEntryIdArray || - (array_type->id == TypeTableEntryIdPointer && + } else if (array_type->id == ZigTypeIdArray || + (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle && - array_type->data.pointer.child_type->id == TypeTableEntryIdArray)) + array_type->data.pointer.child_type->id == ZigTypeIdArray)) { - if (array_type->id == TypeTableEntryIdPointer) { + if (array_type->id == ZigTypeIdPointer) { array_type = array_type->data.pointer.child_type; ptr_type = ptr_type->data.pointer.child_type; if (orig_array_ptr_val->special != ConstValSpecialRuntime) { @@ -14259,7 +14259,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle elem_ptr_instruction->ptr_len, 1, (uint32_t)bit_offset, (uint32_t)bit_width); } - } else if (array_type->id == TypeTableEntryIdPointer) { + } else if (array_type->id == ZigTypeIdPointer) { if (array_type->data.pointer.ptr_len == PtrLenSingle) { ir_add_error_node(ira, elem_ptr_instruction->base.source_node, buf_sprintf("index of single-item pointer")); @@ -14269,7 +14269,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle } else if (is_slice(array_type)) { return_type = adjust_ptr_len(ira->codegen, array_type->data.structure.fields[slice_ptr_index].type_entry, elem_ptr_instruction->ptr_len); - } else if (array_type->id == TypeTableEntryIdArgTuple) { + } else if (array_type->id == ZigTypeIdArgTuple) { ConstExprValue *ptr_val = ir_resolve_const(ira, array_ptr, UndefBad); if (!ptr_val) return ira->codegen->builtin_types.entry_invalid; @@ -14320,7 +14320,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle uint64_t ptr_align = return_type->data.pointer.alignment; if (instr_is_comptime(casted_elem_index)) { uint64_t index = bigint_as_unsigned(&casted_elem_index->value.data.x_bigint); - if (array_type->id == TypeTableEntryIdArray) { + if (array_type->id == ZigTypeIdArray) { uint64_t array_len = array_type->data.array.len; if (index >= array_len) { ir_add_error_node(ira, elem_ptr_instruction->base.source_node, @@ -14353,7 +14353,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle if (orig_array_ptr_val->special != ConstValSpecialRuntime && (orig_array_ptr_val->data.x_ptr.mut != ConstPtrMutRuntimeVar || - array_type->id == TypeTableEntryIdArray)) + array_type->id == ZigTypeIdArray)) { ConstExprValue *array_ptr_val = ir_const_ptr_pointee(ira, orig_array_ptr_val, elem_ptr_instruction->base.source_node); @@ -14361,10 +14361,10 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle return ira->codegen->builtin_types.entry_invalid; if (array_ptr_val->special != ConstValSpecialRuntime && - (array_type->id != TypeTableEntryIdPointer || + (array_type->id != ZigTypeIdPointer || array_ptr_val->data.x_ptr.special != ConstPtrSpecialHardCodedAddr)) { - if (array_type->id == TypeTableEntryIdPointer) { + if (array_type->id == ZigTypeIdPointer) { ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); out_val->data.x_ptr.mut = array_ptr_val->data.x_ptr.mut; size_t new_index; @@ -14461,7 +14461,7 @@ static ZigType *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionEle zig_panic("TODO elem ptr on a slice that was ptrcast from a function"); } return return_type; - } else if (array_type->id == TypeTableEntryIdArray) { + } else if (array_type->id == ZigTypeIdArray) { ConstExprValue *out_val = ir_build_const_from(ira, &elem_ptr_instruction->base); out_val->data.x_ptr.special = ConstPtrSpecialBaseArray; out_val->data.x_ptr.mut = orig_array_ptr_val->data.x_ptr.mut; @@ -14521,11 +14521,11 @@ static IrInstruction *ir_analyze_container_member_access_inner(IrAnalyze *ira, const char *prefix_name; if (is_slice(bare_struct_type)) { prefix_name = ""; - } else if (bare_struct_type->id == TypeTableEntryIdStruct) { + } else if (bare_struct_type->id == ZigTypeIdStruct) { prefix_name = "struct "; - } else if (bare_struct_type->id == TypeTableEntryIdEnum) { + } else if (bare_struct_type->id == ZigTypeIdEnum) { prefix_name = "enum "; - } else if (bare_struct_type->id == TypeTableEntryIdUnion) { + } else if (bare_struct_type->id == ZigTypeIdUnion) { prefix_name = "union "; } else { prefix_name = ""; @@ -14544,10 +14544,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ if ((err = ensure_complete_type(ira->codegen, bare_type))) return ira->codegen->invalid_instruction; - assert(container_ptr->value.type->id == TypeTableEntryIdPointer); + assert(container_ptr->value.type->id == ZigTypeIdPointer); bool is_const = container_ptr->value.type->data.pointer.is_const; bool is_volatile = container_ptr->value.type->data.pointer.is_volatile; - if (bare_type->id == TypeTableEntryIdStruct) { + if (bare_type->id == ZigTypeIdStruct) { TypeStructField *field = find_struct_type_field(bare_type, field_name); if (field) { bool is_packed = (bare_type->data.structure.layout == ContainerLayoutPacked); @@ -14594,10 +14594,10 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ return ir_analyze_container_member_access_inner(ira, bare_type, field_name, source_instr, container_ptr, container_type); } - } else if (bare_type->id == TypeTableEntryIdEnum) { + } else if (bare_type->id == ZigTypeIdEnum) { return ir_analyze_container_member_access_inner(ira, bare_type, field_name, source_instr, container_ptr, container_type); - } else if (bare_type->id == TypeTableEntryIdUnion) { + } else if (bare_type->id == ZigTypeIdUnion) { TypeUnionField *field = find_union_type_field(bare_type, field_name); if (field) { if (instr_is_comptime(container_ptr)) { @@ -14626,7 +14626,7 @@ static IrInstruction *ir_analyze_container_field_ptr(IrAnalyze *ira, Buf *field_ ConstExprValue *payload_val = union_val->data.x_union.payload; ZigType *field_type = field->type_entry; - if (field_type->id == TypeTableEntryIdVoid) { + if (field_type->id == ZigTypeIdVoid) { assert(payload_val == nullptr); payload_val = create_const_vals(1); payload_val->special = ConstValSpecialStatic; @@ -14732,7 +14732,7 @@ static ZigType *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source_instru } static ErrorTableEntry *find_err_table_entry(ZigType *err_set_type, Buf *field_name) { - assert(err_set_type->id == TypeTableEntryIdErrorSet); + assert(err_set_type->id == ZigTypeIdErrorSet); for (uint32_t i = 0; i < err_set_type->data.error_set.err_count; i += 1) { ErrorTableEntry *err_table_entry = err_set_type->data.error_set.errors[i]; if (buf_eql_buf(&err_table_entry->name, field_name)) { @@ -14749,7 +14749,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi return ira->codegen->builtin_types.entry_invalid; ZigType *container_type = container_ptr->value.type->data.pointer.child_type; - assert(container_ptr->value.type->id == TypeTableEntryIdPointer); + assert(container_ptr->value.type->id == ZigTypeIdPointer); Buf *field_name = field_ptr_instruction->field_name_buffer; if (!field_name) { @@ -14765,8 +14765,8 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi if (type_is_invalid(container_type)) { return container_type; } else if (is_container_ref(container_type)) { - assert(container_ptr->value.type->id == TypeTableEntryIdPointer); - if (container_type->id == TypeTableEntryIdPointer) { + assert(container_ptr->value.type->id == ZigTypeIdPointer); + if (container_type->id == ZigTypeIdPointer) { ZigType *bare_type = container_ref_type(container_type); IrInstruction *container_child = ir_get_deref(ira, &field_ptr_instruction->base, container_ptr); IrInstruction *result = ir_analyze_container_field_ptr(ira, field_name, &field_ptr_instruction->base, container_child, bare_type); @@ -14780,7 +14780,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi } else if (is_array_ref(container_type)) { if (buf_eql_str(field_name, "len")) { ConstExprValue *len_val = create_const_vals(1); - if (container_type->id == TypeTableEntryIdPointer) { + if (container_type->id == ZigTypeIdPointer) { init_const_usize(ira->codegen, len_val, container_type->data.pointer.child_type->data.array.len); } else { init_const_usize(ira->codegen, len_val, container_type->data.array.len); @@ -14797,12 +14797,12 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi buf_ptr(&container_type->name))); return ira->codegen->builtin_types.entry_invalid; } - } else if (container_type->id == TypeTableEntryIdArgTuple) { + } else if (container_type->id == ZigTypeIdArgTuple) { ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); if (!container_ptr_val) return ira->codegen->builtin_types.entry_invalid; - assert(container_ptr->value.type->id == TypeTableEntryIdPointer); + assert(container_ptr->value.type->id == ZigTypeIdPointer); ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node); if (child_val == nullptr) return ira->codegen->builtin_types.entry_invalid; @@ -14823,12 +14823,12 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi buf_ptr(&container_type->name))); return ira->codegen->builtin_types.entry_invalid; } - } else if (container_type->id == TypeTableEntryIdMetaType) { + } else if (container_type->id == ZigTypeIdMetaType) { ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); if (!container_ptr_val) return ira->codegen->builtin_types.entry_invalid; - assert(container_ptr->value.type->id == TypeTableEntryIdPointer); + assert(container_ptr->value.type->id == ZigTypeIdPointer); ConstExprValue *child_val = ir_const_ptr_pointee(ira, container_ptr_val, source_node); if (child_val == nullptr) return ira->codegen->builtin_types.entry_invalid; @@ -14841,14 +14841,14 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi bool ptr_is_const = true; bool ptr_is_volatile = false; TypeStructField *ptr_field = &child_type->data.structure.fields[slice_ptr_index]; - assert(ptr_field->type_entry->id == TypeTableEntryIdPointer); + assert(ptr_field->type_entry->id == ZigTypeIdPointer); ZigType *child_type = ptr_field->type_entry->data.pointer.child_type; return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, create_const_type(ira->codegen, child_type), ira->codegen->builtin_types.entry_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); } - if (child_type->id == TypeTableEntryIdEnum) { + if (child_type->id == ZigTypeIdEnum) { if ((err = ensure_complete_type(ira->codegen, child_type))) return ira->codegen->builtin_types.entry_invalid; @@ -14869,7 +14869,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi return ir_analyze_decl_ref(ira, &field_ptr_instruction->base, tld); } } - if (child_type->id == TypeTableEntryIdUnion && + if (child_type->id == ZigTypeIdUnion && (child_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr || child_type->data.unionation.decl_node->data.container_decl.auto_enum)) { @@ -14889,7 +14889,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi buf_sprintf("container '%s' has no member called '%s'", buf_ptr(&child_type->name), buf_ptr(field_name))); return ira->codegen->builtin_types.entry_invalid; - } else if (child_type->id == TypeTableEntryIdErrorSet) { + } else if (child_type->id == ZigTypeIdErrorSet) { ErrorTableEntry *err_entry; ZigType *err_set_type; if (type_is_global_error_set(child_type)) { @@ -14935,7 +14935,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi bool ptr_is_volatile = false; return ir_analyze_const_ptr(ira, &field_ptr_instruction->base, const_val, err_set_type, ConstPtrMutComptimeConst, ptr_is_const, ptr_is_volatile); - } else if (child_type->id == TypeTableEntryIdInt) { + } else if (child_type->id == ZigTypeIdInt) { if (buf_eql_str(field_name, "bit_count")) { bool ptr_is_const = true; bool ptr_is_volatile = false; @@ -14957,7 +14957,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi buf_ptr(&child_type->name), buf_ptr(field_name))); return ira->codegen->builtin_types.entry_invalid; } - } else if (child_type->id == TypeTableEntryIdFloat) { + } else if (child_type->id == ZigTypeIdFloat) { if (buf_eql_str(field_name, "bit_count")) { bool ptr_is_const = true; bool ptr_is_volatile = false; @@ -14972,7 +14972,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi buf_ptr(&child_type->name), buf_ptr(field_name))); return ira->codegen->builtin_types.entry_invalid; } - } else if (child_type->id == TypeTableEntryIdPointer) { + } else if (child_type->id == ZigTypeIdPointer) { if (buf_eql_str(field_name, "Child")) { bool ptr_is_const = true; bool ptr_is_volatile = false; @@ -14994,7 +14994,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi buf_ptr(&child_type->name), buf_ptr(field_name))); return ira->codegen->builtin_types.entry_invalid; } - } else if (child_type->id == TypeTableEntryIdArray) { + } else if (child_type->id == ZigTypeIdArray) { if (buf_eql_str(field_name, "Child")) { bool ptr_is_const = true; bool ptr_is_volatile = false; @@ -15016,7 +15016,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi buf_ptr(&child_type->name), buf_ptr(field_name))); return ira->codegen->builtin_types.entry_invalid; } - } else if (child_type->id == TypeTableEntryIdErrorUnion) { + } else if (child_type->id == ZigTypeIdErrorUnion) { if (buf_eql_str(field_name, "Payload")) { bool ptr_is_const = true; bool ptr_is_volatile = false; @@ -15037,7 +15037,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi buf_ptr(&child_type->name), buf_ptr(field_name))); return ira->codegen->builtin_types.entry_invalid; } - } else if (child_type->id == TypeTableEntryIdOptional) { + } else if (child_type->id == ZigTypeIdOptional) { if (buf_eql_str(field_name, "Child")) { bool ptr_is_const = true; bool ptr_is_volatile = false; @@ -15051,7 +15051,7 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi buf_ptr(&child_type->name), buf_ptr(field_name))); return ira->codegen->builtin_types.entry_invalid; } - } else if (child_type->id == TypeTableEntryIdFn) { + } else if (child_type->id == ZigTypeIdFn) { if (buf_eql_str(field_name, "ReturnType")) { if (child_type->data.fn.fn_type_id.return_type == nullptr) { // Return type can only ever be null, if the function is generic @@ -15093,8 +15093,8 @@ static ZigType *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFi buf_sprintf("type '%s' does not support field access", buf_ptr(&child_type->name))); return ira->codegen->builtin_types.entry_invalid; } - } else if (container_type->id == TypeTableEntryIdNamespace) { - assert(container_ptr->value.type->id == TypeTableEntryIdPointer); + } else if (container_type->id == ZigTypeIdNamespace) { + assert(container_ptr->value.type->id == ZigTypeIdPointer); ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad); if (!container_ptr_val) return ira->codegen->builtin_types.entry_invalid; @@ -15151,7 +15151,7 @@ static ZigType *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionSt if (type_is_invalid(value->value.type)) return value->value.type; - if (ptr->value.type->id != TypeTableEntryIdPointer) { + if (ptr->value.type->id != ZigTypeIdPointer) { ir_add_error(ira, ptr, buf_sprintf("attempt to dereference non pointer type '%s'", buf_ptr(&ptr->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -15208,33 +15208,33 @@ static ZigType *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeO if (type_is_invalid(type_entry)) return ira->codegen->builtin_types.entry_invalid; switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); // handled above - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdPromise: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: + case ZigTypeIdPromise: { ConstExprValue *out_val = ir_build_const_from(ira, &typeof_instruction->base); out_val->data.x_type = type_entry; @@ -15255,11 +15255,11 @@ static ZigType *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira, return type_entry; ZigType *ptr_type; - if (type_entry->id == TypeTableEntryIdArray) { + if (type_entry->id == ZigTypeIdArray) { ptr_type = get_pointer_to_type(ira->codegen, type_entry->data.array.child_type, false); } else if (is_slice(type_entry)) { ptr_type = adjust_ptr_len(ira->codegen, type_entry->data.structure.fields[0].type_entry, PtrLenSingle); - } else if (type_entry->id == TypeTableEntryIdArgTuple) { + } else if (type_entry->id == ZigTypeIdArgTuple) { ConstExprValue *arg_tuple_val = ir_resolve_const(ira, value, UndefBad); if (!arg_tuple_val) return ira->codegen->builtin_types.entry_invalid; @@ -15283,7 +15283,7 @@ static ZigType *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira, if (type_is_invalid(type_entry)) return type_entry; - if (type_entry->id != TypeTableEntryIdPointer) { + if (type_entry->id != ZigTypeIdPointer) { ir_add_error_node(ira, ptr_type_child_instruction->base.source_node, buf_sprintf("expected pointer type, found '%s'", buf_ptr(&type_entry->name))); return ira->codegen->builtin_types.entry_invalid; @@ -15400,24 +15400,24 @@ static ZigType *ir_analyze_instruction_set_float_mode(IrAnalyze *ira, bool *fast_math_on_ptr; AstNode **fast_math_set_node_ptr; - if (target_type->id == TypeTableEntryIdBlock) { + if (target_type->id == ZigTypeIdBlock) { ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block; fast_math_on_ptr = &block_scope->fast_math_on; fast_math_set_node_ptr = &block_scope->fast_math_set_node; - } else if (target_type->id == TypeTableEntryIdFn) { + } else if (target_type->id == ZigTypeIdFn) { assert(target_val->data.x_ptr.special == ConstPtrSpecialFunction); ZigFn *target_fn = target_val->data.x_ptr.data.fn.fn_entry; assert(target_fn->def_scope); fast_math_on_ptr = &target_fn->def_scope->fast_math_on; fast_math_set_node_ptr = &target_fn->def_scope->fast_math_set_node; - } else if (target_type->id == TypeTableEntryIdMetaType) { + } else if (target_type->id == ZigTypeIdMetaType) { ScopeDecls *decls_scope; ZigType *type_arg = target_val->data.x_type; - if (type_arg->id == TypeTableEntryIdStruct) { + if (type_arg->id == ZigTypeIdStruct) { decls_scope = type_arg->data.structure.decls_scope; - } else if (type_arg->id == TypeTableEntryIdEnum) { + } else if (type_arg->id == ZigTypeIdEnum) { decls_scope = type_arg->data.enumeration.decls_scope; - } else if (type_arg->id == TypeTableEntryIdUnion) { + } else if (type_arg->id == ZigTypeIdUnion) { decls_scope = type_arg->data.unionation.decls_scope; } else { ir_add_error_node(ira, target_instruction->source_node, @@ -15476,36 +15476,36 @@ static ZigType *ir_analyze_instruction_slice_type(IrAnalyze *ira, bool is_volatile = slice_type_instruction->is_volatile; switch (child_type->id) { - case TypeTableEntryIdInvalid: // handled above + case ZigTypeIdInvalid: // handled above zig_unreachable(); - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdBlock: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdUnreachable: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdBlock: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: ir_add_error_node(ira, slice_type_instruction->base.source_node, buf_sprintf("slice of type '%s' not allowed", buf_ptr(&child_type->name))); return ira->codegen->builtin_types.entry_invalid; - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdPromise: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBoundFn: + case ZigTypeIdPromise: { if ((err = type_ensure_zero_bits_known(ira->codegen, child_type))) return ira->codegen->builtin_types.entry_invalid; @@ -15587,36 +15587,36 @@ static ZigType *ir_analyze_instruction_array_type(IrAnalyze *ira, if (type_is_invalid(child_type)) return ira->codegen->builtin_types.entry_invalid; switch (child_type->id) { - case TypeTableEntryIdInvalid: // handled above + case ZigTypeIdInvalid: // handled above zig_unreachable(); - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdBlock: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdUnreachable: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdBlock: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: ir_add_error_node(ira, array_type_instruction->base.source_node, buf_sprintf("array of type '%s' not allowed", buf_ptr(&child_type->name))); return ira->codegen->builtin_types.entry_invalid; - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdPromise: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBoundFn: + case ZigTypeIdPromise: { if ((err = ensure_complete_type(ira->codegen, child_type))) return ira->codegen->builtin_types.entry_invalid; @@ -15658,36 +15658,36 @@ static ZigType *ir_analyze_instruction_size_of(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; switch (type_entry->id) { - case TypeTableEntryIdInvalid: // handled above + case ZigTypeIdInvalid: // handled above zig_unreachable(); - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdBlock: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdUnreachable: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdBlock: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdBoundFn: + case ZigTypeIdMetaType: + case ZigTypeIdNamespace: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: ir_add_error_node(ira, size_of_instruction->base.source_node, buf_sprintf("no size available for type '%s'", buf_ptr(&type_entry->name))); return ira->codegen->builtin_types.entry_invalid; - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdPromise: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdPromise: { uint64_t size_in_bytes = type_size(ira->codegen, type_entry); ConstExprValue *out_val = ir_build_const_from(ira, &size_of_instruction->base); @@ -15705,7 +15705,7 @@ static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructi ZigType *type_entry = value->value.type; - if (type_entry->id == TypeTableEntryIdOptional) { + if (type_entry->id == ZigTypeIdOptional) { if (instr_is_comptime(value)) { ConstExprValue *maybe_val = ir_resolve_const(ira, value, UndefBad); if (!maybe_val) @@ -15718,7 +15718,7 @@ static ZigType *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructi ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value); return ira->codegen->builtin_types.entry_bool; - } else if (type_entry->id == TypeTableEntryIdNull) { + } else if (type_entry->id == ZigTypeIdNull) { ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); out_val->data.x_bool = false; return ira->codegen->builtin_types.entry_bool; @@ -15737,12 +15737,12 @@ static ZigType *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; ZigType *ptr_type = value->value.type; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ZigType *type_entry = ptr_type->data.pointer.child_type; if (type_is_invalid(type_entry)) { return ira->codegen->builtin_types.entry_invalid; - } else if (type_entry->id != TypeTableEntryIdOptional) { + } else if (type_entry->id != ZigTypeIdOptional) { ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node, buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name))); return ira->codegen->builtin_types.entry_invalid; @@ -15787,7 +15787,7 @@ static ZigType *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz IrInstruction *value = ctz_instruction->value->other; if (type_is_invalid(value->value.type)) { return ira->codegen->builtin_types.entry_invalid; - } else if (value->value.type->id == TypeTableEntryIdInt) { + } else if (value->value.type->id == ZigTypeIdInt) { ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, value->value.type->data.integral.bit_count); if (value->value.special != ConstValSpecialRuntime) { @@ -15811,7 +15811,7 @@ static ZigType *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz IrInstruction *value = clz_instruction->value->other; if (type_is_invalid(value->value.type)) { return ira->codegen->builtin_types.entry_invalid; - } else if (value->value.type->id == TypeTableEntryIdInt) { + } else if (value->value.type->id == ZigTypeIdInt) { ZigType *return_type = get_smallest_unsigned_int_type(ira->codegen, value->value.type->data.integral.bit_count); if (value->value.special != ConstValSpecialRuntime) { @@ -15836,7 +15836,7 @@ static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPo if (type_is_invalid(value->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (value->value.type->id != TypeTableEntryIdInt && value->value.type->id != TypeTableEntryIdComptimeInt) { + if (value->value.type->id != ZigTypeIdInt && value->value.type->id != ZigTypeIdComptimeInt) { ir_add_error(ira, value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&value->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -15852,7 +15852,7 @@ static ZigType *ir_analyze_instruction_pop_count(IrAnalyze *ira, IrInstructionPo bigint_init_unsigned(&out_val->data.x_bigint, result); return ira->codegen->builtin_types.entry_num_lit_int; } - if (value->value.type->id == TypeTableEntryIdComptimeInt) { + if (value->value.type->id == ZigTypeIdComptimeInt) { Buf *val_buf = buf_alloc(); bigint_append_buf(val_buf, &val->data.x_bigint, 10); ir_add_error(ira, &instruction->base, @@ -15877,11 +15877,11 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source if (type_is_invalid(value->value.type)) return ira->codegen->invalid_instruction; - if (value->value.type->id == TypeTableEntryIdEnum) { + if (value->value.type->id == ZigTypeIdEnum) { return value; } - if (value->value.type->id != TypeTableEntryIdUnion) { + if (value->value.type->id != ZigTypeIdUnion) { ir_add_error(ira, value, buf_sprintf("expected enum or union type, found '%s'", buf_ptr(&value->value.type->name))); return ira->codegen->invalid_instruction; @@ -15896,7 +15896,7 @@ static IrInstruction *ir_analyze_union_tag(IrAnalyze *ira, IrInstruction *source } ZigType *tag_type = value->value.type->data.unionation.tag_type; - assert(tag_type->id == TypeTableEntryIdEnum); + assert(tag_type->id == ZigTypeIdEnum); if (instr_is_comptime(value)) { ConstExprValue *val = ir_resolve_const(ira, value, UndefBad); @@ -15948,7 +15948,7 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira, if (type_is_invalid(case_value->value.type)) return ir_unreach_error(ira); - if (case_value->value.type->id == TypeTableEntryIdEnum) { + if (case_value->value.type->id == ZigTypeIdEnum) { case_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, case_value); if (type_is_invalid(case_value->value.type)) return ir_unreach_error(ira); @@ -15995,7 +15995,7 @@ static ZigType *ir_analyze_instruction_switch_br(IrAnalyze *ira, if (type_is_invalid(new_value->value.type)) continue; - if (new_value->value.type->id == TypeTableEntryIdEnum) { + if (new_value->value.type->id == ZigTypeIdEnum) { new_value = ir_analyze_union_tag(ira, &switch_br_instruction->base, new_value); if (type_is_invalid(new_value->value.type)) continue; @@ -16032,17 +16032,17 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, if (type_is_invalid(target_value_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (target_value_ptr->value.type->id == TypeTableEntryIdMetaType) { + if (target_value_ptr->value.type->id == ZigTypeIdMetaType) { assert(instr_is_comptime(target_value_ptr)); ZigType *ptr_type = target_value_ptr->value.data.x_type; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); out_val->type = ira->codegen->builtin_types.entry_type; out_val->data.x_type = ptr_type->data.pointer.child_type; return out_val->type; } - if (target_value_ptr->value.type->id != TypeTableEntryIdPointer) { + if (target_value_ptr->value.type->id != ZigTypeIdPointer) { ir_add_error(ira, target_value_ptr, buf_sprintf("invalid deref on switch target")); return ira->codegen->builtin_types.entry_invalid; } @@ -16061,20 +16061,20 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; switch (target_type->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdPointer: - case TypeTableEntryIdPromise: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdErrorSet: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdPointer: + case ZigTypeIdPromise: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdErrorSet: if (pointee_val) { ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); copy_const_val(out_val, pointee_val, true); @@ -16084,7 +16084,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, ir_build_load_ptr_from(&ira->new_irb, &switch_target_instruction->base, target_value_ptr); return target_type; - case TypeTableEntryIdUnion: { + case ZigTypeIdUnion: { AstNode *decl_node = target_type->data.unionation.decl_node; if (!decl_node->data.container_decl.auto_enum && decl_node->data.container_decl.init_arg_expr == nullptr) @@ -16097,7 +16097,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, } ZigType *tag_type = target_type->data.unionation.tag_type; assert(tag_type != nullptr); - assert(tag_type->id == TypeTableEntryIdEnum); + assert(tag_type->id == ZigTypeIdEnum); if (pointee_val) { ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); bigint_init_bigint(&out_val->data.x_enum_tag, &pointee_val->data.x_union.tag); @@ -16120,7 +16120,7 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, ir_link_new_instruction(union_tag_inst, &switch_target_instruction->base); return tag_type; } - case TypeTableEntryIdEnum: { + case ZigTypeIdEnum: { if ((err = type_ensure_zero_bits_known(ira->codegen, target_type))) return ira->codegen->builtin_types.entry_invalid; if (target_type->data.enumeration.src_field_count < 2) { @@ -16142,17 +16142,17 @@ static ZigType *ir_analyze_instruction_switch_target(IrAnalyze *ira, ir_link_new_instruction(enum_value, &switch_target_instruction->base); return target_type; } - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdErrorUnion: + case ZigTypeIdUnreachable: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: ir_add_error(ira, &switch_target_instruction->base, buf_sprintf("invalid switch target type '%s'", buf_ptr(&target_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -16169,14 +16169,14 @@ static ZigType *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionS if (type_is_invalid(prong_value->value.type)) return ira->codegen->builtin_types.entry_invalid; - assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer); + assert(target_value_ptr->value.type->id == ZigTypeIdPointer); ZigType *target_type = target_value_ptr->value.type->data.pointer.child_type; - if (target_type->id == TypeTableEntryIdUnion) { + if (target_type->id == ZigTypeIdUnion) { ConstExprValue *prong_val = ir_resolve_const(ira, prong_value, UndefBad); if (!prong_val) return ira->codegen->builtin_types.entry_invalid; - assert(prong_value->value.type->id == TypeTableEntryIdEnum); + assert(prong_value->value.type->id == ZigTypeIdEnum); TypeUnionField *field = find_union_field_by_tag(target_type, &prong_val->data.x_enum_tag); if (instr_is_comptime(target_value_ptr)) { @@ -16285,7 +16285,7 @@ static ZigType *ir_analyze_instruction_array_len(IrAnalyze *ira, ZigType *type_entry = array_value->value.type; if (type_is_invalid(type_entry)) { return ira->codegen->builtin_types.entry_invalid; - } else if (type_entry->id == TypeTableEntryIdArray) { + } else if (type_entry->id == ZigTypeIdArray) { return ir_analyze_const_usize(ira, &array_len_instruction->base, type_entry->data.array.len); } else if (is_slice(type_entry)) { @@ -16318,7 +16318,7 @@ static ZigType *ir_analyze_container_init_fields_union(IrAnalyze *ira, IrInstruc ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) { Error err; - assert(container_type->id == TypeTableEntryIdUnion); + assert(container_type->id == ZigTypeIdUnion); if ((err = ensure_complete_type(ira->codegen, container_type))) return ira->codegen->builtin_types.entry_invalid; @@ -16384,10 +16384,10 @@ static ZigType *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruction * ZigType *container_type, size_t instr_field_count, IrInstructionContainerInitFieldsField *fields) { Error err; - if (container_type->id == TypeTableEntryIdUnion) { + if (container_type->id == ZigTypeIdUnion) { return ir_analyze_container_init_fields_union(ira, instruction, container_type, instr_field_count, fields); } - if (container_type->id != TypeTableEntryIdStruct || is_slice(container_type)) { + if (container_type->id != ZigTypeIdStruct || is_slice(container_type)) { ir_add_error(ira, instruction, buf_sprintf("type '%s' does not support struct initialization syntax", buf_ptr(&container_type->name))); @@ -16508,18 +16508,18 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; size_t elem_count = instruction->item_count; - if (container_type_value->value.type->id == TypeTableEntryIdMetaType) { + if (container_type_value->value.type->id == ZigTypeIdMetaType) { ZigType *container_type = ir_resolve_type(ira, container_type_value); if (type_is_invalid(container_type)) return ira->codegen->builtin_types.entry_invalid; - if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) { + if (container_type->id == ZigTypeIdStruct && !is_slice(container_type) && elem_count == 0) { return ir_analyze_container_init_fields(ira, &instruction->base, container_type, 0, nullptr); - } else if (is_slice(container_type) || container_type->id == TypeTableEntryIdArray) { + } else if (is_slice(container_type) || container_type->id == ZigTypeIdArray) { // array is same as slice init but we make a compile error if the length is wrong ZigType *child_type; - if (container_type->id == TypeTableEntryIdArray) { + if (container_type->id == ZigTypeIdArray) { child_type = container_type->data.array.child_type; if (container_type->data.array.len != elem_count) { ZigType *literal_type = get_array_type(ira->codegen, child_type, elem_count); @@ -16531,7 +16531,7 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, } } else { ZigType *pointer_type = container_type->data.structure.fields[slice_ptr_index].type_entry; - assert(pointer_type->id == TypeTableEntryIdPointer); + assert(pointer_type->id == ZigTypeIdPointer); child_type = pointer_type->data.pointer.child_type; } @@ -16598,7 +16598,7 @@ static ZigType *ir_analyze_instruction_container_init_list(IrAnalyze *ira, container_type_value, elem_count, new_items); ir_add_alloca(ira, new_instruction, fixed_size_array_type); return fixed_size_array_type; - } else if (container_type->id == TypeTableEntryIdVoid) { + } else if (container_type->id == ZigTypeIdVoid) { if (elem_count != 0) { ir_add_error_node(ira, instruction->base.source_node, buf_sprintf("void expression expects no arguments")); @@ -16635,43 +16635,43 @@ static ZigType *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_instruc if (type_is_invalid(target_type)) return ira->codegen->builtin_types.entry_invalid; switch (target_type->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdInt: + case ZigTypeIdInt: { ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); eval_min_max_value(ira->codegen, target_type, out_val, is_max); return ira->codegen->builtin_types.entry_num_lit_int; } - case TypeTableEntryIdBool: - case TypeTableEntryIdVoid: + case ZigTypeIdBool: + case ZigTypeIdVoid: { ConstExprValue *out_val = ir_build_const_from(ira, source_instruction); eval_min_max_value(ira->codegen, target_type, out_val, is_max); return target_type; } - case TypeTableEntryIdEnum: - case TypeTableEntryIdFloat: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdPointer: - case TypeTableEntryIdPromise: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdEnum: + case ZigTypeIdFloat: + case ZigTypeIdMetaType: + case ZigTypeIdUnreachable: + case ZigTypeIdPointer: + case ZigTypeIdPromise: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdUnion: + case ZigTypeIdFn: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: { const char *err_format = is_max ? "no max value available for type '%s'" : @@ -16774,7 +16774,7 @@ static ZigType *ir_analyze_instruction_enum_tag_name(IrAnalyze *ira, IrInstructi if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; - assert(target->value.type->id == TypeTableEntryIdEnum); + assert(target->value.type->id == ZigTypeIdEnum); if (instr_is_comptime(target)) { if ((err = type_ensure_zero_bits_known(ira->codegen, target->value.type))) @@ -16816,7 +16816,7 @@ static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, if (type_is_invalid(field_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (container_type->id != TypeTableEntryIdStruct) { + if (container_type->id != ZigTypeIdStruct) { ir_add_error(ira, type_value, buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -16833,7 +16833,7 @@ static ZigType *ir_analyze_instruction_field_parent_ptr(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; } - if (field_ptr->value.type->id != TypeTableEntryIdPointer) { + if (field_ptr->value.type->id != ZigTypeIdPointer) { ir_add_error(ira, field_ptr, buf_sprintf("expected pointer, found '%s'", buf_ptr(&field_ptr->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -16908,7 +16908,7 @@ static ZigType *ir_analyze_instruction_offset_of(IrAnalyze *ira, if (!field_name) return ira->codegen->builtin_types.entry_invalid; - if (container_type->id != TypeTableEntryIdStruct) { + if (container_type->id != ZigTypeIdStruct) { ir_add_error(ira, type_value, buf_sprintf("expected struct type, found '%s'", buf_ptr(&container_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -16951,11 +16951,11 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig static ZigType *type_info_type = nullptr; if (type_info_var == nullptr) { type_info_var = get_builtin_value(ira->codegen, "TypeInfo"); - assert(type_info_var->type->id == TypeTableEntryIdMetaType); + assert(type_info_var->type->id == ZigTypeIdMetaType); assertNoError(ensure_complete_type(ira->codegen, type_info_var->data.x_type)); type_info_type = type_info_var->data.x_type; - assert(type_info_type->id == TypeTableEntryIdUnion); + assert(type_info_type->id == ZigTypeIdUnion); } if (type_name == nullptr && root == nullptr) @@ -16980,7 +16980,7 @@ static ZigType *ir_type_info_get_type(IrAnalyze *ira, const char *type_name, Zig if ((err = ensure_complete_type(ira->codegen, var->value->type))) return ira->codegen->builtin_types.entry_invalid; - assert(var->value->type->id == TypeTableEntryIdMetaType); + assert(var->value->type->id == ZigTypeIdMetaType); return var->value->data.x_type; } @@ -17078,7 +17078,7 @@ static Error ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Sco if ((err = ensure_complete_type(ira->codegen, var->value->type))) return ErrorSemanticAnalyzeFail; - if (var->value->type->id == TypeTableEntryIdMetaType) + if (var->value->type->id == ZigTypeIdMetaType) { // We have a variable of type 'type', so it's actually a type definition. // 0: Data.Type: type @@ -17238,7 +17238,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty if (is_slice(ptr_type_entry)) { attrs_type = ptr_type_entry->data.structure.fields[slice_ptr_index].type_entry; size_enum_index = 2; - } else if (ptr_type_entry->id == TypeTableEntryIdPointer) { + } else if (ptr_type_entry->id == ZigTypeIdPointer) { attrs_type = ptr_type_entry; size_enum_index = (ptr_type_entry->data.pointer.ptr_len == PtrLenSingle) ? 0 : 1; } else { @@ -17320,20 +17320,20 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE ConstExprValue *result = nullptr; switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdMetaType: - case TypeTableEntryIdVoid: - case TypeTableEntryIdBool: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdOpaque: + case ZigTypeIdMetaType: + case ZigTypeIdVoid: + case ZigTypeIdBool: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdArgTuple: + case ZigTypeIdOpaque: *out = nullptr; return ErrorNone; default: @@ -17347,7 +17347,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE // Fallthrough if we don't find one. } - case TypeTableEntryIdInt: + case ZigTypeIdInt: { result = create_const_vals(1); result->special = ConstValSpecialStatic; @@ -17369,7 +17369,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: { result = create_const_vals(1); result->special = ConstValSpecialStatic; @@ -17386,12 +17386,12 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: { result = create_ptr_like_type_info(ira, type_entry); break; } - case TypeTableEntryIdArray: + case ZigTypeIdArray: { result = create_const_vals(1); result->special = ConstValSpecialStatic; @@ -17413,7 +17413,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: { result = create_const_vals(1); result->special = ConstValSpecialStatic; @@ -17430,7 +17430,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdPromise: + case ZigTypeIdPromise: { result = create_const_vals(1); result->special = ConstValSpecialStatic; @@ -17456,7 +17456,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: { result = create_const_vals(1); result->special = ConstValSpecialStatic; @@ -17506,7 +17506,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdErrorSet: + case ZigTypeIdErrorSet: { result = create_const_vals(1); result->special = ConstValSpecialStatic; @@ -17555,7 +17555,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: { result = create_const_vals(1); result->special = ConstValSpecialStatic; @@ -17578,7 +17578,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: { result = create_const_vals(1); result->special = ConstValSpecialStatic; @@ -17663,7 +17663,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: { if (type_entry->data.structure.is_slice) { result = create_ptr_like_type_info(ira, type_entry); @@ -17737,7 +17737,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdFn: + case ZigTypeIdFn: { result = create_const_vals(1); result->special = ConstValSpecialStatic; @@ -17842,10 +17842,10 @@ static Error ir_make_type_info_value(IrAnalyze *ira, ZigType *type_entry, ConstE break; } - case TypeTableEntryIdBoundFn: + case ZigTypeIdBoundFn: { ZigType *fn_type = type_entry->data.bound_fn.fn_type; - assert(fn_type->id == TypeTableEntryIdFn); + assert(fn_type->id == ZigTypeIdFn); if ((err = ir_make_type_info_value(ira, fn_type, &result))) return err; @@ -17880,7 +17880,7 @@ static ZigType *ir_analyze_instruction_type_info(IrAnalyze *ira, out_val->data.x_union.payload = payload; if (payload != nullptr) { - assert(payload->type->id == TypeTableEntryIdStruct); + assert(payload->type->id == ZigTypeIdStruct); payload->data.x_struct.parent.id = ConstParentIdUnion; payload->data.x_struct.parent.data.p_union.union_val = out_val; } @@ -17897,7 +17897,7 @@ static ZigType *ir_analyze_instruction_type_id(IrAnalyze *ira, return ira->codegen->builtin_types.entry_invalid; ConstExprValue *var_value = get_builtin_value(ira->codegen, "TypeId"); - assert(var_value->type->id == TypeTableEntryIdMetaType); + assert(var_value->type->id == ZigTypeIdMetaType); ZigType *result_type = var_value->data.x_type; ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); @@ -18206,8 +18206,8 @@ static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTru if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; - if (dest_type->id != TypeTableEntryIdInt && - dest_type->id != TypeTableEntryIdComptimeInt) + if (dest_type->id != ZigTypeIdInt && + dest_type->id != ZigTypeIdComptimeInt) { ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -18218,8 +18218,8 @@ static ZigType *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstructionTru if (type_is_invalid(src_type)) return ira->codegen->builtin_types.entry_invalid; - if (src_type->id != TypeTableEntryIdInt && - src_type->id != TypeTableEntryIdComptimeInt) + if (src_type->id != ZigTypeIdInt && + src_type->id != ZigTypeIdComptimeInt) { ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -18253,7 +18253,7 @@ static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionInt if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; - if (dest_type->id != TypeTableEntryIdInt) { + if (dest_type->id != ZigTypeIdInt) { ir_add_error(ira, instruction->dest_type, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; } @@ -18262,7 +18262,7 @@ static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionInt if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (target->value.type->id == TypeTableEntryIdComptimeInt) { + if (target->value.type->id == ZigTypeIdComptimeInt) { if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { IrInstruction *result = ir_resolve_cast(ira, &instruction->base, target, dest_type, CastOpNumLitToConcrete, false); @@ -18275,7 +18275,7 @@ static ZigType *ir_analyze_instruction_int_cast(IrAnalyze *ira, IrInstructionInt } } - if (target->value.type->id != TypeTableEntryIdInt) { + if (target->value.type->id != ZigTypeIdInt) { ir_add_error(ira, instruction->target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&target->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -18294,7 +18294,7 @@ static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionF if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; - if (dest_type->id != TypeTableEntryIdFloat) { + if (dest_type->id != ZigTypeIdFloat) { ir_add_error(ira, instruction->dest_type, buf_sprintf("expected float type, found '%s'", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -18304,12 +18304,12 @@ static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionF if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (target->value.type->id == TypeTableEntryIdComptimeInt || - target->value.type->id == TypeTableEntryIdComptimeFloat) + if (target->value.type->id == ZigTypeIdComptimeInt || + target->value.type->id == ZigTypeIdComptimeFloat) { if (ir_num_lit_fits_in_other_type(ira, target, dest_type, true)) { CastOp op; - if (target->value.type->id == TypeTableEntryIdComptimeInt) { + if (target->value.type->id == ZigTypeIdComptimeInt) { op = CastOpIntToFloat; } else { op = CastOpNumLitToConcrete; @@ -18324,7 +18324,7 @@ static ZigType *ir_analyze_instruction_float_cast(IrAnalyze *ira, IrInstructionF } } - if (target->value.type->id != TypeTableEntryIdFloat) { + if (target->value.type->id != ZigTypeIdFloat) { ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", buf_ptr(&target->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -18342,7 +18342,7 @@ static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructio if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; - if (dest_type->id != TypeTableEntryIdErrorSet) { + if (dest_type->id != ZigTypeIdErrorSet) { ir_add_error(ira, instruction->dest_type, buf_sprintf("expected error set type, found '%s'", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -18352,7 +18352,7 @@ static ZigType *ir_analyze_instruction_err_set_cast(IrAnalyze *ira, IrInstructio if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (target->value.type->id != TypeTableEntryIdErrorSet) { + if (target->value.type->id != ZigTypeIdErrorSet) { ir_add_error(ira, instruction->target, buf_sprintf("expected error set type, found '%s'", buf_ptr(&target->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -18377,7 +18377,7 @@ static ZigType *ir_analyze_instruction_from_bytes(IrAnalyze *ira, IrInstructionF bool src_ptr_const; bool src_ptr_volatile; uint32_t src_ptr_align; - if (target->value.type->id == TypeTableEntryIdPointer) { + if (target->value.type->id == ZigTypeIdPointer) { src_ptr_const = target->value.type->data.pointer.is_const; src_ptr_volatile = target->value.type->data.pointer.is_volatile; src_ptr_align = target->value.type->data.pointer.alignment; @@ -18477,7 +18477,7 @@ static ZigType *ir_analyze_instruction_int_to_float(IrAnalyze *ira, IrInstructio if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (target->value.type->id != TypeTableEntryIdInt && target->value.type->id != TypeTableEntryIdComptimeInt) { + if (target->value.type->id != ZigTypeIdInt && target->value.type->id != ZigTypeIdComptimeInt) { ir_add_error(ira, instruction->target, buf_sprintf("expected int type, found '%s'", buf_ptr(&target->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -18497,7 +18497,7 @@ static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructio if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (target->value.type->id == TypeTableEntryIdComptimeInt) { + if (target->value.type->id == ZigTypeIdComptimeInt) { IrInstruction *casted_value = ir_implicit_cast(ira, target, dest_type); if (type_is_invalid(casted_value->value.type)) return ira->codegen->builtin_types.entry_invalid; @@ -18505,7 +18505,7 @@ static ZigType *ir_analyze_instruction_float_to_int(IrAnalyze *ira, IrInstructio return casted_value->value.type; } - if (target->value.type->id != TypeTableEntryIdFloat && target->value.type->id != TypeTableEntryIdComptimeFloat) { + if (target->value.type->id != ZigTypeIdFloat && target->value.type->id != ZigTypeIdComptimeFloat) { ir_add_error(ira, instruction->target, buf_sprintf("expected float type, found '%s'", buf_ptr(&target->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -18522,7 +18522,7 @@ static ZigType *ir_analyze_instruction_err_to_int(IrAnalyze *ira, IrInstructionE return ira->codegen->builtin_types.entry_invalid; IrInstruction *casted_target; - if (target->value.type->id == TypeTableEntryIdErrorSet) { + if (target->value.type->id == ZigTypeIdErrorSet) { casted_target = target; } else { casted_target = ir_implicit_cast(ira, target, ira->codegen->builtin_types.entry_global_error_set); @@ -18554,7 +18554,7 @@ static ZigType *ir_analyze_instruction_bool_to_int(IrAnalyze *ira, IrInstruction if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (target->value.type->id != TypeTableEntryIdBool) { + if (target->value.type->id != ZigTypeIdBool) { ir_add_error(ira, instruction->target, buf_sprintf("expected bool, found '%s'", buf_ptr(&target->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -18631,12 +18631,12 @@ static ZigType *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemse return ira->codegen->builtin_types.entry_invalid; ZigType *dest_uncasted_type = dest_ptr->value.type; - bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) && + bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && dest_uncasted_type->data.pointer.is_volatile; ZigType *usize = ira->codegen->builtin_types.entry_usize; ZigType *u8 = ira->codegen->builtin_types.entry_u8; - uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ? + uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ? dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); ZigType *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, PtrLenUnknown, dest_align, 0, 0); @@ -18725,13 +18725,13 @@ static ZigType *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcp ZigType *u8 = ira->codegen->builtin_types.entry_u8; ZigType *dest_uncasted_type = dest_ptr->value.type; ZigType *src_uncasted_type = src_ptr->value.type; - bool dest_is_volatile = (dest_uncasted_type->id == TypeTableEntryIdPointer) && + bool dest_is_volatile = (dest_uncasted_type->id == ZigTypeIdPointer) && dest_uncasted_type->data.pointer.is_volatile; - bool src_is_volatile = (src_uncasted_type->id == TypeTableEntryIdPointer) && + bool src_is_volatile = (src_uncasted_type->id == ZigTypeIdPointer) && src_uncasted_type->data.pointer.is_volatile; - uint32_t dest_align = (dest_uncasted_type->id == TypeTableEntryIdPointer) ? + uint32_t dest_align = (dest_uncasted_type->id == ZigTypeIdPointer) ? dest_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); - uint32_t src_align = (src_uncasted_type->id == TypeTableEntryIdPointer) ? + uint32_t src_align = (src_uncasted_type->id == ZigTypeIdPointer) ? src_uncasted_type->data.pointer.alignment : get_abi_alignment(ira->codegen, u8); ZigType *usize = ira->codegen->builtin_types.entry_usize; @@ -18850,7 +18850,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice return ira->codegen->builtin_types.entry_invalid; ZigType *ptr_type = ptr_ptr->value.type; - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ZigType *array_type = ptr_type->data.pointer.child_type; IrInstruction *start = instruction->start->other; @@ -18876,7 +18876,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice ZigType *return_type; - if (array_type->id == TypeTableEntryIdArray) { + if (array_type->id == ZigTypeIdArray) { uint32_t byte_alignment = ptr_type->data.pointer.alignment; if (array_type->data.array.len == 0 && byte_alignment == 0) { byte_alignment = get_abi_alignment(ira->codegen, array_type->data.array.child_type); @@ -18889,10 +18889,10 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice PtrLenUnknown, byte_alignment, 0, 0); return_type = get_slice_type(ira->codegen, slice_ptr_type); - } else if (array_type->id == TypeTableEntryIdPointer) { + } else if (array_type->id == ZigTypeIdPointer) { if (array_type->data.pointer.ptr_len == PtrLenSingle) { ZigType *main_type = array_type->data.pointer.child_type; - if (main_type->id == TypeTableEntryIdArray) { + if (main_type->id == ZigTypeIdArray) { ZigType *slice_ptr_type = get_pointer_to_type_extra(ira->codegen, main_type->data.pointer.child_type, array_type->data.pointer.is_const, array_type->data.pointer.is_volatile, @@ -18932,12 +18932,12 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice size_t abs_offset; size_t rel_end; bool ptr_is_undef = false; - if (array_type->id == TypeTableEntryIdArray || - (array_type->id == TypeTableEntryIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) + if (array_type->id == ZigTypeIdArray || + (array_type->id == ZigTypeIdPointer && array_type->data.pointer.ptr_len == PtrLenSingle)) { - if (array_type->id == TypeTableEntryIdPointer) { + if (array_type->id == ZigTypeIdPointer) { ZigType *child_array_type = array_type->data.pointer.child_type; - assert(child_array_type->id == TypeTableEntryIdArray); + assert(child_array_type->id == ZigTypeIdArray); parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); if (parent_ptr == nullptr) return ira->codegen->builtin_types.entry_invalid; @@ -18956,7 +18956,7 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice parent_ptr = nullptr; abs_offset = 0; } - } else if (array_type->id == TypeTableEntryIdPointer) { + } else if (array_type->id == ZigTypeIdPointer) { assert(array_type->data.pointer.ptr_len == PtrLenUnknown); parent_ptr = ir_const_ptr_pointee(ira, &ptr_ptr->value, instruction->base.source_node); if (parent_ptr == nullptr) @@ -19063,11 +19063,11 @@ static ZigType *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice size_t index = abs_offset + start_scalar; bool is_const = slice_is_const(return_type); init_const_ptr_array(ira->codegen, ptr_val, array_val, index, is_const, PtrLenUnknown); - if (array_type->id == TypeTableEntryIdArray) { + if (array_type->id == ZigTypeIdArray) { ptr_val->data.x_ptr.mut = ptr_ptr->value.data.x_ptr.mut; } else if (is_slice(array_type)) { ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut; - } else if (array_type->id == TypeTableEntryIdPointer) { + } else if (array_type->id == ZigTypeIdPointer) { ptr_val->data.x_ptr.mut = parent_ptr->data.x_ptr.mut; } } else if (ptr_is_undef) { @@ -19122,13 +19122,13 @@ static ZigType *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructio uint64_t result; if (type_is_invalid(container_type)) { return ira->codegen->builtin_types.entry_invalid; - } else if (container_type->id == TypeTableEntryIdEnum) { + } else if (container_type->id == ZigTypeIdEnum) { result = container_type->data.enumeration.src_field_count; - } else if (container_type->id == TypeTableEntryIdStruct) { + } else if (container_type->id == ZigTypeIdStruct) { result = container_type->data.structure.src_field_count; - } else if (container_type->id == TypeTableEntryIdUnion) { + } else if (container_type->id == ZigTypeIdUnion) { result = container_type->data.unionation.src_field_count; - } else if (container_type->id == TypeTableEntryIdErrorSet) { + } else if (container_type->id == ZigTypeIdErrorSet) { if (!resolve_inferred_error_set(ira->codegen, container_type, instruction->base.source_node)) { return ira->codegen->builtin_types.entry_invalid; } @@ -19163,7 +19163,7 @@ static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstruction if (!ir_resolve_usize(ira, index_value, &member_index)) return ira->codegen->builtin_types.entry_invalid; - if (container_type->id == TypeTableEntryIdStruct) { + if (container_type->id == ZigTypeIdStruct) { if (member_index >= container_type->data.structure.src_field_count) { ir_add_error(ira, index_value, buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", @@ -19175,7 +19175,7 @@ static ZigType *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInstruction ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); out_val->data.x_type = field->type_entry; return ira->codegen->builtin_types.entry_type; - } else if (container_type->id == TypeTableEntryIdUnion) { + } else if (container_type->id == ZigTypeIdUnion) { if (member_index >= container_type->data.unionation.src_field_count) { ir_add_error(ira, index_value, buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", @@ -19209,7 +19209,7 @@ static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstruction if (!ir_resolve_usize(ira, index_value, &member_index)) return ira->codegen->builtin_types.entry_invalid; - if (container_type->id == TypeTableEntryIdStruct) { + if (container_type->id == ZigTypeIdStruct) { if (member_index >= container_type->data.structure.src_field_count) { ir_add_error(ira, index_value, buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", @@ -19221,7 +19221,7 @@ static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstruction ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); init_const_str_lit(ira->codegen, out_val, field->name); return out_val->type; - } else if (container_type->id == TypeTableEntryIdEnum) { + } else if (container_type->id == ZigTypeIdEnum) { if (member_index >= container_type->data.enumeration.src_field_count) { ir_add_error(ira, index_value, buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", @@ -19233,7 +19233,7 @@ static ZigType *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInstruction ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); init_const_str_lit(ira->codegen, out_val, field->name); return out_val->type; - } else if (container_type->id == TypeTableEntryIdUnion) { + } else if (container_type->id == ZigTypeIdUnion) { if (member_index >= container_type->data.unionation.src_field_count) { ir_add_error(ira, index_value, buf_sprintf("member index %" ZIG_PRI_u64 " out of bounds; '%s' has %" PRIu32 " members", @@ -19292,36 +19292,36 @@ static ZigType *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstructionAli return ira->codegen->builtin_types.entry_invalid; switch (type_entry->id) { - case TypeTableEntryIdInvalid: + case ZigTypeIdInvalid: zig_unreachable(); - case TypeTableEntryIdMetaType: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdVoid: - case TypeTableEntryIdOpaque: + case ZigTypeIdMetaType: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdVoid: + case ZigTypeIdOpaque: ir_add_error(ira, instruction->type_value, buf_sprintf("no align available for type '%s'", buf_ptr(&type_entry->name))); return ira->codegen->builtin_types.entry_invalid; - case TypeTableEntryIdBool: - case TypeTableEntryIdInt: - case TypeTableEntryIdFloat: - case TypeTableEntryIdPointer: - case TypeTableEntryIdPromise: - case TypeTableEntryIdArray: - case TypeTableEntryIdStruct: - case TypeTableEntryIdOptional: - case TypeTableEntryIdErrorUnion: - case TypeTableEntryIdErrorSet: - case TypeTableEntryIdEnum: - case TypeTableEntryIdUnion: - case TypeTableEntryIdFn: + case ZigTypeIdBool: + case ZigTypeIdInt: + case ZigTypeIdFloat: + case ZigTypeIdPointer: + case ZigTypeIdPromise: + case ZigTypeIdArray: + case ZigTypeIdStruct: + case ZigTypeIdOptional: + case ZigTypeIdErrorUnion: + case ZigTypeIdErrorSet: + case ZigTypeIdEnum: + case ZigTypeIdUnion: + case ZigTypeIdFn: { uint64_t align_in_bytes = get_abi_alignment(ira->codegen, type_entry); ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); @@ -19341,7 +19341,7 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; - if (dest_type->id != TypeTableEntryIdInt) { + if (dest_type->id != ZigTypeIdInt) { ir_add_error(ira, type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -19375,7 +19375,7 @@ static ZigType *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstruction return ira->codegen->builtin_types.entry_invalid; ZigType *expected_ptr_type; - if (result_ptr->value.type->id == TypeTableEntryIdPointer) { + if (result_ptr->value.type->id == ZigTypeIdPointer) { expected_ptr_type = get_pointer_to_type_extra(ira->codegen, dest_type, false, result_ptr->value.type->data.pointer.is_volatile, PtrLenSingle, @@ -19439,7 +19439,7 @@ static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTes ZigType *type_entry = value->value.type; if (type_is_invalid(type_entry)) { return ira->codegen->builtin_types.entry_invalid; - } else if (type_entry->id == TypeTableEntryIdErrorUnion) { + } else if (type_entry->id == ZigTypeIdErrorUnion) { if (instr_is_comptime(value)) { ConstExprValue *err_union_val = ir_resolve_const(ira, value, UndefBad); if (!err_union_val) @@ -19467,7 +19467,7 @@ static ZigType *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTes ir_build_test_err_from(&ira->new_irb, &instruction->base, value); return ira->codegen->builtin_types.entry_bool; - } else if (type_entry->id == TypeTableEntryIdErrorSet) { + } else if (type_entry->id == ZigTypeIdErrorSet) { ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); out_val->data.x_bool = true; return ira->codegen->builtin_types.entry_bool; @@ -19487,12 +19487,12 @@ static ZigType *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira, ZigType *ptr_type = value->value.type; // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ZigType *type_entry = ptr_type->data.pointer.child_type; if (type_is_invalid(type_entry)) { return ira->codegen->builtin_types.entry_invalid; - } else if (type_entry->id == TypeTableEntryIdErrorUnion) { + } else if (type_entry->id == ZigTypeIdErrorUnion) { if (instr_is_comptime(value)) { ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad); if (!ptr_val) @@ -19529,12 +19529,12 @@ static ZigType *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira, ZigType *ptr_type = value->value.type; // This will be a pointer type because unwrap err payload IR instruction operates on a pointer to a thing. - assert(ptr_type->id == TypeTableEntryIdPointer); + assert(ptr_type->id == ZigTypeIdPointer); ZigType *type_entry = ptr_type->data.pointer.child_type; if (type_is_invalid(type_entry)) { return ira->codegen->builtin_types.entry_invalid; - } else if (type_entry->id == TypeTableEntryIdErrorUnion) { + } else if (type_entry->id == ZigTypeIdErrorUnion) { ZigType *payload_type = type_entry->data.error_union.payload_type; if (type_is_invalid(payload_type)) { return ira->codegen->builtin_types.entry_invalid; @@ -19633,7 +19633,7 @@ static ZigType *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstructionFnP fn_type_id.return_type = ir_resolve_type(ira, return_type_value); if (type_is_invalid(fn_type_id.return_type)) return ira->codegen->builtin_types.entry_invalid; - if (fn_type_id.return_type->id == TypeTableEntryIdOpaque) { + if (fn_type_id.return_type->id == ZigTypeIdOpaque) { ir_add_error(ira, instruction->return_type, buf_sprintf("return type cannot be opaque")); return ira->codegen->builtin_types.entry_invalid; @@ -19674,7 +19674,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, if (type_is_invalid(switch_type)) return ira->codegen->builtin_types.entry_invalid; - if (switch_type->id == TypeTableEntryIdEnum) { + if (switch_type->id == ZigTypeIdEnum) { HashMap field_prev_uses = {}; field_prev_uses.init(switch_type->data.enumeration.src_field_count); @@ -19689,7 +19689,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, if (type_is_invalid(end_value->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (start_value->value.type->id != TypeTableEntryIdEnum) { + if (start_value->value.type->id != ZigTypeIdEnum) { ir_add_error(ira, range->start, buf_sprintf("not an enum type")); return ira->codegen->builtin_types.entry_invalid; } @@ -19697,7 +19697,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, BigInt start_index; bigint_init_bigint(&start_index, &start_value->value.data.x_enum_tag); - assert(end_value->value.type->id == TypeTableEntryIdEnum); + assert(end_value->value.type->id == ZigTypeIdEnum); BigInt end_index; bigint_init_bigint(&end_index, &end_value->value.data.x_enum_tag); @@ -19733,7 +19733,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, } } } - } else if (switch_type->id == TypeTableEntryIdErrorSet) { + } else if (switch_type->id == ZigTypeIdErrorSet) { if (!resolve_inferred_error_set(ira->codegen, switch_type, target_value->source_node)) { return ira->codegen->builtin_types.entry_invalid; } @@ -19751,10 +19751,10 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, if (type_is_invalid(end_value->value.type)) return ira->codegen->builtin_types.entry_invalid; - assert(start_value->value.type->id == TypeTableEntryIdErrorSet); + assert(start_value->value.type->id == ZigTypeIdErrorSet); uint32_t start_index = start_value->value.data.x_err_set->value; - assert(end_value->value.type->id == TypeTableEntryIdErrorSet); + assert(end_value->value.type->id == ZigTypeIdErrorSet); uint32_t end_index = end_value->value.data.x_err_set->value; if (start_index != end_index) { @@ -19790,7 +19790,7 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, } free(field_prev_uses); - } else if (switch_type->id == TypeTableEntryIdInt) { + } else if (switch_type->id == ZigTypeIdInt) { RangeSet rs = {0}; for (size_t range_i = 0; range_i < instruction->range_count; range_i += 1) { IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i]; @@ -19817,8 +19817,8 @@ static ZigType *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira, if (!end_val) return ira->codegen->builtin_types.entry_invalid; - assert(start_val->type->id == TypeTableEntryIdInt || start_val->type->id == TypeTableEntryIdComptimeInt); - assert(end_val->type->id == TypeTableEntryIdInt || end_val->type->id == TypeTableEntryIdComptimeInt); + assert(start_val->type->id == ZigTypeIdInt || start_val->type->id == ZigTypeIdComptimeInt); + assert(end_val->type->id == ZigTypeIdInt || end_val->type->id == ZigTypeIdComptimeInt); AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint, start_value->source_node); if (prev_node != nullptr) { @@ -19854,7 +19854,7 @@ static ZigType *ir_analyze_instruction_check_statement_is_void(IrAnalyze *ira, if (type_is_invalid(statement_type)) return ira->codegen->builtin_types.entry_invalid; - if (statement_type->id != TypeTableEntryIdVoid) { + if (statement_type->id != ZigTypeIdVoid) { ir_add_error(ira, &instruction->base, buf_sprintf("expression value is ignored")); } @@ -19892,24 +19892,24 @@ static IrInstruction *ir_align_cast(IrAnalyze *ira, IrInstruction *target, uint3 ZigType *result_type; uint32_t old_align_bytes; - if (target_type->id == TypeTableEntryIdPointer) { + if (target_type->id == ZigTypeIdPointer) { result_type = adjust_ptr_align(ira->codegen, target_type, align_bytes); old_align_bytes = target_type->data.pointer.alignment; - } else if (target_type->id == TypeTableEntryIdFn) { + } else if (target_type->id == ZigTypeIdFn) { FnTypeId fn_type_id = target_type->data.fn.fn_type_id; old_align_bytes = fn_type_id.alignment; fn_type_id.alignment = align_bytes; result_type = get_fn_type(ira->codegen, &fn_type_id); - } else if (target_type->id == TypeTableEntryIdOptional && - target_type->data.maybe.child_type->id == TypeTableEntryIdPointer) + } else if (target_type->id == ZigTypeIdOptional && + target_type->data.maybe.child_type->id == ZigTypeIdPointer) { ZigType *ptr_type = target_type->data.maybe.child_type; old_align_bytes = ptr_type->data.pointer.alignment; ZigType *better_ptr_type = adjust_ptr_align(ira->codegen, ptr_type, align_bytes); result_type = get_optional_type(ira->codegen, better_ptr_type); - } else if (target_type->id == TypeTableEntryIdOptional && - target_type->data.maybe.child_type->id == TypeTableEntryIdFn) + } else if (target_type->id == ZigTypeIdOptional && + target_type->data.maybe.child_type->id == ZigTypeIdFn) { FnTypeId fn_type_id = target_type->data.maybe.child_type->data.fn.fn_type_id; old_align_bytes = fn_type_id.alignment; @@ -20033,33 +20033,33 @@ static ZigType *ir_analyze_instruction_ptr_cast(IrAnalyze *ira, IrInstructionPtr static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { assert(val->special == ConstValSpecialStatic); switch (val->type->id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdPromise: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdOpaque: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdPromise: zig_unreachable(); - case TypeTableEntryIdVoid: + case ZigTypeIdVoid: return; - case TypeTableEntryIdBool: + case ZigTypeIdBool: buf[0] = val->data.x_bool ? 1 : 0; return; - case TypeTableEntryIdInt: + case ZigTypeIdInt: bigint_write_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count, codegen->is_big_endian); return; - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: float_write_ieee597(val, buf, codegen->is_big_endian); return; - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: if (val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { BigInt bn; bigint_init_unsigned(&bn, val->data.x_ptr.data.hard_coded_addr.addr); @@ -20068,7 +20068,7 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue } else { zig_unreachable(); } - case TypeTableEntryIdArray: + case ZigTypeIdArray: { size_t buf_i = 0; expand_undef_array(codegen, val); @@ -20079,19 +20079,19 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue } } return; - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: zig_panic("TODO buf_write_value_bytes struct type"); - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: zig_panic("TODO buf_write_value_bytes maybe type"); - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: zig_panic("TODO buf_write_value_bytes error union"); - case TypeTableEntryIdErrorSet: + case ZigTypeIdErrorSet: zig_panic("TODO buf_write_value_bytes pure error type"); - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: zig_panic("TODO buf_write_value_bytes enum type"); - case TypeTableEntryIdFn: + case ZigTypeIdFn: zig_panic("TODO buf_write_value_bytes fn type"); - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: zig_panic("TODO buf_write_value_bytes union type"); } zig_unreachable(); @@ -20100,33 +20100,33 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue *val) { assert(val->special == ConstValSpecialStatic); switch (val->type->id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: - case TypeTableEntryIdPromise: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdOpaque: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: + case ZigTypeIdPromise: zig_unreachable(); - case TypeTableEntryIdVoid: + case ZigTypeIdVoid: return; - case TypeTableEntryIdBool: + case ZigTypeIdBool: val->data.x_bool = (buf[0] != 0); return; - case TypeTableEntryIdInt: + case ZigTypeIdInt: bigint_read_twos_complement(&val->data.x_bigint, buf, val->type->data.integral.bit_count, codegen->is_big_endian, val->type->data.integral.is_signed); return; - case TypeTableEntryIdFloat: + case ZigTypeIdFloat: float_read_ieee597(val, buf, codegen->is_big_endian); return; - case TypeTableEntryIdPointer: + case ZigTypeIdPointer: { val->data.x_ptr.special = ConstPtrSpecialHardCodedAddr; BigInt bn; @@ -20135,21 +20135,21 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue val->data.x_ptr.data.hard_coded_addr.addr = bigint_as_unsigned(&bn); return; } - case TypeTableEntryIdArray: + case ZigTypeIdArray: zig_panic("TODO buf_read_value_bytes array type"); - case TypeTableEntryIdStruct: + case ZigTypeIdStruct: zig_panic("TODO buf_read_value_bytes struct type"); - case TypeTableEntryIdOptional: + case ZigTypeIdOptional: zig_panic("TODO buf_read_value_bytes maybe type"); - case TypeTableEntryIdErrorUnion: + case ZigTypeIdErrorUnion: zig_panic("TODO buf_read_value_bytes error union"); - case TypeTableEntryIdErrorSet: + case ZigTypeIdErrorSet: zig_panic("TODO buf_read_value_bytes pure error type"); - case TypeTableEntryIdEnum: + case ZigTypeIdEnum: zig_panic("TODO buf_read_value_bytes enum type"); - case TypeTableEntryIdFn: + case ZigTypeIdFn: zig_panic("TODO buf_read_value_bytes fn type"); - case TypeTableEntryIdUnion: + case ZigTypeIdUnion: zig_panic("TODO buf_read_value_bytes union type"); } zig_unreachable(); @@ -20180,18 +20180,18 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit } switch (src_type->id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdOpaque: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: ir_add_error(ira, dest_type_value, buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -20206,18 +20206,18 @@ static ZigType *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstructionBit } switch (dest_type->id) { - case TypeTableEntryIdInvalid: - case TypeTableEntryIdMetaType: - case TypeTableEntryIdOpaque: - case TypeTableEntryIdBoundFn: - case TypeTableEntryIdArgTuple: - case TypeTableEntryIdNamespace: - case TypeTableEntryIdBlock: - case TypeTableEntryIdUnreachable: - case TypeTableEntryIdComptimeFloat: - case TypeTableEntryIdComptimeInt: - case TypeTableEntryIdUndefined: - case TypeTableEntryIdNull: + case ZigTypeIdInvalid: + case ZigTypeIdMetaType: + case ZigTypeIdOpaque: + case ZigTypeIdBoundFn: + case ZigTypeIdArgTuple: + case ZigTypeIdNamespace: + case ZigTypeIdBlock: + case ZigTypeIdUnreachable: + case ZigTypeIdComptimeFloat: + case ZigTypeIdComptimeInt: + case ZigTypeIdUndefined: + case ZigTypeIdNull: ir_add_error(ira, dest_type_value, buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -20384,7 +20384,7 @@ static ZigType *ir_analyze_instruction_ptr_to_int(IrAnalyze *ira, IrInstructionP ConstExprValue *val = ir_resolve_const(ira, target, UndefBad); if (!val) return ira->codegen->builtin_types.entry_invalid; - if (val->type->id == TypeTableEntryIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { + if (val->type->id == ZigTypeIdPointer && val->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) { IrInstruction *result = ir_create_const(&ira->new_irb, instruction->base.scope, instruction->base.source_node, usize); bigint_init_unsigned(&result->value.data.x_bigint, val->data.x_ptr.data.hard_coded_addr.addr); @@ -20406,10 +20406,10 @@ static ZigType *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstructionPtr if (type_is_invalid(child_type)) return ira->codegen->builtin_types.entry_invalid; - if (child_type->id == TypeTableEntryIdUnreachable) { + if (child_type->id == ZigTypeIdUnreachable) { ir_add_error(ira, &instruction->base, buf_sprintf("pointer to noreturn not allowed")); return ira->codegen->builtin_types.entry_invalid; - } else if (child_type->id == TypeTableEntryIdOpaque && instruction->ptr_len == PtrLenUnknown) { + } else if (child_type->id == ZigTypeIdOpaque && instruction->ptr_len == PtrLenUnknown) { ir_add_error(ira, &instruction->base, buf_sprintf("unknown-length pointer to opaque")); return ira->codegen->builtin_types.entry_invalid; } @@ -20510,7 +20510,7 @@ static ZigType *ir_analyze_instruction_arg_type(IrAnalyze *ira, IrInstructionArg if (!ir_resolve_usize(ira, arg_index_inst, &arg_index)) return ira->codegen->builtin_types.entry_invalid; - if (fn_type->id != TypeTableEntryIdFn) { + if (fn_type->id != ZigTypeIdFn) { ir_add_error(ira, fn_type_inst, buf_sprintf("expected function, found '%s'", buf_ptr(&fn_type->name))); return ira->codegen->builtin_types.entry_invalid; } @@ -20545,14 +20545,14 @@ static ZigType *ir_analyze_instruction_tag_type(IrAnalyze *ira, IrInstructionTag if (type_is_invalid(enum_type)) return ira->codegen->builtin_types.entry_invalid; - if (enum_type->id == TypeTableEntryIdEnum) { + if (enum_type->id == ZigTypeIdEnum) { if ((err = ensure_complete_type(ira->codegen, enum_type))) return ira->codegen->builtin_types.entry_invalid; ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); out_val->data.x_type = enum_type->data.enumeration.tag_int_type; return ira->codegen->builtin_types.entry_type; - } else if (enum_type->id == TypeTableEntryIdUnion) { + } else if (enum_type->id == ZigTypeIdUnion) { if ((err = ensure_complete_type(ira->codegen, enum_type))) return ira->codegen->builtin_types.entry_invalid; @@ -20734,7 +20734,7 @@ static ZigType *ir_analyze_instruction_coro_promise(IrAnalyze *ira, IrInstructio if (type_is_invalid(coro_handle->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (coro_handle->value.type->id != TypeTableEntryIdPromise || + if (coro_handle->value.type->id != ZigTypeIdPromise || coro_handle->value.type->data.promise.result_type == nullptr) { ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'", @@ -20774,7 +20774,7 @@ static ZigType *ir_resolve_atomic_operand_type(IrAnalyze *ira, IrInstruction *op if (type_is_invalid(operand_type)) return ira->codegen->builtin_types.entry_invalid; - if (operand_type->id == TypeTableEntryIdInt) { + if (operand_type->id == ZigTypeIdInt) { if (operand_type->data.integral.bit_count < 8) { ir_add_error(ira, op, buf_sprintf("expected integer type 8 bits or larger, found %" PRIu32 "-bit integer type", @@ -20907,7 +20907,7 @@ static ZigType *ir_analyze_instruction_promise_result_type(IrAnalyze *ira, IrIns if (type_is_invalid(promise_type)) return ira->codegen->builtin_types.entry_invalid; - if (promise_type->id != TypeTableEntryIdPromise || promise_type->data.promise.result_type == nullptr) { + if (promise_type->id != ZigTypeIdPromise || promise_type->data.promise.result_type == nullptr) { ir_add_error(ira, &instruction->base, buf_sprintf("expected promise->T, found '%s'", buf_ptr(&promise_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -20942,9 +20942,9 @@ static ZigType *ir_analyze_instruction_merge_err_ret_traces(IrAnalyze *ira, if (type_is_invalid(coro_promise_ptr->value.type)) return ira->codegen->builtin_types.entry_invalid; - assert(coro_promise_ptr->value.type->id == TypeTableEntryIdPointer); + assert(coro_promise_ptr->value.type->id == ZigTypeIdPointer); ZigType *promise_frame_type = coro_promise_ptr->value.type->data.pointer.child_type; - assert(promise_frame_type->id == TypeTableEntryIdStruct); + assert(promise_frame_type->id == ZigTypeIdStruct); ZigType *promise_result_type = promise_frame_type->data.structure.fields[1].type_entry; if (!type_can_fail(promise_result_type)) { @@ -20997,7 +20997,7 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i if (type_is_invalid(op->value.type)) return ira->codegen->builtin_types.entry_invalid; - bool ok_type = float_type->id == TypeTableEntryIdComptimeFloat || float_type->id == TypeTableEntryIdFloat; + bool ok_type = float_type->id == ZigTypeIdComptimeFloat || float_type->id == ZigTypeIdFloat; if (!ok_type) { ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -21014,9 +21014,9 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); - if (float_type->id == TypeTableEntryIdComptimeFloat) { + if (float_type->id == ZigTypeIdComptimeFloat) { bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat); - } else if (float_type->id == TypeTableEntryIdFloat) { + } else if (float_type->id == ZigTypeIdFloat) { switch (float_type->data.floating.bit_count) { case 16: out_val->data.x_f16 = f16_sqrt(val->data.x_f16); @@ -21040,7 +21040,7 @@ static ZigType *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstructionSqrt *i return float_type; } - assert(float_type->id == TypeTableEntryIdFloat); + assert(float_type->id == ZigTypeIdFloat); if (float_type->data.floating.bit_count != 16 && float_type->data.floating.bit_count != 32 && float_type->data.floating.bit_count != 64) { @@ -21061,7 +21061,7 @@ static ZigType *ir_analyze_instruction_enum_to_int(IrAnalyze *ira, IrInstruction if (type_is_invalid(target->value.type)) return ira->codegen->builtin_types.entry_invalid; - if (target->value.type->id != TypeTableEntryIdEnum) { + if (target->value.type->id != ZigTypeIdEnum) { ir_add_error(ira, instruction->target, buf_sprintf("expected enum, found type '%s'", buf_ptr(&target->value.type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -21084,7 +21084,7 @@ static ZigType *ir_analyze_instruction_int_to_enum(IrAnalyze *ira, IrInstruction if (type_is_invalid(dest_type)) return ira->codegen->builtin_types.entry_invalid; - if (dest_type->id != TypeTableEntryIdEnum) { + if (dest_type->id != ZigTypeIdEnum) { ir_add_error(ira, instruction->dest_type, buf_sprintf("expected enum, found type '%s'", buf_ptr(&dest_type->name))); return ira->codegen->builtin_types.entry_invalid; @@ -21420,8 +21420,8 @@ static ZigType *ir_analyze_instruction(IrAnalyze *ira, IrInstruction *instructio if (instruction->other) { instruction->other->value.type = instruction_type; } else { - assert(instruction_type->id == TypeTableEntryIdInvalid || - instruction_type->id == TypeTableEntryIdUnreachable); + assert(instruction_type->id == ZigTypeIdInvalid || + instruction_type->id == ZigTypeIdUnreachable); instruction->other = instruction; } @@ -21478,7 +21478,7 @@ ZigType *ir_analyze(CodeGen *codegen, IrExecutable *old_exec, IrExecutable *new_ } // unreachable instructions do their own control flow. - if (return_type->id == TypeTableEntryIdUnreachable) + if (return_type->id == ZigTypeIdUnreachable) continue; ira->instruction_index += 1; -- cgit v1.2.3 From a375bd0d9f5c7773598a8ea31af8c963d6a79706 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 6 Sep 2018 11:58:58 -0400 Subject: stage1: compile error instead of incorrect code for unimplemented C ABI See #1411 See #1481 --- src/codegen.cpp | 90 +++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 62 insertions(+), 28 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 0300ccca99..20d700fbbd 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3111,6 +3111,51 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) { LLVMAddCallSiteAttribute(call_instr, 1, sret_attr); } +ATTRIBUTE_NORETURN +static void report_errors_and_exit(CodeGen *g) { + assert(g->errors.length != 0); + for (size_t i = 0; i < g->errors.length; i += 1) { + ErrorMsg *err = g->errors.at(i); + print_err_msg(err, g->err_color); + } + exit(1); +} + +static void report_errors_and_maybe_exit(CodeGen *g) { + if (g->errors.length != 0) { + report_errors_and_exit(g); + } +} + +ATTRIBUTE_NORETURN +static void give_up_with_c_abi_error(CodeGen *g, AstNode *source_node) { + ErrorMsg *msg = add_node_error(g, source_node, + buf_sprintf("TODO: support C ABI for more targets. https://github.com/ziglang/zig/issues/1481")); + add_error_note(g, msg, source_node, + buf_sprintf("pointers, integers, floats, bools, and enums work on all targets")); + report_errors_and_exit(g); +} + +static void gen_c_abi_param(CodeGen *g, ZigList *gen_param_values, LLVMValueRef val, + ZigType *ty, AstNode *source_node) +{ + if (ty->id == ZigTypeIdInt || + ty->id == ZigTypeIdFloat || + ty->id == ZigTypeIdBool || + ty->id == ZigTypeIdEnum || + get_codegen_ptr_type(ty) != nullptr) + { + gen_param_values->append(val); + return; + } + + if (g->zig_target.arch.arch == ZigLLVM_x86_64) { + give_up_with_c_abi_error(g, source_node); + } else { + give_up_with_c_abi_error(g, source_node); + } +} + static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) { LLVMValueRef fn_val; ZigType *fn_type; @@ -3128,29 +3173,25 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr ZigType *src_return_type = fn_type_id->return_type; bool ret_has_bits = type_has_bits(src_return_type); + CallingConvention cc = fn_type->data.fn.fn_type_id.cc; + bool is_c_abi = cc == CallingConventionC; + bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type) && - calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc); + calling_convention_does_first_arg_return(cc); bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, fn_type_id); - // +2 for the async args - size_t actual_param_count = instruction->arg_count + (first_arg_ret ? 1 : 0) + (prefix_arg_err_ret_stack ? 1 : 0) + 2; bool is_var_args = fn_type_id->is_var_args; - LLVMValueRef *gen_param_values = allocate(actual_param_count); - size_t gen_param_index = 0; + ZigList gen_param_values = {}; if (first_arg_ret) { - gen_param_values[gen_param_index] = instruction->tmp_ptr; - gen_param_index += 1; + gen_param_values.append(instruction->tmp_ptr); } if (prefix_arg_err_ret_stack) { - gen_param_values[gen_param_index] = get_cur_err_ret_trace_val(g, instruction->base.scope); - gen_param_index += 1; + gen_param_values.append(get_cur_err_ret_trace_val(g, instruction->base.scope)); } if (instruction->is_async) { - gen_param_values[gen_param_index] = ir_llvm_value(g, instruction->async_allocator); - gen_param_index += 1; + gen_param_values.append(ir_llvm_value(g, instruction->async_allocator)); LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, err_union_err_index, ""); - gen_param_values[gen_param_index] = err_val_ptr; - gen_param_index += 1; + gen_param_values.append(err_val_ptr); } for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) { IrInstruction *param_instruction = instruction->args[call_i]; @@ -3158,8 +3199,11 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr if (is_var_args || type_has_bits(param_type)) { LLVMValueRef param_value = ir_llvm_value(g, param_instruction); assert(param_value); - gen_param_values[gen_param_index] = param_value; - gen_param_index += 1; + if (is_c_abi) { + gen_c_abi_param(g, &gen_param_values, param_value, param_type, param_instruction->source_node); + } else { + gen_param_values.append(param_value); + } } } @@ -3176,12 +3220,12 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr break; } - LLVMCallConv llvm_cc = get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc); + LLVMCallConv llvm_cc = get_llvm_cc(g, cc); LLVMValueRef result; if (instruction->new_stack == nullptr) { result = ZigLLVMBuildCall(g->builder, fn_val, - gen_param_values, (unsigned)gen_param_index, llvm_cc, fn_inline, ""); + gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, fn_inline, ""); } else { LLVMValueRef stacksave_fn_val = get_stacksave_fn_val(g); LLVMValueRef stackrestore_fn_val = get_stackrestore_fn_val(g); @@ -3190,7 +3234,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr LLVMValueRef old_stack_ref = LLVMBuildCall(g->builder, stacksave_fn_val, nullptr, 0, ""); gen_set_stack_pointer(g, new_stack_addr); result = ZigLLVMBuildCall(g->builder, fn_val, - gen_param_values, (unsigned)gen_param_index, llvm_cc, fn_inline, ""); + gen_param_values.items, (unsigned)gen_param_values.length, llvm_cc, fn_inline, ""); LLVMBuildCall(g->builder, stackrestore_fn_val, &old_stack_ref, 1, ""); } @@ -5735,16 +5779,6 @@ static void ensure_cache_dir(CodeGen *g) { } } -static void report_errors_and_maybe_exit(CodeGen *g) { - if (g->errors.length != 0) { - for (size_t i = 0; i < g->errors.length; i += 1) { - ErrorMsg *err = g->errors.at(i); - print_err_msg(err, g->err_color); - } - exit(1); - } -} - static void validate_inline_fns(CodeGen *g) { for (size_t i = 0; i < g->inline_fns.length; i += 1) { ZigFn *fn_entry = g->inline_fns.at(i); -- cgit v1.2.3 From a9a925e500c66b8eb57d619b9b6828c70a13d4c5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 6 Sep 2018 16:29:35 -0400 Subject: add C ABI tests --- src/analyze.cpp | 122 ++++++++++++++++------ src/analyze.hpp | 2 + src/codegen.cpp | 242 ++++++++++++++++++++++++++++++++++++++++---- std/build.zig | 27 +++++ test/build_examples.zig | 6 ++ test/gen_h.zig | 28 ++++- test/stage1/c_abi/build.zig | 17 ++++ test/stage1/c_abi/cfuncs.c | 64 ++++++++++++ test/stage1/c_abi/main.zig | 58 +++++++++++ 9 files changed, 515 insertions(+), 51 deletions(-) create mode 100644 test/stage1/c_abi/build.zig create mode 100644 test/stage1/c_abi/cfuncs.c create mode 100644 test/stage1/c_abi/main.zig (limited to 'src/codegen.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index aa4fda7624..7014c0ea9d 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1061,6 +1061,77 @@ ZigType *get_ptr_to_stack_trace_type(CodeGen *g) { return g->ptr_to_stack_trace_type; } +bool type_is_c_abi_int(CodeGen *g, ZigType *ty) { + size_t ty_size = type_size(g, ty); + if (ty_size > g->pointer_size_bytes) + return false; + return (ty->id == ZigTypeIdInt || + ty->id == ZigTypeIdFloat || + ty->id == ZigTypeIdBool || + ty->id == ZigTypeIdEnum || + get_codegen_ptr_type(ty) != nullptr); +} + +// If you edit this function you have to edit the corresponding code: +// codegen.cpp:gen_c_abi_param +// analyze.cpp:gen_c_abi_param_type +// codegen.cpp:gen_c_abi_param_var +// codegen.cpp:gen_c_abi_param_var_init +static void gen_c_abi_param_type(CodeGen *g, ZigList *gen_param_types, + ZigList *param_di_types, ZigType *ty) +{ + if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || + ty->id == ZigTypeIdInt // TODO investigate if we need to change this + ) { + gen_param_types->append(ty->type_ref); + param_di_types->append(ty->di_type); + return; + } + + // Arrays are just pointers + if (ty->id == ZigTypeIdArray) { + ZigType *gen_type = get_pointer_to_type(g, ty, true); + gen_param_types->append(gen_type->type_ref); + param_di_types->append(gen_type->di_type); + return; + } + + if (g->zig_target.arch.arch == ZigLLVM_x86_64) { + size_t ty_size = type_size(g, ty); + if (ty->id == ZigTypeIdStruct || ty->id == ZigTypeIdUnion) { + // "If the size of an object is larger than four eightbytes, or it contains unaligned + // fields, it has class MEMORY" + if (ty_size > 32) { + ZigType *gen_type = get_pointer_to_type(g, ty, true); + gen_param_types->append(gen_type->type_ref); + param_di_types->append(gen_type->di_type); + return; + } + } + if (ty->id == ZigTypeIdStruct) { + // "If the size of the aggregate exceeds a single eightbyte, each is classified + // separately. Each eightbyte gets initialized to class NO_CLASS." + if (ty_size <= 8) { + bool contains_int = false; + for (size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { + if (type_is_c_abi_int(g, ty->data.structure.fields[i].type_entry)) { + contains_int = true; + break; + } + } + if (contains_int) { + ZigType *gen_type = get_int_type(g, false, ty_size * 8); + gen_param_types->append(gen_type->type_ref); + param_di_types->append(gen_type->di_type); + return; + } + } + } + } + + // allow codegen code to report a compile error +} + ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { Error err; auto table_entry = g->fn_type_table.maybe_get(fn_type_id); @@ -1119,18 +1190,18 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { bool first_arg_return = calling_convention_does_first_arg_return(fn_type_id->cc) && handle_is_ptr(fn_type_id->return_type); bool is_async = fn_type_id->cc == CallingConventionAsync; + bool is_c_abi = fn_type_id->cc == CallingConventionC; bool prefix_arg_error_return_trace = g->have_err_ret_tracing && fn_type_can_fail(fn_type_id); // +1 for maybe making the first argument the return value // +1 for maybe first argument the error return trace // +2 for maybe arguments async allocator and error code pointer - LLVMTypeRef *gen_param_types = allocate(4 + fn_type_id->param_count); + ZigList gen_param_types = {}; // +1 because 0 is the return type and // +1 for maybe making first arg ret val and // +1 for maybe first argument the error return trace // +2 for maybe arguments async allocator and error code pointer - ZigLLVMDIType **param_di_types = allocate(5 + fn_type_id->param_count); - param_di_types[0] = fn_type_id->return_type->di_type; - size_t gen_param_index = 0; + ZigList param_di_types = {}; + param_di_types.append(fn_type_id->return_type->di_type); ZigType *gen_return_type; if (is_async) { gen_return_type = get_pointer_to_type(g, g->builtin_types.entry_u8, false); @@ -1138,10 +1209,8 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { gen_return_type = g->builtin_types.entry_void; } else if (first_arg_return) { ZigType *gen_type = get_pointer_to_type(g, fn_type_id->return_type, false); - gen_param_types[gen_param_index] = gen_type->type_ref; - gen_param_index += 1; - // after the gen_param_index += 1 because 0 is the return type - param_di_types[gen_param_index] = gen_type->di_type; + gen_param_types.append(gen_type->type_ref); + param_di_types.append(gen_type->di_type); gen_return_type = g->builtin_types.entry_void; } else { gen_return_type = fn_type_id->return_type; @@ -1150,28 +1219,22 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { if (prefix_arg_error_return_trace) { ZigType *gen_type = get_ptr_to_stack_trace_type(g); - gen_param_types[gen_param_index] = gen_type->type_ref; - gen_param_index += 1; - // after the gen_param_index += 1 because 0 is the return type - param_di_types[gen_param_index] = gen_type->di_type; + gen_param_types.append(gen_type->type_ref); + param_di_types.append(gen_type->di_type); } if (is_async) { { // async allocator param ZigType *gen_type = fn_type_id->async_allocator_type; - gen_param_types[gen_param_index] = gen_type->type_ref; - gen_param_index += 1; - // after the gen_param_index += 1 because 0 is the return type - param_di_types[gen_param_index] = gen_type->di_type; + gen_param_types.append(gen_type->type_ref); + param_di_types.append(gen_type->di_type); } { // error code pointer ZigType *gen_type = get_pointer_to_type(g, g->builtin_types.entry_global_error_set, false); - gen_param_types[gen_param_index] = gen_type->type_ref; - gen_param_index += 1; - // after the gen_param_index += 1 because 0 is the return type - param_di_types[gen_param_index] = gen_type->di_type; + gen_param_types.append(gen_type->type_ref); + param_di_types.append(gen_type->di_type); } } @@ -1187,7 +1250,9 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { if ((err = ensure_complete_type(g, type_entry))) return g->builtin_types.entry_invalid; - if (type_has_bits(type_entry)) { + if (is_c_abi) { + gen_c_abi_param_type(g, &gen_param_types, ¶m_di_types, type_entry); + } else if (type_has_bits(type_entry)) { ZigType *gen_type; if (handle_is_ptr(type_entry)) { gen_type = get_pointer_to_type(g, type_entry, true); @@ -1195,23 +1260,20 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { } else { gen_type = type_entry; } - gen_param_types[gen_param_index] = gen_type->type_ref; - gen_param_info->gen_index = gen_param_index; + gen_param_info->gen_index = gen_param_types.length; gen_param_info->type = gen_type; + gen_param_types.append(gen_type->type_ref); - gen_param_index += 1; - - // after the gen_param_index += 1 because 0 is the return type - param_di_types[gen_param_index] = gen_type->di_type; + param_di_types.append(gen_type->di_type); } } - fn_type->data.fn.gen_param_count = gen_param_index; + fn_type->data.fn.gen_param_count = gen_param_types.length; fn_type->data.fn.raw_type_ref = LLVMFunctionType(gen_return_type->type_ref, - gen_param_types, (unsigned int)gen_param_index, fn_type_id->is_var_args); + gen_param_types.items, (unsigned int)gen_param_types.length, fn_type_id->is_var_args); fn_type->type_ref = LLVMPointerType(fn_type->data.fn.raw_type_ref, 0); - fn_type->di_type = ZigLLVMCreateSubroutineType(g->dbuilder, param_di_types, (int)(gen_param_index + 1), 0); + fn_type->di_type = ZigLLVMCreateSubroutineType(g->dbuilder, param_di_types.items, (int)param_di_types.length, 0); } g->fn_type_table.put(&fn_type->data.fn.fn_type_id, fn_type); diff --git a/src/analyze.hpp b/src/analyze.hpp index 41cc50916e..f13c528c5a 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -210,4 +210,6 @@ ZigType *get_primitive_type(CodeGen *g, Buf *name); bool calling_convention_allows_zig_types(CallingConvention cc); const char *calling_convention_name(CallingConvention cc); +bool type_is_c_abi_int(CodeGen *g, ZigType *ty); + #endif diff --git a/src/codegen.cpp b/src/codegen.cpp index 20d700fbbd..f35f146bb4 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3136,24 +3136,226 @@ static void give_up_with_c_abi_error(CodeGen *g, AstNode *source_node) { report_errors_and_exit(g); } +static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) { + assert(alignment > 0); + LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name); + LLVMSetAlignment(result, alignment); + return result; +} + +// If you edit this function you have to edit the corresponding code: +// codegen.cpp:gen_c_abi_param +// analyze.cpp:gen_c_abi_param_type +// codegen.cpp:gen_c_abi_param_var +// codegen.cpp:gen_c_abi_param_var_init static void gen_c_abi_param(CodeGen *g, ZigList *gen_param_values, LLVMValueRef val, ZigType *ty, AstNode *source_node) { - if (ty->id == ZigTypeIdInt || - ty->id == ZigTypeIdFloat || - ty->id == ZigTypeIdBool || - ty->id == ZigTypeIdEnum || - get_codegen_ptr_type(ty) != nullptr) - { + if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || + ty->id == ZigTypeIdInt // TODO investigate if we need to change this + ) { + gen_param_values->append(val); + return; + } + + // Arrays are just pointers + if (ty->id == ZigTypeIdArray) { + assert(handle_is_ptr(ty)); gen_param_values->append(val); return; } if (g->zig_target.arch.arch == ZigLLVM_x86_64) { - give_up_with_c_abi_error(g, source_node); - } else { - give_up_with_c_abi_error(g, source_node); + // This code all assumes that val is a pointer. + assert(handle_is_ptr(ty)); + + size_t ty_size = type_size(g, ty); + if (ty->id == ZigTypeIdStruct || ty->id == ZigTypeIdUnion) { + // "If the size of an object is larger than four eightbytes, or it contains unaligned + // fields, it has class MEMORY" + if (ty_size > 32) { + gen_param_values->append(val); + return; + } + } + if (ty->id == ZigTypeIdStruct) { + // "If the size of the aggregate exceeds a single eightbyte, each is classified + // separately. Each eightbyte gets initialized to class NO_CLASS." + if (ty_size <= 8) { + bool contains_int = false; + for (size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { + if (type_is_c_abi_int(g, ty->data.structure.fields[i].type_entry)) { + contains_int = true; + break; + } + } + if (contains_int) { + LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); + LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, val, ptr_to_int_type_ref, ""); + LLVMValueRef loaded = LLVMBuildLoad(g->builder, bitcasted, ""); + gen_param_values->append(loaded); + return; + } + } + } + } + + give_up_with_c_abi_error(g, source_node); +} + +// If you edit this function you have to edit the corresponding code: +// codegen.cpp:gen_c_abi_param +// analyze.cpp:gen_c_abi_param_type +// codegen.cpp:gen_c_abi_param_var +// codegen.cpp:gen_c_abi_param_var_init +static void gen_c_abi_param_var(CodeGen *g, ImportTableEntry *import, LLVMValueRef llvm_fn, ZigFn *fn, + ZigVar *var, unsigned *arg_index) +{ + ZigType *ty = var->value->type; + + ZigType *dest_ty = nullptr; + unsigned di_arg_index; + + if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || + ty->id == ZigTypeIdInt // TODO investigate if we need to change this + ) { + var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes); + di_arg_index = *arg_index; + *arg_index += 1; + dest_ty = ty; + goto ok; + } + + // Arrays are just pointers + if (ty->id == ZigTypeIdArray) { + di_arg_index = *arg_index; + var->value_ref = LLVMGetParam(llvm_fn, *arg_index); + dest_ty = get_pointer_to_type(g, ty, false); + *arg_index += 1; + goto ok; + } + + if (g->zig_target.arch.arch == ZigLLVM_x86_64) { + assert(handle_is_ptr(ty)); + size_t ty_size = type_size(g, ty); + + if (ty->id == ZigTypeIdStruct || ty->id == ZigTypeIdUnion) { + // "If the size of an object is larger than four eightbytes, or it contains unaligned + // fields, it has class MEMORY" + if (ty_size > 32) { + di_arg_index = *arg_index; + var->value_ref = LLVMGetParam(llvm_fn, *arg_index); + dest_ty = get_pointer_to_type(g, ty, false); + *arg_index += 1; + goto ok; + } + } + if (ty->id == ZigTypeIdStruct) { + // "If the size of the aggregate exceeds a single eightbyte, each is classified + // separately. Each eightbyte gets initialized to class NO_CLASS." + if (ty_size <= 8) { + bool contains_int = false; + for (size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { + if (type_is_c_abi_int(g, ty->data.structure.fields[i].type_entry)) { + contains_int = true; + break; + } + } + if (contains_int) { + var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes); + *arg_index += 1; + goto ok; + } + } + } + } + + give_up_with_c_abi_error(g, fn->proto_node); + +ok: + if (dest_ty != nullptr && var->decl_node) { + // arg index + 1 because the 0 index is return value + var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope), + buf_ptr(&var->name), import->di_file, + (unsigned)(var->decl_node->line + 1), + dest_ty->di_type, !g->strip_debug_symbols, 0, di_arg_index + 1); + } +} + +// If you edit this function you have to edit the corresponding code: +// codegen.cpp:gen_c_abi_param +// analyze.cpp:gen_c_abi_param_type +// codegen.cpp:gen_c_abi_param_var +// codegen.cpp:gen_c_abi_param_var_init +static void gen_c_abi_param_var_init(CodeGen *g, ImportTableEntry *import, LLVMValueRef llvm_fn, ZigFn *fn, + ZigVar *var, unsigned *arg_index) +{ + ZigType *ty = var->value->type; + + if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || + ty->id == ZigTypeIdInt // TODO investigate if we need to change this + ) { + clear_debug_source_node(g); + gen_store_untyped(g, LLVMGetParam(llvm_fn, *arg_index), var->value_ref, var->align_bytes, false); + if (var->decl_node) { + gen_var_debug_decl(g, var); + } + *arg_index += 1; + return; + } + + // Arrays are just pointers + if (ty->id == ZigTypeIdArray) { + if (var->decl_node) { + gen_var_debug_decl(g, var); + } + *arg_index += 1; + return; + } + + if (g->zig_target.arch.arch == ZigLLVM_x86_64) { + assert(handle_is_ptr(ty)); + size_t ty_size = type_size(g, ty); + + if (ty->id == ZigTypeIdStruct || ty->id == ZigTypeIdUnion) { + // "If the size of an object is larger than four eightbytes, or it contains unaligned + // fields, it has class MEMORY" + if (ty_size > 32) { + if (var->decl_node) { + gen_var_debug_decl(g, var); + } + *arg_index += 1; + return; + } + } + if (ty->id == ZigTypeIdStruct) { + // "If the size of the aggregate exceeds a single eightbyte, each is classified + // separately. Each eightbyte gets initialized to class NO_CLASS." + if (ty_size <= 8) { + bool contains_int = false; + for (size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { + if (type_is_c_abi_int(g, ty->data.structure.fields[i].type_entry)) { + contains_int = true; + break; + } + } + if (contains_int) { + clear_debug_source_node(g); + LLVMValueRef arg = LLVMGetParam(llvm_fn, *arg_index); + LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); + LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, var->value_ref, ptr_to_int_type_ref, ""); + gen_store_untyped(g, arg, bitcasted, var->align_bytes, false); + if (var->decl_node) { + gen_var_debug_decl(g, var); + } + *arg_index += 1; + return; + } + } + } } + + give_up_with_c_abi_error(g, fn->proto_node); } static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) { @@ -5765,13 +5967,6 @@ static void gen_global_var(CodeGen *g, ZigVar *var, LLVMValueRef init_val, // TODO ^^ make an actual global variable } -static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) { - assert(alignment > 0); - LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name); - LLVMSetAlignment(result, alignment); - return result; -} - static void ensure_cache_dir(CodeGen *g) { int err; if ((err = os_make_path(&g->cache_dir))) { @@ -5899,6 +6094,8 @@ static void do_code_gen(CodeGen *g) { // Generate function definitions. for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) { ZigFn *fn_table_entry = g->fn_defs.at(fn_i); + CallingConvention cc = fn_table_entry->type_entry->data.fn.fn_type_id.cc; + bool is_c_abi = cc == CallingConventionC; LLVMValueRef fn = fn_llvm_value(g, fn_table_entry); g->cur_fn = fn_table_entry; @@ -5922,7 +6119,7 @@ static void do_code_gen(CodeGen *g) { } // error return tracing setup - bool is_async = fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionAsync; + bool is_async = cc == CallingConventionAsync; bool have_err_ret_trace_stack = g->have_err_ret_tracing && fn_table_entry->calls_or_awaits_errorable_fn && !is_async && !have_err_ret_trace_arg; LLVMValueRef err_ret_array_val = nullptr; if (have_err_ret_trace_stack) { @@ -5982,6 +6179,7 @@ static void do_code_gen(CodeGen *g) { ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base); // create debug variable declarations for variables and allocate all local variables + unsigned c_abi_arg_index = 0; for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) { ZigVar *var = fn_table_entry->variable_list.at(var_i); @@ -6000,6 +6198,8 @@ static void do_code_gen(CodeGen *g) { buf_ptr(&var->name), import->di_file, (unsigned)(var->decl_node->line + 1), var->value->type->di_type, !g->strip_debug_symbols, 0); + } else if (is_c_abi) { + gen_c_abi_param_var(g, import, fn, fn_table_entry, var, &c_abi_arg_index); } else { assert(var->gen_arg_index != SIZE_MAX); ZigType *gen_type; @@ -6056,7 +6256,14 @@ static void do_code_gen(CodeGen *g) { // create debug variable declarations for parameters // rely on the first variables in the variable_list being parameters. size_t next_var_i = 0; + unsigned c_abi_arg_init_index = 0; for (size_t param_i = 0; param_i < fn_type_id->param_count; param_i += 1) { + if (is_c_abi) { + ZigVar *var = fn_table_entry->variable_list.at(param_i); + gen_c_abi_param_var_init(g, import, fn, fn_table_entry, var, &c_abi_arg_init_index); + continue; + } + FnGenParamInfo *info = &fn_table_entry->type_entry->data.fn.gen_param_info[param_i]; if (info->gen_index == SIZE_MAX) continue; @@ -6078,6 +6285,7 @@ static void do_code_gen(CodeGen *g) { gen_var_debug_decl(g, variable); } } + assert(c_abi_arg_index == c_abi_arg_init_index); ir_render(g, fn_table_entry); diff --git a/std/build.zig b/std/build.zig index 08bb5635d9..4e323eaf7b 100644 --- a/std/build.zig +++ b/std/build.zig @@ -48,6 +48,12 @@ pub const Builder = struct { cache_root: []const u8, release_mode: ?builtin.Mode, + pub const CStd = enum { + C89, + C99, + C11, + }; + const UserInputOptionsMap = HashMap([]const u8, UserInputOption, mem.hash_slice_u8, mem.eql_slice_u8); const AvailableOptionsMap = HashMap([]const u8, AvailableOption, mem.hash_slice_u8, mem.eql_slice_u8); @@ -817,6 +823,7 @@ pub const LibExeObjStep = struct { frameworks: BufSet, verbose_link: bool, no_rosegment: bool, + c_std: Builder.CStd, // zig only stuff root_src: ?[]const u8, @@ -918,6 +925,7 @@ pub const LibExeObjStep = struct { .object_src = undefined, .disable_libc = true, .build_options_contents = std.Buffer.initSize(builder.allocator, 0) catch unreachable, + .c_std = Builder.CStd.C99, }; self.computeOutFileNames(); return self; @@ -952,6 +960,7 @@ pub const LibExeObjStep = struct { .disable_libc = false, .is_zig = false, .linker_script = null, + .c_std = Builder.CStd.C99, .root_src = undefined, .verbose_link = false, @@ -1392,6 +1401,13 @@ pub const LibExeObjStep = struct { const is_darwin = self.target.isDarwin(); + const c_std_arg = switch (self.c_std) { + Builder.CStd.C89 => "-std=c89", + Builder.CStd.C99 => "-std=c99", + Builder.CStd.C11 => "-std=c11", + }; + try cc_args.append(c_std_arg); + switch (self.kind) { Kind.Obj => { cc_args.append("-c") catch unreachable; @@ -1678,6 +1694,17 @@ pub const TestStep = struct { self.filter = text; } + pub fn addObject(self: *TestStep, obj: *LibExeObjStep) void { + assert(obj.kind == LibExeObjStep.Kind.Obj); + + self.step.dependOn(&obj.step); + + self.object_files.append(obj.getOutputPath()) catch unreachable; + + // TODO should be some kind of isolated directory that only has this header in it + self.include_dirs.append(self.builder.cache_root) catch unreachable; + } + pub fn addObjectFile(self: *TestStep, path: []const u8) void { self.object_files.append(path) catch unreachable; } diff --git a/test/build_examples.zig b/test/build_examples.zig index 79192c3e9a..96112fe687 100644 --- a/test/build_examples.zig +++ b/test/build_examples.zig @@ -28,4 +28,10 @@ pub fn addCases(cases: *tests.BuildExamplesContext) void { // TODO figure out how to make this work on darwin - probably libSystem has dlopen/dlsym in it cases.addBuildFile("test/standalone/load_dynamic_library/build.zig"); } + + if (!is_windows // TODO support compiling C files on windows with zig build system + and builtin.arch == builtin.Arch.x86_64 // TODO add C ABI support for other architectures + ) { + cases.addBuildFile("test/stage1/c_abi/build.zig"); + } } diff --git a/test/gen_h.zig b/test/gen_h.zig index b3aaa263d6..11fb55344f 100644 --- a/test/gen_h.zig +++ b/test/gen_h.zig @@ -20,6 +20,9 @@ pub fn addCases(cases: *tests.GenHContext) void { \\ A: i32, \\ B: f32, \\ C: bool, + \\ D: u64, + \\ E: u64, + \\ F: u64, \\}; \\export fn entry(foo: Foo) void { } , @@ -27,6 +30,9 @@ pub fn addCases(cases: *tests.GenHContext) void { \\ int32_t A; \\ float B; \\ bool C; + \\ uint64_t D; + \\ uint64_t E; + \\ uint64_t F; \\}; \\ \\TEST_EXPORT void entry(struct Foo foo); @@ -34,17 +40,34 @@ pub fn addCases(cases: *tests.GenHContext) void { ); cases.add("declare union", + \\const Big = extern struct { + \\ A: u64, + \\ B: u64, + \\ C: u64, + \\ D: u64, + \\ E: u64, + \\}; \\const Foo = extern union { \\ A: i32, \\ B: f32, \\ C: bool, + \\ D: Big, \\}; - \\export fn entry(foo: Foo) void { } + \\export fn entry(foo: Foo) void {} , + \\struct Big { + \\ uint64_t A; + \\ uint64_t B; + \\ uint64_t C; + \\ uint64_t D; + \\ uint64_t E; + \\}; + \\ \\union Foo { \\ int32_t A; \\ float B; \\ bool C; + \\ struct Big D; \\}; \\ \\TEST_EXPORT void entry(union Foo foo); @@ -85,7 +108,6 @@ pub fn addCases(cases: *tests.GenHContext) void { \\export fn a(s: *S) u8 { \\ return s.a; \\} - , \\struct S; \\TEST_EXPORT uint8_t a(struct S * s); @@ -101,7 +123,6 @@ pub fn addCases(cases: *tests.GenHContext) void { \\export fn a(s: *U) u8 { \\ return s.A; \\} - , \\union U; \\TEST_EXPORT uint8_t a(union U * s); @@ -117,7 +138,6 @@ pub fn addCases(cases: *tests.GenHContext) void { \\export fn a(s: *E) u8 { \\ return @enumToInt(s.*); \\} - , \\enum E; \\TEST_EXPORT uint8_t a(enum E * s); diff --git a/test/stage1/c_abi/build.zig b/test/stage1/c_abi/build.zig new file mode 100644 index 0000000000..02db8f7904 --- /dev/null +++ b/test/stage1/c_abi/build.zig @@ -0,0 +1,17 @@ +const Builder = @import("std").build.Builder; + +pub fn build(b: *Builder) void { + const rel_opts = b.standardReleaseOptions(); + + const c_obj = b.addCObject("cfuncs", "cfuncs.c"); + c_obj.setBuildMode(rel_opts); + + const main = b.addTest("main.zig"); + main.setBuildMode(rel_opts); + main.addObject(c_obj); + + const test_step = b.step("test", "Test the program"); + test_step.dependOn(&main.step); + + b.default_step.dependOn(test_step); +} diff --git a/test/stage1/c_abi/cfuncs.c b/test/stage1/c_abi/cfuncs.c new file mode 100644 index 0000000000..aef4618747 --- /dev/null +++ b/test/stage1/c_abi/cfuncs.c @@ -0,0 +1,64 @@ +#include +#include +#include + +void zig_panic(); + +static void assert_or_panic(bool ok) { + if (!ok) { + zig_panic(); + } +} + +void zig_u8(uint8_t); +void zig_u16(uint16_t); +void zig_u32(uint32_t); +void zig_u64(uint64_t); +void zig_i8(int8_t); +void zig_i16(int16_t); +void zig_i32(int32_t); +void zig_i64(int64_t); + +void run_c_tests(void) { + zig_u8(0xff); + zig_u16(0xfffe); + zig_u32(0xfffffffd); + zig_u64(0xfffffffffffffffc); + + zig_i8(-1); + zig_i16(-2); + zig_i32(-3); + zig_i64(-4); +} + +void c_u8(uint8_t x) { + assert_or_panic(x == 0xff); +} + +void c_u16(uint16_t x) { + assert_or_panic(x == 0xfffe); +} + +void c_u32(uint32_t x) { + assert_or_panic(x == 0xfffffffd); +} + +void c_u64(uint64_t x) { + assert_or_panic(x == 0xfffffffffffffffcULL); +} + +void c_i8(int8_t x) { + assert_or_panic(x == -1); +} + +void c_i16(int16_t x) { + assert_or_panic(x == -2); +} + +void c_i32(int32_t x) { + assert_or_panic(x == -3); +} + +void c_i64(int64_t x) { + assert_or_panic(x == -4); +} diff --git a/test/stage1/c_abi/main.zig b/test/stage1/c_abi/main.zig new file mode 100644 index 0000000000..c409def6c7 --- /dev/null +++ b/test/stage1/c_abi/main.zig @@ -0,0 +1,58 @@ +const std = @import("std"); +const assertOrPanic = std.debug.assertOrPanic; + +extern fn run_c_tests() void; + +export fn zig_panic() noreturn { + @panic("zig_panic called from C"); +} + +test "C importing Zig ABI Tests" { + run_c_tests(); +} + +extern fn c_u8(u8) void; +extern fn c_u16(u16) void; +extern fn c_u32(u32) void; +extern fn c_u64(u64) void; +extern fn c_i8(i8) void; +extern fn c_i16(i16) void; +extern fn c_i32(i32) void; +extern fn c_i64(i64) void; + +test "C ABI integers" { + c_u8(0xff); + c_u16(0xfffe); + c_u32(0xfffffffd); + c_u64(0xfffffffffffffffc); + + c_i8(-1); + c_i16(-2); + c_i32(-3); + c_i64(-4); +} + +export fn zig_u8(x: u8) void { + assertOrPanic(x == 0xff); +} +export fn zig_u16(x: u16) void { + assertOrPanic(x == 0xfffe); +} +export fn zig_u32(x: u32) void { + assertOrPanic(x == 0xfffffffd); +} +export fn zig_u64(x: u64) void { + assertOrPanic(x == 0xfffffffffffffffc); +} +export fn zig_i8(x: i8) void { + assertOrPanic(x == -1); +} +export fn zig_i16(x: i16) void { + assertOrPanic(x == -2); +} +export fn zig_i32(x: i32) void { + assertOrPanic(x == -3); +} +export fn zig_i64(x: i64) void { + assertOrPanic(x == -4); +} -- cgit v1.2.3 From be6cccb3a51512dea011326d9ad30ad495e7c716 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Sep 2018 11:52:57 -0400 Subject: stage1: c abi for big struct works --- src/all_types.hpp | 24 +++ src/analyze.cpp | 1 - src/codegen.cpp | 357 ++++++++++++++++++++++++++++----------------- src/codegen.hpp | 1 + test/stage1/c_abi/cfuncs.c | 71 +++++++++ test/stage1/c_abi/main.zig | 74 ++++++++++ 6 files changed, 396 insertions(+), 132 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index dbaa3b5467..a89a94c0a0 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -3284,4 +3284,28 @@ enum FloatMode { FloatModeStrict, }; +enum FnWalkId { + FnWalkIdAttrs, + FnWalkIdCall, +}; + +struct FnWalkAttrs { + ZigFn *fn; + unsigned gen_i; +}; + +struct FnWalkCall { + ZigList *gen_param_values; + IrInstructionCall *inst; + bool is_var_args; +}; + +struct FnWalk { + FnWalkId id; + union { + FnWalkAttrs attrs; + FnWalkCall call; + } data; +}; + #endif diff --git a/src/analyze.cpp b/src/analyze.cpp index 7014c0ea9d..a658c469ac 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1073,7 +1073,6 @@ bool type_is_c_abi_int(CodeGen *g, ZigType *ty) { } // If you edit this function you have to edit the corresponding code: -// codegen.cpp:gen_c_abi_param // analyze.cpp:gen_c_abi_param_type // codegen.cpp:gen_c_abi_param_var // codegen.cpp:gen_c_abi_param_var_init diff --git a/src/codegen.cpp b/src/codegen.cpp index f35f146bb4..469d62f3a2 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -466,7 +466,8 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) { } bool external_linkage = linkage != GlobalLinkageIdInternal; - if (fn_table_entry->type_entry->data.fn.fn_type_id.cc == CallingConventionStdcall && external_linkage && + CallingConvention cc = fn_table_entry->type_entry->data.fn.fn_type_id.cc; + if (cc == CallingConventionStdcall && external_linkage && g->zig_target.arch.arch == ZigLLVM_x86) { // prevent llvm name mangling @@ -510,17 +511,17 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) { break; } - if (fn_type->data.fn.fn_type_id.cc == CallingConventionNaked) { + if (cc == CallingConventionNaked) { addLLVMFnAttr(fn_table_entry->llvm_value, "naked"); } else { LLVMSetFunctionCallConv(fn_table_entry->llvm_value, get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc)); } - if (fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) { + if (cc == CallingConventionAsync) { addLLVMFnAttr(fn_table_entry->llvm_value, "optnone"); addLLVMFnAttr(fn_table_entry->llvm_value, "noinline"); } - bool want_cold = fn_table_entry->is_cold || fn_type->data.fn.fn_type_id.cc == CallingConventionCold; + bool want_cold = fn_table_entry->is_cold || cc == CallingConventionCold; if (want_cold) { ZigLLVMAddFunctionAttrCold(fn_table_entry->llvm_value); } @@ -576,37 +577,16 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) { // nothing to do } else if (type_is_codegen_pointer(return_type)) { addLLVMAttr(fn_table_entry->llvm_value, 0, "nonnull"); - } else if (handle_is_ptr(return_type) && - calling_convention_does_first_arg_return(fn_type->data.fn.fn_type_id.cc)) - { + } else if (handle_is_ptr(return_type) && calling_convention_does_first_arg_return(cc)) { addLLVMArgAttr(fn_table_entry->llvm_value, 0, "sret"); addLLVMArgAttr(fn_table_entry->llvm_value, 0, "nonnull"); } - // set parameter attributes - for (size_t param_i = 0; param_i < fn_type->data.fn.fn_type_id.param_count; param_i += 1) { - FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i]; - size_t gen_index = gen_info->gen_index; - bool is_byval = gen_info->is_byval; - - if (gen_index == SIZE_MAX) { - continue; - } - - FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[param_i]; - - ZigType *param_type = gen_info->type; - if (param_info->is_noalias) { - addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "noalias"); - } - if ((param_type->id == ZigTypeIdPointer && param_type->data.pointer.is_const) || is_byval) { - addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "readonly"); - } - if (param_type->id == ZigTypeIdPointer) { - addLLVMArgAttr(fn_table_entry->llvm_value, (unsigned)gen_index, "nonnull"); - } - } + FnWalk fn_walk = {}; + fn_walk.id = FnWalkIdAttrs; + fn_walk.data.attrs.fn = fn_table_entry; + walk_function_params(g, fn_type, &fn_walk); uint32_t err_ret_trace_arg_index = get_err_ret_trace_arg_index(g, fn_table_entry); if (err_ret_trace_arg_index != UINT32_MAX) { @@ -1888,6 +1868,216 @@ static LLVMValueRef ir_llvm_value(CodeGen *g, IrInstruction *instruction) { return instruction->llvm_value; } +ATTRIBUTE_NORETURN +static void report_errors_and_exit(CodeGen *g) { + assert(g->errors.length != 0); + for (size_t i = 0; i < g->errors.length; i += 1) { + ErrorMsg *err = g->errors.at(i); + print_err_msg(err, g->err_color); + } + exit(1); +} + +static void report_errors_and_maybe_exit(CodeGen *g) { + if (g->errors.length != 0) { + report_errors_and_exit(g); + } +} + +ATTRIBUTE_NORETURN +static void give_up_with_c_abi_error(CodeGen *g, AstNode *source_node) { + ErrorMsg *msg = add_node_error(g, source_node, + buf_sprintf("TODO: support C ABI for more targets. https://github.com/ziglang/zig/issues/1481")); + add_error_note(g, msg, source_node, + buf_sprintf("pointers, integers, floats, bools, and enums work on all targets")); + report_errors_and_exit(g); +} + +static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk, size_t src_i) { + // Initialized from the type for some walks, but because of C var args, + // initialized based on callsite instructions for that one. + FnTypeParamInfo *param_info = nullptr; + ZigType *ty; + AstNode *source_node = nullptr; + LLVMValueRef val; + LLVMValueRef llvm_fn; + switch (fn_walk->id) { + case FnWalkIdAttrs: + if (src_i >= fn_type->data.fn.fn_type_id.param_count) + return false; + param_info = &fn_type->data.fn.fn_type_id.param_info[src_i]; + ty = param_info->type; + source_node = fn_walk->data.attrs.fn->proto_node; + llvm_fn = fn_walk->data.attrs.fn->llvm_value; + break; + case FnWalkIdCall: { + if (src_i >= fn_walk->data.call.inst->arg_count) + return false; + IrInstruction *arg = fn_walk->data.call.inst->args[src_i]; + ty = arg->value.type; + source_node = arg->source_node; + val = ir_llvm_value(g, arg); + break; + } + } + if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || + ty->id == ZigTypeIdInt // TODO investigate if we need to change this + ) { + switch (fn_walk->id) { + case FnWalkIdAttrs: { + ZigType *ptr_type = get_codegen_ptr_type(ty); + if (ptr_type != nullptr) { + if (ty->id != ZigTypeIdOptional) { + addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull"); + } + if (ptr_type->data.pointer.is_const) { + addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "readonly"); + } + if (param_info->is_noalias) { + addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "noalias"); + } + } + fn_walk->data.attrs.gen_i += 1; + break; + } + case FnWalkIdCall: + fn_walk->data.call.gen_param_values->append(val); + break; + } + return true; + } + + // Arrays are just pointers + if (ty->id == ZigTypeIdArray) { + assert(handle_is_ptr(ty)); + switch (fn_walk->id) { + case FnWalkIdAttrs: + addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull"); + fn_walk->data.attrs.gen_i += 1; + break; + case FnWalkIdCall: + fn_walk->data.call.gen_param_values->append(val); + break; + } + return true; + } + + if (g->zig_target.arch.arch == ZigLLVM_x86_64) { + size_t ty_size = type_size(g, ty); + if (ty->id == ZigTypeIdStruct || ty->id == ZigTypeIdUnion) { + assert(handle_is_ptr(ty)); + + // "If the size of an object is larger than four eightbytes, or it contains unaligned + // fields, it has class MEMORY" + if (ty_size > 32) { + switch (fn_walk->id) { + case FnWalkIdAttrs: + addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "byval"); + addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull"); + fn_walk->data.attrs.gen_i += 1; + break; + case FnWalkIdCall: + fn_walk->data.call.gen_param_values->append(val); + break; + } + return true; + } + } + if (ty->id == ZigTypeIdStruct) { + assert(handle_is_ptr(ty)); + // "If the size of the aggregate exceeds a single eightbyte, each is classified + // separately. Each eightbyte gets initialized to class NO_CLASS." + if (ty_size <= 8) { + bool contains_int = false; + for (size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { + if (type_is_c_abi_int(g, ty->data.structure.fields[i].type_entry)) { + contains_int = true; + break; + } + } + if (contains_int) { + switch (fn_walk->id) { + case FnWalkIdAttrs: + fn_walk->data.attrs.gen_i += 1; + break; + case FnWalkIdCall: { + LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); + LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, val, ptr_to_int_type_ref, ""); + LLVMValueRef loaded = LLVMBuildLoad(g->builder, bitcasted, ""); + fn_walk->data.call.gen_param_values->append(loaded); + break; + } + } + return true; + } + } + } + } + if (source_node != nullptr) { + give_up_with_c_abi_error(g, source_node); + } + // otherwise allow codegen code to report a compile error + return false; +} + +void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) { + CallingConvention cc = fn_type->data.fn.fn_type_id.cc; + if (cc == CallingConventionC) { + size_t src_i = 0; + for (;;) { + if (!iter_function_params_c_abi(g, fn_type, fn_walk, src_i)) + break; + src_i += 1; + } + return; + } + if (fn_walk->id == FnWalkIdCall) { + IrInstructionCall *instruction = fn_walk->data.call.inst; + bool is_var_args = fn_walk->data.call.is_var_args; + for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) { + IrInstruction *param_instruction = instruction->args[call_i]; + ZigType *param_type = param_instruction->value.type; + if (is_var_args || type_has_bits(param_type)) { + LLVMValueRef param_value = ir_llvm_value(g, param_instruction); + assert(param_value); + fn_walk->data.call.gen_param_values->append(param_value); + } + } + return; + } + for (size_t param_i = 0; param_i < fn_type->data.fn.fn_type_id.param_count; param_i += 1) { + FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i]; + size_t gen_index = gen_info->gen_index; + + if (gen_index == SIZE_MAX) { + continue; + } + + switch (fn_walk->id) { + case FnWalkIdAttrs: { + LLVMValueRef llvm_fn = fn_walk->data.attrs.fn->llvm_value; + bool is_byval = gen_info->is_byval; + FnTypeParamInfo *param_info = &fn_type->data.fn.fn_type_id.param_info[param_i]; + + ZigType *param_type = gen_info->type; + if (param_info->is_noalias) { + addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "noalias"); + } + if ((param_type->id == ZigTypeIdPointer && param_type->data.pointer.is_const) || is_byval) { + addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "readonly"); + } + if (param_type->id == ZigTypeIdPointer) { + addLLVMArgAttr(llvm_fn, (unsigned)gen_index, "nonnull"); + } + break; + } + case FnWalkIdCall: + // handled before for loop + zig_unreachable(); + } + } +} + static LLVMValueRef ir_render_save_err_ret_addr(CodeGen *g, IrExecutable *executable, IrInstructionSaveErrRetAddr *save_err_ret_addr_instruction) { @@ -3111,31 +3301,6 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) { LLVMAddCallSiteAttribute(call_instr, 1, sret_attr); } -ATTRIBUTE_NORETURN -static void report_errors_and_exit(CodeGen *g) { - assert(g->errors.length != 0); - for (size_t i = 0; i < g->errors.length; i += 1) { - ErrorMsg *err = g->errors.at(i); - print_err_msg(err, g->err_color); - } - exit(1); -} - -static void report_errors_and_maybe_exit(CodeGen *g) { - if (g->errors.length != 0) { - report_errors_and_exit(g); - } -} - -ATTRIBUTE_NORETURN -static void give_up_with_c_abi_error(CodeGen *g, AstNode *source_node) { - ErrorMsg *msg = add_node_error(g, source_node, - buf_sprintf("TODO: support C ABI for more targets. https://github.com/ziglang/zig/issues/1481")); - add_error_note(g, msg, source_node, - buf_sprintf("pointers, integers, floats, bools, and enums work on all targets")); - report_errors_and_exit(g); -} - static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) { assert(alignment > 0); LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name); @@ -3144,67 +3309,6 @@ static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *na } // If you edit this function you have to edit the corresponding code: -// codegen.cpp:gen_c_abi_param -// analyze.cpp:gen_c_abi_param_type -// codegen.cpp:gen_c_abi_param_var -// codegen.cpp:gen_c_abi_param_var_init -static void gen_c_abi_param(CodeGen *g, ZigList *gen_param_values, LLVMValueRef val, - ZigType *ty, AstNode *source_node) -{ - if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || - ty->id == ZigTypeIdInt // TODO investigate if we need to change this - ) { - gen_param_values->append(val); - return; - } - - // Arrays are just pointers - if (ty->id == ZigTypeIdArray) { - assert(handle_is_ptr(ty)); - gen_param_values->append(val); - return; - } - - if (g->zig_target.arch.arch == ZigLLVM_x86_64) { - // This code all assumes that val is a pointer. - assert(handle_is_ptr(ty)); - - size_t ty_size = type_size(g, ty); - if (ty->id == ZigTypeIdStruct || ty->id == ZigTypeIdUnion) { - // "If the size of an object is larger than four eightbytes, or it contains unaligned - // fields, it has class MEMORY" - if (ty_size > 32) { - gen_param_values->append(val); - return; - } - } - if (ty->id == ZigTypeIdStruct) { - // "If the size of the aggregate exceeds a single eightbyte, each is classified - // separately. Each eightbyte gets initialized to class NO_CLASS." - if (ty_size <= 8) { - bool contains_int = false; - for (size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { - if (type_is_c_abi_int(g, ty->data.structure.fields[i].type_entry)) { - contains_int = true; - break; - } - } - if (contains_int) { - LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); - LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, val, ptr_to_int_type_ref, ""); - LLVMValueRef loaded = LLVMBuildLoad(g->builder, bitcasted, ""); - gen_param_values->append(loaded); - return; - } - } - } - } - - give_up_with_c_abi_error(g, source_node); -} - -// If you edit this function you have to edit the corresponding code: -// codegen.cpp:gen_c_abi_param // analyze.cpp:gen_c_abi_param_type // codegen.cpp:gen_c_abi_param_var // codegen.cpp:gen_c_abi_param_var_init @@ -3283,7 +3387,6 @@ ok: } // If you edit this function you have to edit the corresponding code: -// codegen.cpp:gen_c_abi_param // analyze.cpp:gen_c_abi_param_type // codegen.cpp:gen_c_abi_param_var // codegen.cpp:gen_c_abi_param_var_init @@ -3376,7 +3479,6 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr bool ret_has_bits = type_has_bits(src_return_type); CallingConvention cc = fn_type->data.fn.fn_type_id.cc; - bool is_c_abi = cc == CallingConventionC; bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type) && calling_convention_does_first_arg_return(cc); @@ -3395,19 +3497,12 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, instruction->tmp_ptr, err_union_err_index, ""); gen_param_values.append(err_val_ptr); } - for (size_t call_i = 0; call_i < instruction->arg_count; call_i += 1) { - IrInstruction *param_instruction = instruction->args[call_i]; - ZigType *param_type = param_instruction->value.type; - if (is_var_args || type_has_bits(param_type)) { - LLVMValueRef param_value = ir_llvm_value(g, param_instruction); - assert(param_value); - if (is_c_abi) { - gen_c_abi_param(g, &gen_param_values, param_value, param_type, param_instruction->source_node); - } else { - gen_param_values.append(param_value); - } - } - } + FnWalk fn_walk = {}; + fn_walk.id = FnWalkIdCall; + fn_walk.data.call.inst = instruction; + fn_walk.data.call.is_var_args = is_var_args; + fn_walk.data.call.gen_param_values = &gen_param_values; + walk_function_params(g, fn_type, &fn_walk); ZigLLVM_FnInline fn_inline; switch (instruction->fn_inline) { diff --git a/src/codegen.hpp b/src/codegen.hpp index 6297c4611b..785ba9f05d 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -61,5 +61,6 @@ void codegen_translate_c(CodeGen *g, Buf *path); Buf *codegen_generate_builtin_source(CodeGen *g); +void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk); #endif diff --git a/test/stage1/c_abi/cfuncs.c b/test/stage1/c_abi/cfuncs.c index aef4618747..bfdaa006ef 100644 --- a/test/stage1/c_abi/cfuncs.c +++ b/test/stage1/c_abi/cfuncs.c @@ -19,6 +19,29 @@ void zig_i16(int16_t); void zig_i32(int32_t); void zig_i64(int64_t); +void zig_f32(float); +void zig_f64(double); + +void zig_ptr(void *); + +void zig_bool(bool); + +void zig_array(uint8_t[10]); + +static uint8_t array[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; + +struct BigStruct { + uint64_t a; + uint64_t b; + uint64_t c; + uint64_t d; + uint8_t e; +}; + +void zig_big_struct(struct BigStruct); + +static struct BigStruct s = {1, 2, 3, 4, 5}; + void run_c_tests(void) { zig_u8(0xff); zig_u16(0xfffe); @@ -29,6 +52,17 @@ void run_c_tests(void) { zig_i16(-2); zig_i32(-3); zig_i64(-4); + + zig_f32(12.34f); + zig_f64(56.78); + + zig_ptr((void*)0xdeadbeefL); + + zig_bool(true); + + zig_array(array); + + zig_big_struct(s); } void c_u8(uint8_t x) { @@ -62,3 +96,40 @@ void c_i32(int32_t x) { void c_i64(int64_t x) { assert_or_panic(x == -4); } + +void c_f32(float x) { + assert_or_panic(x == 12.34f); +} + +void c_f64(double x) { + assert_or_panic(x == 56.78); +} + +void c_ptr(void *x) { + assert_or_panic(x == (void*)0xdeadbeefL); +} + +void c_bool(bool x) { + assert_or_panic(x); +} + +void c_array(uint8_t x[10]) { + assert_or_panic(x[0] == '1'); + assert_or_panic(x[1] == '2'); + assert_or_panic(x[2] == '3'); + assert_or_panic(x[3] == '4'); + assert_or_panic(x[4] == '5'); + assert_or_panic(x[5] == '6'); + assert_or_panic(x[6] == '7'); + assert_or_panic(x[7] == '8'); + assert_or_panic(x[8] == '9'); + assert_or_panic(x[9] == '0'); +} + +void c_big_struct(struct BigStruct x) { + assert_or_panic(x.a == 1); + assert_or_panic(x.b == 2); + assert_or_panic(x.c == 3); + assert_or_panic(x.d == 4); + assert_or_panic(x.e == 5); +} diff --git a/test/stage1/c_abi/main.zig b/test/stage1/c_abi/main.zig index c409def6c7..5f5e0b0ca6 100644 --- a/test/stage1/c_abi/main.zig +++ b/test/stage1/c_abi/main.zig @@ -56,3 +56,77 @@ export fn zig_i32(x: i32) void { export fn zig_i64(x: i64) void { assertOrPanic(x == -4); } + +extern fn c_f32(f32) void; +extern fn c_f64(f64) void; + +test "C ABI floats" { + c_f32(12.34); + c_f64(56.78); +} + +export fn zig_f32(x: f32) void { + assertOrPanic(x == 12.34); +} +export fn zig_f64(x: f64) void { + assertOrPanic(x == 56.78); +} + +extern fn c_ptr(*c_void) void; + +test "C ABI pointer" { + c_ptr(@intToPtr(*c_void, 0xdeadbeef)); +} + +export fn zig_ptr(x: *c_void) void { + assertOrPanic(@ptrToInt(x) == 0xdeadbeef); +} + +extern fn c_bool(bool) void; + +test "C ABI bool" { + c_bool(true); +} + +export fn zig_bool(x: bool) void { + assertOrPanic(x); +} + +extern fn c_array([10]u8) void; + +test "C ABI array" { + var array: [10]u8 = "1234567890"; + c_array(array); +} + +export fn zig_array(x: [10]u8) void { + assertOrPanic(std.mem.eql(u8, x, "1234567890")); +} + +const BigStruct = extern struct { + a: u64, + b: u64, + c: u64, + d: u64, + e: u8, +}; +extern fn c_big_struct(BigStruct) void; + +test "C ABI big struct" { + var s = BigStruct{ + .a = 1, + .b = 2, + .c = 3, + .d = 4, + .e = 5, + }; + c_big_struct(s); +} + +export fn zig_big_struct(x: BigStruct) void { + assertOrPanic(x.a == 1); + assertOrPanic(x.b == 2); + assertOrPanic(x.c == 3); + assertOrPanic(x.d == 4); + assertOrPanic(x.e == 5); +} -- cgit v1.2.3 From 04d7b565f78895d96e5a43e8b1f4873ea5f529cf Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Sep 2018 12:23:50 -0400 Subject: stage1: refactor fn type analysis to use C ABI walk fn --- src/all_types.hpp | 7 +++++ src/analyze.cpp | 85 ++++++++----------------------------------------------- src/analyze.hpp | 3 +- src/codegen.cpp | 43 ++++++++++++++++++++++++++++ src/codegen.hpp | 2 -- 5 files changed, 64 insertions(+), 76 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index a89a94c0a0..5ce8e88669 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -3287,6 +3287,7 @@ enum FloatMode { enum FnWalkId { FnWalkIdAttrs, FnWalkIdCall, + FnWalkIdTypes, }; struct FnWalkAttrs { @@ -3300,11 +3301,17 @@ struct FnWalkCall { bool is_var_args; }; +struct FnWalkTypes { + ZigList *param_di_types; + ZigList *gen_param_types; +}; + struct FnWalk { FnWalkId id; union { FnWalkAttrs attrs; FnWalkCall call; + FnWalkTypes types; } data; }; diff --git a/src/analyze.cpp b/src/analyze.cpp index a658c469ac..0fe83e0d96 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1061,76 +1061,6 @@ ZigType *get_ptr_to_stack_trace_type(CodeGen *g) { return g->ptr_to_stack_trace_type; } -bool type_is_c_abi_int(CodeGen *g, ZigType *ty) { - size_t ty_size = type_size(g, ty); - if (ty_size > g->pointer_size_bytes) - return false; - return (ty->id == ZigTypeIdInt || - ty->id == ZigTypeIdFloat || - ty->id == ZigTypeIdBool || - ty->id == ZigTypeIdEnum || - get_codegen_ptr_type(ty) != nullptr); -} - -// If you edit this function you have to edit the corresponding code: -// analyze.cpp:gen_c_abi_param_type -// codegen.cpp:gen_c_abi_param_var -// codegen.cpp:gen_c_abi_param_var_init -static void gen_c_abi_param_type(CodeGen *g, ZigList *gen_param_types, - ZigList *param_di_types, ZigType *ty) -{ - if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || - ty->id == ZigTypeIdInt // TODO investigate if we need to change this - ) { - gen_param_types->append(ty->type_ref); - param_di_types->append(ty->di_type); - return; - } - - // Arrays are just pointers - if (ty->id == ZigTypeIdArray) { - ZigType *gen_type = get_pointer_to_type(g, ty, true); - gen_param_types->append(gen_type->type_ref); - param_di_types->append(gen_type->di_type); - return; - } - - if (g->zig_target.arch.arch == ZigLLVM_x86_64) { - size_t ty_size = type_size(g, ty); - if (ty->id == ZigTypeIdStruct || ty->id == ZigTypeIdUnion) { - // "If the size of an object is larger than four eightbytes, or it contains unaligned - // fields, it has class MEMORY" - if (ty_size > 32) { - ZigType *gen_type = get_pointer_to_type(g, ty, true); - gen_param_types->append(gen_type->type_ref); - param_di_types->append(gen_type->di_type); - return; - } - } - if (ty->id == ZigTypeIdStruct) { - // "If the size of the aggregate exceeds a single eightbyte, each is classified - // separately. Each eightbyte gets initialized to class NO_CLASS." - if (ty_size <= 8) { - bool contains_int = false; - for (size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { - if (type_is_c_abi_int(g, ty->data.structure.fields[i].type_entry)) { - contains_int = true; - break; - } - } - if (contains_int) { - ZigType *gen_type = get_int_type(g, false, ty_size * 8); - gen_param_types->append(gen_type->type_ref); - param_di_types->append(gen_type->di_type); - return; - } - } - } - } - - // allow codegen code to report a compile error -} - ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { Error err; auto table_entry = g->fn_type_table.maybe_get(fn_type_id); @@ -1249,9 +1179,10 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { if ((err = ensure_complete_type(g, type_entry))) return g->builtin_types.entry_invalid; - if (is_c_abi) { - gen_c_abi_param_type(g, &gen_param_types, ¶m_di_types, type_entry); - } else if (type_has_bits(type_entry)) { + if (is_c_abi) + continue; + + if (type_has_bits(type_entry)) { ZigType *gen_type; if (handle_is_ptr(type_entry)) { gen_type = get_pointer_to_type(g, type_entry, true); @@ -1267,6 +1198,14 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { } } + if (is_c_abi) { + FnWalk fn_walk = {}; + fn_walk.id = FnWalkIdTypes; + fn_walk.data.types.param_di_types = ¶m_di_types; + fn_walk.data.types.gen_param_types = &gen_param_types; + walk_function_params(g, fn_type, &fn_walk); + } + fn_type->data.fn.gen_param_count = gen_param_types.length; fn_type->data.fn.raw_type_ref = LLVMFunctionType(gen_return_type->type_ref, diff --git a/src/analyze.hpp b/src/analyze.hpp index f13c528c5a..98e4412594 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -210,6 +210,7 @@ ZigType *get_primitive_type(CodeGen *g, Buf *name); bool calling_convention_allows_zig_types(CallingConvention cc); const char *calling_convention_name(CallingConvention cc); -bool type_is_c_abi_int(CodeGen *g, ZigType *ty); +void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk); + #endif diff --git a/src/codegen.cpp b/src/codegen.cpp index 469d62f3a2..e96445ebe3 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1893,6 +1893,17 @@ static void give_up_with_c_abi_error(CodeGen *g, AstNode *source_node) { report_errors_and_exit(g); } +static bool type_is_c_abi_int(CodeGen *g, ZigType *ty) { + size_t ty_size = type_size(g, ty); + if (ty_size > g->pointer_size_bytes) + return false; + return (ty->id == ZigTypeIdInt || + ty->id == ZigTypeIdFloat || + ty->id == ZigTypeIdBool || + ty->id == ZigTypeIdEnum || + get_codegen_ptr_type(ty) != nullptr); +} + static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk, size_t src_i) { // Initialized from the type for some walks, but because of C var args, // initialized based on callsite instructions for that one. @@ -1919,7 +1930,14 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ val = ir_llvm_value(g, arg); break; } + case FnWalkIdTypes: + if (src_i >= fn_type->data.fn.fn_type_id.param_count) + return false; + param_info = &fn_type->data.fn.fn_type_id.param_info[src_i]; + ty = param_info->type; + break; } + if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || ty->id == ZigTypeIdInt // TODO investigate if we need to change this ) { @@ -1943,6 +1961,10 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ case FnWalkIdCall: fn_walk->data.call.gen_param_values->append(val); break; + case FnWalkIdTypes: + fn_walk->data.types.gen_param_types->append(ty->type_ref); + fn_walk->data.types.param_di_types->append(ty->di_type); + break; } return true; } @@ -1958,6 +1980,12 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ case FnWalkIdCall: fn_walk->data.call.gen_param_values->append(val); break; + case FnWalkIdTypes: { + ZigType *gen_type = get_pointer_to_type(g, ty, true); + fn_walk->data.types.gen_param_types->append(gen_type->type_ref); + fn_walk->data.types.param_di_types->append(gen_type->di_type); + break; + } } return true; } @@ -1979,6 +2007,12 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ case FnWalkIdCall: fn_walk->data.call.gen_param_values->append(val); break; + case FnWalkIdTypes: { + ZigType *gen_type = get_pointer_to_type(g, ty, true); + fn_walk->data.types.gen_param_types->append(gen_type->type_ref); + fn_walk->data.types.param_di_types->append(gen_type->di_type); + break; + } } return true; } @@ -2007,6 +2041,12 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ fn_walk->data.call.gen_param_values->append(loaded); break; } + case FnWalkIdTypes: { + ZigType *gen_type = get_int_type(g, false, ty_size * 8); + fn_walk->data.types.gen_param_types->append(gen_type->type_ref); + fn_walk->data.types.param_di_types->append(gen_type->di_type); + break; + } } return true; } @@ -2074,6 +2114,9 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) { case FnWalkIdCall: // handled before for loop zig_unreachable(); + case FnWalkIdTypes: + // Not called for non-c-abi + zig_unreachable(); } } } diff --git a/src/codegen.hpp b/src/codegen.hpp index 785ba9f05d..b1a4dbf6e2 100644 --- a/src/codegen.hpp +++ b/src/codegen.hpp @@ -61,6 +61,4 @@ void codegen_translate_c(CodeGen *g, Buf *path); Buf *codegen_generate_builtin_source(CodeGen *g); -void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk); - #endif -- cgit v1.2.3 From c528c0090089041e63f9bdbb52f951e53ce94631 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Sep 2018 12:59:59 -0400 Subject: stage1: refactor param vars for C ABI --- src/all_types.hpp | 10 ++++ src/codegen.cpp | 155 +++++++++++++++++++++++------------------------------- 2 files changed, 76 insertions(+), 89 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index 5ce8e88669..649250bf3e 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -3288,6 +3288,7 @@ enum FnWalkId { FnWalkIdAttrs, FnWalkIdCall, FnWalkIdTypes, + FnWalkIdVars, }; struct FnWalkAttrs { @@ -3306,12 +3307,21 @@ struct FnWalkTypes { ZigList *gen_param_types; }; +struct FnWalkVars { + ImportTableEntry *import; + LLVMValueRef llvm_fn; + ZigFn *fn; + ZigVar *var; + unsigned gen_i; +}; + struct FnWalk { FnWalkId id; union { FnWalkAttrs attrs; FnWalkCall call; FnWalkTypes types; + FnWalkVars vars; } data; }; diff --git a/src/codegen.cpp b/src/codegen.cpp index e96445ebe3..19d2781ac0 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1904,14 +1904,24 @@ static bool type_is_c_abi_int(CodeGen *g, ZigType *ty) { get_codegen_ptr_type(ty) != nullptr); } +static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) { + assert(alignment > 0); + LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name); + LLVMSetAlignment(result, alignment); + return result; +} + static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk, size_t src_i) { // Initialized from the type for some walks, but because of C var args, // initialized based on callsite instructions for that one. FnTypeParamInfo *param_info = nullptr; ZigType *ty; + ZigType *dest_ty = nullptr; AstNode *source_node = nullptr; LLVMValueRef val; LLVMValueRef llvm_fn; + unsigned di_arg_index; + ZigVar *var; switch (fn_walk->id) { case FnWalkIdAttrs: if (src_i >= fn_type->data.fn.fn_type_id.param_count) @@ -1936,6 +1946,14 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ param_info = &fn_type->data.fn.fn_type_id.param_info[src_i]; ty = param_info->type; break; + case FnWalkIdVars: + assert(src_i < fn_type->data.fn.fn_type_id.param_count); + param_info = &fn_type->data.fn.fn_type_id.param_info[src_i]; + ty = param_info->type; + var = fn_walk->data.vars.var; + source_node = var->decl_node; + llvm_fn = fn_walk->data.vars.llvm_fn; + break; } if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || @@ -1965,6 +1983,13 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ fn_walk->data.types.gen_param_types->append(ty->type_ref); fn_walk->data.types.param_di_types->append(ty->di_type); break; + case FnWalkIdVars: { + var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes); + di_arg_index = fn_walk->data.vars.gen_i; + fn_walk->data.vars.gen_i += 1; + dest_ty = ty; + goto var_ok; + } } return true; } @@ -1986,6 +2011,13 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ fn_walk->data.types.param_di_types->append(gen_type->di_type); break; } + case FnWalkIdVars: { + var->value_ref = LLVMGetParam(llvm_fn, fn_walk->data.vars.gen_i); + di_arg_index = fn_walk->data.vars.gen_i; + dest_ty = get_pointer_to_type(g, ty, false); + fn_walk->data.vars.gen_i += 1; + goto var_ok; + } } return true; } @@ -2013,6 +2045,13 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ fn_walk->data.types.param_di_types->append(gen_type->di_type); break; } + case FnWalkIdVars: { + di_arg_index = fn_walk->data.vars.gen_i; + var->value_ref = LLVMGetParam(llvm_fn, fn_walk->data.vars.gen_i); + dest_ty = get_pointer_to_type(g, ty, false); + fn_walk->data.vars.gen_i += 1; + goto var_ok; + } } return true; } @@ -2047,6 +2086,12 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ fn_walk->data.types.param_di_types->append(gen_type->di_type); break; } + case FnWalkIdVars: { + di_arg_index = fn_walk->data.vars.gen_i; + var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes); + fn_walk->data.vars.gen_i += 1; + goto var_ok; + } } return true; } @@ -2058,6 +2103,16 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ } // otherwise allow codegen code to report a compile error return false; + +var_ok: + if (dest_ty != nullptr && var->decl_node) { + // arg index + 1 because the 0 index is return value + var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope), + buf_ptr(&var->name), fn_walk->data.vars.import->di_file, + (unsigned)(var->decl_node->line + 1), + dest_ty->di_type, !g->strip_debug_symbols, 0, di_arg_index + 1); + } + return true; } void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) { @@ -2117,6 +2172,9 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) { case FnWalkIdTypes: // Not called for non-c-abi zig_unreachable(); + case FnWalkIdVars: + // iter_function_params_c_abi is called directly for this one + zig_unreachable(); } } } @@ -3344,93 +3402,7 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) { LLVMAddCallSiteAttribute(call_instr, 1, sret_attr); } -static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) { - assert(alignment > 0); - LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name); - LLVMSetAlignment(result, alignment); - return result; -} - -// If you edit this function you have to edit the corresponding code: -// analyze.cpp:gen_c_abi_param_type -// codegen.cpp:gen_c_abi_param_var -// codegen.cpp:gen_c_abi_param_var_init -static void gen_c_abi_param_var(CodeGen *g, ImportTableEntry *import, LLVMValueRef llvm_fn, ZigFn *fn, - ZigVar *var, unsigned *arg_index) -{ - ZigType *ty = var->value->type; - - ZigType *dest_ty = nullptr; - unsigned di_arg_index; - - if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || - ty->id == ZigTypeIdInt // TODO investigate if we need to change this - ) { - var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes); - di_arg_index = *arg_index; - *arg_index += 1; - dest_ty = ty; - goto ok; - } - - // Arrays are just pointers - if (ty->id == ZigTypeIdArray) { - di_arg_index = *arg_index; - var->value_ref = LLVMGetParam(llvm_fn, *arg_index); - dest_ty = get_pointer_to_type(g, ty, false); - *arg_index += 1; - goto ok; - } - - if (g->zig_target.arch.arch == ZigLLVM_x86_64) { - assert(handle_is_ptr(ty)); - size_t ty_size = type_size(g, ty); - - if (ty->id == ZigTypeIdStruct || ty->id == ZigTypeIdUnion) { - // "If the size of an object is larger than four eightbytes, or it contains unaligned - // fields, it has class MEMORY" - if (ty_size > 32) { - di_arg_index = *arg_index; - var->value_ref = LLVMGetParam(llvm_fn, *arg_index); - dest_ty = get_pointer_to_type(g, ty, false); - *arg_index += 1; - goto ok; - } - } - if (ty->id == ZigTypeIdStruct) { - // "If the size of the aggregate exceeds a single eightbyte, each is classified - // separately. Each eightbyte gets initialized to class NO_CLASS." - if (ty_size <= 8) { - bool contains_int = false; - for (size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { - if (type_is_c_abi_int(g, ty->data.structure.fields[i].type_entry)) { - contains_int = true; - break; - } - } - if (contains_int) { - var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes); - *arg_index += 1; - goto ok; - } - } - } - } - - give_up_with_c_abi_error(g, fn->proto_node); - -ok: - if (dest_ty != nullptr && var->decl_node) { - // arg index + 1 because the 0 index is return value - var->di_loc_var = ZigLLVMCreateParameterVariable(g->dbuilder, get_di_scope(g, var->parent_scope), - buf_ptr(&var->name), import->di_file, - (unsigned)(var->decl_node->line + 1), - dest_ty->di_type, !g->strip_debug_symbols, 0, di_arg_index + 1); - } -} - // If you edit this function you have to edit the corresponding code: -// analyze.cpp:gen_c_abi_param_type // codegen.cpp:gen_c_abi_param_var // codegen.cpp:gen_c_abi_param_var_init static void gen_c_abi_param_var_init(CodeGen *g, ImportTableEntry *import, LLVMValueRef llvm_fn, ZigFn *fn, @@ -6317,7 +6289,12 @@ static void do_code_gen(CodeGen *g) { ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base); // create debug variable declarations for variables and allocate all local variables - unsigned c_abi_arg_index = 0; + FnWalk fn_walk = {}; + fn_walk.id = FnWalkIdVars; + fn_walk.data.vars.import = import; + fn_walk.data.vars.fn = fn_table_entry; + fn_walk.data.vars.llvm_fn = fn; + fn_walk.data.vars.gen_i = 0; for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) { ZigVar *var = fn_table_entry->variable_list.at(var_i); @@ -6337,7 +6314,8 @@ static void do_code_gen(CodeGen *g) { var->value->type->di_type, !g->strip_debug_symbols, 0); } else if (is_c_abi) { - gen_c_abi_param_var(g, import, fn, fn_table_entry, var, &c_abi_arg_index); + fn_walk.data.vars.var = var; + iter_function_params_c_abi(g, fn_table_entry->type_entry, &fn_walk, var->src_arg_index); } else { assert(var->gen_arg_index != SIZE_MAX); ZigType *gen_type; @@ -6423,7 +6401,6 @@ static void do_code_gen(CodeGen *g) { gen_var_debug_decl(g, variable); } } - assert(c_abi_arg_index == c_abi_arg_init_index); ir_render(g, fn_table_entry); -- cgit v1.2.3 From 421ca1523feec17db75e7c53b05e5abe4c88d58f Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Sep 2018 13:24:41 -0400 Subject: stage1: refactor variable inits to use c abi fn walk --- src/all_types.hpp | 8 +++ src/codegen.cpp | 190 ++++++++++++++++++++++-------------------------------- 2 files changed, 84 insertions(+), 114 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index 649250bf3e..b80fe17053 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -3289,6 +3289,7 @@ enum FnWalkId { FnWalkIdCall, FnWalkIdTypes, FnWalkIdVars, + FnWalkIdInits, }; struct FnWalkAttrs { @@ -3315,6 +3316,12 @@ struct FnWalkVars { unsigned gen_i; }; +struct FnWalkInits { + LLVMValueRef llvm_fn; + ZigFn *fn; + unsigned gen_i; +}; + struct FnWalk { FnWalkId id; union { @@ -3322,6 +3329,7 @@ struct FnWalk { FnWalkCall call; FnWalkTypes types; FnWalkVars vars; + FnWalkInits inits; } data; }; diff --git a/src/codegen.cpp b/src/codegen.cpp index 19d2781ac0..d4de593529 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1954,6 +1954,15 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ source_node = var->decl_node; llvm_fn = fn_walk->data.vars.llvm_fn; break; + case FnWalkIdInits: + if (src_i >= fn_type->data.fn.fn_type_id.param_count) + return false; + param_info = &fn_type->data.fn.fn_type_id.param_info[src_i]; + ty = param_info->type; + var = fn_walk->data.inits.fn->variable_list.at(src_i); + source_node = fn_walk->data.inits.fn->proto_node; + llvm_fn = fn_walk->data.inits.llvm_fn; + break; } if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || @@ -1990,6 +1999,14 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ dest_ty = ty; goto var_ok; } + case FnWalkIdInits: + clear_debug_source_node(g); + gen_store_untyped(g, LLVMGetParam(llvm_fn, fn_walk->data.inits.gen_i), var->value_ref, var->align_bytes, false); + if (var->decl_node) { + gen_var_debug_decl(g, var); + } + fn_walk->data.inits.gen_i += 1; + break; } return true; } @@ -2018,6 +2035,12 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ fn_walk->data.vars.gen_i += 1; goto var_ok; } + case FnWalkIdInits: + if (var->decl_node) { + gen_var_debug_decl(g, var); + } + fn_walk->data.inits.gen_i += 1; + break; } return true; } @@ -2052,6 +2075,12 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ fn_walk->data.vars.gen_i += 1; goto var_ok; } + case FnWalkIdInits: + if (var->decl_node) { + gen_var_debug_decl(g, var); + } + fn_walk->data.inits.gen_i += 1; + break; } return true; } @@ -2092,6 +2121,18 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ fn_walk->data.vars.gen_i += 1; goto var_ok; } + case FnWalkIdInits: { + clear_debug_source_node(g); + LLVMValueRef arg = LLVMGetParam(llvm_fn, fn_walk->data.inits.gen_i += 1); + LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); + LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, var->value_ref, ptr_to_int_type_ref, ""); + gen_store_untyped(g, arg, bitcasted, var->align_bytes, false); + if (var->decl_node) { + gen_var_debug_decl(g, var); + } + fn_walk->data.inits.gen_i += 1; + break; + } } return true; } @@ -2140,6 +2181,7 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) { } return; } + size_t next_var_i = 0; for (size_t param_i = 0; param_i < fn_type->data.fn.fn_type_id.param_count; param_i += 1) { FnGenParamInfo *gen_info = &fn_type->data.fn.gen_param_info[param_i]; size_t gen_index = gen_info->gen_index; @@ -2166,6 +2208,27 @@ void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk) { } break; } + case FnWalkIdInits: { + ZigFn *fn_table_entry = fn_walk->data.inits.fn; + LLVMValueRef llvm_fn = fn_table_entry->llvm_value; + ZigVar *variable = fn_table_entry->variable_list.at(next_var_i); + assert(variable->src_arg_index != SIZE_MAX); + next_var_i += 1; + + assert(variable); + assert(variable->value_ref); + + if (!handle_is_ptr(variable->value->type)) { + clear_debug_source_node(g); + gen_store_untyped(g, LLVMGetParam(llvm_fn, (unsigned)variable->gen_arg_index), variable->value_ref, + variable->align_bytes, false); + } + + if (variable->decl_node) { + gen_var_debug_decl(g, variable); + } + break; + } case FnWalkIdCall: // handled before for loop zig_unreachable(); @@ -3402,80 +3465,6 @@ static void set_call_instr_sret(CodeGen *g, LLVMValueRef call_instr) { LLVMAddCallSiteAttribute(call_instr, 1, sret_attr); } -// If you edit this function you have to edit the corresponding code: -// codegen.cpp:gen_c_abi_param_var -// codegen.cpp:gen_c_abi_param_var_init -static void gen_c_abi_param_var_init(CodeGen *g, ImportTableEntry *import, LLVMValueRef llvm_fn, ZigFn *fn, - ZigVar *var, unsigned *arg_index) -{ - ZigType *ty = var->value->type; - - if (type_is_c_abi_int(g, ty) || ty->id == ZigTypeIdFloat || - ty->id == ZigTypeIdInt // TODO investigate if we need to change this - ) { - clear_debug_source_node(g); - gen_store_untyped(g, LLVMGetParam(llvm_fn, *arg_index), var->value_ref, var->align_bytes, false); - if (var->decl_node) { - gen_var_debug_decl(g, var); - } - *arg_index += 1; - return; - } - - // Arrays are just pointers - if (ty->id == ZigTypeIdArray) { - if (var->decl_node) { - gen_var_debug_decl(g, var); - } - *arg_index += 1; - return; - } - - if (g->zig_target.arch.arch == ZigLLVM_x86_64) { - assert(handle_is_ptr(ty)); - size_t ty_size = type_size(g, ty); - - if (ty->id == ZigTypeIdStruct || ty->id == ZigTypeIdUnion) { - // "If the size of an object is larger than four eightbytes, or it contains unaligned - // fields, it has class MEMORY" - if (ty_size > 32) { - if (var->decl_node) { - gen_var_debug_decl(g, var); - } - *arg_index += 1; - return; - } - } - if (ty->id == ZigTypeIdStruct) { - // "If the size of the aggregate exceeds a single eightbyte, each is classified - // separately. Each eightbyte gets initialized to class NO_CLASS." - if (ty_size <= 8) { - bool contains_int = false; - for (size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { - if (type_is_c_abi_int(g, ty->data.structure.fields[i].type_entry)) { - contains_int = true; - break; - } - } - if (contains_int) { - clear_debug_source_node(g); - LLVMValueRef arg = LLVMGetParam(llvm_fn, *arg_index); - LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); - LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, var->value_ref, ptr_to_int_type_ref, ""); - gen_store_untyped(g, arg, bitcasted, var->align_bytes, false); - if (var->decl_node) { - gen_var_debug_decl(g, var); - } - *arg_index += 1; - return; - } - } - } - } - - give_up_with_c_abi_error(g, fn->proto_node); -} - static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstructionCall *instruction) { LLVMValueRef fn_val; ZigType *fn_type; @@ -6289,12 +6278,12 @@ static void do_code_gen(CodeGen *g) { ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base); // create debug variable declarations for variables and allocate all local variables - FnWalk fn_walk = {}; - fn_walk.id = FnWalkIdVars; - fn_walk.data.vars.import = import; - fn_walk.data.vars.fn = fn_table_entry; - fn_walk.data.vars.llvm_fn = fn; - fn_walk.data.vars.gen_i = 0; + FnWalk fn_walk_var = {}; + fn_walk_var.id = FnWalkIdVars; + fn_walk_var.data.vars.import = import; + fn_walk_var.data.vars.fn = fn_table_entry; + fn_walk_var.data.vars.llvm_fn = fn; + fn_walk_var.data.vars.gen_i = 0; for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) { ZigVar *var = fn_table_entry->variable_list.at(var_i); @@ -6314,8 +6303,8 @@ static void do_code_gen(CodeGen *g) { var->value->type->di_type, !g->strip_debug_symbols, 0); } else if (is_c_abi) { - fn_walk.data.vars.var = var; - iter_function_params_c_abi(g, fn_table_entry->type_entry, &fn_walk, var->src_arg_index); + fn_walk_var.data.vars.var = var; + iter_function_params_c_abi(g, fn_table_entry->type_entry, &fn_walk_var, var->src_arg_index); } else { assert(var->gen_arg_index != SIZE_MAX); ZigType *gen_type; @@ -6367,40 +6356,13 @@ static void do_code_gen(CodeGen *g) { gen_store(g, LLVMConstInt(usize->type_ref, stack_trace_ptr_count, false), len_field_ptr, get_pointer_to_type(g, usize, false)); } - FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id; - // create debug variable declarations for parameters // rely on the first variables in the variable_list being parameters. - size_t next_var_i = 0; - unsigned c_abi_arg_init_index = 0; - for (size_t param_i = 0; param_i < fn_type_id->param_count; param_i += 1) { - if (is_c_abi) { - ZigVar *var = fn_table_entry->variable_list.at(param_i); - gen_c_abi_param_var_init(g, import, fn, fn_table_entry, var, &c_abi_arg_init_index); - continue; - } - - FnGenParamInfo *info = &fn_table_entry->type_entry->data.fn.gen_param_info[param_i]; - if (info->gen_index == SIZE_MAX) - continue; - - ZigVar *variable = fn_table_entry->variable_list.at(next_var_i); - assert(variable->src_arg_index != SIZE_MAX); - next_var_i += 1; - - assert(variable); - assert(variable->value_ref); - - if (!handle_is_ptr(variable->value->type)) { - clear_debug_source_node(g); - gen_store_untyped(g, LLVMGetParam(fn, (unsigned)variable->gen_arg_index), variable->value_ref, - variable->align_bytes, false); - } - - if (variable->decl_node) { - gen_var_debug_decl(g, variable); - } - } + FnWalk fn_walk_init = {}; + fn_walk_init.id = FnWalkIdInits; + fn_walk_init.data.inits.fn = fn_table_entry; + fn_walk_init.data.inits.llvm_fn = fn; + walk_function_params(g, fn_table_entry->type_entry, &fn_walk_init); ir_render(g, fn_table_entry); -- cgit v1.2.3 From 743b2e4afc72f436a73977f896b32e6041785795 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Sep 2018 13:51:11 -0400 Subject: add C ABI test for big unions --- src/codegen.cpp | 4 +++- test/stage1/c_abi/cfuncs.c | 42 ++++++++++++++++++++++++++++++++++---- test/stage1/c_abi/main.zig | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 5 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index d4de593529..8acc7e9702 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1838,6 +1838,7 @@ static LLVMValueRef gen_assign_raw(CodeGen *g, LLVMValueRef ptr, ZigType *ptr_ty } static void gen_var_debug_decl(CodeGen *g, ZigVar *var) { + assert(var->di_loc_var != nullptr); AstNode *source_node = var->decl_node; ZigLLVMDILocation *debug_loc = ZigLLVMGetDebugLoc((unsigned)source_node->line + 1, (unsigned)source_node->column + 1, get_di_scope(g, var->parent_scope)); @@ -2119,11 +2120,12 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ di_arg_index = fn_walk->data.vars.gen_i; var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes); fn_walk->data.vars.gen_i += 1; + dest_ty = ty; goto var_ok; } case FnWalkIdInits: { clear_debug_source_node(g); - LLVMValueRef arg = LLVMGetParam(llvm_fn, fn_walk->data.inits.gen_i += 1); + LLVMValueRef arg = LLVMGetParam(llvm_fn, fn_walk->data.inits.gen_i); LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, var->value_ref, ptr_to_int_type_ref, ""); gen_store_untyped(g, arg, bitcasted, var->align_bytes, false); diff --git a/test/stage1/c_abi/cfuncs.c b/test/stage1/c_abi/cfuncs.c index bfdaa006ef..393c3a4f5a 100644 --- a/test/stage1/c_abi/cfuncs.c +++ b/test/stage1/c_abi/cfuncs.c @@ -28,8 +28,6 @@ void zig_bool(bool); void zig_array(uint8_t[10]); -static uint8_t array[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; - struct BigStruct { uint64_t a; uint64_t b; @@ -40,7 +38,19 @@ struct BigStruct { void zig_big_struct(struct BigStruct); -static struct BigStruct s = {1, 2, 3, 4, 5}; +union BigUnion { + struct BigStruct a; +}; + +void zig_big_union(union BigUnion); + +struct SmallStructInts { + uint8_t a; + uint8_t b; + uint8_t c; + uint8_t d; +}; +void zig_small_struct_ints(struct SmallStructInts); void run_c_tests(void) { zig_u8(0xff); @@ -60,9 +70,19 @@ void run_c_tests(void) { zig_bool(true); + // TODO making this non-static crashes for some reason + static uint8_t array[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; zig_array(array); - zig_big_struct(s); + { + struct BigStruct s = {1, 2, 3, 4, 5}; + zig_big_struct(s); + } + + { + struct SmallStructInts s = {1, 2, 3, 4}; + zig_small_struct_ints(s); + } } void c_u8(uint8_t x) { @@ -133,3 +153,17 @@ void c_big_struct(struct BigStruct x) { assert_or_panic(x.d == 4); assert_or_panic(x.e == 5); } + +void c_big_union(union BigUnion x) { + assert_or_panic(x.a.a == 1); + assert_or_panic(x.a.b == 2); + assert_or_panic(x.a.c == 3); + assert_or_panic(x.a.d == 4); +} + +void c_small_struct_ints(struct SmallStructInts x) { + assert_or_panic(x.a == 1); + assert_or_panic(x.b == 2); + assert_or_panic(x.c == 3); + assert_or_panic(x.d == 4); +} diff --git a/test/stage1/c_abi/main.zig b/test/stage1/c_abi/main.zig index 5f5e0b0ca6..ef425ceb67 100644 --- a/test/stage1/c_abi/main.zig +++ b/test/stage1/c_abi/main.zig @@ -130,3 +130,54 @@ export fn zig_big_struct(x: BigStruct) void { assertOrPanic(x.d == 4); assertOrPanic(x.e == 5); } + +const BigUnion = extern union { + a: BigStruct, +}; +extern fn c_big_union(BigUnion) void; + +test "C ABI big union" { + var x = BigUnion{ + .a = BigStruct{ + .a = 1, + .b = 2, + .c = 3, + .d = 4, + .e = 5, + }, + }; + c_big_union(x); +} + +export fn zig_big_union(x: BigUnion) void { + assertOrPanic(x.a.a == 1); + assertOrPanic(x.a.b == 2); + assertOrPanic(x.a.c == 3); + assertOrPanic(x.a.d == 4); + assertOrPanic(x.a.e == 5); +} + +const SmallStructInts = extern struct { + a: u8, + b: u8, + c: u8, + d: u8, +}; +extern fn c_small_struct_ints(SmallStructInts) void; + +test "C ABI small struct of ints" { + var s = SmallStructInts{ + .a = 1, + .b = 2, + .c = 3, + .d = 4, + }; + c_small_struct_ints(s); +} + +export fn zig_small_struct_ints(x: SmallStructInts) void { + assertOrPanic(x.a == 1); + assertOrPanic(x.b == 2); + assertOrPanic(x.c == 3); + assertOrPanic(x.d == 4); +} -- cgit v1.2.3 From 85534a26c6ddea6277e79b12b759188689f3da43 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Sep 2018 18:34:19 -0400 Subject: stage1: function to classify x86_64 abi types --- src/codegen.cpp | 241 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 150 insertions(+), 91 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index 8acc7e9702..a38cc869dd 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1894,6 +1894,91 @@ static void give_up_with_c_abi_error(CodeGen *g, AstNode *source_node) { report_errors_and_exit(g); } +static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) { + assert(alignment > 0); + LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name); + LLVMSetAlignment(result, alignment); + return result; +} + +enum X64CABIClass { + X64CABIClass_Unknown, + X64CABIClass_MEMORY, + X64CABIClass_INTEGER, + X64CABIClass_SSE, +}; + +static X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) { + size_t ty_size = type_size(g, ty); + if (get_codegen_ptr_type(ty) != nullptr) + return X64CABIClass_INTEGER; + switch (ty->id) { + case ZigTypeIdEnum: + case ZigTypeIdInt: + case ZigTypeIdBool: + return X64CABIClass_INTEGER; + case ZigTypeIdFloat: + return X64CABIClass_SSE; + case ZigTypeIdStruct: { + // "If the size of an object is larger than four eightbytes, or it contains unaligned + // fields, it has class MEMORY" + if (ty_size > 32) + return X64CABIClass_MEMORY; + if (ty->data.structure.layout != ContainerLayoutExtern) { + // TODO determine whether packed structs have any unaligned fields + return X64CABIClass_Unknown; + } + // "If the size of the aggregate exceeds two eightbytes and the first eight- + // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument + // is passed in memory." + if (ty_size > 16) { + // Zig doesn't support vectors and large fp registers yet, so this will always + // be memory. + return X64CABIClass_MEMORY; + } + X64CABIClass working_class = X64CABIClass_Unknown; + for (uint32_t i = 0; i < ty->data.structure.src_field_count; i += 1) { + X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.structure.fields->type_entry); + if (field_class == X64CABIClass_Unknown) + return X64CABIClass_Unknown; + if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) { + working_class = field_class; + } + } + return working_class; + } + case ZigTypeIdUnion: { + // "If the size of an object is larger than four eightbytes, or it contains unaligned + // fields, it has class MEMORY" + if (ty_size > 32) + return X64CABIClass_MEMORY; + if (ty->data.unionation.layout != ContainerLayoutExtern) + return X64CABIClass_MEMORY; + // "If the size of the aggregate exceeds two eightbytes and the first eight- + // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument + // is passed in memory." + if (ty_size > 16) { + // Zig doesn't support vectors and large fp registers yet, so this will always + // be memory. + return X64CABIClass_MEMORY; + } + X64CABIClass working_class = X64CABIClass_Unknown; + for (uint32_t i = 0; i < ty->data.unionation.src_field_count; i += 1) { + X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.unionation.fields->type_entry); + if (field_class == X64CABIClass_Unknown) + return X64CABIClass_Unknown; + if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) { + working_class = field_class; + } + } + return working_class; + } + default: + return X64CABIClass_Unknown; + } +} + +// NOTE this does not depend on x86_64 static bool type_is_c_abi_int(CodeGen *g, ZigType *ty) { size_t ty_size = type_size(g, ty); if (ty_size > g->pointer_size_bytes) @@ -1905,13 +1990,6 @@ static bool type_is_c_abi_int(CodeGen *g, ZigType *ty) { get_codegen_ptr_type(ty) != nullptr); } -static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *name, uint32_t alignment) { - assert(alignment > 0); - LLVMValueRef result = LLVMBuildAlloca(g->builder, type_entry->type_ref, name); - LLVMSetAlignment(result, alignment); - return result; -} - static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk, size_t src_i) { // Initialized from the type for some walks, but because of C var args, // initialized based on callsite instructions for that one. @@ -2047,98 +2125,79 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ } if (g->zig_target.arch.arch == ZigLLVM_x86_64) { + X64CABIClass abi_class = type_c_abi_x86_64_class(g, ty); size_t ty_size = type_size(g, ty); - if (ty->id == ZigTypeIdStruct || ty->id == ZigTypeIdUnion) { + if (abi_class == X64CABIClass_MEMORY) { assert(handle_is_ptr(ty)); - - // "If the size of an object is larger than four eightbytes, or it contains unaligned - // fields, it has class MEMORY" - if (ty_size > 32) { - switch (fn_walk->id) { - case FnWalkIdAttrs: - addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "byval"); - addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull"); - fn_walk->data.attrs.gen_i += 1; - break; - case FnWalkIdCall: - fn_walk->data.call.gen_param_values->append(val); - break; - case FnWalkIdTypes: { - ZigType *gen_type = get_pointer_to_type(g, ty, true); - fn_walk->data.types.gen_param_types->append(gen_type->type_ref); - fn_walk->data.types.param_di_types->append(gen_type->di_type); - break; - } - case FnWalkIdVars: { - di_arg_index = fn_walk->data.vars.gen_i; - var->value_ref = LLVMGetParam(llvm_fn, fn_walk->data.vars.gen_i); - dest_ty = get_pointer_to_type(g, ty, false); - fn_walk->data.vars.gen_i += 1; - goto var_ok; - } - case FnWalkIdInits: - if (var->decl_node) { - gen_var_debug_decl(g, var); - } - fn_walk->data.inits.gen_i += 1; - break; + switch (fn_walk->id) { + case FnWalkIdAttrs: + addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "byval"); + addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull"); + fn_walk->data.attrs.gen_i += 1; + break; + case FnWalkIdCall: + fn_walk->data.call.gen_param_values->append(val); + break; + case FnWalkIdTypes: { + ZigType *gen_type = get_pointer_to_type(g, ty, true); + fn_walk->data.types.gen_param_types->append(gen_type->type_ref); + fn_walk->data.types.param_di_types->append(gen_type->di_type); + break; } - return true; - } - } - if (ty->id == ZigTypeIdStruct) { - assert(handle_is_ptr(ty)); - // "If the size of the aggregate exceeds a single eightbyte, each is classified - // separately. Each eightbyte gets initialized to class NO_CLASS." - if (ty_size <= 8) { - bool contains_int = false; - for (size_t i = 0; i < ty->data.structure.src_field_count; i += 1) { - if (type_is_c_abi_int(g, ty->data.structure.fields[i].type_entry)) { - contains_int = true; - break; + case FnWalkIdVars: { + di_arg_index = fn_walk->data.vars.gen_i; + var->value_ref = LLVMGetParam(llvm_fn, fn_walk->data.vars.gen_i); + dest_ty = get_pointer_to_type(g, ty, false); + fn_walk->data.vars.gen_i += 1; + goto var_ok; + } + case FnWalkIdInits: + if (var->decl_node) { + gen_var_debug_decl(g, var); } + fn_walk->data.inits.gen_i += 1; + break; + } + return true; + } else if (abi_class == X64CABIClass_INTEGER && ty_size <= 8) { + switch (fn_walk->id) { + case FnWalkIdAttrs: + fn_walk->data.attrs.gen_i += 1; + break; + case FnWalkIdCall: { + LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); + LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, val, ptr_to_int_type_ref, ""); + LLVMValueRef loaded = LLVMBuildLoad(g->builder, bitcasted, ""); + fn_walk->data.call.gen_param_values->append(loaded); + break; } - if (contains_int) { - switch (fn_walk->id) { - case FnWalkIdAttrs: - fn_walk->data.attrs.gen_i += 1; - break; - case FnWalkIdCall: { - LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); - LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, val, ptr_to_int_type_ref, ""); - LLVMValueRef loaded = LLVMBuildLoad(g->builder, bitcasted, ""); - fn_walk->data.call.gen_param_values->append(loaded); - break; - } - case FnWalkIdTypes: { - ZigType *gen_type = get_int_type(g, false, ty_size * 8); - fn_walk->data.types.gen_param_types->append(gen_type->type_ref); - fn_walk->data.types.param_di_types->append(gen_type->di_type); - break; - } - case FnWalkIdVars: { - di_arg_index = fn_walk->data.vars.gen_i; - var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes); - fn_walk->data.vars.gen_i += 1; - dest_ty = ty; - goto var_ok; - } - case FnWalkIdInits: { - clear_debug_source_node(g); - LLVMValueRef arg = LLVMGetParam(llvm_fn, fn_walk->data.inits.gen_i); - LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); - LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, var->value_ref, ptr_to_int_type_ref, ""); - gen_store_untyped(g, arg, bitcasted, var->align_bytes, false); - if (var->decl_node) { - gen_var_debug_decl(g, var); - } - fn_walk->data.inits.gen_i += 1; - break; - } + case FnWalkIdTypes: { + ZigType *gen_type = get_int_type(g, false, ty_size * 8); + fn_walk->data.types.gen_param_types->append(gen_type->type_ref); + fn_walk->data.types.param_di_types->append(gen_type->di_type); + break; + } + case FnWalkIdVars: { + di_arg_index = fn_walk->data.vars.gen_i; + var->value_ref = build_alloca(g, ty, buf_ptr(&var->name), var->align_bytes); + fn_walk->data.vars.gen_i += 1; + dest_ty = ty; + goto var_ok; + } + case FnWalkIdInits: { + clear_debug_source_node(g); + LLVMValueRef arg = LLVMGetParam(llvm_fn, fn_walk->data.inits.gen_i); + LLVMTypeRef ptr_to_int_type_ref = LLVMPointerType(LLVMIntType((unsigned)ty_size * 8), 0); + LLVMValueRef bitcasted = LLVMBuildBitCast(g->builder, var->value_ref, ptr_to_int_type_ref, ""); + gen_store_untyped(g, arg, bitcasted, var->align_bytes, false); + if (var->decl_node) { + gen_var_debug_decl(g, var); } - return true; + fn_walk->data.inits.gen_i += 1; + break; } } + return true; } } if (source_node != nullptr) { -- cgit v1.2.3 From 9017efee220950b11070242415b6dc456d4442df Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Sep 2018 18:47:57 -0400 Subject: C ABI: support medium size structs & unions for x86_64 params See #1481 --- src/codegen.cpp | 12 +++++++++--- test/stage1/c_abi/cfuncs.c | 18 ++++++++++++++++++ test/stage1/c_abi/main.zig | 22 ++++++++++++++++++++++ 3 files changed, 49 insertions(+), 3 deletions(-) (limited to 'src/codegen.cpp') diff --git a/src/codegen.cpp b/src/codegen.cpp index a38cc869dd..4be08b03e7 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -354,8 +354,12 @@ static void addLLVMFnAttrInt(LLVMValueRef fn_val, const char *attr_name, uint64_ return addLLVMAttrInt(fn_val, -1, attr_name, attr_val); } -static void addLLVMArgAttr(LLVMValueRef arg_val, unsigned param_index, const char *attr_name) { - return addLLVMAttr(arg_val, param_index + 1, attr_name); +static void addLLVMArgAttr(LLVMValueRef fn_val, unsigned param_index, const char *attr_name) { + return addLLVMAttr(fn_val, param_index + 1, attr_name); +} + +static void addLLVMArgAttrInt(LLVMValueRef fn_val, unsigned param_index, const char *attr_name, uint64_t attr_val) { + return addLLVMAttrInt(fn_val, param_index + 1, attr_name, attr_val); } static bool is_symbol_available(CodeGen *g, Buf *name) { @@ -2096,6 +2100,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ switch (fn_walk->id) { case FnWalkIdAttrs: addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull"); + addLLVMArgAttrInt(llvm_fn, fn_walk->data.attrs.gen_i, "align", get_abi_alignment(g, ty)); fn_walk->data.attrs.gen_i += 1; break; case FnWalkIdCall: @@ -2132,6 +2137,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ switch (fn_walk->id) { case FnWalkIdAttrs: addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "byval"); + addLLVMArgAttrInt(llvm_fn, fn_walk->data.attrs.gen_i, "align", get_abi_alignment(g, ty)); addLLVMArgAttr(llvm_fn, fn_walk->data.attrs.gen_i, "nonnull"); fn_walk->data.attrs.gen_i += 1; break; @@ -2159,7 +2165,7 @@ static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_ break; } return true; - } else if (abi_class == X64CABIClass_INTEGER && ty_size <= 8) { + } else if (abi_class == X64CABIClass_INTEGER) { switch (fn_walk->id) { case FnWalkIdAttrs: fn_walk->data.attrs.gen_i += 1; diff --git a/test/stage1/c_abi/cfuncs.c b/test/stage1/c_abi/cfuncs.c index 393c3a4f5a..ff249d2a59 100644 --- a/test/stage1/c_abi/cfuncs.c +++ b/test/stage1/c_abi/cfuncs.c @@ -52,6 +52,13 @@ struct SmallStructInts { }; void zig_small_struct_ints(struct SmallStructInts); +struct SplitStructInts { + uint64_t a; + uint8_t b; + uint32_t c; +}; +void zig_split_struct_ints(struct SplitStructInts); + void run_c_tests(void) { zig_u8(0xff); zig_u16(0xfffe); @@ -83,6 +90,11 @@ void run_c_tests(void) { struct SmallStructInts s = {1, 2, 3, 4}; zig_small_struct_ints(s); } + + { + struct SplitStructInts s = {1234, 100, 1337}; + zig_split_struct_ints(s); + } } void c_u8(uint8_t x) { @@ -167,3 +179,9 @@ void c_small_struct_ints(struct SmallStructInts x) { assert_or_panic(x.c == 3); assert_or_panic(x.d == 4); } + +void c_split_struct_ints(struct SplitStructInts x) { + assert_or_panic(x.a == 1234); + assert_or_panic(x.b == 100); + assert_or_panic(x.c == 1337); +} diff --git a/test/stage1/c_abi/main.zig b/test/stage1/c_abi/main.zig index ef425ceb67..e1356f50ef 100644 --- a/test/stage1/c_abi/main.zig +++ b/test/stage1/c_abi/main.zig @@ -181,3 +181,25 @@ export fn zig_small_struct_ints(x: SmallStructInts) void { assertOrPanic(x.c == 3); assertOrPanic(x.d == 4); } + +const SplitStructInt = extern struct { + a: u64, + b: u8, + c: u32, +}; +extern fn c_split_struct_ints(SplitStructInt) void; + +test "C ABI split struct of ints" { + var s = SplitStructInt{ + .a = 1234, + .b = 100, + .c = 1337, + }; + c_split_struct_ints(s); +} + +export fn zig_split_struct_ints(x: SplitStructInt) void { + assertOrPanic(x.a == 1234); + assertOrPanic(x.b == 100); + assertOrPanic(x.c == 1337); +} -- cgit v1.2.3 From 9c169f3cf763c58f91b485f907f80cd8d08c4e12 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 7 Sep 2018 20:09:33 -0400 Subject: C ABI: support returning large structs on x86_64 also panic instead of emitting bad code for returning small structs See #1481 --- src/all_types.hpp | 7 +++ src/analyze.cpp | 109 +++++++++++++++++++++++++++++++++++--- src/analyze.hpp | 5 +- src/codegen.cpp | 126 ++++++++------------------------------------ test/behavior.zig | 1 - test/cases/bugs/1230.zig | 14 ----- test/stage1/c_abi/build.zig | 1 + test/stage1/c_abi/cfuncs.c | 25 ++++++++- test/stage1/c_abi/main.zig | 34 ++++++++++++ 9 files changed, 193 insertions(+), 129 deletions(-) delete mode 100644 test/cases/bugs/1230.zig (limited to 'src/codegen.cpp') diff --git a/src/all_types.hpp b/src/all_types.hpp index b80fe17053..6adb53b774 100644 --- a/src/all_types.hpp +++ b/src/all_types.hpp @@ -40,6 +40,13 @@ struct Tld; struct TldExport; struct IrAnalyze; +enum X64CABIClass { + X64CABIClass_Unknown, + X64CABIClass_MEMORY, + X64CABIClass_INTEGER, + X64CABIClass_SSE, +}; + struct IrExecutable { ZigList basic_block_list; Buf *name; diff --git a/src/analyze.cpp b/src/analyze.cpp index 0fe83e0d96..1c49f696bf 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1009,10 +1009,6 @@ ZigType *get_bound_fn_type(CodeGen *g, ZigFn *fn_entry) { return bound_fn_type; } -bool calling_convention_does_first_arg_return(CallingConvention cc) { - return cc == CallingConventionUnspecified; -} - const char *calling_convention_name(CallingConvention cc) { switch (cc) { case CallingConventionUnspecified: return "undefined"; @@ -1061,6 +1057,26 @@ ZigType *get_ptr_to_stack_trace_type(CodeGen *g) { return g->ptr_to_stack_trace_type; } +bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id) { + if (fn_type_id->cc == CallingConventionUnspecified) { + return handle_is_ptr(fn_type_id->return_type); + } + if (fn_type_id->cc != CallingConventionC) { + return false; + } + if (type_is_c_abi_int(g, fn_type_id->return_type)) { + return false; + } + if (g->zig_target.arch.arch == ZigLLVM_x86_64) { + X64CABIClass abi_class = type_c_abi_x86_64_class(g, fn_type_id->return_type); + if (abi_class == X64CABIClass_MEMORY) { + return true; + } + zig_panic("TODO implement C ABI for x86_64 return types. '%s'", buf_ptr(&fn_type_id->return_type->name)); + } + zig_panic("TODO implement C ABI for this architecture"); +} + ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { Error err; auto table_entry = g->fn_type_table.maybe_get(fn_type_id); @@ -1116,8 +1132,7 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { // next, loop over the parameters again and compute debug information // and codegen information if (!skip_debug_info) { - bool first_arg_return = calling_convention_does_first_arg_return(fn_type_id->cc) && - handle_is_ptr(fn_type_id->return_type); + bool first_arg_return = want_first_arg_sret(g, fn_type_id); bool is_async = fn_type_id->cc == CallingConventionAsync; bool is_c_abi = fn_type_id->cc == CallingConventionC; bool prefix_arg_error_return_trace = g->have_err_ret_tracing && fn_type_can_fail(fn_type_id); @@ -6367,3 +6382,85 @@ not_integer: } return nullptr; } + +X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) { + size_t ty_size = type_size(g, ty); + if (get_codegen_ptr_type(ty) != nullptr) + return X64CABIClass_INTEGER; + switch (ty->id) { + case ZigTypeIdEnum: + case ZigTypeIdInt: + case ZigTypeIdBool: + return X64CABIClass_INTEGER; + case ZigTypeIdFloat: + return X64CABIClass_SSE; + case ZigTypeIdStruct: { + // "If the size of an object is larger than four eightbytes, or it contains unaligned + // fields, it has class MEMORY" + if (ty_size > 32) + return X64CABIClass_MEMORY; + if (ty->data.structure.layout != ContainerLayoutExtern) { + // TODO determine whether packed structs have any unaligned fields + return X64CABIClass_Unknown; + } + // "If the size of the aggregate exceeds two eightbytes and the first eight- + // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument + // is passed in memory." + if (ty_size > 16) { + // Zig doesn't support vectors and large fp registers yet, so this will always + // be memory. + return X64CABIClass_MEMORY; + } + X64CABIClass working_class = X64CABIClass_Unknown; + for (uint32_t i = 0; i < ty->data.structure.src_field_count; i += 1) { + X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.structure.fields->type_entry); + if (field_class == X64CABIClass_Unknown) + return X64CABIClass_Unknown; + if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) { + working_class = field_class; + } + } + return working_class; + } + case ZigTypeIdUnion: { + // "If the size of an object is larger than four eightbytes, or it contains unaligned + // fields, it has class MEMORY" + if (ty_size > 32) + return X64CABIClass_MEMORY; + if (ty->data.unionation.layout != ContainerLayoutExtern) + return X64CABIClass_MEMORY; + // "If the size of the aggregate exceeds two eightbytes and the first eight- + // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument + // is passed in memory." + if (ty_size > 16) { + // Zig doesn't support vectors and large fp registers yet, so this will always + // be memory. + return X64CABIClass_MEMORY; + } + X64CABIClass working_class = X64CABIClass_Unknown; + for (uint32_t i = 0; i < ty->data.unionation.src_field_count; i += 1) { + X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.unionation.fields->type_entry); + if (field_class == X64CABIClass_Unknown) + return X64CABIClass_Unknown; + if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) { + working_class = field_class; + } + } + return working_class; + } + default: + return X64CABIClass_Unknown; + } +} + +// NOTE this does not depend on x86_64 +bool type_is_c_abi_int(CodeGen *g, ZigType *ty) { + return (ty->id == ZigTypeIdInt || + ty->id == ZigTypeIdFloat || + ty->id == ZigTypeIdBool || + ty->id == ZigTypeIdEnum || + ty->id == ZigTypeIdVoid || + ty->id == ZigTypeIdUnreachable || + get_codegen_ptr_type(ty) != nullptr); +} + diff --git a/src/analyze.hpp b/src/analyze.hpp index 98e4412594..cd3f52d9c5 100644 --- a/src/analyze.hpp +++ b/src/analyze.hpp @@ -182,7 +182,6 @@ size_t type_id_index(ZigType *entry); ZigType *get_generic_fn_type(CodeGen *g, FnTypeId *fn_type_id); Result type_is_copyable(CodeGen *g, ZigType *type_entry); LinkLib *create_link_lib(Buf *name); -bool calling_convention_does_first_arg_return(CallingConvention cc); LinkLib *add_link_lib(CodeGen *codegen, Buf *lib); uint32_t get_abi_alignment(CodeGen *g, ZigType *type_entry); @@ -211,6 +210,8 @@ bool calling_convention_allows_zig_types(CallingConvention cc); const char *calling_convention_name(CallingConvention cc); void walk_function_params(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk); - +X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty); +bool type_is_c_abi_int(CodeGen *g, ZigType *ty); +bool want_first_arg_sret(CodeGen *g, FnTypeId *fn_type_id); #endif diff --git a/src/codegen.cpp b/src/codegen.cpp index 4be08b03e7..71caf18e28 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -577,19 +577,25 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, ZigFn *fn_table_entry) { // use the ABI alignment, which is fine. } + unsigned init_gen_i = 0; if (!type_has_bits(return_type)) { // nothing to do } else if (type_is_codegen_pointer(return_type)) { addLLVMAttr(fn_table_entry->llvm_value, 0, "nonnull"); - } else if (handle_is_ptr(return_type) && calling_convention_does_first_arg_return(cc)) { + } else if (want_first_arg_sret(g, &fn_type->data.fn.fn_type_id)) { addLLVMArgAttr(fn_table_entry->llvm_value, 0, "sret"); addLLVMArgAttr(fn_table_entry->llvm_value, 0, "nonnull"); + if (cc == CallingConventionC) { + addLLVMArgAttr(fn_table_entry->llvm_value, 0, "noalias"); + } + init_gen_i = 1; } // set parameter attributes FnWalk fn_walk = {}; fn_walk.id = FnWalkIdAttrs; fn_walk.data.attrs.fn = fn_table_entry; + fn_walk.data.attrs.gen_i = init_gen_i; walk_function_params(g, fn_type, &fn_walk); uint32_t err_ret_trace_arg_index = get_err_ret_trace_arg_index(g, fn_table_entry); @@ -1905,95 +1911,6 @@ static LLVMValueRef build_alloca(CodeGen *g, ZigType *type_entry, const char *na return result; } -enum X64CABIClass { - X64CABIClass_Unknown, - X64CABIClass_MEMORY, - X64CABIClass_INTEGER, - X64CABIClass_SSE, -}; - -static X64CABIClass type_c_abi_x86_64_class(CodeGen *g, ZigType *ty) { - size_t ty_size = type_size(g, ty); - if (get_codegen_ptr_type(ty) != nullptr) - return X64CABIClass_INTEGER; - switch (ty->id) { - case ZigTypeIdEnum: - case ZigTypeIdInt: - case ZigTypeIdBool: - return X64CABIClass_INTEGER; - case ZigTypeIdFloat: - return X64CABIClass_SSE; - case ZigTypeIdStruct: { - // "If the size of an object is larger than four eightbytes, or it contains unaligned - // fields, it has class MEMORY" - if (ty_size > 32) - return X64CABIClass_MEMORY; - if (ty->data.structure.layout != ContainerLayoutExtern) { - // TODO determine whether packed structs have any unaligned fields - return X64CABIClass_Unknown; - } - // "If the size of the aggregate exceeds two eightbytes and the first eight- - // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument - // is passed in memory." - if (ty_size > 16) { - // Zig doesn't support vectors and large fp registers yet, so this will always - // be memory. - return X64CABIClass_MEMORY; - } - X64CABIClass working_class = X64CABIClass_Unknown; - for (uint32_t i = 0; i < ty->data.structure.src_field_count; i += 1) { - X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.structure.fields->type_entry); - if (field_class == X64CABIClass_Unknown) - return X64CABIClass_Unknown; - if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) { - working_class = field_class; - } - } - return working_class; - } - case ZigTypeIdUnion: { - // "If the size of an object is larger than four eightbytes, or it contains unaligned - // fields, it has class MEMORY" - if (ty_size > 32) - return X64CABIClass_MEMORY; - if (ty->data.unionation.layout != ContainerLayoutExtern) - return X64CABIClass_MEMORY; - // "If the size of the aggregate exceeds two eightbytes and the first eight- - // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument - // is passed in memory." - if (ty_size > 16) { - // Zig doesn't support vectors and large fp registers yet, so this will always - // be memory. - return X64CABIClass_MEMORY; - } - X64CABIClass working_class = X64CABIClass_Unknown; - for (uint32_t i = 0; i < ty->data.unionation.src_field_count; i += 1) { - X64CABIClass field_class = type_c_abi_x86_64_class(g, ty->data.unionation.fields->type_entry); - if (field_class == X64CABIClass_Unknown) - return X64CABIClass_Unknown; - if (i == 0 || field_class == X64CABIClass_MEMORY || working_class == X64CABIClass_SSE) { - working_class = field_class; - } - } - return working_class; - } - default: - return X64CABIClass_Unknown; - } -} - -// NOTE this does not depend on x86_64 -static bool type_is_c_abi_int(CodeGen *g, ZigType *ty) { - size_t ty_size = type_size(g, ty); - if (ty_size > g->pointer_size_bytes) - return false; - return (ty->id == ZigTypeIdInt || - ty->id == ZigTypeIdFloat || - ty->id == ZigTypeIdBool || - ty->id == ZigTypeIdEnum || - get_codegen_ptr_type(ty) != nullptr); -} - static bool iter_function_params_c_abi(CodeGen *g, ZigType *fn_type, FnWalk *fn_walk, size_t src_i) { // Initialized from the type for some walks, but because of C var args, // initialized based on callsite instructions for that one. @@ -2327,15 +2244,13 @@ static LLVMValueRef ir_render_return(CodeGen *g, IrExecutable *executable, IrIns LLVMValueRef value = ir_llvm_value(g, return_instruction->value); ZigType *return_type = return_instruction->value->value.type; - if (handle_is_ptr(return_type)) { - if (calling_convention_does_first_arg_return(g->cur_fn->type_entry->data.fn.fn_type_id.cc)) { - assert(g->cur_ret_ptr); - gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value); - LLVMBuildRetVoid(g->builder); - } else { - LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, ""); - LLVMBuildRet(g->builder, by_val_value); - } + if (want_first_arg_sret(g, &g->cur_fn->type_entry->data.fn.fn_type_id)) { + assert(g->cur_ret_ptr); + gen_assign_raw(g, g->cur_ret_ptr, get_pointer_to_type(g, return_type, false), value); + LLVMBuildRetVoid(g->builder); + } else if (handle_is_ptr(return_type)) { + LLVMValueRef by_val_value = gen_load_untyped(g, value, 0, false, ""); + LLVMBuildRet(g->builder, by_val_value); } else { LLVMBuildRet(g->builder, value); } @@ -3551,8 +3466,7 @@ static LLVMValueRef ir_render_call(CodeGen *g, IrExecutable *executable, IrInstr CallingConvention cc = fn_type->data.fn.fn_type_id.cc; - bool first_arg_ret = ret_has_bits && handle_is_ptr(src_return_type) && - calling_convention_does_first_arg_return(cc); + bool first_arg_ret = ret_has_bits && want_first_arg_sret(g, fn_type_id); bool prefix_arg_err_ret_stack = get_prefix_arg_err_ret_stack(g, fn_type_id); bool is_var_args = fn_type_id->is_var_args; ZigList gen_param_values = {}; @@ -6260,13 +6174,14 @@ static void do_code_gen(CodeGen *g) { // Generate function definitions. for (size_t fn_i = 0; fn_i < g->fn_defs.length; fn_i += 1) { ZigFn *fn_table_entry = g->fn_defs.at(fn_i); - CallingConvention cc = fn_table_entry->type_entry->data.fn.fn_type_id.cc; + FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id; + CallingConvention cc = fn_type_id->cc; bool is_c_abi = cc == CallingConventionC; LLVMValueRef fn = fn_llvm_value(g, fn_table_entry); g->cur_fn = fn_table_entry; g->cur_fn_val = fn; - ZigType *return_type = fn_table_entry->type_entry->data.fn.fn_type_id.return_type; + ZigType *return_type = fn_type_id->return_type; if (handle_is_ptr(return_type)) { g->cur_ret_ptr = LLVMGetParam(fn, 0); } else { @@ -6344,13 +6259,15 @@ static void do_code_gen(CodeGen *g) { ImportTableEntry *import = get_scope_import(&fn_table_entry->fndef_scope->base); + unsigned gen_i_init = want_first_arg_sret(g, fn_type_id) ? 1 : 0; + // create debug variable declarations for variables and allocate all local variables FnWalk fn_walk_var = {}; fn_walk_var.id = FnWalkIdVars; fn_walk_var.data.vars.import = import; fn_walk_var.data.vars.fn = fn_table_entry; fn_walk_var.data.vars.llvm_fn = fn; - fn_walk_var.data.vars.gen_i = 0; + fn_walk_var.data.vars.gen_i = gen_i_init; for (size_t var_i = 0; var_i < fn_table_entry->variable_list.length; var_i += 1) { ZigVar *var = fn_table_entry->variable_list.at(var_i); @@ -6429,6 +6346,7 @@ static void do_code_gen(CodeGen *g) { fn_walk_init.id = FnWalkIdInits; fn_walk_init.data.inits.fn = fn_table_entry; fn_walk_init.data.inits.llvm_fn = fn; + fn_walk_init.data.inits.gen_i = gen_i_init; walk_function_params(g, fn_table_entry->type_entry, &fn_walk_init); ir_render(g, fn_table_entry); diff --git a/test/behavior.zig b/test/behavior.zig index 6b35b0c030..25997a2a4b 100644 --- a/test/behavior.zig +++ b/test/behavior.zig @@ -9,7 +9,6 @@ comptime { _ = @import("cases/bitcast.zig"); _ = @import("cases/bool.zig"); _ = @import("cases/bugs/1111.zig"); - _ = @import("cases/bugs/1230.zig"); _ = @import("cases/bugs/1277.zig"); _ = @import("cases/bugs/1421.zig"); _ = @import("cases/bugs/394.zig"); diff --git a/test/cases/bugs/1230.zig b/test/cases/bugs/1230.zig deleted file mode 100644 index b782a77f0b..0000000000 --- a/test/cases/bugs/1230.zig +++ /dev/null @@ -1,14 +0,0 @@ -const assert = @import("std").debug.assert; - -const S = extern struct { - x: i32, -}; - -extern fn ret_struct() S { - return S{ .x = 42 }; -} - -test "extern return small struct (bug 1230)" { - const s = ret_struct(); - assert(s.x == 42); -} diff --git a/test/stage1/c_abi/build.zig b/test/stage1/c_abi/build.zig index 02db8f7904..e0a108aeb5 100644 --- a/test/stage1/c_abi/build.zig +++ b/test/stage1/c_abi/build.zig @@ -5,6 +5,7 @@ pub fn build(b: *Builder) void { const c_obj = b.addCObject("cfuncs", "cfuncs.c"); c_obj.setBuildMode(rel_opts); + c_obj.setNoStdLib(true); const main = b.addTest("main.zig"); main.setBuildMode(rel_opts); diff --git a/test/stage1/c_abi/cfuncs.c b/test/stage1/c_abi/cfuncs.c index ff249d2a59..102cd466b1 100644 --- a/test/stage1/c_abi/cfuncs.c +++ b/test/stage1/c_abi/cfuncs.c @@ -59,6 +59,8 @@ struct SplitStructInts { }; void zig_split_struct_ints(struct SplitStructInts); +struct BigStruct zig_big_struct_both(struct BigStruct); + void run_c_tests(void) { zig_u8(0xff); zig_u16(0xfffe); @@ -77,8 +79,7 @@ void run_c_tests(void) { zig_bool(true); - // TODO making this non-static crashes for some reason - static uint8_t array[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; + uint8_t array[10] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}; zig_array(array); { @@ -95,6 +96,16 @@ void run_c_tests(void) { struct SplitStructInts s = {1234, 100, 1337}; zig_split_struct_ints(s); } + + { + struct BigStruct s = {30, 31, 32, 33, 34}; + struct BigStruct res = zig_big_struct_both(s); + assert_or_panic(res.a == 20); + assert_or_panic(res.b == 21); + assert_or_panic(res.c == 22); + assert_or_panic(res.d == 23); + assert_or_panic(res.e == 24); + } } void c_u8(uint8_t x) { @@ -185,3 +196,13 @@ void c_split_struct_ints(struct SplitStructInts x) { assert_or_panic(x.b == 100); assert_or_panic(x.c == 1337); } + +struct BigStruct c_big_struct_both(struct BigStruct x) { + assert_or_panic(x.a == 1); + assert_or_panic(x.b == 2); + assert_or_panic(x.c == 3); + assert_or_panic(x.d == 4); + assert_or_panic(x.e == 5); + struct BigStruct y = {10, 11, 12, 13, 14}; + return y; +} diff --git a/test/stage1/c_abi/main.zig b/test/stage1/c_abi/main.zig index e1356f50ef..196311a283 100644 --- a/test/stage1/c_abi/main.zig +++ b/test/stage1/c_abi/main.zig @@ -203,3 +203,37 @@ export fn zig_split_struct_ints(x: SplitStructInt) void { assertOrPanic(x.b == 100); assertOrPanic(x.c == 1337); } + +extern fn c_big_struct_both(BigStruct) BigStruct; + +test "C ABI sret and byval together" { + var s = BigStruct{ + .a = 1, + .b = 2, + .c = 3, + .d = 4, + .e = 5, + }; + var y = c_big_struct_both(s); + assertOrPanic(y.a == 10); + assertOrPanic(y.b == 11); + assertOrPanic(y.c == 12); + assertOrPanic(y.d == 13); + assertOrPanic(y.e == 14); +} + +export fn zig_big_struct_both(x: BigStruct) BigStruct { + assertOrPanic(x.a == 30); + assertOrPanic(x.b == 31); + assertOrPanic(x.c == 32); + assertOrPanic(x.d == 33); + assertOrPanic(x.e == 34); + var s = BigStruct{ + .a = 20, + .b = 21, + .c = 22, + .d = 23, + .e = 24, + }; + return s; +} -- cgit v1.2.3