Commit Graph

289 Commits

Author SHA1 Message Date
Simon Jakobi
4559a27bf3
Fix isNormalized for field selections (#1210)
In expressions like

    ({ x : Optional/fold } // {=}).x

isNormalized didn't check if the expression being selected from
was normalized.

Fixes #1209.
2019-08-07 03:44:21 +02:00
Simon Jakobi
59226c85bf Move unbalanced braces out of CPP (#1205)
This helps fast-tags parse the containing file
(See https://github.com/elaforge/fast-tags/issues/48)
2019-08-05 23:33:40 +00:00
Ollie Charles
4a93c255db Remove Dhall.X and replace with Data.Void (#1172)
* Remove Dhall.X and replace with Data.Void

This commit removes the Dhall.X module and the Dhall.X.X type,
preferring the use of Data.Void.Void. As I'm sure a lot of people are
actually using X, I've added a type-alias type X = Void. However,
pattern matching on X would be a breaking change.

Fixes #1120.

* Restore unsafeCoerce

* Fix regression

* Unused

* Reorganise exports

* Fix dhall-nix

* Another fix

* Fix Dhall.LSP.Backend.Typing

* Fix dhall-bash
2019-08-05 13:00:59 +00:00
Gabriel Gonzalez
7f2f57f975
Add support for dependent types (#1164) 2019-08-03 21:38:01 -07:00
Gabriel Gonzalez
3d9a1d2a40 Improve error reporting for failed remote imports (#1188)
Several failed remote import messages didn't include the URL that
the interpreter failed to resolve.  This change fixes that and includes
some slight tweaks to improve consistency in how the messages are
formatted.
2019-08-03 12:18:10 +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
Simon Jakobi
f66918d8c8 Optimize a few Set instance (#1184) 2019-08-02 12:06:41 +00:00
Ollie Charles
1b683295fc Implement Natural/subtract (#1133)
* Implement Natural/truncatedSubtract

* Restore commented out code

* Add pretty printing for Natural/truncatedSubtract

* Flip the order of the arguments

* truncatedSubtract -> subtract

* Whitespace

* Whitespace

* Whitespace

* Whitespace

* Remove a try

* Fix Core.hs

* Add a case in Arbitrary (Expr s a)

* Fix Dhall.JSON

* lift2 -> lift0

* Update Dhall.Diff

* Add extra reduction rules

* Fix

* Update Core.hs

* Update dhall-lang submodule

* Updated dhall-lang

* Try rolling back the dhall-lang revision

* Correct isNormalized

* Add more isNormalized rules

* Update dhall-nix
2019-08-02 00:12:43 +00:00
Simon Jakobi
cb38ba2941 More simplifications for field selection (#1174)
…as standardized in https://github.com/dhall-lang/dhall-lang/pull/664.
2019-07-31 03:24:01 +00:00
Simon Jakobi
beb1e7ba6f
Remove old union literal syntax (#1176)
…as standardized in https://github.com/dhall-lang/dhall-lang/pull/573.

Fixes #1175.
2019-07-31 04:44:36 +02: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
Ollie Charles
22d46103c1 Formatting: Indent applications (#1167)
Fixes #515
2019-07-29 18:24:20 +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
Gabriel Gonzalez
7a88cdf481 Change ImportSemantics to not necessarily be α-normalized (#1162)
The motivation for this change is to avoid α-normalizing all imported
expressions.

For example, before this change you would get the following behavior
beginning with an empty cache

```
$ cat ./example.dhall
λ(a : Type) → a

$ dhall <<< './example.dhall'
λ(_ : Type) → _
```

The reason why is that the current code α-normalizes all imported
expressions, even when returning them fresh.

To fix this, I changed the `ImportSemantics` type to not require that
expressions are α-normalized.  Instead, the α-normalization only
happens at the last minute when interacting with the semantic cache, but
nowhere else.

I figured that this change would also be fine from the perspective of
the semi-semantic cache because false-negatives for this cache are
fine.  In particular, we probably don't mind if we get a cache miss for
the semi-semantic cache if the user renames a variable.

After this change imports are no longer α-normalized, whether loaded
from a hot or cold cache:

```
$ cat ./example.dhall
λ(a : Type) → a

$ dhall <<< './example.dhall'
λ(a : Type) → a

$ dhall <<< './example.dhall'
λ(a : Type) → a
```
2019-07-28 14:30:01 +00:00
Frederik Ramcke
fd8683216d Fix tests without with-http flag (#1159)
* Allow customization of remote import resolution

Makes the `Status` type more general; previously support for
`Network.HTTP.Client` was hardcoded. In short:

```
data Status = Status
    { _stack :: NonEmpty Chained
    [...]
--  , _manager :: Maybe Dynamic
--  --   importing the same expression twice with different values
++  , _remote :: URL -> StateT Status IO Data.Text.Text
++  -- ^ The remote resolver, fetches the content at the given URL.

    [...]
    }

```

* Simplify and expose `toHeaders`

`toHeaders` will be needed for mock http testing

* Fix compilation without `with-http` flag

* Fix compilation with `with-http` flag

* Fix tests without `with-http` flag

Implements a mock http client that handles requests to:
- `https://raw.githubusercontent.com/dhall-lang/dhall-lang/master/`
- `https://test.dhall-lang.org/Bool/package.dhall`
- `https://httpbin.org/user-agent`

This allows tests involving remote imports to succeed even when compiled
without the `with-http` flag.

* Build `dhall` with HTTP support compiled out in CI

... to prevent regressions from occurring in the future
2019-07-27 02:59:25 +00:00
Frederik Ramcke
5bb84cbd94 Fix compilation without with-http flag (#1157)
* Fix compilation without `with-http` flag

* Fix compilation with `with-http` flag
2019-07-27 02:03:47 +00:00
Frederik Ramcke
76a0d4159b Implement semi-semantic caching (#1154)
* Tag ImportSemantics with their semantic hashes

This is in preparation for semi-semantic caching.

* Collect the list of imports during import resolution

The final step needed in preparation for semi-semantic caching!

* Implement semi-semantic caching

This completes the implementation of the "semi-semantic caching"
proposal (issue #1098).

We compute the semi-semantic hash of a dhall import/file/expression as
follows:

- Parse the input;
- compute the semantic hashes of all imports referenced in the AST, i.e.
the hashes of their normal forms;
- compute the syntactic hash of the input (hashing the parsed AST);
- concatenate the syntactic hash of the input with the semantic hashes
of its imports and hash the result.

The "semi-semantic" cache (normal forms, indexed by semi-semantic
hashes) has the following properties:

- For a given input we can quickly find out if it is in the cache: we
only need to parse the input – we don't need to typecheck or normalise
it!
- The cache stays consistent, that is, we don't need to ‘invalidate’ old
cache entries if their dependencies change!

* Simplify semi-semantic hash

As suggested by @Gabriel439.

* Simplify code

We don't actually need to carry the list of imports around when loading.

* Restore `load`
2019-07-26 13:45:18 +00:00
Frederik Ramcke
d93c01dfbf Fix isNormalized test (#1155)
* Fix `isNormalized` test

The test in question failed intermittently because `isNormalized` is
more thorough than `normalize`, in the sense that it throws exceptions
for more non-welltyped expressions. As a result, we need to use `spoon`
not just when computing the normal form of a raw expression, but also
when calling `isNormalized` on the result. Note that the test may still
randomly fail in the future, because normalizing non-welltyped
expressions needn't terminate!

* Comment on non-totality of `isNormalized`
2019-07-26 07:58:58 +00:00
Frederik Ramcke
36379cec2e Fix import alternatives to recover from type errors (#1152)
Previously, `BAD="0 0" dhall <<< "env:BAD ? 0"` resulted in the
following error:
```
↳ env:BAD

Error: Not a function

1│ 0 0

BAD:1:1
```

According to the standard the above expression was supposed to evaluate
successfully to `0`. See #1146 for further discussion.
2019-07-25 18:05:55 -07:00
Frederik Ramcke
4faf25bbbe Load imports recursively (#1128)
* Load imports recursively

This is the big change that enables us to implement 'semi-semantic'
caching.

* Use `throwM` instead of `liftIO . throwIO`

* Fix build with __GHCJS__

* Fix exceptions in Dhall.Import

* Fix dhall-lsp-server

* Revert exception behaviour on typecheck errors

This is one for a separate pull request!

* Make sure loadImportFresh returns alpha-normal expression

As caught by @Gabriel439, `loadImportFresh` violated the invariant that
`ImportSemantics` should be alpha-beta-normal. This fix also means that
we don't have to alpha-normalise again in `loadImportWithSemanticCache`.

* Remove old comment

* Fix regression test for issue 216

Turns out the test was testing the wrong thing, because it was
pretty-printing an import. This worked previously because when importing
uncached expressions we would not alpha-normalise them.

* Restore `dhall freeze` bevhaviour

Newly frozen imports should also be present in the cache.
2019-07-23 16:11:33 +00:00
Ollie Charles
d55bf8f3a3 Add instance Lift (Expr s a) (#1119)
This allows Exprs to be lifted in template-haskell. This is useful to
build a [dhall||] quasiquoter
2019-07-21 12:10:53 -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
Gabriel Gonzalez
0120f2650d Document that normalize is partial (#1140)
* Document that `normalize` is partial

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

* Document other partial functions

... as suggested by @sjakobi
2019-07-20 20:14:52 +00:00
Gabriel Gonzalez
0c61b0d048 Forbid invalid codepoints (#1104)
* Forbid invalid codepoints

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

* Don't validate code points outside of escape sequences

... as suggested by @sjakobi

It's not necessary (since the `text` package forbids invalid UTF8) and
slows down performance as verified by the `dhall-parser` comment parsing
benchmarks

* Restore `nonCharacter` parsing test
2019-07-20 19:41:18 +00:00
Simon Jakobi
0ee6ce6f6f Implement "Generalize empty list annotations" (#1112)
…as standardized in https://github.com/dhall-lang/dhall-lang/pull/630

Also:

* Update the dhall-lang submodule to the state of
  https://github.com/dhall-lang/dhall-lang/pull/654.

* Skip the nonCharacter test for now.

Fixes #414.
Fixes #770.
2019-07-20 18:05:23 +00:00
Simon Jakobi
482984eb6d Allow only valid HTTP(S) reg-names (#1124)
Corresponding change to the standard:
https://github.com/dhall-lang/dhall-lang/pull/627

The potPourri parser test remains disabled due to
https://github.com/dhall-lang/dhall-lang/pull/655.

Fixes https://github.com/dhall-lang/dhall-haskell/issues/1110.
2019-07-20 00:54:27 +00:00
Simon Jakobi
e40e847730 Always typecheck the type annotation on 'toMap' (#1132)
Previously, ill-typed expressions like this one got into normalization:

    toMap {=} : <>.x

Also:

* Tweak Expr's Arbitrary instance:
  - Boring nullary constructors don't need to be so frequent.
  - Large NaturalLits can cause normalization to OOM, which we don't
    want when running the testsuite.

* Add property test to check that all well-typed expressions can be
  normalized.
2019-07-19 23:14:01 +00:00
Gabriel Gonzalez
a440c6cd28 Improve error message for missing constructor (#1137)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1130
2019-07-19 20:17:14 +00:00
Frederik Ramcke
7e9728f0e9 dhall-lsp-server: Freezing imports (#1123)
* Implement dhall.freezeImport and dhall.freezeAllImports

* Remove old (broken) test suite

* Rename `relativePosition` to `subtractPosition`

as suggested by @Gabriel439

* Add doctest for `subtractPosition`

as suggested by @Gabriel439

* Simplify getImportHashPosition

As spotted by @Gabriel439

* Use `forM` instead of `mapM` for prettier code

As suggested by @Gabriel439
2019-07-19 17:24:11 +00:00
Simon Jakobi
b4f71b2aa2 Check normalizeWithM for consistency with normalize (#1126)
* Check normalizeWithM for consistency with normalize

* Implements constant folding of Natural/fold applications normalizeWithM.

* Changes the Arbitrary Var instance to generate only non-negative indices.
  Otherwise failures like this one would pop up:

    normalizeWithM should be consistent with normalize: FAIL (8.51s)
          *** Failed! Falsified (after 318133 tests and 6 shrinks):
          Let (Binding {variable = "", annotation = Nothing, value = List} :| []) (Var (V "" (-1)))
          Var (V "" (-1)) /= Var (V "" (-2))
          Use --quickcheck-replay=180244 to reproduce.

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

* QuickCheck tests: Specialize the 'natural' Gen to Naturals

Previously it could produce about any number, not just non-negative
ones.
2019-07-19 15:33:59 +00:00
Simon Jakobi
40ec83743d Make isNormalized consistent with normalize (#1115)
To be more precise (citing the haddocks):

    Given a well-typed expression e, (isNormalized e) is equivalent to
    (e == normalize e).

    Given an ill-typed expression, isNormalized may return True or False.

An even closer correspondence between isNormalized and 'normalize' is
currently tricky to achieve as 'normalize' returns errors only for some
ill-typed expressions. Once 'normalize' is more principled in this
regard, isNormalized could be changed to return a (Maybe Bool).

This re-enables a property test checking this consistency. Since
'normalize' returns errors for some ill-typed expressions, we
catch have to catch these, which requires an NFData for Expr.
2019-07-17 22:19: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
Frederik Ramcke
6534ce85ed Fix incorrect Canonicalize law (#1118)
It is not the case that
    canonicalize (a <> b) = canonicalize a <> canonicalize b.
For example
    canonicalize (Directory ["asd"] <> Directory [".."])
    = Directory [],
but
    canonicalize (Directory ["asd"]) <> canonicalize (Directory [".."])
    = Directory ["..", "asd"].

The law we want instead is:
    canonicalize (a <> b)
    = canonicalize (canonicalize a <> canonicalize b)
2019-07-17 13:13:40 +00:00
Frederik Ramcke
33ebf7ee71 dhall-lsp-server: Turn imports into clickable links (#1121)
* Expose `localToPath` in Dhall.Import

Also modifies `localToPath` to return a relative path if the input was
relative, rather than resolving relative paths by appending the current
directory.

* Turn imports into clickable links

This implements a handler for 'Document Link' requests. As a result,
imports are now clickable!

* Recover original behaviour
2019-07-17 08:54:56 +00:00
Simon Jakobi
e044b4ab68
toMap normalization: Misc improvements (#1116)
…addressing my own comments on
https://github.com/dhall-lang/dhall-haskell/pull/1041.
2019-07-15 23:50:40 +02:00
Simon Jakobi
3856612763
Sort the fields of a record projection during normalization (#1111)
…as standardized in https://github.com/dhall-lang/dhall-lang/pull/625.
2019-07-15 20:55:00 +02:00
Mario
8aa2ac3ce9 Implementation of toMap (#1041)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/610
2019-07-15 08:28:29 -07:00
Simon Jakobi
b2cbc8227f Remove usage of legacy Optional syntax (#1091)
* Remove usage of legacy Optional syntax

* Dhall.JSON: Use multilet in examples

* Update dhall-json/src/Dhall/JSON.hs

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* Update dhall-json/src/Dhall/JSON.hs

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* Update dhall-json/src/Dhall/JSON.hs

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* Update dhall-nix/src/Dhall/Nix.hs

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* Update dhall-nix/src/Dhall/Nix.hs

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* Revert changes to travis.yml

* Lint travis.dhall
2019-07-14 18:36:41 +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
635a4489d2 Fix unexpected decoding successes in tests (#1088)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1082

All of the successes are due to accepting expressions that would not
have been produced by a compliant encoder, such as:

* Expressions that use a variable name of `_` that could have been
  encoded more compactly

* An expression tagged as a `Natural` number storing a negative number

* An expression encoding a function appled to 0 arguments
2019-07-07 17:22:53 +00:00
Simon Jakobi
f1234c4efa Don't typecheck the head of a list twice. (#1085) 2019-07-07 16:50:06 +00:00
Simon Jakobi
e40d0bc624 Simplify typechecking of Combine and CombineTypes (#1067)
Also add Dhall.Map.outerJoin, inspired by Semialign.align.
2019-07-07 16:00:25 +00:00
Simon Jakobi
d7114a32de Simplify normalization of record projection (#1071)
…via new functions Dhall.Map.{keysSet,restrictKeys} and
Dhall.Set.fromSet.

Also apply these functions in a few more cases.
2019-07-07 14:33:07 +00:00
Simon Jakobi
3b4f826eda Dhall.Map: Remove the keys list when sorting (#1066)
Also add the unorderedSingleton and unorderedFromList functions.

This speeds up the "issue 412" benchmark by ~9% and "union performance"
by ~2%.
2019-07-07 07:21:04 +00:00
Gabriel Gonzalez
c116207663 Update to latest dhall-lang (#1084)
* Update to latest `dhall-lang`

The main updates are to support the following two changes to the
standard:

* https://github.com/dhall-lang/dhall-lang/pull/604
* https://github.com/dhall-lang/dhall-lang/pull/611

* `s/fields/fails/`

... as caught by @sjakobi

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>
2019-07-07 06:08:58 +00:00
Simon Jakobi
76efe630b2 Remove cruft related to the removed 'constructors' keyword (#1077) 2019-07-06 22:38:02 +00:00
Simon Jakobi
9a2e25b92d Dhall.Map.fromList: Fix docs (#1078)
Closes #1052.
2019-07-06 20:58:32 +00:00
Simon Jakobi
28fc9e1870 Dhall.Eval.eqMapsBy: Compare map sizes before contents (#1065)
Data.Map.size is O(1), so we expose it via Dhall.Map.
2019-07-05 04:04:08 +00:00
Simon Jakobi
c7e48bf497 Skip re-typechecking the first non-empty union alternative (#1057)
For the deep-nested-large-record benchmark, this results in a
speedup of about 0.5–1%.
2019-07-03 16:57:05 +00:00
Simon Jakobi
e061f35c4c Simplify Dhall.Parser.Combinators.toMap (#1053)
This changes the parsing error for some cases.

Previously:

    ⊢ {b=1, a=1, b=1, a=1}

    Error: Invalid input

    (stdin):1:20:
      |
    1 | {b=1, a=1, b=1, a=1}
      |                    ^
    duplicate field: b

Now:

    ⊢ {b=1, a=1, b=1, a=1}

    Error: Invalid input

    (stdin):1:20:
      |
    1 | {b=1, a=1, b=1, a=1}
      |                    ^
    duplicate field: a

Also add a new function to Dhall.Map: fromListWithKey
2019-07-03 15:46:13 +00:00
Gabriel Gonzalez
af0e77ce00
Consistently format multi-line strings (#1056)
Fixes #973

The formatter was behaving inconsistently for multi-line strings
depending on whether or not they were at the top level or nested as
a subexpression.  For example, the same multi-line string would be
rendered in multi-line form if it was at the top level and rendered
compactly if nested within another expression.

The root cause was that the pretty-printing logic was missing a top-level
`Pretty.group` call (which is the function responsible for enabling
compact representations if they fit), which this change fixes.
2019-07-02 13:54:54 -07:00
Simon Jakobi
51a020e3e4
Dhall.Map: Reflect original key ordering in Ord instance (#1050) 2019-07-02 19:44:33 +02:00
Gabriel Gonzalez
f5819dd6d6 Improve performance of type-checking record literals (#1048)
While benchmarking the example from #769 I saw that a significant
amount of time was spent benchmarking record literals.  When I looked
at the code more closely I saw that the first key in the record literal
was being type-checked twice (once to figure out the record's associated
type-checking constant and once as part of the `process` loop).

This change fixes that, which speeds up interpretation of the large
example by 9%:

Before:

```
time                 18.13 s    (18.11 s .. 18.16 s)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 18.09 s    (18.07 s .. 18.11 s)
std dev              21.92 ms   (10.66 ms .. 29.76 ms)
variance introduced by outliers: 19% (moderately inflated)
```

After:

```
time                 16.53 s    (16.49 s .. 16.60 s)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 16.59 s    (16.56 s .. 16.64 s)
std dev              43.65 ms   (6.227 ms .. 56.35 ms)
variance introduced by outliers: 19% (moderately inflated)
```
2019-07-02 18:42:05 +02:00
Simon Jakobi
0057901e58 Dhall.Map: Change Foldable and Traversable instances to respect the key ordering (#1051) 2019-07-02 07:47:41 -07:00
Gabriel Gonzalez
92bdd56a34
Switch Var to use an Int (#1044)
Related to: https://github.com/dhall-lang/dhall-haskell/issues/1039

We'll probably never see indices that exceed the space of an `Int` and
the interpreter would probably not be able to handle 9223372036854775807
nested binders anyway.
2019-07-01 17:24:13 -07:00
Fabrizio Ferrai
04d82120a4 Implement importing as Location (#1019) 2019-06-30 22:00:14 -07:00
Simon Jakobi
7647adba1a
Speed up Dhall.Map.unorderedTraverseWithKey_ (#1036)
This reduces the runtime of the `deep-nested-large-record` benchmark by about 50%.

Note that previously, contrary to its name and documentation, this function traversed a Dhall.Map in insertion order due to its use of Dhall.Map.toList! With this change, the traversal is changed to ascending key order.

Also:
- Fix the deep-nested-large-record benchmark

- Remove the map-operations benchmark: This benchmark actually reports a ~20% loss of performance for the unorderedTraverseWithKey_ change.  Since we eventually care about dhall's performance we it's better not to be mislead by a questionable micro-benchmark.
2019-06-30 19:54:13 +02:00
Gabriel Gonzalez
bb365dd0f3
Remove prettyDiff internal helper (#1038)
... as suggested by @sjakobi in https://github.com/dhall-lang/dhall-haskell/pull/1027#issuecomment-506516607

After some internal refactors, `prettyDiff` is now just an
alias for `Dhall.Diff.diffNormalized`, so it's no longer
necessary.
2019-06-28 07:30:15 -07:00
Gabriel Gonzalez
250fdfc348
Reject record projection when there is a field type mismatch (#1027)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1020

This also includes small fixes to the `MissingField` error message,
which I found along the way.
2019-06-27 21:55:09 -07:00
Gabriel Gonzalez
09016735fa
Use vertical bars for the left margin of source spans (#1030)
This separates the source from the line numbers using vertical bars
instead of colons.  The main reason for this is to more clearly
delimit the two and to also prevent the old colon from being confused
as a type annotation.
2019-06-27 20:37:10 -07:00
Gabriel Gonzalez
484182b74e
Remove the InvalidField error constructor (#1026)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1025

There were two error constructors related to invalid field types:

* `InvalidField`: for field types whose types were invalid type-checking
  constants
* `InvalidFieldType`: for all other invalid field types

As @sjakobi noted, there are no invalid field types for the former
category, so we can remove that category of error entirely.

Note that `InvalidField` was still being used in a few places, but each
of those uses should actually have been using `InvalidFieldType`
instead, which this change also fixes.
2019-06-27 13:19:16 -07:00
Simon Jakobi
79e33b46f3
Misc cleanup in Dhall.Map (#1029) 2019-06-27 09:15:51 +02:00
Simon Jakobi
634f1f3d9a
Allow Sort as type annotation (#1024)
Standardized in https://github.com/dhall-lang/dhall-lang/pull/507.
2019-06-27 05:59:53 +02:00
Clément Delafargue
b9aeb345e4 Make the type of extract richer (#1011)
see #387
2019-06-24 07:22:35 -07:00
Gabriel Gonzalez
c4de94224c
Improve error message for unsaturated merge (#1015)
This improves the error message when users attempt to apply `merge` to only
one argument, as suggested by:

https://github.com/dhall-lang/dhall-lang/issues/106#issuecomment-503523358

For example:

```
$ dhall <<< 'merge { Foo = True }'

Error: Invalid input

(stdin):2:1:
  |
2 | <empty line>
  | ^
unexpected end of input
expecting '.', second argument to ❰merge❱, or whitespace
```
2019-06-22 10:02:28 -07:00
Ivan
6fee49d47c fix tutorial typo (#1016)
Thank you!
2019-06-20 12:08:20 +01:00
Gabriel Gonzalez
5c93429b59
Fix substitution into record projection by type (#1012)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1009

The `subst`/`shift`/`subExpressions` functions did not correctly
reflect the recent change to support projection by type
2019-06-18 18:20:02 -07:00
Gabriel Gonzalez
b001a61a02
Minor fix to dhall diff (#1006)
`dhall diff` slightly misbehaves when diffing the following expression with
itself:

```dhall
λ(f : List Bool -> Bool) → f ([] : List Bool)
```

... producing the following diff:

```
  λ(… :   …
        → …)
→ …@…
  - [ … ] : List …
  + [ … ] : List …
```

This is because there are two places in the `Dhall.Diff` module responsible
for comparing lists:

* Once in `diffApplicationExpression`, which compares two lists with at least
  one type annotation between them
* Once in `diffPrimitiveExpression`, which compares two lists if neither one has
  a type annotation

Those cases exhaustively cover all possible pairs of lists, but there was a
third (incorrect) fallback case that prematurely gave up and displayed them as
different.  This fallback would trigger when applying a function to an empty
list, since the diffing algorithm wouldn't have a chance to return back to the
top-level `diffExpression` and try to compare the lists correctly in
`diffApplicationExpression`.

After this change, the diff now doesn't include a spurious difference:

```
  λ(… :   …
        → …)
→ …@…
  …
```
2019-06-14 09:43:30 -07: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
154d1c52cf
Remove support for old-style List-like Optional literals (#1002)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/572
2019-06-13 17:59:49 -07:00
Gabriel Gonzalez
188ebc8f26
Implement new Unicode braced escape sequence (#987)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/580
2019-06-11 17:27:40 -07:00
Frederik Ramcke
801e9bc7ab Fix linting of unused let bindings (#1001)
* Find unused bindings inside nested lets

The removeUnusedBindings rule only matches the first bound variable in a
nested let block (of the form "let ... let ... in ..."). This means that
so far the linter missed cases like
  let a = 0 let b = 0 in a.
This simple fix unfolds all let blocks (syntactically this means
inserting `in's everywhere) before applying the linting rules; the
LetInLet rule folds everything back together in the end. Applied to the
example from above we now return the correct result,
  let a = 0 in a.

* Rewrite `lint` in a more explicit style; add comments

* Don't export implementation details

* Fix `freeIn` to correctly handle de Briujn indices

Previously we had "x@0" `freeIn` "x@1" == True (but "x@1" `freeIn` "x@0"
== False). The fix is to use subst instead of shift to change
occurrences of the given variable.

* Fix `removeUnusedBindings` to update de Bruijn indices

Whenever we remove an unused binding we need to update any references to
variables outside the let block, so that
  let a = 0 let a = 0 in a@1
gets correctly rewritten into
  let a = 0 in a   (a = a@0)
instead of
  let a = 0 let a = 0 in a@1
  ~> let a = 0 in a@1
  ~> a@1
2019-06-11 09:25:50 -07:00
Gabriel Gonzalez
26bb77e99e
Move lens-like utilities to Dhall.Optics module (#986) 2019-06-05 20:18:42 -07:00
Gabriel Gonzalez
bb490a7a18
Fix Natural/fold for GHCJS bindings (#985)
Fixes https://github.com/dhall-lang/dhall-lang/issues/579

`Natural/fold` was misbehaving on GHCJS due to the use of `Natural`
arithmetic (for some reason).  This is a problem I've seen and fixed
before, but needed to be fixed again after the migration to the new
`Dhall.Eval` normalization engine.

The fix is easy: use `Integer` instead of `Natural` for the accumulator
of the fold and the bug disappears.
2019-06-05 18:48:10 -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
8dc52fa3d2
Add support for improved using behavior (#967)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/560
2019-06-01 08:27:26 -07:00
Gabriel Gonzalez
7410f8d3bd
Update to latest version of standard (#976) 2019-05-30 22:40:05 -07:00
Gabriel Gonzalez
3c08c627e8
Support projection by record type (#958)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/499
2019-05-27 20:54:42 -07:00
Valery V. Vorotyntsev
6d363ce734 Dhall.Tutorial: fix shell output formatting (#972)
Fixes #971
2019-05-27 20:05:27 -07:00
Gabriel Gonzalez
a9bacbecfe
Add :clear command to dhall repl (#966)
Fixes #860
2019-05-24 09:39:19 -07:00
Gabriel Gonzalez
411726a3eb
Reject wrong type annotation for record/union literals/types (#965)
Fixes #959
2019-05-23 08:37:19 -07:00
quasicomputational
d77e174ab7 CPP out Monad.fail definition. (#961)
As Dhall's bounds don't allow base 4.13, this doesn't actually affect
anyone running in a supported configuration (i.e., without
--allow-newer). Further note that base 4.13 (i.e., GHC 8.8) isn't
tested in CI at present.

This could well be the last GHC 8.8-related change needed to
code (bounds will definitely need to be adjusted). In this case, a
Dhall release with relaxed bounds will suffice to finish off GHC 8.8
support.

However, it's also possible that dependencies might bundle together
breaking changes with 8.8 support, in which case adaptations will
still need to be made.
2019-05-22 18:48:31 -07:00
quasicomputational
7e6ac01810 Add chunkExprs. (#954) 2019-05-15 08:51:31 -07:00
Gabriel Gonzalez
0bbfe6f14c
Move customization documentation into Haskell package (#951)
Related to https://github.com/dhall-lang/dhall-lang/issues/544
2019-05-14 17:55:15 -07:00
Greg Pfeil
de8e7639df Fix diff output to not double-print key-value separators. (#952)
E.g.,
```
{ unit :   …
```
was being printed as
```
{ unit : :   …
```
2019-05-14 08:00:02 -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
Gabriel Gonzalez
d788b780a2
Update to latest version of language standard (#948)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/947
2019-05-13 08:23:46 -07:00
quasicomputational
48c73f3ef9 Add and expose genericInject. (#940)
This is a counterpart to `genericAuto`, which is useful for dealing
with types coming from a library without orphan instances.
2019-05-05 20:21:50 -07:00
Gabriel Gonzalez
7d56778350
Fix another α-normalization bug (#938)
This was caught by the following test:

372230d161/tests/alpha-normalization/success/unit/FunctionNestedBindingXXFreeA.dhall
2019-05-05 19:30:26 -07:00
Stephen Paul Weber
2fc7f79959 Reduce dependency requirements to what is in sid (#939)
This make it easier to build the package on debian unstable, which is
the first step towards an official package.
2019-05-05 07:54:14 -07:00
Gabriel Gonzalez
a929d4e0bb
Fix marshalling of unions (including enums) in and out of Dhall (#936)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/930
2019-05-04 22:29:51 -07:00
Basile Henry
29ccd7d0cb Fix repl autocomplete for Records and Unions (#937) 2019-05-04 12:13:09 -07:00
klntsky
74fcafe5d3 dhall freeze subcommand should respect --ascii flag (#934)
Fixes #877
2019-05-03 13:44:59 -07:00
Greg Pfeil
1073d04b82 Fix merging of sort-level record types. (#891)
Fixes #890
2019-05-03 08:50:23 -07:00
AndrasKovacs
931dc50522 Fix alpha normalization (#931)
Fixes #929
2019-05-02 13:50:17 -07:00
quasicomputational
c9ea8b99ca Teach genericAuto about new-style union construction. (#927)
The underlying bug is very similar to #915, and in fact this builds on
the fix for that in #918.

Closes #926.
2019-05-02 09:26:53 -07:00
quasicomputational
4f9defec25 Use MonadFail.fail, not Monad.fail. (#912)
Monad.fail is no more with GHC 8.8, so this is a forced change.
However, it will also work on older GHCs.
2019-05-01 11:22:39 -07:00
klntsky
962a172b53
Converted sample code to doctest for RecordType, UnionInputType, RecordInputType 2019-05-01 09:52:43 +03:00
Gabriel Gonzalez
6d510ee2b1
Add line numbers to error messages (#919)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/905

For example, this file:

```haskell
[ 1
, 2
, 3
, Bool

+ 1
]
```

... now produces this error message:

```
Use "dhall --explain" for detailed errors

↳ ./example.dhall

Error: ❰+❱ only works on ❰Natural❱s

4:   Bool
5:
6:
7:
8:
9: + 1

/Users/gabriel/proj/dhall-haskell/dhall/example.dhall:4:3
```
2019-04-30 15:31:18 -07:00
Gabriel Gonzalez
d1501b51f9
Increase lines of context for error messages (#916)
Related to https://github.com/dhall-lang/dhall-haskell/issues/905

This increases the size of expressions that we display in error messages to
20 on each side before we begin truncating the output
2019-04-30 10:55:00 -07:00
Gabriel Gonzalez
07c9c62af3
Fix marshaling new-style union literals (#918)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/915
2019-04-30 08:18:12 -07:00
Gabriel Gonzalez
21da6f2b7f
Update to latest test suite (#903)
This requires implementing the following changes to the standard:

* https://github.com/dhall-lang/dhall-lang/pull/481
* https://github.com/dhall-lang/dhall-lang/pull/488
* https://github.com/dhall-lang/dhall-lang/pull/489
* https://github.com/dhall-lang/dhall-lang/pull/497
2019-04-25 15:05:02 -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
AndrasKovacs
fcca883e00 Add a new environment machine normalizer (#876)
- Dhall.Eval: new evaluator, conversion checker and normalizer.
  There is no standalone alpha normalizer yet.
- There is a new option "new-normalize" for dhall executable, which uses
  the new normalizer.
- Type checker is unchanged.
- new implementation: alphaNormalize, judgmentallyEqual, normalize
- normalizeWith takes a Maybe ReifiedNormalizer argument now, and switches to
  the new evaluator whenever the input normalizer is Nothing
- QuickCheck test for isNormalized removed, because we don't support evaluation
  of ill-typed terms, which the test would require.
2019-04-17 16:41:04 -07:00
Fabrizio Ferrai
58ae94df0e
Fix typechecking of Sorts in records (#881)
As standardized in dhall-lang/dhall-lang#453
2019-04-07 14:50:49 +03:00
Gabriel Gonzalez
ba55d55307
Add support for fields named after built-ins (#875)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/437
2019-03-30 11:50:26 -07:00
Gabriel Gonzalez
fe5d100226
Fix parsing of identifiers that overlap with imports (#870)
Fixes https://github.com/dhall-lang/dhall-lang/issues/446
2019-03-28 08:51:01 -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
a2ab6a59ec
Add support for empty alternatives (#863)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/438

This also adds `dhall-json` support for empty alternatives

In particular, this translates empty alternatives to strings encoding the alternative name

```haskell
-- ./example.dhall

let Role = < Wizard | Fighter | Rogue >

in  [ Role.Wizard, Role.Fighter ]
```

```
$ dhall-to-json <<< './example.dhall'
["Wizard","Fighter"]
```
2019-03-27 15:29:10 -07:00
Gabriel Gonzalez
4c9dc60b20
Fix dhall decode bug (#859)
... as caught by @singpolyma

`Dhall.Binary.unApply` was failing to uncurry functions due to the presence of
`Note` constructors.  This caused `dhall encode` to produce different
results from `dhall hash` since the latter was normalizing the expression
(and therefore removing `Note` constructors) whereas the former was not.
2019-03-24 13:18:21 -07:00
Gabriel Gonzalez
c900081a34
Remove deprecated Path constructor (#858)
The `Path` constructor was deprecated a long time ago, so it's pretty
safe to remove now
2019-03-24 12:21:08 -07:00
Gabriel Gonzalez
ff3dc7f9e7
Add --help information for --annotate flag (#856) 2019-03-24 11:42:27 -07:00
Gabriel Gonzalez
c3ba33a80a
Add unit tests (#854)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/416
2019-03-24 11:01:43 -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
Justin Le
35513e715a Fix for UnionType (#857)
Fix the type equality check by using judgmental equality
2019-03-16 10:12:55 -07:00
Gabriel Gonzalez
bffe2ed2a1
Remove support for URL fragments (#851)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/406
2019-03-14 07:23:23 -07:00
Gabriel Gonzalez
4b7bdd458c
Add CORS support (#846)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/411
2019-03-12 18:36:38 -07:00
Gabriel Gonzalez
1e3c2a1c84
Be more strict when decoding variables named "_" (#847)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/407
2019-03-07 22:09:41 -08:00
Gabriel Gonzalez
2efed4b4a5
Expand the set of valid quoted labels (#840)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/408
2019-03-07 21:42:57 -08:00
Gabriel Gonzalez
05d9405d29
Simplify import resolution logic (#833)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/391

This also updates the `loadWith` judgment to more closely match the variable
names used in the standard
2019-03-04 19:11:25 -08:00
Fabrizio Ferrai
74e8003905
Sort record and union fields when CBOR-encoding (#835)
Also sort fields in the `Arbitrary` instance for `Dhall.Map` in serialization tests
2019-03-04 00:08:43 +02:00
Basile Henry
13a1158538 Fix REPL autocomplete (#837)
This commit fixes an issue that made the last branch of the completer
unreachable.

The second to last branch was always `True`:

```
> split (== '.') "anything"
["anything"]
```

Signed-off-by: Basile Henry <bjm.henry@gmail.com>
2019-03-02 14:54:18 -08:00
Gabriel Gonzalez
36f0e55a5f
Remove the constructors keyword (#829)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/385
2019-02-27 21:44:36 -08:00
Gabriel Gonzalez
375688c97c
Small improvements to dhall format (#831)
Fixes #832 832

This includes two changes:

* Fix a missing newline at the end of `dhall format` output when not using
  the `--inplace` option

* Better align ASCII output
2019-02-27 11:32:48 -08:00
Gabriel Gonzalez
744a90c547
Add :set/:unset commands to dhall repl (#828)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/823

These allow one to enable or disable command-line options

Currently these only support `--explain`
2019-02-25 08:51:02 -08:00
Fabrizio Ferrai
8527a651d7 CBOR-encode only some special values as half-floats (#822)
Co-Authored-By: f-f <fabrizio.ferrai@gmail.com>
2019-02-23 11:21:28 -08:00
Javier Neira
d714754e14 Show some details in InvalidType error output (#824) 2019-02-23 09:49:14 -08:00
Gabriel Gonzalez
5b0686b01c
Fix relative precedence of != and == (#825)
Fixes https://github.com/dhall-lang/dhall-lang/issues/373

The standard specifies that `!=` should have higher precedence than `==`,
which this change fixes.
2019-02-23 08:56:16 -08:00
Gabriel Gonzalez
e3dde9dfa7
Implement Text/show (#811)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/365
2019-02-12 18:42:48 -08:00
Ollie Charles
7349eb08c3 Remove explicit recursion from Dhall lint in favour of micropasses (#817) 2019-02-12 17:18:23 -08:00
Gabriel Gonzalez
112efa7df7
Fix import source locations (#815)
.. as caught by @Profpatsch in:

https://github.com/dhall-lang/dhall-haskell/pull/812#issuecomment-462134701

Before this change the location was always being reported as `(stdin):1:1`
because the `SourcedException` kept getting modified with a broader
source location in the `Note` branch of `loadWith`.

This was originally done so that alternative imports would show the entire
source span, but it mistakenly just kept bubbling up regardless of whether or
not there were alternative imports.

Instead, this includes an approximate source span for alternative imports.
The source span bounds are correct but the contents just show which imports
were alternated, even if they might have been buried in a larger expression.

For example, if the original expression had been:

```haskell
Some ./x ? None ./y
```

... then the source span for the error message would display just:

```haskell
./x ? ./y
```

... which is probably as good as it will get for now.
2019-02-12 09:04:32 -08:00
Basile Henry
d20b1ca60d Save and load REPL context via :save and :load commands (#807)
The format for the save file is a plain Dhall file containing REPL commands.
This will hopefully mean that the save file can be edited manually if need be
without too much effort.

Signed-off-by: Basile Henry <bjm.henry@gmail.com>
2019-02-11 22:24:29 -08:00
Gabriel Gonzalez
98497e44ec
Add source position information for missing imports (#812)
Related to #561

This adds source position information to missing imports

Before:

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

↳ ./foo

Error: Missing file …/foo
```

After:

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

↳ ./foo

Error: Missing file …/foo

(stdin):1:1
```
2019-02-08 07:32:00 -08: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
2f26dac1ff
Add support for Unicode path components (#800)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/353
2019-02-04 19:14:07 -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
Gabriel Gonzalez
1a94f5558e
Fix parser for natural-raw (#804)
Fixes https://github.com/dhall-lang/dhall-lang/issues/357

This uses `Text.Megaparsec.Char.Lexer.decimal` which matches the Dhall
grammar.  The previous `decimal` parser was also accepting non-standard
hex and octal literals.
2019-01-31 13:05:19 -08:00
Basile Henry
29375ad462 Add :hash command to the repl (#806)
Signed-off-by: Basile Henry <bjm.henry@gmail.com>
2019-01-31 12:12:05 -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
Mario Lang
0460f28a38 Fix a typo (#792) 2019-01-23 14:57:06 -08:00
Gabriel Gonzalez
095ee6db61
Don't fail if $HOME environment variable is unset (#789)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/788

This removes the dependency on the `directory` library's utility
functions (which require `HOME` to be set)
2019-01-21 08:22:16 -08:00
Gabriel Gonzalez
96d34ee92a
Don't disable -fwarn-incomplete-uni-patterns at module level (#784)
... as suggested by @ocharles in
c368d66a6f (commitcomment-31973007)

Instead, explicitly opt out more narrowly with `unsafeExpect*` functions
2019-01-18 07:13:49 -08:00
Gabriel Gonzalez
f24f665047
Fix non-exhaustive pattern match in dhall lint (#780)
`dhall lint` would fail on the following expression:

```
    let replicate = https://prelude.dhall-lang.org/List/replicate

in  let Config = { name : Text, age : Natural }

in  let Configs = List Config

in  replicate 10 Text "!"
```

... because the code (incorrectly) assumed that simplifying an inner
`let` binding would preserve at least one `let` binding.  However, when the
outer `let` (beginning with `let replicate`) is simplified the inner `let`
(beginning with `let Config`) simplifies down to just `replicate 10 Text "!"`
which has no `let` binding at all, leading to a pattern match failure.

This change fixes that by extending the code to correctly handle that case
with an exhaustive pattern match.
2019-01-16 21:59:11 -08:00
Gabriel Gonzalez
aed91b3b44
Fix parsing of list annotations (#779)
Related to: https://github.com/dhall-lang/dhall-lang/issues/343

According to the standard a non-empty list with a type annotation should
not be encoded with the type annotation alongside the list elements.  The
type annotation should be parsed and encoded as a separate constructor.
2019-01-16 20:28:12 -08:00
Gabriel Gonzalez
f5928e4472
Fix Nix build to reinstate -Werror (#781)
A refactor of the Nix build accidentally removed the `-Werror` flag, which
caused some warnings to get past CI.  This change fixes that and removes the
warnings.
2019-01-16 19:39:51 -08:00
Javier Neira
3f004ff9bb Fix test errors in windows caused by encoding (#782) 2019-01-16 19:15:57 -08:00