odin-lang / Odin

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

Race condition related to #soa and proc arguments 2 #3204

Closed DireLines closed 5 months ago

DireLines commented 7 months ago

Context

Tried adding a Script component to my game, it caused a compile error to sometimes happen. I pared the code down to this single file where the bug happens a little less than half the time. The bug seems to trigger depending on the order in which Odin evaluates the code. If objects is listed first in the definition of Game, the issue seems to be fixed

package main

import "core:time"

main :: proc() {
    game := Game{}
}

Input :: struct {}

Game :: struct {
    input_system: ^Input, //removing this or reordering below objects fixes the bug 
    objects:      #soa[dynamic]GameObject,
    start_tick:   time.Tick, //removing this fixes the bug 
}

GameObject :: struct {
    awake: proc(game: ^Game), //making it so that no args are of type ^Game fixes the bug
}

Please provide any relevant information about your setup. This is important in case the issue is not reproducible except for under certain conditions.

Expected Behavior

odin build main.odin -file successfully compiles

Current Behavior

Internal Compiler Error: Type_Info for 'Tick' could not be found fish: Job 1, 'odin build main.odin -file' terminated by signal SIGTRAP (Trace or breakpoint trap)

Steps to Reproduce

  1. save this code to a file, main.odin
  2. run odin build main.odin -file or odin build .
  3. This seems to be a race condition and the error occurs about 30% of the time, the other 70% build successfully
rick-masters commented 5 months ago

I can still reproduce this with https://github.com/odin-lang/Odin/commit/1009182f7b35e38e0fba375ad830fc609a7be831:

[rick@hb-ubuntu-20.04 3204]$ ../../Odin-latest/odin build .
Internal Compiler Error: Type_Info for 'Tick' could not be found
Illegal instruction (core dumped)
[rick@hb-ubuntu-20.04 3204]$ ../../Odin-latest/odin report
Where to find more information and get into contact when you encounter a bug:

        Website: https://odin-lang.org
        GitHub:  https://github.com/odin-lang/Odin/issues

Useful information to add to a bug report:

        Odin:    dev-2024-03:1009182f7
        OS:      Ubuntu 22.04.4 LTS, Linux 6.5.0-1014-aws
        CPU:     Intel(R) Xeon(R) Platinum 8488C
        RAM:     31548 MiB
        Backend: LLVM 14.0.0

I have a forthcoming PR with an explanation but I suspect @gingerBill might come up with a better solution.

gingerBill commented 5 months ago

I am struggling to replicate this, but thank you for the detailed post in #3335