mirror of
https://github.com/ziglang/zig.git
synced 2026-02-19 15:58:50 +00:00
stage2: make line field of @src runtime known
This commit is contained in:
parent
226994cd7e
commit
89cef9f5f7
@ -1686,7 +1686,9 @@ fn resolveMaybeUndefValAllowVariables(
|
||||
switch (air_tags[i]) {
|
||||
.constant => {
|
||||
const ty_pl = sema.air_instructions.items(.data)[i].ty_pl;
|
||||
return sema.air_values.items[ty_pl.payload];
|
||||
const val = sema.air_values.items[ty_pl.payload];
|
||||
if (val.tag() == .runtime_int) return null;
|
||||
return val;
|
||||
},
|
||||
.const_ty => {
|
||||
return try sema.air_instructions.items(.data)[i].ty.toValue(sema.arena);
|
||||
@ -12151,9 +12153,8 @@ fn zirBuiltinSrc(
|
||||
field_values[0] = file_name_val;
|
||||
// fn_name: [:0]const u8,
|
||||
field_values[1] = func_name_val;
|
||||
// TODO these should be runtime only!
|
||||
// line: u32
|
||||
field_values[2] = try Value.Tag.int_u64.create(sema.arena, extra.line + 1);
|
||||
field_values[2] = try Value.Tag.runtime_int.create(sema.arena, extra.line + 1);
|
||||
// column: u32,
|
||||
field_values[3] = try Value.Tag.int_u64.create(sema.arena, extra.column + 1);
|
||||
|
||||
|
||||
@ -495,5 +495,6 @@ pub fn print(
|
||||
},
|
||||
.generic_poison_type => return writer.writeAll("(generic poison type)"),
|
||||
.generic_poison => return writer.writeAll("(generic poison)"),
|
||||
.runtime_int => return writer.writeAll("[runtime value]"),
|
||||
};
|
||||
}
|
||||
|
||||
@ -111,6 +111,7 @@ pub const Value = extern union {
|
||||
int_i64,
|
||||
int_big_positive,
|
||||
int_big_negative,
|
||||
runtime_int,
|
||||
function,
|
||||
extern_fn,
|
||||
variable,
|
||||
@ -304,6 +305,7 @@ pub const Value = extern union {
|
||||
.int_type => Payload.IntType,
|
||||
.int_u64 => Payload.U64,
|
||||
.int_i64 => Payload.I64,
|
||||
.runtime_int => Payload.U64,
|
||||
.function => Payload.Function,
|
||||
.variable => Payload.Variable,
|
||||
.decl_ref_mut => Payload.DeclRefMut,
|
||||
@ -483,6 +485,7 @@ pub const Value = extern union {
|
||||
},
|
||||
.int_type => return self.copyPayloadShallow(arena, Payload.IntType),
|
||||
.int_u64 => return self.copyPayloadShallow(arena, Payload.U64),
|
||||
.runtime_int => return self.copyPayloadShallow(arena, Payload.U64),
|
||||
.int_i64 => return self.copyPayloadShallow(arena, Payload.I64),
|
||||
.int_big_positive, .int_big_negative => {
|
||||
const old_payload = self.cast(Payload.BigInt).?;
|
||||
@ -762,6 +765,7 @@ pub const Value = extern union {
|
||||
.int_i64 => return std.fmt.formatIntValue(val.castTag(.int_i64).?.data, "", options, out_stream),
|
||||
.int_big_positive => return out_stream.print("{}", .{val.castTag(.int_big_positive).?.asBigInt()}),
|
||||
.int_big_negative => return out_stream.print("{}", .{val.castTag(.int_big_negative).?.asBigInt()}),
|
||||
.runtime_int => return out_stream.writeAll("[runtime value]"),
|
||||
.function => return out_stream.print("(function decl={d})", .{val.castTag(.function).?.data.owner_decl}),
|
||||
.extern_fn => return out_stream.writeAll("(extern function)"),
|
||||
.variable => return out_stream.writeAll("(variable)"),
|
||||
@ -1077,6 +1081,8 @@ pub const Value = extern union {
|
||||
.int_big_positive => return val.castTag(.int_big_positive).?.asBigInt(),
|
||||
.int_big_negative => return val.castTag(.int_big_negative).?.asBigInt(),
|
||||
|
||||
.runtime_int => return BigIntMutable.init(&space.limbs, val.castTag(.runtime_int).?.data).toConst(),
|
||||
|
||||
.undef => unreachable,
|
||||
|
||||
.lazy_align => {
|
||||
@ -1132,6 +1138,8 @@ pub const Value = extern union {
|
||||
.int_big_positive => return val.castTag(.int_big_positive).?.asBigInt().to(u64) catch null,
|
||||
.int_big_negative => return val.castTag(.int_big_negative).?.asBigInt().to(u64) catch null,
|
||||
|
||||
.runtime_int => return val.castTag(.runtime_int).?.data,
|
||||
|
||||
.undef => unreachable,
|
||||
|
||||
.lazy_align => {
|
||||
|
||||
14
test/cases/compile_errors/src_fields_runtime.zig
Normal file
14
test/cases/compile_errors/src_fields_runtime.zig
Normal file
@ -0,0 +1,14 @@
|
||||
pub export fn entry1() void {
|
||||
const s = @src();
|
||||
comptime var a: []const u8 = s.file;
|
||||
comptime var b: []const u8 = s.fn_name;
|
||||
comptime var c: u32 = s.column;
|
||||
comptime var d: u32 = s.line;
|
||||
_ = a; _ = b; _ = c; _ = d;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :6:28: error: cannot store runtime value in compile time variable
|
||||
Loading…
x
Reference in New Issue
Block a user