0.6.0: init_new/init_temp removed. LinkedList API rewritten. List "pop" and "remove" function now return Optionals. RingBuffer API rewritten. Allocator interface changed. Deprecated Allocator, DString and mem functions removed. "identity" functions are now constants for Matrix and Complex numbers. @default implementations for interfaces removed. any* => any, same for interfaces. Emit local/private globals as "private" in LLVM, following C "static". Updated enum syntax. Add support [rgba] properties in vectors. Improved checks of aliased "void". Subarray -> slice. Fix of llvm codegen enum check. Improved alignment handling. Add --output-dir #1155. Removed List/Object append. GenericList renamed AnyList. Remove unused "unwrap". Fixes to cond. Optimize output in dead branches. Better checking of operator methods. Disallow any from implementing dynamic methods. Check for operator mismatch. Remove unnecessary bitfield. Remove numbering in --list* commands Old style enum declaration for params/type, but now the type is optional. Add note on #1086. Allow making distinct types out of "void", "typeid", "anyfault" and faults. Remove system linker build options. "Try" expressions must be simple expressions. Add optimized build to Mac tests. Register int. assert(false) only allowed in unused branches or in tests. Compile time failed asserts is a compile time error. Remove current_block_is_target. Bug when assigning an optional from an optional. Remove unused emit_zstring. Simplify phi code. Remove unnecessary unreachable blocks and remove unnecessary current_block NULL assignments. Proper handling of '.' and Win32 '//server' paths. Add "no discard" to expression blocks with a return value. Detect "unsigned >= 0" as errors. Fix issue with distinct void as a member #1147. Improve callstack debug information #1184. Fix issue with absolute output-dir paths. Lambdas were not type checked thoroughly #1185. Fix compilation warning #1187. Request jump table using @jump for switches. Path normalization - fix possible null terminator out of bounds. Improved error messages on inlined macros.

Upgrade of mingw in CI. Fix problems using reflection on interface types #1203. Improved debug information on defer. $foreach doesn't create an implicit syntactic scope.
Error if `@if` depends on `@if`. Updated Linux stacktrace. Fix of default argument stacktrace. Allow linking libraries directly by file path. Improve inlining warning messages. Added `index_of_char_from`. Compiler crash using enum nameof from different module #1205. Removed unused fields in find_msvc. Use vswhere to find msvc. Update tests for LLVM 19
This commit is contained in:
Christoffer Lerno
2024-02-23 00:18:43 +01:00
parent 321c5ec756
commit e293c435af
271 changed files with 7608 additions and 6181 deletions

View File

@@ -10,7 +10,7 @@ fault BacktraceFault
RESOLUTION_FAILED,
}
const Backtrace BACKTRACE_UNKNOWN = { 0, "", "", "", 0, null };
const Backtrace BACKTRACE_UNKNOWN = { 0, "", "", "", 0, null, false };
struct Backtrace (Printable)
{
@@ -19,7 +19,8 @@ struct Backtrace (Printable)
String object_file;
String file;
uint line;
Allocator* allocator;
Allocator allocator;
bool is_inline;
}
@@ -35,15 +36,16 @@ fn bool Backtrace.is_unknown(&self)
fn usz! Backtrace.to_format(&self, Formatter* formatter) @dynamic
{
String inline_suffix = self.is_inline ? " [inline]" : "";
if (self.has_file())
{
return formatter.printf("%s (in %s) (%s:%d)", self.function, self.object_file, self.file, self.line);
return formatter.printf("%s (in %s) (%s:%d)%s", self.function, self.object_file, self.file, self.line, inline_suffix);
}
if (self.is_unknown())
{
return formatter.printf("??? (in unknown)");
return formatter.printf("??? (in unknown)%s", inline_suffix);
}
return formatter.printf("%s (in %s) (source unavailable)", self.function, self.object_file);
return formatter.printf("%s (in %s) (source unavailable)%s", self.function, self.object_file, inline_suffix);
}
fn void Backtrace.free(&self)
{
@@ -53,7 +55,7 @@ fn void Backtrace.free(&self)
allocator::free(self.allocator, self.file);
}
fn Backtrace* Backtrace.init(&self, uptr offset, String function, String object_file, String file = "", uint line = 0, Allocator* allocator)
fn Backtrace* Backtrace.init(&self, uptr offset, String function, String object_file, String file = "", uint line = 0, Allocator allocator)
{
if (!allocator)
{
@@ -95,7 +97,7 @@ def symbolize_backtrace = linux::symbolize_backtrace @if(env::LINUX);
def symbolize_backtrace = win32::symbolize_backtrace @if(env::WIN32);
def symbolize_backtrace = darwin::symbolize_backtrace @if(env::DARWIN);
fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator* allocator) @if(!env::NATIVE_STACKTRACE)
fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator allocator) @if(!env::NATIVE_STACKTRACE)
{
return {};
}

