Browse Source

Split up `init_preload` into specific parts

gingerBill 7 years ago
parent
commit
9bd7f023b2
6 changed files with 182 additions and 212 deletions
  1. 73 86
      core/bits/bits.odin
  2. 6 6
      src/check_expr.cpp
  3. 3 3
      src/check_type.cpp
  4. 98 112
      src/checker.cpp
  5. 2 3
      src/checker.hpp
  6. 0 2
      src/entity.cpp

+ 73 - 86
core/bits/bits.odin

@@ -2,50 +2,50 @@ package bits
 
 import "core:os"
 
-U8_MIN   ::   u8(0);
-U16_MIN  ::  u16(0);
-U32_MIN  ::  u32(0);
-U64_MIN  ::  u64(0);
-
-U8_MAX   ::   ~u8(0);
-U16_MAX  ::  ~u16(0);
-U32_MAX  ::  ~u32(0);
-U64_MAX  ::  ~u64(0);
-
-I8_MIN   ::   i8(  ~u8(0) >> 1);
-I16_MIN  ::  i16( ~u16(0) >> 1);
-I32_MIN  ::  i32( ~u32(0) >> 1);
-I64_MIN  ::  i64( ~u64(0) >> 1);
-
-I8_MAX   ::   -I8_MIN - 1;
-I16_MAX  ::  -I16_MIN - 1;
-I32_MAX  ::  -I32_MIN - 1;
-I64_MAX  ::  -I64_MIN - 1;
+U8_MIN  ::  u8(0);
+U16_MIN :: u16(0);
+U32_MIN :: u32(0);
+U64_MIN :: u64(0);
+
+U8_MAX  ::  ~u8(0);
+U16_MAX :: ~u16(0);
+U32_MAX :: ~u32(0);
+U64_MAX :: ~u64(0);
+
+I8_MIN  ::  i8( ~u8(0) >> 1);
+I16_MIN :: i16(~u16(0) >> 1);
+I32_MIN :: i32(~u32(0) >> 1);
+I64_MIN :: i64(~u64(0) >> 1);
+
+I8_MAX  ::  -I8_MIN - 1;
+I16_MAX :: -I16_MIN - 1;
+I32_MAX :: -I32_MIN - 1;
+I64_MAX :: -I64_MIN - 1;
 
 foreign {
-	@(link_name="llvm.ctpop.i8")        __llvm_ctpop8   :: proc(u8)   ->   u8 ---;
-	@(link_name="llvm.ctpop.i16")       __llvm_ctpop16  :: proc(u16)  ->  u16 ---;
-	@(link_name="llvm.ctpop.i32")       __llvm_ctpop32  :: proc(u32)  ->  u32 ---;
-	@(link_name="llvm.ctpop.i64")       __llvm_ctpop64  :: proc(u64)  ->  u64 ---;
-
-	@(link_name="llvm.ctlz.i8")         __llvm_ctlz8   :: proc(u8,   bool) ->   u8 ---;
-	@(link_name="llvm.ctlz.i16")        __llvm_ctlz16  :: proc(u16,  bool) ->  u16 ---;
-	@(link_name="llvm.ctlz.i32")        __llvm_ctlz32  :: proc(u32,  bool) ->  u32 ---;
-	@(link_name="llvm.ctlz.i64")        __llvm_ctlz64  :: proc(u64,  bool) ->  u64 ---;
-
-	@(link_name="llvm.cttz.i8")         __llvm_cttz8   :: proc(u8,   bool) ->   u8 ---;
-	@(link_name="llvm.cttz.i16")        __llvm_cttz16  :: proc(u16,  bool) ->  u16 ---;
-	@(link_name="llvm.cttz.i32")        __llvm_cttz32  :: proc(u32,  bool) ->  u32 ---;
-	@(link_name="llvm.cttz.i64")        __llvm_cttz64  :: proc(u64,  bool) ->  u64 ---;
-
-	@(link_name="llvm.bitreverse.i8")   __llvm_bitreverse8   :: proc(u8)   ->   u8 ---;
-	@(link_name="llvm.bitreverse.i16")  __llvm_bitreverse16  :: proc(u16)  ->  u16 ---;
-	@(link_name="llvm.bitreverse.i32")  __llvm_bitreverse32  :: proc(u32)  ->  u32 ---;
-	@(link_name="llvm.bitreverse.i64")  __llvm_bitreverse64  :: proc(u64)  ->  u64 ---;
-
-	@(link_name="llvm.bswap.i16")  byte_swap16  :: proc(u16)  ->  u16 ---;
-	@(link_name="llvm.bswap.i32")  byte_swap32  :: proc(u32)  ->  u32 ---;
-	@(link_name="llvm.bswap.i64")  byte_swap64  :: proc(u64)  ->  u64 ---;
+	@(link_name="llvm.ctpop.i8")        count_ones8  :: proc(i:  u8) ->  u8 ---
+	@(link_name="llvm.ctpop.i16")       count_ones16 :: proc(i: u16) -> u16 ---
+	@(link_name="llvm.ctpop.i32")       count_ones32 :: proc(i: u32) -> u32 ---
+	@(link_name="llvm.ctpop.i64")       count_ones64 :: proc(i: u64) -> u64 ---
+
+	@(link_name="llvm.ctlz.i8")         leading_zeros8  :: proc(i:  u8, is_zero_undef := false) ->  u8 ---
+	@(link_name="llvm.ctlz.i16")        leading_zeros16 :: proc(i: u16, is_zero_undef := false) -> u16 ---
+	@(link_name="llvm.ctlz.i32")        leading_zeros32 :: proc(i: u32, is_zero_undef := false) -> u32 ---
+	@(link_name="llvm.ctlz.i64")        leading_zeros64 :: proc(i: u64, is_zero_undef := false) -> u64 ---
+
+	@(link_name="llvm.cttz.i8")         trailing_zeros8  :: proc(i:  u8,  is_zero_undef := false) ->  u8 ---
+	@(link_name="llvm.cttz.i16")        trailing_zeros16 :: proc(i: u16,  is_zero_undef := false) -> u16 ---
+	@(link_name="llvm.cttz.i32")        trailing_zeros32 :: proc(i: u32,  is_zero_undef := false) -> u32 ---
+	@(link_name="llvm.cttz.i64")        trailing_zeros64 :: proc(i: u64,  is_zero_undef := false) -> u64 ---
+
+	@(link_name="llvm.bitreverse.i8")   reverse_bits8  :: proc(i:  u8) ->  u8 ---
+	@(link_name="llvm.bitreverse.i16")  reverse_bits16 :: proc(i: u16) -> u16 ---
+	@(link_name="llvm.bitreverse.i32")  reverse_bits32 :: proc(i: u32) -> u32 ---
+	@(link_name="llvm.bitreverse.i64")  reverse_bits64 :: proc(i: u64) -> u64 ---
+
+	@(link_name="llvm.bswap.i16")       byte_swap16 :: proc(u16) -> u16 ---
+	@(link_name="llvm.bswap.i32")       byte_swap32 :: proc(u32) -> u32 ---
+	@(link_name="llvm.bswap.i64")       byte_swap64 :: proc(u64) -> u64 ---
 }
 
 byte_swap_uint :: proc(i: uint) -> uint {
@@ -58,10 +58,6 @@ byte_swap_uint :: proc(i: uint) -> uint {
 
 byte_swap :: proc[byte_swap16, byte_swap32, byte_swap64, byte_swap_uint];
 
-count_ones8   :: proc(i:   u8) ->   u8 { return __llvm_ctpop8(i); }
-count_ones16  :: proc(i:  u16) ->  u16 { return __llvm_ctpop16(i); }
-count_ones32  :: proc(i:  u32) ->  u32 { return __llvm_ctpop32(i); }
-count_ones64  :: proc(i:  u64) ->  u64 { return __llvm_ctpop64(i); }
 
 count_zeros8   :: proc(i:   u8) ->   u8 { return   8 - count_ones8(i); }
 count_zeros16  :: proc(i:  u16) ->  u16 { return  16 - count_ones16(i); }
@@ -80,22 +76,6 @@ rotate_right16  :: proc(i: u16,  s: uint) ->  u16 { return (i >> s)|(i << (8*siz
 rotate_right32  :: proc(i: u32,  s: uint) ->  u32 { return (i >> s)|(i << (8*size_of(u32)  - s)); }
 rotate_right64  :: proc(i: u64,  s: uint) ->  u64 { return (i >> s)|(i << (8*size_of(u64)  - s)); }
 
-leading_zeros8   :: proc(i:   u8) ->   u8 { return __llvm_ctlz8(i, false); }
-leading_zeros16  :: proc(i:  u16) ->  u16 { return __llvm_ctlz16(i, false); }
-leading_zeros32  :: proc(i:  u32) ->  u32 { return __llvm_ctlz32(i, false); }
-leading_zeros64  :: proc(i:  u64) ->  u64 { return __llvm_ctlz64(i, false); }
-
-trailing_zeros8   :: proc(i:   u8) ->   u8 { return __llvm_cttz8(i, false); }
-trailing_zeros16  :: proc(i:  u16) ->  u16 { return __llvm_cttz16(i, false); }
-trailing_zeros32  :: proc(i:  u32) ->  u32 { return __llvm_cttz32(i, false); }
-trailing_zeros64  :: proc(i:  u64) ->  u64 { return __llvm_cttz64(i, false); }
-
-
-reverse_bits8   :: proc(i:   u8) ->   u8 { return __llvm_bitreverse8(i); }
-reverse_bits16  :: proc(i:  u16) ->  u16 { return __llvm_bitreverse16(i); }
-reverse_bits32  :: proc(i:  u32) ->  u32 { return __llvm_bitreverse32(i); }
-reverse_bits64  :: proc(i:  u64) ->  u64 { return __llvm_bitreverse64(i); }
-
 from_be_u8   :: proc(i:   u8) ->   u8 { return i; }
 from_be_u16  :: proc(i:  u16) ->  u16 { when os.ENDIAN == "big" { return i; } else { return byte_swap(i); } }
 from_be_u32  :: proc(i:  u32) ->  u32 { when os.ENDIAN == "big" { return i; } else { return byte_swap(i); } }
@@ -122,14 +102,17 @@ to_le_u64  :: proc(i:  u64) ->  u64 { when os.ENDIAN == "little" { return i; } e
 to_le_uint :: proc(i: uint) -> uint { when os.ENDIAN == "little" { return i; } else { return byte_swap(i); } }
 
 
-overflowing_add_u8   :: proc(lhs, rhs:   u8) -> (u8, bool)   { foreign { @(link_name="llvm.uadd.with.overflow.i8")   op :: proc(u8, u8)     -> (u8, bool)   --- }; return op(lhs, rhs); }
-overflowing_add_i8   :: proc(lhs, rhs:   i8) -> (i8, bool)   { foreign { @(link_name="llvm.sadd.with.overflow.i8")   op :: proc(i8, i8)     -> (i8, bool)   --- }; return op(lhs, rhs); }
-overflowing_add_u16  :: proc(lhs, rhs:  u16) -> (u16, bool)  { foreign { @(link_name="llvm.uadd.with.overflow.i16")  op :: proc(u16, u16)   -> (u16, bool)  --- }; return op(lhs, rhs); }
-overflowing_add_i16  :: proc(lhs, rhs:  i16) -> (i16, bool)  { foreign { @(link_name="llvm.sadd.with.overflow.i16")  op :: proc(i16, i16)   -> (i16, bool)  --- }; return op(lhs, rhs); }
-overflowing_add_u32  :: proc(lhs, rhs:  u32) -> (u32, bool)  { foreign { @(link_name="llvm.uadd.with.overflow.i32")  op :: proc(u32, u32)   -> (u32, bool)  --- }; return op(lhs, rhs); }
-overflowing_add_i32  :: proc(lhs, rhs:  i32) -> (i32, bool)  { foreign { @(link_name="llvm.sadd.with.overflow.i32")  op :: proc(i32, i32)   -> (i32, bool)  --- }; return op(lhs, rhs); }
-overflowing_add_u64  :: proc(lhs, rhs:  u64) -> (u64, bool)  { foreign { @(link_name="llvm.uadd.with.overflow.i64")  op :: proc(u64, u64)   -> (u64, bool)  --- }; return op(lhs, rhs); }
-overflowing_add_i64  :: proc(lhs, rhs:  i64) -> (i64, bool)  { foreign { @(link_name="llvm.sadd.with.overflow.i64")  op :: proc(i64, i64)   -> (i64, bool)  --- }; return op(lhs, rhs); }
+foreign {
+	@(link_name="llvm.uadd.with.overflow.i8")  overflowing_add_u8  :: proc(lhs, rhs:  u8) -> (u8, bool)  ---
+	@(link_name="llvm.sadd.with.overflow.i8")  overflowing_add_i8  :: proc(lhs, rhs:  i8) -> (i8, bool)  ---
+	@(link_name="llvm.uadd.with.overflow.i16") overflowing_add_u16 :: proc(lhs, rhs: u16) -> (u16, bool) ---
+	@(link_name="llvm.sadd.with.overflow.i16") overflowing_add_i16 :: proc(lhs, rhs: i16) -> (i16, bool) ---
+	@(link_name="llvm.uadd.with.overflow.i32") overflowing_add_u32 :: proc(lhs, rhs: u32) -> (u32, bool) ---
+	@(link_name="llvm.sadd.with.overflow.i32") overflowing_add_i32 :: proc(lhs, rhs: i32) -> (i32, bool) ---
+	@(link_name="llvm.uadd.with.overflow.i64") overflowing_add_u64 :: proc(lhs, rhs: u64) -> (u64, bool) ---
+	@(link_name="llvm.sadd.with.overflow.i64") overflowing_add_i64 :: proc(lhs, rhs: i64) -> (i64, bool) ---
+}
+
 overflowing_add_uint :: proc(lhs, rhs: uint) -> (uint, bool) {
 	when size_of(uint) == size_of(u32) {
 		x, ok := overflowing_add_u32(u32(lhs), u32(rhs));
@@ -157,14 +140,16 @@ overflowing_add :: proc[
 	overflowing_add_uint, overflowing_add_int,
 ];
 
-overflowing_sub_u8   :: proc(lhs, rhs:   u8) -> (u8, bool)   { foreign { @(link_name="llvm.usub.with.overflow.i8")   op :: proc(u8, u8)     -> (u8, bool)   --- }; return op(lhs, rhs); }
-overflowing_sub_i8   :: proc(lhs, rhs:   i8) -> (i8, bool)   { foreign { @(link_name="llvm.ssub.with.overflow.i8")   op :: proc(i8, i8)     -> (i8, bool)   --- }; return op(lhs, rhs); }
-overflowing_sub_u16  :: proc(lhs, rhs:  u16) -> (u16, bool)  { foreign { @(link_name="llvm.usub.with.overflow.i16")  op :: proc(u16, u16)   -> (u16, bool)  --- }; return op(lhs, rhs); }
-overflowing_sub_i16  :: proc(lhs, rhs:  i16) -> (i16, bool)  { foreign { @(link_name="llvm.ssub.with.overflow.i16")  op :: proc(i16, i16)   -> (i16, bool)  --- }; return op(lhs, rhs); }
-overflowing_sub_u32  :: proc(lhs, rhs:  u32) -> (u32, bool)  { foreign { @(link_name="llvm.usub.with.overflow.i32")  op :: proc(u32, u32)   -> (u32, bool)  --- }; return op(lhs, rhs); }
-overflowing_sub_i32  :: proc(lhs, rhs:  i32) -> (i32, bool)  { foreign { @(link_name="llvm.ssub.with.overflow.i32")  op :: proc(i32, i32)   -> (i32, bool)  --- }; return op(lhs, rhs); }
-overflowing_sub_u64  :: proc(lhs, rhs:  u64) -> (u64, bool)  { foreign { @(link_name="llvm.usub.with.overflow.i64")  op :: proc(u64, u64)   -> (u64, bool)  --- }; return op(lhs, rhs); }
-overflowing_sub_i64  :: proc(lhs, rhs:  i64) -> (i64, bool)  { foreign { @(link_name="llvm.ssub.with.overflow.i64")  op :: proc(i64, i64)   -> (i64, bool)  --- }; return op(lhs, rhs); }
+foreign {
+	@(link_name="llvm.usub.with.overflow.i8")  overflowing_sub_u8  :: proc(lhs, rhs:  u8) -> (u8, bool)  ---
+	@(link_name="llvm.ssub.with.overflow.i8")  overflowing_sub_i8  :: proc(lhs, rhs:  i8) -> (i8, bool)  ---
+	@(link_name="llvm.usub.with.overflow.i16") overflowing_sub_u16 :: proc(lhs, rhs: u16) -> (u16, bool) ---
+	@(link_name="llvm.ssub.with.overflow.i16") overflowing_sub_i16 :: proc(lhs, rhs: i16) -> (i16, bool) ---
+	@(link_name="llvm.usub.with.overflow.i32") overflowing_sub_u32 :: proc(lhs, rhs: u32) -> (u32, bool) ---
+	@(link_name="llvm.ssub.with.overflow.i32") overflowing_sub_i32 :: proc(lhs, rhs: i32) -> (i32, bool) ---
+	@(link_name="llvm.usub.with.overflow.i64") overflowing_sub_u64 :: proc(lhs, rhs: u64) -> (u64, bool) ---
+	@(link_name="llvm.ssub.with.overflow.i64") overflowing_sub_i64 :: proc(lhs, rhs: i64) -> (i64, bool) ---
+}
 overflowing_sub_uint :: proc(lhs, rhs: uint) -> (uint, bool) {
 	when size_of(uint) == size_of(u32) {
 		x, ok := overflowing_sub_u32(u32(lhs), u32(rhs));
@@ -193,14 +178,16 @@ overflowing_sub :: proc[
 ];
 
 
-overflowing_mul_u8   :: proc(lhs, rhs:   u8) -> (u8, bool)   { foreign { @(link_name="llvm.umul.with.overflow.i8")   op :: proc(u8, u8)     -> (u8, bool)   --- }; return op(lhs, rhs); }
-overflowing_mul_i8   :: proc(lhs, rhs:   i8) -> (i8, bool)   { foreign { @(link_name="llvm.smul.with.overflow.i8")   op :: proc(i8, i8)     -> (i8, bool)   --- }; return op(lhs, rhs); }
-overflowing_mul_u16  :: proc(lhs, rhs:  u16) -> (u16, bool)  { foreign { @(link_name="llvm.umul.with.overflow.i16")  op :: proc(u16, u16)   -> (u16, bool)  --- }; return op(lhs, rhs); }
-overflowing_mul_i16  :: proc(lhs, rhs:  i16) -> (i16, bool)  { foreign { @(link_name="llvm.smul.with.overflow.i16")  op :: proc(i16, i16)   -> (i16, bool)  --- }; return op(lhs, rhs); }
-overflowing_mul_u32  :: proc(lhs, rhs:  u32) -> (u32, bool)  { foreign { @(link_name="llvm.umul.with.overflow.i32")  op :: proc(u32, u32)   -> (u32, bool)  --- }; return op(lhs, rhs); }
-overflowing_mul_i32  :: proc(lhs, rhs:  i32) -> (i32, bool)  { foreign { @(link_name="llvm.smul.with.overflow.i32")  op :: proc(i32, i32)   -> (i32, bool)  --- }; return op(lhs, rhs); }
-overflowing_mul_u64  :: proc(lhs, rhs:  u64) -> (u64, bool)  { foreign { @(link_name="llvm.umul.with.overflow.i64")  op :: proc(u64, u64)   -> (u64, bool)  --- }; return op(lhs, rhs); }
-overflowing_mul_i64  :: proc(lhs, rhs:  i64) -> (i64, bool)  { foreign { @(link_name="llvm.smul.with.overflow.i64")  op :: proc(i64, i64)   -> (i64, bool)  --- }; return op(lhs, rhs); }
+foreign {
+	@(link_name="llvm.umul.with.overflow.i8")  overflowing_mul_u8  :: proc(lhs, rhs:  u8) -> (u8, bool)  ---
+	@(link_name="llvm.smul.with.overflow.i8")  overflowing_mul_i8  :: proc(lhs, rhs:  i8) -> (i8, bool)  ---
+	@(link_name="llvm.umul.with.overflow.i16") overflowing_mul_u16 :: proc(lhs, rhs: u16) -> (u16, bool) ---
+	@(link_name="llvm.smul.with.overflow.i16") overflowing_mul_i16 :: proc(lhs, rhs: i16) -> (i16, bool) ---
+	@(link_name="llvm.umul.with.overflow.i32") overflowing_mul_u32 :: proc(lhs, rhs: u32) -> (u32, bool) ---
+	@(link_name="llvm.smul.with.overflow.i32") overflowing_mul_i32 :: proc(lhs, rhs: i32) -> (i32, bool) ---
+	@(link_name="llvm.umul.with.overflow.i64") overflowing_mul_u64 :: proc(lhs, rhs: u64) -> (u64, bool) ---
+	@(link_name="llvm.smul.with.overflow.i64") overflowing_mul_i64 :: proc(lhs, rhs: i64) -> (i64, bool) ---
+}
 overflowing_mul_uint :: proc(lhs, rhs: uint) -> (uint, bool) {
 	when size_of(uint) == size_of(u32) {
 		x, ok := overflowing_mul_u32(u32(lhs), u32(rhs));

+ 6 - 6
src/check_expr.cpp

@@ -3380,11 +3380,11 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call,
 	case BuiltinProc_type_info_of: {
 		// proc type_info_of(Type) -> ^Type_Info
 		if (c->scope->is_global) {
-			compiler_error("'type_info_of' Cannot be declared within a #shared_global_scope due to how the internals of the compiler works");
+			compiler_error("'type_info_of' Cannot be declared within the runtime package due to how the internals of the compiler works");
 		}
 
 		// NOTE(bill): The type information may not be setup yet
-		init_preload(c->checker);
+		init_core_type_info(c->checker);
 		AstNode *expr = ce->args[0];
 		Operand o = {};
 		check_expr_or_type(c, &o, expr);
@@ -3415,11 +3415,11 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, AstNode *call,
 	case BuiltinProc_typeid_of: {
 		// proc typeid_of(Type) -> typeid
 		if (c->scope->is_global) {
-			compiler_error("'typeid_of' Cannot be declared within a #shared_global_scope due to how the internals of the compiler works");
+			compiler_error("'typeid_of' Cannot be declared within the runtime package due to how the internals of the compiler works");
 		}
 
 		// NOTE(bill): The type information may not be setup yet
-		init_preload(c->checker);
+		init_core_type_info(c->checker);
 		AstNode *expr = ce->args[0];
 		Operand o = {};
 		check_expr_or_type(c, &o, expr);
@@ -5224,7 +5224,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node,
 				return kind;
 			}
 
-			init_preload(c->checker);
+			init_core_context(c->checker);
 			o->mode = Addressing_Immutable;
 			o->type = t_context;
 			break;
@@ -5304,7 +5304,7 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, AstNode *node,
 				o->value = exact_value_string(c->proc_name);
 			}
 		} else if (bd->name == "caller_location") {
-			init_preload(c->checker);
+			init_core_source_code_location(c->checker);
 			error(node, "#caller_location may only be used as a default argument parameter");
 			o->type = t_source_code_location;
 			o->mode = Addressing_Value;

+ 3 - 3
src/check_type.cpp

@@ -844,7 +844,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool
 		if (type_expr == nullptr) {
 			if (default_value->kind == AstNode_BasicDirective &&
 			    default_value->BasicDirective.name == "caller_location") {
-				init_preload(ctx->checker);
+				init_core_source_code_location(ctx->checker);
 				default_is_location = true;
 				type = t_source_code_location;
 			} else {
@@ -942,7 +942,7 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, AstNode *_params, bool
 					Operand o = {};
 					if (default_value->kind == AstNode_BasicDirective &&
 					    default_value->BasicDirective.name == "caller_location") {
-						init_preload(ctx->checker);
+						init_core_source_code_location(ctx->checker);
 						default_is_location = true;
 						o.type = t_source_code_location;
 						o.mode = Addressing_Value;
@@ -1715,7 +1715,7 @@ void check_map_type(CheckerContext *ctx, Type *type, AstNode *node) {
 	}
 
 
-	init_preload(ctx->checker);
+	init_core_map_type(ctx->checker);
 	init_map_internal_types(type);
 
 	// error(node, "'map' types are not yet implemented");

+ 98 - 112
src/checker.cpp

@@ -814,7 +814,7 @@ isize type_info_index(CheckerInfo *info, Type *type, bool error_on_failure) {
 	}
 
 	if (error_on_failure && entry_index < 0) {
-		compiler_error("TypeInfo for '%s' could not be found", type_to_string(type));
+		compiler_error("Type_Info for '%s' could not be found", type_to_string(type));
 	}
 	return entry_index;
 }
@@ -1555,116 +1555,111 @@ Array<Entity *> proc_group_entities(CheckerContext *c, Operand o) {
 
 
 
-
-void init_preload(Checker *c) {
-	if (t_type_info == nullptr) {
-		Entity *type_info_entity = find_core_entity(c, str_lit("Type_Info"));
-
-		t_type_info = type_info_entity->type;
-		t_type_info_ptr = alloc_type_pointer(t_type_info);
-		GB_ASSERT(is_type_struct(type_info_entity->type));
-		TypeStruct *tis = &base_type(type_info_entity->type)->Struct;
-
-		Entity *type_info_enum_value = find_core_entity(c, str_lit("Type_Info_Enum_Value"));
-
-		t_type_info_enum_value = type_info_enum_value->type;
-		t_type_info_enum_value_ptr = alloc_type_pointer(t_type_info_enum_value);
-
-		GB_ASSERT(tis->fields.count == 4);
-
-		Entity *type_info_variant = tis->fields[3];
-		Type *tiv_type = type_info_variant->type;
-		GB_ASSERT(is_type_union(tiv_type));
-
-		t_type_info_named         = find_core_type(c, str_lit("Type_Info_Named"));
-		t_type_info_integer       = find_core_type(c, str_lit("Type_Info_Integer"));
-		t_type_info_rune          = find_core_type(c, str_lit("Type_Info_Rune"));
-		t_type_info_float         = find_core_type(c, str_lit("Type_Info_Float"));
-		t_type_info_complex       = find_core_type(c, str_lit("Type_Info_Complex"));
-		t_type_info_string        = find_core_type(c, str_lit("Type_Info_String"));
-		t_type_info_boolean       = find_core_type(c, str_lit("Type_Info_Boolean"));
-		t_type_info_any           = find_core_type(c, str_lit("Type_Info_Any"));
-		t_type_info_typeid        = find_core_type(c, str_lit("Type_Info_Type_Id"));
-		t_type_info_pointer       = find_core_type(c, str_lit("Type_Info_Pointer"));
-		t_type_info_procedure     = find_core_type(c, str_lit("Type_Info_Procedure"));
-		t_type_info_array         = find_core_type(c, str_lit("Type_Info_Array"));
-		t_type_info_dynamic_array = find_core_type(c, str_lit("Type_Info_Dynamic_Array"));
-		t_type_info_slice         = find_core_type(c, str_lit("Type_Info_Slice"));
-		t_type_info_tuple         = find_core_type(c, str_lit("Type_Info_Tuple"));
-		t_type_info_struct        = find_core_type(c, str_lit("Type_Info_Struct"));
-		t_type_info_union         = find_core_type(c, str_lit("Type_Info_Union"));
-		t_type_info_enum          = find_core_type(c, str_lit("Type_Info_Enum"));
-		t_type_info_map           = find_core_type(c, str_lit("Type_Info_Map"));
-		t_type_info_bit_field     = find_core_type(c, str_lit("Type_Info_Bit_Field"));
-
-		t_type_info_named_ptr         = alloc_type_pointer(t_type_info_named);
-		t_type_info_integer_ptr       = alloc_type_pointer(t_type_info_integer);
-		t_type_info_rune_ptr          = alloc_type_pointer(t_type_info_rune);
-		t_type_info_float_ptr         = alloc_type_pointer(t_type_info_float);
-		t_type_info_complex_ptr       = alloc_type_pointer(t_type_info_complex);
-		t_type_info_string_ptr        = alloc_type_pointer(t_type_info_string);
-		t_type_info_boolean_ptr       = alloc_type_pointer(t_type_info_boolean);
-		t_type_info_any_ptr           = alloc_type_pointer(t_type_info_any);
-		t_type_info_typeid_ptr        = alloc_type_pointer(t_type_info_typeid);
-		t_type_info_pointer_ptr       = alloc_type_pointer(t_type_info_pointer);
-		t_type_info_procedure_ptr     = alloc_type_pointer(t_type_info_procedure);
-		t_type_info_array_ptr         = alloc_type_pointer(t_type_info_array);
-		t_type_info_dynamic_array_ptr = alloc_type_pointer(t_type_info_dynamic_array);
-		t_type_info_slice_ptr         = alloc_type_pointer(t_type_info_slice);
-		t_type_info_tuple_ptr         = alloc_type_pointer(t_type_info_tuple);
-		t_type_info_struct_ptr        = alloc_type_pointer(t_type_info_struct);
-		t_type_info_union_ptr         = alloc_type_pointer(t_type_info_union);
-		t_type_info_enum_ptr          = alloc_type_pointer(t_type_info_enum);
-		t_type_info_map_ptr           = alloc_type_pointer(t_type_info_map);
-		t_type_info_bit_field_ptr     = alloc_type_pointer(t_type_info_bit_field);
-	}
-
-	if (t_allocator == nullptr) {
-		AstPackage *mem = get_core_package(&c->info, str_lit("mem"));
-		Entity *e = scope_lookup_entity(mem->scope, str_lit("Allocator"));
-		t_allocator = e->type;
-		t_allocator_ptr = alloc_type_pointer(t_allocator);
-	}
-
-	if (t_context == nullptr) {
-		Entity *e = find_core_entity(c, str_lit("Context"));
-		e_context = e;
-		t_context = e->type;
-		t_context_ptr = alloc_type_pointer(t_context);
-	}
-
-	if (t_source_code_location == nullptr) {
-		Entity *e = find_core_entity(c, str_lit("Source_Code_Location"));
-		t_source_code_location = e->type;
-		t_source_code_location_ptr = alloc_type_pointer(t_allocator);
+void init_core_type_info(Checker *c) {
+	if (t_type_info != nullptr) {
+		return;
 	}
-
-	if (t_map_key == nullptr) {
-		Entity *e = find_core_entity(c, str_lit("__Map_Key"));
-		t_map_key = e->type;
+	Entity *type_info_entity = find_core_entity(c, str_lit("Type_Info"));
+
+	t_type_info = type_info_entity->type;
+	t_type_info_ptr = alloc_type_pointer(t_type_info);
+	GB_ASSERT(is_type_struct(type_info_entity->type));
+	TypeStruct *tis = &base_type(type_info_entity->type)->Struct;
+
+	Entity *type_info_enum_value = find_core_entity(c, str_lit("Type_Info_Enum_Value"));
+
+	t_type_info_enum_value = type_info_enum_value->type;
+	t_type_info_enum_value_ptr = alloc_type_pointer(t_type_info_enum_value);
+
+	GB_ASSERT(tis->fields.count == 4);
+
+	Entity *type_info_variant = tis->fields[3];
+	Type *tiv_type = type_info_variant->type;
+	GB_ASSERT(is_type_union(tiv_type));
+
+	t_type_info_named         = find_core_type(c, str_lit("Type_Info_Named"));
+	t_type_info_integer       = find_core_type(c, str_lit("Type_Info_Integer"));
+	t_type_info_rune          = find_core_type(c, str_lit("Type_Info_Rune"));
+	t_type_info_float         = find_core_type(c, str_lit("Type_Info_Float"));
+	t_type_info_complex       = find_core_type(c, str_lit("Type_Info_Complex"));
+	t_type_info_string        = find_core_type(c, str_lit("Type_Info_String"));
+	t_type_info_boolean       = find_core_type(c, str_lit("Type_Info_Boolean"));
+	t_type_info_any           = find_core_type(c, str_lit("Type_Info_Any"));
+	t_type_info_typeid        = find_core_type(c, str_lit("Type_Info_Type_Id"));
+	t_type_info_pointer       = find_core_type(c, str_lit("Type_Info_Pointer"));
+	t_type_info_procedure     = find_core_type(c, str_lit("Type_Info_Procedure"));
+	t_type_info_array         = find_core_type(c, str_lit("Type_Info_Array"));
+	t_type_info_dynamic_array = find_core_type(c, str_lit("Type_Info_Dynamic_Array"));
+	t_type_info_slice         = find_core_type(c, str_lit("Type_Info_Slice"));
+	t_type_info_tuple         = find_core_type(c, str_lit("Type_Info_Tuple"));
+	t_type_info_struct        = find_core_type(c, str_lit("Type_Info_Struct"));
+	t_type_info_union         = find_core_type(c, str_lit("Type_Info_Union"));
+	t_type_info_enum          = find_core_type(c, str_lit("Type_Info_Enum"));
+	t_type_info_map           = find_core_type(c, str_lit("Type_Info_Map"));
+	t_type_info_bit_field     = find_core_type(c, str_lit("Type_Info_Bit_Field"));
+
+	t_type_info_named_ptr         = alloc_type_pointer(t_type_info_named);
+	t_type_info_integer_ptr       = alloc_type_pointer(t_type_info_integer);
+	t_type_info_rune_ptr          = alloc_type_pointer(t_type_info_rune);
+	t_type_info_float_ptr         = alloc_type_pointer(t_type_info_float);
+	t_type_info_complex_ptr       = alloc_type_pointer(t_type_info_complex);
+	t_type_info_string_ptr        = alloc_type_pointer(t_type_info_string);
+	t_type_info_boolean_ptr       = alloc_type_pointer(t_type_info_boolean);
+	t_type_info_any_ptr           = alloc_type_pointer(t_type_info_any);
+	t_type_info_typeid_ptr        = alloc_type_pointer(t_type_info_typeid);
+	t_type_info_pointer_ptr       = alloc_type_pointer(t_type_info_pointer);
+	t_type_info_procedure_ptr     = alloc_type_pointer(t_type_info_procedure);
+	t_type_info_array_ptr         = alloc_type_pointer(t_type_info_array);
+	t_type_info_dynamic_array_ptr = alloc_type_pointer(t_type_info_dynamic_array);
+	t_type_info_slice_ptr         = alloc_type_pointer(t_type_info_slice);
+	t_type_info_tuple_ptr         = alloc_type_pointer(t_type_info_tuple);
+	t_type_info_struct_ptr        = alloc_type_pointer(t_type_info_struct);
+	t_type_info_union_ptr         = alloc_type_pointer(t_type_info_union);
+	t_type_info_enum_ptr          = alloc_type_pointer(t_type_info_enum);
+	t_type_info_map_ptr           = alloc_type_pointer(t_type_info_map);
+	t_type_info_bit_field_ptr     = alloc_type_pointer(t_type_info_bit_field);
+}
+
+void init_core_allocator(Checker *c) {
+	if (t_allocator != nullptr) {
+		return;
 	}
+	t_allocator = find_core_type(c, str_lit("Allocator"));
+	t_allocator_ptr = alloc_type_pointer(t_allocator);
+}
 
-	if (t_map_header == nullptr) {
-		Entity *e = find_core_entity(c, str_lit("__Map_Header"));
-		t_map_header = e->type;
+void init_core_context(Checker *c) {
+	if (t_context != nullptr) {
+		return;
 	}
+	t_context = find_core_type(c, str_lit("Context"));
+	t_context_ptr = alloc_type_pointer(t_context);
+}
 
+void init_core_source_code_location(Checker *c) {
+	if (t_source_code_location != nullptr) {
+		return;
+	}
+	t_source_code_location = find_core_type(c, str_lit("Source_Code_Location"));
+	t_source_code_location_ptr = alloc_type_pointer(t_allocator);
+}
 
-	{
-		String _global = str_lit("_global");
-
-		Entity *type_info_entity = find_core_entity(c, str_lit("Type_Info"));
-		Scope *preload_scope = type_info_entity->scope;
-
-		Entity *e = alloc_entity_import_name(preload_scope, make_token_ident(_global), t_invalid,
-		                                     str_lit(""), _global,
-		                                     preload_scope);
-
-		add_entity(c, universal_scope, nullptr, e);
+void init_core_map_type(Checker *c) {
+	if (t_map_key == nullptr) {
+		t_map_key = find_core_type(c, str_lit("__Map_Key"));
 	}
 
-	c->done_preload = true;
+	if (t_map_header == nullptr) {
+		t_map_header = find_core_type(c, str_lit("__Map_Header"));
+	}
+}
 
+void init_preload(Checker *c) {
+	init_core_type_info(c);
+	init_core_allocator(c);
+	init_core_context(c);
+	init_core_source_code_location(c);
+	init_core_map_type(c);
 }
 
 
@@ -2210,7 +2205,6 @@ void check_collect_entities(CheckerContext *c, Array<AstNode *> const &nodes) {
 
 void check_all_global_entities(Checker *c) {
 	Scope *prev_file = nullptr;
-	bool processing_preload = true;
 
 	for_array(i, c->info.entities) {
 		Entity *e = c->info.entities[i];
@@ -2245,14 +2239,6 @@ void check_all_global_entities(Checker *c) {
 		ctx.decl = d;
 		ctx.scope = d->scope;
 		check_entity_decl(&ctx, e, d, nullptr);
-
-		if (pkg->kind != Package_Runtime) {
-			processing_preload = false;
-		}
-
-		if (!processing_preload) {
-			init_preload(c);
-		}
 	}
 }
 
@@ -3196,7 +3182,7 @@ void check_parsed_files(Checker *c) {
 	check_all_global_entities(c);
 
 	TIME_SECTION("init preload");
-	init_preload(c); // NOTE(bill): This could be setup previously through the use of 'type_info_of'
+	init_preload(c);
 
 	CheckerContext prev_context = c->init_ctx;
 	defer (c->init_ctx = prev_context);

+ 2 - 3
src/checker.hpp

@@ -336,9 +336,8 @@ struct Checker {
 	Array<ProcedureInfo> procs_to_check;
 	PtrSet<AstPackage *> checked_packages;
 
-	gbAllocator          allocator;
-	CheckerContext       init_ctx;
-	bool                 done_preload;
+	gbAllocator    allocator;
+	CheckerContext init_ctx;
 };
 
 

+ 0 - 2
src/entity.cpp

@@ -148,8 +148,6 @@ struct Entity {
 	};
 };
 
-gb_global Entity *e_context = nullptr;
-
 bool is_entity_kind_exported(EntityKind kind) {
 	switch (kind) {
 	case Entity_Builtin: