rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.77k stars 12.77k forks source link

Infinite types not detected #68209

Open truchi opened 4 years ago

truchi commented 4 years ago

Gentlemen,

The following code causes my computer to freeze when attempting compilation (variant: takes a long time to compile and errs with "...infinite size..."). It should have warned about the infinite size type.

    // /!\ DO NOT COMPILE THIS CODE FOR FUN /!\
fn main() {
    #[derive(Debug)]
    enum Atom<V, E> {
        Vertex(V),
        Edge(E),
    }

    #[derive(Debug)]
    struct Edge<E, V> {
        data: E,
        // atom: Option<&'a Atom<Vertex<'a, V, Self>, Self>>, // Variant
        atom: Option<Box<Atom<Vertex<V, Self>, Self>>>, // Bug here
    }

    #[derive(Debug)]
    struct Vertex<V, E> {
        data: V,
        // atom: Option<&'a Atom<Self, Edge<'a, E, Self>>>, // Variant
        atom: Option<Box<Atom<Self, Edge<E, Self>>>>,  // Bug here
    }

    let vertex = Vertex::<i8, i8> {
        data: 1,
        atom: None,
    };

    let edge = Edge::<i8, i8> {
        data: 1,
        atom: None,
    };

    println!("{:#?} {:#?}", vertex, edge);
}

Hope this helps.

jfrimmel commented 4 years ago

Unfortunately the code provided is not compilable as there are definitions (for MyVertex and MyEdge) and an enclosing function missing. Could you please update your code with a self-contained example

truchi commented 4 years ago

Oops sorry missed that. Updated.

jfrimmel commented 4 years ago

I've run the example on a server with 32GiB RAM and 48GiB swap memory using rustc 1.42.0-nightly (31dd4f4ac 2020-01-13). The OOM killer was on guard and killed rustc after 6.8min:

   Compiling compile-test v0.1.0 (/home/jfrimmel/compile-test)
error: could not compile `compile-test`.

Caused by:
  process didn't exit successfully: `rustc --edition=2018 --crate-name compile_test src/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=a40bb9266b098d04 -C extra-filename=-a40bb9266b098d04 --out-dir /home/jfrimmel/compile-test/target/debug/deps -C incremental=/home/jfrimmel/compile-test/target/debug/incremental -L dependency=/home/jfrimmel/compile-test/target/debug/deps` (signal: 9, SIGKILL: kill)

I took a screenshot of HTOP after ~4min. You can say, that the memory usage is quite high :smile: HTOP Screenshot

Below you find the relevant part of dmesg:

[2254946.092252] oom-kill:constraint=CONSTRAINT_NONE,nodemask=(null),cpuset=/,mems_allowed=0,global_oom,task_memcg=/user.slice/user-1000.slice/session-93.scope,task=rustc,pid=136409,uid=1000
[2254946.092262] Out of memory: Killed process 136409 (rustc) total-vm:134493012kB, anon-rss:31864240kB, file-rss:0kB, shmem-rss:0kB
[2254949.915967] oom_reaper: reaped process 136409 (rustc), now anon-rss:0kB, file-rss:0kB, shmem-rss:0kB

As you can see, the memory rustc tried to acquire was up to 128GiB...

jfrimmel commented 4 years ago

Triage: no change, still happens with

rustc +nightly --version --verbose
rustc 1.47.0-nightly (5180f3da5 2020-08-23)
binary: rustc
commit-hash: 5180f3da5fd72627a8d38558ad1297df38793acd
commit-date: 2020-08-23
host: x86_64-unknown-linux-gnu
release: 1.47.0-nightly
LLVM version: 11.0