Skip to content

Commit

Permalink
Store stack trace type in Zcu
Browse files Browse the repository at this point in the history
  • Loading branch information
antlilja committed Aug 16, 2024
1 parent 0b0e7bf commit 42b5362
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
2 changes: 2 additions & 0 deletions src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10059,6 +10059,8 @@ fn finishFunc(
// lower this fn type.
const unresolved_stack_trace_ty = try pt.getBuiltinType("StackTrace");
try unresolved_stack_trace_ty.resolveFields(pt);

if (mod.stack_trace_type == .none) mod.stack_trace_type = unresolved_stack_trace_ty.toIntern();
}

return Air.internedToRef(if (opt_func_index != .none) opt_func_index else func_ty);
Expand Down
1 change: 1 addition & 0 deletions src/Zcu.zig
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ panic_messages: [PanicId.len]InternPool.Nav.Index.Optional = .{.none} ** PanicId
/// The panic function body.
panic_func_index: InternPool.Index = .none,
null_stack_trace: InternPool.Index = .none,
stack_trace_type: InternPool.Index = .none,

pub const PerThread = @import("Zcu/PerThread.zig");

Expand Down
26 changes: 2 additions & 24 deletions src/codegen/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2716,7 +2716,7 @@ pub const Object = struct {
if (Type.fromInterned(fn_info.return_type).isError(zcu) and
zcu.comp.config.any_error_tracing)
{
const ptr_ty = try pt.singleMutPtrType(try getStackTraceType(pt));
const ptr_ty = try pt.ptrType(.{ .child = zcu.stack_trace_type });
debug_param_types.appendAssumeCapacity(try o.lowerDebugType(pt, ptr_ty));
}

Expand Down Expand Up @@ -3545,7 +3545,7 @@ pub const Object = struct {
if (Type.fromInterned(fn_info.return_type).isError(mod) and
mod.comp.config.any_error_tracing)
{
const ptr_ty = try pt.singleMutPtrType(try getStackTraceType(pt));
const ptr_ty = try pt.ptrType(.{ .child = mod.stack_trace_type });
try llvm_params.append(o.gpa, try o.lowerType(pt, ptr_ty));
}

Expand Down Expand Up @@ -11841,28 +11841,6 @@ const optional_layout_version = 3;

const lt_errors_fn_name = "__zig_lt_errors_len";

fn getStackTraceType(pt: Zcu.PerThread) Allocator.Error!Type {
const zcu = pt.zcu;
const ip = &zcu.intern_pool;

const std_mod = zcu.std_mod;
const std_file_imported = pt.importPkg(std_mod) catch unreachable;

const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls);
const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index));
const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu));
const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;

const stack_trace_str = try ip.getOrPutString(zcu.gpa, pt.tid, "StackTrace", .no_embedded_nulls);
// buffer is only used for int_type, `builtin` is a struct.
const builtin_ty = zcu.navValue(builtin_nav).toType();
const builtin_namespace = zcu.namespacePtr(builtin_ty.getNamespaceIndex(zcu));
const stack_trace_nav = builtin_namespace.pub_decls.getKeyAdapted(stack_trace_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;

// Sema should have ensured that StackTrace was analyzed.
return zcu.navValue(stack_trace_nav).toType();
}

fn compilerRtIntBits(bits: u16) u16 {
inline for (.{ 32, 64, 128 }) |b| {
if (bits <= b) {
Expand Down

0 comments on commit 42b5362

Please sign in to comment.