mirror of
https://github.com/ziglang/zig.git
synced 2025-12-12 01:03:13 +00:00
Zcu.Decl: remove ty field
`Decl` can no longer store un-interned values, so this field is now unnecessary. The type can instead be fetched with the new `typeOf` helper method, which just gets the type of the Decl's `Value`.
This commit is contained in:
parent
341857e5cd
commit
c6f3e9d79c
@ -6581,7 +6581,6 @@ pub fn getFuncInstance(ip: *InternPool, gpa: Allocator, arg: GetFuncInstanceKey)
|
|||||||
generic_owner,
|
generic_owner,
|
||||||
func_index,
|
func_index,
|
||||||
func_extra_index,
|
func_extra_index,
|
||||||
func_ty,
|
|
||||||
arg.alignment,
|
arg.alignment,
|
||||||
arg.section,
|
arg.section,
|
||||||
);
|
);
|
||||||
@ -6711,7 +6710,6 @@ pub fn getFuncInstanceIes(
|
|||||||
generic_owner,
|
generic_owner,
|
||||||
func_index,
|
func_index,
|
||||||
func_extra_index,
|
func_extra_index,
|
||||||
func_ty,
|
|
||||||
arg.alignment,
|
arg.alignment,
|
||||||
arg.section,
|
arg.section,
|
||||||
);
|
);
|
||||||
@ -6723,7 +6721,6 @@ fn finishFuncInstance(
|
|||||||
generic_owner: Index,
|
generic_owner: Index,
|
||||||
func_index: Index,
|
func_index: Index,
|
||||||
func_extra_index: u32,
|
func_extra_index: u32,
|
||||||
func_ty: Index,
|
|
||||||
alignment: Alignment,
|
alignment: Alignment,
|
||||||
section: OptionalNullTerminatedString,
|
section: OptionalNullTerminatedString,
|
||||||
) Allocator.Error!Index {
|
) Allocator.Error!Index {
|
||||||
@ -6735,7 +6732,6 @@ fn finishFuncInstance(
|
|||||||
.src_line = fn_owner_decl.src_line,
|
.src_line = fn_owner_decl.src_line,
|
||||||
.has_tv = true,
|
.has_tv = true,
|
||||||
.owns_tv = true,
|
.owns_tv = true,
|
||||||
.ty = @import("type.zig").Type.fromInterned(func_ty),
|
|
||||||
.val = @import("Value.zig").fromInterned(func_index),
|
.val = @import("Value.zig").fromInterned(func_index),
|
||||||
.alignment = alignment,
|
.alignment = alignment,
|
||||||
.@"linksection" = section,
|
.@"linksection" = section,
|
||||||
|
|||||||
@ -330,9 +330,6 @@ const ValueArena = struct {
|
|||||||
|
|
||||||
pub const Decl = struct {
|
pub const Decl = struct {
|
||||||
name: InternPool.NullTerminatedString,
|
name: InternPool.NullTerminatedString,
|
||||||
/// The most recent Type of the Decl after a successful semantic analysis.
|
|
||||||
/// Populated when `has_tv`.
|
|
||||||
ty: Type,
|
|
||||||
/// The most recent Value of the Decl after a successful semantic analysis.
|
/// The most recent Value of the Decl after a successful semantic analysis.
|
||||||
/// Populated when `has_tv`.
|
/// Populated when `has_tv`.
|
||||||
val: Value,
|
val: Value,
|
||||||
@ -487,20 +484,28 @@ pub const Decl = struct {
|
|||||||
zcu.namespacePtr(decl.src_namespace).fullyQualifiedName(zcu, decl.name);
|
zcu.namespacePtr(decl.src_namespace).fullyQualifiedName(zcu, decl.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn typedValue(decl: Decl) error{AnalysisFail}!TypedValue {
|
pub fn typeOf(decl: Decl, zcu: *const Zcu) Type {
|
||||||
|
assert(decl.has_tv);
|
||||||
|
return Type.fromInterned(zcu.intern_pool.typeOf(decl.val.toIntern()));
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn typedValue(decl: Decl, zcu: *const Zcu) error{AnalysisFail}!TypedValue {
|
||||||
if (!decl.has_tv) return error.AnalysisFail;
|
if (!decl.has_tv) return error.AnalysisFail;
|
||||||
return TypedValue{ .ty = decl.ty, .val = decl.val };
|
return .{
|
||||||
|
.ty = decl.typeOf(zcu),
|
||||||
|
.val = decl.val,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn internValue(decl: *Decl, zcu: *Zcu) Allocator.Error!InternPool.Index {
|
pub fn internValue(decl: *Decl, zcu: *Zcu) Allocator.Error!InternPool.Index {
|
||||||
assert(decl.has_tv);
|
assert(decl.has_tv);
|
||||||
const ip_index = try decl.val.intern(decl.ty, zcu);
|
const ip_index = try decl.val.intern(decl.typeOf(zcu), zcu);
|
||||||
decl.val = Value.fromInterned(ip_index);
|
decl.val = Value.fromInterned(ip_index);
|
||||||
return ip_index;
|
return ip_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn isFunction(decl: Decl, zcu: *const Zcu) !bool {
|
pub fn isFunction(decl: Decl, zcu: *const Zcu) !bool {
|
||||||
const tv = try decl.typedValue();
|
const tv = try decl.typedValue(zcu);
|
||||||
return tv.ty.zigTypeTag(zcu) == .Fn;
|
return tv.ty.zigTypeTag(zcu) == .Fn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -590,7 +595,7 @@ pub const Decl = struct {
|
|||||||
@tagName(decl.analysis),
|
@tagName(decl.analysis),
|
||||||
});
|
});
|
||||||
if (decl.has_tv) {
|
if (decl.has_tv) {
|
||||||
std.debug.print(" ty={} val={}", .{ decl.ty, decl.val });
|
std.debug.print(" val={}", .{decl.val});
|
||||||
}
|
}
|
||||||
std.debug.print("\n", .{});
|
std.debug.print("\n", .{});
|
||||||
}
|
}
|
||||||
@ -615,7 +620,7 @@ pub const Decl = struct {
|
|||||||
pub fn getAlignment(decl: Decl, zcu: *Zcu) Alignment {
|
pub fn getAlignment(decl: Decl, zcu: *Zcu) Alignment {
|
||||||
assert(decl.has_tv);
|
assert(decl.has_tv);
|
||||||
if (decl.alignment != .none) return decl.alignment;
|
if (decl.alignment != .none) return decl.alignment;
|
||||||
return decl.ty.abiAlignment(zcu);
|
return decl.typeOf(zcu).abiAlignment(zcu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Upgrade a `LazySrcLoc` to a `SrcLoc` based on the `Decl` provided.
|
/// Upgrade a `LazySrcLoc` to a `SrcLoc` based on the `Decl` provided.
|
||||||
@ -3525,7 +3530,6 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {
|
|||||||
new_decl.src_line = 0;
|
new_decl.src_line = 0;
|
||||||
new_decl.is_pub = true;
|
new_decl.is_pub = true;
|
||||||
new_decl.is_exported = false;
|
new_decl.is_exported = false;
|
||||||
new_decl.ty = Type.type;
|
|
||||||
new_decl.alignment = .none;
|
new_decl.alignment = .none;
|
||||||
new_decl.@"linksection" = .none;
|
new_decl.@"linksection" = .none;
|
||||||
new_decl.alive = true; // This Decl corresponds to a File and is therefore always alive.
|
new_decl.alive = true; // This Decl corresponds to a File and is therefore always alive.
|
||||||
@ -3594,7 +3598,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
|
|||||||
|
|
||||||
const old_has_tv = decl.has_tv;
|
const old_has_tv = decl.has_tv;
|
||||||
// The following values are ignored if `!old_has_tv`
|
// The following values are ignored if `!old_has_tv`
|
||||||
const old_ty = decl.ty;
|
const old_ty = decl.typeOf(mod);
|
||||||
const old_val = decl.val;
|
const old_val = decl.val;
|
||||||
const old_align = decl.alignment;
|
const old_align = decl.alignment;
|
||||||
const old_linksection = decl.@"linksection";
|
const old_linksection = decl.@"linksection";
|
||||||
@ -3716,7 +3720,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
|
|||||||
return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});
|
return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});
|
||||||
}
|
}
|
||||||
|
|
||||||
decl.ty = Type.fromInterned(InternPool.Index.type_type);
|
|
||||||
decl.val = ty.toValue();
|
decl.val = ty.toValue();
|
||||||
decl.alignment = .none;
|
decl.alignment = .none;
|
||||||
decl.@"linksection" = .none;
|
decl.@"linksection" = .none;
|
||||||
@ -3760,7 +3763,6 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
decl.ty = decl_tv.ty;
|
|
||||||
decl.val = Value.fromInterned((try decl_tv.val.intern(decl_tv.ty, mod)));
|
decl.val = Value.fromInterned((try decl_tv.val.intern(decl_tv.ty, mod)));
|
||||||
// Function linksection, align, and addrspace were already set by Sema
|
// Function linksection, align, and addrspace were already set by Sema
|
||||||
if (!is_func) {
|
if (!is_func) {
|
||||||
@ -3806,10 +3808,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
|
|||||||
decl.analysis = .complete;
|
decl.analysis = .complete;
|
||||||
|
|
||||||
const result: SemaDeclResult = if (old_has_tv) .{
|
const result: SemaDeclResult = if (old_has_tv) .{
|
||||||
.invalidate_decl_val = !decl.ty.eql(old_ty, mod) or
|
.invalidate_decl_val = !decl_tv.ty.eql(old_ty, mod) or
|
||||||
!decl.val.eql(old_val, decl.ty, mod) or
|
!decl.val.eql(old_val, decl_tv.ty, mod) or
|
||||||
is_inline != old_is_inline,
|
is_inline != old_is_inline,
|
||||||
.invalidate_decl_ref = !decl.ty.eql(old_ty, mod) or
|
.invalidate_decl_ref = !decl_tv.ty.eql(old_ty, mod) or
|
||||||
decl.alignment != old_align or
|
decl.alignment != old_align or
|
||||||
decl.@"linksection" != old_linksection or
|
decl.@"linksection" != old_linksection or
|
||||||
decl.@"addrspace" != old_addrspace or
|
decl.@"addrspace" != old_addrspace or
|
||||||
@ -3819,11 +3821,11 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
|
|||||||
.invalidate_decl_ref = true,
|
.invalidate_decl_ref = true,
|
||||||
};
|
};
|
||||||
|
|
||||||
const has_runtime_bits = queue_linker_work and (is_func or try sema.typeHasRuntimeBits(decl.ty));
|
const has_runtime_bits = queue_linker_work and (is_func or try sema.typeHasRuntimeBits(decl_tv.ty));
|
||||||
if (has_runtime_bits) {
|
if (has_runtime_bits) {
|
||||||
// Needed for codegen_decl which will call updateDecl and then the
|
// Needed for codegen_decl which will call updateDecl and then the
|
||||||
// codegen backend wants full access to the Decl Type.
|
// codegen backend wants full access to the Decl Type.
|
||||||
try sema.resolveTypeFully(decl.ty);
|
try sema.resolveTypeFully(decl_tv.ty);
|
||||||
|
|
||||||
try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });
|
try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });
|
||||||
|
|
||||||
@ -3850,7 +3852,7 @@ fn semaAnonOwnerDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult {
|
|||||||
|
|
||||||
log.debug("semaAnonOwnerDecl '{d}'", .{@intFromEnum(decl_index)});
|
log.debug("semaAnonOwnerDecl '{d}'", .{@intFromEnum(decl_index)});
|
||||||
|
|
||||||
switch (decl.ty.zigTypeTag(zcu)) {
|
switch (decl.typeOf(zcu).zigTypeTag(zcu)) {
|
||||||
.Fn => @panic("TODO: update fn instance"),
|
.Fn => @panic("TODO: update fn instance"),
|
||||||
.Type => {},
|
.Type => {},
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
@ -4479,7 +4481,7 @@ pub fn finalizeAnonDecl(mod: *Module, decl_index: Decl.Index) Allocator.Error!vo
|
|||||||
// if the Decl is referenced by an instruction or another constant. Otherwise,
|
// if the Decl is referenced by an instruction or another constant. Otherwise,
|
||||||
// the Decl will be garbage collected by the `codegen_decl` task instead of sent
|
// the Decl will be garbage collected by the `codegen_decl` task instead of sent
|
||||||
// to the linker.
|
// to the linker.
|
||||||
if (mod.declPtr(decl_index).ty.isFnOrHasRuntimeBits(mod)) {
|
if (mod.declPtr(decl_index).typeOf(mod).isFnOrHasRuntimeBits(mod)) {
|
||||||
try mod.comp.anon_work_queue.writeItem(.{ .codegen_decl = decl_index });
|
try mod.comp.anon_work_queue.writeItem(.{ .codegen_decl = decl_index });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4563,7 +4565,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
|
|||||||
// the runtime-known parameters only, not to be confused with the
|
// the runtime-known parameters only, not to be confused with the
|
||||||
// generic_owner function type, which potentially has more parameters,
|
// generic_owner function type, which potentially has more parameters,
|
||||||
// including comptime parameters.
|
// including comptime parameters.
|
||||||
const fn_ty = decl.ty;
|
const fn_ty = decl.typeOf(mod);
|
||||||
const fn_ty_info = mod.typeToFunc(fn_ty).?;
|
const fn_ty_info = mod.typeToFunc(fn_ty).?;
|
||||||
|
|
||||||
var sema: Sema = .{
|
var sema: Sema = .{
|
||||||
@ -4812,7 +4814,6 @@ pub fn allocateNewDecl(
|
|||||||
.src_line = undefined,
|
.src_line = undefined,
|
||||||
.has_tv = false,
|
.has_tv = false,
|
||||||
.owns_tv = false,
|
.owns_tv = false,
|
||||||
.ty = undefined,
|
|
||||||
.val = undefined,
|
.val = undefined,
|
||||||
.alignment = undefined,
|
.alignment = undefined,
|
||||||
.@"linksection" = .none,
|
.@"linksection" = .none,
|
||||||
@ -4889,7 +4890,6 @@ pub fn initNewAnonDecl(
|
|||||||
|
|
||||||
new_decl.name = name;
|
new_decl.name = name;
|
||||||
new_decl.src_line = src_line;
|
new_decl.src_line = src_line;
|
||||||
new_decl.ty = typed_value.ty;
|
|
||||||
new_decl.val = typed_value.val;
|
new_decl.val = typed_value.val;
|
||||||
new_decl.alignment = .none;
|
new_decl.alignment = .none;
|
||||||
new_decl.@"linksection" = .none;
|
new_decl.@"linksection" = .none;
|
||||||
@ -5419,7 +5419,7 @@ pub fn populateTestFunctions(
|
|||||||
try mod.ensureDeclAnalyzed(decl_index);
|
try mod.ensureDeclAnalyzed(decl_index);
|
||||||
}
|
}
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
const test_fn_ty = decl.ty.slicePtrFieldType(mod).childType(mod);
|
const test_fn_ty = decl.typeOf(mod).slicePtrFieldType(mod).childType(mod);
|
||||||
|
|
||||||
const array_decl_index = d: {
|
const array_decl_index = d: {
|
||||||
// Add mod.test_functions to an array decl then make the test_functions
|
// Add mod.test_functions to an array decl then make the test_functions
|
||||||
@ -5463,7 +5463,7 @@ pub fn populateTestFunctions(
|
|||||||
// func
|
// func
|
||||||
try mod.intern(.{ .ptr = .{
|
try mod.intern(.{ .ptr = .{
|
||||||
.ty = try mod.intern(.{ .ptr_type = .{
|
.ty = try mod.intern(.{ .ptr_type = .{
|
||||||
.child = test_decl.ty.toIntern(),
|
.child = test_decl.typeOf(mod).toIntern(),
|
||||||
.flags = .{
|
.flags = .{
|
||||||
.is_const = true,
|
.is_const = true,
|
||||||
},
|
},
|
||||||
@ -5515,7 +5515,6 @@ pub fn populateTestFunctions(
|
|||||||
|
|
||||||
// Since we are replacing the Decl's value we must perform cleanup on the
|
// Since we are replacing the Decl's value we must perform cleanup on the
|
||||||
// previous value.
|
// previous value.
|
||||||
decl.ty = new_ty;
|
|
||||||
decl.val = new_val;
|
decl.val = new_val;
|
||||||
decl.has_tv = true;
|
decl.has_tv = true;
|
||||||
}
|
}
|
||||||
|
|||||||
33
src/Sema.zig
33
src/Sema.zig
@ -6425,16 +6425,17 @@ pub fn analyzeExport(
|
|||||||
|
|
||||||
try mod.ensureDeclAnalyzed(exported_decl_index);
|
try mod.ensureDeclAnalyzed(exported_decl_index);
|
||||||
const exported_decl = mod.declPtr(exported_decl_index);
|
const exported_decl = mod.declPtr(exported_decl_index);
|
||||||
|
const export_ty = exported_decl.typeOf(mod);
|
||||||
|
|
||||||
if (!try sema.validateExternType(exported_decl.ty, .other)) {
|
if (!try sema.validateExternType(export_ty, .other)) {
|
||||||
const msg = msg: {
|
const msg = msg: {
|
||||||
const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{exported_decl.ty.fmt(mod)});
|
const msg = try sema.errMsg(block, src, "unable to export type '{}'", .{export_ty.fmt(mod)});
|
||||||
errdefer msg.destroy(gpa);
|
errdefer msg.destroy(gpa);
|
||||||
|
|
||||||
const src_decl = mod.declPtr(block.src_decl);
|
const src_decl = mod.declPtr(block.src_decl);
|
||||||
try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), exported_decl.ty, .other);
|
try sema.explainWhyTypeIsNotExtern(msg, src_decl.toSrcLoc(src, mod), export_ty, .other);
|
||||||
|
|
||||||
try sema.addDeclaredHereNote(msg, exported_decl.ty);
|
try sema.addDeclaredHereNote(msg, export_ty);
|
||||||
break :msg msg;
|
break :msg msg;
|
||||||
};
|
};
|
||||||
return sema.failWithOwnedErrorMsg(block, msg);
|
return sema.failWithOwnedErrorMsg(block, msg);
|
||||||
@ -6503,7 +6504,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
|
|||||||
}
|
}
|
||||||
|
|
||||||
const fn_owner_decl = mod.funcOwnerDeclPtr(sema.func_index);
|
const fn_owner_decl = mod.funcOwnerDeclPtr(sema.func_index);
|
||||||
switch (fn_owner_decl.ty.fnCallingConvention(mod)) {
|
switch (fn_owner_decl.typeOf(mod).fnCallingConvention(mod)) {
|
||||||
.Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}),
|
.Naked => return sema.fail(block, src, "@setAlignStack in naked function", .{}),
|
||||||
.Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}),
|
.Inline => return sema.fail(block, src, "@setAlignStack in inline function", .{}),
|
||||||
else => if (block.inlining != null) {
|
else => if (block.inlining != null) {
|
||||||
@ -7692,7 +7693,7 @@ fn analyzeCall(
|
|||||||
// comptime memory is mutated.
|
// comptime memory is mutated.
|
||||||
const memoized_arg_values = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len);
|
const memoized_arg_values = try sema.arena.alloc(InternPool.Index, func_ty_info.param_types.len);
|
||||||
|
|
||||||
const owner_info = mod.typeToFunc(fn_owner_decl.ty).?;
|
const owner_info = mod.typeToFunc(fn_owner_decl.typeOf(mod)).?;
|
||||||
const new_param_types = try sema.arena.alloc(InternPool.Index, owner_info.param_types.len);
|
const new_param_types = try sema.arena.alloc(InternPool.Index, owner_info.param_types.len);
|
||||||
var new_fn_info: InternPool.GetFuncTypeKey = .{
|
var new_fn_info: InternPool.GetFuncTypeKey = .{
|
||||||
.param_types = new_param_types,
|
.param_types = new_param_types,
|
||||||
@ -7960,9 +7961,9 @@ fn handleTailCall(sema: *Sema, block: *Block, call_src: LazySrcLoc, func_ty: Typ
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const func_decl = mod.funcOwnerDeclPtr(sema.owner_func_index);
|
const func_decl = mod.funcOwnerDeclPtr(sema.owner_func_index);
|
||||||
if (!func_ty.eql(func_decl.ty, mod)) {
|
if (!func_ty.eql(func_decl.typeOf(mod), mod)) {
|
||||||
return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{
|
return sema.fail(block, call_src, "unable to perform tail call: type of function being called '{}' does not match type of calling function '{}'", .{
|
||||||
func_ty.fmt(mod), func_decl.ty.fmt(mod),
|
func_ty.fmt(mod), func_decl.typeOf(mod).fmt(mod),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ = try block.addUnOp(.ret, result);
|
_ = try block.addUnOp(.ret, result);
|
||||||
@ -26641,7 +26642,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block) !void {
|
|||||||
// decl_index may be an alias; we must find the decl that actually
|
// decl_index may be an alias; we must find the decl that actually
|
||||||
// owns the function.
|
// owns the function.
|
||||||
try sema.ensureDeclAnalyzed(decl_index);
|
try sema.ensureDeclAnalyzed(decl_index);
|
||||||
const tv = try mod.declPtr(decl_index).typedValue();
|
const tv = try mod.declPtr(decl_index).typedValue(mod);
|
||||||
try sema.declareDependency(.{ .decl_val = decl_index });
|
try sema.declareDependency(.{ .decl_val = decl_index });
|
||||||
assert(tv.ty.zigTypeTag(mod) == .Fn);
|
assert(tv.ty.zigTypeTag(mod) == .Fn);
|
||||||
assert(try sema.fnHasRuntimeBits(tv.ty));
|
assert(try sema.fnHasRuntimeBits(tv.ty));
|
||||||
@ -31374,16 +31375,16 @@ fn beginComptimePtrLoad(
|
|||||||
.ptr => |ptr| switch (ptr.addr) {
|
.ptr => |ptr| switch (ptr.addr) {
|
||||||
.decl => |decl_index| blk: {
|
.decl => |decl_index| blk: {
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
const decl_tv = try decl.typedValue();
|
const decl_tv = try decl.typedValue(mod);
|
||||||
try sema.declareDependency(.{ .decl_val = decl_index });
|
try sema.declareDependency(.{ .decl_val = decl_index });
|
||||||
if (decl.val.getVariable(mod) != null) return error.RuntimeLoad;
|
if (decl.val.getVariable(mod) != null) return error.RuntimeLoad;
|
||||||
|
|
||||||
const layout_defined = decl.ty.hasWellDefinedLayout(mod);
|
const layout_defined = decl.typeOf(mod).hasWellDefinedLayout(mod);
|
||||||
break :blk ComptimePtrLoadKit{
|
break :blk ComptimePtrLoadKit{
|
||||||
.parent = if (layout_defined) .{ .tv = decl_tv, .byte_offset = 0 } else null,
|
.parent = if (layout_defined) .{ .tv = decl_tv, .byte_offset = 0 } else null,
|
||||||
.pointee = decl_tv,
|
.pointee = decl_tv,
|
||||||
.is_mutable = false,
|
.is_mutable = false,
|
||||||
.ty_without_well_defined_layout = if (!layout_defined) decl.ty else null,
|
.ty_without_well_defined_layout = if (!layout_defined) decl.typeOf(mod) else null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
.comptime_alloc => |alloc_index| kit: {
|
.comptime_alloc => |alloc_index| kit: {
|
||||||
@ -32668,7 +32669,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn
|
|||||||
const mod = sema.mod;
|
const mod = sema.mod;
|
||||||
try sema.ensureDeclAnalyzed(decl_index);
|
try sema.ensureDeclAnalyzed(decl_index);
|
||||||
|
|
||||||
const decl_tv = try mod.declPtr(decl_index).typedValue();
|
const decl_tv = try mod.declPtr(decl_index).typedValue(mod);
|
||||||
const owner_decl = mod.declPtr(switch (mod.intern_pool.indexToKey(decl_tv.val.toIntern())) {
|
const owner_decl = mod.declPtr(switch (mod.intern_pool.indexToKey(decl_tv.val.toIntern())) {
|
||||||
.variable => |variable| variable.decl,
|
.variable => |variable| variable.decl,
|
||||||
.extern_func => |extern_func| extern_func.decl,
|
.extern_func => |extern_func| extern_func.decl,
|
||||||
@ -32697,7 +32698,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: InternPool.DeclIndex, analyze_fn
|
|||||||
fn maybeQueueFuncBodyAnalysis(sema: *Sema, decl_index: InternPool.DeclIndex) !void {
|
fn maybeQueueFuncBodyAnalysis(sema: *Sema, decl_index: InternPool.DeclIndex) !void {
|
||||||
const mod = sema.mod;
|
const mod = sema.mod;
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
const tv = try decl.typedValue();
|
const tv = try decl.typedValue(mod);
|
||||||
if (tv.ty.zigTypeTag(mod) != .Fn) return;
|
if (tv.ty.zigTypeTag(mod) != .Fn) return;
|
||||||
if (!try sema.fnHasRuntimeBits(tv.ty)) return;
|
if (!try sema.fnHasRuntimeBits(tv.ty)) return;
|
||||||
const func_index = tv.val.toIntern();
|
const func_index = tv.val.toIntern();
|
||||||
@ -36611,7 +36612,7 @@ fn resolveInferredErrorSet(
|
|||||||
// inferred error sets, each call gets an adhoc InferredErrorSet object, which
|
// inferred error sets, each call gets an adhoc InferredErrorSet object, which
|
||||||
// has no corresponding function body.
|
// has no corresponding function body.
|
||||||
const ies_func_owner_decl = mod.declPtr(func.owner_decl);
|
const ies_func_owner_decl = mod.declPtr(func.owner_decl);
|
||||||
const ies_func_info = mod.typeToFunc(ies_func_owner_decl.ty).?;
|
const ies_func_info = mod.typeToFunc(ies_func_owner_decl.typeOf(mod)).?;
|
||||||
// if ies declared by a inline function with generic return type, the return_type should be generic_poison,
|
// if ies declared by a inline function with generic return type, the return_type should be generic_poison,
|
||||||
// because inline function does not create a new declaration, and the ies has been filled with analyzeCall,
|
// because inline function does not create a new declaration, and the ies has been filled with analyzeCall,
|
||||||
// so here we can simply skip this case.
|
// so here we can simply skip this case.
|
||||||
@ -37629,7 +37630,6 @@ fn generateUnionTagTypeNumbered(
|
|||||||
.tag_mode = .explicit,
|
.tag_mode = .explicit,
|
||||||
});
|
});
|
||||||
|
|
||||||
new_decl.ty = Type.type;
|
|
||||||
new_decl.val = Value.fromInterned(enum_ty);
|
new_decl.val = Value.fromInterned(enum_ty);
|
||||||
|
|
||||||
try mod.finalizeAnonDecl(new_decl_index);
|
try mod.finalizeAnonDecl(new_decl_index);
|
||||||
@ -37675,7 +37675,6 @@ fn generateUnionTagTypeSimple(
|
|||||||
|
|
||||||
const new_decl = mod.declPtr(new_decl_index);
|
const new_decl = mod.declPtr(new_decl_index);
|
||||||
new_decl.owns_tv = true;
|
new_decl.owns_tv = true;
|
||||||
new_decl.ty = Type.type;
|
|
||||||
new_decl.val = Value.fromInterned(enum_ty);
|
new_decl.val = Value.fromInterned(enum_ty);
|
||||||
|
|
||||||
try mod.finalizeAnonDecl(new_decl_index);
|
try mod.finalizeAnonDecl(new_decl_index);
|
||||||
|
|||||||
@ -315,7 +315,7 @@ pub fn print(
|
|||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
if (level == 0) return writer.print("(decl '{}')", .{decl.name.fmt(ip)});
|
if (level == 0) return writer.print("(decl '{}')", .{decl.name.fmt(ip)});
|
||||||
return print(.{
|
return print(.{
|
||||||
.ty = decl.ty,
|
.ty = decl.typeOf(mod),
|
||||||
.val = decl.val,
|
.val = decl.val,
|
||||||
}, writer, level - 1, mod);
|
}, writer, level - 1, mod);
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1585,7 +1585,7 @@ pub fn sliceLen(val: Value, mod: *Module) u64 {
|
|||||||
const ip = &mod.intern_pool;
|
const ip = &mod.intern_pool;
|
||||||
return switch (ip.indexToKey(val.toIntern())) {
|
return switch (ip.indexToKey(val.toIntern())) {
|
||||||
.ptr => |ptr| switch (ip.indexToKey(switch (ptr.addr) {
|
.ptr => |ptr| switch (ip.indexToKey(switch (ptr.addr) {
|
||||||
.decl => |decl| mod.declPtr(decl).ty.toIntern(),
|
.decl => |decl| mod.declPtr(decl).typeOf(mod).toIntern(),
|
||||||
.comptime_alloc => @panic("TODO"),
|
.comptime_alloc => @panic("TODO"),
|
||||||
.anon_decl => |anon_decl| ip.typeOf(anon_decl.val),
|
.anon_decl => |anon_decl| ip.typeOf(anon_decl.val),
|
||||||
.comptime_field => |comptime_field| ip.typeOf(comptime_field),
|
.comptime_field => |comptime_field| ip.typeOf(comptime_field),
|
||||||
|
|||||||
@ -342,7 +342,7 @@ pub fn generate(
|
|||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const fn_owner_decl = zcu.declPtr(func.owner_decl);
|
const fn_owner_decl = zcu.declPtr(func.owner_decl);
|
||||||
assert(fn_owner_decl.has_tv);
|
assert(fn_owner_decl.has_tv);
|
||||||
const fn_type = fn_owner_decl.ty;
|
const fn_type = fn_owner_decl.typeOf(zcu);
|
||||||
const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
|
const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
|
||||||
const target = &namespace.file_scope.mod.resolved_target.result;
|
const target = &namespace.file_scope.mod.resolved_target.result;
|
||||||
|
|
||||||
|
|||||||
@ -349,7 +349,7 @@ pub fn generate(
|
|||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const fn_owner_decl = zcu.declPtr(func.owner_decl);
|
const fn_owner_decl = zcu.declPtr(func.owner_decl);
|
||||||
assert(fn_owner_decl.has_tv);
|
assert(fn_owner_decl.has_tv);
|
||||||
const fn_type = fn_owner_decl.ty;
|
const fn_type = fn_owner_decl.typeOf(zcu);
|
||||||
const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
|
const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
|
||||||
const target = &namespace.file_scope.mod.resolved_target.result;
|
const target = &namespace.file_scope.mod.resolved_target.result;
|
||||||
|
|
||||||
|
|||||||
@ -230,7 +230,7 @@ pub fn generate(
|
|||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const fn_owner_decl = zcu.declPtr(func.owner_decl);
|
const fn_owner_decl = zcu.declPtr(func.owner_decl);
|
||||||
assert(fn_owner_decl.has_tv);
|
assert(fn_owner_decl.has_tv);
|
||||||
const fn_type = fn_owner_decl.ty;
|
const fn_type = fn_owner_decl.typeOf(zcu);
|
||||||
const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
|
const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
|
||||||
const target = &namespace.file_scope.mod.resolved_target.result;
|
const target = &namespace.file_scope.mod.resolved_target.result;
|
||||||
|
|
||||||
|
|||||||
@ -273,7 +273,7 @@ pub fn generate(
|
|||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const fn_owner_decl = zcu.declPtr(func.owner_decl);
|
const fn_owner_decl = zcu.declPtr(func.owner_decl);
|
||||||
assert(fn_owner_decl.has_tv);
|
assert(fn_owner_decl.has_tv);
|
||||||
const fn_type = fn_owner_decl.ty;
|
const fn_type = fn_owner_decl.typeOf(zcu);
|
||||||
const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
|
const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
|
||||||
const target = &namespace.file_scope.mod.resolved_target.result;
|
const target = &namespace.file_scope.mod.resolved_target.result;
|
||||||
|
|
||||||
|
|||||||
@ -1243,12 +1243,12 @@ pub fn generate(
|
|||||||
fn genFunc(func: *CodeGen) InnerError!void {
|
fn genFunc(func: *CodeGen) InnerError!void {
|
||||||
const mod = func.bin_file.base.comp.module.?;
|
const mod = func.bin_file.base.comp.module.?;
|
||||||
const ip = &mod.intern_pool;
|
const ip = &mod.intern_pool;
|
||||||
const fn_info = mod.typeToFunc(func.decl.ty).?;
|
const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?;
|
||||||
var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types.get(ip), Type.fromInterned(fn_info.return_type), mod);
|
var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types.get(ip), Type.fromInterned(fn_info.return_type), mod);
|
||||||
defer func_type.deinit(func.gpa);
|
defer func_type.deinit(func.gpa);
|
||||||
_ = try func.bin_file.storeDeclType(func.decl_index, func_type);
|
_ = try func.bin_file.storeDeclType(func.decl_index, func_type);
|
||||||
|
|
||||||
var cc_result = try func.resolveCallingConventionValues(func.decl.ty);
|
var cc_result = try func.resolveCallingConventionValues(func.decl.typeOf(mod));
|
||||||
defer cc_result.deinit(func.gpa);
|
defer cc_result.deinit(func.gpa);
|
||||||
|
|
||||||
func.args = cc_result.args;
|
func.args = cc_result.args;
|
||||||
@ -2087,7 +2087,7 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
|
|||||||
const mod = func.bin_file.base.comp.module.?;
|
const mod = func.bin_file.base.comp.module.?;
|
||||||
const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
|
const un_op = func.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
|
||||||
const operand = try func.resolveInst(un_op);
|
const operand = try func.resolveInst(un_op);
|
||||||
const fn_info = mod.typeToFunc(func.decl.ty).?;
|
const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?;
|
||||||
const ret_ty = Type.fromInterned(fn_info.return_type);
|
const ret_ty = Type.fromInterned(fn_info.return_type);
|
||||||
|
|
||||||
// result must be stored in the stack and we return a pointer
|
// result must be stored in the stack and we return a pointer
|
||||||
@ -2135,7 +2135,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
|
|||||||
break :result try func.allocStack(Type.usize); // create pointer to void
|
break :result try func.allocStack(Type.usize); // create pointer to void
|
||||||
}
|
}
|
||||||
|
|
||||||
const fn_info = mod.typeToFunc(func.decl.ty).?;
|
const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?;
|
||||||
if (firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), mod)) {
|
if (firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), mod)) {
|
||||||
break :result func.return_value;
|
break :result func.return_value;
|
||||||
}
|
}
|
||||||
@ -2152,7 +2152,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
|
|||||||
const operand = try func.resolveInst(un_op);
|
const operand = try func.resolveInst(un_op);
|
||||||
const ret_ty = func.typeOf(un_op).childType(mod);
|
const ret_ty = func.typeOf(un_op).childType(mod);
|
||||||
|
|
||||||
const fn_info = mod.typeToFunc(func.decl.ty).?;
|
const fn_info = mod.typeToFunc(func.decl.typeOf(mod)).?;
|
||||||
if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
||||||
if (ret_ty.isError(mod)) {
|
if (ret_ty.isError(mod)) {
|
||||||
try func.addImm32(0);
|
try func.addImm32(0);
|
||||||
@ -2193,7 +2193,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
|
|||||||
break :blk function.owner_decl;
|
break :blk function.owner_decl;
|
||||||
} else if (func_val.getExternFunc(mod)) |extern_func| {
|
} else if (func_val.getExternFunc(mod)) |extern_func| {
|
||||||
const ext_decl = mod.declPtr(extern_func.decl);
|
const ext_decl = mod.declPtr(extern_func.decl);
|
||||||
const ext_info = mod.typeToFunc(ext_decl.ty).?;
|
const ext_info = mod.typeToFunc(ext_decl.typeOf(mod)).?;
|
||||||
var func_type = try genFunctype(func.gpa, ext_info.cc, ext_info.param_types.get(ip), Type.fromInterned(ext_info.return_type), mod);
|
var func_type = try genFunctype(func.gpa, ext_info.cc, ext_info.param_types.get(ip), Type.fromInterned(ext_info.return_type), mod);
|
||||||
defer func_type.deinit(func.gpa);
|
defer func_type.deinit(func.gpa);
|
||||||
const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_func.decl);
|
const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_func.decl);
|
||||||
@ -2530,7 +2530,7 @@ fn airArg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
|
|||||||
const mod = func.bin_file.base.comp.module.?;
|
const mod = func.bin_file.base.comp.module.?;
|
||||||
const arg_index = func.arg_index;
|
const arg_index = func.arg_index;
|
||||||
const arg = func.args[arg_index];
|
const arg = func.args[arg_index];
|
||||||
const cc = mod.typeToFunc(func.decl.ty).?.cc;
|
const cc = mod.typeToFunc(func.decl.typeOf(mod)).?.cc;
|
||||||
const arg_ty = func.typeOfIndex(inst);
|
const arg_ty = func.typeOfIndex(inst);
|
||||||
if (cc == .C) {
|
if (cc == .C) {
|
||||||
const arg_classes = abi.classifyType(arg_ty, mod);
|
const arg_classes = abi.classifyType(arg_ty, mod);
|
||||||
@ -3122,7 +3122,7 @@ fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: InternPool.Dec
|
|||||||
const mod = func.bin_file.base.comp.module.?;
|
const mod = func.bin_file.base.comp.module.?;
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
try mod.markDeclAlive(decl);
|
try mod.markDeclAlive(decl);
|
||||||
const ptr_ty = try mod.singleMutPtrType(decl.ty);
|
const ptr_ty = try mod.singleMutPtrType(decl.typeOf(mod));
|
||||||
return func.lowerDeclRefValue(.{ .ty = ptr_ty, .val = ptr_val }, decl_index, offset);
|
return func.lowerDeclRefValue(.{ .ty = ptr_ty, .val = ptr_val }, decl_index, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3173,7 +3173,8 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: InternPool.Decl
|
|||||||
return func.lowerDeclRefValue(tv, func_val.decl, offset);
|
return func.lowerDeclRefValue(tv, func_val.decl, offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (decl.ty.zigTypeTag(mod) != .Fn and !decl.ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
const decl_ty = decl.typeOf(mod);
|
||||||
|
if (decl_ty.zigTypeTag(mod) != .Fn and !decl_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
||||||
return WValue{ .imm32 = 0xaaaaaaaa };
|
return WValue{ .imm32 = 0xaaaaaaaa };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3182,7 +3183,7 @@ fn lowerDeclRefValue(func: *CodeGen, tv: TypedValue, decl_index: InternPool.Decl
|
|||||||
const atom = func.bin_file.getAtom(atom_index);
|
const atom = func.bin_file.getAtom(atom_index);
|
||||||
|
|
||||||
const target_sym_index = @intFromEnum(atom.sym_index);
|
const target_sym_index = @intFromEnum(atom.sym_index);
|
||||||
if (decl.ty.zigTypeTag(mod) == .Fn) {
|
if (decl_ty.zigTypeTag(mod) == .Fn) {
|
||||||
return WValue{ .function_index = target_sym_index };
|
return WValue{ .function_index = target_sym_index };
|
||||||
} else if (offset == 0) {
|
} else if (offset == 0) {
|
||||||
return WValue{ .memory = target_sym_index };
|
return WValue{ .memory = target_sym_index };
|
||||||
|
|||||||
@ -808,7 +808,7 @@ pub fn generate(
|
|||||||
const func = zcu.funcInfo(func_index);
|
const func = zcu.funcInfo(func_index);
|
||||||
const fn_owner_decl = zcu.declPtr(func.owner_decl);
|
const fn_owner_decl = zcu.declPtr(func.owner_decl);
|
||||||
assert(fn_owner_decl.has_tv);
|
assert(fn_owner_decl.has_tv);
|
||||||
const fn_type = fn_owner_decl.ty;
|
const fn_type = fn_owner_decl.typeOf(zcu);
|
||||||
const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
|
const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
|
||||||
const mod = namespace.file_scope.mod;
|
const mod = namespace.file_scope.mod;
|
||||||
|
|
||||||
|
|||||||
@ -829,8 +829,8 @@ fn lowerDeclRef(
|
|||||||
const target = namespace.file_scope.mod.resolved_target.result;
|
const target = namespace.file_scope.mod.resolved_target.result;
|
||||||
|
|
||||||
const ptr_width = target.ptrBitWidth();
|
const ptr_width = target.ptrBitWidth();
|
||||||
const is_fn_body = decl.ty.zigTypeTag(zcu) == .Fn;
|
const is_fn_body = decl.typeOf(zcu).zigTypeTag(zcu) == .Fn;
|
||||||
if (!is_fn_body and !decl.ty.hasRuntimeBits(zcu)) {
|
if (!is_fn_body and !decl.typeOf(zcu).hasRuntimeBits(zcu)) {
|
||||||
try code.appendNTimes(0xaa, @divExact(ptr_width, 8));
|
try code.appendNTimes(0xaa, @divExact(ptr_width, 8));
|
||||||
return Result.ok;
|
return Result.ok;
|
||||||
}
|
}
|
||||||
@ -932,7 +932,7 @@ fn genDeclRef(
|
|||||||
};
|
};
|
||||||
const decl = zcu.declPtr(decl_index);
|
const decl = zcu.declPtr(decl_index);
|
||||||
|
|
||||||
if (!decl.ty.isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
|
if (!decl.typeOf(zcu).isFnOrHasRuntimeBitsIgnoreComptime(zcu)) {
|
||||||
const imm: u64 = switch (ptr_bytes) {
|
const imm: u64 = switch (ptr_bytes) {
|
||||||
1 => 0xaa,
|
1 => 0xaa,
|
||||||
2 => 0xaaaa,
|
2 => 0xaaaa,
|
||||||
|
|||||||
@ -657,7 +657,7 @@ pub const DeclGen = struct {
|
|||||||
assert(decl.has_tv);
|
assert(decl.has_tv);
|
||||||
|
|
||||||
// Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
|
// Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
|
||||||
if (ty.isPtrAtRuntime(mod) and !decl.ty.isFnOrHasRuntimeBits(mod)) {
|
if (ty.isPtrAtRuntime(mod) and !decl.typeOf(mod).isFnOrHasRuntimeBits(mod)) {
|
||||||
return dg.writeCValue(writer, .{ .undef = ty });
|
return dg.writeCValue(writer, .{ .undef = ty });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,7 +673,7 @@ pub const DeclGen = struct {
|
|||||||
// them). The analysis until now should ensure that the C function
|
// them). The analysis until now should ensure that the C function
|
||||||
// pointers are compatible. If they are not, then there is a bug
|
// pointers are compatible. If they are not, then there is a bug
|
||||||
// somewhere and we should let the C compiler tell us about it.
|
// somewhere and we should let the C compiler tell us about it.
|
||||||
const need_typecast = if (ty.castPtrToFn(mod)) |_| false else !ty.childType(mod).eql(decl.ty, mod);
|
const need_typecast = if (ty.castPtrToFn(mod)) |_| false else !ty.childType(mod).eql(decl.typeOf(mod), mod);
|
||||||
if (need_typecast) {
|
if (need_typecast) {
|
||||||
try writer.writeAll("((");
|
try writer.writeAll("((");
|
||||||
try dg.renderType(writer, ty);
|
try dg.renderType(writer, ty);
|
||||||
@ -1588,9 +1588,10 @@ pub const DeclGen = struct {
|
|||||||
const ip = &mod.intern_pool;
|
const ip = &mod.intern_pool;
|
||||||
|
|
||||||
const fn_decl = mod.declPtr(fn_decl_index);
|
const fn_decl = mod.declPtr(fn_decl_index);
|
||||||
const fn_cty_idx = try dg.typeToIndex(fn_decl.ty, kind);
|
const fn_ty = fn_decl.typeOf(mod);
|
||||||
|
const fn_cty_idx = try dg.typeToIndex(fn_ty, kind);
|
||||||
|
|
||||||
const fn_info = mod.typeToFunc(fn_decl.ty).?;
|
const fn_info = mod.typeToFunc(fn_ty).?;
|
||||||
if (fn_info.cc == .Naked) {
|
if (fn_info.cc == .Naked) {
|
||||||
switch (kind) {
|
switch (kind) {
|
||||||
.forward => try w.writeAll("zig_naked_decl "),
|
.forward => try w.writeAll("zig_naked_decl "),
|
||||||
@ -1971,7 +1972,7 @@ pub const DeclGen = struct {
|
|||||||
) !void {
|
) !void {
|
||||||
const decl = dg.module.declPtr(decl_index);
|
const decl = dg.module.declPtr(decl_index);
|
||||||
const fwd = dg.fwdDeclWriter();
|
const fwd = dg.fwdDeclWriter();
|
||||||
const is_global = variable.is_extern or dg.declIsGlobal(.{ .ty = decl.ty, .val = decl.val });
|
const is_global = variable.is_extern or dg.declIsGlobal(.{ .ty = decl.typeOf(dg.module), .val = decl.val });
|
||||||
try fwd.writeAll(if (is_global) "zig_extern " else "static ");
|
try fwd.writeAll(if (is_global) "zig_extern " else "static ");
|
||||||
const maybe_exports = dg.module.decl_exports.get(decl_index);
|
const maybe_exports = dg.module.decl_exports.get(decl_index);
|
||||||
const export_weak_linkage = if (maybe_exports) |exports|
|
const export_weak_linkage = if (maybe_exports) |exports|
|
||||||
@ -1982,7 +1983,7 @@ pub const DeclGen = struct {
|
|||||||
if (variable.is_threadlocal) try fwd.writeAll("zig_threadlocal ");
|
if (variable.is_threadlocal) try fwd.writeAll("zig_threadlocal ");
|
||||||
try dg.renderTypeAndName(
|
try dg.renderTypeAndName(
|
||||||
fwd,
|
fwd,
|
||||||
decl.ty,
|
decl.typeOf(dg.module),
|
||||||
.{ .decl = decl_index },
|
.{ .decl = decl_index },
|
||||||
CQualifiers.init(.{ .@"const" = variable.is_const }),
|
CQualifiers.init(.{ .@"const" = variable.is_const }),
|
||||||
decl.alignment,
|
decl.alignment,
|
||||||
@ -2656,7 +2657,7 @@ fn genExports(o: *Object) !void {
|
|||||||
.anon, .flush => return,
|
.anon, .flush => return,
|
||||||
};
|
};
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
const tv: TypedValue = .{ .ty = decl.ty, .val = Value.fromInterned((try decl.internValue(mod))) };
|
const tv: TypedValue = .{ .ty = decl.typeOf(mod), .val = Value.fromInterned((try decl.internValue(mod))) };
|
||||||
const fwd = o.dg.fwdDeclWriter();
|
const fwd = o.dg.fwdDeclWriter();
|
||||||
|
|
||||||
const exports = mod.decl_exports.get(decl_index) orelse return;
|
const exports = mod.decl_exports.get(decl_index) orelse return;
|
||||||
@ -2687,7 +2688,7 @@ fn genExports(o: *Object) !void {
|
|||||||
const export_name = ip.stringToSlice(@"export".opts.name);
|
const export_name = ip.stringToSlice(@"export".opts.name);
|
||||||
try o.dg.renderTypeAndName(
|
try o.dg.renderTypeAndName(
|
||||||
fwd,
|
fwd,
|
||||||
decl.ty,
|
decl.typeOf(mod),
|
||||||
.{ .identifier = export_name },
|
.{ .identifier = export_name },
|
||||||
CQualifiers.init(.{ .@"const" = is_variable_const }),
|
CQualifiers.init(.{ .@"const" = is_variable_const }),
|
||||||
decl.alignment,
|
decl.alignment,
|
||||||
@ -2769,7 +2770,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
|
|||||||
},
|
},
|
||||||
.never_tail, .never_inline => |fn_decl_index| {
|
.never_tail, .never_inline => |fn_decl_index| {
|
||||||
const fn_decl = mod.declPtr(fn_decl_index);
|
const fn_decl = mod.declPtr(fn_decl_index);
|
||||||
const fn_cty = try o.dg.typeToCType(fn_decl.ty, .complete);
|
const fn_cty = try o.dg.typeToCType(fn_decl.typeOf(mod), .complete);
|
||||||
const fn_info = fn_cty.cast(CType.Payload.Function).?.data;
|
const fn_info = fn_cty.cast(CType.Payload.Function).?.data;
|
||||||
|
|
||||||
const fwd_decl_writer = o.dg.fwdDeclWriter();
|
const fwd_decl_writer = o.dg.fwdDeclWriter();
|
||||||
@ -2806,7 +2807,7 @@ pub fn genFunc(f: *Function) !void {
|
|||||||
const decl_index = o.dg.pass.decl;
|
const decl_index = o.dg.pass.decl;
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
const tv: TypedValue = .{
|
const tv: TypedValue = .{
|
||||||
.ty = decl.ty,
|
.ty = decl.typeOf(mod),
|
||||||
.val = decl.val,
|
.val = decl.val,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -2893,7 +2894,7 @@ pub fn genDecl(o: *Object) !void {
|
|||||||
const mod = o.dg.module;
|
const mod = o.dg.module;
|
||||||
const decl_index = o.dg.pass.decl;
|
const decl_index = o.dg.pass.decl;
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
const tv: TypedValue = .{ .ty = decl.ty, .val = Value.fromInterned((try decl.internValue(mod))) };
|
const tv: TypedValue = .{ .ty = decl.typeOf(mod), .val = Value.fromInterned((try decl.internValue(mod))) };
|
||||||
|
|
||||||
if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return;
|
if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return;
|
||||||
if (tv.val.getExternFunc(mod)) |_| {
|
if (tv.val.getExternFunc(mod)) |_| {
|
||||||
@ -2979,7 +2980,7 @@ pub fn genHeader(dg: *DeclGen) error{ AnalysisFail, OutOfMemory }!void {
|
|||||||
const decl_index = dg.pass.decl;
|
const decl_index = dg.pass.decl;
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
const tv: TypedValue = .{
|
const tv: TypedValue = .{
|
||||||
.ty = decl.ty,
|
.ty = decl.typeOf(mod),
|
||||||
.val = decl.val,
|
.val = decl.val,
|
||||||
};
|
};
|
||||||
const writer = dg.fwdDeclWriter();
|
const writer = dg.fwdDeclWriter();
|
||||||
@ -7392,7 +7393,7 @@ fn airCVaStart(f: *Function, inst: Air.Inst.Index) !CValue {
|
|||||||
const inst_ty = f.typeOfIndex(inst);
|
const inst_ty = f.typeOfIndex(inst);
|
||||||
const decl_index = f.object.dg.pass.decl;
|
const decl_index = f.object.dg.pass.decl;
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
const fn_cty = try f.typeToCType(decl.ty, .complete);
|
const fn_cty = try f.typeToCType(decl.typeOf(mod), .complete);
|
||||||
const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len;
|
const param_len = fn_cty.castTag(.varargs_function).?.data.param_types.len;
|
||||||
|
|
||||||
const writer = f.object.writer();
|
const writer = f.object.writer();
|
||||||
|
|||||||
@ -1384,7 +1384,7 @@ pub const Object = struct {
|
|||||||
const decl = zcu.declPtr(decl_index);
|
const decl = zcu.declPtr(decl_index);
|
||||||
const namespace = zcu.namespacePtr(decl.src_namespace);
|
const namespace = zcu.namespacePtr(decl.src_namespace);
|
||||||
const owner_mod = namespace.file_scope.mod;
|
const owner_mod = namespace.file_scope.mod;
|
||||||
const fn_info = zcu.typeToFunc(decl.ty).?;
|
const fn_info = zcu.typeToFunc(decl.typeOf(zcu)).?;
|
||||||
const target = zcu.getTarget();
|
const target = zcu.getTarget();
|
||||||
const ip = &zcu.intern_pool;
|
const ip = &zcu.intern_pool;
|
||||||
|
|
||||||
@ -1659,7 +1659,7 @@ pub const Object = struct {
|
|||||||
const line_number = decl.src_line + 1;
|
const line_number = decl.src_line + 1;
|
||||||
const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
|
const is_internal_linkage = decl.val.getExternFunc(zcu) == null and
|
||||||
!zcu.decl_exports.contains(decl_index);
|
!zcu.decl_exports.contains(decl_index);
|
||||||
const debug_decl_type = try o.lowerDebugType(decl.ty);
|
const debug_decl_type = try o.lowerDebugType(decl.typeOf(zcu));
|
||||||
|
|
||||||
const subprogram = try o.builder.debugSubprogram(
|
const subprogram = try o.builder.debugSubprogram(
|
||||||
file,
|
file,
|
||||||
@ -2881,7 +2881,7 @@ pub const Object = struct {
|
|||||||
const decl = zcu.declPtr(decl_index);
|
const decl = zcu.declPtr(decl_index);
|
||||||
const namespace = zcu.namespacePtr(decl.src_namespace);
|
const namespace = zcu.namespacePtr(decl.src_namespace);
|
||||||
const owner_mod = namespace.file_scope.mod;
|
const owner_mod = namespace.file_scope.mod;
|
||||||
const zig_fn_type = decl.ty;
|
const zig_fn_type = decl.typeOf(zcu);
|
||||||
const gop = try o.decl_map.getOrPut(gpa, decl_index);
|
const gop = try o.decl_map.getOrPut(gpa, decl_index);
|
||||||
if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;
|
if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;
|
||||||
|
|
||||||
@ -3112,7 +3112,7 @@ pub const Object = struct {
|
|||||||
try o.builder.strtabString(mod.intern_pool.stringToSlice(
|
try o.builder.strtabString(mod.intern_pool.stringToSlice(
|
||||||
if (is_extern) decl.name else try decl.fullyQualifiedName(mod),
|
if (is_extern) decl.name else try decl.fullyQualifiedName(mod),
|
||||||
)),
|
)),
|
||||||
try o.lowerType(decl.ty),
|
try o.lowerType(decl.typeOf(mod)),
|
||||||
toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()),
|
toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()),
|
||||||
);
|
);
|
||||||
gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
|
gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
|
||||||
@ -4263,7 +4263,7 @@ pub const Object = struct {
|
|||||||
const mod = o.module;
|
const mod = o.module;
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
try mod.markDeclAlive(decl);
|
try mod.markDeclAlive(decl);
|
||||||
const ptr_ty = try mod.singleMutPtrType(decl.ty);
|
const ptr_ty = try mod.singleMutPtrType(decl.typeOf(mod));
|
||||||
return o.lowerDeclRefValue(ptr_ty, decl_index);
|
return o.lowerDeclRefValue(ptr_ty, decl_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4450,9 +4450,10 @@ pub const Object = struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const is_fn_body = decl.ty.zigTypeTag(mod) == .Fn;
|
const decl_ty = decl.typeOf(mod);
|
||||||
if ((!is_fn_body and !decl.ty.hasRuntimeBits(mod)) or
|
const is_fn_body = decl_ty.zigTypeTag(mod) == .Fn;
|
||||||
(is_fn_body and mod.typeToFunc(decl.ty).?.is_generic)) return o.lowerPtrToVoid(ty);
|
if ((!is_fn_body and !decl_ty.hasRuntimeBits(mod)) or
|
||||||
|
(is_fn_body and mod.typeToFunc(decl_ty).?.is_generic)) return o.lowerPtrToVoid(ty);
|
||||||
|
|
||||||
try mod.markDeclAlive(decl);
|
try mod.markDeclAlive(decl);
|
||||||
|
|
||||||
@ -4740,7 +4741,7 @@ pub const DeclGen = struct {
|
|||||||
debug_file, // File
|
debug_file, // File
|
||||||
debug_file, // Scope
|
debug_file, // Scope
|
||||||
line_number,
|
line_number,
|
||||||
try o.lowerDebugType(decl.ty),
|
try o.lowerDebugType(decl.typeOf(zcu)),
|
||||||
variable_index,
|
variable_index,
|
||||||
.{ .local = is_internal_linkage },
|
.{ .local = is_internal_linkage },
|
||||||
);
|
);
|
||||||
@ -5530,7 +5531,7 @@ pub const FuncGen = struct {
|
|||||||
const mod = o.module;
|
const mod = o.module;
|
||||||
const msg_decl_index = mod.panic_messages[@intFromEnum(panic_id)].unwrap().?;
|
const msg_decl_index = mod.panic_messages[@intFromEnum(panic_id)].unwrap().?;
|
||||||
const msg_decl = mod.declPtr(msg_decl_index);
|
const msg_decl = mod.declPtr(msg_decl_index);
|
||||||
const msg_len = msg_decl.ty.childType(mod).arrayLen(mod);
|
const msg_len = msg_decl.typeOf(mod).childType(mod).arrayLen(mod);
|
||||||
const msg_ptr = try o.lowerValue(try msg_decl.internValue(mod));
|
const msg_ptr = try o.lowerValue(try msg_decl.internValue(mod));
|
||||||
const null_opt_addr_global = try fg.resolveNullOptUsize();
|
const null_opt_addr_global = try fg.resolveNullOptUsize();
|
||||||
const target = mod.getTarget();
|
const target = mod.getTarget();
|
||||||
@ -5544,7 +5545,7 @@ pub const FuncGen = struct {
|
|||||||
// )
|
// )
|
||||||
const panic_func = mod.funcInfo(mod.panic_func_index);
|
const panic_func = mod.funcInfo(mod.panic_func_index);
|
||||||
const panic_decl = mod.declPtr(panic_func.owner_decl);
|
const panic_decl = mod.declPtr(panic_func.owner_decl);
|
||||||
const fn_info = mod.typeToFunc(panic_decl.ty).?;
|
const fn_info = mod.typeToFunc(panic_decl.typeOf(mod)).?;
|
||||||
const panic_global = try o.resolveLlvmFunction(panic_func.owner_decl);
|
const panic_global = try o.resolveLlvmFunction(panic_func.owner_decl);
|
||||||
_ = try fg.wip.call(
|
_ = try fg.wip.call(
|
||||||
.normal,
|
.normal,
|
||||||
@ -5612,7 +5613,7 @@ pub const FuncGen = struct {
|
|||||||
_ = try self.wip.retVoid();
|
_ = try self.wip.retVoid();
|
||||||
return .none;
|
return .none;
|
||||||
}
|
}
|
||||||
const fn_info = mod.typeToFunc(self.dg.decl.ty).?;
|
const fn_info = mod.typeToFunc(self.dg.decl.typeOf(mod)).?;
|
||||||
if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
||||||
if (Type.fromInterned(fn_info.return_type).isError(mod)) {
|
if (Type.fromInterned(fn_info.return_type).isError(mod)) {
|
||||||
// Functions with an empty error set are emitted with an error code
|
// Functions with an empty error set are emitted with an error code
|
||||||
@ -5674,7 +5675,7 @@ pub const FuncGen = struct {
|
|||||||
const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
|
const un_op = self.air.instructions.items(.data)[@intFromEnum(inst)].un_op;
|
||||||
const ptr_ty = self.typeOf(un_op);
|
const ptr_ty = self.typeOf(un_op);
|
||||||
const ret_ty = ptr_ty.childType(mod);
|
const ret_ty = ptr_ty.childType(mod);
|
||||||
const fn_info = mod.typeToFunc(self.dg.decl.ty).?;
|
const fn_info = mod.typeToFunc(self.dg.decl.typeOf(mod)).?;
|
||||||
if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
||||||
if (Type.fromInterned(fn_info.return_type).isError(mod)) {
|
if (Type.fromInterned(fn_info.return_type).isError(mod)) {
|
||||||
// Functions with an empty error set are emitted with an error code
|
// Functions with an empty error set are emitted with an error code
|
||||||
|
|||||||
@ -1221,7 +1221,7 @@ const DeclGen = struct {
|
|||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!decl.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) {
|
if (!decl.typeOf(mod).isFnOrHasRuntimeBitsIgnoreComptime(mod)) {
|
||||||
// Pointer to nothing - return undefined.
|
// Pointer to nothing - return undefined.
|
||||||
return self.spv.constUndef(ty_ref);
|
return self.spv.constUndef(ty_ref);
|
||||||
}
|
}
|
||||||
@ -1237,7 +1237,7 @@ const DeclGen = struct {
|
|||||||
const final_storage_class = self.spvStorageClass(decl.@"addrspace");
|
const final_storage_class = self.spvStorageClass(decl.@"addrspace");
|
||||||
try self.addFunctionDep(spv_decl_index, final_storage_class);
|
try self.addFunctionDep(spv_decl_index, final_storage_class);
|
||||||
|
|
||||||
const decl_ptr_ty_ref = try self.ptrType(decl.ty, final_storage_class);
|
const decl_ptr_ty_ref = try self.ptrType(decl.typeOf(mod), final_storage_class);
|
||||||
|
|
||||||
const ptr_id = switch (final_storage_class) {
|
const ptr_id = switch (final_storage_class) {
|
||||||
.Generic => try self.castToGeneric(self.typeId(decl_ptr_ty_ref), decl_id),
|
.Generic => try self.castToGeneric(self.typeId(decl_ptr_ty_ref), decl_id),
|
||||||
@ -2044,11 +2044,11 @@ const DeclGen = struct {
|
|||||||
|
|
||||||
switch (self.spv.declPtr(spv_decl_index).kind) {
|
switch (self.spv.declPtr(spv_decl_index).kind) {
|
||||||
.func => {
|
.func => {
|
||||||
assert(decl.ty.zigTypeTag(mod) == .Fn);
|
assert(decl.typeOf(mod).zigTypeTag(mod) == .Fn);
|
||||||
const fn_info = mod.typeToFunc(decl.ty).?;
|
const fn_info = mod.typeToFunc(decl.typeOf(mod)).?;
|
||||||
const return_ty_ref = try self.resolveFnReturnType(Type.fromInterned(fn_info.return_type));
|
const return_ty_ref = try self.resolveFnReturnType(Type.fromInterned(fn_info.return_type));
|
||||||
|
|
||||||
const prototype_ty_ref = try self.resolveType(decl.ty, .direct);
|
const prototype_ty_ref = try self.resolveType(decl.typeOf(mod), .direct);
|
||||||
try self.func.prologue.emit(self.spv.gpa, .OpFunction, .{
|
try self.func.prologue.emit(self.spv.gpa, .OpFunction, .{
|
||||||
.id_result_type = self.typeId(return_ty_ref),
|
.id_result_type = self.typeId(return_ty_ref),
|
||||||
.id_result = result_id,
|
.id_result = result_id,
|
||||||
@ -2121,7 +2121,7 @@ const DeclGen = struct {
|
|||||||
const final_storage_class = self.spvStorageClass(decl.@"addrspace");
|
const final_storage_class = self.spvStorageClass(decl.@"addrspace");
|
||||||
assert(final_storage_class != .Generic); // These should be instance globals
|
assert(final_storage_class != .Generic); // These should be instance globals
|
||||||
|
|
||||||
const ptr_ty_ref = try self.ptrType(decl.ty, final_storage_class);
|
const ptr_ty_ref = try self.ptrType(decl.typeOf(mod), final_storage_class);
|
||||||
|
|
||||||
try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpVariable, .{
|
try self.spv.sections.types_globals_constants.emit(self.spv.gpa, .OpVariable, .{
|
||||||
.id_result_type = self.typeId(ptr_ty_ref),
|
.id_result_type = self.typeId(ptr_ty_ref),
|
||||||
@ -2144,7 +2144,7 @@ const DeclGen = struct {
|
|||||||
|
|
||||||
try self.spv.declareDeclDeps(spv_decl_index, &.{});
|
try self.spv.declareDeclDeps(spv_decl_index, &.{});
|
||||||
|
|
||||||
const ptr_ty_ref = try self.ptrType(decl.ty, .Function);
|
const ptr_ty_ref = try self.ptrType(decl.typeOf(mod), .Function);
|
||||||
|
|
||||||
if (maybe_init_val) |init_val| {
|
if (maybe_init_val) |init_val| {
|
||||||
// TODO: Combine with resolveAnonDecl?
|
// TODO: Combine with resolveAnonDecl?
|
||||||
@ -2168,7 +2168,7 @@ const DeclGen = struct {
|
|||||||
});
|
});
|
||||||
self.current_block_label = root_block_id;
|
self.current_block_label = root_block_id;
|
||||||
|
|
||||||
const val_id = try self.constant(decl.ty, init_val, .indirect);
|
const val_id = try self.constant(decl.typeOf(mod), init_val, .indirect);
|
||||||
try self.func.body.emit(self.spv.gpa, .OpStore, .{
|
try self.func.body.emit(self.spv.gpa, .OpStore, .{
|
||||||
.pointer = result_id,
|
.pointer = result_id,
|
||||||
.object = val_id,
|
.object = val_id,
|
||||||
@ -4785,7 +4785,7 @@ const DeclGen = struct {
|
|||||||
const mod = self.module;
|
const mod = self.module;
|
||||||
if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
||||||
const decl = mod.declPtr(self.decl_index);
|
const decl = mod.declPtr(self.decl_index);
|
||||||
const fn_info = mod.typeToFunc(decl.ty).?;
|
const fn_info = mod.typeToFunc(decl.typeOf(mod)).?;
|
||||||
if (Type.fromInterned(fn_info.return_type).isError(mod)) {
|
if (Type.fromInterned(fn_info.return_type).isError(mod)) {
|
||||||
// Functions with an empty error set are emitted with an error code
|
// Functions with an empty error set are emitted with an error code
|
||||||
// return type and return zero so they can be function pointers coerced
|
// return type and return zero so they can be function pointers coerced
|
||||||
@ -4810,7 +4810,7 @@ const DeclGen = struct {
|
|||||||
|
|
||||||
if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
|
||||||
const decl = mod.declPtr(self.decl_index);
|
const decl = mod.declPtr(self.decl_index);
|
||||||
const fn_info = mod.typeToFunc(decl.ty).?;
|
const fn_info = mod.typeToFunc(decl.typeOf(mod)).?;
|
||||||
if (Type.fromInterned(fn_info.return_type).isError(mod)) {
|
if (Type.fromInterned(fn_info.return_type).isError(mod)) {
|
||||||
// Functions with an empty error set are emitted with an error code
|
// Functions with an empty error set are emitted with an error code
|
||||||
// return type and return zero so they can be function pointers coerced
|
// return type and return zero so they can be function pointers coerced
|
||||||
|
|||||||
@ -209,7 +209,7 @@ pub fn updateFunc(
|
|||||||
.module = module,
|
.module = module,
|
||||||
.error_msg = null,
|
.error_msg = null,
|
||||||
.pass = .{ .decl = decl_index },
|
.pass = .{ .decl = decl_index },
|
||||||
.is_naked_fn = decl.ty.fnCallingConvention(module) == .Naked,
|
.is_naked_fn = decl.typeOf(module).fnCallingConvention(module) == .Naked,
|
||||||
.fwd_decl = fwd_decl.toManaged(gpa),
|
.fwd_decl = fwd_decl.toManaged(gpa),
|
||||||
.ctypes = ctypes.*,
|
.ctypes = ctypes.*,
|
||||||
.anon_decl_deps = self.anon_decls,
|
.anon_decl_deps = self.anon_decls,
|
||||||
|
|||||||
@ -1272,7 +1272,7 @@ pub fn updateDecl(
|
|||||||
|
|
||||||
const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
|
const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
|
||||||
const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
|
const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
|
||||||
.ty = decl.ty,
|
.ty = decl.typeOf(mod),
|
||||||
.val = decl_val,
|
.val = decl_val,
|
||||||
}, &code_buffer, .none, .{
|
}, &code_buffer, .none, .{
|
||||||
.parent_atom_index = atom.getSymbolIndex().?,
|
.parent_atom_index = atom.getSymbolIndex().?,
|
||||||
@ -1399,8 +1399,8 @@ pub fn getOrCreateAtomForDecl(self: *Coff, decl_index: InternPool.DeclIndex) !At
|
|||||||
|
|
||||||
fn getDeclOutputSection(self: *Coff, decl_index: InternPool.DeclIndex) u16 {
|
fn getDeclOutputSection(self: *Coff, decl_index: InternPool.DeclIndex) u16 {
|
||||||
const decl = self.base.comp.module.?.declPtr(decl_index);
|
const decl = self.base.comp.module.?.declPtr(decl_index);
|
||||||
const ty = decl.ty;
|
|
||||||
const mod = self.base.comp.module.?;
|
const mod = self.base.comp.module.?;
|
||||||
|
const ty = decl.typeOf(mod);
|
||||||
const zig_ty = ty.zigTypeTag(mod);
|
const zig_ty = ty.zigTypeTag(mod);
|
||||||
const val = decl.val;
|
const val = decl.val;
|
||||||
const index: u16 = blk: {
|
const index: u16 = blk: {
|
||||||
@ -1535,7 +1535,7 @@ pub fn updateExports(
|
|||||||
.x86 => std.builtin.CallingConvention.Stdcall,
|
.x86 => std.builtin.CallingConvention.Stdcall,
|
||||||
else => std.builtin.CallingConvention.C,
|
else => std.builtin.CallingConvention.C,
|
||||||
};
|
};
|
||||||
const decl_cc = exported_decl.ty.fnCallingConvention(mod);
|
const decl_cc = exported_decl.typeOf(mod).fnCallingConvention(mod);
|
||||||
if (decl_cc == .C and ip.stringEqlSlice(exp.opts.name, "main") and
|
if (decl_cc == .C and ip.stringEqlSlice(exp.opts.name, "main") and
|
||||||
comp.config.link_libc)
|
comp.config.link_libc)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1109,7 +1109,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde
|
|||||||
|
|
||||||
assert(decl.has_tv);
|
assert(decl.has_tv);
|
||||||
|
|
||||||
switch (decl.ty.zigTypeTag(mod)) {
|
switch (decl.typeOf(mod).zigTypeTag(mod)) {
|
||||||
.Fn => {
|
.Fn => {
|
||||||
_ = try self.getOrCreateAtomForDecl(.src_fn, decl_index);
|
_ = try self.getOrCreateAtomForDecl(.src_fn, decl_index);
|
||||||
|
|
||||||
@ -1162,7 +1162,7 @@ pub fn initDeclState(self: *Dwarf, mod: *Module, decl_index: InternPool.DeclInde
|
|||||||
try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 +
|
try dbg_info_buffer.ensureUnusedCapacity(1 + ptr_width_bytes + 4 + 4 +
|
||||||
(decl_name_slice.len + 1) + (decl_linkage_name_slice.len + 1));
|
(decl_name_slice.len + 1) + (decl_linkage_name_slice.len + 1));
|
||||||
|
|
||||||
const fn_ret_type = decl.ty.fnReturnType(mod);
|
const fn_ret_type = decl.typeOf(mod).fnReturnType(mod);
|
||||||
const fn_ret_has_bits = fn_ret_type.hasRuntimeBits(mod);
|
const fn_ret_has_bits = fn_ret_type.hasRuntimeBits(mod);
|
||||||
dbg_info_buffer.appendAssumeCapacity(@intFromEnum(
|
dbg_info_buffer.appendAssumeCapacity(@intFromEnum(
|
||||||
@as(AbbrevCode, if (fn_ret_has_bits) .subprogram else .subprogram_retvoid),
|
@as(AbbrevCode, if (fn_ret_has_bits) .subprogram else .subprogram_retvoid),
|
||||||
@ -1215,7 +1215,7 @@ pub fn commitDeclState(
|
|||||||
var dbg_info_buffer = &decl_state.dbg_info;
|
var dbg_info_buffer = &decl_state.dbg_info;
|
||||||
|
|
||||||
assert(decl.has_tv);
|
assert(decl.has_tv);
|
||||||
switch (decl.ty.zigTypeTag(zcu)) {
|
switch (decl.typeOf(zcu).zigTypeTag(zcu)) {
|
||||||
.Fn => {
|
.Fn => {
|
||||||
try decl_state.setInlineFunc(decl.val.toIntern());
|
try decl_state.setInlineFunc(decl.val.toIntern());
|
||||||
|
|
||||||
|
|||||||
@ -846,7 +846,7 @@ fn getDeclShdrIndex(
|
|||||||
_ = self;
|
_ = self;
|
||||||
const mod = elf_file.base.comp.module.?;
|
const mod = elf_file.base.comp.module.?;
|
||||||
const any_non_single_threaded = elf_file.base.comp.config.any_non_single_threaded;
|
const any_non_single_threaded = elf_file.base.comp.config.any_non_single_threaded;
|
||||||
const shdr_index = switch (decl.ty.zigTypeTag(mod)) {
|
const shdr_index = switch (decl.typeOf(mod).zigTypeTag(mod)) {
|
||||||
.Fn => elf_file.zig_text_section_index.?,
|
.Fn => elf_file.zig_text_section_index.?,
|
||||||
else => blk: {
|
else => blk: {
|
||||||
if (decl.getOwnedVariable(mod)) |variable| {
|
if (decl.getOwnedVariable(mod)) |variable| {
|
||||||
@ -1158,7 +1158,7 @@ pub fn updateDecl(
|
|||||||
const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
|
const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
|
||||||
const res = if (decl_state) |*ds|
|
const res = if (decl_state) |*ds|
|
||||||
try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{
|
try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{
|
||||||
.ty = decl.ty,
|
.ty = decl.typeOf(mod),
|
||||||
.val = decl_val,
|
.val = decl_val,
|
||||||
}, &code_buffer, .{
|
}, &code_buffer, .{
|
||||||
.dwarf = ds,
|
.dwarf = ds,
|
||||||
@ -1167,7 +1167,7 @@ pub fn updateDecl(
|
|||||||
})
|
})
|
||||||
else
|
else
|
||||||
try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{
|
try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{
|
||||||
.ty = decl.ty,
|
.ty = decl.typeOf(mod),
|
||||||
.val = decl_val,
|
.val = decl_val,
|
||||||
}, &code_buffer, .none, .{
|
}, &code_buffer, .none, .{
|
||||||
.parent_atom_index = sym_index,
|
.parent_atom_index = sym_index,
|
||||||
|
|||||||
@ -740,7 +740,7 @@ pub fn updateDecl(
|
|||||||
const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
|
const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
|
||||||
const res =
|
const res =
|
||||||
try codegen.generateSymbol(&macho_file.base, decl.srcLoc(mod), .{
|
try codegen.generateSymbol(&macho_file.base, decl.srcLoc(mod), .{
|
||||||
.ty = decl.ty,
|
.ty = decl.typeOf(mod),
|
||||||
.val = decl_val,
|
.val = decl_val,
|
||||||
}, &code_buffer, dio, .{
|
}, &code_buffer, dio, .{
|
||||||
.parent_atom_index = sym_index,
|
.parent_atom_index = sym_index,
|
||||||
@ -1021,7 +1021,7 @@ fn getDeclOutputSection(
|
|||||||
_ = self;
|
_ = self;
|
||||||
const mod = macho_file.base.comp.module.?;
|
const mod = macho_file.base.comp.module.?;
|
||||||
const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;
|
const any_non_single_threaded = macho_file.base.comp.config.any_non_single_threaded;
|
||||||
const sect_id: u8 = switch (decl.ty.zigTypeTag(mod)) {
|
const sect_id: u8 = switch (decl.typeOf(mod).zigTypeTag(mod)) {
|
||||||
.Fn => macho_file.zig_text_sect_index.?,
|
.Fn => macho_file.zig_text_sect_index.?,
|
||||||
else => blk: {
|
else => blk: {
|
||||||
if (decl.getOwnedVariable(mod)) |variable| {
|
if (decl.getOwnedVariable(mod)) |variable| {
|
||||||
|
|||||||
@ -177,7 +177,7 @@ pub const Atom = struct {
|
|||||||
return if (self.code_ptr) |p| p[0..self.other.code_len] else blk: {
|
return if (self.code_ptr) |p| p[0..self.other.code_len] else blk: {
|
||||||
const decl_index = self.other.decl_index;
|
const decl_index = self.other.decl_index;
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
if (decl.ty.zigTypeTag(mod) == .Fn) {
|
if (decl.typeOf(mod).zigTypeTag(mod) == .Fn) {
|
||||||
const table = plan9.fn_decl_table.get(decl.getFileScope(mod)).?.functions;
|
const table = plan9.fn_decl_table.get(decl.getFileScope(mod)).?.functions;
|
||||||
const output = table.get(decl_index).?;
|
const output = table.get(decl_index).?;
|
||||||
break :blk output.code;
|
break :blk output.code;
|
||||||
@ -540,7 +540,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
|
|||||||
const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
|
const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
|
||||||
// TODO we need the symbol index for symbol in the table of locals for the containing atom
|
// TODO we need the symbol index for symbol in the table of locals for the containing atom
|
||||||
const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
|
const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
|
||||||
.ty = decl.ty,
|
.ty = decl.typeOf(mod),
|
||||||
.val = decl_val,
|
.val = decl_val,
|
||||||
}, &code_buffer, .{ .none = {} }, .{
|
}, &code_buffer, .{ .none = {} }, .{
|
||||||
.parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
|
.parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
|
||||||
@ -566,7 +566,7 @@ fn updateFinish(self: *Plan9, decl_index: InternPool.DeclIndex) !void {
|
|||||||
const gpa = self.base.comp.gpa;
|
const gpa = self.base.comp.gpa;
|
||||||
const mod = self.base.comp.module.?;
|
const mod = self.base.comp.module.?;
|
||||||
const decl = mod.declPtr(decl_index);
|
const decl = mod.declPtr(decl_index);
|
||||||
const is_fn = (decl.ty.zigTypeTag(mod) == .Fn);
|
const is_fn = (decl.typeOf(mod).zigTypeTag(mod) == .Fn);
|
||||||
const sym_t: aout.Sym.Type = if (is_fn) .t else .d;
|
const sym_t: aout.Sym.Type = if (is_fn) .t else .d;
|
||||||
|
|
||||||
const atom = self.getAtomPtr(self.decls.get(decl_index).?.index);
|
const atom = self.getAtomPtr(self.decls.get(decl_index).?.index);
|
||||||
|
|||||||
@ -163,7 +163,7 @@ pub fn updateExports(
|
|||||||
if (decl.val.isFuncBody(mod)) {
|
if (decl.val.isFuncBody(mod)) {
|
||||||
const target = mod.getTarget();
|
const target = mod.getTarget();
|
||||||
const spv_decl_index = try self.object.resolveDecl(mod, decl_index);
|
const spv_decl_index = try self.object.resolveDecl(mod, decl_index);
|
||||||
const execution_model = switch (decl.ty.fnCallingConvention(mod)) {
|
const execution_model = switch (decl.typeOf(mod).fnCallingConvention(mod)) {
|
||||||
.Vertex => spec.ExecutionModel.Vertex,
|
.Vertex => spec.ExecutionModel.Vertex,
|
||||||
.Fragment => spec.ExecutionModel.Fragment,
|
.Fragment => spec.ExecutionModel.Fragment,
|
||||||
.Kernel => spec.ExecutionModel.Kernel,
|
.Kernel => spec.ExecutionModel.Kernel,
|
||||||
|
|||||||
@ -270,7 +270,7 @@ pub fn updateDecl(
|
|||||||
const res = try codegen.generateSymbol(
|
const res = try codegen.generateSymbol(
|
||||||
&wasm_file.base,
|
&wasm_file.base,
|
||||||
decl.srcLoc(mod),
|
decl.srcLoc(mod),
|
||||||
.{ .ty = decl.ty, .val = val },
|
.{ .ty = decl.typeOf(mod), .val = val },
|
||||||
&code_writer,
|
&code_writer,
|
||||||
.none,
|
.none,
|
||||||
.{ .parent_atom_index = @intFromEnum(atom.sym_index) },
|
.{ .parent_atom_index = @intFromEnum(atom.sym_index) },
|
||||||
@ -346,7 +346,7 @@ fn finishUpdateDecl(
|
|||||||
try atom.code.appendSlice(gpa, code);
|
try atom.code.appendSlice(gpa, code);
|
||||||
atom.size = @intCast(code.len);
|
atom.size = @intCast(code.len);
|
||||||
|
|
||||||
switch (decl.ty.zigTypeTag(mod)) {
|
switch (decl.typeOf(mod).zigTypeTag(mod)) {
|
||||||
.Fn => {
|
.Fn => {
|
||||||
sym.index = try zig_object.appendFunction(gpa, .{ .type_index = zig_object.atom_types.get(atom_index).? });
|
sym.index = try zig_object.appendFunction(gpa, .{ .type_index = zig_object.atom_types.get(atom_index).? });
|
||||||
sym.tag = .function;
|
sym.tag = .function;
|
||||||
@ -764,7 +764,7 @@ pub fn getDeclVAddr(
|
|||||||
const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;
|
const atom_index = wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = @enumFromInt(reloc_info.parent_atom_index) }).?;
|
||||||
const atom = wasm_file.getAtomPtr(atom_index);
|
const atom = wasm_file.getAtomPtr(atom_index);
|
||||||
const is_wasm32 = target.cpu.arch == .wasm32;
|
const is_wasm32 = target.cpu.arch == .wasm32;
|
||||||
if (decl.ty.zigTypeTag(mod) == .Fn) {
|
if (decl.typeOf(mod).zigTypeTag(mod) == .Fn) {
|
||||||
std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations
|
std.debug.assert(reloc_info.addend == 0); // addend not allowed for function relocations
|
||||||
try atom.relocs.append(gpa, .{
|
try atom.relocs.append(gpa, .{
|
||||||
.index = target_symbol_index,
|
.index = target_symbol_index,
|
||||||
@ -964,7 +964,7 @@ pub fn freeDecl(zig_object: *ZigObject, wasm_file: *Wasm, decl_index: InternPool
|
|||||||
if (sym.isGlobal()) {
|
if (sym.isGlobal()) {
|
||||||
std.debug.assert(zig_object.global_syms.remove(atom.sym_index));
|
std.debug.assert(zig_object.global_syms.remove(atom.sym_index));
|
||||||
}
|
}
|
||||||
switch (decl.ty.zigTypeTag(mod)) {
|
switch (decl.typeOf(mod).zigTypeTag(mod)) {
|
||||||
.Fn => {
|
.Fn => {
|
||||||
zig_object.functions_free_list.append(gpa, sym.index) catch {};
|
zig_object.functions_free_list.append(gpa, sym.index) catch {};
|
||||||
std.debug.assert(zig_object.atom_types.remove(atom_index));
|
std.debug.assert(zig_object.atom_types.remove(atom_index));
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user