From e7e1866e5047a85648e758a2d94c8247c65a6608 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 27 Apr 2021 13:09:37 +0100 Subject: [PATCH] Fix #893 --- core/fmt/fmt.odin | 11 ----------- src/check_decl.cpp | 5 +++-- src/check_expr.cpp | 5 +++-- src/checker.cpp | 7 +++++-- src/entity.cpp | 2 ++ src/llvm_backend.cpp | 38 +++++++++++++++++++++++--------------- 6 files changed, 36 insertions(+), 32 deletions(-) diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin index 6de6b0245..f9c386ffb 100644 --- a/core/fmt/fmt.odin +++ b/core/fmt/fmt.odin @@ -1908,17 +1908,6 @@ fmt_value :: proc(fi: ^Info, v: any, verb: rune) { } } - - handle_relative_pointer :: proc(ptr: ^$T) -> rawptr where intrinsics.type_is_integer(T) { - if ptr^ == 0 { - return nil; - } - when intrinsics.type_is_unsigned(T) { - return rawptr(uintptr(ptr) + uintptr(ptr^)); - } else { - return rawptr(uintptr(ptr) + uintptr(i64(ptr^))); - } - } } fmt_complex :: proc(fi: ^Info, c: complex128, bits: int, verb: rune) { diff --git a/src/check_decl.cpp b/src/check_decl.cpp index f008317ad..f43248593 100644 --- a/src/check_decl.cpp +++ b/src/check_decl.cpp @@ -352,16 +352,17 @@ void override_entity_in_scope(Entity *original_entity, Entity *new_entity) { string_map_set(&found_scope->elements, original_name, new_entity); + original_entity->flags |= EntityFlag_Overridden; original_entity->type = new_entity->type; + original_entity->aliased_of = new_entity; if (original_entity->identifier == nullptr) { original_entity->identifier = new_entity->identifier; } if (original_entity->identifier != nullptr && original_entity->identifier->kind == Ast_Ident) { - original_entity->identifier->Ident.entity = nullptr; + original_entity->identifier->Ident.entity = new_entity; } - original_entity->flags |= EntityFlag_Overridden; // IMPORTANT NOTE(bill, 2021-04-10): copy only the variants // This is most likely NEVER required, but it does not at all hurt to keep diff --git a/src/check_expr.cpp b/src/check_expr.cpp index 6c4a78e53..91f0e5d84 100644 --- a/src/check_expr.cpp +++ b/src/check_expr.cpp @@ -1141,6 +1141,9 @@ Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *named_type, Typ } return nullptr; } + + GB_ASSERT((e->flags & EntityFlag_Overridden) == 0); + if (e->parent_proc_decl != nullptr && e->parent_proc_decl != c->curr_proc_decl) { if (e->kind == Entity_Variable) { @@ -1195,8 +1198,6 @@ Entity *check_ident(CheckerContext *c, Operand *o, Ast *n, Type *named_type, Typ if (e->state == EntityState_Unresolved) { check_entity_decl(c, e, nullptr, named_type); } - - if (e->type == nullptr) { // TODO(bill): Which is correct? return or compiler_error? // compiler_error("How did this happen? type: %s; identifier: %.*s\n", type_to_string(e->type), LIT(name)); diff --git a/src/checker.cpp b/src/checker.cpp index 878435d67..eaf3b5322 100644 --- a/src/checker.cpp +++ b/src/checker.cpp @@ -960,7 +960,11 @@ Entity *entity_of_node(Ast *expr) { expr = unparen_expr(expr); switch (expr->kind) { case_ast_node(ident, Ident, expr); - return ident->entity; + Entity *e = ident->entity; + if (e && e->flags & EntityFlag_Overridden) { + // GB_PANIC("use of an overriden entity: %.*s", LIT(e->token.string)); + } + return e; case_end; case_ast_node(se, SelectorExpr, expr); Ast *s = unselector_expr(se->selector); @@ -973,7 +977,6 @@ Entity *entity_of_node(Ast *expr) { return nullptr; } - DeclInfo *decl_info_of_entity(Entity *e) { if (e != nullptr) { return e->decl_info; diff --git a/src/entity.cpp b/src/entity.cpp index d1f4c78e6..460f4ec6d 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -126,6 +126,8 @@ struct Entity { Entity * using_parent; Ast * using_expr; + Entity * aliased_of; + lbModule * code_gen_module; lbProcedure *code_gen_procedure; diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index 758f8e5d1..52c69c7c7 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -3544,16 +3544,14 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { Ast *ident = vd->names[i]; GB_ASSERT(ident->kind == Ast_Ident); Entity *e = entity_of_node(ident); - if (e == nullptr) { - continue; - } + GB_ASSERT(e != nullptr); if (e->kind != Entity_TypeName) { continue; } bool polymorphic_struct = false; if (e->type != nullptr && e->kind == Entity_TypeName) { - Type *bt = base_type(e->type); + Type *bt = base_type(e->type); if (bt->kind == Type_Struct) { polymorphic_struct = bt->Struct.is_polymorphic; } @@ -3575,12 +3573,16 @@ void lb_build_constant_value_decl(lbProcedure *p, AstValueDecl *vd) { Ast *ident = vd->names[i]; GB_ASSERT(ident->kind == Ast_Ident); Entity *e = entity_of_node(ident); - if (e == nullptr) { - continue; - } + GB_ASSERT(e != nullptr); if (e->kind != Entity_Procedure) { continue; } + GB_ASSERT (vd->values[i] != nullptr); + + Ast *value = unparen_expr(vd->values[i]); + if (value->kind != Ast_ProcLit) { + continue; // It's an alias + } CheckerInfo *info = p->module->info; DeclInfo *decl = decl_info_of_entity(e); @@ -11436,7 +11438,13 @@ lbValue lb_get_using_variable(lbProcedure *p, Entity *e) { GB_ASSERT(v.value != nullptr); GB_ASSERT_MSG(parent->type == type_deref(v.type), "%s %s", type_to_string(parent->type), type_to_string(v.type)); lbValue ptr = lb_emit_deep_field_gep(p, v, sel); - lb_add_debug_local_variable(p, ptr.value, e->type, e->token); + if (parent->scope) { + if ((parent->scope->flags & (ScopeFlag_File|ScopeFlag_Pkg)) == 0) { + lb_add_debug_local_variable(p, ptr.value, e->type, e->token); + } + } else { + lb_add_debug_local_variable(p, ptr.value, e->type, e->token); + } return ptr; } @@ -13778,13 +13786,13 @@ void lb_generate_code(lbGenerator *gen) { } gbString producer = gb_string_make(heap_allocator(), "odin"); - producer = gb_string_append_fmt(producer, " version %.*s", LIT(ODIN_VERSION)); - #ifdef NIGHTLY - producer = gb_string_appendc(producer, "-nightly"); - #endif - #ifdef GIT_SHA - producer = gb_string_append_fmt(producer, "-%s", GIT_SHA); - #endif + // producer = gb_string_append_fmt(producer, " version %.*s", LIT(ODIN_VERSION)); + // #ifdef NIGHTLY + // producer = gb_string_appendc(producer, "-nightly"); + // #endif + // #ifdef GIT_SHA + // producer = gb_string_append_fmt(producer, "-%s", GIT_SHA); + // #endif gbString split_name = gb_string_make(heap_allocator(), "");