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

signalAutomaton gets shared, to disastrous results #2801

Open
gergoerdi opened this issue Aug 27, 2024 · 1 comment
Open

signalAutomaton gets shared, to disastrous results #2801

gergoerdi opened this issue Aug 27, 2024 · 1 comment

Comments

@gergoerdi
Copy link
Contributor

gergoerdi commented Aug 27, 2024

The below program runs fine in GHCi, but when compiled and run, fails after the first invocation of sim:

module Main where

import Clash.Prelude
import Control.Arrow.Transformer.Automaton

circuit :: (HiddenClockResetEnable dom) => Signal dom Int -> Signal dom Int
circuit x = register 0 x

sim :: Int -> Int
sim x = start (signalAutomaton @System circuit) x
  where
    start (Automaton step) x = load sim x
      where
        (_, sim) = step 0

    load (Automaton step) x = consume sim
      where
        (_, sim) = step x

    consume (Automaton step) = output
      where
        (output, sim) = step 0

main :: IO ()
main = do
    print $ sim 1
    print $ sim 3
1
bug: user error (signalAutomaton: non-affine use of continuation)
@gergoerdi
Copy link
Contributor Author

On Slack's #Clash, @christiaanb recommended trying -O0 which indeed is an effective workaround, however, I'm worried what its effect on simulation performance is.

I have also tried adding {-# OPAQUE sim #-} as per his recommendation but that does not fix the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant