tvix doesn't detect infinite recursion

#251
Opened by qyliss at 2023-02-07T16·22+00

Nix can detect infinite recursions, but tvix can't. This can result in infinite loops, stack overflows, being OOM killed, or presumably not being able to allocate memory if overcommit is disabled.

% nix-instantiate -E 'let x = x; in x'
error: infinite recursion encountered

       at «string»:1:9:

            1| let x = x; in x
             |         ^

  1. qyliss updated the body of this issue at 2023-02-07T16·22+00
  2. Hmm, I wonder if this broke with the recent force refactoring, too. Will look into it.

    tazjin at 2023-02-07T17·24+00

  3. This is related to handling of inner thunks, and a result of the unrolling of their handling in cl/8012. The correct way to handle this is probably to contract that handling again, and make sure that all thunk representations are left in a valid state when exiting the thunk side of the trampoline.

    This naive implementation passes most tests, but isn't completely done yet:

    ThunkRepr::Evaluated(val) => {
        // Restore this thunk's outer representation.
        self.0.replace(ThunkRepr::Evaluated(val.clone()));
    
        return Ok(Trampoline {
            action: None,
            continuation: Some(Box::new(move |vm: &mut VM| {
                Thunk::force_trampoline(vm, val)
                    .map_err(|kind| Error::new(kind, todo!("BUG: [b/238](https://b.tvl.fyi/238)")))
            })),
        })
    }
    

    I'll continue with this tomorrow, it's almost midnight and time to sleep.

    tazjin at 2023-02-07T20·55+00

  4. Fixed in cl/8104, although that will take some time to land.

    tazjin at 2023-02-26T13·54+00

  5. tazjin closed this issue at 2023-03-14T09·18+00