haskell / haskell-language-server

Official haskell ide support via language server (LSP). Successor of ghcide & haskell-ide-engine.
Apache License 2.0
2.65k stars 355 forks source link

Evaluating `TemplateHaskell` #2946

Open ndzik opened 2 years ago

ndzik commented 2 years ago

Example project

So I created a minimal project showcasing the problem here.

Versions

hie-bios version 0.8.1 compiled by GHC 8.10.7 Project also compiles with GHC 8.10.7 In case of relevance also the version for HLS: haskell-language-server version: 1.7.0.0 (GHC: 8.10.7)

Problem

I am playing around a bit with plutus and write some smart contracts. I was able to get HLS to work with my project up to a point were I am only left with a seemingly false negative related to the evaluation of TemplateHaskell code as far as I can tell.

I do not know if this might be a general problem with template haskell evaluation and quasiquotation or if it is just me missing some dependency for hie-bios to work.

Some more information can be found in my example project.

Surprisingly HLS still is able to type everything correctly, it just keeps complaining where the plutus code is generated:

hie-bios: GHC Core to PLC plugin: E043:Error: Reference to a name which is not a local, a builtin, or an external INLINABLE function: Variable Ledger.Typed.Scripts.Validators.wrapValidator
            No unfolding
Context: Compiling expr: Ledger.Typed.Scripts.Validators.wrapValidator
Context: Compiling expr: Ledger.Typed.Scripts.Validators.wrapValidator
                           @ MyLib.ExampleInput
Context: Compiling expr: Ledger.Typed.Scripts.Validators.wrapValidator
                           @ MyLib.ExampleInput @ MyLib.ExampleInput
Context: Compiling expr: Ledger.Typed.Scripts.Validators.wrapValidator
                           @ MyLib.ExampleInput
                           @ MyLib.ExampleInput
                           MyLib.$fUnsafeFromDataExampleInput
Context: Compiling expr: Ledger.Typed.Scripts.Validators.wrapValidator
                           @ MyLib.ExampleInput
                           @ MyLib.ExampleInput
                           MyLib.$fUnsafeFromDataExampleInput
                           MyLib.$fUnsafeFromDataExampleInput
Context: Compiling expr at "minex-0.1.0.0-inplace:MyLib:(36,8)-(36,35)"

Maybe someone here can point me in the right direction (:

Thanks for your time, kind reader.

fendor commented 2 years ago

For clarification, this error only happens with hie-bios? E.g. hie-bios check <some-file>? If so, the session loading logic of hie-bios is rudimentary and might fail in the face of Template Haskell. HLS is much more advanced when it comes to TH support, so it seems possible that hie-bios just has a bug.

ndzik commented 2 years ago

Yes the error happens using hie-bios check lib:minex, in case of the example project. I originally encountered the error in HLS and after looking through the documentation and testing around a little bit I came to the point where I realized it might be related to hie-bios.

fendor commented 2 years ago

If the error is encountered in HLS, that is likely to be unrelated to hie-bios since HLS uses its own logic, completely disjoint to hie-bios check. That both have the same error is rather an accident in this case.

So, this error needs to be raised with the HLS team, since I think it is unlikely to be caused by hie-bios directly.

I can move the issue if you agree with this course of action?

hasufell commented 2 years ago

@michaelpj

ndzik commented 2 years ago

I am fine with moving this issue if your assessment is that fixing something here would not help with HLS's error. But the call is on you (: