authorgravatar for sahnvour@pm.meSahnvour <sahnvour@pm.me> 2019-03-02 18:12:56+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-02 14:27:37-05:00
log4bac22e88898158fc49e69db5bbe26a324797d68
tree82c9845d2f113594f359339548bf949823413711
parent67b4de33d2729fdb21337e5a0e05f6273bce23ba

all integers returned by @typeInfo are now comptime_int


4 files changed, 25 insertions(+), 25 deletions(-)

doc/langref.html.in+7-7
...@@ -6827,18 +6827,18 @@ pub const TypeInfo = union(TypeId) {...@@ -6827,18 +6827,18 @@ pub const TypeInfo = union(TypeId) {
68276827
6828 pub const Int = struct {6828 pub const Int = struct {
6829 is_signed: bool,6829 is_signed: bool,
6830 bits: u8,6830 bits: comptime_int,
6831 };6831 };
68326832
6833 pub const Float = struct {6833 pub const Float = struct {
6834 bits: u8,6834 bits: comptime_int,
6835 };6835 };
68366836
6837 pub const Pointer = struct {6837 pub const Pointer = struct {
6838 size: Size,6838 size: Size,
6839 is_const: bool,6839 is_const: bool,
6840 is_volatile: bool,6840 is_volatile: bool,
6841 alignment: u32,6841 alignment: comptime_int,
6842 child: type,6842 child: type,
68436843
6844 pub const Size = enum {6844 pub const Size = enum {
...@@ -6849,7 +6849,7 @@ pub const TypeInfo = union(TypeId) {...@@ -6849,7 +6849,7 @@ pub const TypeInfo = union(TypeId) {
6849 };6849 };
68506850
6851 pub const Array = struct {6851 pub const Array = struct {
6852 len: usize,6852 len: comptime_int,
6853 child: type,6853 child: type,
6854 };6854 };
68556855
...@@ -6861,7 +6861,7 @@ pub const TypeInfo = union(TypeId) {...@@ -6861,7 +6861,7 @@ pub const TypeInfo = union(TypeId) {
68616861
6862 pub const StructField = struct {6862 pub const StructField = struct {
6863 name: []const u8,6863 name: []const u8,
6864 offset: ?usize,6864 offset: ?comptime_int,
6865 field_type: type,6865 field_type: type,
6866 };6866 };
68676867
...@@ -6882,7 +6882,7 @@ pub const TypeInfo = union(TypeId) {...@@ -6882,7 +6882,7 @@ pub const TypeInfo = union(TypeId) {
68826882
6883 pub const Error = struct {6883 pub const Error = struct {
6884 name: []const u8,6884 name: []const u8,
6885 value: usize,6885 value: comptime_int,
6886 };6886 };
68876887
6888 pub const ErrorSet = struct {6888 pub const ErrorSet = struct {
...@@ -6891,7 +6891,7 @@ pub const TypeInfo = union(TypeId) {...@@ -6891,7 +6891,7 @@ pub const TypeInfo = union(TypeId) {
68916891
6892 pub const EnumField = struct {6892 pub const EnumField = struct {
6893 name: []const u8,6893 name: []const u8,
6894 value: usize,6894 value: comptime_int,
6895 };6895 };
68966896
6897 pub const Enum = struct {6897 pub const Enum = struct {
src/codegen.cpp+8-8
...@@ -7492,18 +7492,18 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7492,18 +7492,18 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7492 "\n\n"7492 "\n\n"
7493 " pub const Int = struct {\n"7493 " pub const Int = struct {\n"
7494 " is_signed: bool,\n"7494 " is_signed: bool,\n"
7495 " bits: u8,\n"7495 " bits: comptime_int,\n"
7496 " };\n"7496 " };\n"
7497 "\n"7497 "\n"
7498 " pub const Float = struct {\n"7498 " pub const Float = struct {\n"
7499 " bits: u8,\n"7499 " bits: comptime_int,\n"
7500 " };\n"7500 " };\n"
7501 "\n"7501 "\n"
7502 " pub const Pointer = struct {\n"7502 " pub const Pointer = struct {\n"
7503 " size: Size,\n"7503 " size: Size,\n"
7504 " is_const: bool,\n"7504 " is_const: bool,\n"
7505 " is_volatile: bool,\n"7505 " is_volatile: bool,\n"
7506 " alignment: u32,\n"7506 " alignment: comptime_int,\n"
7507 " child: type,\n"7507 " child: type,\n"
7508 "\n"7508 "\n"
7509 " pub const Size = enum {\n"7509 " pub const Size = enum {\n"
...@@ -7515,7 +7515,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7515,7 +7515,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7515 " };\n"7515 " };\n"
7516 "\n"7516 "\n"
7517 " pub const Array = struct {\n"7517 " pub const Array = struct {\n"
7518 " len: usize,\n"7518 " len: comptime_int,\n"
7519 " child: type,\n"7519 " child: type,\n"
7520 " };\n"7520 " };\n"
7521 "\n"7521 "\n"
...@@ -7527,7 +7527,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7527,7 +7527,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7527 "\n"7527 "\n"
7528 " pub const StructField = struct {\n"7528 " pub const StructField = struct {\n"
7529 " name: []const u8,\n"7529 " name: []const u8,\n"
7530 " offset: ?usize,\n"7530 " offset: ?comptime_int,\n"
7531 " field_type: type,\n"7531 " field_type: type,\n"
7532 " };\n"7532 " };\n"
7533 "\n"7533 "\n"
...@@ -7548,7 +7548,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7548,7 +7548,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7548 "\n"7548 "\n"
7549 " pub const Error = struct {\n"7549 " pub const Error = struct {\n"
7550 " name: []const u8,\n"7550 " name: []const u8,\n"
7551 " value: usize,\n"7551 " value: comptime_int,\n"
7552 " };\n"7552 " };\n"
7553 "\n"7553 "\n"
7554 " pub const ErrorSet = struct {\n"7554 " pub const ErrorSet = struct {\n"
...@@ -7557,7 +7557,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7557,7 +7557,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7557 "\n"7557 "\n"
7558 " pub const EnumField = struct {\n"7558 " pub const EnumField = struct {\n"
7559 " name: []const u8,\n"7559 " name: []const u8,\n"
7560 " value: usize,\n"7560 " value: comptime_int,\n"
7561 " };\n"7561 " };\n"
7562 "\n"7562 "\n"
7563 " pub const Enum = struct {\n"7563 " pub const Enum = struct {\n"
...@@ -7609,7 +7609,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {...@@ -7609,7 +7609,7 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
7609 " };\n"7609 " };\n"
7610 "\n"7610 "\n"
7611 " pub const Vector = struct {\n"7611 " pub const Vector = struct {\n"
7612 " len: u32,\n"7612 " len: comptime_int,\n"
7613 " child: type,\n"7613 " child: type,\n"
7614 " };\n"7614 " };\n"
7615 "\n"7615 "\n"
src/ir.cpp+8-8
...@@ -17997,7 +17997,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty...@@ -17997,7 +17997,7 @@ static ConstExprValue *create_ptr_like_type_info(IrAnalyze *ira, ZigType *ptr_ty
17997 // alignment: u3217997 // alignment: u32
17998 ensure_field_index(result->type, "alignment", 3);17998 ensure_field_index(result->type, "alignment", 3);
17999 fields[3].special = ConstValSpecialStatic;17999 fields[3].special = ConstValSpecialStatic;
18000 fields[3].type = get_int_type(ira->codegen, false, 29);18000 fields[3].type = ira->codegen->builtin_types.entry_num_lit_int;
18001 bigint_init_unsigned(&fields[3].data.x_bigint, get_ptr_align(ira->codegen, attrs_type));18001 bigint_init_unsigned(&fields[3].data.x_bigint, get_ptr_align(ira->codegen, attrs_type));
18002 // child: type18002 // child: type
18003 ensure_field_index(result->type, "child", 4);18003 ensure_field_index(result->type, "child", 4);
...@@ -18016,7 +18016,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,...@@ -18016,7 +18016,7 @@ static void make_enum_field_val(IrAnalyze *ira, ConstExprValue *enum_field_val,
1801618016
18017 ConstExprValue *inner_fields = create_const_vals(2);18017 ConstExprValue *inner_fields = create_const_vals(2);
18018 inner_fields[1].special = ConstValSpecialStatic;18018 inner_fields[1].special = ConstValSpecialStatic;
18019 inner_fields[1].type = ira->codegen->builtin_types.entry_usize;18019 inner_fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;
1802018020
18021 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name);18021 ConstExprValue *name = create_const_str_lit(ira->codegen, enum_field->name);
18022 init_const_slice(ira->codegen, &inner_fields[0], name, 0, buf_len(enum_field->name), true);18022 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...@@ -18080,7 +18080,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
18080 // bits: u818080 // bits: u8
18081 ensure_field_index(result->type, "bits", 1);18081 ensure_field_index(result->type, "bits", 1);
18082 fields[1].special = ConstValSpecialStatic;18082 fields[1].special = ConstValSpecialStatic;
18083 fields[1].type = ira->codegen->builtin_types.entry_u8;18083 fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;
18084 bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count);18084 bigint_init_unsigned(&fields[1].data.x_bigint, type_entry->data.integral.bit_count);
1808518085
18086 break;18086 break;
...@@ -18097,7 +18097,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -18097,7 +18097,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
18097 // bits: u818097 // bits: u8
18098 ensure_field_index(result->type, "bits", 0);18098 ensure_field_index(result->type, "bits", 0);
18099 fields[0].special = ConstValSpecialStatic;18099 fields[0].special = ConstValSpecialStatic;
18100 fields[0].type = ira->codegen->builtin_types.entry_u8;18100 fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;
18101 bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count);18101 bigint_init_unsigned(&fields->data.x_bigint, type_entry->data.floating.bit_count);
1810218102
18103 break;18103 break;
...@@ -18121,7 +18121,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -18121,7 +18121,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
18121 // len: usize18121 // len: usize
18122 ensure_field_index(result->type, "len", 0);18122 ensure_field_index(result->type, "len", 0);
18123 fields[0].special = ConstValSpecialStatic;18123 fields[0].special = ConstValSpecialStatic;
18124 fields[0].type = ira->codegen->builtin_types.entry_usize;18124 fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;
18125 bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len);18125 bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.array.len);
18126 // child: type18126 // child: type
18127 ensure_field_index(result->type, "child", 1);18127 ensure_field_index(result->type, "child", 1);
...@@ -18142,7 +18142,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -18142,7 +18142,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
18142 // len: usize18142 // len: usize
18143 ensure_field_index(result->type, "len", 0);18143 ensure_field_index(result->type, "len", 0);
18144 fields[0].special = ConstValSpecialStatic;18144 fields[0].special = ConstValSpecialStatic;
18145 fields[0].type = ira->codegen->builtin_types.entry_u32;18145 fields[0].type = ira->codegen->builtin_types.entry_num_lit_int;
18146 bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.vector.len);18146 bigint_init_unsigned(&fields[0].data.x_bigint, type_entry->data.vector.len);
18147 // child: type18147 // child: type
18148 ensure_field_index(result->type, "child", 1);18148 ensure_field_index(result->type, "child", 1);
...@@ -18286,7 +18286,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -18286,7 +18286,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
1828618286
18287 ConstExprValue *inner_fields = create_const_vals(2);18287 ConstExprValue *inner_fields = create_const_vals(2);
18288 inner_fields[1].special = ConstValSpecialStatic;18288 inner_fields[1].special = ConstValSpecialStatic;
18289 inner_fields[1].type = ira->codegen->builtin_types.entry_usize;18289 inner_fields[1].type = ira->codegen->builtin_types.entry_num_lit_int;
1829018290
18291 ConstExprValue *name = nullptr;18291 ConstExprValue *name = nullptr;
18292 if (error->cached_error_name_val != nullptr)18292 if (error->cached_error_name_val != nullptr)
...@@ -18458,7 +18458,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr...@@ -18458,7 +18458,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
1845818458
18459 ConstExprValue *inner_fields = create_const_vals(3);18459 ConstExprValue *inner_fields = create_const_vals(3);
18460 inner_fields[1].special = ConstValSpecialStatic;18460 inner_fields[1].special = ConstValSpecialStatic;
18461 inner_fields[1].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_usize);18461 inner_fields[1].type = get_optional_type(ira->codegen, ira->codegen->builtin_types.entry_num_lit_int);
1846218462
18463 if (!type_has_bits(struct_field->type_entry)) {18463 if (!type_has_bits(struct_field->type_entry)) {
18464 inner_fields[1].data.x_optional = nullptr;18464 inner_fields[1].data.x_optional = nullptr;
std/math/index.zig+2-2
...@@ -738,14 +738,14 @@ test "math.f64_min" {...@@ -738,14 +738,14 @@ test "math.f64_min" {
738738
739pub fn maxInt(comptime T: type) comptime_int {739pub fn maxInt(comptime T: type) comptime_int {
740 const info = @typeInfo(T);740 const info = @typeInfo(T);
741 const bit_count = comptime_int(info.Int.bits); // TODO #1683741 const bit_count = info.Int.bits;
742 if (bit_count == 0) return 0;742 if (bit_count == 0) return 0;
743 return (1 << (bit_count - @boolToInt(info.Int.is_signed))) - 1;743 return (1 << (bit_count - @boolToInt(info.Int.is_signed))) - 1;
744}744}
745745
746pub fn minInt(comptime T: type) comptime_int {746pub fn minInt(comptime T: type) comptime_int {
747 const info = @typeInfo(T);747 const info = @typeInfo(T);
748 const bit_count = comptime_int(info.Int.bits); // TODO #1683748 const bit_count = info.Int.bits;
749 if (!info.Int.is_signed) return 0;749 if (!info.Int.is_signed) return 0;
750 if (bit_count == 0) return 0;750 if (bit_count == 0) return 0;
751 return -(1 << (bit_count - 1));751 return -(1 << (bit_count - 1));