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

imperative statement (not BVI context) on PreludeBSV.bo #20

Closed
picnoir opened this issue Feb 6, 2020 · 4 comments
Closed

imperative statement (not BVI context) on PreludeBSV.bo #20

picnoir opened this issue Feb 6, 2020 · 4 comments

Comments

@picnoir
Copy link

picnoir commented Feb 6, 2020

I'm getting a bsc

imperative statement (not BVI context)make[3]: *** [Makefile:25: /build/source/build/bsvlib/PreludeBSV.bo] Error 1

error when building 11f9a729fe5bb301f0899d3497e79e004a047e37 patched with https://patch-diff.githubusercontent.com/raw/B-Lang-org/bsc/pull/18.patch on NixOS

Full Log

/build/source/inst/bin/bsc -stdlib-names -bdir /build/source/build/bsvlib -p . -vsearch /build/source/build/bsvlib -no-use-prelude Prelude.bs
Warning: "Prelude.bs", line 975, column 19: (P0223)
  Definition of `a' is not used.
Warning: "Prelude.bs", line 1026, column 35: (P0102)
  Declaration of `x' shadows previous declaration at "Prelude.bs", line 1022,
  column 8
Warning: "Prelude.bs", line 1026, column 37: (P0223)
  Definition of `xs' is not used.
Warning: "Prelude.bs", line 1033, column 24: (P0102)
  Declaration of `x' shadows previous declaration at "Prelude.bs", line 1031,
  column 14
Warning: "Prelude.bs", line 1051, column 11: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 1153, column 6: (P0223)
  Definition of `n' is not used.
Warning: "Prelude.bs", line 1168, column 5: (P0223)
  Definition of `f' is not used.
Warning: "Prelude.bs", line 1179, column 9: (P0223)
  Definition of `n' is not used.
Warning: "Prelude.bs", line 1266, column 19: (P0223)
  Definition of `a' is not used.
Warning: "Prelude.bs", line 1266, column 21: (P0223)
  Definition of `i' is not used.
Warning: "Prelude.bs", line 1357, column 19: (P0223)
  Definition of `a' is not used.
Warning: "Prelude.bs", line 1357, column 21: (P0223)
  Definition of `i' is not used.
Warning: "Prelude.bs", line 1378, column 8: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 1378, column 10: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 1489, column 19: (P0223)
  Definition of `a' is not used.
Warning: "Prelude.bs", line 1532, column 7: (P0223)
  Definition of `s_d' is not used.
Warning: "Prelude.bs", line 1604, column 30: (P0102)
  Declaration of `x' shadows previous declaration at "Prelude.bs", line 1602,
  column 19
Warning: "Prelude.bs", line 1637, column 19: (P0223)
  Definition of `a' is not used.
Warning: "Prelude.bs", line 1657, column 11: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 1694, column 31: (P0102)
  Declaration of `x' shadows previous declaration at "Prelude.bs", line 1692,
  column 20
Warning: "Prelude.bs", line 1820, column 15: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 1855, column 15: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 1868, column 15: (P0102)
  Declaration of `x' shadows previous declaration at "Prelude.bs", line 1862,
  column 6
Warning: "Prelude.bs", line 1891, column 15: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 1904, column 15: (P0102)
  Declaration of `x' shadows previous declaration at "Prelude.bs", line 1898,
  column 6
Warning: "Prelude.bs", line 2058, column 8: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2058, column 10: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 2059, column 11: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2060, column 8: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2060, column 10: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 2061, column 8: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2061, column 10: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 2062, column 8: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2062, column 10: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 2075, column 16: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2076, column 19: (P0223)
  Definition of `a' is not used.
Warning: "Prelude.bs", line 2076, column 21: (P0223)
  Definition of `i' is not used.
Warning: "Prelude.bs", line 2275, column 8: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2275, column 10: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 2276, column 11: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2277, column 8: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2277, column 10: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 2278, column 8: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2278, column 10: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 2279, column 8: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2279, column 10: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 2292, column 16: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 2293, column 19: (P0223)
  Definition of `a' is not used.
Warning: "Prelude.bs", line 2293, column 21: (P0223)
  Definition of `i' is not used.
