| ... | @@ -20,7 +20,7 @@ | ... | @@ -20,7 +20,7 @@ |
| 20 | | 20 | |
| 21 | static const size_t default_backward_branch_quota = 1000; | 21 | static const size_t default_backward_branch_quota = 1000; |
| 22 | | 22 | |
| 23 | static Error resolve_struct_type(CodeGen *g, ZigType *struct_type); | 23 | static Error ATTRIBUTE_MUST_USE resolve_struct_type(CodeGen *g, ZigType *struct_type); |
| 24 | | 24 | |
| 25 | static Error ATTRIBUTE_MUST_USE resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type); | 25 | static Error ATTRIBUTE_MUST_USE resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type); |
| 26 | static Error ATTRIBUTE_MUST_USE resolve_struct_alignment(CodeGen *g, ZigType *struct_type); | 26 | static Error ATTRIBUTE_MUST_USE resolve_struct_alignment(CodeGen *g, ZigType *struct_type); |
| ... | @@ -271,6 +271,8 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) { | ... | @@ -271,6 +271,8 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) { |
| 271 | return type_entry->data.structure.resolve_status >= status; | 271 | return type_entry->data.structure.resolve_status >= status; |
| 272 | case ZigTypeIdUnion: | 272 | case ZigTypeIdUnion: |
| 273 | return type_entry->data.unionation.resolve_status >= status; | 273 | return type_entry->data.unionation.resolve_status >= status; |
| | 274 | case ZigTypeIdEnum: |
| | 275 | return type_entry->data.enumeration.resolve_status >= status; |
| 274 | case ZigTypeIdFnFrame: | 276 | case ZigTypeIdFnFrame: |
| 275 | switch (status) { | 277 | switch (status) { |
| 276 | case ResolveStatusInvalid: | 278 | case ResolveStatusInvalid: |
| ... | @@ -285,23 +287,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) { | ... | @@ -285,23 +287,6 @@ bool type_is_resolved(ZigType *type_entry, ResolveStatus status) { |
| 285 | case ResolveStatusLLVMFull: | 287 | case ResolveStatusLLVMFull: |
| 286 | return type_entry->llvm_type != nullptr; | 288 | return type_entry->llvm_type != nullptr; |
| 287 | } | 289 | } |
| 288 | case ZigTypeIdEnum: | | |
| 289 | switch (status) { | | |
| 290 | case ResolveStatusUnstarted: | | |
| 291 | return true; | | |
| 292 | case ResolveStatusInvalid: | | |
| 293 | zig_unreachable(); | | |
| 294 | case ResolveStatusZeroBitsKnown: | | |
| 295 | return type_entry->data.enumeration.zero_bits_known; | | |
| 296 | case ResolveStatusAlignmentKnown: | | |
| 297 | return type_entry->data.enumeration.zero_bits_known; | | |
| 298 | case ResolveStatusSizeKnown: | | |
| 299 | return type_entry->data.enumeration.complete; | | |
| 300 | case ResolveStatusLLVMFwdDecl: | | |
| 301 | case ResolveStatusLLVMFull: | | |
| 302 | return type_entry->llvm_di_type != nullptr; | | |
| 303 | } | | |
| 304 | zig_unreachable(); | | |
| 305 | case ZigTypeIdOpaque: | 290 | case ZigTypeIdOpaque: |
| 306 | return status < ResolveStatusSizeKnown; | 291 | return status < ResolveStatusSizeKnown; |
| 307 | case ZigTypeIdMetaType: | 292 | case ZigTypeIdMetaType: |
| ... | @@ -865,7 +850,7 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { | ... | @@ -865,7 +850,7 @@ ZigType *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) { |
| 865 | return table_entry->value; | 850 | return table_entry->value; |
| 866 | } | 851 | } |
| 867 | if (fn_type_id->return_type != nullptr) { | 852 | if (fn_type_id->return_type != nullptr) { |
| 868 | if ((err = ensure_complete_type(g, fn_type_id->return_type))) | 853 | if ((err = type_resolve(g, fn_type_id->return_type, ResolveStatusSizeKnown))) |
| 869 | return g->builtin_types.entry_invalid; | 854 | return g->builtin_types.entry_invalid; |
| 870 | assert(fn_type_id->return_type->id != ZigTypeIdOpaque); | 855 | assert(fn_type_id->return_type->id != ZigTypeIdOpaque); |
| 871 | } else { | 856 | } else { |
| ... | @@ -1404,7 +1389,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc | ... | @@ -1404,7 +1389,6 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc |
| 1404 | add_node_error(g, proto_node, | 1389 | add_node_error(g, proto_node, |
| 1405 | buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447")); | 1390 | buf_sprintf("TODO implement inferred return types https://github.com/ziglang/zig/issues/447")); |
| 1406 | return g->builtin_types.entry_invalid; | 1391 | return g->builtin_types.entry_invalid; |
| 1407 | //return get_generic_fn_type(g, &fn_type_id); | | |
| 1408 | } | 1392 | } |
| 1409 | | 1393 | |
| 1410 | ZigType *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type); | 1394 | ZigType *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type); |
| ... | @@ -1490,7 +1474,7 @@ bool type_is_invalid(ZigType *type_entry) { | ... | @@ -1490,7 +1474,7 @@ bool type_is_invalid(ZigType *type_entry) { |
| 1490 | case ZigTypeIdUnion: | 1474 | case ZigTypeIdUnion: |
| 1491 | return type_entry->data.unionation.resolve_status == ResolveStatusInvalid; | 1475 | return type_entry->data.unionation.resolve_status == ResolveStatusInvalid; |
| 1492 | case ZigTypeIdEnum: | 1476 | case ZigTypeIdEnum: |
| 1493 | return type_entry->data.enumeration.is_invalid; | 1477 | return type_entry->data.enumeration.resolve_status == ResolveStatusInvalid; |
| 1494 | default: | 1478 | default: |
| 1495 | return false; | 1479 | return false; |
| 1496 | } | 1480 | } |
| ... | @@ -1602,9 +1586,8 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { | ... | @@ -1602,9 +1586,8 @@ static Error resolve_struct_type(CodeGen *g, ZigType *struct_type) { |
| 1602 | if (struct_type->data.structure.resolve_loop_flag) { | 1586 | if (struct_type->data.structure.resolve_loop_flag) { |
| 1603 | if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { | 1587 | if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { |
| 1604 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; | 1588 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 1605 | ErrorMsg *msg = add_node_error(g, decl_node, | 1589 | g->trace_err = add_node_error(g, decl_node, |
| 1606 | buf_sprintf("struct '%s' contains itself", buf_ptr(&struct_type->name))); | 1590 | buf_sprintf("struct '%s' depends on its own size", buf_ptr(&struct_type->name))); |
| 1607 | emit_error_notes_for_ref_stack(g, msg); | | |
| 1608 | } | 1591 | } |
| 1609 | return ErrorSemanticAnalyzeFail; | 1592 | return ErrorSemanticAnalyzeFail; |
| 1610 | } | 1593 | } |
| ... | @@ -1728,14 +1711,13 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) { | ... | @@ -1728,14 +1711,13 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) { |
| 1728 | if (union_type->data.unionation.resolve_status >= ResolveStatusAlignmentKnown) | 1711 | if (union_type->data.unionation.resolve_status >= ResolveStatusAlignmentKnown) |
| 1729 | return ErrorNone; | 1712 | return ErrorNone; |
| 1730 | | 1713 | |
| | 1714 | AstNode *decl_node = union_type->data.structure.decl_node; |
| | 1715 | |
| 1731 | if (union_type->data.unionation.resolve_loop_flag) { | 1716 | if (union_type->data.unionation.resolve_loop_flag) { |
| 1732 | if (!union_type->data.unionation.reported_infinite_err) { | 1717 | if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) { |
| 1733 | AstNode *decl_node = union_type->data.unionation.decl_node; | | |
| 1734 | union_type->data.unionation.reported_infinite_err = true; | | |
| 1735 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; | 1718 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 1736 | ErrorMsg *msg = add_node_error(g, decl_node, | 1719 | g->trace_err = add_node_error(g, decl_node, |
| 1737 | buf_sprintf("union '%s' contains itself", buf_ptr(&union_type->name))); | 1720 | buf_sprintf("union '%s' depends on its own alignment", buf_ptr(&union_type->name))); |
| 1738 | emit_error_notes_for_ref_stack(g, msg); | | |
| 1739 | } | 1721 | } |
| 1740 | return ErrorSemanticAnalyzeFail; | 1722 | return ErrorSemanticAnalyzeFail; |
| 1741 | } | 1723 | } |
| ... | @@ -1752,13 +1734,12 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) { | ... | @@ -1752,13 +1734,12 @@ static Error resolve_union_alignment(CodeGen *g, ZigType *union_type) { |
| 1752 | if (field->gen_index == UINT32_MAX) | 1734 | if (field->gen_index == UINT32_MAX) |
| 1753 | continue; | 1735 | continue; |
| 1754 | | 1736 | |
| | 1737 | src_assert(field->type_entry != nullptr, decl_node); |
| | 1738 | |
| 1755 | size_t this_field_align; | 1739 | size_t this_field_align; |
| 1756 | if (packed) { | 1740 | if (packed) { |
| 1757 | // TODO: https://github.com/ziglang/zig/issues/1512 | 1741 | // TODO: https://github.com/ziglang/zig/issues/1512 |
| 1758 | this_field_align = 1; | 1742 | this_field_align = 1; |
| 1759 | // This is the same hack as resolve_struct_alignment. See the comment there. | | |
| 1760 | } else if (field->type_entry == nullptr) { | | |
| 1761 | this_field_align = g->builtin_types.entry_usize->abi_align; | | |
| 1762 | } else { | 1743 | } else { |
| 1763 | if ((err = type_resolve(g, field->type_entry, ResolveStatusAlignmentKnown))) { | 1744 | if ((err = type_resolve(g, field->type_entry, ResolveStatusAlignmentKnown))) { |
| 1764 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; | 1745 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| ... | @@ -1839,12 +1820,10 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { | ... | @@ -1839,12 +1820,10 @@ static Error resolve_union_type(CodeGen *g, ZigType *union_type) { |
| 1839 | size_t union_size_in_bits = 0; | 1820 | size_t union_size_in_bits = 0; |
| 1840 | | 1821 | |
| 1841 | if (union_type->data.unionation.resolve_loop_flag) { | 1822 | if (union_type->data.unionation.resolve_loop_flag) { |
| 1842 | if (!union_type->data.unionation.reported_infinite_err) { | 1823 | if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) { |
| 1843 | union_type->data.unionation.reported_infinite_err = true; | | |
| 1844 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; | 1824 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 1845 | ErrorMsg *msg = add_node_error(g, decl_node, | 1825 | g->trace_err = add_node_error(g, decl_node, |
| 1846 | buf_sprintf("union '%s' depends on its own size", buf_ptr(&union_type->name))); | 1826 | buf_sprintf("union '%s' depends on its own size", buf_ptr(&union_type->name))); |
| 1847 | emit_error_notes_for_ref_stack(g, msg); | | |
| 1848 | } | 1827 | } |
| 1849 | return ErrorSemanticAnalyzeFail; | 1828 | return ErrorSemanticAnalyzeFail; |
| 1850 | } | 1829 | } |
| ... | @@ -1925,24 +1904,25 @@ static bool type_is_valid_extern_enum_tag(CodeGen *g, ZigType *ty) { | ... | @@ -1925,24 +1904,25 @@ static bool type_is_valid_extern_enum_tag(CodeGen *g, ZigType *ty) { |
| 1925 | static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { | 1904 | static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 1926 | assert(enum_type->id == ZigTypeIdEnum); | 1905 | assert(enum_type->id == ZigTypeIdEnum); |
| 1927 | | 1906 | |
| 1928 | if (enum_type->data.enumeration.is_invalid) | 1907 | if (enum_type->data.enumeration.resolve_status == ResolveStatusInvalid) |
| 1929 | return ErrorSemanticAnalyzeFail; | 1908 | return ErrorSemanticAnalyzeFail; |
| 1930 | | 1909 | if (enum_type->data.enumeration.resolve_status >= ResolveStatusZeroBitsKnown) |
| 1931 | if (enum_type->data.enumeration.zero_bits_known) | | |
| 1932 | return ErrorNone; | 1910 | return ErrorNone; |
| 1933 | | 1911 | |
| 1934 | if (enum_type->data.enumeration.zero_bits_loop_flag) { | 1912 | AstNode *decl_node = enum_type->data.enumeration.decl_node; |
| 1935 | ErrorMsg *msg = add_node_error(g, enum_type->data.enumeration.decl_node, | 1913 | assert(decl_node->type == NodeTypeContainerDecl); |
| 1936 | buf_sprintf("'%s' depends on itself", buf_ptr(&enum_type->name))); | 1914 | |
| 1937 | emit_error_notes_for_ref_stack(g, msg); | 1915 | if (enum_type->data.enumeration.resolve_loop_flag) { |
| 1938 | enum_type->data.enumeration.is_invalid = true; | 1916 | if (enum_type->data.enumeration.resolve_status != ResolveStatusInvalid) { |
| | 1917 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| | 1918 | g->trace_err = add_node_error(g, decl_node, |
| | 1919 | buf_sprintf("circular dependency: whether enum '%s' has non-zero size", |
| | 1920 | buf_ptr(&enum_type->name))); |
| | 1921 | } |
| 1939 | return ErrorSemanticAnalyzeFail; | 1922 | return ErrorSemanticAnalyzeFail; |
| 1940 | } | 1923 | } |
| 1941 | | 1924 | |
| 1942 | enum_type->data.enumeration.zero_bits_loop_flag = true; | 1925 | enum_type->data.enumeration.resolve_loop_flag = true; |
| 1943 | | | |
| 1944 | AstNode *decl_node = enum_type->data.enumeration.decl_node; | | |
| 1945 | assert(decl_node->type == NodeTypeContainerDecl); | | |
| 1946 | | 1926 | |
| 1947 | assert(!enum_type->data.enumeration.fields); | 1927 | assert(!enum_type->data.enumeration.fields); |
| 1948 | uint32_t field_count = (uint32_t)decl_node->data.container_decl.fields.length; | 1928 | uint32_t field_count = (uint32_t)decl_node->data.container_decl.fields.length; |
| ... | @@ -1951,9 +1931,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { | ... | @@ -1951,9 +1931,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 1951 | | 1931 | |
| 1952 | enum_type->data.enumeration.src_field_count = field_count; | 1932 | enum_type->data.enumeration.src_field_count = field_count; |
| 1953 | enum_type->data.enumeration.fields = nullptr; | 1933 | enum_type->data.enumeration.fields = nullptr; |
| 1954 | enum_type->data.enumeration.is_invalid = true; | 1934 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 1955 | enum_type->data.enumeration.zero_bits_loop_flag = false; | | |
| 1956 | enum_type->data.enumeration.zero_bits_known = true; | | |
| 1957 | return ErrorSemanticAnalyzeFail; | 1935 | return ErrorSemanticAnalyzeFail; |
| 1958 | } | 1936 | } |
| 1959 | | 1937 | |
| ... | @@ -1982,14 +1960,14 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { | ... | @@ -1982,14 +1960,14 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 1982 | if (decl_node->data.container_decl.init_arg_expr != nullptr) { | 1960 | if (decl_node->data.container_decl.init_arg_expr != nullptr) { |
| 1983 | ZigType *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr); | 1961 | ZigType *wanted_tag_int_type = analyze_type_expr(g, scope, decl_node->data.container_decl.init_arg_expr); |
| 1984 | if (type_is_invalid(wanted_tag_int_type)) { | 1962 | if (type_is_invalid(wanted_tag_int_type)) { |
| 1985 | enum_type->data.enumeration.is_invalid = true; | 1963 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 1986 | } else if (wanted_tag_int_type->id != ZigTypeIdInt) { | 1964 | } else if (wanted_tag_int_type->id != ZigTypeIdInt) { |
| 1987 | enum_type->data.enumeration.is_invalid = true; | 1965 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 1988 | add_node_error(g, decl_node->data.container_decl.init_arg_expr, | 1966 | add_node_error(g, decl_node->data.container_decl.init_arg_expr, |
| 1989 | buf_sprintf("expected integer, found '%s'", buf_ptr(&wanted_tag_int_type->name))); | 1967 | buf_sprintf("expected integer, found '%s'", buf_ptr(&wanted_tag_int_type->name))); |
| 1990 | } else if (enum_type->data.enumeration.layout == ContainerLayoutExtern && | 1968 | } else if (enum_type->data.enumeration.layout == ContainerLayoutExtern && |
| 1991 | !type_is_valid_extern_enum_tag(g, wanted_tag_int_type)) { | 1969 | !type_is_valid_extern_enum_tag(g, wanted_tag_int_type)) { |
| 1992 | enum_type->data.enumeration.is_invalid = true; | 1970 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 1993 | ErrorMsg *msg = add_node_error(g, decl_node->data.container_decl.init_arg_expr, | 1971 | ErrorMsg *msg = add_node_error(g, decl_node->data.container_decl.init_arg_expr, |
| 1994 | buf_sprintf("'%s' is not a valid tag type for an extern enum", | 1972 | buf_sprintf("'%s' is not a valid tag type for an extern enum", |
| 1995 | buf_ptr(&wanted_tag_int_type->name))); | 1973 | buf_ptr(&wanted_tag_int_type->name))); |
| ... | @@ -2029,7 +2007,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { | ... | @@ -2029,7 +2007,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 2029 | ErrorMsg *msg = add_node_error(g, field_node, | 2007 | ErrorMsg *msg = add_node_error(g, field_node, |
| 2030 | buf_sprintf("duplicate enum field: '%s'", buf_ptr(type_enum_field->name))); | 2008 | buf_sprintf("duplicate enum field: '%s'", buf_ptr(type_enum_field->name))); |
| 2031 | add_error_note(g, msg, field_entry->value->decl_node, buf_sprintf("other field here")); | 2009 | add_error_note(g, msg, field_entry->value->decl_node, buf_sprintf("other field here")); |
| 2032 | enum_type->data.enumeration.is_invalid = true; | 2010 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 2033 | continue; | 2011 | continue; |
| 2034 | } | 2012 | } |
| 2035 | | 2013 | |
| ... | @@ -2039,7 +2017,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { | ... | @@ -2039,7 +2017,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 2039 | // A user-specified value is available | 2017 | // A user-specified value is available |
| 2040 | ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr); | 2018 | ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr); |
| 2041 | if (type_is_invalid(result->type)) { | 2019 | if (type_is_invalid(result->type)) { |
| 2042 | enum_type->data.enumeration.is_invalid = true; | 2020 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 2043 | continue; | 2021 | continue; |
| 2044 | } | 2022 | } |
| 2045 | | 2023 | |
| ... | @@ -2060,7 +2038,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { | ... | @@ -2060,7 +2038,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 2060 | if (!bigint_fits_in_bits(&type_enum_field->value, | 2038 | if (!bigint_fits_in_bits(&type_enum_field->value, |
| 2061 | tag_int_type->size_in_bits, | 2039 | tag_int_type->size_in_bits, |
| 2062 | tag_int_type->data.integral.is_signed)) { | 2040 | tag_int_type->data.integral.is_signed)) { |
| 2063 | enum_type->data.enumeration.is_invalid = true; | 2041 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 2064 | | 2042 | |
| 2065 | Buf *val_buf = buf_alloc(); | 2043 | Buf *val_buf = buf_alloc(); |
| 2066 | bigint_append_buf(val_buf, &type_enum_field->value, 10); | 2044 | bigint_append_buf(val_buf, &type_enum_field->value, 10); |
| ... | @@ -2075,7 +2053,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { | ... | @@ -2075,7 +2053,7 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 2075 | // Make sure the value is unique | 2053 | // Make sure the value is unique |
| 2076 | auto entry = occupied_tag_values.put_unique(type_enum_field->value, field_node); | 2054 | auto entry = occupied_tag_values.put_unique(type_enum_field->value, field_node); |
| 2077 | if (entry != nullptr) { | 2055 | if (entry != nullptr) { |
| 2078 | enum_type->data.enumeration.is_invalid = true; | 2056 | enum_type->data.enumeration.resolve_status = ResolveStatusInvalid; |
| 2079 | | 2057 | |
| 2080 | Buf *val_buf = buf_alloc(); | 2058 | Buf *val_buf = buf_alloc(); |
| 2081 | bigint_append_buf(val_buf, &type_enum_field->value, 10); | 2059 | bigint_append_buf(val_buf, &type_enum_field->value, 10); |
| ... | @@ -2089,13 +2067,12 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { | ... | @@ -2089,13 +2067,12 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) { |
| 2089 | last_enum_field = type_enum_field; | 2067 | last_enum_field = type_enum_field; |
| 2090 | } | 2068 | } |
| 2091 | | 2069 | |
| 2092 | enum_type->data.enumeration.zero_bits_loop_flag = false; | 2070 | if (enum_type->data.enumeration.resolve_status == ResolveStatusInvalid) |
| 2093 | enum_type->data.enumeration.zero_bits_known = true; | | |
| 2094 | enum_type->data.enumeration.complete = true; | | |
| 2095 | | | |
| 2096 | if (enum_type->data.enumeration.is_invalid) | | |
| 2097 | return ErrorSemanticAnalyzeFail; | 2071 | return ErrorSemanticAnalyzeFail; |
| 2098 | | 2072 | |
| | 2073 | enum_type->data.enumeration.resolve_loop_flag = false; |
| | 2074 | enum_type->data.enumeration.resolve_status = ResolveStatusSizeKnown; |
| | 2075 | |
| 2099 | return ErrorNone; | 2076 | return ErrorNone; |
| 2100 | } | 2077 | } |
| 2101 | | 2078 | |
| ... | @@ -2113,12 +2090,13 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { | ... | @@ -2113,12 +2090,13 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) { |
| 2113 | assert(decl_node->type == NodeTypeContainerDecl); | 2090 | assert(decl_node->type == NodeTypeContainerDecl); |
| 2114 | | 2091 | |
| 2115 | if (struct_type->data.structure.resolve_loop_flag) { | 2092 | if (struct_type->data.structure.resolve_loop_flag) { |
| 2116 | // TODO This is a problem. I believe it can be solved with lazy values. | 2093 | if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { |
| 2117 | struct_type->size_in_bits = SIZE_MAX; | 2094 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 2118 | struct_type->abi_size = SIZE_MAX; | 2095 | g->trace_err = add_node_error(g, decl_node, |
| 2119 | struct_type->data.structure.resolve_status = ResolveStatusZeroBitsKnown; | 2096 | buf_sprintf("circular dependency: whether struct '%s' has non-zero size", |
| 2120 | struct_type->data.structure.resolve_loop_flag = false; | 2097 | buf_ptr(&struct_type->name))); |
| 2121 | return ErrorNone; | 2098 | } |
| | 2099 | return ErrorSemanticAnalyzeFail; |
| 2122 | } | 2100 | } |
| 2123 | | 2101 | |
| 2124 | struct_type->data.structure.resolve_loop_flag = true; | 2102 | struct_type->data.structure.resolve_loop_flag = true; |
| ... | @@ -2237,9 +2215,8 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) { | ... | @@ -2237,9 +2215,8 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) { |
| 2237 | if (struct_type->data.structure.resolve_loop_flag) { | 2215 | if (struct_type->data.structure.resolve_loop_flag) { |
| 2238 | if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { | 2216 | if (struct_type->data.structure.resolve_status != ResolveStatusInvalid) { |
| 2239 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; | 2217 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| 2240 | ErrorMsg *msg = add_node_error(g, decl_node, | 2218 | g->trace_err = add_node_error(g, decl_node, |
| 2241 | buf_sprintf("struct '%s' contains itself", buf_ptr(&struct_type->name))); | 2219 | buf_sprintf("struct '%s' depends on its own alignment", buf_ptr(&struct_type->name))); |
| 2242 | emit_error_notes_for_ref_stack(g, msg); | | |
| 2243 | } | 2220 | } |
| 2244 | return ErrorSemanticAnalyzeFail; | 2221 | return ErrorSemanticAnalyzeFail; |
| 2245 | } | 2222 | } |
| ... | @@ -2255,20 +2232,12 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) { | ... | @@ -2255,20 +2232,12 @@ static Error resolve_struct_alignment(CodeGen *g, ZigType *struct_type) { |
| 2255 | if (field->gen_index == SIZE_MAX) | 2232 | if (field->gen_index == SIZE_MAX) |
| 2256 | continue; | 2233 | continue; |
| 2257 | | 2234 | |
| | 2235 | src_assert(field->type_entry != nullptr, decl_node); |
| | 2236 | |
| 2258 | size_t this_field_align; | 2237 | size_t this_field_align; |
| 2259 | if (packed) { | 2238 | if (packed) { |
| 2260 | // TODO: https://github.com/ziglang/zig/issues/1512 | 2239 | // TODO: https://github.com/ziglang/zig/issues/1512 |
| 2261 | this_field_align = 1; | 2240 | this_field_align = 1; |
| 2262 | // TODO If we have no type_entry for the field, we've already failed to | | |
| 2263 | // compile the program correctly. This stage1 compiler needs a deeper | | |
| 2264 | // reworking to make this correct, or we can ignore the problem | | |
| 2265 | // and make sure it is fixed in stage2. This workaround is for when | | |
| 2266 | // there is a false positive of a dependency loop, of alignment depending | | |
| 2267 | // on itself. When this false positive happens we assume a pointer-aligned | | |
| 2268 | // field, which is usually fine but could be incorrectly over-aligned or | | |
| 2269 | // even under-aligned. See https://github.com/ziglang/zig/issues/1512 | | |
| 2270 | } else if (field->type_entry == nullptr) { | | |
| 2271 | this_field_align = g->builtin_types.entry_usize->abi_align; | | |
| 2272 | } else { | 2241 | } else { |
| 2273 | if ((err = type_resolve(g, field->type_entry, ResolveStatusAlignmentKnown))) { | 2242 | if ((err = type_resolve(g, field->type_entry, ResolveStatusAlignmentKnown))) { |
| 2274 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; | 2243 | struct_type->data.structure.resolve_status = ResolveStatusInvalid; |
| ... | @@ -2304,23 +2273,21 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { | ... | @@ -2304,23 +2273,21 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 2304 | if (union_type->data.unionation.resolve_status >= ResolveStatusZeroBitsKnown) | 2273 | if (union_type->data.unionation.resolve_status >= ResolveStatusZeroBitsKnown) |
| 2305 | return ErrorNone; | 2274 | return ErrorNone; |
| 2306 | | 2275 | |
| | 2276 | AstNode *decl_node = union_type->data.unionation.decl_node; |
| | 2277 | assert(decl_node->type == NodeTypeContainerDecl); |
| | 2278 | |
| 2307 | if (union_type->data.unionation.resolve_loop_flag) { | 2279 | if (union_type->data.unionation.resolve_loop_flag) { |
| 2308 | // If we get here it's due to recursion. From this we conclude that the struct is | 2280 | if (union_type->data.unionation.resolve_status != ResolveStatusInvalid) { |
| 2309 | // not zero bits. | 2281 | union_type->data.unionation.resolve_status = ResolveStatusInvalid; |
| 2310 | // TODO actually it could still be zero bits. Here we should continue analyzing | 2282 | g->trace_err = add_node_error(g, decl_node, |
| 2311 | // the union from the next field index. | 2283 | buf_sprintf("circular dependency: whether union '%s' has non-zero size", |
| 2312 | union_type->data.unionation.resolve_status = ResolveStatusZeroBitsKnown; | 2284 | buf_ptr(&union_type->name))); |
| 2313 | union_type->data.unionation.resolve_loop_flag = false; | 2285 | } |
| 2314 | union_type->abi_size = SIZE_MAX; | 2286 | return ErrorSemanticAnalyzeFail; |
| 2315 | union_type->size_in_bits = SIZE_MAX; | | |
| 2316 | return ErrorNone; | | |
| 2317 | } | 2287 | } |
| 2318 | | 2288 | |
| 2319 | union_type->data.unionation.resolve_loop_flag = true; | 2289 | union_type->data.unionation.resolve_loop_flag = true; |
| 2320 | | 2290 | |
| 2321 | AstNode *decl_node = union_type->data.unionation.decl_node; | | |
| 2322 | assert(decl_node->type == NodeTypeContainerDecl); | | |
| 2323 | | | |
| 2324 | assert(union_type->data.unionation.fields == nullptr); | 2291 | assert(union_type->data.unionation.fields == nullptr); |
| 2325 | uint32_t field_count = (uint32_t)decl_node->data.container_decl.fields.length; | 2292 | uint32_t field_count = (uint32_t)decl_node->data.container_decl.fields.length; |
| 2326 | if (field_count == 0) { | 2293 | if (field_count == 0) { |
| ... | @@ -2380,14 +2347,13 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { | ... | @@ -2380,14 +2347,13 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) { |
| 2380 | tag_type->size_in_bits = tag_int_type->size_in_bits; | 2347 | tag_type->size_in_bits = tag_int_type->size_in_bits; |
| 2381 | | 2348 | |
| 2382 | tag_type->data.enumeration.tag_int_type = tag_int_type; | 2349 | tag_type->data.enumeration.tag_int_type = tag_int_type; |
| 2383 | tag_type->data.enumeration.zero_bits_known = true; | 2350 | tag_type->data.enumeration.resolve_status = ResolveStatusSizeKnown; |
| 2384 | tag_type->data.enumeration.decl_node = decl_node; | 2351 | tag_type->data.enumeration.decl_node = decl_node; |
| 2385 | tag_type->data.enumeration.layout = ContainerLayoutAuto; | 2352 | tag_type->data.enumeration.layout = ContainerLayoutAuto; |
| 2386 | tag_type->data.enumeration.src_field_count = field_count; | 2353 | tag_type->data.enumeration.src_field_count = field_count; |
| 2387 | tag_type->data.enumeration.fields = allocate<TypeEnumField>(field_count); | 2354 | tag_type->data.enumeration.fields = allocate<TypeEnumField>(field_count); |
| 2388 | tag_type->data.enumeration.fields_by_name.init(field_count); | 2355 | tag_type->data.enumeration.fields_by_name.init(field_count); |
| 2389 | tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope; | 2356 | tag_type->data.enumeration.decls_scope = union_type->data.unionation.decls_scope; |
| 2390 | tag_type->data.enumeration.complete = true; | | |
| 2391 | } else if (enum_type_node != nullptr) { | 2357 | } else if (enum_type_node != nullptr) { |
| 2392 | ZigType *enum_type = analyze_type_expr(g, scope, enum_type_node); | 2358 | ZigType *enum_type = analyze_type_expr(g, scope, enum_type_node); |
| 2393 | if (type_is_invalid(enum_type)) { | 2359 | if (type_is_invalid(enum_type)) { |
| ... | @@ -3185,9 +3151,8 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) { | ... | @@ -3185,9 +3151,8 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var) { |
| 3185 | ZigType *explicit_type = nullptr; | 3151 | ZigType *explicit_type = nullptr; |
| 3186 | if (var_decl->type) { | 3152 | if (var_decl->type) { |
| 3187 | if (tld_var->analyzing_type) { | 3153 | if (tld_var->analyzing_type) { |
| 3188 | ErrorMsg *msg = add_node_error(g, var_decl->type, | 3154 | g->trace_err = add_node_error(g, var_decl->type, |
| 3189 | buf_sprintf("type of '%s' depends on itself", buf_ptr(tld_var->base.name))); | 3155 | buf_sprintf("type of '%s' depends on itself", buf_ptr(tld_var->base.name))); |
| 3190 | emit_error_notes_for_ref_stack(g, msg); | | |
| 3191 | explicit_type = g->builtin_types.entry_invalid; | 3156 | explicit_type = g->builtin_types.entry_invalid; |
| 3192 | } else { | 3157 | } else { |
| 3193 | tld_var->analyzing_type = true; | 3158 | tld_var->analyzing_type = true; |
| ... | @@ -3386,7 +3351,6 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node) { | ... | @@ -3386,7 +3351,6 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node) { |
| 3386 | | 3351 | |
| 3387 | assert(tld->resolution != TldResolutionResolving); | 3352 | assert(tld->resolution != TldResolutionResolving); |
| 3388 | tld->resolution = TldResolutionResolving; | 3353 | tld->resolution = TldResolutionResolving; |
| 3389 | g->tld_ref_source_node_stack.append(source_node); | | |
| 3390 | | 3354 | |
| 3391 | switch (tld->id) { | 3355 | switch (tld->id) { |
| 3392 | case TldIdVar: | 3356 | case TldIdVar: |
| ... | @@ -3424,7 +3388,10 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node) { | ... | @@ -3424,7 +3388,10 @@ void resolve_top_level_decl(CodeGen *g, Tld *tld, AstNode *source_node) { |
| 3424 | } | 3388 | } |
| 3425 | | 3389 | |
| 3426 | tld->resolution = TldResolutionOk; | 3390 | tld->resolution = TldResolutionOk; |
| 3427 | g->tld_ref_source_node_stack.pop(); | 3391 | |
| | 3392 | if (g->trace_err != nullptr && source_node != nullptr) { |
| | 3393 | g->trace_err = add_error_note(g, g->trace_err, source_node, buf_create_from_str("referenced here")); |
| | 3394 | } |
| 3428 | } | 3395 | } |
| 3429 | | 3396 | |
| 3430 | Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name) { | 3397 | Tld *find_container_decl(CodeGen *g, ScopeDecls *decls_scope, Buf *name) { |
| ... | @@ -3550,7 +3517,7 @@ TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag) | ... | @@ -3550,7 +3517,7 @@ TypeUnionField *find_union_field_by_tag(ZigType *type_entry, const BigInt *tag) |
| 3550 | } | 3517 | } |
| 3551 | | 3518 | |
| 3552 | TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag) { | 3519 | TypeEnumField *find_enum_field_by_tag(ZigType *enum_type, const BigInt *tag) { |
| 3553 | assert(enum_type->data.enumeration.zero_bits_known); | 3520 | assert(type_is_resolved(enum_type, ResolveStatusZeroBitsKnown)); |
| 3554 | for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) { | 3521 | for (uint32_t i = 0; i < enum_type->data.enumeration.src_field_count; i += 1) { |
| 3555 | TypeEnumField *field = &enum_type->data.enumeration.fields[i]; | 3522 | TypeEnumField *field = &enum_type->data.enumeration.fields[i]; |
| 3556 | if (bigint_cmp(&field->value, tag) == CmpEQ) { | 3523 | if (bigint_cmp(&field->value, tag) == CmpEQ) { |
| ... | @@ -3619,43 +3586,6 @@ ZigType *container_ref_type(ZigType *type_entry) { | ... | @@ -3619,43 +3586,6 @@ ZigType *container_ref_type(ZigType *type_entry) { |
| 3619 | type_entry->data.pointer.child_type : type_entry; | 3586 | type_entry->data.pointer.child_type : type_entry; |
| 3620 | } | 3587 | } |
| 3621 | | 3588 | |
| 3622 | Error resolve_container_type(CodeGen *g, ZigType *type_entry) { | | |
| 3623 | switch (type_entry->id) { | | |
| 3624 | case ZigTypeIdStruct: | | |
| 3625 | return resolve_struct_type(g, type_entry); | | |
| 3626 | case ZigTypeIdEnum: | | |
| 3627 | return resolve_enum_zero_bits(g, type_entry); | | |
| 3628 | case ZigTypeIdUnion: | | |
| 3629 | return resolve_union_type(g, type_entry); | | |
| 3630 | case ZigTypeIdPointer: | | |
| 3631 | case ZigTypeIdMetaType: | | |
| 3632 | case ZigTypeIdVoid: | | |
| 3633 | case ZigTypeIdBool: | | |
| 3634 | case ZigTypeIdUnreachable: | | |
| 3635 | case ZigTypeIdInt: | | |
| 3636 | case ZigTypeIdFloat: | | |
| 3637 | case ZigTypeIdArray: | | |
| 3638 | case ZigTypeIdComptimeFloat: | | |
| 3639 | case ZigTypeIdComptimeInt: | | |
| 3640 | case ZigTypeIdEnumLiteral: | | |
| 3641 | case ZigTypeIdUndefined: | | |
| 3642 | case ZigTypeIdNull: | | |
| 3643 | case ZigTypeIdOptional: | | |
| 3644 | case ZigTypeIdErrorUnion: | | |
| 3645 | case ZigTypeIdErrorSet: | | |
| 3646 | case ZigTypeIdFn: | | |
| 3647 | case ZigTypeIdBoundFn: | | |
| 3648 | case ZigTypeIdInvalid: | | |
| 3649 | case ZigTypeIdArgTuple: | | |
| 3650 | case ZigTypeIdOpaque: | | |
| 3651 | case ZigTypeIdVector: | | |
| 3652 | case ZigTypeIdFnFrame: | | |
| 3653 | case ZigTypeIdAnyFrame: | | |
| 3654 | zig_unreachable(); | | |
| 3655 | } | | |
| 3656 | zig_unreachable(); | | |
| 3657 | } | | |
| 3658 | | | |
| 3659 | ZigType *get_src_ptr_type(ZigType *type) { | 3589 | ZigType *get_src_ptr_type(ZigType *type) { |
| 3660 | if (type->id == ZigTypeIdPointer) return type; | 3590 | if (type->id == ZigTypeIdPointer) return type; |
| 3661 | if (type->id == ZigTypeIdFn) return type; | 3591 | if (type->id == ZigTypeIdFn) return type; |
| ... | @@ -3906,7 +3836,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) { | ... | @@ -3906,7 +3836,7 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) { |
| 3906 | &fn->analyzed_executable, fn_type_id->return_type, return_type_node); | 3836 | &fn->analyzed_executable, fn_type_id->return_type, return_type_node); |
| 3907 | fn->src_implicit_return_type = block_return_type; | 3837 | fn->src_implicit_return_type = block_return_type; |
| 3908 | | 3838 | |
| 3909 | if (type_is_invalid(block_return_type) || fn->analyzed_executable.invalid) { | 3839 | if (type_is_invalid(block_return_type) || fn->analyzed_executable.first_err_trace_msg != nullptr) { |
| 3910 | assert(g->errors.length > 0); | 3840 | assert(g->errors.length > 0); |
| 3911 | fn->anal_state = FnAnalStateInvalid; | 3841 | fn->anal_state = FnAnalStateInvalid; |
| 3912 | return; | 3842 | return; |
| ... | @@ -3990,7 +3920,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { | ... | @@ -3990,7 +3920,7 @@ static void analyze_fn_body(CodeGen *g, ZigFn *fn_table_entry) { |
| 3990 | assert(!fn_type->data.fn.is_generic); | 3920 | assert(!fn_type->data.fn.is_generic); |
| 3991 | | 3921 | |
| 3992 | ir_gen_fn(g, fn_table_entry); | 3922 | ir_gen_fn(g, fn_table_entry); |
| 3993 | if (fn_table_entry->ir_executable.invalid) { | 3923 | if (fn_table_entry->ir_executable.first_err_trace_msg != nullptr) { |
| 3994 | fn_table_entry->anal_state = FnAnalStateInvalid; | 3924 | fn_table_entry->anal_state = FnAnalStateInvalid; |
| 3995 | return; | 3925 | return; |
| 3996 | } | 3926 | } |
| ... | @@ -4128,12 +4058,14 @@ void semantic_analyze(CodeGen *g) { | ... | @@ -4128,12 +4058,14 @@ void semantic_analyze(CodeGen *g) { |
| 4128 | { | 4058 | { |
| 4129 | for (; g->resolve_queue_index < g->resolve_queue.length; g->resolve_queue_index += 1) { | 4059 | for (; g->resolve_queue_index < g->resolve_queue.length; g->resolve_queue_index += 1) { |
| 4130 | Tld *tld = g->resolve_queue.at(g->resolve_queue_index); | 4060 | Tld *tld = g->resolve_queue.at(g->resolve_queue_index); |
| | 4061 | g->trace_err = nullptr; |
| 4131 | AstNode *source_node = nullptr; | 4062 | AstNode *source_node = nullptr; |
| 4132 | resolve_top_level_decl(g, tld, source_node); | 4063 | resolve_top_level_decl(g, tld, source_node); |
| 4133 | } | 4064 | } |
| 4134 | | 4065 | |
| 4135 | for (; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) { | 4066 | for (; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) { |
| 4136 | ZigFn *fn_entry = g->fn_defs.at(g->fn_defs_index); | 4067 | ZigFn *fn_entry = g->fn_defs.at(g->fn_defs_index); |
| | 4068 | g->trace_err = nullptr; |
| 4137 | analyze_fn_body(g, fn_entry); | 4069 | analyze_fn_body(g, fn_entry); |
| 4138 | } | 4070 | } |
| 4139 | } | 4071 | } |
| ... | @@ -4145,6 +4077,7 @@ void semantic_analyze(CodeGen *g) { | ... | @@ -4145,6 +4077,7 @@ void semantic_analyze(CodeGen *g) { |
| 4145 | // second pass over functions for detecting async | 4077 | // second pass over functions for detecting async |
| 4146 | for (g->fn_defs_index = 0; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) { | 4078 | for (g->fn_defs_index = 0; g->fn_defs_index < g->fn_defs.length; g->fn_defs_index += 1) { |
| 4147 | ZigFn *fn = g->fn_defs.at(g->fn_defs_index); | 4079 | ZigFn *fn = g->fn_defs.at(g->fn_defs_index); |
| | 4080 | g->trace_err = nullptr; |
| 4148 | analyze_fn_async(g, fn, true); | 4081 | analyze_fn_async(g, fn, true); |
| 4149 | if (fn_is_async(fn) && fn->non_async_node != nullptr) { | 4082 | if (fn_is_async(fn) && fn->non_async_node != nullptr) { |
| 4150 | ErrorMsg *msg = add_node_error(g, fn->proto_node, | 4083 | ErrorMsg *msg = add_node_error(g, fn->proto_node, |
| ... | @@ -5143,34 +5076,6 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_ | ... | @@ -5143,34 +5076,6 @@ ConstExprValue *create_const_arg_tuple(CodeGen *g, size_t arg_index_start, size_ |
| 5143 | } | 5076 | } |
| 5144 | | 5077 | |
| 5145 | | 5078 | |
| 5146 | void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { | | |
| 5147 | Error err; | | |
| 5148 | ZigType *wanted_type = const_val->type; | | |
| 5149 | if (wanted_type->id == ZigTypeIdArray) { | | |
| 5150 | const_val->special = ConstValSpecialStatic; | | |
| 5151 | const_val->data.x_array.special = ConstArraySpecialUndef; | | |
| 5152 | } else if (wanted_type->id == ZigTypeIdStruct) { | | |
| 5153 | if ((err = ensure_complete_type(g, wanted_type))) { | | |
| 5154 | return; | | |
| 5155 | } | | |
| 5156 | | | |
| 5157 | const_val->special = ConstValSpecialStatic; | | |
| 5158 | size_t field_count = wanted_type->data.structure.src_field_count; | | |
| 5159 | const_val->data.x_struct.fields = create_const_vals(field_count); | | |
| 5160 | for (size_t i = 0; i < field_count; i += 1) { | | |
| 5161 | ConstExprValue *field_val = &const_val->data.x_struct.fields[i]; | | |
| 5162 | field_val->type = wanted_type->data.structure.fields[i].type_entry; | | |
| 5163 | assert(field_val->type); | | |
| 5164 | init_const_undefined(g, field_val); | | |
| 5165 | field_val->parent.id = ConstParentIdStruct; | | |
| 5166 | field_val->parent.data.p_struct.struct_val = const_val; | | |
| 5167 | field_val->parent.data.p_struct.field_index = i; | | |
| 5168 | } | | |
| 5169 | } else { | | |
| 5170 | const_val->special = ConstValSpecialUndef; | | |
| 5171 | } | | |
| 5172 | } | | |
| 5173 | | | |
| 5174 | ConstExprValue *create_const_vals(size_t count) { | 5079 | ConstExprValue *create_const_vals(size_t count) { |
| 5175 | ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count); | 5080 | ConstGlobalRefs *global_refs = allocate<ConstGlobalRefs>(count); |
| 5176 | ConstExprValue *vals = allocate<ConstExprValue>(count); | 5081 | ConstExprValue *vals = allocate<ConstExprValue>(count); |
| ... | @@ -5180,10 +5085,6 @@ ConstExprValue *create_const_vals(size_t count) { | ... | @@ -5180,10 +5085,6 @@ ConstExprValue *create_const_vals(size_t count) { |
| 5180 | return vals; | 5085 | return vals; |
| 5181 | } | 5086 | } |
| 5182 | | 5087 | |
| 5183 | Error ensure_complete_type(CodeGen *g, ZigType *type_entry) { | | |
| 5184 | return type_resolve(g, type_entry, ResolveStatusSizeKnown); | | |
| 5185 | } | | |
| 5186 | | | |
| 5187 | static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) { | 5088 | static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) { |
| 5188 | if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) | 5089 | if (orig_fn_type->data.fn.fn_type_id.cc == CallingConventionAsync) |
| 5189 | return orig_fn_type; | 5090 | return orig_fn_type; |
| ... | @@ -5197,27 +5098,6 @@ static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) { | ... | @@ -5197,27 +5098,6 @@ static ZigType *get_async_fn_type(CodeGen *g, ZigType *orig_fn_type) { |
| 5197 | return fn_type; | 5098 | return fn_type; |
| 5198 | } | 5099 | } |
| 5199 | | 5100 | |
| 5200 | static void emit_error_notes_for_type_loop(CodeGen *g, ErrorMsg *msg, ZigType *stop_type, | | |
| 5201 | ZigType *ty, AstNode *src_node) | | |
| 5202 | { | | |
| 5203 | ErrorMsg *note = add_error_note(g, msg, src_node, | | |
| 5204 | buf_sprintf("when analyzing type '%s' here", buf_ptr(&ty->name))); | | |
| 5205 | if (ty == stop_type) | | |
| 5206 | return; | | |
| 5207 | switch (ty->id) { | | |
| 5208 | case ZigTypeIdFnFrame: { | | |
| 5209 | ty->data.frame.reported_loop_err = true; | | |
| 5210 | ZigType *depending_type = ty->data.frame.resolve_loop_type; | | |
| 5211 | if (depending_type == nullptr) | | |
| 5212 | return; | | |
| 5213 | emit_error_notes_for_type_loop(g, note, stop_type, | | |
| 5214 | depending_type, ty->data.frame.resolve_loop_src_node); | | |
| 5215 | } | | |
| 5216 | default: | | |
| 5217 | return; | | |
| 5218 | } | | |
| 5219 | } | | |
| 5220 | | | |
| 5221 | static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { | 5101 | static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5222 | Error err; | 5102 | Error err; |
| 5223 | | 5103 | |
| ... | @@ -5230,13 +5110,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { | ... | @@ -5230,13 +5110,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5230 | if (frame_type->data.frame.resolve_loop_type != nullptr) { | 5110 | if (frame_type->data.frame.resolve_loop_type != nullptr) { |
| 5231 | if (!frame_type->data.frame.reported_loop_err) { | 5111 | if (!frame_type->data.frame.reported_loop_err) { |
| 5232 | frame_type->data.frame.reported_loop_err = true; | 5112 | frame_type->data.frame.reported_loop_err = true; |
| 5233 | ErrorMsg *msg = add_node_error(g, fn->proto_node, | 5113 | g->trace_err = add_node_error(g, fn->proto_node, |
| 5234 | buf_sprintf("'%s' depends on itself", buf_ptr(&frame_type->name))); | 5114 | buf_sprintf("'%s' depends on itself", buf_ptr(&frame_type->name))); |
| 5235 | emit_error_notes_for_type_loop(g, msg, | | |
| 5236 | frame_type, | | |
| 5237 | frame_type->data.frame.resolve_loop_type, | | |
| 5238 | frame_type->data.frame.resolve_loop_src_node); | | |
| 5239 | emit_error_notes_for_ref_stack(g, msg); | | |
| 5240 | } | 5115 | } |
| 5241 | return ErrorSemanticAnalyzeFail; | 5116 | return ErrorSemanticAnalyzeFail; |
| 5242 | } | 5117 | } |
| ... | @@ -5252,11 +5127,9 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { | ... | @@ -5252,11 +5127,9 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5252 | return ErrorSemanticAnalyzeFail; | 5127 | return ErrorSemanticAnalyzeFail; |
| 5253 | break; | 5128 | break; |
| 5254 | case FnAnalStateProbing: { | 5129 | case FnAnalStateProbing: { |
| 5255 | ErrorMsg *msg = add_node_error(g, fn->proto_node, | 5130 | g->trace_err = add_node_error(g, fn->proto_node, |
| 5256 | buf_sprintf("cannot resolve '%s': function not fully analyzed yet", | 5131 | buf_sprintf("cannot resolve '%s': function not fully analyzed yet", |
| 5257 | buf_ptr(&frame_type->name))); | 5132 | buf_ptr(&frame_type->name))); |
| 5258 | ir_add_analysis_trace(fn->ir_executable.analysis, msg, | | |
| 5259 | buf_sprintf("depends on its own frame here")); | | |
| 5260 | return ErrorSemanticAnalyzeFail; | 5133 | return ErrorSemanticAnalyzeFail; |
| 5261 | } | 5134 | } |
| 5262 | } | 5135 | } |
| ... | @@ -5327,10 +5200,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { | ... | @@ -5327,10 +5200,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) { |
| 5327 | if (callee->anal_state == FnAnalStateProbing) { | 5200 | if (callee->anal_state == FnAnalStateProbing) { |
| 5328 | ErrorMsg *msg = add_node_error(g, fn->proto_node, | 5201 | ErrorMsg *msg = add_node_error(g, fn->proto_node, |
| 5329 | buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name))); | 5202 | buf_sprintf("unable to determine async function frame of '%s'", buf_ptr(&fn->symbol_name))); |
| 5330 | ErrorMsg *note = add_error_note(g, msg, call->base.source_node, | 5203 | g->trace_err = add_error_note(g, msg, call->base.source_node, |
| 5331 | buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name))); | 5204 | buf_sprintf("analysis of function '%s' depends on the frame", buf_ptr(&callee->symbol_name))); |
| 5332 | ir_add_analysis_trace(callee->ir_executable.analysis, note, | | |
| 5333 | buf_sprintf("depends on the frame here")); | | |
| 5334 | return ErrorSemanticAnalyzeFail; | 5205 | return ErrorSemanticAnalyzeFail; |
| 5335 | } | 5206 | } |
| 5336 | | 5207 | |
| ... | @@ -6229,6 +6100,40 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) { | ... | @@ -6229,6 +6100,40 @@ bool zig_llvm_fn_key_eql(ZigLLVMFnKey a, ZigLLVMFnKey b) { |
| 6229 | zig_unreachable(); | 6100 | zig_unreachable(); |
| 6230 | } | 6101 | } |
| 6231 | | 6102 | |
| | 6103 | static void init_const_undefined(CodeGen *g, ConstExprValue *const_val) { |
| | 6104 | Error err; |
| | 6105 | ZigType *wanted_type = const_val->type; |
| | 6106 | if (wanted_type->id == ZigTypeIdArray) { |
| | 6107 | const_val->special = ConstValSpecialStatic; |
| | 6108 | const_val->data.x_array.special = ConstArraySpecialUndef; |
| | 6109 | } else if (wanted_type->id == ZigTypeIdStruct) { |
| | 6110 | if ((err = type_resolve(g, wanted_type, ResolveStatusZeroBitsKnown))) { |
| | 6111 | return; |
| | 6112 | } |
| | 6113 | |
| | 6114 | const_val->special = ConstValSpecialStatic; |
| | 6115 | size_t field_count = wanted_type->data.structure.src_field_count; |
| | 6116 | const_val->data.x_struct.fields = create_const_vals(field_count); |
| | 6117 | for (size_t i = 0; i < field_count; i += 1) { |
| | 6118 | ConstExprValue *field_val = &const_val->data.x_struct.fields[i]; |
| | 6119 | field_val->type = wanted_type->data.structure.fields[i].type_entry; |
| | 6120 | assert(field_val->type); |
| | 6121 | init_const_undefined(g, field_val); |
| | 6122 | field_val->parent.id = ConstParentIdStruct; |
| | 6123 | field_val->parent.data.p_struct.struct_val = const_val; |
| | 6124 | field_val->parent.data.p_struct.field_index = i; |
| | 6125 | } |
| | 6126 | } else { |
| | 6127 | const_val->special = ConstValSpecialUndef; |
| | 6128 | } |
| | 6129 | } |
| | 6130 | |
| | 6131 | void expand_undef_struct(CodeGen *g, ConstExprValue *const_val) { |
| | 6132 | if (const_val->special == ConstValSpecialUndef) { |
| | 6133 | init_const_undefined(g, const_val); |
| | 6134 | } |
| | 6135 | } |
| | 6136 | |
| 6232 | // Canonicalize the array value as ConstArraySpecialNone | 6137 | // Canonicalize the array value as ConstArraySpecialNone |
| 6233 | void expand_undef_array(CodeGen *g, ConstExprValue *const_val) { | 6138 | void expand_undef_array(CodeGen *g, ConstExprValue *const_val) { |
| 6234 | size_t elem_count; | 6139 | size_t elem_count; |
| ... | @@ -6707,19 +6612,6 @@ bool ptr_allows_addr_zero(ZigType *ptr_type) { | ... | @@ -6707,19 +6612,6 @@ bool ptr_allows_addr_zero(ZigType *ptr_type) { |
| 6707 | return false; | 6612 | return false; |
| 6708 | } | 6613 | } |
| 6709 | | 6614 | |
| 6710 | void emit_error_notes_for_ref_stack(CodeGen *g, ErrorMsg *msg) { | | |
| 6711 | size_t i = g->tld_ref_source_node_stack.length; | | |
| 6712 | for (;;) { | | |
| 6713 | if (i == 0) | | |
| 6714 | break; | | |
| 6715 | i -= 1; | | |
| 6716 | AstNode *source_node = g->tld_ref_source_node_stack.at(i); | | |
| 6717 | if (source_node) { | | |
| 6718 | msg = add_error_note(g, msg, source_node, buf_sprintf("referenced here")); | | |
| 6719 | } | | |
| 6720 | } | | |
| 6721 | } | | |
| 6722 | | | |
| 6723 | Buf *type_bare_name(ZigType *type_entry) { | 6615 | Buf *type_bare_name(ZigType *type_entry) { |
| 6724 | if (is_slice(type_entry)) { | 6616 | if (is_slice(type_entry)) { |
| 6725 | return &type_entry->name; | 6617 | return &type_entry->name; |
| ... | @@ -7122,10 +7014,9 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS | ... | @@ -7122,10 +7014,9 @@ static void resolve_llvm_types_struct(CodeGen *g, ZigType *struct_type, ResolveS |
| 7122 | struct_type->data.structure.resolve_status = ResolveStatusLLVMFull; | 7014 | struct_type->data.structure.resolve_status = ResolveStatusLLVMFull; |
| 7123 | } | 7015 | } |
| 7124 | | 7016 | |
| 7125 | static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) { | 7017 | static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type, ResolveStatus wanted_resolve_status) { |
| 7126 | assert(!enum_type->data.enumeration.is_invalid); | 7018 | assert(enum_type->data.enumeration.resolve_status >= ResolveStatusSizeKnown); |
| 7127 | assert(enum_type->data.enumeration.complete); | 7019 | if (enum_type->data.enumeration.resolve_status >= wanted_resolve_status) return; |
| 7128 | if (enum_type->llvm_di_type != nullptr) return; | | |
| 7129 | | 7020 | |
| 7130 | Scope *scope = &enum_type->data.enumeration.decls_scope->base; | 7021 | Scope *scope = &enum_type->data.enumeration.decls_scope->base; |
| 7131 | ZigType *import = get_scope_import(scope); | 7022 | ZigType *import = get_scope_import(scope); |
| ... | @@ -7146,6 +7037,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) { | ... | @@ -7146,6 +7037,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) { |
| 7146 | debug_align_in_bits, | 7037 | debug_align_in_bits, |
| 7147 | ZigLLVM_DIFlags_Zero, | 7038 | ZigLLVM_DIFlags_Zero, |
| 7148 | nullptr, di_element_types, (int)debug_field_count, 0, nullptr, ""); | 7039 | nullptr, di_element_types, (int)debug_field_count, 0, nullptr, ""); |
| | 7040 | enum_type->data.enumeration.resolve_status = ResolveStatusLLVMFull; |
| 7149 | return; | 7041 | return; |
| 7150 | } | 7042 | } |
| 7151 | | 7043 | |
| ... | @@ -7178,6 +7070,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) { | ... | @@ -7178,6 +7070,7 @@ static void resolve_llvm_types_enum(CodeGen *g, ZigType *enum_type) { |
| 7178 | get_llvm_di_type(g, tag_int_type), ""); | 7070 | get_llvm_di_type(g, tag_int_type), ""); |
| 7179 | | 7071 | |
| 7180 | enum_type->llvm_di_type = tag_di_type; | 7072 | enum_type->llvm_di_type = tag_di_type; |
| | 7073 | enum_type->data.enumeration.resolve_status = ResolveStatusLLVMFull; |
| 7181 | } | 7074 | } |
| 7182 | | 7075 | |
| 7183 | static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveStatus wanted_resolve_status) { | 7076 | static void resolve_llvm_types_union(CodeGen *g, ZigType *union_type, ResolveStatus wanted_resolve_status) { |
| ... | @@ -7909,7 +7802,7 @@ static void resolve_llvm_types(CodeGen *g, ZigType *type, ResolveStatus wanted_r | ... | @@ -7909,7 +7802,7 @@ static void resolve_llvm_types(CodeGen *g, ZigType *type, ResolveStatus wanted_r |
| 7909 | else | 7802 | else |
| 7910 | return resolve_llvm_types_struct(g, type, wanted_resolve_status, nullptr); | 7803 | return resolve_llvm_types_struct(g, type, wanted_resolve_status, nullptr); |
| 7911 | case ZigTypeIdEnum: | 7804 | case ZigTypeIdEnum: |
| 7912 | return resolve_llvm_types_enum(g, type); | 7805 | return resolve_llvm_types_enum(g, type, wanted_resolve_status); |
| 7913 | case ZigTypeIdUnion: | 7806 | case ZigTypeIdUnion: |
| 7914 | return resolve_llvm_types_union(g, type, wanted_resolve_status); | 7807 | return resolve_llvm_types_union(g, type, wanted_resolve_status); |
| 7915 | case ZigTypeIdPointer: | 7808 | case ZigTypeIdPointer: |