@@ -17934,7 +17934,6 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, AstNode *source_node, ZigVa
17934
17934
17935
17935
ensure_field_index(type_info_declaration_type, "name", 0);
17936
17936
ensure_field_index(type_info_declaration_type, "is_pub", 1);
17937
- ensure_field_index(type_info_declaration_type, "data", 2);
17938
17937
17939
17938
if (!resolve_types) {
17940
17939
ZigType *ptr_type = get_pointer_to_type_extra(ira->codegen, type_info_declaration_type,
@@ -17954,61 +17953,27 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, AstNode *source_node, ZigVa
17954
17953
return ErrorNone;
17955
17954
}
17956
17955
17957
- ZigType *type_info_declaration_data_type = ir_type_info_get_type(ira, "Data", type_info_declaration_type);
17958
- if ((err = type_resolve(ira->codegen, type_info_declaration_data_type, ResolveStatusSizeKnown)))
17959
- return err;
17960
-
17961
- ZigType *type_info_fn_decl_type = ir_type_info_get_type(ira, "FnDecl", type_info_declaration_data_type);
17962
- if ((err = type_resolve(ira->codegen, type_info_fn_decl_type, ResolveStatusSizeKnown)))
17963
- return err;
17964
-
17965
17956
resolve_container_usingnamespace_decls(ira->codegen, decls_scope);
17966
17957
17967
- // The unresolved declarations are collected in a separate queue to avoid
17968
- // modifying decl_table while iterating over it
17969
- ZigList<Tld*> resolve_decl_queue{};
17970
-
17958
+ // Loop through our declarations once to figure out how many declarations
17959
+ // we will generate info for.
17960
+ int declaration_count = 0;
17971
17961
auto decl_it = decls_scope->decl_table.entry_iterator();
17972
17962
decltype(decls_scope->decl_table)::Entry *curr_entry = nullptr;
17973
- while ((curr_entry = decl_it.next()) != nullptr) {
17974
- if (curr_entry->value->resolution == TldResolutionInvalid) {
17975
- return ErrorSemanticAnalyzeFail;
17976
- }
17977
-
17978
- if (curr_entry->value->resolution == TldResolutionResolving) {
17979
- ir_error_dependency_loop(ira, source_node);
17980
- return ErrorSemanticAnalyzeFail;
17981
- }
17982
-
17983
- // If the declaration is unresolved, force it to be resolved again.
17984
- if (curr_entry->value->resolution == TldResolutionUnresolved)
17985
- resolve_decl_queue.append(curr_entry->value);
17986
- }
17987
-
17988
- for (size_t i = 0; i < resolve_decl_queue.length; i++) {
17989
- Tld *decl = resolve_decl_queue.at(i);
17990
- resolve_top_level_decl(ira->codegen, decl, decl->source_node, false);
17991
- if (decl->resolution == TldResolutionInvalid) {
17992
- return ErrorSemanticAnalyzeFail;
17993
- }
17994
- }
17995
-
17996
- resolve_decl_queue.deinit();
17997
-
17998
- // Loop through our declarations once to figure out how many declarations we will generate info for.
17999
- int declaration_count = 0;
18000
- decl_it = decls_scope->decl_table.entry_iterator();
18001
17963
while ((curr_entry = decl_it.next()) != nullptr) {
18002
17964
// Skip comptime blocks and test functions.
18003
17965
if (curr_entry->value->id == TldIdCompTime)
18004
17966
continue;
18005
17967
18006
- if (curr_entry->value->id == TldIdFn) {
18007
- ZigFn *fn_entry = ((TldFn *) curr_entry->value)->fn_entry;
18008
- if (fn_entry->is_test)
18009
- continue;
17968
+ if (curr_entry->value->id == TldIdFn &&
17969
+ curr_entry->value->source_node->type == NodeTypeTestDecl)
17970
+ {
17971
+ continue;
18010
17972
}
18011
17973
17974
+ if (curr_entry->value->resolution == TldResolutionInvalid)
17975
+ return ErrorSemanticAnalyzeFail;
17976
+
18012
17977
declaration_count += 1;
18013
17978
}
18014
17979
@@ -18027,154 +17992,24 @@ static Error ir_make_type_info_decls(IrAnalyze *ira, AstNode *source_node, ZigVa
18027
17992
// Skip comptime blocks and test functions.
18028
17993
if (curr_entry->value->id == TldIdCompTime) {
18029
17994
continue;
18030
- } else if (curr_entry->value->id == TldIdFn) {
18031
- ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
18032
- if (fn_entry->is_test)
18033
- continue;
17995
+ }
17996
+ if (curr_entry->value->id == TldIdFn &&
17997
+ curr_entry->value->source_node->type == NodeTypeTestDecl)
17998
+ {
17999
+ continue;
18034
18000
}
18035
18001
18036
18002
ZigValue *declaration_val = &declaration_array->data.x_array.data.s_none.elements[declaration_index];
18037
18003
18038
18004
declaration_val->special = ConstValSpecialStatic;
18039
18005
declaration_val->type = type_info_declaration_type;
18040
18006
18041
- ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 3 );
18007
+ ZigValue **inner_fields = alloc_const_vals_ptrs(ira->codegen, 2 );
18042
18008
ZigValue *name = create_const_str_lit(ira->codegen, curr_entry->key)->data.x_ptr.data.ref.pointee;
18043
18009
init_const_slice(ira->codegen, inner_fields[0], name, 0, buf_len(curr_entry->key), true, nullptr);
18044
18010
inner_fields[1]->special = ConstValSpecialStatic;
18045
18011
inner_fields[1]->type = ira->codegen->builtin_types.entry_bool;
18046
18012
inner_fields[1]->data.x_bool = curr_entry->value->visib_mod == VisibModPub;
18047
- inner_fields[2]->special = ConstValSpecialStatic;
18048
- inner_fields[2]->type = type_info_declaration_data_type;
18049
- inner_fields[2]->parent.id = ConstParentIdStruct;
18050
- inner_fields[2]->parent.data.p_struct.struct_val = declaration_val;
18051
- inner_fields[2]->parent.data.p_struct.field_index = 1;
18052
-
18053
- switch (curr_entry->value->id) {
18054
- case TldIdVar:
18055
- {
18056
- ZigVar *var = ((TldVar *)curr_entry->value)->var;
18057
- assert(var != nullptr);
18058
-
18059
- if ((err = type_resolve(ira->codegen, var->const_value->type, ResolveStatusSizeKnown)))
18060
- return ErrorSemanticAnalyzeFail;
18061
-
18062
- if (var->const_value->type->id == ZigTypeIdMetaType) {
18063
- // We have a variable of type 'type', so it's actually a type declaration.
18064
- // 0: Data.Type: type
18065
- bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 0);
18066
- inner_fields[2]->data.x_union.payload = var->const_value;
18067
- } else {
18068
- // We have a variable of another type, so we store the type of the variable.
18069
- // 1: Data.Var: type
18070
- bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 1);
18071
-
18072
- ZigValue *payload = ira->codegen->pass1_arena->create<ZigValue>();
18073
- payload->special = ConstValSpecialStatic;
18074
- payload->type = ira->codegen->builtin_types.entry_type;
18075
- payload->data.x_type = var->const_value->type;
18076
-
18077
- inner_fields[2]->data.x_union.payload = payload;
18078
- }
18079
-
18080
- break;
18081
- }
18082
- case TldIdFn:
18083
- {
18084
- // 2: Data.Fn: Data.FnDecl
18085
- bigint_init_unsigned(&inner_fields[2]->data.x_union.tag, 2);
18086
-
18087
- ZigFn *fn_entry = ((TldFn *)curr_entry->value)->fn_entry;
18088
- assert(!fn_entry->is_test);
18089
- assert(fn_entry->type_entry != nullptr);
18090
-
18091
- AstNodeFnProto *fn_node = &fn_entry->proto_node->data.fn_proto;
18092
-
18093
- ZigValue *fn_decl_val = ira->codegen->pass1_arena->create<ZigValue>();
18094
- fn_decl_val->special = ConstValSpecialStatic;
18095
- fn_decl_val->type = type_info_fn_decl_type;
18096
- fn_decl_val->parent.id = ConstParentIdUnion;
18097
- fn_decl_val->parent.data.p_union.union_val = inner_fields[2];
18098
-
18099
- ZigValue **fn_decl_fields = alloc_const_vals_ptrs(ira->codegen, 9);
18100
- fn_decl_val->data.x_struct.fields = fn_decl_fields;
18101
-
18102
- // fn_type: type
18103
- ensure_field_index(fn_decl_val->type, "fn_type", 0);
18104
- fn_decl_fields[0]->special = ConstValSpecialStatic;
18105
- fn_decl_fields[0]->type = ira->codegen->builtin_types.entry_type;
18106
- fn_decl_fields[0]->data.x_type = fn_entry->type_entry;
18107
- // is_noinline: bool
18108
- ensure_field_index(fn_decl_val->type, "is_noinline", 1);
18109
- fn_decl_fields[1]->special = ConstValSpecialStatic;
18110
- fn_decl_fields[1]->type = ira->codegen->builtin_types.entry_bool;
18111
- fn_decl_fields[1]->data.x_bool = fn_entry->is_noinline;
18112
- // is_var_args: bool
18113
- ensure_field_index(fn_decl_val->type, "is_var_args", 2);
18114
- bool is_varargs = fn_node->is_var_args;
18115
- fn_decl_fields[2]->special = ConstValSpecialStatic;
18116
- fn_decl_fields[2]->type = ira->codegen->builtin_types.entry_bool;
18117
- fn_decl_fields[2]->data.x_bool = is_varargs;
18118
- // is_extern: bool
18119
- ensure_field_index(fn_decl_val->type, "is_extern", 3);
18120
- fn_decl_fields[3]->special = ConstValSpecialStatic;
18121
- fn_decl_fields[3]->type = ira->codegen->builtin_types.entry_bool;
18122
- fn_decl_fields[3]->data.x_bool = fn_node->is_extern;
18123
- // is_export: bool
18124
- ensure_field_index(fn_decl_val->type, "is_export", 4);
18125
- fn_decl_fields[4]->special = ConstValSpecialStatic;
18126
- fn_decl_fields[4]->type = ira->codegen->builtin_types.entry_bool;
18127
- fn_decl_fields[4]->data.x_bool = fn_node->is_export;
18128
- // lib_name: ?[]const u8
18129
- ensure_field_index(fn_decl_val->type, "lib_name", 5);
18130
- fn_decl_fields[5]->special = ConstValSpecialStatic;
18131
- ZigType *u8_ptr = get_pointer_to_type_extra(
18132
- ira->codegen, ira->codegen->builtin_types.entry_u8,
18133
- true, false, PtrLenUnknown,
18134
- 0, 0, 0, false);
18135
- fn_decl_fields[5]->type = get_optional_type(ira->codegen, get_slice_type(ira->codegen, u8_ptr));
18136
- if (fn_node->is_extern && fn_node->lib_name != nullptr && buf_len(fn_node->lib_name) > 0) {
18137
- ZigValue *slice_val = ira->codegen->pass1_arena->create<ZigValue>();
18138
- ZigValue *lib_name = create_const_str_lit(ira->codegen, fn_node->lib_name)->data.x_ptr.data.ref.pointee;
18139
- init_const_slice(ira->codegen, slice_val, lib_name, 0, buf_len(fn_node->lib_name), true, nullptr);
18140
- set_optional_payload(fn_decl_fields[5], slice_val);
18141
- } else {
18142
- set_optional_payload(fn_decl_fields[5], nullptr);
18143
- }
18144
- // return_type: type
18145
- ensure_field_index(fn_decl_val->type, "return_type", 6);
18146
- fn_decl_fields[6]->special = ConstValSpecialStatic;
18147
- fn_decl_fields[6]->type = ira->codegen->builtin_types.entry_type;
18148
- fn_decl_fields[6]->data.x_type = fn_entry->type_entry->data.fn.fn_type_id.return_type;
18149
- // arg_names: [][] const u8
18150
- ensure_field_index(fn_decl_val->type, "arg_names", 7);
18151
- size_t fn_arg_count = fn_entry->variable_list.length;
18152
- ZigValue *fn_arg_name_array = ira->codegen->pass1_arena->create<ZigValue>();
18153
- fn_arg_name_array->special = ConstValSpecialStatic;
18154
- fn_arg_name_array->type = get_array_type(ira->codegen,
18155
- get_slice_type(ira->codegen, u8_ptr), fn_arg_count, nullptr);
18156
- fn_arg_name_array->data.x_array.special = ConstArraySpecialNone;
18157
- fn_arg_name_array->data.x_array.data.s_none.elements = ira->codegen->pass1_arena->allocate<ZigValue>(fn_arg_count);
18158
-
18159
- init_const_slice(ira->codegen, fn_decl_fields[7], fn_arg_name_array, 0, fn_arg_count, false, nullptr);
18160
-
18161
- for (size_t fn_arg_index = 0; fn_arg_index < fn_arg_count; fn_arg_index++) {
18162
- ZigVar *arg_var = fn_entry->variable_list.at(fn_arg_index);
18163
- ZigValue *fn_arg_name_val = &fn_arg_name_array->data.x_array.data.s_none.elements[fn_arg_index];
18164
- ZigValue *arg_name = create_const_str_lit(ira->codegen,
18165
- buf_create_from_str(arg_var->name))->data.x_ptr.data.ref.pointee;
18166
- init_const_slice(ira->codegen, fn_arg_name_val, arg_name, 0, strlen(arg_var->name), true, nullptr);
18167
- fn_arg_name_val->parent.id = ConstParentIdArray;
18168
- fn_arg_name_val->parent.data.p_array.array_val = fn_arg_name_array;
18169
- fn_arg_name_val->parent.data.p_array.elem_index = fn_arg_index;
18170
- }
18171
-
18172
- inner_fields[2]->data.x_union.payload = fn_decl_val;
18173
- break;
18174
- }
18175
- default:
18176
- zig_unreachable();
18177
- }
18178
18013
18179
18014
declaration_val->data.x_struct.fields = inner_fields;
18180
18015
declaration_index += 1;
0 commit comments