ParsleyHaskell icon indicating copy to clipboard operation
ParsleyHaskell copied to clipboard

Unable to compile Bisons/Flex benchmarks

Open ju1m opened this issue 4 years ago • 8 comments

Looks like C files listed in: https://github.com/J-mie6/ParsleyHaskell/blob/a20a8a6ad1c266b4eb3e5f3c3cb72be3daf1e6de/parsley.cabal#L51 are missing or voluntarily not committed in the git repository. I thus naïvely tried to generate them manually like so:

cd benchmarks/Bisons/
flex Nandlang.l
bison -d Nandlang.y # -d also generates Nandlang.tab.h

However, when compiling benchmarks I hit this error:

$ nix -L run .#benchmarks
[…]
  ghc: panic! (the 'impossible' happened)
    (GHC version 8.6.5 for x86_64-unknown-linux):
        Loading temp shared object failed: /build/ghc396_0/libghc_5.so: undefined symbol: yylex

Should I add some pkgconfig-depends: or extra-libraries: because some C lib is missing? Or is it related to https://github.com/haskell/cabal/issues/5623 ? But then how could it have ever worked? Anyway, everything works as expected after removing this problematic benchmark: https://github.com/J-mie6/ParsleyHaskell/blob/a20a8a6ad1c266b4eb3e5f3c3cb72be3daf1e6de/benchmarks/Benchmarks.hs#L189

Thanks for this amazing library.

My current hacky flake.nix to reproduce if need be:

{
# Update inputs with:
# nix flake update --recreate-lock-file
inputs.flake-utils.url = "github:numtide/flake-utils";
inputs.haskell-nix.url = "github:input-output-hk/haskell.nix";
inputs.all-hies.url = "github:infinisil/all-hies";
inputs.all-hies.flake = false;
outputs = inputs: let
  projectName = "parsley";
  in inputs.flake-utils.lib.eachDefaultSystem (system: let
    #pkgs = inputs.haskell-nix.legacyPackages.${system};
    pkgs = import inputs.haskell-nix.sources.nixpkgs (inputs.haskell-nix.nixpkgsArgs // {
      localSystem = { inherit system; };
      overlays = inputs.haskell-nix.nixpkgsArgs.overlays ++ [
        (import inputs.all-hies {}).overlay
        (self: super: {
          fl = self.flex;
        })
      ];
    });
    compiler-nix-name = "ghc865";
    project = pkgs.haskell-nix.cabalProject {
      src = pkgs.haskell-nix.haskellLib.cleanGit {
        name = projectName;
        src = ./.;
      };
      inherit compiler-nix-name;
      index-state = "2020-08-28T00:00:00Z";
      # To be kept up to date with source-repository-package entries in cabal.project
      sha256map = {
        "https://github.com/J-mie6/lift-plugin.git"."e7bf0b4ee361a17c55170ce234a5542544625991" =
          "kLw6EjBApspjMs9kC+2Jl9sIgTnM/wfO+iADElpTfa0=";
        "https://github.com/J-mie6/idioms-plugins.git"."1ca37d047d5c8568bee6caf5a506995cd53265f5" =
          "PoBllnC7Q2S+cKriqjGR58QsA0GvrZ8R8h7GWHsZyxc=";
      };
      # Update by commenting materialized and running:
      # nix run .#materialize
      #materialized = ./plan-nix;
    };
    in {
    # Build with: nix build
    defaultPackage = project.${projectName}.components.exes."playground";
    #packages.${projectName} = project;
    # Run with: nix run .#benchmarks -- --output=benchmarks.html
    apps."benchmarks" = {
      type = "app";
      program = "${project.${projectName}.components.exes."benchmarks"}/bin/benchmarks";
    };
    # Run with: nix run .#playground
    apps."playground" = {
      type = "app";
      program = "${inputs.self.defaultPackage.${system}}/bin/playground";
    };
    # Run with: nix run .#materialize
    apps.materialize = {
      type = "app";
      program = (pkgs.writeShellScript "materialize" ''
        ${pkgs.rsync}/bin/rsync --delete -ai ${project.plan-nix}/ plan-nix/
      '').outPath;
    };
    # Run with: nix run .#register
    apps.register = {
      type = "app";
      program = (pkgs.writeShellScript "register" ''
        set -x
        nix-store --add-root nix.root --indirect --realise ${project.roots}
      '').outPath;
    };
    # Get a development environment with: nix develop
    devShell = project.shellFor {
      packages = hpkgs: [
        hpkgs."${projectName}"
      ];
      #components = hpkgs: [];
      #additional = hpkgs: [];
      withHoogle = false;
      tools = {
        cabal = "3.2.0.0";
        #hie = "unstable";
        #hlint = "2.2.11";
      };
      builtInputs = with project.haskellPackages; [
      ];
      exactDeps = true;
      shellHook = ''
      '';
    };
    }
  );
}

ju1m avatar Sep 02 '20 06:09 ju1m

Yeah, they are voluntarily left out, because I consider it bad form to keep them in the repo when they are essentially "precompiled" files. I've forgotten the exact commands I used to generate my lex.yy.c, Nandlang.tab.c and Nandlang.tab.h files, but I can find that out for you later. I'm not sure if a c lib is missing for you or not I'm afraid. It's a shame I couldn't figure out how to make cabal generate them for me!

j-mie6 avatar Sep 02 '20 14:09 j-mie6

Is there a solution already? I get the following error after generating the c and h files with bison and lex:

ghc: panic! (the 'impossible' happened)
  (GHC version 8.6.5 for x86_64-unknown-linux):
	Loading temp shared object failed: /run/user/29829/ghc19759_0/libghc_1.so: undefined symbol: set_input_string

knothed avatar Nov 12 '21 14:11 knothed

I don't know what would cause that: I would just recommend disabling the nandlang benchmarks in the cabal file.

j-mie6 avatar Nov 13 '21 16:11 j-mie6

(Also as an aside, I would recommend upgrading to 8.10+ when running benchmarks, the Parsley backend for 8.10+ has way more in the way of optimisations and general optimisation stability compared with 8.8-)

j-mie6 avatar Nov 13 '21 16:11 j-mie6

Okay I’ll try upgrading GHC. But I would actually like to run the Nandland benchmarks, so disabling them is not an option for me :D

knothed avatar Nov 13 '21 19:11 knothed

very well, try the prebuilt-bison branch: I've added my pregenerated bison binaries there.

j-mie6 avatar Nov 13 '21 20:11 j-mie6

Thank you! It still doesn't seem to work with GHC 8.6.5... I'll need to upgrade then probably.

knothed avatar Nov 17 '21 14:11 knothed

that's strange, it works for 8.6.5 for me (with those generated files)! It looks like set_input_string is included in lex.yy.c, and is needed by Nandlang.tab.c. Perhaps you need to update your cabal as well, which might not be linking the files properly?

j-mie6 avatar Nov 17 '21 14:11 j-mie6