zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit eb0b1d38ff91a144f0739dabbc24cb32776d8f2d (tree)
parent 73ab0afaddb6fd71a800b11b3bf807c8ca37a9e8
Author: Andrew Kelley <superjoe30@gmail.com>
Date:   Thu, 25 Oct 2018 12:52:12 -0400

remove 3 more implicit casts to const pointers

see #1465

Diffstat:
Mdoc/langref.html.in | 6------
Msrc/ir.cpp | 61-------------------------------------------------------------
2 files changed, 0 insertions(+), 67 deletions(-)

diff --git a/doc/langref.html.in b/doc/langref.html.in @@ -4035,12 +4035,6 @@ test "float widening" { {#header_open|Implicit Cast: E to E!T#} <p>TODO</p> {#header_close#} - {#header_open|Implicit Cast: comptime_int to *const integer#} - <p>TODO</p> - {#header_close#} - {#header_open|Implicit Cast: comptime_float to *const float#} - <p>TODO</p> - {#header_close#} {#header_open|Implicit Cast: compile-time known numbers#} <p>TODO</p> {#header_close#} diff --git a/src/ir.cpp b/src/ir.cpp @@ -10483,31 +10483,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } } - // cast from [N]T to *const []const T - if (wanted_type->id == ZigTypeIdPointer && - wanted_type->data.pointer.is_const && - is_slice(wanted_type->data.pointer.child_type) && - actual_type->id == ZigTypeIdArray) - { - ZigType *ptr_type = - wanted_type->data.pointer.child_type->data.structure.fields[slice_ptr_index].type_entry; - assert(ptr_type->id == ZigTypeIdPointer); - if ((ptr_type->data.pointer.is_const || actual_type->data.array.len == 0) && - types_match_const_cast_only(ira, ptr_type->data.pointer.child_type, actual_type->data.array.child_type, - source_node, false).id == ConstCastResultIdOk) - { - IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); - if (type_is_invalid(cast1->value.type)) - return ira->codegen->invalid_instruction; - - IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); - if (type_is_invalid(cast2->value.type)) - return ira->codegen->invalid_instruction; - - return cast2; - } - } - // cast from [N]T to ?[]const T if (wanted_type->id == ZigTypeIdOptional && is_slice(wanted_type->data.maybe.child_type) && @@ -10705,7 +10680,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } // cast from number literal to another type - // cast from number literal to *const integer if (actual_type->id == ZigTypeIdComptimeFloat || actual_type->id == ZigTypeIdComptimeInt) { @@ -10721,18 +10695,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst return ira->codegen->invalid_instruction; return cast2; - } else if (wanted_type->id == ZigTypeIdPointer && - wanted_type->data.pointer.is_const) - { - IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.pointer.child_type, value); - if (type_is_invalid(cast1->value.type)) - return ira->codegen->invalid_instruction; - - IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); - if (type_is_invalid(cast2->value.type)) - return ira->codegen->invalid_instruction; - - return cast2; } else if (ir_num_lit_fits_in_other_type(ira, value, wanted_type, true)) { CastOp op; if ((actual_type->id == ZigTypeIdComptimeFloat && @@ -10786,29 +10748,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst } } - // enum to *const union which has the enum as the tag type - if (actual_type->id == ZigTypeIdEnum && wanted_type->id == ZigTypeIdPointer) { - ZigType *union_type = wanted_type->data.pointer.child_type; - if (union_type->data.unionation.decl_node->data.container_decl.auto_enum || - union_type->data.unionation.decl_node->data.container_decl.init_arg_expr != nullptr) - { - if ((err = type_resolve(ira->codegen, union_type, ResolveStatusZeroBitsKnown))) - return ira->codegen->invalid_instruction; - - if (union_type->data.unionation.tag_type == actual_type) { - IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, union_type, value); - if (type_is_invalid(cast1->value.type)) - return ira->codegen->invalid_instruction; - - IrInstruction *cast2 = ir_analyze_cast(ira, source_instr, wanted_type, cast1); - if (type_is_invalid(cast2->value.type)) - return ira->codegen->invalid_instruction; - - return cast2; - } - } - } - // cast from *T to *[1]T if (wanted_type->id == ZigTypeIdPointer && wanted_type->data.pointer.ptr_len == PtrLenSingle && actual_type->id == ZigTypeIdPointer && actual_type->data.pointer.ptr_len == PtrLenSingle)