Commit Graph

436 Commits

Author SHA1 Message Date
Simon Jakobi
acd5144ef7 dhall repl: Don't normalize inferred types (#1338)
Context: #1300
2019-09-26 17:33:42 +00:00
Simon Jakobi
87f352d66e Fix a type in the nestedReduction test case (#1339) 2019-09-26 16:43:36 +00:00
Simon Jakobi
72bf46b600 Add a Show instance for Val (#1344)
Since Val contains functions, its Show instance cannot be
derived in the usual way without exposing a non-standard Show
instance for (Val a -> Val a). Instead, we rely on the user to
provide a fitting instance, e.g. by importing Text.Show.Functions.
2019-09-26 15:58:51 +00:00
Simon Jakobi
f825dd18d9 Add link to GHC ticket for rounding issue in Integer/toDouble (#1348) 2019-09-26 15:13:43 +00:00
Gabriel Gonzalez
5b136dfa2c
Version 1.26.0 → 1.26.1 (#1336) 2019-09-24 21:14:33 -07:00
Gabriel Gonzalez
328a6739a8 Build against Diff-0.4.* (#1343)
Related to https://github.com/commercialhaskell/stackage/issues/4842
2019-09-25 03:29:02 +00:00
Gabriel Gonzalez
1682c4c5f2 Fix inferred type for record projection (#1342)
This ensures that record projection correctly sorts the fields in the
inferred type

This fixes the regression test in
https://github.com/dhall-lang/dhall-lang/pull/750
2019-09-25 02:34:51 +00:00
Javier Neira
08747af8d3 Warn about missing cache directory (#1320)
* Warning action about missing cache dir

* Add warning to executable

* Correct duplicate cacheName in getCacheFile

* Warn if dhall-haskell cache dir is not usable

* Improve warn message

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Correct plural

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Improve syntax

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Use runMaybeT to make 2 step warnings

* Add FlexibleContexts to make happy lts-6

* Catch IOException's when handling cache dir

This make the haskell impl follow the standard.

* Correct unwanted identantion

* Push warnings to get* wrapper functions

* Remove unnecessary lang extension

* Inline warnings in get* functions

* Being consistent with break lines

* Apply suggestions from code review

About phrasing, formatting, syntax, etc

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

* doesPathExist is not in directory-1.2.2.0

* Make message fit in 80 cols
2019-09-24 08:59:58 +00:00
Gabriel Gonzalez
95809b467d
Use Dhall.Eval for type-checking (#1335)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1306

The following comment describe how this works in depth:

https://github.com/dhall-lang/dhall-haskell/issues/1129#issuecomment-532928798

The short explanation is that we can substantially speed up type-checking
by not substituting `let` expressions and instead adding the bound variable
to the context.  This is the same as the type-checking "fast path" that
we had before adding dependent types, except this time it works even in the
presence of dependent types.

The main difference is that we add the `let`-bound type *and* value to the
context and use `Dhall.Eval.conv` to perform equivalence checking instead of
`Dhall.Core.judgmentallyEqual`.
2019-09-22 10:37:26 -07:00
Gabriel Gonzalez
183cc9291a Add --censor flag support for censoring type errors (#1329)
* Add `--censor` flag support for censoring type errors

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

* Reuse `censorText`

... as caught by @sjakobi

* Remove `typeWith` refactor

... as caught by @sjakobi

This is a vestige of a refactor that I reverted incompletely

* Reuse `Dhall.Core.censorText` in `Dhall.Parser` module

... as suggested by @sjakobi
2019-09-22 04:44:51 +00:00
Simon Jakobi
b556a65644 Handle --version consistently (#1334)
* dhall --version

* dhall-to-bash --version

* dhall-to-nix --version

* dhall-lsp-server --version
2019-09-22 03:55:26 +00:00
Vanessa McHale
fe748e2884
Dhall version (#1332)
* Add Dhall.Version module

* Add Paths_dhall to Autogen-Modules
2019-09-20 15:53:13 +00:00
Patrick Mylund Nielsen
fa84b0dc19
Different with-http CPP check; fix remote imports in GHCJS (#1330)
Completes the changes in #1311
2019-09-20 10:44:15 -04:00
Simon Jakobi
0ef00bf5e3 Fix running the type-inference failure tests (#1326)
This fixes several bugs introduced in
fddce0b8cf.
2019-09-19 15:46:07 +00:00
Ollie Charles
8ead6012e9 dhall: Support GHC 8.8 (#1324) 2019-09-19 14:14:54 +00:00
Gabriel Gonzalez
54241f88c7 Disable 1-field simplification by default (#1321)
* Disable 1-field simplification by default

This builds on top of #1315 to minimize disruption by disabling the
breaking change by default and instead requiring the user to opt in
by setting a new `collapseSingletonRecords` option to `True`.

The additional tests added to verify this also caught a bug in the
`Interpret` instance for functions, which this change also fixes.

* Change to three-valued option

... based on feedback from @sjakobi

This change the option to a three-valued option:

* `Bare`    - 1-field constructor does not include a nested record
* `Wrapped` - 1-field constructor always includes a nested record
* `Smart`   - Named fields that don't begin with `_` include a nested record

The default is `Wrapped` (for backwards compatibility), but users will
probably want to eventually switch to `Smart`

* Don't depend on `fieldModifier` for determining if a field is anonymous

... as suggested by @sjakobi
2019-09-19 07:07:23 +00:00
Simon Jakobi
2fcbf84e2f dhall type: Add --quiet option (#1325)
Closes #1323.
2019-09-19 05:45:39 +00:00
Ryan Scott
62ee6ff249 Give dhall repl's turnstile an ASCII variant (#1327)
This makes `⊢` print as `|-` under `dhall --ascii repl`.
2019-09-18 12:29:08 -07:00
Gabriel Gonzalez
8bced75668 Refactor Dhall.Eval (#1322)
* Refactor `Dhall.Eval`

This updates the style of `Dhall.Eval` to match the stylistic
and naming conventions of the rest of the `dhall` package.

* Import `Data.Set` fully qualified

... as suggested by @sjakobi

* Re-enable warnings

... as wished by @sjakobi

* Remove `{eval,conv,quote}E` synonyms

... as suggested by @sjakobi

* INLINE `qVar`

... literally

... as suggested by @sjakobi

* Remove unnecessary `MIN_VERSION_base(4,8,0)`

... as caught by @sjakobi

We still need `CPP` elsewhere within the same file, though

* Fix style of `vProjectByFields` function

... as caught by @sjakobi
2019-09-18 00:29:22 +00:00
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
Gabriel Gonzalez
65710954cf
Version 1.25.0 → 1.26.0 (#1286) 2019-09-11 19:37:25 -07: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
Gabriel Gonzalez
70948b3cba
Build against profunctors-5.5.* (#1299) 2019-09-10 18:39:11 -07: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
d1d0b3d462 Get rid of some CPP by upgrading to generic-random-1.3 (#1292) 2019-09-08 18:42:22 +00:00
Gabriel Gonzalez
04956193e9 Build against ansi-terminal-0.10.* (#1287) 2019-09-07 14:06:57 +00:00
Vanessa McHale
eef23eb229 Bump memory (#1285) 2019-09-06 19:56:26 -05: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
Gabriel Gonzalez
4445eee871 Use tasty-expected-failure (#1250)
* Use `tasty-expected-failure`

... to exercise tests that we currently skip

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

* Fix bounds syntax for `tasty-expected-failure`

... as caught by @sjakobi

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>

* Fix GHC 8.6 build failure

`tasty-expected-failure` needs to be bumped to include revision 1, which
supports GHC 8.6

* Fix build failure for older `tasty-hunit` versions

`tasty-hunit-0.9.2` and older have the wrong type for `assertFailure`

* Fix `stack` build for LTS 6

... and sort the list of `extra-deps`
2019-08-30 03:31:19 +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
quasicomputational
4c6d76e4a8 Run all of the dhall package's tests on Appveyor. (#1142)
This entails a bunch of surgery to the package set used with LTS 6.
Because I was seeing errors, I disabled allow-newer and found this
consistent package set. I also needed a newer version of `tls`, which
entailed a bunch of bumps.
2019-08-20 14:38:01 +00:00
Simon Jakobi
93711aecf8 Throw error when union value is incompatible with Inline nesting (#1226) 2019-08-20 03:12:16 +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
fc3f79a9df Make the number of QuickCheck tests overridable on the CLI (#1206)
You can now _increase_ the number of QuickCheck tests with
the --quickcheck-tests CLI option, e.g.

    cabal test dhall:tasty --test-options "--quickcheck-tests 1000000"
2019-08-07 06:33:06 +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
Ollie Charles
ae788fde89 Add bounds to either dependency (#1202)
`ealt` (which we use) is only available from version 5 up.
2019-08-06 00:48:48 +00: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
Simon Jakobi
2cf6a1ba74
Update dhall-lang to latest master (#1200)
…to fix build failures due to the submodule pointing at an unreachable commit.

* Disable a currently failing testcase.
* Update the extra-source-files in dhall.cabal.
2019-08-05 02:16:41 +02: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
Gabriel Gonzalez
15bf9c8e53
Fix standard version typo in CHANGELOG (#1180)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1168
2019-08-01 22:44:46 -07: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
d45f3ec46b
Version 1.24.0 → 1.25.0 (#1156) 2019-07-28 21:46:32 -07: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
34e6791f25 Make regression test #151 test the right thing (#1153)
From dhall/tests/Dhall/Test/Regression.hs:

    These two examples contain the following expression that loops
    infinitely if you normalize the expression before type-checking the
    expression:
    (λ(x : A) → x x) (λ(x : A) → x x)

The problem is typechecking that snipped already fails even before we
hit the self-application with the following error:
    Unbound variable: A

This is fixed by quantifying over `A`, resulting in the desired type
error:
    Error: Not a function
    1│                           x x
2019-07-26 01:43:09 +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
Simon Jakobi
88d6671e38
Enable the fixed potPourri test (#1144)
Context: https://github.com/dhall-lang/dhall-lang/pull/655
2019-07-21 15:21:20 +02: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
Gabriel Gonzalez
cbd6a6543d Support lens-family-core-2.0.0 (#1141)
Related to https://github.com/commercialhaskell/stackage/issues/4725
2019-07-20 12:18:49 +00:00
Simon Jakobi
8aa8add453 Catch errors in normalizeWithM when testing it (#1139)
Context: #1138
2019-07-20 04:30:42 +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
f0d017d7c5 Fix test suite to accept expected decoding failures (#1136)
This will be necessary for https://github.com/dhall-lang/dhall-lang/pull/640
2019-07-19 21:11:22 +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
quasicomputational
0df6362a9d Make the tests build with GHC 7.10. (#1134) 2019-07-18 23:11:51 +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
Gabriel Gonzalez
462f82a0f8 Build against optparse-applicative-0.15 (#1081)
Related to https://github.com/commercialhaskell/stackage/issues/4693
2019-07-07 11:49:11 +00:00
Simon Jakobi
f873b0d66e Increase coverage of acceptance tests (#1072)
* dhall:tasty: Unskip a few tests

These remain broken:

- tests/parser/failure/annotation
- tests/parser/failure/missingSpace
- tests/parser/failure/unit/ImportEnvWrongEscape
- tests/parser/failure/unit/ListLitEmptyAnnotation
- tests/parser/failure/unit/ListLitEmptyPrecedence
- tests/parser/success/unit/MergeParenAnnotation

* Typo

* Add binary-decode failure tests

A few pass, but these are broken:

- tests/binary-decode/failure/unit/ApplyNoArgs
- tests/binary-decode/failure/unit/LambdaExplicitlyNamedUnderscore
- tests/binary-decode/failure/unit/NaturalNegativeOne
- tests/binary-decode/failure/unit/PiExplicitlyNamedUnderscore
- tests/binary-decode/failure/unit/VariableExplicitlyNamedUnderscore

* dhall:tasty: Add semantic-hash tests
2019-07-07 11:00:55 +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
Simon Jakobi
15e981f61c
Fix benchmarks, run them on AppVeyor (#1033)
Since we only want to ensure that the benchmarks continue to
work, we use the following benchmark arguments to run them
as quickly as possible:

- `--quick` ensures that gauge runs only a single sample.
- `--min-duration=0` sets the number of iterations per sample to 1.
- `--include-first-iter` causes gauge to accept that one iteration
  instead of discarding it and running a second one.

This also removes the dhall-command benchmark:

This was a non-standard benchmark that failed when run
without input from stdin. To replace this profiling tool,
I have added instructions for profiling the main executables
to the README.
2019-07-01 12:52:43 +02: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
Dmitry Dolgov
0bf4e41020 Fix appveyor tests (#1037)
Fixes #1034

Fixes the `import/success/hashFromCache`  test on Windows

Disables currently broken dhall-lsp-server tests
2019-06-30 14:35:55 +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