Merge branch 'master' into poly

This commit is contained in:
kalsprite
2026-08-07 17:41:30 -07:00
41 changed files with 1301 additions and 224 deletions

View File

@@ -410,6 +410,15 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
}
if (!src->Proc.is_polymorphic || src->Proc.is_poly_specialized) {
// NOTE: polymorphic procedure check not idempotent without this
if (src->Proc.is_poly_specialized && base_entity->Procedure.generated_from_polymorphic) {
if (are_types_identical(src, dst)) {
if (poly_proc_data) {
poly_proc_data->gen_entity = base_entity;
}
return true;
}
}
return false;
}
@@ -457,9 +466,7 @@ gb_internal bool find_or_generate_polymorphic_procedure(CheckerContext *old_c, E
scope->flags |= ScopeFlag_Proc;
nctx.scope = scope;
nctx.allow_polymorphic_types = true;
if (nctx.polymorphic_scope == nullptr) {
nctx.polymorphic_scope = scope;
}
nctx.polymorphic_scope = scope;
auto *pt = &src->Proc;
@@ -1027,17 +1034,6 @@ gb_internal bool check_is_assignable_to_with_score(CheckerContext *c, Operand *o
return false;
}
// Handle polymorphic procedure used as default parameter
if (operand->mode == Addressing_Value && is_type_proc(type) && is_type_proc(operand->type)) {
Entity *e = entity_from_expr(operand->expr);
if (e != nullptr && e->kind == Entity_Procedure && is_type_polymorphic(e->type) && !is_type_polymorphic(type)) {
// Special case: Allow a polymorphic procedure to be used as default value for concrete proc type
// during the initial check. It will be properly instantiated when actually used.
if (score_) *score_ = assign_score_function(1);
return true;
}
}
i64 score = check_distance_between_types(c, operand, type, allow_array_programming);
if (score >= 0) {
if (score_) *score_ = assign_score_function(score, is_variadic);
@@ -4090,7 +4086,7 @@ gb_internal bool check_transmute(CheckerContext *c, Ast *node, Operand *o, Type
big_int_shl_eq(&umax, &sz_in_bits);
if (is_type_unsigned(src_t) && !is_type_unsigned(dst_t)) {
if (big_int_cmp(&v, &smax) >= 0) {
if (big_int_cmp(&v, &smax) > 0) {
big_int_sub_eq(&v, &umax);
}
} else if (!is_type_unsigned(src_t) && is_type_unsigned(dst_t)) {
@@ -7637,7 +7633,9 @@ gb_internal CallArgumentData check_call_arguments_proc_group(CheckerContext *c,
if (max_matched_features > 0) {
for_array(i, valids) {
Entity *p = procs[valids[i].index];
// NOTE: A polymorphic candidate appends its instantiated entity to proc_entities above,
// so valids[i].index can be >= procs.count.
Entity *p = proc_entities[valids[i].index];
Type *t = base_type(p->type);
GB_ASSERT(t->kind == Type_Proc);