Odin icon indicating copy to clipboard operation
Odin copied to clipboard

Shared Generic across structs sometimes causes build errors

Open Skytrias opened this issue 2 years ago • 4 comments

Context

    Odin: dev-2023-11:dd9b0ae4
    OS:   Windows 10 Home Basic (version: 22H2), build 19045.3570
    CPU:  AMD Ryzen 5 3600 6-Core Processor
    RAM:  16310 MiB

Expected Behavior

Allow to use Generic $T normally across structs in different procedures.

Current Behavior

crashes about 20% of the builds, otherwhise it compiles as expected. Maybe it's something about the build step and how structs get built internally with generics across threads?

Steps to Reproduce

package src

A :: struct($T: typeid) {
    value: T,
}

B :: struct($T: typeid) {
    a: A(T)
}

// second proc is important!
test :: proc() {
    a: A(int) = { 10 }
    b: B(int) = { a }
}

main :: proc() {
    a: A(int) = { 10 }
    b: B(int) = { a }
}

Failure Logs

.../main.odin(20:16) Cannot assign value 'a' of type 'A($T=int) (package src)' to 'A($T=int) (package src)' in structure literal
    b: B(int) = { a }
                  ^
    Suggestion: the expression may be directly casted to type A($T=int)

or

.../main.odin(13:16) Too many values in structure literal, expected 0, got 1
    b: B(int) = { a }

Skytrias avatar Nov 11 '23 18:11 Skytrias

I ran the compiler with -fsanitize=thread using your example and race hazards were detected and reported. The reports are pretty easy to comprehend, but I don't know enough about the compiler internals to suggest fixes. I suspect a few well placed semaphores will go a long way!

JesseRMeyer avatar Nov 19 '23 19:11 JesseRMeyer

The linked issue has been fixed, can you verify it also fixed this one?

laytan avatar Dec 19 '23 23:12 laytan

Still happens, but the error rate isn't as frequent as before.

JesseRMeyer avatar Dec 19 '23 23:12 JesseRMeyer

Can this be replicated any more on the latest commit?

gingerBill avatar Mar 25 '24 13:03 gingerBill