View File

@@ -9,7 +9,7 @@ import std::io::path, libc, std::os;
* @require name.len > 0
* @return! SearchResult.MISSING
**/
fn String! get_var(String name, Allocator* allocator = allocator::heap())
fn String! get_var(String name, Allocator allocator = allocator::heap())
{
@pool(allocator)
{
@@ -72,7 +72,7 @@ fn bool set_var(String name, String value, bool overwrite = true)
/**
* Returns the current user's home directory.
**/
fn String! get_home_dir(Allocator* using = allocator::heap())
fn String! get_home_dir(Allocator using = allocator::heap())
{
String home;
$if !env::WIN32:
@@ -86,7 +86,7 @@ fn String! get_home_dir(Allocator* using = allocator::heap())
/**
* Returns the current user's config directory.
**/
fn Path! get_config_dir(Allocator* allocator = allocator::heap())
fn Path! get_config_dir(Allocator allocator = allocator::heap())
{
@pool(allocator)
{
@@ -126,7 +126,7 @@ fn bool clear_var(String name)
};
}
fn String! executable_path(Allocator *allocator = allocator::heap())
fn String! executable_path(Allocator allocator = allocator::heap())
{
$if env::DARWIN:
return darwin::executable_path(allocator);

View File

@@ -128,17 +128,17 @@ fn ulong! elf_module_image_base(String path) @local
return 0;
}
fn Backtrace! backtrace_load_from_exec(void* addr, Allocator* allocator) @local
fn void! backtrace_add_from_exec(BacktraceList* list, void* addr, Allocator allocator) @local
{
char[] buf = mem::temp_alloc_array(char, 1024);
String exec_path = process::execute_stdout_to_buffer(buf, {"realpath", "-e", string::tformat("/proc/%d/exe", posix::getpid())})!;
String obj_name = exec_path.copy(allocator);
String addr2line = process::execute_stdout_to_buffer(buf, {"addr2line", "-p", "-i", "-C", "-f", "-e", exec_path, string::tformat("0x%x", addr)})!;
return backtrace_from_addr2line(addr, addr2line, obj_name, "???", allocator);
return backtrace_add_addr2line(list, addr, addr2line, obj_name, "???", allocator);
}
fn Backtrace! backtrace_load_from_dlinfo(void* addr, Linux_Dl_info* info, Allocator* allocator) @local
fn void! backtrace_add_from_dlinfo(BacktraceList* list, void* addr, Linux_Dl_info* info, Allocator allocator) @local
{
char[] buf = mem::temp_alloc_array(char, 1024);
@@ -146,30 +146,19 @@ fn Backtrace! backtrace_load_from_dlinfo(void* addr, Linux_Dl_info* info, Alloca
ZString obj_path = info.dli_fname;
String sname = info.dli_sname ? info.dli_sname.str_view() : "???";
String addr2line = process::execute_stdout_to_buffer(buf, {"addr2line", "-p", "-i", "-C", "-f", "-e", obj_path.str_view(), string::tformat("0x%x", obj_addr - 1)})!;
return backtrace_from_addr2line(addr, addr2line, info.dli_fname.str_view(), sname, allocator);
return backtrace_add_addr2line(list, addr, addr2line, info.dli_fname.str_view(), sname, allocator);
}
fn Backtrace! backtrace_from_addr2line(void* addr, String addr2line, String obj_name, String func_name, Allocator* allocator) @local
fn Backtrace! backtrace_line_parse(String string, String obj_name, String func_name, bool is_inlined, Allocator allocator)
{
String[] parts = addr2line.tsplit(" at ");
if (parts.len != 2)
{
return {
.function = func_name.copy(allocator),
.object_file = obj_name.copy(allocator),
.offset = (uptr)addr,
.file = "".copy(allocator),
.line = 0,
.allocator = allocator
};
}
String[] parts = string.trim().tsplit(" at ");
if (parts.len != 2) return SearchResult.MISSING?;
uint line = 0;
uint line = 0;
String source = "";
if (!parts[1].contains("?") && parts[1].contains(":"))
{
usz index = parts[1].rindex_of_char(':')!;
source = parts[1][:index];
line = parts[1][index + 1..].to_uint()!;
}
@@ -179,25 +168,53 @@ fn Backtrace! backtrace_from_addr2line(void* addr, String addr2line, String obj_
.file = source.copy(allocator),
.line = line,
.allocator = allocator,
.is_inline = is_inlined
};
}
fn Backtrace! backtrace_load_element(void* addr, Allocator* allocator = allocator::heap()) @local
fn void! backtrace_add_addr2line(BacktraceList* list, void* addr, String addr2line, String obj_name, String func_name, Allocator allocator) @local
{
if (!addr) return backtrace::BACKTRACE_UNKNOWN;
String[] inline_parts = addr2line.tsplit("(inlined by)");
usz last = inline_parts.len - 1;
foreach (i, part : inline_parts)
{
bool is_inline = i != last;
Backtrace! trace = backtrace_line_parse(part, obj_name, func_name, is_inline, allocator);
if (catch trace)
{
list.push({
.function = func_name.copy(allocator),
.object_file = obj_name.copy(allocator),
.offset = (uptr)addr,
.file = "".copy(allocator),
.line = 0,
.allocator = allocator,
.is_inline = is_inline
});
continue;
}
list.push(trace);
}
}
fn void! backtrace_add_element(BacktraceList *list, void* addr, Allocator allocator = allocator::heap()) @local
{
if (!addr)
{
list.push(backtrace::BACKTRACE_UNKNOWN);
return;
}
@pool(allocator) {
Linux_Dl_info info;
if (dladdr(addr, &info) == 0)
{
return backtrace_load_from_exec(addr, allocator);
return backtrace_add_from_exec(list, addr, allocator);
}
return backtrace_load_from_dlinfo(addr, &info, allocator);
return backtrace_add_from_dlinfo(list, addr, &info, allocator);
};
}
fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator* allocator)
fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator allocator)
{
BacktraceList list;
list.new_init(backtrace.len, allocator);
@@ -213,8 +230,7 @@ fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator* allocator)
{
foreach (addr : backtrace)
{
Backtrace trace = backtrace_load_element(addr, allocator)!;
list.append(trace);
backtrace_add_element(&list, addr, allocator)!;
}
};
return list;

View File

@@ -68,7 +68,7 @@ struct Darwin_segment_command_64
}
fn String! executable_path(Allocator *allocator)
fn String! executable_path(Allocator allocator)
{
char[4096] path;
uint len = path.len;
@@ -93,7 +93,7 @@ fn uptr! load_address() @local
}
fn Backtrace! backtrace_load_element(String execpath, void* buffer, void* load_address, Allocator* allocator = allocator::heap()) @local
fn Backtrace! backtrace_load_element(String execpath, void* buffer, void* load_address, Allocator allocator = allocator::heap()) @local
{
@pool(allocator)
{
@@ -132,7 +132,7 @@ fn Backtrace! backtrace_load_element(String execpath, void* buffer, void* load_a
};
}
fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator* allocator)
fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator allocator)
{
void *load_addr = (void *)load_address()!;
BacktraceList list;
@@ -150,7 +150,7 @@ fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator* allocator)
String execpath = executable_path(allocator::temp())!;
foreach (addr : backtrace)
{
list.append(backtrace_load_element(execpath, addr, load_addr, allocator) ?? backtrace::BACKTRACE_UNKNOWN);
list.push(backtrace_load_element(execpath, addr, load_addr, allocator) ?? backtrace::BACKTRACE_UNKNOWN);
}
};
return list;

