aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2019-12-08 18:39:52 -0500
committerAndrew Kelley <andrew@ziglang.org>2019-12-08 18:39:52 -0500
commit6504c5098ead851b369af0525c11ad2ea4cee8a2 (patch)
tree3eaa22acec3003b3dfc5965d9a475c63afbd23ce /src/ir.cpp
parentd5e788072d8b207334c0eab0f1289317a55c9344 (diff)
downloadzig-6504c5098ead851b369af0525c11ad2ea4cee8a2.tar.gz
zig-6504c5098ead851b369af0525c11ad2ea4cee8a2.zip
tuple detection does not require AST node
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index f9985d602a..fc53e2ecdf 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -724,14 +724,11 @@ static bool is_opt_err_set(ZigType *ty) {
}
static bool is_tuple(ZigType *type) {
- return type->id == ZigTypeIdStruct && type->data.structure.decl_node != nullptr &&
- type->data.structure.decl_node->type == NodeTypeContainerInitExpr &&
- (type->data.structure.decl_node->data.container_init_expr.kind == ContainerInitKindArray ||
- type->data.structure.decl_node->data.container_init_expr.entries.length == 0);
+ return type->id == ZigTypeIdStruct && type->data.structure.special == StructSpecialInferredTuple;
}
static bool is_slice(ZigType *type) {
- return type->id == ZigTypeIdStruct && type->data.structure.is_slice;
+ return type->id == ZigTypeIdStruct && type->data.structure.special == StructSpecialSlice;
}
static bool slice_is_const(ZigType *type) {
@@ -13928,7 +13925,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
}
// cast from inferred struct type to array, union, or struct
- if (actual_type->id == ZigTypeIdStruct && actual_type->data.structure.is_inferred) {
+ if (is_anon_container(actual_type)) {
AstNode *decl_node = actual_type->data.structure.decl_node;
ir_assert(decl_node->type == NodeTypeContainerInitExpr, source_instr);
ContainerInitKind init_kind = decl_node->data.container_init_expr.kind;
@@ -17047,10 +17044,17 @@ static IrInstruction *ir_analyze_instruction_resolve_result(IrAnalyze *ira,
Buf *name = get_anon_type_name(ira->codegen, nullptr, container_string(ContainerKindStruct),
instruction->base.scope, instruction->base.source_node, bare_name);
+ StructSpecial struct_special = StructSpecialInferredStruct;
+ if (instruction->base.source_node->type == NodeTypeContainerInitExpr &&
+ instruction->base.source_node->data.container_init_expr.kind == ContainerInitKindArray)
+ {
+ struct_special = StructSpecialInferredTuple;
+ }
+
ZigType *inferred_struct_type = get_partial_container_type(ira->codegen,
instruction->base.scope, ContainerKindStruct, instruction->base.source_node,
buf_ptr(name), bare_name, ContainerLayoutAuto);
- inferred_struct_type->data.structure.is_inferred = true;
+ inferred_struct_type->data.structure.special = struct_special;
inferred_struct_type->data.structure.resolve_status = ResolveStatusBeingInferred;
implicit_elem_type = inferred_struct_type;
}
@@ -19570,7 +19574,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
bool is_const = struct_ptr->value->type->data.pointer.is_const;
bool is_volatile = struct_ptr->value->type->data.pointer.is_volatile;
ZigType *ptr_type;
- if (struct_type->data.structure.is_inferred) {
+ if (is_anon_container(struct_type)) {
ptr_type = get_pointer_to_type_extra(ira->codegen, field_type,
is_const, is_volatile, PtrLenSingle, 0, 0, 0, false);
} else {
@@ -22816,7 +22820,7 @@ static Error ir_make_type_info_value(IrAnalyze *ira, IrInstruction *source_instr
}
case ZigTypeIdStruct:
{
- if (type_entry->data.structure.is_slice) {
+ if (type_entry->data.structure.special == StructSpecialSlice) {
result = create_ptr_like_type_info(ira, type_entry);
if (result == nullptr)
return ErrorSemanticAnalyzeFail;