Skip to content

Parapoly Types are type checked incorrectly due to race condition #2463

@Lperlind

Description

@Lperlind
  • Operating System & Odin Version:
    Odin: dev-2023-04:b42bb5be
    OS: Windows 10 Home Basic (version: 21H2), build 19044.2728
    CPU: AMD Ryzen 7 5800X 8-Core Processor
    RAM: 32711 MiB

The type checker will randomly fail with a parapoly type due to a race condition. An error will be reported that a field is missing.
I can only reproduce this with parapoly types that are defined in separate procedures.
Take the following minimal failure case:

package will_eventually_fail

Foo :: struct($N: int) {
    a: u32,
}

bar :: proc(foo: ^Foo($N)) {
    foo.a = 1
}

a :: proc() {
	foo: Foo(1)
	bar(&foo)
}

b :: proc() {
	foo: Foo(1)
	bar(&foo)
}

Running Odin check will pass majority of the time. Every so often (10-100 runs) I will get

will_eventually_fail.odin(8:5) 'foo' of type '^Foo(1)' has no field 'a'
        foo.a = 1
        ^~^

Which is incorrect.
Now if I define Foo(1) in a and make b define Foo(2) instead then I never get the error (I have done 10k + runs).

package fine

Foo :: struct($N: int) {
    a: u32,
}

bar :: proc(foo: ^Foo($N)) {
    foo.a = 1
}

a :: proc() {
	foo: Foo(1)
	bar(&foo)
}

a :: proc() {
	foo: Foo(2) // <-- the only change
	bar(&foo)
}

My suspicion is that all the information to resolve Foo(1) is being done by one thread when another thread is checking it when the type information is half completed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions