Merge pull request #1057 from ziglang/comptime-int

Rename integer literal type and float literal type
This commit is contained in:
Andrew Kelley 2018-06-05 10:16:51 -04:00 committed by GitHub
commit 677eaf29b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 355 additions and 341 deletions

View File

@ -4893,10 +4893,10 @@ pub const TypeId = enum {
Pointer, Pointer,
Array, Array,
Struct, Struct,
FloatLiteral, ComptimeFloat,
IntLiteral, ComptimeInt,
UndefinedLiteral, Undefined,
NullLiteral, Null,
Nullable, Nullable,
ErrorUnion, ErrorUnion,
Error, Error,
@ -4927,10 +4927,10 @@ pub const TypeInfo = union(TypeId) {
Pointer: Pointer, Pointer: Pointer,
Array: Array, Array: Array,
Struct: Struct, Struct: Struct,
FloatLiteral: void, ComptimeFloat: void,
IntLiteral: void, ComptimeInt: void,
UndefinedLiteral: void, Undefined: void,
NullLiteral: void, Null: void,
Nullable: Nullable, Nullable: Nullable,
ErrorUnion: ErrorUnion, ErrorUnion: ErrorUnion,
ErrorSet: ErrorSet, ErrorSet: ErrorSet,
@ -5685,10 +5685,10 @@ pub const TypeId = enum {
Pointer, Pointer,
Array, Array,
Struct, Struct,
FloatLiteral, ComptimeFloat,
IntLiteral, ComptimeInt,
UndefinedLiteral, Undefined,
NullLiteral, Null,
Nullable, Nullable,
ErrorUnion, ErrorUnion,
ErrorSet, ErrorSet,
@ -5713,10 +5713,10 @@ pub const TypeInfo = union(TypeId) {
Pointer: Pointer, Pointer: Pointer,
Array: Array, Array: Array,
Struct: Struct, Struct: Struct,
FloatLiteral: void, ComptimeFloat: void,
IntLiteral: void, ComptimeInt: void,
UndefinedLiteral: void, Undefined: void,
NullLiteral: void, Null: void,
Nullable: Nullable, Nullable: Nullable,
ErrorUnion: ErrorUnion, ErrorUnion: ErrorUnion,
ErrorSet: ErrorSet, ErrorSet: ErrorSet,

View File

@ -1159,10 +1159,10 @@ enum TypeTableEntryId {
TypeTableEntryIdPointer, TypeTableEntryIdPointer,
TypeTableEntryIdArray, TypeTableEntryIdArray,
TypeTableEntryIdStruct, TypeTableEntryIdStruct,
TypeTableEntryIdNumLitFloat, TypeTableEntryIdComptimeFloat,
TypeTableEntryIdNumLitInt, TypeTableEntryIdComptimeInt,
TypeTableEntryIdUndefLit, TypeTableEntryIdUndefined,
TypeTableEntryIdNullLit, TypeTableEntryIdNull,
TypeTableEntryIdMaybe, TypeTableEntryIdMaybe,
TypeTableEntryIdErrorUnion, TypeTableEntryIdErrorUnion,
TypeTableEntryIdErrorSet, TypeTableEntryIdErrorSet,

View File

@ -232,10 +232,10 @@ bool type_is_complete(TypeTableEntry *type_entry) {
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdPointer: case TypeTableEntryIdPointer:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -268,10 +268,10 @@ bool type_has_zero_bits_known(TypeTableEntry *type_entry) {
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdPointer: case TypeTableEntryIdPointer:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -1333,10 +1333,10 @@ static bool type_allowed_in_packed_struct(TypeTableEntry *type_entry) {
zig_unreachable(); zig_unreachable();
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
@ -1374,10 +1374,10 @@ static bool type_allowed_in_extern(CodeGen *g, TypeTableEntry *type_entry) {
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
zig_unreachable(); zig_unreachable();
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
@ -1511,15 +1511,15 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
return g->builtin_types.entry_invalid; return g->builtin_types.entry_invalid;
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdArgTuple: case TypeTableEntryIdArgTuple:
case TypeTableEntryIdOpaque: case TypeTableEntryIdOpaque:
add_node_error(g, param_node->data.param_decl.type, add_node_error(g, param_node->data.param_decl.type,
buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name))); buf_sprintf("parameter of type '%s' not allowed", buf_ptr(&type_entry->name)));
return g->builtin_types.entry_invalid; return g->builtin_types.entry_invalid;
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
@ -1599,16 +1599,16 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
zig_unreachable(); zig_unreachable();
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdArgTuple: case TypeTableEntryIdArgTuple:
case TypeTableEntryIdOpaque: case TypeTableEntryIdOpaque:
add_node_error(g, fn_proto->return_type, add_node_error(g, fn_proto->return_type,
buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name))); buf_sprintf("return type '%s' not allowed", buf_ptr(&fn_type_id.return_type->name)));
return g->builtin_types.entry_invalid; return g->builtin_types.entry_invalid;
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
@ -3337,16 +3337,16 @@ TypeTableEntry *validate_var_type(CodeGen *g, AstNode *source_node, TypeTableEnt
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
return g->builtin_types.entry_invalid; return g->builtin_types.entry_invalid;
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdNull:
case TypeTableEntryIdUndefLit:
case TypeTableEntryIdNullLit:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdArgTuple: case TypeTableEntryIdArgTuple:
case TypeTableEntryIdOpaque: case TypeTableEntryIdOpaque:
add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed", add_node_error(g, source_node, buf_sprintf("variable of type '%s' not allowed",
buf_ptr(&type_entry->name))); buf_ptr(&type_entry->name)));
return g->builtin_types.entry_invalid; return g->builtin_types.entry_invalid;
case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdVoid: case TypeTableEntryIdVoid:
@ -3480,12 +3480,12 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) {
add_node_error(g, source_node, buf_sprintf("variable initialization is unreachable")); add_node_error(g, source_node, buf_sprintf("variable initialization is unreachable"));
implicit_type = g->builtin_types.entry_invalid; implicit_type = g->builtin_types.entry_invalid;
} else if ((!is_const || linkage == VarLinkageExternal) && } else if ((!is_const || linkage == VarLinkageExternal) &&
(implicit_type->id == TypeTableEntryIdNumLitFloat || (implicit_type->id == TypeTableEntryIdComptimeFloat ||
implicit_type->id == TypeTableEntryIdNumLitInt)) implicit_type->id == TypeTableEntryIdComptimeInt))
{ {
add_node_error(g, source_node, buf_sprintf("unable to infer variable type")); add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
implicit_type = g->builtin_types.entry_invalid; implicit_type = g->builtin_types.entry_invalid;
} else if (implicit_type->id == TypeTableEntryIdNullLit) { } else if (implicit_type->id == TypeTableEntryIdNull) {
add_node_error(g, source_node, buf_sprintf("unable to infer variable type")); add_node_error(g, source_node, buf_sprintf("unable to infer variable type"));
implicit_type = g->builtin_types.entry_invalid; implicit_type = g->builtin_types.entry_invalid;
} else if (implicit_type->id == TypeTableEntryIdMetaType && !is_const) { } else if (implicit_type->id == TypeTableEntryIdMetaType && !is_const) {
@ -3730,10 +3730,10 @@ static bool is_container(TypeTableEntry *type_entry) {
case TypeTableEntryIdInt: case TypeTableEntryIdInt:
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -3779,10 +3779,10 @@ void resolve_container_type(CodeGen *g, TypeTableEntry *type_entry) {
case TypeTableEntryIdInt: case TypeTableEntryIdInt:
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -4283,10 +4283,10 @@ bool handle_is_ptr(TypeTableEntry *type_entry) {
switch (type_entry->id) { switch (type_entry->id) {
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
@ -4568,7 +4568,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
case TypeTableEntryIdVoid: case TypeTableEntryIdVoid:
return (uint32_t)4149439618; return (uint32_t)4149439618;
case TypeTableEntryIdInt: case TypeTableEntryIdInt:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
{ {
uint32_t result = 1331471175; uint32_t result = 1331471175;
for (size_t i = 0; i < const_val->data.x_bigint.digit_count; i += 1) { for (size_t i = 0; i < const_val->data.x_bigint.digit_count; i += 1) {
@ -4609,7 +4609,7 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
default: default:
zig_unreachable(); zig_unreachable();
} }
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
{ {
float128_t f128 = bigfloat_to_f128(&const_val->data.x_bigfloat); float128_t f128 = bigfloat_to_f128(&const_val->data.x_bigfloat);
uint32_t ints[4]; uint32_t ints[4];
@ -4672,9 +4672,9 @@ static uint32_t hash_const_val(ConstExprValue *const_val) {
case TypeTableEntryIdPromise: case TypeTableEntryIdPromise:
// TODO better hashing algorithm // TODO better hashing algorithm
return 223048345; return 223048345;
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
return 162837799; return 162837799;
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
return 844854567; return 844854567;
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
// TODO better hashing algorithm // TODO better hashing algorithm
@ -4754,10 +4754,10 @@ static bool can_mutate_comptime_var_state(ConstExprValue *value) {
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdInt: case TypeTableEntryIdInt:
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
case TypeTableEntryIdFn: case TypeTableEntryIdFn:
@ -4819,10 +4819,10 @@ static bool return_type_is_cacheable(TypeTableEntry *return_type) {
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdInt: case TypeTableEntryIdInt:
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
case TypeTableEntryIdFn: case TypeTableEntryIdFn:
@ -4930,10 +4930,10 @@ bool type_requires_comptime(TypeTableEntry *type_entry) {
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
case TypeTableEntryIdOpaque: case TypeTableEntryIdOpaque:
zig_unreachable(); zig_unreachable();
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
@ -5070,7 +5070,7 @@ ConstExprValue *create_const_signed(TypeTableEntry *type, int64_t x) {
void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value) { void init_const_float(ConstExprValue *const_val, TypeTableEntry *type, double value) {
const_val->special = ConstValSpecialStatic; const_val->special = ConstValSpecialStatic;
const_val->type = type; const_val->type = type;
if (type->id == TypeTableEntryIdNumLitFloat) { if (type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_init_64(&const_val->data.x_bigfloat, value); bigfloat_init_64(&const_val->data.x_bigfloat, value);
} else if (type->id == TypeTableEntryIdFloat) { } else if (type->id == TypeTableEntryIdFloat) {
switch (type->data.floating.bit_count) { switch (type->data.floating.bit_count) {
@ -5350,10 +5350,10 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
default: default:
zig_unreachable(); zig_unreachable();
} }
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
return bigfloat_cmp(&a->data.x_bigfloat, &b->data.x_bigfloat) == CmpEQ; return bigfloat_cmp(&a->data.x_bigfloat, &b->data.x_bigfloat) == CmpEQ;
case TypeTableEntryIdInt: case TypeTableEntryIdInt:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ; return bigint_cmp(&a->data.x_bigint, &b->data.x_bigint) == CmpEQ;
case TypeTableEntryIdPointer: case TypeTableEntryIdPointer:
case TypeTableEntryIdFn: case TypeTableEntryIdFn:
@ -5410,9 +5410,9 @@ bool const_values_equal(ConstExprValue *a, ConstExprValue *b) {
return false; return false;
} }
return true; return true;
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
zig_panic("TODO"); zig_panic("TODO");
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
zig_panic("TODO"); zig_panic("TODO");
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
if (a->data.x_maybe == nullptr || b->data.x_maybe == nullptr) { if (a->data.x_maybe == nullptr || b->data.x_maybe == nullptr) {
@ -5514,7 +5514,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
case TypeTableEntryIdVoid: case TypeTableEntryIdVoid:
buf_appendf(buf, "{}"); buf_appendf(buf, "{}");
return; return;
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
bigfloat_append_buf(buf, &const_val->data.x_bigfloat); bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
return; return;
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
@ -5542,7 +5542,7 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
default: default:
zig_unreachable(); zig_unreachable();
} }
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdInt: case TypeTableEntryIdInt:
bigint_append_buf(buf, &const_val->data.x_bigint, 10); bigint_append_buf(buf, &const_val->data.x_bigint, 10);
return; return;
@ -5646,12 +5646,12 @@ void render_const_value(CodeGen *g, Buf *buf, ConstExprValue *const_val) {
buf_appendf(buf, "}"); buf_appendf(buf, "}");
return; return;
} }
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
{ {
buf_appendf(buf, "null"); buf_appendf(buf, "null");
return; return;
} }
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
{ {
buf_appendf(buf, "undefined"); buf_appendf(buf, "undefined");
return; return;
@ -5761,10 +5761,10 @@ uint32_t type_id_hash(TypeId x) {
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdStruct: case TypeTableEntryIdStruct:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
case TypeTableEntryIdEnum: case TypeTableEntryIdEnum:
@ -5807,10 +5807,10 @@ bool type_id_eql(TypeId a, TypeId b) {
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdStruct: case TypeTableEntryIdStruct:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdPromise: case TypeTableEntryIdPromise:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -5929,10 +5929,10 @@ static const TypeTableEntryId all_type_ids[] = {
TypeTableEntryIdPointer, TypeTableEntryIdPointer,
TypeTableEntryIdArray, TypeTableEntryIdArray,
TypeTableEntryIdStruct, TypeTableEntryIdStruct,
TypeTableEntryIdNumLitFloat, TypeTableEntryIdComptimeFloat,
TypeTableEntryIdNumLitInt, TypeTableEntryIdComptimeInt,
TypeTableEntryIdUndefLit, TypeTableEntryIdUndefined,
TypeTableEntryIdNullLit, TypeTableEntryIdNull,
TypeTableEntryIdMaybe, TypeTableEntryIdMaybe,
TypeTableEntryIdErrorUnion, TypeTableEntryIdErrorUnion,
TypeTableEntryIdErrorSet, TypeTableEntryIdErrorSet,
@ -5980,13 +5980,13 @@ size_t type_id_index(TypeTableEntry *entry) {
if (entry->data.structure.is_slice) if (entry->data.structure.is_slice)
return 25; return 25;
return 8; return 8;
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
return 9; return 9;
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
return 10; return 10;
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
return 11; return 11;
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
return 12; return 12;
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
return 13; return 13;
@ -6038,14 +6038,14 @@ const char *type_id_name(TypeTableEntryId id) {
return "Array"; return "Array";
case TypeTableEntryIdStruct: case TypeTableEntryIdStruct:
return "Struct"; return "Struct";
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
return "FloatLiteral"; return "ComptimeFloat";
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
return "IntLiteral"; return "ComptimeInt";
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
return "UndefinedLiteral"; return "Undefined";
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
return "NullLiteral"; return "Null";
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
return "Nullable"; return "Nullable";
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:

View File

@ -4916,10 +4916,10 @@ static LLVMValueRef pack_const_int(CodeGen *g, LLVMTypeRef big_int_type_ref, Con
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
@ -5362,10 +5362,10 @@ static LLVMValueRef gen_const_val(CodeGen *g, ConstExprValue *const_val, const c
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
@ -5604,7 +5604,7 @@ static void do_code_gen(CodeGen *g) {
TldVar *tld_var = g->global_vars.at(i); TldVar *tld_var = g->global_vars.at(i);
VariableTableEntry *var = tld_var->var; VariableTableEntry *var = tld_var->var;
if (var->value->type->id == TypeTableEntryIdNumLitFloat) { if (var->value->type->id == TypeTableEntryIdComptimeFloat) {
// Generate debug info for it but that's it. // Generate debug info for it but that's it.
ConstExprValue *const_val = var->value; ConstExprValue *const_val = var->value;
assert(const_val->special != ConstValSpecialRuntime); assert(const_val->special != ConstValSpecialRuntime);
@ -5618,7 +5618,7 @@ static void do_code_gen(CodeGen *g) {
continue; continue;
} }
if (var->value->type->id == TypeTableEntryIdNumLitInt) { if (var->value->type->id == TypeTableEntryIdComptimeInt) {
// Generate debug info for it but that's it. // Generate debug info for it but that's it.
ConstExprValue *const_val = var->value; ConstExprValue *const_val = var->value;
assert(const_val->special != ConstValSpecialRuntime); assert(const_val->special != ConstValSpecialRuntime);
@ -6012,25 +6012,27 @@ static void define_builtin_types(CodeGen *g) {
g->builtin_types.entry_block = entry; g->builtin_types.entry_block = entry;
} }
{ {
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNumLitFloat); TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdComptimeFloat);
buf_init_from_str(&entry->name, "(float literal)"); buf_init_from_str(&entry->name, "comptime_float");
entry->zero_bits = true; entry->zero_bits = true;
g->builtin_types.entry_num_lit_float = entry; g->builtin_types.entry_num_lit_float = entry;
g->primitive_type_table.put(&entry->name, entry);
} }
{ {
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNumLitInt); TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdComptimeInt);
buf_init_from_str(&entry->name, "(integer literal)"); buf_init_from_str(&entry->name, "comptime_int");
entry->zero_bits = true; entry->zero_bits = true;
g->builtin_types.entry_num_lit_int = entry; g->builtin_types.entry_num_lit_int = entry;
g->primitive_type_table.put(&entry->name, entry);
} }
{ {
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUndefLit); TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdUndefined);
buf_init_from_str(&entry->name, "(undefined)"); buf_init_from_str(&entry->name, "(undefined)");
entry->zero_bits = true; entry->zero_bits = true;
g->builtin_types.entry_undef = entry; g->builtin_types.entry_undef = entry;
} }
{ {
TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNullLit); TypeTableEntry *entry = new_type_table_entry(TypeTableEntryIdNull);
buf_init_from_str(&entry->name, "(null)"); buf_init_from_str(&entry->name, "(null)");
entry->zero_bits = true; entry->zero_bits = true;
g->builtin_types.entry_null = entry; g->builtin_types.entry_null = entry;
@ -6495,10 +6497,10 @@ static void define_builtin_compile_vars(CodeGen *g) {
" Slice: Slice,\n" " Slice: Slice,\n"
" Array: Array,\n" " Array: Array,\n"
" Struct: Struct,\n" " Struct: Struct,\n"
" FloatLiteral: void,\n" " ComptimeFloat: void,\n"
" IntLiteral: void,\n" " ComptimeInt: void,\n"
" UndefinedLiteral: void,\n" " Undefined: void,\n"
" NullLiteral: void,\n" " Null: void,\n"
" Nullable: Nullable,\n" " Nullable: Nullable,\n"
" ErrorUnion: ErrorUnion,\n" " ErrorUnion: ErrorUnion,\n"
" ErrorSet: ErrorSet,\n" " ErrorSet: ErrorSet,\n"
@ -7070,10 +7072,10 @@ static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry
switch (type_entry->id) { switch (type_entry->id) {
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
@ -7255,10 +7257,10 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdArgTuple: case TypeTableEntryIdArgTuple:
case TypeTableEntryIdPromise: case TypeTableEntryIdPromise:
zig_unreachable(); zig_unreachable();
@ -7407,11 +7409,11 @@ static void gen_h_file(CodeGen *g) {
case TypeTableEntryIdInt: case TypeTableEntryIdInt:
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdPointer: case TypeTableEntryIdPointer:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:

View File

@ -6945,14 +6945,14 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
} }
static bool const_val_fits_in_num_lit(ConstExprValue *const_val, TypeTableEntry *num_lit_type) { static bool const_val_fits_in_num_lit(ConstExprValue *const_val, TypeTableEntry *num_lit_type) {
return ((num_lit_type->id == TypeTableEntryIdNumLitFloat && return ((num_lit_type->id == TypeTableEntryIdComptimeFloat &&
(const_val->type->id == TypeTableEntryIdFloat || const_val->type->id == TypeTableEntryIdNumLitFloat)) || (const_val->type->id == TypeTableEntryIdFloat || const_val->type->id == TypeTableEntryIdComptimeFloat)) ||
(num_lit_type->id == TypeTableEntryIdNumLitInt && (num_lit_type->id == TypeTableEntryIdComptimeInt &&
(const_val->type->id == TypeTableEntryIdInt || const_val->type->id == TypeTableEntryIdNumLitInt))); (const_val->type->id == TypeTableEntryIdInt || const_val->type->id == TypeTableEntryIdComptimeInt)));
} }
static bool float_has_fraction(ConstExprValue *const_val) { static bool float_has_fraction(ConstExprValue *const_val) {
if (const_val->type->id == TypeTableEntryIdNumLitFloat) { if (const_val->type->id == TypeTableEntryIdComptimeFloat) {
return bigfloat_has_fraction(&const_val->data.x_bigfloat); return bigfloat_has_fraction(&const_val->data.x_bigfloat);
} else if (const_val->type->id == TypeTableEntryIdFloat) { } else if (const_val->type->id == TypeTableEntryIdFloat) {
switch (const_val->type->data.floating.bit_count) { switch (const_val->type->data.floating.bit_count) {
@ -6975,7 +6975,7 @@ static bool float_has_fraction(ConstExprValue *const_val) {
} }
static void float_append_buf(Buf *buf, ConstExprValue *const_val) { static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
if (const_val->type->id == TypeTableEntryIdNumLitFloat) { if (const_val->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_append_buf(buf, &const_val->data.x_bigfloat); bigfloat_append_buf(buf, &const_val->data.x_bigfloat);
} else if (const_val->type->id == TypeTableEntryIdFloat) { } else if (const_val->type->id == TypeTableEntryIdFloat) {
switch (const_val->type->data.floating.bit_count) { switch (const_val->type->data.floating.bit_count) {
@ -7010,7 +7010,7 @@ static void float_append_buf(Buf *buf, ConstExprValue *const_val) {
} }
static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) { static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
if (const_val->type->id == TypeTableEntryIdNumLitFloat) { if (const_val->type->id == TypeTableEntryIdComptimeFloat) {
bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat); bigint_init_bigfloat(bigint, &const_val->data.x_bigfloat);
} else if (const_val->type->id == TypeTableEntryIdFloat) { } else if (const_val->type->id == TypeTableEntryIdFloat) {
switch (const_val->type->data.floating.bit_count) { switch (const_val->type->data.floating.bit_count) {
@ -7046,7 +7046,7 @@ static void float_init_bigint(BigInt *bigint, ConstExprValue *const_val) {
} }
static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) { static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
if (dest_val->type->id == TypeTableEntryIdNumLitFloat) { if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat); bigfloat_init_bigfloat(&dest_val->data.x_bigfloat, bigfloat);
} else if (dest_val->type->id == TypeTableEntryIdFloat) { } else if (dest_val->type->id == TypeTableEntryIdFloat) {
switch (dest_val->type->data.floating.bit_count) { switch (dest_val->type->data.floating.bit_count) {
@ -7068,7 +7068,7 @@ static void float_init_bigfloat(ConstExprValue *dest_val, BigFloat *bigfloat) {
} }
static void float_init_f32(ConstExprValue *dest_val, float x) { static void float_init_f32(ConstExprValue *dest_val, float x) {
if (dest_val->type->id == TypeTableEntryIdNumLitFloat) { if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_init_32(&dest_val->data.x_bigfloat, x); bigfloat_init_32(&dest_val->data.x_bigfloat, x);
} else if (dest_val->type->id == TypeTableEntryIdFloat) { } else if (dest_val->type->id == TypeTableEntryIdFloat) {
switch (dest_val->type->data.floating.bit_count) { switch (dest_val->type->data.floating.bit_count) {
@ -7094,7 +7094,7 @@ static void float_init_f32(ConstExprValue *dest_val, float x) {
} }
static void float_init_f64(ConstExprValue *dest_val, double x) { static void float_init_f64(ConstExprValue *dest_val, double x) {
if (dest_val->type->id == TypeTableEntryIdNumLitFloat) { if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_init_64(&dest_val->data.x_bigfloat, x); bigfloat_init_64(&dest_val->data.x_bigfloat, x);
} else if (dest_val->type->id == TypeTableEntryIdFloat) { } else if (dest_val->type->id == TypeTableEntryIdFloat) {
switch (dest_val->type->data.floating.bit_count) { switch (dest_val->type->data.floating.bit_count) {
@ -7120,7 +7120,7 @@ static void float_init_f64(ConstExprValue *dest_val, double x) {
} }
static void float_init_f128(ConstExprValue *dest_val, float128_t x) { static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
if (dest_val->type->id == TypeTableEntryIdNumLitFloat) { if (dest_val->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_init_128(&dest_val->data.x_bigfloat, x); bigfloat_init_128(&dest_val->data.x_bigfloat, x);
} else if (dest_val->type->id == TypeTableEntryIdFloat) { } else if (dest_val->type->id == TypeTableEntryIdFloat) {
switch (dest_val->type->data.floating.bit_count) { switch (dest_val->type->data.floating.bit_count) {
@ -7150,7 +7150,7 @@ static void float_init_f128(ConstExprValue *dest_val, float128_t x) {
} }
static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) { static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val) {
if (src_val->type->id == TypeTableEntryIdNumLitFloat) { if (src_val->type->id == TypeTableEntryIdComptimeFloat) {
float_init_bigfloat(dest_val, &src_val->data.x_bigfloat); float_init_bigfloat(dest_val, &src_val->data.x_bigfloat);
} else if (src_val->type->id == TypeTableEntryIdFloat) { } else if (src_val->type->id == TypeTableEntryIdFloat) {
switch (src_val->type->data.floating.bit_count) { switch (src_val->type->data.floating.bit_count) {
@ -7173,7 +7173,7 @@ static void float_init_float(ConstExprValue *dest_val, ConstExprValue *src_val)
static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) { static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type); assert(op1->type == op2->type);
if (op1->type->id == TypeTableEntryIdNumLitFloat) { if (op1->type->id == TypeTableEntryIdComptimeFloat) {
return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat); return bigfloat_cmp(&op1->data.x_bigfloat, &op2->data.x_bigfloat);
} else if (op1->type->id == TypeTableEntryIdFloat) { } else if (op1->type->id == TypeTableEntryIdFloat) {
switch (op1->type->data.floating.bit_count) { switch (op1->type->data.floating.bit_count) {
@ -7210,7 +7210,7 @@ static Cmp float_cmp(ConstExprValue *op1, ConstExprValue *op2) {
} }
static Cmp float_cmp_zero(ConstExprValue *op) { static Cmp float_cmp_zero(ConstExprValue *op) {
if (op->type->id == TypeTableEntryIdNumLitFloat) { if (op->type->id == TypeTableEntryIdComptimeFloat) {
return bigfloat_cmp_zero(&op->data.x_bigfloat); return bigfloat_cmp_zero(&op->data.x_bigfloat);
} else if (op->type->id == TypeTableEntryIdFloat) { } else if (op->type->id == TypeTableEntryIdFloat) {
switch (op->type->data.floating.bit_count) { switch (op->type->data.floating.bit_count) {
@ -7251,7 +7251,7 @@ static Cmp float_cmp_zero(ConstExprValue *op) {
static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type); assert(op1->type == op2->type);
out_val->type = op1->type; out_val->type = op1->type;
if (op1->type->id == TypeTableEntryIdNumLitFloat) { if (op1->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_add(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); bigfloat_add(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
} else if (op1->type->id == TypeTableEntryIdFloat) { } else if (op1->type->id == TypeTableEntryIdFloat) {
switch (op1->type->data.floating.bit_count) { switch (op1->type->data.floating.bit_count) {
@ -7275,7 +7275,7 @@ static void float_add(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type); assert(op1->type == op2->type);
out_val->type = op1->type; out_val->type = op1->type;
if (op1->type->id == TypeTableEntryIdNumLitFloat) { if (op1->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_sub(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); bigfloat_sub(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
} else if (op1->type->id == TypeTableEntryIdFloat) { } else if (op1->type->id == TypeTableEntryIdFloat) {
switch (op1->type->data.floating.bit_count) { switch (op1->type->data.floating.bit_count) {
@ -7299,7 +7299,7 @@ static void float_sub(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type); assert(op1->type == op2->type);
out_val->type = op1->type; out_val->type = op1->type;
if (op1->type->id == TypeTableEntryIdNumLitFloat) { if (op1->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_mul(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); bigfloat_mul(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
} else if (op1->type->id == TypeTableEntryIdFloat) { } else if (op1->type->id == TypeTableEntryIdFloat) {
switch (op1->type->data.floating.bit_count) { switch (op1->type->data.floating.bit_count) {
@ -7323,7 +7323,7 @@ static void float_mul(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type); assert(op1->type == op2->type);
out_val->type = op1->type; out_val->type = op1->type;
if (op1->type->id == TypeTableEntryIdNumLitFloat) { if (op1->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_div(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); bigfloat_div(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
} else if (op1->type->id == TypeTableEntryIdFloat) { } else if (op1->type->id == TypeTableEntryIdFloat) {
switch (op1->type->data.floating.bit_count) { switch (op1->type->data.floating.bit_count) {
@ -7347,7 +7347,7 @@ static void float_div(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type); assert(op1->type == op2->type);
out_val->type = op1->type; out_val->type = op1->type;
if (op1->type->id == TypeTableEntryIdNumLitFloat) { if (op1->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_div_trunc(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); bigfloat_div_trunc(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
} else if (op1->type->id == TypeTableEntryIdFloat) { } else if (op1->type->id == TypeTableEntryIdFloat) {
switch (op1->type->data.floating.bit_count) { switch (op1->type->data.floating.bit_count) {
@ -7382,7 +7382,7 @@ static void float_div_trunc(ConstExprValue *out_val, ConstExprValue *op1, ConstE
static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type); assert(op1->type == op2->type);
out_val->type = op1->type; out_val->type = op1->type;
if (op1->type->id == TypeTableEntryIdNumLitFloat) { if (op1->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_div_floor(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); bigfloat_div_floor(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
} else if (op1->type->id == TypeTableEntryIdFloat) { } else if (op1->type->id == TypeTableEntryIdFloat) {
switch (op1->type->data.floating.bit_count) { switch (op1->type->data.floating.bit_count) {
@ -7407,7 +7407,7 @@ static void float_div_floor(ConstExprValue *out_val, ConstExprValue *op1, ConstE
static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type); assert(op1->type == op2->type);
out_val->type = op1->type; out_val->type = op1->type;
if (op1->type->id == TypeTableEntryIdNumLitFloat) { if (op1->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_rem(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); bigfloat_rem(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
} else if (op1->type->id == TypeTableEntryIdFloat) { } else if (op1->type->id == TypeTableEntryIdFloat) {
switch (op1->type->data.floating.bit_count) { switch (op1->type->data.floating.bit_count) {
@ -7431,7 +7431,7 @@ static void float_rem(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) { static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprValue *op2) {
assert(op1->type == op2->type); assert(op1->type == op2->type);
out_val->type = op1->type; out_val->type = op1->type;
if (op1->type->id == TypeTableEntryIdNumLitFloat) { if (op1->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_mod(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat); bigfloat_mod(&out_val->data.x_bigfloat, &op1->data.x_bigfloat, &op2->data.x_bigfloat);
} else if (op1->type->id == TypeTableEntryIdFloat) { } else if (op1->type->id == TypeTableEntryIdFloat) {
switch (op1->type->data.floating.bit_count) { switch (op1->type->data.floating.bit_count) {
@ -7456,7 +7456,7 @@ static void float_mod(ConstExprValue *out_val, ConstExprValue *op1, ConstExprVal
static void float_negate(ConstExprValue *out_val, ConstExprValue *op) { static void float_negate(ConstExprValue *out_val, ConstExprValue *op) {
out_val->type = op->type; out_val->type = op->type;
if (op->type->id == TypeTableEntryIdNumLitFloat) { if (op->type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat); bigfloat_negate(&out_val->data.x_bigfloat, &op->data.x_bigfloat);
} else if (op->type->id == TypeTableEntryIdFloat) { } else if (op->type->id == TypeTableEntryIdFloat) {
switch (op->type->data.floating.bit_count) { switch (op->type->data.floating.bit_count) {
@ -7530,9 +7530,9 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
assert(const_val->special != ConstValSpecialRuntime); assert(const_val->special != ConstValSpecialRuntime);
bool const_val_is_int = (const_val->type->id == TypeTableEntryIdInt || bool const_val_is_int = (const_val->type->id == TypeTableEntryIdInt ||
const_val->type->id == TypeTableEntryIdNumLitInt); const_val->type->id == TypeTableEntryIdComptimeInt);
bool const_val_is_float = (const_val->type->id == TypeTableEntryIdFloat || bool const_val_is_float = (const_val->type->id == TypeTableEntryIdFloat ||
const_val->type->id == TypeTableEntryIdNumLitFloat); const_val->type->id == TypeTableEntryIdComptimeFloat);
if (other_type->id == TypeTableEntryIdFloat) { if (other_type->id == TypeTableEntryIdFloat) {
return true; return true;
} else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) { } else if (other_type->id == TypeTableEntryIdInt && const_val_is_int) {
@ -7576,7 +7576,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
return true; return true;
} }
} }
if (explicit_cast && (other_type->id == TypeTableEntryIdInt || other_type->id == TypeTableEntryIdNumLitInt) && if (explicit_cast && (other_type->id == TypeTableEntryIdInt || other_type->id == TypeTableEntryIdComptimeInt) &&
const_val_is_float) const_val_is_float)
{ {
if (float_has_fraction(const_val)) { if (float_has_fraction(const_val)) {
@ -7589,7 +7589,7 @@ static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruc
buf_ptr(&other_type->name))); buf_ptr(&other_type->name)));
return false; return false;
} else { } else {
if (other_type->id == TypeTableEntryIdNumLitInt) { if (other_type->id == TypeTableEntryIdComptimeInt) {
return true; return true;
} else { } else {
BigInt bigint; BigInt bigint;
@ -7960,7 +7960,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
// implicit conversion from null literal to maybe type // implicit conversion from null literal to maybe type
if (expected_type->id == TypeTableEntryIdMaybe && if (expected_type->id == TypeTableEntryIdMaybe &&
actual_type->id == TypeTableEntryIdNullLit) actual_type->id == TypeTableEntryIdNull)
{ {
return ImplicitCastMatchResultYes; return ImplicitCastMatchResultYes;
} }
@ -8078,8 +8078,8 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
// implicit number literal to typed number // implicit number literal to typed number
// implicit number literal to &const integer // implicit number literal to &const integer
if (actual_type->id == TypeTableEntryIdNumLitFloat || if (actual_type->id == TypeTableEntryIdComptimeFloat ||
actual_type->id == TypeTableEntryIdNumLitInt) actual_type->id == TypeTableEntryIdComptimeInt)
{ {
if (expected_type->id == TypeTableEntryIdPointer && if (expected_type->id == TypeTableEntryIdPointer &&
expected_type->data.pointer.is_const) expected_type->data.pointer.is_const)
@ -8099,9 +8099,9 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
// implicit typed number to integer or float literal. // implicit typed number to integer or float literal.
// works when the number is known // works when the number is known
if (value->value.special == ConstValSpecialStatic) { if (value->value.special == ConstValSpecialStatic) {
if (actual_type->id == TypeTableEntryIdInt && expected_type->id == TypeTableEntryIdNumLitInt) { if (actual_type->id == TypeTableEntryIdInt && expected_type->id == TypeTableEntryIdComptimeInt) {
return ImplicitCastMatchResultYes; return ImplicitCastMatchResultYes;
} else if (actual_type->id == TypeTableEntryIdFloat && expected_type->id == TypeTableEntryIdNumLitFloat) { } else if (actual_type->id == TypeTableEntryIdFloat && expected_type->id == TypeTableEntryIdComptimeFloat) {
return ImplicitCastMatchResultYes; return ImplicitCastMatchResultYes;
} }
} }
@ -8142,7 +8142,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
} }
// implicit undefined literal to anything // implicit undefined literal to anything
if (actual_type->id == TypeTableEntryIdUndefLit) { if (actual_type->id == TypeTableEntryIdUndefined) {
return ImplicitCastMatchResultYes; return ImplicitCastMatchResultYes;
} }
@ -8190,7 +8190,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
} }
} }
bool any_are_null = (prev_inst->value.type->id == TypeTableEntryIdNullLit); bool any_are_null = (prev_inst->value.type->id == TypeTableEntryIdNull);
bool convert_to_const_slice = false; bool convert_to_const_slice = false;
for (size_t i = 1; i < instruction_count; i += 1) { for (size_t i = 1; i < instruction_count; i += 1) {
IrInstruction *cur_inst = instructions[i]; IrInstruction *cur_inst = instructions[i];
@ -8469,12 +8469,12 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
} }
} }
if (prev_type->id == TypeTableEntryIdNullLit) { if (prev_type->id == TypeTableEntryIdNull) {
prev_inst = cur_inst; prev_inst = cur_inst;
continue; continue;
} }
if (cur_type->id == TypeTableEntryIdNullLit) { if (cur_type->id == TypeTableEntryIdNull) {
any_are_null = true; any_are_null = true;
continue; continue;
} }
@ -8546,17 +8546,17 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
continue; continue;
} }
if (cur_type->id == TypeTableEntryIdUndefLit) { if (cur_type->id == TypeTableEntryIdUndefined) {
continue; continue;
} }
if (prev_type->id == TypeTableEntryIdUndefLit) { if (prev_type->id == TypeTableEntryIdUndefined) {
prev_inst = cur_inst; prev_inst = cur_inst;
continue; continue;
} }
if (prev_type->id == TypeTableEntryIdNumLitInt || if (prev_type->id == TypeTableEntryIdComptimeInt ||
prev_type->id == TypeTableEntryIdNumLitFloat) prev_type->id == TypeTableEntryIdComptimeFloat)
{ {
if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) { if (ir_num_lit_fits_in_other_type(ira, prev_inst, cur_type, false)) {
prev_inst = cur_inst; prev_inst = cur_inst;
@ -8566,8 +8566,8 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
} }
} }
if (cur_type->id == TypeTableEntryIdNumLitInt || if (cur_type->id == TypeTableEntryIdComptimeInt ||
cur_type->id == TypeTableEntryIdNumLitFloat) cur_type->id == TypeTableEntryIdComptimeFloat)
{ {
if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) { if (ir_num_lit_fits_in_other_type(ira, cur_inst, prev_type, false)) {
continue; continue;
@ -8671,13 +8671,13 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
} else if (expected_type != nullptr && expected_type->id == TypeTableEntryIdErrorUnion) { } else if (expected_type != nullptr && expected_type->id == TypeTableEntryIdErrorUnion) {
return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type); return get_error_union_type(ira->codegen, err_set_type, expected_type->data.error_union.payload_type);
} else { } else {
if (prev_inst->value.type->id == TypeTableEntryIdNumLitInt || if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt ||
prev_inst->value.type->id == TypeTableEntryIdNumLitFloat) prev_inst->value.type->id == TypeTableEntryIdComptimeFloat)
{ {
ir_add_error_node(ira, source_node, ir_add_error_node(ira, source_node,
buf_sprintf("unable to make error union out of number literal")); buf_sprintf("unable to make error union out of number literal"));
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
} else if (prev_inst->value.type->id == TypeTableEntryIdNullLit) { } else if (prev_inst->value.type->id == TypeTableEntryIdNull) {
ir_add_error_node(ira, source_node, ir_add_error_node(ira, source_node,
buf_sprintf("unable to make error union out of null literal")); buf_sprintf("unable to make error union out of null literal"));
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
@ -8685,9 +8685,9 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type); return get_error_union_type(ira->codegen, err_set_type, prev_inst->value.type);
} }
} }
} else if (any_are_null && prev_inst->value.type->id != TypeTableEntryIdNullLit) { } else if (any_are_null && prev_inst->value.type->id != TypeTableEntryIdNull) {
if (prev_inst->value.type->id == TypeTableEntryIdNumLitInt || if (prev_inst->value.type->id == TypeTableEntryIdComptimeInt ||
prev_inst->value.type->id == TypeTableEntryIdNumLitFloat) prev_inst->value.type->id == TypeTableEntryIdComptimeFloat)
{ {
ir_add_error_node(ira, source_node, ir_add_error_node(ira, source_node,
buf_sprintf("unable to make maybe out of number literal")); buf_sprintf("unable to make maybe out of number literal"));
@ -8743,7 +8743,7 @@ static void eval_const_expr_implicit_cast(CastOp cast_op,
break; break;
} }
case CastOpNumLitToConcrete: case CastOpNumLitToConcrete:
if (other_val->type->id == TypeTableEntryIdNumLitFloat) { if (other_val->type->id == TypeTableEntryIdComptimeFloat) {
assert(new_type->id == TypeTableEntryIdFloat); assert(new_type->id == TypeTableEntryIdFloat);
switch (new_type->data.floating.bit_count) { switch (new_type->data.floating.bit_count) {
case 32: case 32:
@ -8758,7 +8758,7 @@ static void eval_const_expr_implicit_cast(CastOp cast_op,
default: default:
zig_unreachable(); zig_unreachable();
} }
} else if (other_val->type->id == TypeTableEntryIdNumLitInt) { } else if (other_val->type->id == TypeTableEntryIdComptimeInt) {
bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint); bigint_init_bigint(&const_val->data.x_bigint, &other_val->data.x_bigint);
} else { } else {
zig_unreachable(); zig_unreachable();
@ -9601,9 +9601,9 @@ static IrInstruction *ir_analyze_number_to_literal(IrAnalyze *ira, IrInstruction
IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope, IrInstruction *result = ir_create_const(&ira->new_irb, source_instr->scope,
source_instr->source_node, wanted_type); source_instr->source_node, wanted_type);
if (wanted_type->id == TypeTableEntryIdNumLitFloat) { if (wanted_type->id == TypeTableEntryIdComptimeFloat) {
float_init_float(&result->value, val); float_init_float(&result->value, val);
} else if (wanted_type->id == TypeTableEntryIdNumLitInt) { } else if (wanted_type->id == TypeTableEntryIdComptimeInt) {
bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint); bigint_init_bigint(&result->value.data.x_bigint, &val->data.x_bigint);
} else { } else {
zig_unreachable(); zig_unreachable();
@ -9978,8 +9978,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type; TypeTableEntry *wanted_child_type = wanted_type->data.maybe.child_type;
if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk) { if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk) {
return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
} else if (actual_type->id == TypeTableEntryIdNumLitInt || } else if (actual_type->id == TypeTableEntryIdComptimeInt ||
actual_type->id == TypeTableEntryIdNumLitFloat) actual_type->id == TypeTableEntryIdComptimeFloat)
{ {
if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) { if (ir_num_lit_fits_in_other_type(ira, value, wanted_child_type, true)) {
return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type); return ir_analyze_maybe_wrap(ira, source_instr, value, wanted_type);
@ -10004,7 +10004,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// explicit cast from null literal to maybe type // explicit cast from null literal to maybe type
if (wanted_type->id == TypeTableEntryIdMaybe && if (wanted_type->id == TypeTableEntryIdMaybe &&
actual_type->id == TypeTableEntryIdNullLit) actual_type->id == TypeTableEntryIdNull)
{ {
return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type); return ir_analyze_null_to_maybe(ira, source_instr, value, wanted_type);
} }
@ -10013,8 +10013,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
if (wanted_type->id == TypeTableEntryIdErrorUnion) { if (wanted_type->id == TypeTableEntryIdErrorUnion) {
if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, source_node).id == ConstCastResultIdOk) { if (types_match_const_cast_only(ira, wanted_type->data.error_union.payload_type, actual_type, source_node).id == ConstCastResultIdOk) {
return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
} else if (actual_type->id == TypeTableEntryIdNumLitInt || } else if (actual_type->id == TypeTableEntryIdComptimeInt ||
actual_type->id == TypeTableEntryIdNumLitFloat) actual_type->id == TypeTableEntryIdComptimeFloat)
{ {
if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) { if (ir_num_lit_fits_in_other_type(ira, value, wanted_type->data.error_union.payload_type, true)) {
return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type); return ir_analyze_err_wrap_payload(ira, source_instr, value, wanted_type);
@ -10061,9 +10061,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
{ {
TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type; TypeTableEntry *wanted_child_type = wanted_type->data.error_union.payload_type->data.maybe.child_type;
if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk || if (types_match_const_cast_only(ira, wanted_child_type, actual_type, source_node).id == ConstCastResultIdOk ||
actual_type->id == TypeTableEntryIdNullLit || actual_type->id == TypeTableEntryIdNull ||
actual_type->id == TypeTableEntryIdNumLitInt || actual_type->id == TypeTableEntryIdComptimeInt ||
actual_type->id == TypeTableEntryIdNumLitFloat) actual_type->id == TypeTableEntryIdComptimeFloat)
{ {
IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value); IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.error_union.payload_type, value);
if (type_is_invalid(cast1->value.type)) if (type_is_invalid(cast1->value.type))
@ -10079,8 +10079,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// explicit cast from number literal to another type // explicit cast from number literal to another type
// explicit cast from number literal to &const integer // explicit cast from number literal to &const integer
if (actual_type->id == TypeTableEntryIdNumLitFloat || if (actual_type->id == TypeTableEntryIdComptimeFloat ||
actual_type->id == TypeTableEntryIdNumLitInt) actual_type->id == TypeTableEntryIdComptimeInt)
{ {
ensure_complete_type(ira->codegen, wanted_type); ensure_complete_type(ira->codegen, wanted_type);
if (type_is_invalid(wanted_type)) if (type_is_invalid(wanted_type))
@ -10109,9 +10109,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
return cast2; return cast2;
} else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) {
CastOp op; CastOp op;
if ((actual_type->id == TypeTableEntryIdNumLitFloat && if ((actual_type->id == TypeTableEntryIdComptimeFloat &&
wanted_type->id == TypeTableEntryIdFloat) || wanted_type->id == TypeTableEntryIdFloat) ||
(actual_type->id == TypeTableEntryIdNumLitInt && (actual_type->id == TypeTableEntryIdComptimeInt &&
wanted_type->id == TypeTableEntryIdInt)) wanted_type->id == TypeTableEntryIdInt))
{ {
op = CastOpNumLitToConcrete; op = CastOpNumLitToConcrete;
@ -10131,8 +10131,8 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// explicit cast from typed number to integer or float literal. // explicit cast from typed number to integer or float literal.
// works when the number is known at compile time // works when the number is known at compile time
if (instr_is_comptime(value) && if (instr_is_comptime(value) &&
((actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdNumLitInt) || ((actual_type->id == TypeTableEntryIdInt && wanted_type->id == TypeTableEntryIdComptimeInt) ||
(actual_type->id == TypeTableEntryIdFloat && wanted_type->id == TypeTableEntryIdNumLitFloat))) (actual_type->id == TypeTableEntryIdFloat && wanted_type->id == TypeTableEntryIdComptimeFloat)))
{ {
return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type); return ir_analyze_number_to_literal(ira, source_instr, value, wanted_type);
} }
@ -10230,7 +10230,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
// explicit cast from undefined to anything // explicit cast from undefined to anything
if (actual_type->id == TypeTableEntryIdUndefLit) { if (actual_type->id == TypeTableEntryIdUndefined) {
return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type); return ir_analyze_undefined_to_anything(ira, source_instr, value, wanted_type);
} }
@ -10627,19 +10627,19 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
IrBinOp op_id = bin_op_instruction->op_id; IrBinOp op_id = bin_op_instruction->op_id;
bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq); bool is_equality_cmp = (op_id == IrBinOpCmpEq || op_id == IrBinOpCmpNotEq);
if (is_equality_cmp && if (is_equality_cmp &&
((op1->value.type->id == TypeTableEntryIdNullLit && op2->value.type->id == TypeTableEntryIdMaybe) || ((op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdMaybe) ||
(op2->value.type->id == TypeTableEntryIdNullLit && op1->value.type->id == TypeTableEntryIdMaybe) || (op2->value.type->id == TypeTableEntryIdNull && op1->value.type->id == TypeTableEntryIdMaybe) ||
(op1->value.type->id == TypeTableEntryIdNullLit && op2->value.type->id == TypeTableEntryIdNullLit))) (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull)))
{ {
if (op1->value.type->id == TypeTableEntryIdNullLit && op2->value.type->id == TypeTableEntryIdNullLit) { if (op1->value.type->id == TypeTableEntryIdNull && op2->value.type->id == TypeTableEntryIdNull) {
ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base); ConstExprValue *out_val = ir_build_const_from(ira, &bin_op_instruction->base);
out_val->data.x_bool = (op_id == IrBinOpCmpEq); out_val->data.x_bool = (op_id == IrBinOpCmpEq);
return ira->codegen->builtin_types.entry_bool; return ira->codegen->builtin_types.entry_bool;
} }
IrInstruction *maybe_op; IrInstruction *maybe_op;
if (op1->value.type->id == TypeTableEntryIdNullLit) { if (op1->value.type->id == TypeTableEntryIdNull) {
maybe_op = op2; maybe_op = op2;
} else if (op2->value.type->id == TypeTableEntryIdNullLit) { } else if (op2->value.type->id == TypeTableEntryIdNull) {
maybe_op = op1; maybe_op = op1;
} else { } else {
zig_unreachable(); zig_unreachable();
@ -10759,8 +10759,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
zig_unreachable(); // handled above zig_unreachable(); // handled above
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdInt: case TypeTableEntryIdInt:
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
break; break;
@ -10795,8 +10795,8 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdStruct: case TypeTableEntryIdStruct:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdUnion: case TypeTableEntryIdUnion:
@ -10818,10 +10818,10 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
bool one_possible_value = !type_requires_comptime(resolved_type) && !type_has_bits(resolved_type); bool one_possible_value = !type_requires_comptime(resolved_type) && !type_has_bits(resolved_type);
if (one_possible_value || (value_is_comptime(op1_val) && value_is_comptime(op2_val))) { if (one_possible_value || (value_is_comptime(op1_val) && value_is_comptime(op2_val))) {
bool answer; bool answer;
if (resolved_type->id == TypeTableEntryIdNumLitFloat || resolved_type->id == TypeTableEntryIdFloat) { if (resolved_type->id == TypeTableEntryIdComptimeFloat || resolved_type->id == TypeTableEntryIdFloat) {
Cmp cmp_result = float_cmp(op1_val, op2_val); Cmp cmp_result = float_cmp(op1_val, op2_val);
answer = resolve_cmp_op_id(op_id, cmp_result); answer = resolve_cmp_op_id(op_id, cmp_result);
} else if (resolved_type->id == TypeTableEntryIdNumLitInt || resolved_type->id == TypeTableEntryIdInt) { } else if (resolved_type->id == TypeTableEntryIdComptimeInt || resolved_type->id == TypeTableEntryIdInt) {
Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint); Cmp cmp_result = bigint_cmp(&op1_val->data.x_bigint, &op2_val->data.x_bigint);
answer = resolve_cmp_op_id(op_id, cmp_result); answer = resolve_cmp_op_id(op_id, cmp_result);
} else { } else {
@ -10885,12 +10885,12 @@ static int ir_eval_math_op(TypeTableEntry *type_entry, ConstExprValue *op1_val,
bool is_int; bool is_int;
bool is_float; bool is_float;
Cmp op2_zcmp; Cmp op2_zcmp;
if (type_entry->id == TypeTableEntryIdInt || type_entry->id == TypeTableEntryIdNumLitInt) { if (type_entry->id == TypeTableEntryIdInt || type_entry->id == TypeTableEntryIdComptimeInt) {
is_int = true; is_int = true;
is_float = false; is_float = false;
op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint); op2_zcmp = bigint_cmp_zero(&op2_val->data.x_bigint);
} else if (type_entry->id == TypeTableEntryIdFloat || } else if (type_entry->id == TypeTableEntryIdFloat ||
type_entry->id == TypeTableEntryIdNumLitFloat) type_entry->id == TypeTableEntryIdComptimeFloat)
{ {
is_int = false; is_int = false;
is_float = true; is_float = true;
@ -11064,7 +11064,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
if (type_is_invalid(op1->value.type)) if (type_is_invalid(op1->value.type))
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
if (op1->value.type->id != TypeTableEntryIdInt && op1->value.type->id != TypeTableEntryIdNumLitInt) { if (op1->value.type->id != TypeTableEntryIdInt && op1->value.type->id != TypeTableEntryIdComptimeInt) {
ir_add_error(ira, &bin_op_instruction->base, ir_add_error(ira, &bin_op_instruction->base,
buf_sprintf("bit shifting operation expected integer type, found '%s'", buf_sprintf("bit shifting operation expected integer type, found '%s'",
buf_ptr(&op1->value.type->name))); buf_ptr(&op1->value.type->name)));
@ -11077,7 +11077,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
IrInstruction *casted_op2; IrInstruction *casted_op2;
IrBinOp op_id = bin_op_instruction->op_id; IrBinOp op_id = bin_op_instruction->op_id;
if (op1->value.type->id == TypeTableEntryIdNumLitInt) { if (op1->value.type->id == TypeTableEntryIdComptimeInt) {
casted_op2 = op2; casted_op2 = op2;
if (op_id == IrBinOpBitShiftLeftLossy) { if (op_id == IrBinOpBitShiftLeftLossy) {
@ -11122,7 +11122,7 @@ static TypeTableEntry *ir_analyze_bit_shift(IrAnalyze *ira, IrInstructionBinOp *
ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false); ir_num_lit_fits_in_other_type(ira, result_instruction, op1->value.type, false);
return op1->value.type; return op1->value.type;
} else if (op1->value.type->id == TypeTableEntryIdNumLitInt) { } else if (op1->value.type->id == TypeTableEntryIdComptimeInt) {
ir_add_error(ira, &bin_op_instruction->base, ir_add_error(ira, &bin_op_instruction->base,
buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known")); buf_sprintf("LHS of shift must be an integer type, or RHS must be compile-time known"));
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
@ -11158,15 +11158,15 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
if (type_is_invalid(resolved_type)) if (type_is_invalid(resolved_type))
return resolved_type; return resolved_type;
bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdNumLitInt; bool is_int = resolved_type->id == TypeTableEntryIdInt || resolved_type->id == TypeTableEntryIdComptimeInt;
bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdNumLitFloat; bool is_float = resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdComptimeFloat;
bool is_signed_div = ( bool is_signed_div = (
(resolved_type->id == TypeTableEntryIdInt && resolved_type->data.integral.is_signed) || (resolved_type->id == TypeTableEntryIdInt && resolved_type->data.integral.is_signed) ||
resolved_type->id == TypeTableEntryIdFloat || resolved_type->id == TypeTableEntryIdFloat ||
(resolved_type->id == TypeTableEntryIdNumLitFloat && (resolved_type->id == TypeTableEntryIdComptimeFloat &&
((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) != ((bigfloat_cmp_zero(&op1->value.data.x_bigfloat) != CmpGT) !=
(bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) || (bigfloat_cmp_zero(&op2->value.data.x_bigfloat) != CmpGT))) ||
(resolved_type->id == TypeTableEntryIdNumLitInt && (resolved_type->id == TypeTableEntryIdComptimeInt &&
((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) != ((bigint_cmp_zero(&op1->value.data.x_bigint) != CmpGT) !=
(bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT))) (bigint_cmp_zero(&op2->value.data.x_bigint) != CmpGT)))
); );
@ -11267,7 +11267,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
} }
if (resolved_type->id == TypeTableEntryIdNumLitInt) { if (resolved_type->id == TypeTableEntryIdComptimeInt) {
if (op_id == IrBinOpAddWrap) { if (op_id == IrBinOpAddWrap) {
op_id = IrBinOpAdd; op_id = IrBinOpAdd;
} else if (op_id == IrBinOpSubWrap) { } else if (op_id == IrBinOpSubWrap) {
@ -11641,11 +11641,11 @@ static VarClassRequired get_var_class_required(TypeTableEntry *type_entry) {
case TypeTableEntryIdFn: case TypeTableEntryIdFn:
case TypeTableEntryIdPromise: case TypeTableEntryIdPromise:
return VarClassRequiredAny; return VarClassRequiredAny;
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdOpaque: case TypeTableEntryIdOpaque:
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
@ -11910,10 +11910,10 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdVoid: case TypeTableEntryIdVoid:
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -11934,10 +11934,10 @@ static TypeTableEntry *ir_analyze_instruction_export(IrAnalyze *ira, IrInstructi
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdPointer: case TypeTableEntryIdPointer:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -12149,7 +12149,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
} }
bool comptime_arg = param_decl_node->data.param_decl.is_inline || bool comptime_arg = param_decl_node->data.param_decl.is_inline ||
casted_arg->value.type->id == TypeTableEntryIdNumLitInt || casted_arg->value.type->id == TypeTableEntryIdNumLitFloat; casted_arg->value.type->id == TypeTableEntryIdComptimeInt || casted_arg->value.type->id == TypeTableEntryIdComptimeFloat;
ConstExprValue *arg_val; ConstExprValue *arg_val;
@ -12174,8 +12174,8 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
var->shadowable = !comptime_arg; var->shadowable = !comptime_arg;
*next_proto_i += 1; *next_proto_i += 1;
} else if (casted_arg->value.type->id == TypeTableEntryIdNumLitInt || } else if (casted_arg->value.type->id == TypeTableEntryIdComptimeInt ||
casted_arg->value.type->id == TypeTableEntryIdNumLitFloat) casted_arg->value.type->id == TypeTableEntryIdComptimeFloat)
{ {
ir_add_error(ira, casted_arg, ir_add_error(ira, casted_arg,
buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557")); buf_sprintf("compiler bug: integer and float literals in var args function must be casted. https://github.com/ziglang/zig/issues/557"));
@ -12898,10 +12898,10 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
case TypeTableEntryIdPointer: case TypeTableEntryIdPointer:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdStruct: case TypeTableEntryIdStruct:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -12935,10 +12935,10 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap); bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap);
bool is_float = (expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdNumLitFloat); bool is_float = (expr_type->id == TypeTableEntryIdFloat || expr_type->id == TypeTableEntryIdComptimeFloat);
if ((expr_type->id == TypeTableEntryIdInt && expr_type->data.integral.is_signed) || if ((expr_type->id == TypeTableEntryIdInt && expr_type->data.integral.is_signed) ||
expr_type->id == TypeTableEntryIdNumLitInt || (is_float && !is_wrap_op)) expr_type->id == TypeTableEntryIdComptimeInt || (is_float && !is_wrap_op))
{ {
if (instr_is_comptime(value)) { if (instr_is_comptime(value)) {
ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad); ConstExprValue *target_const_val = ir_resolve_const(ira, value, UndefBad);
@ -12954,7 +12954,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
} else { } else {
bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint); bigint_negate(&out_val->data.x_bigint, &target_const_val->data.x_bigint);
} }
if (is_wrap_op || is_float || expr_type->id == TypeTableEntryIdNumLitInt) { if (is_wrap_op || is_float || expr_type->id == TypeTableEntryIdComptimeInt) {
return expr_type; return expr_type;
} }
@ -13150,10 +13150,10 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
if (type_is_invalid(resolved_type)) if (type_is_invalid(resolved_type))
return resolved_type; return resolved_type;
if (resolved_type->id == TypeTableEntryIdNumLitFloat || if (resolved_type->id == TypeTableEntryIdComptimeFloat ||
resolved_type->id == TypeTableEntryIdNumLitInt || resolved_type->id == TypeTableEntryIdComptimeInt ||
resolved_type->id == TypeTableEntryIdNullLit || resolved_type->id == TypeTableEntryIdNull ||
resolved_type->id == TypeTableEntryIdUndefLit) resolved_type->id == TypeTableEntryIdUndefined)
{ {
ir_add_error_node(ira, phi_instruction->base.source_node, ir_add_error_node(ira, phi_instruction->base.source_node,
buf_sprintf("unable to infer expression type")); buf_sprintf("unable to infer expression type"));
@ -14213,10 +14213,10 @@ static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructi
switch (type_entry->id) { switch (type_entry->id) {
case TypeTableEntryIdInvalid: case TypeTableEntryIdInvalid:
zig_unreachable(); // handled above zig_unreachable(); // handled above
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
@ -14479,8 +14479,8 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
case TypeTableEntryIdInvalid: // handled above case TypeTableEntryIdInvalid: // handled above
zig_unreachable(); zig_unreachable();
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdArgTuple: case TypeTableEntryIdArgTuple:
case TypeTableEntryIdOpaque: case TypeTableEntryIdOpaque:
@ -14495,8 +14495,8 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
case TypeTableEntryIdPointer: case TypeTableEntryIdPointer:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdStruct: case TypeTableEntryIdStruct:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -14587,8 +14587,8 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
case TypeTableEntryIdInvalid: // handled above case TypeTableEntryIdInvalid: // handled above
zig_unreachable(); zig_unreachable();
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdArgTuple: case TypeTableEntryIdArgTuple:
case TypeTableEntryIdOpaque: case TypeTableEntryIdOpaque:
@ -14603,8 +14603,8 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
case TypeTableEntryIdPointer: case TypeTableEntryIdPointer:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdStruct: case TypeTableEntryIdStruct:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -14656,11 +14656,11 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
case TypeTableEntryIdInvalid: // handled above case TypeTableEntryIdInvalid: // handled above
zig_unreachable(); zig_unreachable();
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
@ -14713,7 +14713,7 @@ static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrIn
ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value); ir_build_test_nonnull_from(&ira->new_irb, &instruction->base, value);
return ira->codegen->builtin_types.entry_bool; return ira->codegen->builtin_types.entry_bool;
} else if (type_entry->id == TypeTableEntryIdNullLit) { } else if (type_entry->id == TypeTableEntryIdNull) {
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
out_val->data.x_bool = false; out_val->data.x_bool = false;
return ira->codegen->builtin_types.entry_bool; return ira->codegen->builtin_types.entry_bool;
@ -15020,8 +15020,8 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
case TypeTableEntryIdBool: case TypeTableEntryIdBool:
case TypeTableEntryIdInt: case TypeTableEntryIdInt:
case TypeTableEntryIdFloat: case TypeTableEntryIdFloat:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdPointer: case TypeTableEntryIdPointer:
case TypeTableEntryIdPromise: case TypeTableEntryIdPromise:
case TypeTableEntryIdFn: case TypeTableEntryIdFn:
@ -15099,8 +15099,8 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdStruct: case TypeTableEntryIdStruct:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
@ -15618,10 +15618,10 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
case TypeTableEntryIdPromise: case TypeTableEntryIdPromise:
case TypeTableEntryIdArray: case TypeTableEntryIdArray:
case TypeTableEntryIdStruct: case TypeTableEntryIdStruct:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdMaybe: case TypeTableEntryIdMaybe:
case TypeTableEntryIdErrorUnion: case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdErrorSet: case TypeTableEntryIdErrorSet:
@ -16280,10 +16280,10 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
case TypeTableEntryIdVoid: case TypeTableEntryIdVoid:
case TypeTableEntryIdBool: case TypeTableEntryIdBool:
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdArgTuple: case TypeTableEntryIdArgTuple:
@ -17143,7 +17143,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
if (dest_type->id != TypeTableEntryIdInt && if (dest_type->id != TypeTableEntryIdInt &&
dest_type->id != TypeTableEntryIdNumLitInt) dest_type->id != TypeTableEntryIdComptimeInt)
{ {
ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name))); ir_add_error(ira, dest_type_value, buf_sprintf("expected integer type, found '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
@ -17155,7 +17155,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
if (src_type->id != TypeTableEntryIdInt && if (src_type->id != TypeTableEntryIdInt &&
src_type->id != TypeTableEntryIdNumLitInt) src_type->id != TypeTableEntryIdComptimeInt)
{ {
ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name))); ir_add_error(ira, target, buf_sprintf("expected integer type, found '%s'", buf_ptr(&src_type->name)));
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
@ -17876,10 +17876,10 @@ static TypeTableEntry *ir_analyze_instruction_align_of(IrAnalyze *ira, IrInstruc
zig_unreachable(); zig_unreachable();
case TypeTableEntryIdMetaType: case TypeTableEntryIdMetaType:
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdBoundFn: case TypeTableEntryIdBoundFn:
@ -18377,8 +18377,8 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
if (!end_val) if (!end_val)
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
assert(start_val->type->id == TypeTableEntryIdInt || start_val->type->id == TypeTableEntryIdNumLitInt); assert(start_val->type->id == TypeTableEntryIdInt || start_val->type->id == TypeTableEntryIdComptimeInt);
assert(end_val->type->id == TypeTableEntryIdInt || end_val->type->id == TypeTableEntryIdNumLitInt); assert(end_val->type->id == TypeTableEntryIdInt || end_val->type->id == TypeTableEntryIdComptimeInt);
AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint, AstNode *prev_node = rangeset_add_range(&rs, &start_val->data.x_bigint, &end_val->data.x_bigint,
start_value->source_node); start_value->source_node);
if (prev_node != nullptr) { if (prev_node != nullptr) {
@ -18610,10 +18610,10 @@ static void buf_write_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdPromise: case TypeTableEntryIdPromise:
zig_unreachable(); zig_unreachable();
case TypeTableEntryIdVoid: case TypeTableEntryIdVoid:
@ -18677,10 +18677,10 @@ static void buf_read_value_bytes(CodeGen *codegen, uint8_t *buf, ConstExprValue
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
case TypeTableEntryIdPromise: case TypeTableEntryIdPromise:
zig_unreachable(); zig_unreachable();
case TypeTableEntryIdVoid: case TypeTableEntryIdVoid:
@ -18758,10 +18758,10 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
ir_add_error(ira, dest_type_value, ir_add_error(ira, dest_type_value,
buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name))); buf_sprintf("unable to @bitCast from type '%s'", buf_ptr(&src_type->name)));
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
@ -18784,10 +18784,10 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
case TypeTableEntryIdNamespace: case TypeTableEntryIdNamespace:
case TypeTableEntryIdBlock: case TypeTableEntryIdBlock:
case TypeTableEntryIdUnreachable: case TypeTableEntryIdUnreachable:
case TypeTableEntryIdNumLitFloat: case TypeTableEntryIdComptimeFloat:
case TypeTableEntryIdNumLitInt: case TypeTableEntryIdComptimeInt:
case TypeTableEntryIdUndefLit: case TypeTableEntryIdUndefined:
case TypeTableEntryIdNullLit: case TypeTableEntryIdNull:
ir_add_error(ira, dest_type_value, ir_add_error(ira, dest_type_value,
buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name))); buf_sprintf("unable to @bitCast to type '%s'", buf_ptr(&dest_type->name)));
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
@ -19560,7 +19560,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
if (type_is_invalid(op->value.type)) if (type_is_invalid(op->value.type))
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
bool ok_type = float_type->id == TypeTableEntryIdNumLitFloat || float_type->id == TypeTableEntryIdFloat; bool ok_type = float_type->id == TypeTableEntryIdComptimeFloat || float_type->id == TypeTableEntryIdFloat;
if (!ok_type) { if (!ok_type) {
ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name))); ir_add_error(ira, instruction->type, buf_sprintf("@sqrt does not support type '%s'", buf_ptr(&float_type->name)));
return ira->codegen->builtin_types.entry_invalid; return ira->codegen->builtin_types.entry_invalid;
@ -19577,7 +19577,7 @@ static TypeTableEntry *ir_analyze_instruction_sqrt(IrAnalyze *ira, IrInstruction
ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base); ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
if (float_type->id == TypeTableEntryIdNumLitFloat) { if (float_type->id == TypeTableEntryIdComptimeFloat) {
bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat); bigfloat_sqrt(&out_val->data.x_bigfloat, &val->data.x_bigfloat);
} else if (float_type->id == TypeTableEntryIdFloat) { } else if (float_type->id == TypeTableEntryIdFloat) {
switch (float_type->data.floating.bit_count) { switch (float_type->data.floating.bit_count) {

View File

@ -14,7 +14,7 @@ const TypeId = builtin.TypeId;
pub fn ln(x: var) @typeOf(x) { pub fn ln(x: var) @typeOf(x) {
const T = @typeOf(x); const T = @typeOf(x);
switch (@typeId(T)) { switch (@typeId(T)) {
TypeId.FloatLiteral => { TypeId.ComptimeFloat => {
return @typeOf(1.0)(ln_64(x)); return @typeOf(1.0)(ln_64(x));
}, },
TypeId.Float => { TypeId.Float => {
@ -24,7 +24,7 @@ pub fn ln(x: var) @typeOf(x) {
else => @compileError("ln not implemented for " ++ @typeName(T)), else => @compileError("ln not implemented for " ++ @typeName(T)),
}; };
}, },
TypeId.IntLiteral => { TypeId.ComptimeInt => {
return @typeOf(1)(math.floor(ln_64(f64(x)))); return @typeOf(1)(math.floor(ln_64(f64(x))));
}, },
TypeId.Int => { TypeId.Int => {

View File

@ -9,15 +9,15 @@ pub fn log(comptime T: type, base: T, x: T) T {
return math.log2(x); return math.log2(x);
} else if (base == 10) { } else if (base == 10) {
return math.log10(x); return math.log10(x);
} else if ((@typeId(T) == TypeId.Float or @typeId(T) == TypeId.FloatLiteral) and base == math.e) { } else if ((@typeId(T) == TypeId.Float or @typeId(T) == TypeId.ComptimeFloat) and base == math.e) {
return math.ln(x); return math.ln(x);
} }
switch (@typeId(T)) { switch (@typeId(T)) {
TypeId.FloatLiteral => { TypeId.ComptimeFloat => {
return @typeOf(1.0)(math.ln(f64(x)) / math.ln(f64(base))); return @typeOf(1.0)(math.ln(f64(x)) / math.ln(f64(base)));
}, },
TypeId.IntLiteral => { TypeId.ComptimeInt => {
return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(f64(base)))); return @typeOf(1)(math.floor(math.ln(f64(x)) / math.ln(f64(base))));
}, },
builtin.TypeId.Int => { builtin.TypeId.Int => {

View File

@ -14,7 +14,7 @@ const TypeId = builtin.TypeId;
pub fn log10(x: var) @typeOf(x) { pub fn log10(x: var) @typeOf(x) {
const T = @typeOf(x); const T = @typeOf(x);
switch (@typeId(T)) { switch (@typeId(T)) {
TypeId.FloatLiteral => { TypeId.ComptimeFloat => {
return @typeOf(1.0)(log10_64(x)); return @typeOf(1.0)(log10_64(x));
}, },
TypeId.Float => { TypeId.Float => {
@ -24,7 +24,7 @@ pub fn log10(x: var) @typeOf(x) {
else => @compileError("log10 not implemented for " ++ @typeName(T)), else => @compileError("log10 not implemented for " ++ @typeName(T)),
}; };
}, },
TypeId.IntLiteral => { TypeId.ComptimeInt => {
return @typeOf(1)(math.floor(log10_64(f64(x)))); return @typeOf(1)(math.floor(log10_64(f64(x))));
}, },
TypeId.Int => { TypeId.Int => {

View File

@ -14,7 +14,7 @@ const TypeId = builtin.TypeId;
pub fn log2(x: var) @typeOf(x) { pub fn log2(x: var) @typeOf(x) {
const T = @typeOf(x); const T = @typeOf(x);
switch (@typeId(T)) { switch (@typeId(T)) {
TypeId.FloatLiteral => { TypeId.ComptimeFloat => {
return @typeOf(1.0)(log2_64(x)); return @typeOf(1.0)(log2_64(x));
}, },
TypeId.Float => { TypeId.Float => {
@ -24,7 +24,7 @@ pub fn log2(x: var) @typeOf(x) {
else => @compileError("log2 not implemented for " ++ @typeName(T)), else => @compileError("log2 not implemented for " ++ @typeName(T)),
}; };
}, },
TypeId.IntLiteral => comptime { TypeId.ComptimeInt => comptime {
var result = 0; var result = 0;
var x_shifted = x; var x_shifted = x;
while (b: { while (b: {

View File

@ -14,9 +14,9 @@ const TypeId = builtin.TypeId;
pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) { pub fn sqrt(x: var) (if (@typeId(@typeOf(x)) == TypeId.Int) @IntType(false, @typeOf(x).bit_count / 2) else @typeOf(x)) {
const T = @typeOf(x); const T = @typeOf(x);
switch (@typeId(T)) { switch (@typeId(T)) {
TypeId.FloatLiteral => return T(@sqrt(f64, x)), // TODO upgrade to f128 TypeId.ComptimeFloat => return T(@sqrt(f64, x)), // TODO upgrade to f128
TypeId.Float => return @sqrt(T, x), TypeId.Float => return @sqrt(T, x),
TypeId.IntLiteral => comptime { TypeId.ComptimeInt => comptime {
if (x > @maxValue(u128)) { if (x > @maxValue(u128)) {
@compileError("sqrt not implemented for comptime_int greater than 128 bits"); @compileError("sqrt not implemented for comptime_int greater than 128 bits");
} }

View File

@ -329,14 +329,14 @@ fn testShrExact(x: u8) void {
assert(shifted == 0b00101101); assert(shifted == 0b00101101);
} }
test "big number addition" { test "comptime_int addition" {
comptime { comptime {
assert(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950); assert(35361831660712422535336160538497375248 + 101752735581729509668353361206450473702 == 137114567242441932203689521744947848950);
assert(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380); assert(594491908217841670578297176641415611445982232488944558774612 + 390603545391089362063884922208143568023166603618446395589768 == 985095453608931032642182098849559179469148836107390954364380);
} }
} }
test "big number multiplication" { test "comptime_int multiplication" {
comptime { comptime {
assert( assert(
45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567, 45960427431263824329884196484953148229 * 128339149605334697009938835852565949723 == 5898522172026096622534201617172456926982464453350084962781392314016180490567,
@ -347,13 +347,13 @@ test "big number multiplication" {
} }
} }
test "big number shifting" { test "comptime_int shifting" {
comptime { comptime {
assert((u128(1) << 127) == 0x80000000000000000000000000000000); assert((u128(1) << 127) == 0x80000000000000000000000000000000);
} }
} }
test "big number multi-limb shift and mask" { test "comptime_int multi-limb shift and mask" {
comptime { comptime {
var a = 0xefffffffa0000001eeeeeeefaaaaaaab; var a = 0xefffffffa0000001eeeeeeefaaaaaaab;
@ -370,7 +370,7 @@ test "big number multi-limb shift and mask" {
} }
} }
test "big number multi-limb partial shift right" { test "comptime_int multi-limb partial shift right" {
comptime { comptime {
var a = 0x1ffffffffeeeeeeee; var a = 0x1ffffffffeeeeeeee;
a >>= 16; a >>= 16;
@ -391,7 +391,7 @@ fn test_xor() void {
assert(0xFF ^ 0xFF == 0x00); assert(0xFF ^ 0xFF == 0x00);
} }
test "big number xor" { test "comptime_int xor" {
comptime { comptime {
assert(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); assert(0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF ^ 0x00000000000000000000000000000000 == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
assert(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF); assert(0xFFFFFFFFFFFFFFFF0000000000000000 ^ 0x0000000000000000FFFFFFFFFFFFFFFF == 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
@ -449,3 +449,15 @@ test "@sqrt" {
fn testSqrt(comptime T: type, x: T) void { fn testSqrt(comptime T: type, x: T) void {
assert(@sqrt(T, x * x) == x); assert(@sqrt(T, x * x) == x);
} }
test "comptime_int param and return" {
const a = comptimeAdd(35361831660712422535336160538497375248, 101752735581729509668353361206450473702);
assert(a == 137114567242441932203689521744947848950);
const b = comptimeAdd(594491908217841670578297176641415611445982232488944558774612, 390603545391089362063884922208143568023166603618446395589768);
assert(b == 985095453608931032642182098849559179469148836107390954364380);
}
fn comptimeAdd(comptime a: comptime_int, comptime b: comptime_int) comptime_int {
return a + b;
}

View File

@ -501,10 +501,10 @@ test "@typeId" {
assert(@typeId(*f32) == Tid.Pointer); assert(@typeId(*f32) == Tid.Pointer);
assert(@typeId([2]u8) == Tid.Array); assert(@typeId([2]u8) == Tid.Array);
assert(@typeId(AStruct) == Tid.Struct); assert(@typeId(AStruct) == Tid.Struct);
assert(@typeId(@typeOf(1)) == Tid.IntLiteral); assert(@typeId(@typeOf(1)) == Tid.ComptimeInt);
assert(@typeId(@typeOf(1.0)) == Tid.FloatLiteral); assert(@typeId(@typeOf(1.0)) == Tid.ComptimeFloat);
assert(@typeId(@typeOf(undefined)) == Tid.UndefinedLiteral); assert(@typeId(@typeOf(undefined)) == Tid.Undefined);
assert(@typeId(@typeOf(null)) == Tid.NullLiteral); assert(@typeId(@typeOf(null)) == Tid.Null);
assert(@typeId(?i32) == Tid.Nullable); assert(@typeId(?i32) == Tid.Nullable);
assert(@typeId(error!i32) == Tid.ErrorUnion); assert(@typeId(error!i32) == Tid.ErrorUnion);
assert(@typeId(error) == Tid.ErrorSet); assert(@typeId(error) == Tid.ErrorSet);

View File

@ -1539,7 +1539,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\fn foo() *const i32 { return y; } \\fn foo() *const i32 { return y; }
\\export fn entry() usize { return @sizeOf(@typeOf(foo)); } \\export fn entry() usize { return @sizeOf(@typeOf(foo)); }
, ,
".tmp_source.zig:3:30: error: expected type '*const i32', found '*const (integer literal)'", ".tmp_source.zig:3:30: error: expected type '*const i32', found '*const comptime_int'",
); );
cases.add( cases.add(
@ -1555,7 +1555,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\const x = 2 == 2.0; \\const x = 2 == 2.0;
\\export fn entry() usize { return @sizeOf(@typeOf(x)); } \\export fn entry() usize { return @sizeOf(@typeOf(x)); }
, ,
".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type '(float literal)'", ".tmp_source.zig:1:11: error: integer value 2 cannot be implicitly casted to type 'comptime_float'",
); );
cases.add( cases.add(
@ -2189,7 +2189,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ \\
\\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); } \\export fn entry() usize { return @sizeOf(@typeOf(block_aligned_stuff)); }
, ,
".tmp_source.zig:3:60: error: unable to perform binary not operation on type '(integer literal)'", ".tmp_source.zig:3:60: error: unable to perform binary not operation on type 'comptime_int'",
); );
cases.addCase(x: { cases.addCase(x: {
@ -3269,10 +3269,10 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ fn bar(self: *const Foo) void {} \\ fn bar(self: *const Foo) void {}
\\}; \\};
, ,
".tmp_source.zig:4:4: error: variable of type '*(integer literal)' must be const or comptime", ".tmp_source.zig:4:4: error: variable of type '*comptime_int' must be const or comptime",
".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime", ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime",
".tmp_source.zig:8:4: error: variable of type '(integer literal)' must be const or comptime", ".tmp_source.zig:8:4: error: variable of type 'comptime_int' must be const or comptime",
".tmp_source.zig:9:4: error: variable of type '(float literal)' must be const or comptime", ".tmp_source.zig:9:4: error: variable of type 'comptime_float' must be const or comptime",
".tmp_source.zig:10:4: error: variable of type '(block)' must be const or comptime", ".tmp_source.zig:10:4: error: variable of type '(block)' must be const or comptime",
".tmp_source.zig:11:4: error: variable of type '(null)' must be const or comptime", ".tmp_source.zig:11:4: error: variable of type '(null)' must be const or comptime",
".tmp_source.zig:12:4: error: variable of type 'Opaque' must be const or comptime", ".tmp_source.zig:12:4: error: variable of type 'Opaque' must be const or comptime",