Browse Source

Fix Internal Compiler Error: Type_Info for 'XXX' could not be found #507

gingerBill 5 years ago
parent
commit
1d14b3059e
4 changed files with 20 additions and 11 deletions
  1. 2 0
      core/math/math.odin
  2. 10 5
      src/checker.cpp
  3. 1 1
      src/checker.hpp
  4. 7 5
      src/ir.cpp

+ 2 - 0
core/math/math.odin

@@ -157,6 +157,7 @@ trunc_f32 :: proc(x: f32) -> f32 {
 	switch classify(x) {
 	case .Zero, .Neg_Zero, .NaN, .Inf, .Neg_Inf:
 		return x;
+	case .Normal, .Subnormal: // carry on
 	}
 	return trunc_internal(x);
 }
@@ -186,6 +187,7 @@ trunc_f64 :: proc(x: f64) -> f64 {
 	switch classify(x) {
 	case .Zero, .Neg_Zero, .NaN, .Inf, .Neg_Inf:
 		return x;
+	case .Normal, .Subnormal: // carry on
 	}
 	return trunc_internal(x);
 }

+ 10 - 5
src/checker.cpp

@@ -1435,7 +1435,12 @@ void add_min_dep_type_info(Checker *c, Type *t) {
 
 	auto *set = &c->info.minimum_dependency_type_info_set;
 
-	isize ti_index = type_info_index(&c->info, t);
+	isize ti_index = type_info_index(&c->info, t, false);
+	if (ti_index < 0) {
+		add_type_info_type(&c->init_ctx, t); // Missing the type information
+		ti_index = type_info_index(&c->info, t, false);
+	}
+	GB_ASSERT(ti_index >= 0);
 	if (ptr_set_exists(set, ti_index)) {
 		// Type Already exists
 		return;
@@ -1528,16 +1533,16 @@ void add_min_dep_type_info(Checker *c, Type *t) {
 		break;
 
 	case Type_Struct:
+		for_array(i, bt->Struct.fields) {
+			Entity *f = bt->Struct.fields[i];
+			add_min_dep_type_info(c, f->type);
+		}
 		if (bt->Struct.scope != nullptr) {
 			for_array(i, bt->Struct.scope->elements.entries) {
 				Entity *e = bt->Struct.scope->elements.entries[i].value;
 				add_min_dep_type_info(c, e->type);
 			}
 		}
-		for_array(i, bt->Struct.fields) {
-			Entity *f = bt->Struct.fields[i];
-			add_min_dep_type_info(c, f->type);
-		}
 		break;
 
 	case Type_BitFieldValue:

+ 1 - 1
src/checker.hpp

@@ -330,7 +330,7 @@ DeclInfo *   decl_info_of_ident     (Ast *ident);
 DeclInfo *   decl_info_of_entity    (Entity * e);
 AstFile *    ast_file_of_filename   (CheckerInfo *i, String   filename);
 // IMPORTANT: Only to use once checking is done
-isize        type_info_index        (CheckerInfo *i, Type *   type, bool error_on_failure = true);
+isize        type_info_index        (CheckerInfo *i, Type *type, bool error_on_failure);
 
 // Will return nullptr if not found
 Entity *entity_of_node(Ast *expr);

+ 7 - 5
src/ir.cpp

@@ -5800,11 +5800,13 @@ isize ir_type_info_count(CheckerInfo *info) {
 }
 
 isize ir_type_info_index(CheckerInfo *info, Type *type, bool err_on_not_found=true) {
-	isize index = type_info_index(info, type);
-	auto *set = &info->minimum_dependency_type_info_set;
-	for_array(i, set->entries) {
-		if (set->entries[i].ptr == index) {
-			return i+1;
+	isize index = type_info_index(info, type, false);
+	if (index >= 0) {
+		auto *set = &info->minimum_dependency_type_info_set;
+		for_array(i, set->entries) {
+			if (set->entries[i].ptr == index) {
+				return i+1;
+			}
 		}
 	}
 	if (err_on_not_found) {