Hello,
While working on an assignment I noticed the Haskell Language Sever for VS Code does not always compile when programming with certain Clash code. Is there a way to make my HLS fully clash-compatible, or is there an existing language server implementation? If not, are there plans to release an official clash language server?
In my experience the Haskell Language Server is rather unstable. As far as I know, written Clash code is no different from normal Haskell code and should not interfere more with HLS than comparable Haskell.
Are there any specific problems you are running in to?
HLS is quite unstable but you can get it to compile if you for example comment then uncomment out a line, but in our case there is a specific error that consistently prevents the interpreter from checking other code. Here is a snippet:
instance forall a n . (BitPack a, BitPack n,
KnownNat (BitSize a), KnownNat (BitSize n))
=> BitPack (Axi4Stream a n) where
type BitSize (Axi4Stream a n) = BitSize a + BitSize n + 1
– Create a BitVector
pack (Axi4Stream { tData = tdata, tLast = tlast, tKeep = tkeep}) =
pack tkeep ++# pack tlast ++# pack tdata
unpack bv =
let (axis, tdata) = BV.split# @(BitSize a) bv
(tkeep, tlast) = BV.split# @1 axis
in (Axi4Stream {
tData = unpack tdata,
tLast = unpack tlast,
tKeep = unpack tkeep})
This is the error we run into:
1 of 8] Compiling Axi
clash\Axi.hs:44:35: error: parse error on input `@’
|
44 | let (axis, tdata) = BV.split# @(BitSize a) bv
I see you are using internal MagicHash function with Visible Type Applications. It could be that HLS can not handle that combination.
Does your code compile and could you post a snippet containing the relevant types?
Here is the clashi output. It compiles, albeit with some warnings:
when making flags consistent: warning:
Optimization flags conflict with --interactive; optimization flags ignored.
Clashi, version 1.8.1 (using clash-lib, version 1.8.1):
https://clash-lang.org/ :? for help
[1 of 1] Compiling Axi ( Axi.hs, interpreted )
Axi.hs:22:10: warning: [-Wmissing-methods]
* No explicit implementation for
liftTyped' * In the instance declaration for
Lift (Axi4Stream a n)’
|
22 | instance (Lift a, Lift n) => Lift (Axi4Stream a n) where
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Axi.hs:26:10: warning: [-Wmissing-methods]
* No explicit implementation for
abs',
signum’, and fromInteger' * In the instance declaration for
Num (Axi4Stream a n)’
|
26 | instance (Num a, Num n) => Num (Axi4Stream a n) where
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ok, one module loaded.
and :t Axi4Stream:
Axi4Stream :: a → Bool → n → Axi4Stream a n
Could you try adding:
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE MagicHash #-}
To the top of your file that throws the error?
edit: Fixed typo
Pasting that as is did not seem to fix it, but I changed the {-'s to {-# and it seems to have fixed it!
Seems HLS wasn’t the problem, was just my lack of using these packages. Thank you for the help!
1 Like
I adjusted my comment to properly reflect the solution.
They are not packages though, they are language extensions. Useful Haskell features which are not part of the official specification.
The problem is caused by clashi
having these extensions enabled, but HLS does not have them enabled by default, which is why you have to add them to the top of your module.
There are many more extensions/options that clash enables by default that depending on your code you might have to make HLS aware of.
When you get to a bigger project with more then one .hs file, it might be helpful to use a project setup with a .cabal file that sets all these options for you in one place.
You could use the clash-lang/simple template for a starting point for such a setup.
Although that it doesn’t enable MagicHash, so you’ll have to add that one.
2 Likes