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

iterate cannot be used to describe a reset value #1240

Open
christiaanb opened this issue Mar 20, 2020 · 2 comments
Open

iterate cannot be used to describe a reset value #1240

christiaanb opened this issue Mar 20, 2020 · 2 comments
Labels

Comments

@christiaanb
Copy link
Member

The following fails to compile:

module Test where

import Clash.Prelude

topEntity = register @System (iterate d1 not True)

giving the following error:

Test.hs:5:1: error:

    Clash.Netlist.BlackBox(188): Couldn't instantiate blackbox for Clash.Signal.Internal.register#. Verification procedure reported:

    Argument 5 should be literal, as blackbox used ~CONST[5], but was:

    Identifier "xs" Nothing

    The source location of the error is not exact, only indicative, as it is acquired
    after optimizations. The actual location of the error can be in a function that is
    inlined. To prevent inlining of those functions, annotate them with a NOINLINE pragma.
  |
5 | topEntity = register @System (iterate d1 not True)
  | ^^^^^^^^^

looking at the debug output we see:

  xs[8286623314361788996] :: Clash.Sized.Vector.Vec[8214565720323789569]
                               1
                               GHC.Types.Bool[3674937295934324744]
  = Clash.Sized.Vector.init @1
      @GHC.Types.Bool[3674937295934324744]
      (Clash.Sized.Vector.Cons[8214565720323789572]
         @(GHC.TypeNats.+[3674937295934325068] 1 1)
         @GHC.Types.Bool[3674937295934324744]
         @1
         (_CO_
            @(GHC.Prim.~#[3674937295934324842]
                GHC.Types.Nat[3674937295934325064]
                GHC.Types.Nat[3674937295934325064]
                (GHC.TypeNats.+[3674937295934325068] 1 1)
                (GHC.TypeNats.+[3674937295934325068] 1 1)))
         GHC.Types.True[3891110078048108589]
         (Clash.Sized.Vector.Cons[8214565720323789572] @1
            @GHC.Types.Bool[3674937295934324744]
            @0
            _CO_
            (GHC.Classes.not
               (Clash.Sized.Vector.head @0
                  @GHC.Types.Bool[3674937295934324744]
                  xs[8286623314361788996][LocalId]))
            (Clash.Sized.Vector.Nil[8214565720323789573] @0
               @GHC.Types.Bool[3674937295934324744]
               _CO_)))

i.e.

let xs = init (Cons True (Cons (not (head xs)) Nil))

which is semantically a constant, because the second element of the list is never used, but not syntactically; and so Clash doesn't want to inline it.

@christiaanb
Copy link
Member Author

A work-around is to use TemplateHaskell:

module Test where

import Clash.Prelude

topEntity = register @System $(lift (iterate d1 not True))

christiaanb added a commit that referenced this issue Mar 20, 2020
But use `GHC.Magic.inline` to make sure it doesn't want to
share the value for powerup and reset.

Fixes #1240
martijnbastiaan added a commit that referenced this issue May 28, 2020
martijnbastiaan added a commit that referenced this issue May 28, 2020
martijnbastiaan added a commit that referenced this issue May 28, 2020
martijnbastiaan added a commit that referenced this issue May 28, 2020
martijnbastiaan added a commit that referenced this issue May 28, 2020
martijnbastiaan added a commit that referenced this issue Jun 2, 2020
martijnbastiaan added a commit that referenced this issue Jun 3, 2020
martijnbastiaan added a commit that referenced this issue Jun 4, 2020
martijnbastiaan added a commit that referenced this issue Jun 11, 2020
martijnbastiaan added a commit that referenced this issue Jun 11, 2020
@martijnbastiaan
Copy link
Member

PR #1240 is reverted in 1.2, but should also be reverted in master, reopening this issue.

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

Successfully merging a pull request may close this issue.

2 participants