Warning: "Prelude.bs", line 2659, column 16: (P0223)
  Definition of `p' is not used.
Warning: "Prelude.bs", line 3154, column 16: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 3169, column 9: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 3169, column 11: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 3170, column 9: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 3170, column 11: (P0223)
  Definition of `y' is not used.
Warning: "Prelude.bs", line 3171, column 9: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 3172, column 9: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 3407, column 17: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 3411, column 22: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 3411, column 24: (P0223)
  Definition of `xs' is not used.
Warning: "Prelude.bs", line 3425, column 18: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 3439, column 32: (P0102)
  Declaration of `xs' shadows previous declaration at "Prelude.bs", line 3431,
  column 21
Warning: "Prelude.bs", line 3439, column 32: (P0223)
  Definition of `xs' is not used.
Warning: "Prelude.bs", line 3440, column 30: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 3440, column 32: (P0102)
  Declaration of `xs' shadows previous declaration at "Prelude.bs", line 3431,
  column 21
Warning: "Prelude.bs", line 3440, column 36: (P0102)
  Declaration of `n' shadows previous declaration at "Prelude.bs", line 3431,
  column 24
Warning: "Prelude.bs", line 3445, column 37: (P0223)
  Definition of `n' is not used.
Warning: "Prelude.bs", line 3460, column 21: (P0223)
  Definition of `x' is not used.
Warning: "Prelude.bs", line 3487, column 12: (P0223)
  Definition of `f' is not used.
Warning: "Prelude.bs", line 3491, column 14: (P0223)
  Definition of `f' is not used.
Warning: "Prelude.bs", line 3495, column 14: (P0223)
  Definition of `f' is not used.
Warning: "Prelude.bs", line 3580, column 30: (P0102)
  Declaration of `v1' shadows previous declaration at "Prelude.bs", line 3579,
  column 9
Warning: "Prelude.bs", line 3580, column 33: (P0102)
  Declaration of `v2' shadows previous declaration at "Prelude.bs", line 3579,
  column 12
Warning: "Prelude.bs", line 3607, column 19: (P0223)
  Definition of `k' is not used.
Warning: "Prelude.bs", line 3658, column 34: (P0223)
  Definition of `t' is not used.
Warning: "Prelude.bs", line 3711, column 34: (P0223)
  Definition of `a' is not used.
Warning: "Prelude.bs", line 3714, column 21: (P0223)
  Definition of `pos' is not used.
Warning: "Prelude.bs", line 3714, column 25: (P0223)
  Definition of `kind' is not used.
Warning: "Prelude.bs", line 3735, column 25: (P0223)
  Definition of `kind' is not used.
Warning: "Prelude.bs", line 3738, column 25: (P0223)
  Definition of `kind' is not used.
Warning: "Prelude.bs", line 3741, column 25: (P0223)
  Definition of `kind' is not used.
Warning: "Prelude.bs", line 3744, column 25: (P0223)
  Definition of `kind' is not used.
Warning: "Prelude.bs", line 3747, column 25: (P0223)
  Definition of `kind' is not used.
Warning: "Prelude.bs", line 3750, column 25: (P0223)
  Definition of `kind' is not used.
Warning: "Prelude.bs", line 3980, column 8: (P0223)
  Definition of `value' is not used.
/build/source/inst/bin/bsc -stdlib-names -bdir /build/source/build/bsvlib -p . -vsearch /build/source/build/bsvlib -no-use-prelude PreludeBSV.bsv
imperative statement (not BVI context)make[3]: *** [Makefile:25: /build/source/build/bsvlib/PreludeBSV.bo] Error 1
make[3]: Leaving directory '/build/source/src/Libraries/Base1'
make[2]: *** [Makefile:31: build] Error 2
make[2]: Leaving directory '/build/source/src/Libraries'
make[1]: *** [Makefile:16: install] Error 2
make[1]: Leaving directory '/build/source/src'
make: *** [Makefile:24: install] Error 2
builder for '/nix/store/j5m5qb4ibc7c989iq4bsmaqha7slkijq-bsc-unstable-2020.02.05.drv' failed with exit code 2
error: build of '/nix/store/j5m5qb4ibc7c989iq4bsmaqha7slkijq-bsc-unstable-2020.02.05.drv' failed

