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

Add a "dhall parse-tree" command for debugging purposes #1553

Merged
merged 3 commits into from
Nov 22, 2019

Conversation

sjakobi
Copy link
Collaborator

@sjakobi sjakobi commented Nov 17, 2019

Sample output:

$ echo 'toMap {=} : a ? b' | dhall parse-tree
ToMap 
    ( RecordLit ( fromList [] ) ) 
    ( Just 
        ( ImportAlt 
            ( Var ( V "a" 0 ) ) 
            ( Var ( V "b" 0 ) )
        )
    )
$ echo "http://a?/" | dhall parse-tree
Embed 
    ( Import 
        { importHashed = ImportHashed 
            { hash = Nothing
            , importType = Remote 
                ( URL 
                    { scheme = HTTP
                    , authority = "a" 
                    , path = File 
                        { directory = Directory { components = [] }
                        , file = "" 
                        } 
                    , query = Just "/" 
                    , headers = Nothing
                    } 
                )
            } 
        , importMode = Code
        } 
    )

@Gabriella439
Copy link
Collaborator

Gabriella439 commented Nov 17, 2019

I'm a little bit reluctant to do this because the internal AST is highly volatile and verbose (especially if we start adding Maybe Src fields for preserving comments). I don't want end users to depend too much on it from the command line.

Also, remember that the CBOR representation already plays the role of a language-independent AST and dhall encode --json lets you debug that:

$ dhall encode --json <<< 'toMap {=} : a ? b'
[
    27,
    [
        8,
        {}
    ],
    [
        3,
        11,
        [
            "a",
            0
        ],
        [
            "b",
            0
        ]
    ]
]
$ dhall encode --json <<< 'http://a?/'
[
    24,
    null,
    0,
    0,
    null,
    "a",
    "",
    "/"
]

@sjakobi
Copy link
Collaborator Author

sjakobi commented Nov 17, 2019

Personally I don't find the output of dhall encode --json very easy to understand.

Regarding your compatibility concerns – the usage info already says "for debugging":

Output the parsed syntax tree (for debugging)

Would it help if I add "output may change at any time" or something like that?

@sjakobi sjakobi force-pushed the sjakobi/parse-tree branch 3 times, most recently from 371bf79 to 6767ab3 Compare November 17, 2019 04:18
@sjakobi
Copy link
Collaborator Author

sjakobi commented Nov 17, 2019

I wonder why Hydra complains about a missing aeson dependency when the executable with the aeson dependency is configured to be unbuildable (with -f-buildexample):

setupCompileFlags: -package-db=/tmp/nix-build-pretty-simple-3.1.0.0.drv-0/setup-package.conf.d -j4 -threaded
[1 of 1] Compiling Main             ( Setup.hs, /tmp/nix-build-pretty-simple-3.1.0.0.drv-0/Main.o )
Linking Setup ...
configuring
configureFlags: --verbose --prefix=/nix/store/3s0hq9wnjhyzwq31jf68fbp2imfpxrw4-pretty-simple-3.1.0.0 --libdir=$prefix/lib/$compiler --libsubdir=$pkgid --docdir=/nix/store/5s3zghpy8qdyqhxys23h8j779mlxn707-pretty-simple-3.1.0.0-doc/share/doc/pretty-simple-3.1.0.0 --with-gcc=gcc --package-db=/tmp/nix-build-pretty-simple-3.1.0.0.drv-0/package.conf.d --enable-split-objs --enable-library-profiling --disable-executable-profiling --enable-shared --disable-coverage --disable-executable-dynamic --disable-tests --enable-library-vanilla --enable-library-for-ghci -f-buildexample -f-buildexe --extra-lib-dirs=/nix/store/w8bxy3xrvrd1ci5772y7arkicj0q7x3h-ncurses-6.1/lib --extra-lib-dirs=/nix/store/d60s5bwv6r3hl6w8cg5j7znwaiva43n8-gmp-6.1.2/lib
Warning: pretty-simple.cabal: Ignoring unknown section type: custom-setup
Configuring pretty-simple-3.1.0.0...
Setup: At least the following dependencies are missing:
aeson -any, optparse-applicative -any
builder for '/nix/store/syia6wg6dk64mkxgppbqb6yqm9l8bv8g-pretty-simple-3.1.0.0.drv' failed with exit code 1

@Gabriella439
Copy link
Collaborator

