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

compiler hangs indefinitely #4594

Open
foldcat opened this issue Dec 18, 2024 · 2 comments
Open

compiler hangs indefinitely #4594

foldcat opened this issue Dec 18, 2024 · 2 comments
Labels
bug checker replicated We were able to replicate the bug.

Comments

@foldcat
Copy link

foldcat commented Dec 18, 2024

Context

  • odin report output:
    Odin: dev-2024-12
    OS: Gentoo Linux, Linux 6.6.62-gentoo-dist
    CPU: 13th Gen Intel(R) Core(TM) i5-13400F
    RAM: 31927 MiB
    Backend: LLVM 19.1.4+libcxx

Expected Behavior

this piece of code compiles

package test

import "core:fmt"

Foo :: struct($T: typeid) {
        val: T,
        a:   Foo(T),
        b:   Foo(T),
}

make_foo :: proc($T: typeid, v: T) -> Foo(T) {
        return new_clone(Foo{val = v})
}

main :: proc() {
  f := make_foo(int, 1)
}

Current Behavior

compiler hangs indefinitely

Steps to Reproduce

  1. paste the code
  2. odin build .
  3. hangs indefinitely
@Kelimion
Copy link
Member

Kelimion commented Dec 18, 2024

It is a bug, but the code as provided wasn't going to compile because Foo incorporating itself is a cycle.
This does work:

package test

import "core:fmt"

Foo :: struct($T: typeid) {
	val: T,
	a:   ^Foo(T), // Can't be `Foo(T)` because a struct can't contain itself.
	b:   ^Foo(T),
}

make_foo :: proc($T: typeid, v: T) -> ^Foo(T) { // `new_clone` returns a pointer
	return new_clone(Foo(T){val = v})       // `Foo{val = v}` had to become `Foo(T){val = v}`
}

main :: proc() {
	f := make_foo(int, 1)
	fmt.println(f) // &Foo($T=int){val = 1, a = <nil>, b = <nil>}
}

@Kelimion Kelimion added bug replicated We were able to replicate the bug. checker labels Dec 18, 2024
@Kelimion
Copy link
Member

Having said that, it doesn't hang for me so much as fail with a stack overflow.

Odin:    dev-2024-12:d3f072835
OS:      Windows 10 Professional (version: 22H2), build 19045.4780
CPU:     AMD Ryzen 9 5950X 16-Core Processor
RAM:     65444 MiB
Backend: LLVM 18.1.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug checker replicated We were able to replicate the bug.
Projects
None yet
Development

No branches or pull requests

2 participants