Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessing parameter/field of parametric struct type cause complier hang #3471

Open
blob1807 opened this issue Apr 23, 2024 · 1 comment
Open

Comments

@blob1807
Copy link
Contributor

Context

Odin: dev-2024-04-nightly:a00d96c0d
OS: Windows 11 Home Basic (version: 23H2), build 22631.3447
CPU: AMD Ryzen 7 6800HS with Radeon Graphics
RAM: 15608 MiB
Backend: LLVM 17.0.1

Expected Behavior

The same as if it wasn't parametric, i.e. Error: Type 'K' has no field 'l' and Error: Type 'K' has no field 'm'

Current Behavior

Trying to access the parameter or field of parametric struct on the type itself causes complier to indefinitely hang.

Failure Information (for bugs)

Steps to Reproduce

package t 

main :: proc() { 
    K :: struct($m:int){l:int}
    k := K.l
    // or
    k := K.m
}
  1. Copy Paste
  2. Run
  3. Profit??
@Feoramund
Copy link
Contributor

I've narrowed this down to the thread waiting here:

Odin/src/types.cpp

Lines 3220 to 3221 in 96abe86

if (type->kind == Type_Struct) {
wait_signal_until_available(&type->Struct.fields_wait_signal);

It looks like the following code handles non-polymorphics and sets the signal, but nothing is done for polymorphics. I'm not familiar enough with the type checker to know what the proper fix would be. Removing either the wait or raising the signal in all cases causes this hang to no longer occur, at least.

Odin/src/check_type.cpp

Lines 660 to 669 in 96abe86

if (!struct_type->Struct.is_polymorphic) {
if (st->where_clauses.count > 0 && st->polymorphic_params == nullptr) {
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);
wait_signal_set(&struct_type->Struct.fields_wait_signal);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants