aboutsummaryrefslogtreecommitdiff
path: root/src/ir.cpp
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-07-17 15:08:36 +0100
committerGinger Bill <bill@gingerbill.org>2017-07-17 15:08:36 +0100
commit9a8759efefa24f5ae1e6d91b67dca72357a99ff9 (patch)
treef0c5087618010a4fa4d85cbe019426f9c18a7ede /src/ir.cpp
parent054948e701c1340e72ac236d58da15ca9e6d617c (diff)
Polymorphic type specialization for procedures
Diffstat (limited to 'src/ir.cpp')
-rw-r--r--src/ir.cpp29
1 files changed, 20 insertions, 9 deletions
diff --git a/src/ir.cpp b/src/ir.cpp
index c3fa9902f..98ebfa4c6 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -2826,6 +2826,9 @@ irValue *ir_emit_conv(irProcedure *proc, irValue *value, Type *t) {
}
if (are_types_identical(src, dst)) {
+ if (!are_types_identical(src_type, t)) {
+ return ir_emit_transmute(proc, value, t);
+ }
return value;
}
@@ -5752,19 +5755,24 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) {
continue;
}
- bool polymorphic = is_type_polymorphic(e->type);
- if (polymorphic && !is_type_struct(e->type)) {
- continue;
- }
- if (map_get(&proc->module->min_dep_map, hash_pointer(e)) == nullptr) {
- // NOTE(bill): Nothing depends upon it so doesn't need to be built
- continue;
- }
+ String entity_name = e->token.string;
if (e->kind == Entity_TypeName) {
+ bool polymorphic_struct = false;
+ if (e->type != nullptr && e->kind == Entity_TypeName) {
+ Type *bt = base_type(e->type);
+ if (bt->kind == Type_Record) {
+ polymorphic_struct = bt->Record.is_polymorphic;
+ }
+ }
+
+ if (!polymorphic_struct && map_get(&proc->module->min_dep_map, hash_pointer(e)) == nullptr) {
+ continue;
+ }
+
// NOTE(bill): Generate a new name
// parent_proc.name-guid
- String ts_name = e->token.string;
+ String ts_name = entity_name;
isize name_len = proc->name.len + 1 + ts_name.len + 1 + 10 + 1;
u8 *name_text = gb_alloc_array(proc->module->allocator, u8, name_len);
@@ -5787,6 +5795,9 @@ void ir_build_constant_value_decl(irProcedure *proc, AstNodeValueDecl *vd) {
auto procs = *found;
for_array(i, procs) {
Entity *e = procs[i];
+ if (map_get(&proc->module->min_dep_map, hash_pointer(e)) == nullptr) {
+ continue;
+ }
DeclInfo *d = decl_info_of_entity(info, e);
ir_build_poly_proc(proc, &d->proc_lit->ProcLit, e);
}