authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-07 19:50:25-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-07 19:50:25-04:00
logb65203f5736199bdc8d98d27728be5e92a17d565
tree7029a118db8097d583a37b83f35a65106e11085d
parent688ff2830d82ea36a9f022ecb7cf4c2bf2e4c586

remove @canImplicitCast builtin

nobody will miss it

6 files changed, 1 insertions(+), 100 deletions(-)

doc/langref.html.in+1-10
...@@ -3845,9 +3845,6 @@ pub fn printValue(self: *OutStream, value: var) !void {...@@ -3845,9 +3845,6 @@ pub fn printValue(self: *OutStream, value: var) !void {
3845 return self.printInt(T, value);3845 return self.printInt(T, value);
3846 } else if (@isFloat(T)) {3846 } else if (@isFloat(T)) {
3847 return self.printFloat(T, value);3847 return self.printFloat(T, value);
3848 } else if (@canImplicitCast([]const u8, value)) {
3849 const casted_value = ([]const u8)(value);
3850 return self.write(casted_value);
3851 } else {3848 } else {
3852 @compileError("Unable to print type '" ++ @typeName(T) ++ "'");3849 @compileError("Unable to print type '" ++ @typeName(T) ++ "'");
3853 }3850 }
...@@ -4102,12 +4099,6 @@ comptime {...@@ -4102,12 +4099,6 @@ comptime {
4102 </p>4099 </p>
4103 {#see_also|Import from C Header File|@cImport|@cDefine|@cInclude#}4100 {#see_also|Import from C Header File|@cImport|@cDefine|@cInclude#}
4104 {#header_close#}4101 {#header_close#}
4105 {#header_open|@canImplicitCast#}
4106 <pre><code class="zig">@canImplicitCast(comptime T: type, value) bool</code></pre>
4107 <p>
4108 Returns whether a value can be implicitly casted to a given type.
4109 </p>
4110 {#header_close#}
4111 {#header_open|@clz#}4102 {#header_open|@clz#}
4112 <pre><code class="zig">@clz(x: T) U</code></pre>4103 <pre><code class="zig">@clz(x: T) U</code></pre>
4113 <p>4104 <p>
...@@ -6136,7 +6127,7 @@ hljs.registerLanguage("zig", function(t) {...@@ -6136,7 +6127,7 @@ hljs.registerLanguage("zig", function(t) {
6136 a = t.IR + "\\s*\\(",6127 a = t.IR + "\\s*\\(",
6137 c = {6128 c = {
6138 keyword: "const align var extern stdcallcc nakedcc volatile export pub noalias inline struct packed enum union break return try catch test continue unreachable comptime and or asm defer errdefer if else switch while for fn use bool f32 f64 void type noreturn error i8 u8 i16 u16 i32 u32 i64 u64 isize usize i8w u8w i16w i32w u32w i64w u64w isizew usizew c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong",6129 keyword: "const align var extern stdcallcc nakedcc volatile export pub noalias inline struct packed enum union break return try catch test continue unreachable comptime and or asm defer errdefer if else switch while for fn use bool f32 f64 void type noreturn error i8 u8 i16 u16 i32 u32 i64 u64 isize usize i8w u8w i16w i32w u32w i64w u64w isizew usizew c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong",
6139 built_in: "atomicLoad breakpoint returnAddress frameAddress fieldParentPtr setFloatMode IntType OpaqueType compileError compileLog setCold setRuntimeSafety setEvalBranchQuota offsetOf memcpy inlineCall setGlobalLinkage setGlobalSection divTrunc divFloor enumTagName intToPtr ptrToInt panic canImplicitCast ptrCast bitCast rem mod memset sizeOf alignOf alignCast maxValue minValue memberCount memberName memberType typeOf addWithOverflow subWithOverflow mulWithOverflow shlWithOverflow shlExact shrExact cInclude cDefine cUndef ctz clz import cImport errorName embedFile cmpxchgStrong cmpxchgWeak fence divExact truncate atomicRmw sqrt field typeInfo typeName newStackCall",6130 built_in: "atomicLoad breakpoint returnAddress frameAddress fieldParentPtr setFloatMode IntType OpaqueType compileError compileLog setCold setRuntimeSafety setEvalBranchQuota offsetOf memcpy inlineCall setGlobalLinkage setGlobalSection divTrunc divFloor enumTagName intToPtr ptrToInt panic ptrCast bitCast rem mod memset sizeOf alignOf alignCast maxValue minValue memberCount memberName memberType typeOf addWithOverflow subWithOverflow mulWithOverflow shlWithOverflow shlExact shrExact cInclude cDefine cUndef ctz clz import cImport errorName embedFile cmpxchgStrong cmpxchgWeak fence divExact truncate atomicRmw sqrt field typeInfo typeName newStackCall",
6140 literal: "true false null undefined"6131 literal: "true false null undefined"
6141 },6132 },
6142 n = [e, t.CLCM, t.CBCM, s, r];6133 n = [e, t.CLCM, t.CBCM, s, r];
src/all_types.hpp-9
...@@ -1354,7 +1354,6 @@ enum BuiltinFnId {...@@ -1354,7 +1354,6 @@ enum BuiltinFnId {
1354 BuiltinFnIdSetRuntimeSafety,1354 BuiltinFnIdSetRuntimeSafety,
1355 BuiltinFnIdSetFloatMode,1355 BuiltinFnIdSetFloatMode,
1356 BuiltinFnIdTypeName,1356 BuiltinFnIdTypeName,
1357 BuiltinFnIdCanImplicitCast,
1358 BuiltinFnIdPanic,1357 BuiltinFnIdPanic,
1359 BuiltinFnIdPtrCast,1358 BuiltinFnIdPtrCast,
1360 BuiltinFnIdBitCast,1359 BuiltinFnIdBitCast,
...@@ -2065,7 +2064,6 @@ enum IrInstructionId {...@@ -2065,7 +2064,6 @@ enum IrInstructionId {
2065 IrInstructionIdCheckSwitchProngs,2064 IrInstructionIdCheckSwitchProngs,
2066 IrInstructionIdCheckStatementIsVoid,2065 IrInstructionIdCheckStatementIsVoid,
2067 IrInstructionIdTypeName,2066 IrInstructionIdTypeName,
2068 IrInstructionIdCanImplicitCast,
2069 IrInstructionIdDeclRef,2067 IrInstructionIdDeclRef,
2070 IrInstructionIdPanic,2068 IrInstructionIdPanic,
2071 IrInstructionIdTagName,2069 IrInstructionIdTagName,
...@@ -2858,13 +2856,6 @@ struct IrInstructionTypeName {...@@ -2858,13 +2856,6 @@ struct IrInstructionTypeName {
2858 IrInstruction *type_value;2856 IrInstruction *type_value;
2859};2857};
28602858
2861struct IrInstructionCanImplicitCast {
2862 IrInstruction base;
2863
2864 IrInstruction *type_value;
2865 IrInstruction *target_value;
2866};
2867
2868struct IrInstructionDeclRef {2859struct IrInstructionDeclRef {
2869 IrInstruction base;2860 IrInstruction base;
28702861
src/codegen.cpp-2
...@@ -4625,7 +4625,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -4625,7 +4625,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
4625 case IrInstructionIdCheckSwitchProngs:4625 case IrInstructionIdCheckSwitchProngs:
4626 case IrInstructionIdCheckStatementIsVoid:4626 case IrInstructionIdCheckStatementIsVoid:
4627 case IrInstructionIdTypeName:4627 case IrInstructionIdTypeName:
4628 case IrInstructionIdCanImplicitCast:
4629 case IrInstructionIdDeclRef:4628 case IrInstructionIdDeclRef:
4630 case IrInstructionIdSwitchVar:4629 case IrInstructionIdSwitchVar:
4631 case IrInstructionIdOffsetOf:4630 case IrInstructionIdOffsetOf:
...@@ -6277,7 +6276,6 @@ static void define_builtin_fns(CodeGen *g) {...@@ -6277,7 +6276,6 @@ static void define_builtin_fns(CodeGen *g) {
6277 create_builtin_fn(g, BuiltinFnIdCImport, "cImport", 1);6276 create_builtin_fn(g, BuiltinFnIdCImport, "cImport", 1);
6278 create_builtin_fn(g, BuiltinFnIdErrName, "errorName", 1);6277 create_builtin_fn(g, BuiltinFnIdErrName, "errorName", 1);
6279 create_builtin_fn(g, BuiltinFnIdTypeName, "typeName", 1);6278 create_builtin_fn(g, BuiltinFnIdTypeName, "typeName", 1);
6280 create_builtin_fn(g, BuiltinFnIdCanImplicitCast, "canImplicitCast", 2);
6281 create_builtin_fn(g, BuiltinFnIdEmbedFile, "embedFile", 1);6279 create_builtin_fn(g, BuiltinFnIdEmbedFile, "embedFile", 1);
6282 create_builtin_fn(g, BuiltinFnIdCmpxchgWeak, "cmpxchgWeak", 6);6280 create_builtin_fn(g, BuiltinFnIdCmpxchgWeak, "cmpxchgWeak", 6);
6283 create_builtin_fn(g, BuiltinFnIdCmpxchgStrong, "cmpxchgStrong", 6);6281 create_builtin_fn(g, BuiltinFnIdCmpxchgStrong, "cmpxchgStrong", 6);
src/ir.cpp-60
...@@ -585,10 +585,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeName *) {...@@ -585,10 +585,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeName *) {
585 return IrInstructionIdTypeName;585 return IrInstructionIdTypeName;
586}586}
587587
588static constexpr IrInstructionId ir_instruction_id(IrInstructionCanImplicitCast *) {
589 return IrInstructionIdCanImplicitCast;
590}
591
592static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclRef *) {588static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclRef *) {
593 return IrInstructionIdDeclRef;589 return IrInstructionIdDeclRef;
594}590}
...@@ -2348,20 +2344,6 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *...@@ -2348,20 +2344,6 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *
2348 return &instruction->base;2344 return &instruction->base;
2349}2345}
23502346
2351static IrInstruction *ir_build_can_implicit_cast(IrBuilder *irb, Scope *scope, AstNode *source_node,
2352 IrInstruction *type_value, IrInstruction *target_value)
2353{
2354 IrInstructionCanImplicitCast *instruction = ir_build_instruction<IrInstructionCanImplicitCast>(
2355 irb, scope, source_node);
2356 instruction->type_value = type_value;
2357 instruction->target_value = target_value;
2358
2359 ir_ref_instruction(type_value, irb->current_basic_block);
2360 ir_ref_instruction(target_value, irb->current_basic_block);
2361
2362 return &instruction->base;
2363}
2364
2365static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node,2347static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node,
2366 Tld *tld, LVal lval)2348 Tld *tld, LVal lval)
2367{2349{
...@@ -4132,21 +4114,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -4132,21 +4114,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
4132 IrInstruction *type_name = ir_build_type_name(irb, scope, node, arg0_value);4114 IrInstruction *type_name = ir_build_type_name(irb, scope, node, arg0_value);
4133 return ir_lval_wrap(irb, scope, type_name, lval);4115 return ir_lval_wrap(irb, scope, type_name, lval);
4134 }4116 }
4135 case BuiltinFnIdCanImplicitCast:
4136 {
4137 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
4138 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
4139 if (arg0_value == irb->codegen->invalid_instruction)
4140 return arg0_value;
4141
4142 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
4143 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
4144 if (arg1_value == irb->codegen->invalid_instruction)
4145 return arg1_value;
4146
4147 IrInstruction *can_implicit_cast = ir_build_can_implicit_cast(irb, scope, node, arg0_value, arg1_value);
4148 return ir_lval_wrap(irb, scope, can_implicit_cast, lval);
4149 }
4150 case BuiltinFnIdPanic:4117 case BuiltinFnIdPanic:
4151 {4118 {
4152 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);4119 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
...@@ -18405,30 +18372,6 @@ static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze...@@ -18405,30 +18372,6 @@ static TypeTableEntry *ir_analyze_instruction_check_statement_is_void(IrAnalyze
18405 return ira->codegen->builtin_types.entry_void;18372 return ira->codegen->builtin_types.entry_void;
18406}18373}
1840718374
18408static TypeTableEntry *ir_analyze_instruction_can_implicit_cast(IrAnalyze *ira,
18409 IrInstructionCanImplicitCast *instruction)
18410{
18411 IrInstruction *type_value = instruction->type_value->other;
18412 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
18413 if (type_is_invalid(type_entry))
18414 return ira->codegen->builtin_types.entry_invalid;
18415
18416 IrInstruction *target_value = instruction->target_value->other;
18417 if (type_is_invalid(target_value->value.type))
18418 return ira->codegen->builtin_types.entry_invalid;
18419
18420 ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, type_entry, target_value->value.type,
18421 target_value);
18422
18423 if (result == ImplicitCastMatchResultReportedError) {
18424 zig_panic("TODO refactor implicit cast tester to return bool without reporting errors");
18425 }
18426
18427 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
18428 out_val->data.x_bool = (result == ImplicitCastMatchResultYes);
18429 return ira->codegen->builtin_types.entry_bool;
18430}
18431
18432static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {18375static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
18433 IrInstruction *msg = instruction->msg->other;18376 IrInstruction *msg = instruction->msg->other;
18434 if (type_is_invalid(msg->value.type))18377 if (type_is_invalid(msg->value.type))
...@@ -19762,8 +19705,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -19762,8 +19705,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
19762 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstructionCheckSwitchProngs *)instruction);19705 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstructionCheckSwitchProngs *)instruction);
19763 case IrInstructionIdCheckStatementIsVoid:19706 case IrInstructionIdCheckStatementIsVoid:
19764 return ir_analyze_instruction_check_statement_is_void(ira, (IrInstructionCheckStatementIsVoid *)instruction);19707 return ir_analyze_instruction_check_statement_is_void(ira, (IrInstructionCheckStatementIsVoid *)instruction);
19765 case IrInstructionIdCanImplicitCast:
19766 return ir_analyze_instruction_can_implicit_cast(ira, (IrInstructionCanImplicitCast *)instruction);
19767 case IrInstructionIdDeclRef:19708 case IrInstructionIdDeclRef:
19768 return ir_analyze_instruction_decl_ref(ira, (IrInstructionDeclRef *)instruction);19709 return ir_analyze_instruction_decl_ref(ira, (IrInstructionDeclRef *)instruction);
19769 case IrInstructionIdPanic:19710 case IrInstructionIdPanic:
...@@ -20043,7 +19984,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -20043,7 +19984,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
20043 case IrInstructionIdIntToEnum:19984 case IrInstructionIdIntToEnum:
20044 case IrInstructionIdIntToErr:19985 case IrInstructionIdIntToErr:
20045 case IrInstructionIdErrToInt:19986 case IrInstructionIdErrToInt:
20046 case IrInstructionIdCanImplicitCast:
20047 case IrInstructionIdDeclRef:19987 case IrInstructionIdDeclRef:
20048 case IrInstructionIdErrName:19988 case IrInstructionIdErrName:
20049 case IrInstructionIdTypeName:19989 case IrInstructionIdTypeName:
src/ir_print.cpp-11
...@@ -913,14 +913,6 @@ static void ir_print_tag_name(IrPrint *irp, IrInstructionTagName *instruction) {...@@ -913,14 +913,6 @@ static void ir_print_tag_name(IrPrint *irp, IrInstructionTagName *instruction) {
913 ir_print_other_instruction(irp, instruction->target);913 ir_print_other_instruction(irp, instruction->target);
914}914}
915915
916static void ir_print_can_implicit_cast(IrPrint *irp, IrInstructionCanImplicitCast *instruction) {
917 fprintf(irp->f, "@canImplicitCast(");
918 ir_print_other_instruction(irp, instruction->type_value);
919 fprintf(irp->f, ",");
920 ir_print_other_instruction(irp, instruction->target_value);
921 fprintf(irp->f, ")");
922}
923
924static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {916static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {
925 fprintf(irp->f, "&");917 fprintf(irp->f, "&");
926 if (instruction->align_value != nullptr) {918 if (instruction->align_value != nullptr) {
...@@ -1524,9 +1516,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1524,9 +1516,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1524 case IrInstructionIdTagName:1516 case IrInstructionIdTagName:
1525 ir_print_tag_name(irp, (IrInstructionTagName *)instruction);1517 ir_print_tag_name(irp, (IrInstructionTagName *)instruction);
1526 break;1518 break;
1527 case IrInstructionIdCanImplicitCast:
1528 ir_print_can_implicit_cast(irp, (IrInstructionCanImplicitCast *)instruction);
1529 break;
1530 case IrInstructionIdPtrType:1519 case IrInstructionIdPtrType:
1531 ir_print_ptr_type(irp, (IrInstructionPtrType *)instruction);1520 ir_print_ptr_type(irp, (IrInstructionPtrType *)instruction);
1532 break;1521 break;
test/cases/misc.zig-8
...@@ -523,14 +523,6 @@ test "@typeId" {...@@ -523,14 +523,6 @@ test "@typeId" {
523 }523 }
524}524}
525525
526test "@canImplicitCast" {
527 comptime {
528 assert(@canImplicitCast(i64, i32(3)));
529 assert(!@canImplicitCast(i32, f32(1.234)));
530 assert(@canImplicitCast([]const u8, "aoeu"));
531 }
532}
533
534test "@typeName" {526test "@typeName" {
535 const Struct = struct {};527 const Struct = struct {};
536 const Union = union {528 const Union = union {