Skip to content

Commit

Permalink
remove 3 more implicit casts to const pointers
Browse files Browse the repository at this point in the history
see #1465
  • Loading branch information
andrewrk committed Oct 25, 2018
1 parent 73ab0af commit eb0b1d3
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 67 deletions.
6 changes: 0 additions & 6 deletions doc/langref.html.in
Original file line number Diff line number Diff line change
Expand Up @@ -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#}
Expand Down
61 changes: 0 additions & 61 deletions src/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down Expand Up @@ -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)
{
Expand All @@ -10720,18 +10694,6 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
if (type_is_invalid(cast2->value.type))
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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit eb0b1d3

Please sign in to comment.