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 {
38453845 return self.printInt(T, value);
38463846 } else if (@isFloat(T)) {
38473847 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);
38513848 } else {
38523849 @compileError("Unable to print type '" ++ @typeName(T) ++ "'");
38533850 }
......@@ -4102,12 +4099,6 @@ comptime {
41024099 </p>
41034100 {#see_also|Import from C Header File|@cImport|@cDefine|@cInclude#}
41044101 {#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#}
41114102 {#header_open|@clz#}
41124103 <pre><code class="zig">@clz(x: T) U</code></pre>
41134104 <p>
......@@ -6136,7 +6127,7 @@ hljs.registerLanguage("zig", function(t) {
61366127 a = t.IR + "\\s*\\(",
61376128 c = {
61386129 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",
61406131 literal: "true false null undefined"
61416132 },
61426133 n = [e, t.CLCM, t.CBCM, s, r];
src/all_types.hpp-9
......@@ -1354,7 +1354,6 @@ enum BuiltinFnId {
13541354 BuiltinFnIdSetRuntimeSafety,
13551355 BuiltinFnIdSetFloatMode,
13561356 BuiltinFnIdTypeName,
1357 BuiltinFnIdCanImplicitCast,
13581357 BuiltinFnIdPanic,
13591358 BuiltinFnIdPtrCast,
13601359 BuiltinFnIdBitCast,
......@@ -2065,7 +2064,6 @@ enum IrInstructionId {
20652064 IrInstructionIdCheckSwitchProngs,
20662065 IrInstructionIdCheckStatementIsVoid,
20672066 IrInstructionIdTypeName,
2068 IrInstructionIdCanImplicitCast,
20692067 IrInstructionIdDeclRef,
20702068 IrInstructionIdPanic,
20712069 IrInstructionIdTagName,
......@@ -2858,13 +2856,6 @@ struct IrInstructionTypeName {
28582856 IrInstruction *type_value;
28592857};
28602858
2861struct IrInstructionCanImplicitCast {
2862 IrInstruction base;
2863
2864 IrInstruction *type_value;
2865 IrInstruction *target_value;
2866};
2867
28682859struct IrInstructionDeclRef {
28692860 IrInstruction base;
28702861
src/codegen.cpp-2
......@@ -4625,7 +4625,6 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
46254625 case IrInstructionIdCheckSwitchProngs:
46264626 case IrInstructionIdCheckStatementIsVoid:
46274627 case IrInstructionIdTypeName:
4628 case IrInstructionIdCanImplicitCast:
46294628 case IrInstructionIdDeclRef:
46304629 case IrInstructionIdSwitchVar:
46314630 case IrInstructionIdOffsetOf:
......@@ -6277,7 +6276,6 @@ static void define_builtin_fns(CodeGen *g) {
62776276 create_builtin_fn(g, BuiltinFnIdCImport, "cImport", 1);
62786277 create_builtin_fn(g, BuiltinFnIdErrName, "errorName", 1);
62796278 create_builtin_fn(g, BuiltinFnIdTypeName, "typeName", 1);
6280 create_builtin_fn(g, BuiltinFnIdCanImplicitCast, "canImplicitCast", 2);
62816279 create_builtin_fn(g, BuiltinFnIdEmbedFile, "embedFile", 1);
62826280 create_builtin_fn(g, BuiltinFnIdCmpxchgWeak, "cmpxchgWeak", 6);
62836281 create_builtin_fn(g, BuiltinFnIdCmpxchgStrong, "cmpxchgStrong", 6);
src/ir.cpp-60
......@@ -585,10 +585,6 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionTypeName *) {
585585 return IrInstructionIdTypeName;
586586}
587587
588static constexpr IrInstructionId ir_instruction_id(IrInstructionCanImplicitCast *) {
589 return IrInstructionIdCanImplicitCast;
590}
591
592588static constexpr IrInstructionId ir_instruction_id(IrInstructionDeclRef *) {
593589 return IrInstructionIdDeclRef;
594590}
......@@ -2348,20 +2344,6 @@ static IrInstruction *ir_build_type_name(IrBuilder *irb, Scope *scope, AstNode *
23482344 return &instruction->base;
23492345}
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
23652347static IrInstruction *ir_build_decl_ref(IrBuilder *irb, Scope *scope, AstNode *source_node,
23662348 Tld *tld, LVal lval)
23672349{
......@@ -4132,21 +4114,6 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
41324114 IrInstruction *type_name = ir_build_type_name(irb, scope, node, arg0_value);
41334115 return ir_lval_wrap(irb, scope, type_name, lval);
41344116 }
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 }
41504117 case BuiltinFnIdPanic:
41514118 {
41524119 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
1840518372 return ira->codegen->builtin_types.entry_void;
1840618373}
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
1843218375static TypeTableEntry *ir_analyze_instruction_panic(IrAnalyze *ira, IrInstructionPanic *instruction) {
1843318376 IrInstruction *msg = instruction->msg->other;
1843418377 if (type_is_invalid(msg->value.type))
......@@ -19762,8 +19705,6 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
1976219705 return ir_analyze_instruction_check_switch_prongs(ira, (IrInstructionCheckSwitchProngs *)instruction);
1976319706 case IrInstructionIdCheckStatementIsVoid:
1976419707 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);
1976719708 case IrInstructionIdDeclRef:
1976819709 return ir_analyze_instruction_decl_ref(ira, (IrInstructionDeclRef *)instruction);
1976919710 case IrInstructionIdPanic:
......@@ -20043,7 +19984,6 @@ bool ir_has_side_effects(IrInstruction *instruction) {
2004319984 case IrInstructionIdIntToEnum:
2004419985 case IrInstructionIdIntToErr:
2004519986 case IrInstructionIdErrToInt:
20046 case IrInstructionIdCanImplicitCast:
2004719987 case IrInstructionIdDeclRef:
2004819988 case IrInstructionIdErrName:
2004919989 case IrInstructionIdTypeName:
src/ir_print.cpp-11
......@@ -913,14 +913,6 @@ static void ir_print_tag_name(IrPrint *irp, IrInstructionTagName *instruction) {
913913 ir_print_other_instruction(irp, instruction->target);
914914}
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
924916static void ir_print_ptr_type(IrPrint *irp, IrInstructionPtrType *instruction) {
925917 fprintf(irp->f, "&");
926918 if (instruction->align_value != nullptr) {
......@@ -1524,9 +1516,6 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
15241516 case IrInstructionIdTagName:
15251517 ir_print_tag_name(irp, (IrInstructionTagName *)instruction);
15261518 break;
1527 case IrInstructionIdCanImplicitCast:
1528 ir_print_can_implicit_cast(irp, (IrInstructionCanImplicitCast *)instruction);
1529 break;
15301519 case IrInstructionIdPtrType:
15311520 ir_print_ptr_type(irp, (IrInstructionPtrType *)instruction);
15321521 break;
test/cases/misc.zig-8
......@@ -523,14 +523,6 @@ test "@typeId" {
523523 }
524524}
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
534526test "@typeName" {
535527 const Struct = struct {};
536528 const Union = union {