View File

@@ -24,7 +24,7 @@ macro Class! class_by_name(ZString c)
return cls ?: ObjcFailure.CLASS_NOT_FOUND?;
}
macro Class[] class_get_list(Allocator *allocator = allocator::heap())
macro Class[] class_get_list(Allocator allocator = allocator::heap())
{
int num_classes = macos_objc_getClassList(null, 0);
if (!num_classes) return {};

View File

@@ -99,6 +99,8 @@ extern fn CFile _fdopen(int fd, ZString mode);
extern fn CInt _access(ZString path, CInt mode);
extern fn CInt _waccess(WString path, CInt mode);
extern fn WString _wfullpath(WString absPath, WString relPath, usz maxLength);
/*
extern ulong _win32_GetCurrentDirectoryW(ulong, Char16* buffer) @extern("GetCurrentDirectoryW");
extern bool _win32_CreateSymbolicLinkW(WString symlink_file, WString target_file, ulong flags) @extern("CreateSymbolicLinkW");

View File

@@ -152,7 +152,7 @@ struct Symbol
Win32_DWORD64 displacement;
fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator* allocator)
fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator allocator)
{
BacktraceList list;
list.new_init(backtrace.len, allocator);
@@ -161,12 +161,12 @@ fn BacktraceList! symbolize_backtrace(void*[] backtrace, Allocator* allocator)
defer symCleanup(process);
foreach (addr : backtrace)
{
list.append(resolve_backtrace(addr, process, allocator) ?? backtrace::BACKTRACE_UNKNOWN);
list.push(resolve_backtrace(addr, process, allocator) ?? backtrace::BACKTRACE_UNKNOWN);
}
return list;
}
fn Backtrace! resolve_backtrace(void* addr, Win32_HANDLE process, Allocator* allocator)
fn Backtrace! resolve_backtrace(void* addr, Win32_HANDLE process, Allocator allocator)
{
Symbol symbol;
//Win32_DWORD image_type = load_modules()!;