odin-lang / Odin

Odin Programming Language
https://odin-lang.org
BSD 3-Clause "New" or "Revised" License
6.66k stars 584 forks source link

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

Closed blob1807 closed 3 months ago

blob1807 commented 5 months ago

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 commented 5 months ago

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

https://github.com/odin-lang/Odin/blob/96abe8627c885a8829dd8e3fb3455a3b5e196c7a/src/types.cpp#L3220-L3221

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.

https://github.com/odin-lang/Odin/blob/96abe8627c885a8829dd8e3fb3455a3b5e196c7a/src/check_type.cpp#L660-L669