mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-29 10:50:05 +00:00
Fix missing type_info with manual linear search
This commit is contained in:
@@ -866,7 +866,7 @@ void check_parsed_files(Checker *c) {
|
||||
t_type_info_ptr = make_type_pointer(c->allocator, t_type_info);
|
||||
|
||||
auto *record = &get_base_type(e->type)->Record;
|
||||
GB_ASSERT(record->field_count == 15);
|
||||
GB_ASSERT_MSG(record->field_count == 15, "Internal Compiler Error: Invalid `Type_Info` layout");
|
||||
t_type_info_named = record->fields[ 1]->type;
|
||||
t_type_info_integer = record->fields[ 2]->type;
|
||||
t_type_info_float = record->fields[ 3]->type;
|
||||
@@ -881,6 +881,7 @@ void check_parsed_files(Checker *c) {
|
||||
t_type_info_union = record->fields[12]->type;
|
||||
t_type_info_raw_union = record->fields[13]->type;
|
||||
t_type_info_enum = record->fields[14]->type;
|
||||
// t_type_info_any = record->fields[15]->type;
|
||||
}
|
||||
|
||||
check_global_entity(c, Entity_Constant);
|
||||
|
||||
@@ -6,7 +6,6 @@ enum BuiltinProcId;
|
||||
ENTITY_KIND(Invalid), \
|
||||
ENTITY_KIND(Constant), \
|
||||
ENTITY_KIND(Variable), \
|
||||
ENTITY_KIND(UsingVariable), \
|
||||
ENTITY_KIND(TypeName), \
|
||||
ENTITY_KIND(Procedure), \
|
||||
ENTITY_KIND(Builtin), \
|
||||
@@ -46,10 +45,12 @@ struct Entity {
|
||||
b8 used; // Variable is used
|
||||
b8 is_field; // Is struct field
|
||||
b8 anonymous; // Variable is an anonymous
|
||||
b8 is_using; // `using` variable
|
||||
} Variable;
|
||||
struct {} UsingVariable;
|
||||
struct {} TypeName;
|
||||
struct { b8 used; } Procedure;
|
||||
struct {
|
||||
b8 pure;
|
||||
} Procedure;
|
||||
struct { BuiltinProcId id; } Builtin;
|
||||
};
|
||||
};
|
||||
@@ -77,8 +78,9 @@ Entity *make_entity_variable(gbAllocator a, Scope *scope, Token token, Type *typ
|
||||
|
||||
Entity *make_entity_using_variable(gbAllocator a, Entity *parent, Token token, Type *type) {
|
||||
GB_ASSERT(parent != NULL);
|
||||
Entity *entity = alloc_entity(a, Entity_UsingVariable, parent->scope, token, type);
|
||||
Entity *entity = alloc_entity(a, Entity_Variable, parent->scope, token, type);
|
||||
entity->using_parent = parent;
|
||||
entity->Variable.is_using = true;
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
@@ -91,8 +91,6 @@ b32 check_is_assignable_to(Checker *c, Operand *operand, Type *type, b32 is_argu
|
||||
|
||||
Type *s = operand->type;
|
||||
|
||||
|
||||
|
||||
if (are_types_identical(s, type)) {
|
||||
return true;
|
||||
}
|
||||
@@ -179,6 +177,7 @@ void check_assignment(Checker *c, Operand *operand, Type *type, String context_n
|
||||
Type *target_type = type;
|
||||
|
||||
if (type == NULL || is_type_any(type)) {
|
||||
add_type_info_type(c, type);
|
||||
target_type = default_type(operand->type);
|
||||
}
|
||||
convert_to_typed(c, operand, target_type);
|
||||
@@ -795,11 +794,6 @@ void check_identifier(Checker *c, Operand *o, AstNode *n, Type *named_type, Cycl
|
||||
o->mode = Addressing_Builtin;
|
||||
break;
|
||||
|
||||
case Entity_UsingVariable:
|
||||
// TODO(bill): Entity_UsingVariable: is this correct?
|
||||
o->mode = Addressing_Variable;
|
||||
break;
|
||||
|
||||
default:
|
||||
GB_PANIC("Compiler error: Unknown EntityKind");
|
||||
break;
|
||||
|
||||
@@ -452,6 +452,7 @@ void check_proc_decl(Checker *c, Entity *e, DeclInfo *d, b32 check_body_later) {
|
||||
b32 is_foreign = (pd->tags & ProcTag_foreign) != 0;
|
||||
b32 is_inline = (pd->tags & ProcTag_inline) != 0;
|
||||
b32 is_no_inline = (pd->tags & ProcTag_no_inline) != 0;
|
||||
b32 is_pure = (pd->tags & ProcTag_pure) != 0;
|
||||
|
||||
|
||||
|
||||
@@ -1283,8 +1284,7 @@ void check_stmt(Checker *c, AstNode *node, u32 flags) {
|
||||
error(&c->error_collector, us->token, "`using` cannot be applied to a procedure");
|
||||
break;
|
||||
|
||||
case Entity_Variable:
|
||||
case Entity_UsingVariable: {
|
||||
case Entity_Variable: {
|
||||
Type *t = get_base_type(type_deref(e->type));
|
||||
if (is_type_struct(t) || is_type_raw_union(t)) {
|
||||
Scope **found = map_get(&c->info.scopes, hash_pointer(t->Record.node));
|
||||
|
||||
@@ -369,6 +369,7 @@ gb_global Type *t_type_info_struct = NULL;
|
||||
gb_global Type *t_type_info_union = NULL;
|
||||
gb_global Type *t_type_info_raw_union = NULL;
|
||||
gb_global Type *t_type_info_enum = NULL;
|
||||
gb_global Type *t_type_info_any = NULL;
|
||||
|
||||
|
||||
|
||||
|
||||
+17
-7
@@ -1532,7 +1532,6 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *t, b32 is_arg
|
||||
ssaValue *type_info_data = *found;
|
||||
CheckerInfo *info = proc->module->info;
|
||||
|
||||
|
||||
ssaValue *result = ssa_add_local_generated(proc, t_any);
|
||||
|
||||
// NOTE(bill): Make copy on stack so I can reference it later
|
||||
@@ -1542,8 +1541,20 @@ ssaValue *ssa_emit_conv(ssaProcedure *proc, ssaValue *value, Type *t, b32 is_arg
|
||||
|
||||
|
||||
MapFindResult fr = map__find(&info->type_info_types, hash_pointer(src_type));
|
||||
GB_ASSERT(fr.entry_index >= 0);
|
||||
ssaValue *ti = ssa_emit_struct_gep(proc, type_info_data, fr.entry_index, t_type_info_ptr);
|
||||
isize entry_index = fr.entry_index;
|
||||
if (entry_index < 0) {
|
||||
// NOTE(bill): Do manual search
|
||||
// TODO(bill): This is O(n) and can be very slow
|
||||
gb_for_array(i, info->type_info_types.entries){
|
||||
auto *e = &info->type_info_types.entries[i];
|
||||
Type *t = e->value;
|
||||
if (are_types_identical(t, src_type)) {
|
||||
entry_index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ssaValue *ti = ssa_emit_struct_gep(proc, type_info_data, entry_index, t_type_info_ptr);
|
||||
|
||||
ssaValue *gep0 = ssa_emit_struct_gep(proc, result, v_zero32, make_type_pointer(proc->module->allocator, t_type_info_ptr));
|
||||
ssaValue *gep1 = ssa_emit_struct_gep(proc, result, v_one32, make_type_pointer(proc->module->allocator, t_rawptr));
|
||||
@@ -2396,11 +2407,11 @@ ssaValue *ssa_build_expr(ssaProcedure *proc, AstNode *expr) {
|
||||
|
||||
|
||||
ssaValue *ssa_add_using_variable(ssaProcedure *proc, Entity *e) {
|
||||
GB_ASSERT(e->kind == Entity_UsingVariable);
|
||||
GB_ASSERT(e->kind == Entity_Variable && e->Variable.is_using);
|
||||
String name = e->token.string;
|
||||
Entity *parent = e->using_parent;
|
||||
ssaValue *p = NULL;
|
||||
if (parent->kind == Entity_UsingVariable) {
|
||||
if (parent->kind == Entity_Variable && parent->Variable.is_using) {
|
||||
p = ssa_add_using_variable(proc, parent);
|
||||
}
|
||||
|
||||
@@ -2432,7 +2443,7 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
|
||||
ssaValue **found = map_get(&proc->module->values, hash_pointer(e));
|
||||
if (found) {
|
||||
v = *found;
|
||||
} else if (e->kind == Entity_UsingVariable) {
|
||||
} else if (e->kind == Entity_Variable && e->Variable.is_using) {
|
||||
v = ssa_add_using_variable(proc, e);
|
||||
}
|
||||
if (v == NULL) {
|
||||
@@ -2536,7 +2547,6 @@ ssaAddr ssa_build_addr(ssaProcedure *proc, AstNode *expr) {
|
||||
|
||||
ssaValue *index = ssa_emit_conv(proc, ssa_build_expr(proc, ie->index), t_int);
|
||||
v = ssa_emit_ptr_offset(proc, elem, index);
|
||||
// gb_printf_err("HERE! %s -> %s\n", type_to_string(ssa_type(v)), expr_to_string(expr));
|
||||
return ssa_make_addr(v, expr);
|
||||
case_end;
|
||||
|
||||
|
||||
+2
-2
@@ -41,14 +41,14 @@ i32 win32_exec_command_line_app(char *fmt, ...) {
|
||||
}
|
||||
|
||||
|
||||
#if 1
|
||||
#if defined(DISPLAY_TIMING)
|
||||
#define INIT_TIMER() u64 start_time, end_time = 0, total_time = 0; start_time = gb_utc_time_now()
|
||||
#define PRINT_TIMER(section) do { \
|
||||
u64 diff; \
|
||||
end_time = gb_utc_time_now(); \
|
||||
diff = end_time - start_time; \
|
||||
total_time += diff; \
|
||||
gb_printf_err("%s: %lld ms\n", section, diff/1000); \
|
||||
gb_printf_err("%s: %.1f ms\n", section, diff/1000.0f); \
|
||||
start_time = gb_utc_time_now(); \
|
||||
} while (0)
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@ enum ProcTag {
|
||||
ProcTag_foreign = GB_BIT(0),
|
||||
ProcTag_inline = GB_BIT(1),
|
||||
ProcTag_no_inline = GB_BIT(2),
|
||||
ProcTag_pure = GB_BIT(3),
|
||||
};
|
||||
|
||||
enum VarDeclTag {
|
||||
@@ -1157,6 +1158,8 @@ void parse_proc_tags(AstFile *f, u64 *tags, String *foreign_name) {
|
||||
check_proc_add_tag(f, tag_expr, tags, ProcTag_inline, tag_name);
|
||||
} else if (are_strings_equal(tag_name, make_string("no_inline"))) {
|
||||
check_proc_add_tag(f, tag_expr, tags, ProcTag_no_inline, tag_name);
|
||||
} else if (are_strings_equal(tag_name, make_string("pure"))) {
|
||||
check_proc_add_tag(f, tag_expr, tags, ProcTag_pure, tag_name);
|
||||
} else {
|
||||
ast_file_err(f, ast_node_token(tag_expr), "Unknown procedure tag");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user