    {-|
    Copyright  :  (C) 2015-2016, University of Twente
                      2022     , QBayLogic B.V.
    License    :  BSD2 (see the file LICENSE)
    Maintainer :  QBayLogic B.V. <devops@qbaylogic.com>
    -}

    {-# LANGUAGE CPP #-}
    {-# LANGUAGE Unsafe #-}

    module Clash.Promoted.Nat.Unsafe
      (unsafeSNat)
    where

    import Data.Reflection    (reifyNat)
    import Unsafe.Coerce      (unsafeCoerce)

    import Clash.Annotations.Primitive (hasBlackBox)
    import Clash.Promoted.Nat (SNat, snatProxy)

    -- | I hope you know what you're doing
    unsafeSNat :: Integer -> SNat k
    unsafeSNat :: forall (k :: Nat). Integer -> SNat k
    unsafeSNat Integer
    i = Integer
    -> (forall (n :: Nat). KnownNat n => Proxy n -> SNat k) -> SNat k
    forall r.
    Integer -> (forall (n :: Nat). KnownNat n => Proxy n -> r) -> r
    reifyNat Integer
    i ((forall (n :: Nat). KnownNat n => Proxy n -> SNat k) -> SNat k)
    -> (forall (n :: Nat). KnownNat n => Proxy n -> SNat k) -> SNat k
    forall a b. (a -> b) -> a -> b
    $ (\Proxy n
    p -> SNat n -> SNat k
    forall a b. a -> b
    unsafeCoerce (Proxy n -> SNat n
    forall (n :: Nat) (proxy :: Nat -> Type).
    KnownNat n =>
    proxy n -> SNat n
    snatProxy Proxy n
    p))
    -- See: https://github.com/clash-lang/clash-compiler/pull/2511
    {-# CLASH_OPAQUE unsafeSNat #-}
    {-# ANN unsafeSNat hasBlackBox #-}