Reproduction

  1. Install nix ( https://nixos.org/nix/ )
  2. Fetch https://github.com/NinjaTrappeur/nixpkgs/tree/bluespec-bsc
  3. Run nix-build -A bluespec-bsc
@picnoir picnoir changed the title /build/source/inst/bin/bsc -stdlib-names -bdir /build/source/build/bsvlib -p . -vsearch /build/source/build/bsvlib -no-use-prelude PreludeBSV.bsv /build/source/inst/bin/bsc -stdlib-names -bdir /build/source/build/bsvlib -p . -vsearch /build/source/build/bsvlib -no-use-prelude PreludeBSV.bsv is failing Feb 6, 2020
@picnoir picnoir changed the title /build/source/inst/bin/bsc -stdlib-names -bdir /build/source/build/bsvlib -p . -vsearch /build/source/build/bsvlib -no-use-prelude PreludeBSV.bsv is failing imperative statement (not BVI context) on PreludeBSV.bo Feb 6, 2020
@flokli
Copy link
Contributor

flokli commented Feb 6, 2020

FYI, I managed to get past that failure with GCC 7.5.0 and GHC 8.0.2 and pushed my current WIP to my bluespec-bsc nixpkgs branch.

Note GHC 8.0.2 is way out of support, see #16 (comment)

Whoever is interested, I joined the #bluespec channel on freenode.

@flokli
Copy link
Contributor

flokli commented Feb 8, 2020

I'm able to trigger this with GHC 8.6.5 as well, with 8.4.4 it seemed to still work.

@dramforever
Copy link
Contributor

dramforever commented Feb 9, 2020

This is untested but I think I have found the issue. The culprit is here:

instance Monad (GenParser tok st) where
return x = parsecReturn x
p >>= f = parsecBind p f
#if !defined(__GLASGOW_HASKELL__) || (__GLASGOW_HASKELL__ < 806)
fail msg = parsecFail msg
#endif
#if !defined(__GLASGOW_HASKELL__) || (__GLASGOW_HASKELL__ >= 800)
instance MonadFail (GenParser tok st) where
fail msg = parsecFail msg
#endif

Which seems to be have been written intending to take care of the transitioning regarding MonadFail. However, fail of the Monad class is still (basically) error (see source); it's just no longer used when desugaring do. Which means that given GHC >= 8.6, a call to fail will not trigger a backtrack and instead will crash the whole program with the message, which seems to be happening here:

> when (stmtContext flags /= ISCBVI) (fail "imperative statement (not BVI context)")


(Edit: took out large parts of this comment because apparently I found outdated information)

grepping for the #if, I see three Monads affected by this:

  • src/Parsec/ParsecPrim.hs:242
  • src/comp/ErrorMonad.hs:28
  • src/comp/SEMonad.hs:23

These instances should be written like shown in this migration guide instead: https://gitlab.haskell.org/ghc/ghc/wikis/proposal/monad-fail#adapting-old-code

After I test everything I can write a pull request.

@quark17
Copy link
Collaborator

quark17 commented Feb 9, 2020

Ah, thank you! This makes sense. I added these conditionals recently, and tested that it compiled on various 8.x versions, but I didn't have working installations so I hadn't tested that it ran properly. (Both Debian10 and MacPorts on Catalina have issues with GHC that I hadn't gotten past.) I've installed GHC 8.6.5 on Ubuntu 16.04 (xenial) and confirmed that the repo builds and checks, so I'll commit these changes. Thanks!

@quark17 quark17 closed this as completed in 7b3538c Feb 9, 2020
quark17 added a commit that referenced this issue Feb 9, 2020
Fix Monad instances affected by MonadFail, fix #20
ncihnegn pushed a commit to ncihnegn/bsc that referenced this issue Mar 4, 2020
Extend the #if around fail in Monad to include 8.6 (< 806 -> < 808).
This way, everyone is happy:

- For 8.6 or earlier, Prelude.fail is Monad.fail, which goes to the
  custom function (8.6 would get errorWithoutStackTrace otherwise)
- For 8.8 or later, Prelude.fail is MonadFail.fail, which also goes to
  the custom function.
- Also, there is no fail in Monad in 8.8+, so the #if removes it.
ncihnegn pushed a commit to ncihnegn/bsc that referenced this issue Mar 4, 2020
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

4 participants