Commit Graph

236 Commits

Author SHA1 Message Date
Javier Neira
640913f8d2
Fix default cache handling in windows (#1272)
* Ignore all stack*.yaml.lock files
* Use `$LOCALAPPDATA` environment variable in windows
2019-09-16 09:51:00 +02:00
Simon Jakobi
17c28d4b6c Adjust type inference for record literals (#1309)
… to changes from
https://github.com/dhall-lang/dhall-lang/pull/740.
2019-09-15 20:03:58 +00:00
Gabriel Gonzalez
ca86ed612c Simplify Inject/Interpret for 1-field records (#1315)
* Simplify `Inject`/`Interpret` for 1-field records

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

Now a Haskell type like:

```haskell
data Example = Foo Bool | Bar Text
```

... corresponds to this Dhall type:

```dhall
{ Foo : Bool | Bar : Text }
```

* Fix documentation

* Add additional test cases

... as suggested by @sjakobi

* Test all permutations of:

* 0, 1, or 2 fields
* Fields of type `()` or `Double`
* Named or anonymous fields
2019-09-15 03:37:42 +00:00
Simon Jakobi
fddce0b8cf Adjust type-checking test setup (#1275)
… in response to https://github.com/dhall-lang/dhall-lang/pull/723.
2019-09-15 02:56:16 +00:00
Simon Jakobi
1fed9063d5 Prevent repl from inserting inferred 'Sort's into context (#1318)
To type-check and evaluate inputs in the context of previous
inputs, the repl constructs a let-expression that includes
the previous input and variable assignments as bindings.

Previously these bindings would also be annotated with
inferred types. For example a session like

    ⊢ Kind
    ⊢ "foo"

would be represented as

    let it : Sort = Kind
    in  "foo"

However `Sort` does not typecheck as an annotation of a let-binding,
resulting in the confusing message

    Error: ❰Sort❱ has no type, kind, or sort

Constructing the let-bindings without the type annotations fixes the
problem.

Fixes #1193.
2019-09-15 02:16:26 +00:00
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
93943a29c4 Format record fields more compactly if they fit on 1 line (#1314)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1313
2019-09-14 14:10:29 +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
Patrick Mylund Nielsen
c29b128339
Improve GHCJS support (cabal build, SHA256 hashing) (#1311) 2019-09-13 11:42:55 -04:00
Simon Jakobi
88c2f29a57
Simplify nested record projections (#1307)
… as standardized in https://github.com/dhall-lang/dhall-lang/pull/729.
2019-09-13 05:38:27 +02:00
Simon Jakobi
796680bb99 Simplify ⫽ within projection (#1283)
… as standardized in https://github.com/dhall-lang/dhall-lang/pull/697.
2019-09-12 11:42:31 +00:00
Simon Jakobi
cb5ccab636 let-formatting: Insert hardline in front of the '=' instead of behind (#1302)
Fixes #1301.
2019-09-11 05:21:11 +00:00
Gabriel Gonzalez
4458cf04a2 Simplify recursive Interpret instance (#1298)
* Simplify recursive `Interpret` instance

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

The motivation behind this change is to:

* Remove the dependency on `free` and `distributive`
* Simplify the API and the implementation

* Fix `stack-lts-6` build

* Remove now-unused test files

... as caught by @sjakobi
2019-09-11 03:24:10 +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
quasicomputational
a5c77b1db7 Binding docs + combinators for 1.26 (#1291)
* Add a haddock to explain the various `Binding` fields.

* Add combinators to make dealing with `Binding` less awkward.

With all of the source information flying around, manually
deconstructing and reconstructing `Binding`s is a pain. These
combinators cover some very common cases.

* Use `bindingExprs` to simplify `subExpressions`.

* Use bindingExprs and chunkExprs to simplify another traversal.
2019-09-08 21:15:18 +00:00
Gabriel Gonzalez
74a03f3870 Re-export Data.Void.absurd from Dhall.TypeCheck (#1295)
... as suggested by @quasicomputational in:

https://github.com/dhall-lang/dhall-haskell/pull/1286#issuecomment-529137803
2019-09-08 20:33:09 +00:00
Simon Jakobi
71bb56931d Use generic-random for Expr's Arbitrary instance (#1282)
Full coverage of all Expr constructors is now checked by the
type-checker. This revealed that that the IntegerToDouble, TextShow,
Some and None constructors were missing.

Also:
* Increase frequency for Lam, Pi and App
* Fix a few inconsistencies in normalization
* Remove some dead code in D.T.QuickCheck

Closes #1256.
2019-09-06 18:05:51 +00: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
Simon Jakobi
cdbeb61bb1 Add ImportAlt to Arbitrary instance, fix isNormalized and diff (#1276)
Also:

* Add @Gabriel439's explanation regarding whitespace as a comment

* Fix precedence in diffs of subexpressions
2019-09-05 14:45:38 +00:00
Simon Jakobi
0ebf705a75 Strip leading whitespace (#1270)
Fixes #1267.
2019-09-05 06:08:15 +00:00
Gabriel Gonzalez
141bd8d6f4 Fix diffs for assert and (#1266)
... as caught by @sjakobi in https://github.com/dhall-lang/dhall-haskell/issues/1256#issuecomment-526829515
2019-09-05 05:28:57 +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
Simon Jakobi
d86ac06c2a
Fix typechecking of toMap (#1279)
Fixes #1278.

Also improve some formatting.
2019-09-05 04:56:36 +02:00
Simon Jakobi
350b54c43e Lint: Don't remove asserts wrapped in lambdas or other expressions (#1269)
Also reuse the core linting logic in dhall-lsp-server
2019-09-01 18:09:28 +00:00
Ollie Charles
287752563f Restore support for records containing both types and terms (#1173)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/689
2019-08-31 13:35:26 -05:00
Simon Jakobi
72fd2ac983
Treat multi-lets as syntactic sugar (#1242)
Closes #1185.

This mostly reverts "Add support for multi-`let` (#675)" /
8a5bfaa3b9.

Also:

* Add fields for Src
  This is useful for to make 'Note's less noisy during debugging:

      first srcText expr
2019-08-31 18:31:24 +02: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
Gabriel Gonzalez
dbcfe7019d Fix Inject instance for lists (#1261)
* Fix `Inject` instance for lists

Fixes #1254

This also adds tests for conversions back and forth between Dhall and
Haskell values

* Add `Inject` instances for `Scientific` and `String`

... so that we don't need to comment them out!
2019-08-30 04:15:43 +00:00
Simon Jakobi
e687b11fc2 Avoid handling Notes in Dhall.Diff (#1260)
* Avoid handling `Note`s in Dhall.Diff

Context: #1256.

* Fix QuickCheck tests
2019-08-30 02:30:55 +00:00
Gabriel Gonzalez
557abad603 Fix diff for Text literals (#1262)
This is essentially the exact same problem and fix as #1213

Normally I would add a test, except that our test suite for diffs doesn't
yet support escape codes.  However, the basic problem was the following
output:

```
$ dhall diff '"1"' '"2"'
- "…"
+ "…"
```

... which now displays (with color highlighting) this output:

```
$ dhall diff '"1"' '"2"'
"12"  -- Imagine that the 1 is red and the 2 is green
```
2019-08-29 22:49:21 +00:00
Gabriel Gonzalez
9ff63b2234 Improve HTTP errors (#1253)
* Improve HTTP errors

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

This improves HTTP error messages by:

* Expanding the set of recognized status codes
* Adding up to 7 lines of the response body

For example:

```
Error: Remote file missing

URL:

↳ https://httpbin.org/statu

Message:

1│ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2│ <title>404 Not Found</title>
3│ <h1>Not Found</h1>
4│ <p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>
```

* Always include HTTP status code in output

... as suggested by @sjakobi

* Use "not found" wording for 404 message

This is closer to the official wording for the error message

* Compress error message formatting

There's no need to put the URL and status code on separate lines since
they are compact
2019-08-29 18:01:43 +00:00
Gabriel Gonzalez
0b3dae7496 Document Dhall support for caching protected imports (#1247)
Fixes #1234
2019-08-25 22:59:38 +00:00
Philip Potter
06dc9ab55f [dhall format] Prefer unquoted URLs (#1235)
* [dhall format] Prefer unquoted URLs

This updates `dhall format` to prefer unquoted URLs.

I included the test cases described in #1109, but along the way I
discovered a standard bug so I have opened dhall-lang/dhall-lang#704 to
fix it.  This change depends on that upstream fix.

Fixes #1109.

* pull in latest dhall-lang

* skip unimplemented tests
2019-08-22 21:28:26 +00:00
Gabriel Gonzalez
f3d6a7ac61 Improve diff for non-empty lists (#1244)
* Improve diff for non-empty lists

... as discussed in https://github.com/dhall-lang/dhall-haskell/issues/1243

* Improve diff for empty list

... as suggested by @sjakobi
2019-08-21 01:42:26 +00:00
Simon Jakobi
f75d98aa9c
Update dhall-lang submodule, skip test failures (#1240)
The new tests were introduced in dhall-lang/dhall-lang#698.

Also:

* Document shortcommings of Expr's Eq and Ord instances.
  Haddock for GHC-7.10.3 can't handle haddocks on vanilla derived
  instances, so we use StandaloneDeriving.

* Add explanation for skipped AssertNaN test
2019-08-19 18:51:13 +02:00
Eric Conlon
96c94ddfc4 :help command in repl (#1237)
* :help command in repl (#1236)

* review feedback
2019-08-18 19:42:56 +00:00
Gabriel Gonzalez
0348d18ac7 Fix documentation for UnionInputType (#1230)
Fixes #1227
2019-08-10 00:12:35 +00:00
Gabriel Gonzalez
c392f4a286 Fix NaN to be judgmentally equivalent to itself (#1231)
... as required by the standard

Fixes #1224
2019-08-09 23:32:53 +00:00
MaxOw
ec8bcf0d63 Add autoWithFix helper function for Interpreting recursive data types (#1161) (#1195)
* Add autoWithFix helper function (#1161)

* Fix some dependencies. Remove TypeApplications extension.

* Pin recursion-schemes to appease hydra.

* Implement review suggestions.

* Fix error in documentation.
2019-08-09 20:09:09 +00:00
Simon Jakobi
ce17b86bc5 Make equivalences of terms of different types fail during typechecking (#1225)
* Make equivalences of terms of different types fail during typechecking

This fixes the `EquivalenceNotSameType` test from
https://github.com/dhall-lang/dhall-lang/pull/698.

* s/assertion/equivalence
2019-08-09 17:50:11 +00:00
Simon Jakobi
94f9f75c6a Remove some redundant sorting during normalization (#1228)
We can rely on the result of an operation on two sorted maps being
sorted already.
2019-08-09 16:00:07 +00:00
Simon Jakobi
c2cc641408 Implement missing rules for field selection normalization (#1179)
…as standardized in https://github.com/dhall-lang/dhall-lang/pull/682.
2019-08-08 14:36:01 +00:00
Simon Jakobi
97f0ff8552 Simplify Natural/subtract when its arguments are equivalent (#1220)
…as standardized in https://github.com/dhall-lang/dhall-lang/pull/685.
2019-08-08 02:39:21 +00:00
Gabriel Gonzalez
ecb5814f59 Fix diffs for lists (#1213)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1211

The original implementation of diffing two lists in #450 attempted to add a
special case in the logic for when the list had no common elements.
However, this led to a bug where the two lists would display different
if they were both empty.

lists would never render.

This change fixes that by removing the special case.

The new output for the linked example is:

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

Error: Assertion failed

[ …
, - 1
, …
, + 55
]

16│                assert : fibs 10 ≡ [ 0, 1, 2, 3, 5, 8, 13, 21, 34, 55 ]
17│

(stdin):16:16
```
2019-08-08 02:00:00 +00:00
Simon Jakobi
b9375fc9c7 Implement "Simplify ⫽ when its arguments are equivalent" (#1196)
…as standardized in https://github.com/dhall-lang/dhall-lang/pull/684
2019-08-08 00:14:08 +00:00
Simon Jakobi
0871fcd857 Prevent "Natural/subtract 0" from causing a panic (#1208)
Previously, normalizing `Natural/subtract 0` would result in this
error:

    ⊢ Natural/subtract 0

    Error: Compiler bug

    An ill-typed expression was encountered during normalization.
    Explanation: This error message means that there is a bug in the Dhall compiler.
    You didn't do anything wrong, but if you would like to see this problem fixed
    then you should report the bug at:

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

    CallStack (from HasCallStack):
      error, called at src/Dhall/Eval.hs:865:38 in dhall-1.25.0-FCOZ7uxqivz8dkVwuN7aED:Dhall.Eval

This updates the dhall-lang submodule to include a new testcase added
in https://github.com/dhall-lang/dhall-lang/pull/692.
2019-08-07 02:38:56 +00:00
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