@sjakobi: Would it be possible to hide the parse-tree subcommand from the --help output? The reason I ask is that I don't want to publicize Haskell-specific features for a utility which is designed to be language-agnostic

I also think the subcommand should have Haskell in the name, since it is language-specific (e.g. haskell-tree)

@Gabriella439
Copy link
Collaborator

@sjakobi: That seems like a cabal bug to me. However, it might be simpler to just let it build the sample executables

@sjakobi
Copy link
Collaborator Author

sjakobi commented Nov 18, 2019

Would it be possible to hide the parse-tree subcommand from the --help output?

I think hiding should be possible, but I haven't gotten it to work yet (see pcapriotti/optparse-applicative#365).

@sjakobi sjakobi changed the title Add a "dhall parse-tree" command for debugging purposes WIP: Add a "dhall parse-tree" command for debugging purposes Nov 18, 2019
@sjakobi
Copy link
Collaborator Author

sjakobi commented Nov 18, 2019

That seems like a cabal bug to me. However, it might be simpler to just let it build the sample executables

The error was already present when I didn't use the cabal flags: https://hydra.dhall-lang.org/build/45291/nixlog/3

Am I using cabal2nix incorrectly? It just doesn't seem to include the executable dependencies:

$ cabal2nix cabal://pretty-simple
{ mkDerivation, ansi-terminal, base, Cabal, cabal-doctest
, containers, criterion, doctest, Glob, mtl, QuickCheck, stdenv
, template-haskell, text, transformers
}:
mkDerivation {
  pname = "pretty-simple";
  version = "3.1.0.0";
  sha256 = "ea8a062fe7a535a0778ea0f85442551b9a67fad95979fc3e4c617399452c775c";
  isLibrary = true;
  isExecutable = true;
  setupHaskellDepends = [ base Cabal cabal-doctest ];
  libraryHaskellDepends = [
    ansi-terminal base containers mtl text transformers
  ];
  testHaskellDepends = [
    base doctest Glob QuickCheck template-haskell
  ];
  benchmarkHaskellDepends = [ base criterion text ];
  homepage = "https://github.com/cdepillabout/pretty-simple";
  description = "pretty printer for data types with a 'Show' instance";
  license = stdenv.lib.licenses.bsd3;
}

@Gabriella439
Copy link
Collaborator

@sjakobi: What version of cabal2nix are you using? I just tested and I'm getting the executable dependencies:

$ cabal2nix cabal://pretty-simple-3.1.0.0
{ mkDerivation, aeson, ansi-terminal, base, bytestring, Cabal
, cabal-doctest, containers, criterion, doctest, Glob, mtl
, optparse-applicative, QuickCheck, stdenv, template-haskell, text
, transformers
}:
mkDerivation {
  pname = "pretty-simple";
  version = "3.1.0.0";
  sha256 = "ea8a062fe7a535a0778ea0f85442551b9a67fad95979fc3e4c617399452c775c";
  isLibrary = true;
  isExecutable = true;
  setupHaskellDepends = [ base Cabal cabal-doctest ];
  libraryHaskellDepends = [
    ansi-terminal base containers mtl text transformers
  ];
  executableHaskellDepends = [
    aeson base bytestring optparse-applicative text
  ];
  testHaskellDepends = [
    base doctest Glob QuickCheck template-haskell
  ];
  benchmarkHaskellDepends = [ base criterion text ];
  homepage = "https://github.com/cdepillabout/pretty-simple";
  description = "pretty printer for data types with a 'Show' instance";
  license = stdenv.lib.licenses.bsd3;
}

@Gabriella439
Copy link
Collaborator

I forgot to mention that the version I'm using is:

$ cabal2nix --version
cabal2nix 2.8.1

@sjakobi
Copy link
Collaborator Author

sjakobi commented Nov 18, 2019

$ cabal2nix --version
cabal2nix 2.15.0

For other packages I'm still getting the executableHaskellDepends

I've made a bug report: NixOS/cabal2nix#436.

@sjakobi sjakobi changed the title WIP: Add a "dhall parse-tree" command for debugging purposes Add a "dhall parse-tree" command for debugging purposes Nov 20, 2019
Copy link
Collaborator

@Gabriella439 Gabriella439 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor suggestion

dhall/src/Dhall/Main.hs Outdated Show resolved Hide resolved
@mergify mergify bot merged commit feb378b into master Nov 22, 2019
@mergify mergify bot deleted the sjakobi/parse-tree branch November 22, 2019 03:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants