Commit Graph

32 Commits

Author SHA1 Message Date
Simon Jakobi
9d4fa51450 dhall type: Don't normalize inferred types (#1317)
Since some inferred types are in non-normal form, `dhall type`
would previously return types that weren't strictly
standard-conforming. This change prevents further confusion.

Closes #1300.
2019-09-14 23:31:12 +00:00
Gabriel Gonzalez
79bd32e4b9 Add --censor switch for disabling source code display (#1312)
* Add `--censor` switch for disabling source code display

Related to #1294

This currently only affects parse errors, but can later be extended
to type errors, too

* Fix type blindiness

... as requested by @sjakobi

* Replace `Bool` with `Censor`
* Replace `Maybe FilePath` with `Input`
2019-09-14 05:01:23 +00:00
Simon Jakobi
37f819c8bb
Add --no-cache flag (#1290)
When enabled, we handle protected imports as if the semantic cache was
empty:
  * Protected imports are resolved again, downloaded or read from
    the filesystem as necessary.
  * Protected imports are β-normalized, not αβ-normalized.
  * Protected imports are checked against their SHA256 hashes,
    failing to resolve if they don't match.

Context:
https://github.com/dhall-lang/dhall-haskell/pull/1275#issuecomment-528847192
2019-09-09 22:37:30 +02:00
Gabriel Gonzalez
8c8ea2a7ce Change dhall type to resolve imports (#1281)
* Change `dhall type` to resolve imports

Fixes https://github.com/dhall-lang/dhall-haskell/issues/1277

The original motivation was that `dhall type` would represent a
type-inference-only phase.  However, in practice that wasn't very useful
so `dhall type` now performs import resolution followed by type inference.

* Fix loading relative to root directory

... as caught by @sjakobi

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>
2019-09-05 16:12:55 +00:00
Gabriel Gonzalez
96921f03ab
Fix dhall format to preserve let comments (#1273)
Related to https://github.com/dhall-lang/dhall-haskell/issues/145

Note that this also refactors `Let` to use `Binding` in order
to avoid having to duplicate `Src`-related fields in two
places.
2019-09-04 23:41:44 -05:00
Gabriel Gonzalez
64b12f330f Improve description of dhall lint (#1264)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1252
2019-08-31 14:00:28 +00:00
Gabriel Gonzalez
0d266b91c5 Small fixes to dhall diff (#1263)
* Small fixes to `dhall diff`

Related to https://github.com/dhall-lang/dhall-haskell/issues/1255

* Simplify function type diffs by omitting the bound variable name when possible
* Non-zero exit code when `dhall diff` is non-empty

Note that this is a breaking change to the `Dhall.Diff` API by changing the
exposed utilities to all expose the more general `Diff` type instead of a
`Doc`.  This means that we also no longer need separate exports for
`diff` and `diffExpression`.

* Fix build failure for tests

* Fix golden test result

* Rename `diffExpression` to `diff`

... as suggested by @sjakobi

* Add test coverage for diffing function types
2019-08-31 13:18:46 +00:00
Simon Jakobi
1700fa72d8 Fix import logic with --file for dhall-to-{json,yaml} (#1191)
Fixes #1183.
2019-08-03 11:03:42 +00:00
Gabriel Gonzalez
a81c75fc5b Remove most uses of StandardVersion from the API (#1169)
* Remove most uses of `StandardVersion` from the API

We no longer support multiple versions of the standard, except for
supporting old integrity checks, so this change removes all inessential
uses of `StandardVersion` from the API and command-line interface.

* Fix `dhall-lsp-server` build
2019-07-31 01:49:53 +00:00
Gabriel Gonzalez
3f2c42014f
Simplify dhall version output to just version string (#1163)
The motivation for this is two-fold:

* To get rid of the standard version from the output

  Currently it's just "None", which could be fixed, but keeping it up to
  date is error-prone, so I prefer to just remove it.

* To make the output machine-readable

Example:

```
$ dhall version
1.24.0
```
2019-07-28 20:44:30 -07:00
Simon Jakobi
c8a0df3748 Specialize Expr's ToTerm instance to (Expr X a) (#1143)
* This simplifies pattern matching during encoding.
2019-07-21 15:17:41 +00:00
Frederik Ramcke
d5d0224bc3 Preparing Dhall.Import for "Semi-semantic" caching (#1113)
* Fix misleading comment

* Add `Chained` type to capture fully chained imports

Until now we used `Import` two mean two different things:
- The syntactic construct; e.g. `./a.dhall` corresponds to the following
  AST:
  ```
  Embed
    (Import
      (ImportHashed Nothing (Local Here (Directory ["."]) "a.dhall"))
      Code)
  ```

- The physical location the import is pointing to, computed by
'chaining' the syntactical import with the the 'physical' parent import.
For example the syntactic import `./a.dhall` might actually refer to the
remote file `http://host/directory/a.dhall`.

This commit adds a `Chained` newtype on top of `Import` to make this
distinction explicit at type level.

* Use `HTTPHeaders` alias for binary headers

I claim that `HTTPHeaders` is more readable and informative than the
unfolded type `(CI ByteString, ByteString)`.

* Typecheck and normalise http headers earlier

Previously we would typecheck and normalise http headers in
`exprFromImport`, i.e. while loading the import. This commit adds the
invariant that any headers in 'Chained' imports are already typechecked
and normalised, and moves this step into `loadWith` accordingly.

This causes a subtle difference in behaviour when importing remote files
with headers `as Location`: previously, nonsensical expressions like
`http://a using 0 0 as Location` were valid, while they would now cause
a type error.

* Fix dhall-lsp-server

* Fix Dhall.Import API regarding `Chained` imports

Do not expose the `Chained` constructor; we don't want external code
breaking our invariants! Also further clarifies the comment describing
the `Chained` type.

* Fix dhall-lsp-server

Since we are no longer able to construct `Chained` imports directly we
need to export a few additional helper functions from Dhall.Import.
Furthermore, since VSCode (and presumably the other editors out there
implementing the LSP protocol) does not support opening remote files
anyway we can get rid of some complications by dropping support for
remote files entirely on the back-end.

* Generalise decodeExpression, fixes TODO

* Fix tests

* Fix benchmarks

* Remove Travis cache for `~/.local/bin`

* Fix copy-pasted comment

Thanks to @Gabriel439 for spotting this!

* Add clarifying comment to `toHeaders`
2019-07-17 15:20:48 +00:00
Gabriel Gonzalez
90b62ee9d7 Replace dhall-to-text with dhall text subcommand (#1090)
Fixes #1087
2019-07-08 17:18:09 +00:00
Frederik Ramcke
8ae7b603fe
dhall-lsp-server: Fix cache to correctly invalidate transitive dependencies (#1069)
* Move "Dot" import graph generation to Dhall.Main

Previously `Dhall.Import` would generate the import graph in "dot"
format while resolving imports. This change simplifies `Dhall.Import` to
only keep track of the adjacency list representing the import graph,
moving the logic for generating "dot" files to Dhall.Main.

This change will allow us to implement proper cache invalidation for
`dhall-lsp-server`.

* Correctly invalidate transitive dependencies

Fixes dhall-lsp-server`s caching behaviour to correctly invalidate
cached imports that (possibly indirectly) depend on the changed file.

Example:

Suppose we have the following three files:
{- In A.dhall -} 2 : ./B.dhall
{- In B.dhall -} ./C.dhall
{- In C.dhall -} Natural

Previously, changing C.dhall to `Text` would not cause `A.dhall` to stop
type-checking, since the old version of `B.dhall` (which evaluated to
`Natural`) would still have been in the cache. This change fixes that
behaviour.

* Make edges of import graph self-documenting

As suggested by @Gabriel439

* Don't cache expressions manually

After computing the diagnostics for a given file we added its normal
form to the cache, but forgot to add its dependencies to the dependency
graph. This bug points out that keeping the import graph consistent
manually is probably not a good idea. With this commit we never mess
with the import cache manually; this means that files are only cached
once they are depended upon by some other file, potentially causing us
to duplicate work (but no more than once).

* Fix left-overs from previous commit
2019-07-08 10:55:15 +00:00
Gabriel Gonzalez
53f5fa158e
Fix --file option (#1004)
The `--file` option was essentially broken since it passed in the
file path instead of the directory, meaning that transitive imports
would not be computed correctly (they'd be off by one path component).
2019-06-14 08:50:37 -07:00
Gabriel Gonzalez
e8ac5e3bd0
Add new --cache flag to dhall freeze (#980)
Part of https://github.com/dhall-lang/dhall-lang/issues/563

This flag freezes imports in the same way as the Prelude by providing a
fallback unprotected import without an integrity check.  The primary use
case for this is caching imports with a graceful fallback, which is why
the flag is named `--cache`
2019-06-01 09:44:01 -07:00
Gabriel Gonzalez
20f6d8c316
Add --file flag (#949)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/882

This allows users to supply the Dhall expression by path instead of via
standard input.  This also ensures that transitive imports are resolved
appropriately relative to the file's path.

In other words, instead of this:

```
$ dhall <<< './foo/bar.dhall'
```

Users can now do:

```
$ dhall --file foo/bar.dhall
```
2019-05-13 09:26:38 -07:00
klntsky
74fcafe5d3 dhall freeze subcommand should respect --ascii flag (#934)
Fixes #877
2019-05-03 13:44:59 -07:00
Gabriel Gonzalez
7d31506be4
Automatically discover tests (#897)
This adds a new `Dhall.Test.Util.discover` utility for auto-generating
a `TestTree` from a directory tree.  This simplifies keeping up to date
with changes to the standard test suite.
2019-04-24 13:01:46 -07:00
Gabriel Gonzalez
2a78ac06b7
Define expression equality as CBOR equality (#866)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/426

This adds two new `ToTerm`/`FromTerm` classes in order to minimize
code disruption.  The main disruption is due to renaming the old
`encode`/`decode` to `encodeExpression`/`decodeExpression`
2019-03-27 18:26:02 -07:00
Gabriel Gonzalez
ff3dc7f9e7
Add --help information for --annotate flag (#856) 2019-03-24 11:42:27 -07:00
Gabriel Gonzalez
dce46fc6c8
Add --alpha flag to α-normalize output (#855)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/853

... as suggested by @singpolyma
2019-03-16 11:20:19 -07:00
Gabriel Gonzalez
2cdaf91636
Add --check flag to dhall format (#810)
Fixes #809

This allows the user to check if the input is formatted instead of formatting
the input
2019-02-06 18:19:25 -08:00
Gabriel Gonzalez
04ec45803d
Remove version tag from encoded expressions (#805)
* Remove version tag from encoded expressions

... as standardized in https://github.com/dhall-lang/dhall-lang/pull/362

This includes backwards compatibility for older encoded expressions
2019-02-03 21:17:41 -08:00
Gabriel Gonzalez
15d0b8d063
Change dhall freeze to only freeze Remote imports (#808)
The motivation behind this change is so that users can freeze remote imports
(like the Prelude) but ignore local imports so that subsequent runs of the
interpreter reflect changes to local files and environment variables.

The reasoning behind this is that there are two primary benefits of integrity
checks:

* Improved security
* Caching

... and one downside which is that updates to those imports are not pulled in
until the integrity check is updated or removed.

However, environment variables and local file paths do not benefit from
improved security or caching, so there is only a downside to freezing them.

Specifically:

* Environment variables and local file paths are both cheap to resolve

  ... so they don't really benefit from caching.

  To be precise, they *could* benefit from caching if the cache expression is
  cheaper to parse and normalize compared to the original file.  For those
  cases there is still an `--all` flag to freeze all imports.

* Environment variables and local file paths are trusted

  For example, when a user runs the `dhall` executable they are implicitly
  trusting their filesystem which provides that executable.  Similarly, when
  they run `dhall` without an absolute path they are implicitly trusting that
  their `PATH` environment variable has not been compromised to point to a
  malicious executable.

  Up until now, Dhall's threat model has always been that local imports are
  trusted but remote imports are not, so this is consistent with that threat
  model.

... so as far as environment variables and local files are concerned there are
only downsides to freezing them and no up-side.  This is why this change
no longer freezes them.

This also renames `hashImport` to `freezeImport` for more terminology
consistency.
2019-02-01 07:46:03 -08:00
Ville Tirronen
b2514ff8bf Add --immediate-dependencies flag to resolve mode (#803)
This is useful for integrating dhall to build systems where dhall
expressions (e.g. of type `Text`) are build products.

This also renames the `--list` flag to `--transitive-dependencies`
2019-01-31 15:24:17 -08:00
Ville Tirronen
3fbd0d72f8 Add --list flag to dhall resolve (#795)
This commit adds a flag for producing a machine readable listing of
dependencies of a dhall expression.

This flag can be used to integrate dhall more easily to file watchers or
build systems which require such lists of dependencies.
2019-01-28 21:43:37 -08:00
Gabriel Gonzalez
2d2c897e3f
Include standard version in dhall version output (#793)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/791
2019-01-25 09:01:55 -08:00
Gabriel Gonzalez
a671e9c2f5
Add --json flag for dhall {decode,encode} (#717)
Fixes #714

This adds a `--json` flag that `dhall decode` and `dhall encode` can use to
read/write the equivalent JSON representation of the CBOR.  This comes in
handy for the parsing compliance tests which use this CBOR-as-JSON as the
standard representation of the abstract syntax tree.
2018-11-28 17:51:20 -08:00
Basile Henry
65f5377f0c
Unique dependencies in dot graph (#713)
* Add dotgen to stack.yaml

* Generate strict dot graph (prune redundant connections)
2018-11-26 17:19:02 +01:00
Basile Henry
c8dc585430
Generate dot graph to visualize import graph (#698)
* Add dotgen as a dependency

Signed-off-by: Basile Henry <bjm.henry@gmail.com>

* Build up dot graph while resolving imports

Signed-off-by: Basile Henry <bjm.henry@gmail.com>

* Add --dot option to resolve in CLI

Signed-off-by: Basile Henry <bjm.henry@gmail.com>

* Handle diamond dependencies in dot graph

* Refactor dot graph generation
2018-11-26 07:24:20 +02:00
Gabriel Gonzalez
aecfbc9acc
Migrate dhall-{bash,json,text} into this repository (#661)
The motivation for this change is:

* To catch build failures in downstream packages whenever we make a breaking
  change to the `dhall` API
* To reduce the amount of work I need in order to cut a release for all of
  these packages
* To better share Nix/CI-related logic between the projects

Note that I have not yet migrated `dhall-nix` in.  I'm waiting for
https://github.com/dhall-lang/dhall-nix/issues/17 to be fixed since
`dhall-nix` is incompatible with later versions of `megaparsec` due to
`hnix`.
2018-10-28 17:32:51 -07:00