Remove unused code

This commit is contained in:
gingerBill
2021-08-19 15:03:10 +01:00
parent 33239324b8
commit 7845769d4b
21 changed files with 38 additions and 135 deletions
+2
View File
@@ -270,6 +270,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
BlockingMutex *ignore_mutex = nullptr;
String path = {};
bool ok = determine_path_from_string(ignore_mutex, call, base_dir, original_string, &path);
gb_unused(ok);
char *c_str = alloc_cstring(a, path);
defer (gb_free(a, c_str));
@@ -369,6 +370,7 @@ bool check_builtin_procedure(CheckerContext *c, Operand *operand, Ast *call, i32
}
bool is_defined = check_identifier_exists(c->scope, arg);
gb_unused(is_defined);
operand->type = t_untyped_bool;
operand->mode = Addressing_Constant;
operand->value = exact_value_bool(false);
+1 -2
View File
@@ -384,7 +384,6 @@ void check_const_decl(CheckerContext *ctx, Entity *e, Ast *type_expr, Ast *init,
Operand operand = {};
Entity *other_entity = nullptr;
if (init != nullptr) {
Entity *entity = nullptr;
if (init->kind == Ast_Ident) {
@@ -1287,9 +1286,9 @@ void check_proc_body(CheckerContext *ctx_, Token token, DeclInfo *decl, Type *ty
check_open_scope(ctx, body);
{
for_array(i, using_entities) {
Entity *e = using_entities[i].e;
Entity *uvar = using_entities[i].uvar;
Entity *prev = scope_insert(ctx->scope, uvar);
gb_unused(prev);
// NOTE(bill): Don't err here
}
+2 -18
View File
@@ -913,7 +913,6 @@ bool is_polymorphic_type_assignable(CheckerContext *c, Type *poly, Type *source,
Entity *e = scope_lookup(gt->Generic.scope, gt->Generic.name);
GB_ASSERT(e != nullptr);
if (e->kind == Entity_TypeName) {
Type *elem = poly->Array.elem;
Type *index = source->EnumeratedArray.index;
Type *it = base_type(index);
if (it->kind != Type_Enum) {
@@ -2399,7 +2398,6 @@ bool check_is_castable_to(CheckerContext *c, Operand *operand, Type *y) {
bool check_cast_internal(CheckerContext *c, Operand *x, Type *type) {
bool is_const_expr = x->mode == Addressing_Constant;
bool can_convert = false;
Type *bt = base_type(type);
if (is_const_expr && is_type_constant_type(bt)) {
@@ -3181,10 +3179,8 @@ void convert_to_typed(CheckerContext *c, Operand *operand, Type *target_type) {
if (valid_count > 1) {
gb_sort_array(valids, valid_count, valid_index_and_score_cmp);
i64 best_score = valids[0].score;
Type *best_type = t->Union.variants[valids[0].index];
for (isize i = 1; i < valid_count; i++) {
auto v = valids[i];
Type *vt = t->Union.variants[v.index];
if (best_score > v.score) {
valid_count = i;
break;
@@ -3557,7 +3553,6 @@ ExactValue get_constant_field(CheckerContext *c, Operand const *operand, Selecti
ExactValue value = operand->value;
if (value.kind == ExactValue_Compound) {
i32 depth = 0;
while (sel.index.count > 0) {
i32 index = sel.index[0];
sel = sub_selection(sel, 1);
@@ -3712,7 +3707,6 @@ Entity *check_selector(CheckerContext *c, Operand *operand, Ast *node, Type *typ
add_entity_use(c, op_expr, e);
expr_entity = e;
Entity *original_e = e;
if (e != nullptr && e->kind == Entity_ImportName && selector->kind == Ast_Ident) {
// IMPORTANT NOTE(bill): This is very sloppy code but it's also very fragile
// It pretty much needs to be in this order and this way
@@ -4163,7 +4157,6 @@ bool check_assignment_arguments(CheckerContext *ctx, Array<Operand> const &lhs,
if (o.type == nullptr || o.type->kind != Type_Tuple) {
if (lhs.count == 2 && rhs.count == 1 &&
(o.mode == Addressing_MapIndex || o.mode == Addressing_OptionalOk || o.mode == Addressing_OptionalOkPtr)) {
bool do_normal = true;
Ast *expr = unparen_expr(o.expr);
Operand val0 = o;
@@ -4269,7 +4262,6 @@ bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count,
if (o.type == nullptr || o.type->kind != Type_Tuple) {
if (allow_ok && lhs_count == 2 && rhs.count == 1 &&
(o.mode == Addressing_MapIndex || o.mode == Addressing_OptionalOk || o.mode == Addressing_OptionalOkPtr)) {
bool do_normal = true;
Ast *expr = unparen_expr(o.expr);
Operand val0 = o;
@@ -5348,6 +5340,7 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type
proc_type = e->type;
CallArgumentData data = {};
CallArgumentError err = call_checker(c, call, proc_type, e, operands, CallArgumentMode_ShowErrors, &data);
gb_unused(err);
Entity *entity_to_use = data.gen_entity != nullptr ? data.gen_entity : e;
add_entity_use(c, ident, entity_to_use);
if (entity_to_use != nullptr) {
@@ -5381,6 +5374,7 @@ CallArgumentData check_call_arguments(CheckerContext *c, Operand *operand, Type
CallArgumentData data = {};
CallArgumentError err = call_checker(c, call, proc_type, e, operands, CallArgumentMode_ShowErrors, &data);
gb_unused(err);
Entity *entity_to_use = data.gen_entity != nullptr ? data.gen_entity : e;
add_entity_use(c, ident, entity_to_use);
if (entity_to_use != nullptr) {
@@ -6270,12 +6264,8 @@ bool attempt_implicit_selector_expr(CheckerContext *c, Operand *o, AstImplicitSe
o->type = e->type;
return true;
}
bool show_error = true;
if (is_type_union(th)) {
Type *union_type = base_type(th);
isize enum_count = 0;
Type *et = nullptr;
auto operands = array_make<Operand>(temporary_allocator(), 0, union_type->Union.variants.count);
for_array(i, union_type->Union.variants) {
@@ -6311,7 +6301,6 @@ ExprKind check_implicit_selector_expr(CheckerContext *c, Operand *o, Ast *node,
return Expr_Expr;
}
o->type = th;
Type *enum_type = th;
bool ok = attempt_implicit_selector_expr(c, o, ise, th);
if (!ok) {
@@ -7533,7 +7522,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
is_constant = false;
} else {
for_array(index, cl->elems) {
Entity *field = nullptr;
Ast *elem = cl->elems[index];
if (elem->kind == Ast_FieldValue) {
error(elem, "'field = value' in a bit_set a literal is not allowed");
@@ -7585,7 +7573,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
u64 bits = 0;
for_array(index, cl->elems) {
Entity *field = nullptr;
Ast *elem = cl->elems[index];
GB_ASSERT(elem->kind != Ast_FieldValue);
TypeAndValue tav = elem->tav;
@@ -7677,7 +7664,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
return kind;
}
bool src_is_ptr = is_type_pointer(o->type);
Type *src = type_deref(o->type);
Type *bsrc = base_type(src);
@@ -7725,8 +7711,6 @@ ExprKind check_expr_base_internal(CheckerContext *c, Operand *o, Ast *node, Type
} else {
Type *t = check_type(c, ta->type);
Type *dst = t;
Type *bdst = base_type(dst);
if (is_type_union(src)) {
bool ok = false;
+11 -11
View File
@@ -59,9 +59,6 @@ void populate_using_entity_scope(CheckerContext *ctx, Ast *node, AstField *field
}
}
} else if (t->kind == Type_Array && t->Array.count <= 4) {
Entity *e = nullptr;
String name = {};
i32 idx = 0;
switch (t->Array.count) {
case 4:
populate_using_array_index(ctx, node, field, t, str_lit("w"), 3);
@@ -121,8 +118,6 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Array<Entity *> *fields
ast_node(p, Field, param);
Ast *type_expr = p->type;
Type *type = nullptr;
bool detemine_type_from_operand = false;
if (type_expr != nullptr) {
type = check_type_expr(ctx, type_expr, nullptr);
@@ -591,6 +586,7 @@ void check_struct_type(CheckerContext *ctx, Type *struct_type, Ast *node, Array<
error(st->where_clauses[0], "'where' clauses can only be used on structures with polymorphic parameters");
} else {
bool where_clause_ok = evaluate_where_clauses(ctx, node, ctx->scope, &st->where_clauses, true);
gb_unused(where_clause_ok);
}
check_struct_fields(ctx, node, &struct_type->Struct.fields, &struct_type->Struct.tags, st->fields, min_field_count, struct_type, context);
}
@@ -625,6 +621,7 @@ void check_union_type(CheckerContext *ctx, Type *union_type, Ast *node, Array<Op
error(ut->where_clauses[0], "'where' clauses can only be used on unions with polymorphic parameters");
} else {
bool where_clause_ok = evaluate_where_clauses(ctx, node, ctx->scope, &ut->where_clauses, true);
gb_unused(where_clause_ok);
}
}
@@ -1093,6 +1090,10 @@ bool check_type_specialization_to(CheckerContext *ctx, Type *specialization, Typ
return false;
} else {
bool ok = is_polymorphic_type_assignable(ctx, st, tt, true, modify_type);
if (!ok) {
// TODO(bill, 2021-08-19): is this logic correct?
return false;
}
}
}
}
@@ -1133,6 +1134,10 @@ bool check_type_specialization_to(CheckerContext *ctx, Type *specialization, Typ
}
} else {
bool ok = is_polymorphic_type_assignable(ctx, st, tt, true, modify_type);
if (!ok) {
// TODO(bill, 2021-08-19): is this logic correct?
return false;
}
}
}
@@ -1297,8 +1302,6 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
return nullptr;
}
bool allow_polymorphic_types = ctx->allow_polymorphic_types;
bool success = true;
ast_node(field_list, FieldList, _params);
Slice<Ast *> params = field_list->list;
@@ -1308,8 +1311,6 @@ Type *check_get_params(CheckerContext *ctx, Scope *scope, Ast *_params, bool *is
return nullptr;
}
isize variable_count = 0;
for_array(i, params) {
Ast *field = params[i];
@@ -2080,7 +2081,6 @@ void init_map_entry_type(Type *type) {
value: Value,
}
*/
Ast *dummy_node = alloc_ast_node(nullptr, Ast_Invalid);
Scope *s = create_scope(nullptr, builtin_pkg->scope);
auto fields = array_make<Entity *>(permanent_allocator(), 0, 4);
@@ -2114,7 +2114,6 @@ void init_map_internal_types(Type *type) {
entries: [dynamic]EntryType;
}
*/
Ast *dummy_node = alloc_ast_node(nullptr, Ast_Invalid);
Scope *s = create_scope(nullptr, builtin_pkg->scope);
Type *hashes_type = alloc_type_slice(t_int);
@@ -2386,6 +2385,7 @@ bool check_type_internal(CheckerContext *ctx, Ast *e, Type **type, Type *named_t
case_ast_node(i, Ident, e);
Operand o = {};
Entity *entity = check_ident(ctx, &o, e, named_type, nullptr, false);
gb_unused(entity);
gbString err_str = nullptr;
defer (gb_string_free(err_str));
+1 -13
View File
@@ -2112,9 +2112,6 @@ void add_entity_dependency_from_procedure_parameters(Map<EntityGraphNode *> *M,
if (tuple == nullptr) {
return;
}
Entity *e = n->entity;
bool print_deps = false;
GB_ASSERT(tuple->kind == Type_Tuple);
TypeTuple *t = &tuple->Tuple;
for_array(i, t->variables) {
@@ -2138,7 +2135,6 @@ Array<EntityGraphNode *> generate_entity_dependency_graph(CheckerInfo *info, gbA
defer (map_destroy(&M));
for_array(i, info->entities) {
Entity *e = info->entities[i];
DeclInfo *d = e->decl_info;
if (is_entity_a_dependency(e)) {
EntityGraphNode *n = gb_alloc_item(allocator, EntityGraphNode);
n->entity = e;
@@ -4345,8 +4341,6 @@ void check_import_entities(Checker *c) {
reset_checker_context(&ctx, f, &untyped);
ctx.collect_delayed_decls = true;
MPMCQueue<Ast *> *q = nullptr;
// Check import declarations first to simplify things
for (Ast *id = nullptr; mpmc_dequeue(&f->delayed_decls_queues[AstDelayQueue_Import], &id); /**/) {
check_add_import_decl(&ctx, id);
@@ -4730,7 +4724,6 @@ GB_THREAD_PROC(thread_proc_body) {
ThreadProcBodyData *data = cast(ThreadProcBodyData *)thread->user_data;
Checker *c = data->checker;
GB_ASSERT(c != nullptr);
ThreadProcBodyData *all_data = data->all_data;
ProcBodyQueue *this_queue = data->queue;
UntypedExprInfoMap untyped = {};
@@ -4897,9 +4890,6 @@ void check_deferred_procedures(Checker *c) {
GB_ASSERT(src_params->kind == Type_Tuple);
GB_ASSERT(dst_params->kind == Type_Tuple);
auto const &sv = src_params->Tuple.variables;
auto const &dv = dst_params->Tuple.variables;
if (are_types_identical(src_params, dst_params)) {
// Okay!
} else {
@@ -4928,9 +4918,6 @@ void check_deferred_procedures(Checker *c) {
GB_ASSERT(src_results->kind == Type_Tuple);
GB_ASSERT(dst_params->kind == Type_Tuple);
auto const &sv = src_results->Tuple.variables;
auto const &dv = dst_params->Tuple.variables;
if (are_types_identical(src_results, dst_params)) {
// Okay!
} else {
@@ -4955,6 +4942,7 @@ void check_deferred_procedures(Checker *c) {
Type *tsrc = alloc_type_tuple();
auto &sv = tsrc->Tuple.variables;
auto const &dv = dst_params->Tuple.variables;
gb_unused(dv);
isize len = 0;
if (src_params != nullptr) {
-1
View File
@@ -107,7 +107,6 @@ bool print_doc_comment_group_string(i32 indent, CommentGroup *g) {
String original_comment = comment;
bool slash_slash = comment[1] == '/';
bool slash_star = comment[1] == '*';
if (comment[1] == '/') {
comment.text += 2;
comment.len -= 2;
+1 -2
View File
@@ -301,7 +301,6 @@ bool odin_doc_append_comment_group_string(Array<u8> *buf, CommentGroup *g) {
String original_comment = comment;
bool slash_slash = comment[1] == '/';
bool slash_star = comment[1] == '*';
if (comment[1] == '/') {
comment.text += 2;
comment.len -= 2;
@@ -895,6 +894,7 @@ void odin_doc_update_entities(OdinDocWriter *w) {
for_array(i, entities) {
Entity *e = entities[i];
OdinDocTypeIndex type_index = odin_doc_type(w, e->type);
gb_unused(type_index);
}
}
@@ -974,7 +974,6 @@ OdinDocArray<OdinDocEntityIndex> odin_doc_add_pkg_entities(OdinDocWriter *w, Ast
auto entity_indices = array_make<OdinDocEntityIndex>(heap_allocator(), 0, w->entity_cache.entries.count);
defer (array_free(&entity_indices));
EntityKind curr_entity_kind = Entity_Invalid;
for_array(i, entities) {
Entity *e = entities[i];
if (e->pkg != pkg) {
+3 -20
View File
@@ -75,7 +75,6 @@ void lb_emit_init_context(lbProcedure *p, lbAddr addr) {
GB_ASSERT(addr.kind == lbAddr_Context);
GB_ASSERT(addr.ctx.sel.index.count == 0);
lbModule *m = p->module;
auto args = array_make<lbValue>(permanent_allocator(), 1);
args[0] = addr.addr;
lb_emit_runtime_call(p, "__init_context", args);
@@ -118,7 +117,6 @@ lbContextData *lb_push_context_onto_stack(lbProcedure *p, lbAddr ctx) {
lbValue lb_get_equal_proc_for_type(lbModule *m, Type *type) {
Type *original_type = type;
type = base_type(type);
GB_ASSERT(is_type_comparable(type));
@@ -276,12 +274,10 @@ lbValue lb_simple_compare_hash(lbProcedure *p, Type *type, lbValue data, lbValue
}
lbValue lb_get_hasher_proc_for_type(lbModule *m, Type *type) {
Type *original_type = type;
type = core_type(type);
GB_ASSERT(is_type_valid_for_keys(type));
Type *pt = alloc_type_pointer(type);
LLVMTypeRef ptr_type = lb_type(m, pt);
auto key = hash_type(type);
lbProcedure **found = map_get(&m->hasher_procs, key);
@@ -358,7 +354,6 @@ lbValue lb_get_hasher_proc_for_type(lbModule *m, Type *type) {
lb_start_block(p, case_block);
Type *v = type->Union.variants[i];
Type *vp = alloc_type_pointer(v);
lbValue case_tag = lb_const_union_tag(p->module, type, v);
lbValue variant_hasher = lb_get_hasher_proc_for_type(m, v);
@@ -490,6 +485,7 @@ lbValue lb_gen_map_header(lbProcedure *p, lbValue map_val_ptr, Type *map_type) {
Type *key_type = map_type->Map.key;
Type *val_type = map_type->Map.value;
gb_unused(val_type);
// NOTE(bill): Removes unnecessary allocation if split gep
lbValue gep0 = lb_emit_struct_ep(p, h.addr, 0);
@@ -564,10 +560,8 @@ lbValue lb_const_hash(lbModule *m, lbValue key, Type *key_type) {
}
lbValue lb_gen_map_hash(lbProcedure *p, lbValue key, Type *key_type) {
Type *hash_type = t_u64;
lbAddr v = lb_add_local_generated(p, t_map_hash, true);
lbValue vp = lb_addr_get_ptr(p, v);
Type *t = base_type(key.type);
key = lb_emit_conv(p, key, key_type);
lbValue key_ptr = lb_address_from_load_or_generate_local(p, key);
@@ -622,9 +616,6 @@ lbProcedure *lb_create_startup_type_info(lbModule *m) {
lb_populate_function_pass_manager(m, default_function_pass_manager, false, build_context.optimization_level);
LLVMFinalizeFunctionPassManager(default_function_pass_manager);
Type *params = alloc_type_tuple();
Type *results = alloc_type_tuple();
Type *proc_type = alloc_type_proc(nullptr, nullptr, 0, nullptr, 0, false, ProcCC_CDecl);
lbProcedure *p = lb_create_dummy_procedure(m, str_lit(LB_STARTUP_TYPE_INFO_PROC_NAME), proc_type);
@@ -654,9 +645,6 @@ lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *start
lb_populate_function_pass_manager(main_module, default_function_pass_manager, false, build_context.optimization_level);
LLVMFinalizeFunctionPassManager(default_function_pass_manager);
Type *params = alloc_type_tuple();
Type *results = alloc_type_tuple();
Type *proc_type = alloc_type_proc(nullptr, nullptr, 0, nullptr, 0, false, ProcCC_CDecl);
lbProcedure *p = lb_create_dummy_procedure(main_module, str_lit(LB_STARTUP_RUNTIME_PROC_NAME), proc_type);
@@ -695,9 +683,6 @@ lbProcedure *lb_create_startup_runtime(lbModule *main_module, lbProcedure *start
GB_PANIC("Invalid init value, got %s", expr_to_string(init_expr));
}
LLVMValueKind value_kind = LLVMGetValueKind(init.value);
// gb_printf_err("%s %d\n", LLVMPrintValueToString(init.value));
if (is_type_any(e->type) || is_type_union(e->type)) {
var->init = init;
} else if (lb_is_const_or_global(init)) {
@@ -1135,7 +1120,6 @@ void lb_generate_code(lbGenerator *gen) {
LLVMInitializeNativeTarget();
char const *target_triple = alloc_cstring(permanent_allocator(), build_context.metrics.target_triplet);
char const *target_data_layout = alloc_cstring(permanent_allocator(), build_context.metrics.target_data_layout);
for_array(i, gen->modules.entries) {
LLVMSetTarget(gen->modules.entries[i].value->mod, target_triple);
}
@@ -1500,9 +1484,8 @@ void lb_generate_code(lbGenerator *gen) {
TIME_SECTION("LLVM Global Procedures and Types");
for_array(i, info->entities) {
Entity *e = info->entities[i];
String name = e->token.string;
DeclInfo *decl = e->decl_info;
Scope * scope = e->scope;
String name = e->token.string;
Scope * scope = e->scope;
if ((scope->flags & ScopeFlag_File) == 0) {
continue;
+2 -9
View File
@@ -45,10 +45,8 @@ LLVMMetadataRef lb_debug_location_from_ast(lbProcedure *p, Ast *node) {
}
LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type) {
Type *original_type = type;
LLVMContextRef ctx = m->ctx;
i64 size = type_size_of(type); // Check size
gb_unused(size);
GB_ASSERT(type != t_invalid);
@@ -56,7 +54,6 @@ LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type) {
unsigned const word_bits = cast(unsigned)(8*build_context.word_size);
GB_ASSERT(type->kind == Type_Proc);
LLVMTypeRef return_type = LLVMVoidTypeInContext(ctx);
unsigned parameter_count = 1;
for (i32 i = 0; i < type->Proc.param_count; i++) {
Entity *e = type->Proc.params->Tuple.variables[i];
@@ -73,8 +70,6 @@ LLVMMetadataRef lb_debug_type_internal_proc(lbModule *m, Type *type) {
parameters[param_index++] = lb_debug_type(m, type->Proc.results);
}
LLVMMetadataRef parent_scope = nullptr;
LLVMMetadataRef scope = nullptr;
LLVMMetadataRef file = nullptr;
for (i32 i = 0; i < type->Proc.param_count; i++) {
@@ -129,10 +124,8 @@ LLVMMetadataRef lb_debug_type_basic_type(lbModule *m, String const &name, u64 si
}
LLVMMetadataRef lb_debug_type_internal(lbModule *m, Type *type) {
Type *original_type = type;
LLVMContextRef ctx = m->ctx;
i64 size = type_size_of(type); // Check size
gb_unused(size);
GB_ASSERT(type != t_invalid);
+1 -10
View File
@@ -430,8 +430,6 @@ lbValue lb_emit_arith_array(lbProcedure *p, TokenKind op, lbValue lhs, lbValue r
lbValue lb_emit_arith(lbProcedure *p, TokenKind op, lbValue lhs, lbValue rhs, Type *type) {
lbModule *m = p->module;
if (is_type_array_like(lhs.type) || is_type_array_like(rhs.type)) {
return lb_emit_arith_array(p, op, lhs, rhs, type);
} else if (is_type_complex(type)) {
@@ -779,7 +777,6 @@ lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) {
case Token_not_in:
{
lbValue left = lb_build_expr(p, be->left);
Type *type = default_type(tv.type);
lbValue right = lb_build_expr(p, be->right);
Type *rt = base_type(right.type);
if (is_type_pointer(rt)) {
@@ -989,7 +986,7 @@ lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
if (is_type_boolean(src) && (is_type_boolean(dst) || is_type_integer(dst))) {
LLVMValueRef b = LLVMBuildICmp(p->builder, LLVMIntNE, value.value, LLVMConstNull(lb_type(m, value.type)), "");
lbValue res = {};
res.value = LLVMBuildIntCast2(p->builder, value.value, lb_type(m, t), false, "");
res.value = LLVMBuildIntCast2(p->builder, b, lb_type(m, t), false, "");
res.type = t;
return res;
}
@@ -1228,14 +1225,12 @@ lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) {
// subtype polymorphism casting
if (check_is_assignable_to_using_subtype(src_type, t)) {
Type *st = type_deref(src_type);
Type *pst = st;
st = type_deref(st);
bool st_is_ptr = is_type_pointer(src_type);
st = base_type(st);
Type *dt = t;
bool dt_is_ptr = type_deref(dt) != dt;
GB_ASSERT(is_type_struct(st) || is_type_raw_union(st));
String field_name = lookup_subtype_polymorphic_field(t, src_type);
@@ -1966,7 +1961,6 @@ lbValue lb_build_unary_and(lbProcedure *p, Ast *expr) {
lbValue key = lb_build_expr(p, ie->index);
key = lb_emit_conv(p, key, t->Map.key);
Type *result_type = type_of_expr(expr);
lbAddr addr = lb_addr_map(map_val, key, t, alloc_type_pointer(t->Map.value));
lbValue ptr = lb_addr_get_ptr(p, addr);
@@ -3403,9 +3397,6 @@ lbAddr lb_build_addr(lbProcedure *p, Ast *expr) {
}
case Type_Slice: {
if (cl->elems.count > 0) {
Type *elem_type = bt->Slice.elem;
Type *elem_ptr_type = alloc_type_pointer(elem_type);
Type *elem_ptr_ptr_type = alloc_type_pointer(elem_ptr_type);
lbValue slice = lb_const_value(p->module, type, exact_value_compound(expr));
lbValue data = lb_slice_elem(p, slice);
+5 -6
View File
@@ -811,7 +811,6 @@ LLVMTypeRef llvm_addr_type(lbValue addr_val) {
}
lbValue lb_emit_load(lbProcedure *p, lbValue value) {
lbModule *m = p->module;
GB_ASSERT(value.value != nullptr);
GB_ASSERT(is_type_pointer(value.type));
Type *t = type_deref(value.type);
@@ -981,7 +980,6 @@ lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) {
Entity *field = t->Struct.fields[i];
Type *base_type = field->type;
GB_ASSERT(base_type->kind == Type_Pointer);
Type *elem = base_type->Pointer.elem;
lbValue dst = lb_emit_struct_ep(p, res.addr, cast(i32)i);
lbValue src_ptr = lb_emit_struct_ep(p, addr.addr, cast(i32)i);
@@ -1010,7 +1008,6 @@ lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) {
}
}
Type *elem_type = base_type(array_type->Array.elem);
lbAddr res = lb_add_local_generated(p, addr.swizzle.type, false);
lbValue ptr = lb_addr_get_ptr(p, res);
GB_ASSERT(is_type_pointer(ptr.type));
@@ -1044,8 +1041,8 @@ lbValue lb_addr_load(lbProcedure *p, lbAddr const &addr) {
GB_ASSERT(array_type->kind == Type_Array);
unsigned res_align = cast(unsigned)type_align_of(addr.swizzle_large.type);
gb_unused(res_align);
Type *elem_type = base_type(array_type->Array.elem);
lbAddr res = lb_add_local_generated(p, addr.swizzle_large.type, false);
lbValue ptr = lb_addr_get_ptr(p, res);
GB_ASSERT(is_type_pointer(ptr.type));
@@ -1291,10 +1288,9 @@ String lb_get_entity_name(lbModule *m, Entity *e, String default_name) {
LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
Type *original_type = type;
LLVMContextRef ctx = m->ctx;
i64 size = type_size_of(type); // Check size
gb_unused(size);
GB_ASSERT(type != t_invalid);
@@ -1681,6 +1677,7 @@ LLVMTypeRef lb_type_internal(lbModule *m, Type *type) {
// LLVM takes the first element's alignment as the entire alignment (like C)
i64 align = type_align_of(type);
i64 size = type_size_of(type);
gb_unused(size);
if (is_type_union_maybe_pointer_original_alignment(type)) {
LLVMTypeRef fields[1] = {lb_type(m, type->Union.variants[0])};
@@ -1890,6 +1887,7 @@ lbFunctionType *lb_get_function_type(lbModule *m, lbProcedure *p, Type *pt) {
ft_found = map_get(&m->function_type_map, hash_type(pt));
if (!ft_found) {
LLVMTypeRef llvm_proc_type = lb_type(p->module, pt);
gb_unused(llvm_proc_type);
ft_found = map_get(&m->function_type_map, hash_type(pt));
}
GB_ASSERT(ft_found != nullptr);
@@ -1905,6 +1903,7 @@ void lb_ensure_abi_function_type(lbModule *m, lbProcedure *p) {
lbFunctionType **ft_found = map_get(&m->function_type_map, hash);
if (ft_found == nullptr) {
LLVMTypeRef llvm_proc_type = lb_type(p->module, p->type);
gb_unused(llvm_proc_type);
ft_found = map_get(&m->function_type_map, hash);
}
GB_ASSERT(ft_found != nullptr);
+3 -7
View File
@@ -179,8 +179,9 @@ lbProcedure *lb_create_procedure(lbModule *m, Entity *entity, bool ignore_body)
TypeTuple *params = &pt->Proc.params->Tuple;
for (isize i = 0; i < pt->Proc.param_count; i++) {
Entity *e = params->variables[i];
Type *original_type = e->type;
if (e->kind != Entity_Variable) continue;
if (e->kind != Entity_Variable) {
continue;
}
if (i+1 == params->variables.count && pt->Proc.c_vararg) {
continue;
@@ -658,7 +659,6 @@ lbValue lb_emit_call_internal(lbProcedure *p, lbValue value, lbValue return_ptr,
{
LLVMTypeRef ftp = lb_type(p->module, value.type);
LLVMTypeRef ft = LLVMGetElementType(ftp);
LLVMValueRef fn = value.value;
if (!lb_is_type_kind(LLVMTypeOf(value.value), LLVMFunctionTypeKind)) {
fn = LLVMBuildPointerCast(p->builder, fn, ftp, "");
@@ -1690,8 +1690,6 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
case BuiltinProc_atomic_cxchgweak_failacq:
case BuiltinProc_atomic_cxchgweak_acq_failrelaxed:
case BuiltinProc_atomic_cxchgweak_acqrel_failrelaxed: {
Type *type = expr->tav.type;
lbValue address = lb_build_expr(p, ce->args[0]);
Type *elem = type_deref(address.type);
lbValue old_value = lb_build_expr(p, ce->args[1]);
@@ -1765,7 +1763,6 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
case BuiltinProc_fixed_point_mul_sat:
case BuiltinProc_fixed_point_div_sat:
{
bool do_bswap = is_type_different_to_arch_endianness(tv.type);
Type *platform_type = integer_endian_type_to_platform_type(tv.type);
lbValue x = lb_emit_conv(p, lb_build_expr(p, ce->args[0]), platform_type);
@@ -2062,7 +2059,6 @@ lbValue lb_build_call_expr_internal(lbProcedure *p, Ast *expr) {
Type *at = a.type;
if (at->kind == Type_Tuple) {
for_array(i, at->Tuple.variables) {
Entity *e = at->Tuple.variables[i];
lbValue v = lb_emit_struct_ev(p, a, cast(i32)i);
args[arg_index++] = v;
}
-6
View File
@@ -547,7 +547,6 @@ void lb_build_range_enum(lbProcedure *p, Type *enum_type, Type *val_type, lbValu
Type *t = enum_type;
GB_ASSERT(is_type_enum(t));
Type *enum_ptr = alloc_type_pointer(t);
t = base_type(t);
Type *core_elem = core_type(t);
GB_ASSERT(t->kind == Type_Enum);
@@ -863,8 +862,6 @@ void lb_build_unroll_range_stmt(lbProcedure *p, AstUnrollRangeStmt *rs, Scope *s
lbValue val = {};
lbValue key = {};
lbBlock *loop = nullptr;
lbBlock *done = nullptr;
Ast *expr = unparen_expr(rs->expr);
TypeAndValue tav = type_and_value_of_expr(expr);
@@ -1460,7 +1457,6 @@ void lb_build_assignment(lbProcedure *p, Array<lbAddr> &lvals, Slice<Ast *> cons
Type *t = init.type;
GB_ASSERT(t->kind == Type_Tuple);
for_array(i, t->Tuple.variables) {
Entity *e = t->Tuple.variables[i];
lbValue v = lb_emit_struct_ev(p, init, cast(i32)i);
array_add(&inits, v);
}
@@ -1553,7 +1549,6 @@ void lb_build_return_stmt(lbProcedure *p, Slice<Ast *> const &return_results) {
Type *t = res.type;
if (t->kind == Type_Tuple) {
for_array(i, t->Tuple.variables) {
Entity *e = t->Tuple.variables[i];
lbValue v = lb_emit_struct_ev(p, res, cast(i32)i);
array_add(&results, v);
}
@@ -1765,7 +1760,6 @@ void lb_build_for_stmt(lbProcedure *p, Ast *node) {
void lb_build_assign_stmt_array(lbProcedure *p, TokenKind op, lbAddr const &lhs, lbValue const &value) {
Type *lhs_type = lb_addr_type(lhs);
Type *rhs_type = value.type;
Type *array_type = base_type(lhs_type);
GB_ASSERT(is_type_array_like(array_type));
i64 count = get_array_type_count(array_type);
-11
View File
@@ -155,7 +155,6 @@ lbValue lb_type_info_member_tags_offset(lbProcedure *p, isize count) {
void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info data
lbModule *m = p->module;
LLVMContextRef ctx = m->ctx;
CheckerInfo *info = m->info;
{
@@ -176,16 +175,9 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
// Useful types
Type *t_i64_slice_ptr = alloc_type_pointer(alloc_type_slice(t_i64));
Type *t_string_slice_ptr = alloc_type_pointer(alloc_type_slice(t_string));
Entity *type_info_flags_entity = find_core_entity(info->checker, str_lit("Type_Info_Flags"));
Type *t_type_info_flags = type_info_flags_entity->type;
i32 type_info_member_types_index = 0;
i32 type_info_member_names_index = 0;
i32 type_info_member_offsets_index = 0;
for_array(type_info_type_index, info->type_info_types) {
Type *t = info->type_info_types[type_info_type_index];
if (t == nullptr || t == t_invalid) {
@@ -567,9 +559,6 @@ void lb_setup_type_info_data(lbProcedure *p) { // NOTE(bill): Setup type_info da
GB_ASSERT(is_type_integer(t->Enum.base_type));
LLVMTypeRef align_type = lb_alignment_prefix_type_hack(m, type_align_of(t));
LLVMTypeRef array_type = LLVMArrayType(lb_type(m, t_u8), 8);
for_array(i, fields) {
name_values[i] = lb_const_string(m, fields[i]->token.string).value;
value_values[i] = lb_const_value(m, t_i64, fields[i]->Constant.value).value;
-2
View File
@@ -1207,7 +1207,6 @@ lbValue lb_map_entries(lbProcedure *p, lbValue value) {
Type *t = base_type(value.type);
GB_ASSERT_MSG(t->kind == Type_Map, "%s", type_to_string(t));
init_map_internal_types(t);
Type *gst = t->Map.generated_struct_type;
i32 index = 1;
lbValue entries = lb_emit_struct_ev(p, value, index);
return entries;
@@ -1217,7 +1216,6 @@ lbValue lb_map_entries_ptr(lbProcedure *p, lbValue value) {
Type *t = base_type(type_deref(value.type));
GB_ASSERT_MSG(t->kind == Type_Map, "%s", type_to_string(t));
init_map_internal_types(t);
Type *gst = t->Map.generated_struct_type;
i32 index = 1;
lbValue entries = lb_emit_struct_ep(p, value, index);
return entries;
+4 -4
View File
@@ -236,8 +236,8 @@ i32 linker_stage(lbGenerator *gen) {
for_array(i, m->foreign_library_paths) {
String lib = m->foreign_library_paths[i];
GB_ASSERT(lib.len < gb_count_of(lib_str_buf)-1);
isize len = gb_snprintf(lib_str_buf, gb_size_of(lib_str_buf),
" \"%.*s\"", LIT(lib));
gb_snprintf(lib_str_buf, gb_size_of(lib_str_buf),
" \"%.*s\"", LIT(lib));
lib_str = gb_string_appendc(lib_str, lib_str_buf);
}
}
@@ -245,8 +245,8 @@ i32 linker_stage(lbGenerator *gen) {
for_array(i, gen->default_module.foreign_library_paths) {
String lib = gen->default_module.foreign_library_paths[i];
GB_ASSERT(lib.len < gb_count_of(lib_str_buf)-1);
isize len = gb_snprintf(lib_str_buf, gb_size_of(lib_str_buf),
" \"%.*s\"", LIT(lib));
gb_snprintf(lib_str_buf, gb_size_of(lib_str_buf),
" \"%.*s\"", LIT(lib));
lib_str = gb_string_appendc(lib_str, lib_str_buf);
}
-3
View File
@@ -2432,7 +2432,6 @@ Ast *parse_operand(AstFile *f, bool lhs) {
bool no_nil = false;
bool maybe = false;
CommentGroup *docs = f->lead_comment;
Token start_token = f->curr_token;
if (allow_token(f, Token_OpenParen)) {
@@ -3634,7 +3633,6 @@ bool parse_expect_field_separator(AstFile *f, Ast *param) {
}
Ast *parse_struct_field_list(AstFile *f, isize *name_count_) {
CommentGroup *docs = f->lead_comment;
Token start_token = f->curr_token;
auto decls = array_make<Ast *>(heap_allocator());
@@ -4750,7 +4748,6 @@ ParseFileError init_ast_file(AstFile *f, String fullpath, TokenPos *err_pos) {
isize init_token_cap = gb_max(token_cap, 16);
array_init(&f->tokens, heap_allocator(), 0, gb_max(init_token_cap, 16));
isize cap0 = f->tokens.capacity;
if (err == TokenizerInit_Empty) {
Token token = {Token_EOF};
+1 -1
View File
@@ -709,7 +709,7 @@ struct Ast {
};
#define ast_node(n_, Kind_, node_) GB_JOIN2(Ast, Kind_) *n_ = &(node_)->Kind_; GB_ASSERT_MSG((node_)->kind == GB_JOIN2(Ast_, Kind_), \
#define ast_node(n_, Kind_, node_) GB_JOIN2(Ast, Kind_) *n_ = &(node_)->Kind_; gb_unused(n_); GB_ASSERT_MSG((node_)->kind == GB_JOIN2(Ast_, Kind_), \
"expected '%.*s' got '%.*s'", \
LIT(ast_strings[GB_JOIN2(Ast_, Kind_)]), LIT(ast_strings[(node_)->kind]))
#define case_ast_node(n_, Kind_, node_) case GB_JOIN2(Ast_, Kind_): { ast_node(n_, Kind_, node_);
+1 -1
View File
@@ -946,7 +946,7 @@ void generate_and_print_query_data_go_to_definitions(Checker *c) {
isize data_min_size = 0;
u32 header_offset = cast(u32)data_min_size;
u32 header_offset = cast(u32)data_min_size; gb_unused(header_offset);
data_min_size += gb_size_of(GoToDefHeader);
data_min_size = align_formula_isize(data_min_size, 8);
-2
View File
@@ -539,14 +539,12 @@ String quote_to_ascii(gbAllocator a, String str, u8 quote='"') {
r = 0XFFFD;
}
if (r < 0x10000) {
u8 b = cast(u8)r;
array_add(&buf, cast(u8)'\\');
array_add(&buf, cast(u8)'u');
for (isize i = 12; i >= 0; i -= 4) {
array_add(&buf, cast(u8)lower_hex[(r>>i)&0xf]);
}
} else {
u8 b = cast(u8)r;
array_add(&buf, cast(u8)'\\');
array_add(&buf, cast(u8)'U');
for (isize i = 28; i >= 0; i -= 4) {
-6
View File
@@ -1286,7 +1286,6 @@ i64 get_array_type_count(Type *t) {
Type *core_array_type(Type *t) {
for (;;) {
Type *prev = t;
t = base_array_type(t);
if (t->kind != Type_Array && t->kind != Type_EnumeratedArray && t->kind != Type_SimdVector) {
break;
@@ -1664,7 +1663,6 @@ Scope *polymorphic_record_parent_scope(Type *t) {
}
bool is_type_polymorphic_record_specialized(Type *t) {
Type *original_type = t;
t = base_type(t);
if (t->kind == Type_Struct) {
return t->Struct.is_poly_specialized;
@@ -3030,10 +3028,6 @@ i64 type_align_of_internal(Type *t, TypePath *path) {
}
case Type_SimdVector: {
// align of
i64 count = t->SimdVector.count;
Type *elem = t->SimdVector.elem;
i64 size = count * type_size_of_internal(elem, path);
// IMPORTANT TODO(bill): Figure out the alignment of vector types
return gb_clamp(next_pow2(type_size_of_internal(t, path)), 1, build_context.max_align);
}