From 4bac22e88898158fc49e69db5bbe26a324797d68 Mon Sep 17 00:00:00 2001 From: Sahnvour Date: Sat, 2 Mar 2019 18:12:56 +0100 Subject: [PATCH] all integers returned by @typeInfo are now comptime_int --- doc/langref.html.in | 14 +++++++------- src/codegen.cpp | 16 ++++++++-------- src/ir.cpp | 16 ++++++++-------- std/math/index.zig | 4 ++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/doc/langref.html.in b/doc/langref.html.in index 6b798770ef..959bbcfc07 100644 --- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -6827,18 +6827,18 @@ pub const TypeInfo = union(TypeId) { pub const Int = struct { is_signed: bool, - bits: u8, + bits: comptime_int, }; pub const Float = struct { - bits: u8, + bits: comptime_int, }; pub const Pointer = struct { size: Size, is_const: bool, is_volatile: bool, - alignment: u32, + alignment: comptime_int, child: type, pub const Size = enum { @@ -6849,7 +6849,7 @@ pub const TypeInfo = union(TypeId) { }; pub const Array = struct { - len: usize, + len: comptime_int, child: type, }; @@ -6861,7 +6861,7 @@ pub const TypeInfo = union(TypeId) { pub const StructField = struct { name: []const u8, - offset: ?usize, + offset: ?comptime_int, field_type: type, }; @@ -6882,7 +6882,7 @@ pub const TypeInfo = union(TypeId) { pub const Error = struct { name: []const u8, - value: usize, + value: comptime_int, }; pub const ErrorSet = struct { @@ -6891,7 +6891,7 @@ pub const TypeInfo = union(TypeId) { pub const EnumField = struct { name: []const u8, - value: usize, + value: comptime_int, }; pub const Enum = struct { diff --git a/src/codegen.cpp b/src/codegen.cpp index 77832e215d..52e20108de 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -7492,18 +7492,18 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { "\n\n" " pub const Int = struct {\n" " is_signed: bool,\n" - " bits: u8,\n" + " bits: comptime_int,\n" " };\n" "\n" " pub const Float = struct {\n" - " bits: u8,\n" + " bits: comptime_int,\n" " };\n" "\n" " pub const Pointer = struct {\n" " size: Size,\n" " is_const: bool,\n" " is_volatile: bool,\n" - " alignment: u32,\n" + " alignment: comptime_int,\n" " child: type,\n" "\n" " pub const Size = enum {\n" @@ -7515,7 +7515,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { " };\n" "\n" " pub const Array = struct {\n" - " len: usize,\n" + " len: comptime_int,\n" " child: type,\n" " };\n" "\n" @@ -7527,7 +7527,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { "\n" " pub const StructField = struct {\n" " name: []const u8,\n" - " offset: ?usize,\n" + " offset: ?comptime_int,\n" " field_type: type,\n" " };\n" "\n" @@ -7548,7 +7548,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { "\n" " pub const Error = struct {\n" " name: []const u8,\n" - " value: usize,\n" + " value: comptime_int,\n" " };\n" "\n" " pub const ErrorSet = struct {\n" @@ -7557,7 +7557,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { "\n" " pub const EnumField = struct {\n" " name: []const u8,\n" - " value: usize,\n" + " value: comptime_int,\n" " };\n" "\n" " pub const Enum = struct {\n" @@ -7609,7 +7609,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) { " };\n" "\n" " pub const Vector = struct {\n" - " len: u32,\n" + " len: comptime_int,\n" " child: type,\n" " };\n" "\n" diff --git a/src/ir.cpp b/src/ir.cpp index 2452011d79..e081b4b052 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -17997,7 +17997,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty // alignment: u32 ensure_field_index(result->type, "alignment", 3); fields[3].special = ConstValSpecialStatic; - fields[3].type = get_int_type(ira->codegen, false, 29); + fields[3].type = ira->codegen->builtin_types.entry_num_lit_int; bigint_init_unsigned(&fields[3].data.x_bigint, get_ptr_align(ira->codegen, attrs_type)); // child: type ensure_field_index(result->type, "child", 4); @@ -18016,7 +18016,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val, ConstExprValue *inner_fields = create_const_vals(2); inner_fields[1].special = ConstValSpecialStatic; - inner_fields[1].type = ira->codegen->builtin_types.entry_usize; + inner_fields[1].type = ira->codegen->builtin_types.entry_num_lit_int; ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name); init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(enum_field->name), true); @@ -18080,7 +18080,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr // bits: u8 ensure_field_index(result->type, "bits", 1); fields[1].special = ConstValSpecialStatic; - fields[1].type = ira->codegen->builtin_types.entry_u8; + fields[1].type = ira->codegen->builtin_types.entry_num_lit_int; bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count); break; @@ -18097,7 +18097,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr // bits: u8 ensure_field_index(result->type, "bits", 0); fields[0].special = ConstValSpecialStatic; - fields[0].type = ira->codegen->builtin_types.entry_u8; + fields[0].type = ira->codegen->builtin_types.entry_num_lit_int; bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count); break; @@ -18121,7 +18121,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr // len: usize ensure_field_index(result->type, "len", 0); fields[0].special = ConstValSpecialStatic; - fields[0].type = ira->codegen->builtin_types.entry_usize; + fields[0].type = ira->codegen->builtin_types.entry_num_lit_int; bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len); // child: type ensure_field_index(result->type, "child", 1); @@ -18142,7 +18142,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr // len: usize ensure_field_index(result->type, "len", 0); fields[0].special = ConstValSpecialStatic; - fields[0].type = ira->codegen->builtin_types.entry_u32; + fields[0].type = ira->codegen->builtin_types.entry_num_lit_int; bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.vector.len); // child: type ensure_field_index(result->type, "child", 1); @@ -18286,7 +18286,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr ConstExprValue *inner_fields = create_const_vals(2); inner_fields[1].special = ConstValSpecialStatic; - inner_fields[1].type = ira->codegen->builtin_types.entry_usize; + inner_fields[1].type = ira->codegen->builtin_types.entry_num_lit_int; ConstExprValue *name = nullptr; if (error->cached_error_name_val != nullptr) @@ -18458,7 +18458,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr ConstExprValue *inner_fields = create_const_vals(3); inner_fields[1].special = ConstValSpecialStatic; - inner_fields[1].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_usize); + inner_fields[1].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int); if (!type_has_bits(struct_field->type_entry)) { inner_fields[1].data.x_optional = nullptr; diff --git a/std/math/index.zig b/std/math/index.zig index 20648139b8..89f228d35e 100644 --- a/std/math/index.zig +++ b/std/math/index.zig @@ -738,14 +738,14 @@ test "math.f64_min" { pub fn maxInt(comptime T: type) comptime_int { const info = @typeInfo(T); - const bit_count = comptime_int(info.Int.bits); // TODO #1683 + const bit_count = info.Int.bits; if (bit_count == 0) return 0; return (1 << (bit_count - @boolToInt(info.Int.is_signed))) - 1; } pub fn minInt(comptime T: type) comptime_int { const info = @typeInfo(T); - const bit_count = comptime_int(info.Int.bits); // TODO #1683 + const bit_count = info.Int.bits; if (!info.Int.is_signed) return 0; if (bit_count == 0) return 0; return -(1 << (bit_count - 1));