More culling

This commit is contained in:
gingerBill
2021-09-13 01:07:24 +01:00
parent fb8fa5217d
commit f5bc95eb34
3 changed files with 27 additions and 51 deletions
+2 -11
View File
@@ -188,13 +188,6 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields
} }
Entity *make_names_field_for_struct(CheckerContext *ctx, Scope *scope) {
Entity *e = alloc_entity_field(scope, make_token_ident(str_lit("names")), t_string_slice, false, 0);
e->flags |= EntityFlag_TypeField;
e->flags |= EntityFlag_Value;
return e;
}
bool check_custom_align(CheckerContext *ctx, Ast *node, i64 *align_) { bool check_custom_align(CheckerContext *ctx, Ast *node, i64 *align_) {
GB_ASSERT(align_ != nullptr); GB_ASSERT(align_ != nullptr);
Operand o = {}; Operand o = {};
@@ -565,8 +558,7 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array<
case_end; case_end;
} }
} }
struct_type->Struct.names = make_names_field_for_struct(ctx, ctx->scope);
scope_reserve(ctx->scope, min_field_count); scope_reserve(ctx->scope, min_field_count);
if (st->is_raw_union && min_field_count > 1) { if (st->is_raw_union && min_field_count > 1) {
@@ -658,7 +650,7 @@ void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array<Op
} }
} }
union_type->Union.variants = variants; union_type->Union.variants = slice_from_array(variants);
union_type->Union.no_nil = ut->no_nil; union_type->Union.no_nil = ut->no_nil;
union_type->Union.maybe = ut->maybe; union_type->Union.maybe = ut->maybe;
if (union_type->Union.no_nil) { if (union_type->Union.no_nil) {
@@ -818,7 +810,6 @@ void check_enum_type(CheckerContext *ctx, Type *enum_type, Type *named_type, Ast
enum_type->Enum.fields = fields; enum_type->Enum.fields = fields;
enum_type->Enum.names = make_names_field_for_struct(ctx, ctx->scope);
*enum_type->Enum.min_value = min_value; *enum_type->Enum.min_value = min_value;
*enum_type->Enum.max_value = max_value; *enum_type->Enum.max_value = max_value;
+5
View File
@@ -2221,6 +2221,11 @@ int strip_semicolons(Parser *parser) {
int main(int arg_count, char const **arg_ptr) { int main(int arg_count, char const **arg_ptr) {
#define TIME_SECTION(str) do { debugf("[Section] %s\n", str); timings_start_section(&global_timings, str_lit(str)); } while (0) #define TIME_SECTION(str) do { debugf("[Section] %s\n", str); timings_start_section(&global_timings, str_lit(str)); } while (0)
#define TYPE_KIND(k, ...) gb_printf("%s %td\n", #k, sizeof(Type##k));
TYPE_KINDS
#undef TYPE_KIND
gb_printf("Type %td\n", sizeof(Type));
if (arg_count < 2) { if (arg_count < 2) {
usage(make_string_c(arg_ptr[0])); usage(make_string_c(arg_ptr[0]));
return 1; return 1;
+20 -40
View File
@@ -121,7 +121,7 @@ struct BasicType {
String name; String name;
}; };
enum StructSoaKind { enum StructSoaKind : u8 {
StructSoa_None = 0, StructSoa_None = 0,
StructSoa_Fixed = 1, StructSoa_Fixed = 1,
StructSoa_Slice = 2, StructSoa_Slice = 2,
@@ -135,38 +135,37 @@ struct TypeStruct {
Ast * node; Ast * node;
Scope * scope; Scope * scope;
Type * polymorphic_params; // Type_Tuple i64 custom_align;
Type * polymorphic_parent; Type * polymorphic_params; // Type_Tuple
Type * polymorphic_parent;
i64 custom_align;
Entity * names;
Type * soa_elem; Type * soa_elem;
i64 soa_count; i64 soa_count;
StructSoaKind soa_kind; StructSoaKind soa_kind;
bool is_polymorphic; bool is_polymorphic;
bool are_offsets_set : 1; bool are_offsets_set : 1;
bool are_offsets_being_processed : 1; bool are_offsets_being_processed : 1;
bool is_packed : 1; bool is_packed : 1;
bool is_raw_union : 1; bool is_raw_union : 1;
bool is_poly_specialized : 1; bool is_poly_specialized : 1;
}; };
struct TypeUnion { struct TypeUnion {
Array<Type *> variants; Slice<Type *> variants;
Ast * node; Ast * node;
Scope * scope; Scope * scope;
i64 variant_block_size; i64 variant_block_size;
i64 custom_align; i64 custom_align;
i64 tag_size;
Type * polymorphic_params; // Type_Tuple Type * polymorphic_params; // Type_Tuple
Type * polymorphic_parent; Type * polymorphic_parent;
bool no_nil; i16 tag_size;
bool maybe;
bool is_polymorphic; bool is_polymorphic;
bool is_poly_specialized; bool is_poly_specialized : 1;
bool no_nil : 1;
bool maybe : 1;
}; };
struct TypeProc { struct TypeProc {
@@ -237,7 +236,6 @@ struct TypeProc {
Array<Entity *> fields; \ Array<Entity *> fields; \
Ast *node; \ Ast *node; \
Scope * scope; \ Scope * scope; \
Entity * names; \
Type * base_type; \ Type * base_type; \
ExactValue *min_value; \ ExactValue *min_value; \
ExactValue *max_value; \ ExactValue *max_value; \
@@ -2311,7 +2309,7 @@ i64 union_tag_size(Type *u) {
} }
} }
u->Union.tag_size = gb_min3(max_align, build_context.max_align, 8); u->Union.tag_size = cast(i16)gb_min3(max_align, build_context.max_align, 8);
return u->Union.tag_size; return u->Union.tag_size;
} }
@@ -2478,24 +2476,6 @@ Selection lookup_field_with_selection(Type *type_, String field_name, bool is_ty
type = base_type(type); type = base_type(type);
if (is_type) { if (is_type) {
switch (type->kind) {
case Type_Struct:
if (type->Struct.names != nullptr &&
field_name == "names") {
sel.entity = type->Struct.names;
return sel;
}
break;
case Type_Enum:
if (type->Enum.names != nullptr &&
field_name == "names") {
sel.entity = type->Enum.names;
return sel;
}
break;
}
if (is_type_enum(type)) { if (is_type_enum(type)) {
// NOTE(bill): These may not have been added yet, so check in case // NOTE(bill): These may not have been added yet, so check in case
for_array(i, type->Enum.fields) { for_array(i, type->Enum.fields) {
@@ -3269,7 +3249,7 @@ i64 type_size_of_internal(Type *t, TypePath *path) {
i64 tag_size = union_tag_size(t); i64 tag_size = union_tag_size(t);
size = align_formula(max, tag_size); size = align_formula(max, tag_size);
// NOTE(bill): Calculate the padding between the common fields and the tag // NOTE(bill): Calculate the padding between the common fields and the tag
t->Union.tag_size = tag_size; t->Union.tag_size = cast(i16)tag_size;
t->Union.variant_block_size = size - field_size; t->Union.variant_block_size = size - field_size;
size += tag_size; size += tag_size;