Commit Graph

307 Commits

Author SHA1 Message Date
Gabriel Gonzalez
b3b6bb4e1d Partially fix whitespace parsing performance regression (#1512)
* Partially fix whitespace parsing performance regression

This undoes some of the performance regression introduced
in https://github.com/dhall-lang/dhall-haskell/pull/1483

Before #1483:

```
benchmarked Line comment
time                 11.86 ms   (11.69 ms .. 11.98 ms)
                     0.999 R²   (0.999 R² .. 1.000 R²)
mean                 11.84 ms   (11.79 ms .. 11.89 ms)
std dev              129.4 μs   (107.2 μs .. 164.1 μs)

benchmarked Block comment
time                 13.20 ms   (13.00 ms .. 13.41 ms)
                     0.999 R²   (0.998 R² .. 1.000 R²)
mean                 13.59 ms   (13.41 ms .. 13.94 ms)
std dev              600.0 μs   (142.2 μs .. 953.7 μs)
```

After #1483:

```
benchmarked Line comment
time                 288.7 ms   (282.8 ms .. 294.7 ms)
                     1.000 R²   (0.999 R² .. 1.000 R²)
mean                 292.3 ms   (290.8 ms .. 294.6 ms)
std dev              3.156 ms   (2.216 ms .. 4.546 ms)

benchmarked Block comment
time                 286.2 ms   (280.9 ms .. 292.6 ms)
                     0.999 R²   (0.998 R² .. 1.000 R²)
mean                 290.6 ms   (288.3 ms .. 292.9 ms)
std dev              3.875 ms   (2.866 ms .. 5.500 ms)
```

After this change:

```
benchmarked Line comment
time                 61.44 ms   (60.37 ms .. 63.03 ms)
                     0.999 R²   (0.997 R² .. 1.000 R²)
mean                 61.41 ms   (60.74 ms .. 62.25 ms)
std dev              1.341 ms   (945.0 μs .. 1.901 ms)

benchmarked Block comment
time                 61.83 ms   (60.97 ms .. 63.14 ms)
                     0.999 R²   (0.998 R² .. 1.000 R²)
mean                 61.16 ms   (60.33 ms .. 61.85 ms)
std dev              1.396 ms   (1.011 ms .. 1.907 ms)
```

* Correctly parse `https://example.com usingBla`

... as caught by @sjakobi
2019-11-04 02:12:02 +00:00
Simon Jakobi
7eec31d1d7 Parse whitespace more precisely (#1483)
This is preparatory work for #1454.

This also fixes some cases where dhall would previously accept
malformatted inputs.

The changes to dhall-lsp-server are mostly untested. See #1510.

Co-authored-by: Gabriel Gonzalez <Gabriel439@gmail.com>
2019-11-03 19:42:58 +00:00
Gabriel Gonzalez
cc1814be98 Add Dhall.function (#1507)
... which is the non-typeclass version of the `Interpret` instance for
`a -> b`
2019-11-02 04:36:27 +00:00
Gabriel Gonzalez
7ea5f6fa51 Remove support for fusion (#1478)
* Remove support for fusion

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

* Update `dhall.cabal` to match the latest Prelude

* Update `dhall-lang`

... and blacklist tests we don't support yet

* Add missing files to `dhall.cabal`
2019-11-01 05:33:05 +00:00
Gabriel Gonzalez
b843cae5d2
Improve encoding/decoding speed (#1500)
... by not going through a `Term` intermediate

This gives a ~28% performance in decoding improvement, which means that
cache looks are not faster.

Here are the new decoding benchmarks before and after this change:

Before:

```
benchmarked Issue #108/Binary
time                 266.5 μs   (265.7 μs .. 267.4 μs)
                     1.000 R²   (1.000 R² .. 1.000 R²)
mean                 266.3 μs   (265.6 μs .. 267.1 μs)
std dev              2.418 μs   (1.891 μs .. 3.436 μs)

benchmarking Kubernetes/Binary ... took 36.94 s, total 56 iterations
benchmarked Kubernetes/Binary
time                 641.3 ms   (623.0 ms .. 655.4 ms)
                     0.999 R²   (0.997 R² .. 1.000 R²)
mean                 679.7 ms   (665.5 ms .. 702.6 ms)
std dev              29.48 ms   (14.15 ms .. 39.05 ms)
```

After:

```
benchmarked Issue #108/Binary
time                 282.2 μs   (279.6 μs .. 284.7 μs)
                     1.000 R²   (0.999 R² .. 1.000 R²)
mean                 281.9 μs   (280.7 μs .. 287.7 μs)
std dev              7.089 μs   (2.550 μs .. 15.44 μs)
variance introduced by outliers: 11% (moderately inflated)

benchmarking Kubernetes/Binary ... took 27.57 s, total 56 iterations
benchmarked Kubernetes/Binary
time                 499.1 ms   (488.1 ms .. 506.6 ms)
                     0.999 R²   (0.998 R² .. 1.000 R²)
mean                 498.9 ms   (494.4 ms .. 503.9 ms)
std dev              8.539 ms   (6.236 ms .. 12.56 ms)
```

There's a slight performance regression for the decoding microbenchmark, but
in practice my testing on real examples matches performance improvements seen
in the larger benchmark based on an example cache product from
`dhall-kubernetes`.

Note that is a breaking change because:

* There is no longer a `FromTerm` nor `ToTerm` class.  Now we use the
  `Serialise` class and `{encode,decode}Expression` now work on `ByteString`s
  instead of `Term`s

* I further narrowed the types of several encoding/decoding utilites to expect a
  `Void` for the first type parameter of `Expr`

* This is a regression with respect to stripping 55799 CBOR tags, mainly
  because properly handling the tags at every possible point in the syntax tree
  would considerably complicate the code
2019-10-31 20:05:22 -07:00
Simon Jakobi
9d16602388
Follow-up fixes for #1485 (#1489) 2019-10-30 16:13:51 +01:00
Simon Jakobi
d5b7c3860e
Rename Type to Decoder, InputType to Encoder (#1485)
* s/InputType/Encoder

* Rename input* functions on the ToDhall side to encode*

* Haddocks: Use "encoder" instead of "injector"

* s/Type/Decoder

* Haddocks: Stop using the word "parser" for Decoders

* Rename encode{Record,Union} to {record,union}Encoder
2019-10-30 14:24:15 +01:00
Simon Jakobi
343e64e0ce Update reservedIdentifiers (#1473)
* Add `missing` and `assert`
* Reformat them to match the grammar
2019-10-30 12:31:30 +00:00
Gabriel Gonzalez
1349a50f91 Add Integer/{clamp,negate} built-ins (#1486)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/780
2019-10-29 17:21:00 +00:00
Gabriel Gonzalez
1a0778e9fa Don't include context in default output (#1482)
The motivation for this is so that `dhall` can be made much faster on very
large projects like `dhall-kubernetes-charts` where vast majority of the time
is spent rendering the very large `Context` when type-checking fails, delaying
the user from getting to the actual error message.

The `Context` also gets in the way of the user noticing the (far more useful)
type diff, but the performance cost is the primary motivation for this change.

If the user wants the context they can still use the `--explain` flag.
2019-10-27 23:52:50 +00:00
Gabriel Gonzalez
5c26dace8b Improve parsing error messages (#1443)
* Improve parsing error messages

The main changes are:

* Don't quote expected tokens in the error message (to avoid visual clutter)
* Consolidate expected tokens into simpler categories (e.g. "operator" or
  "literal") instead of listing them all

For example, this would be an error message before this change:

```
$ dhall <<< '1 + [1'
dhall:
Error: Invalid input

(stdin):2:1:
  |
2 | <empty line>
  | ^
unexpected end of input
expecting "!=", "&&", "++", "->", "//", "//\\", "/\", "==", "===", "merge", "toMap", "||", "→", "∧", "≡", "⩓", "⫽", '#', '(', '*', '+', ',', '.', ':', '?', ']', built-in expression, double infinity, double literal, import, integer literal, label, list literal, natural literal, record type or literal, text literal, union type, or whitespace
```

... and this would be an error message after this change:

```
$ dhall <<< '1 + [1'
dhall:
Error: Invalid input

(stdin):1:4:
  |
1 | 1 + [1
  |    ^^^^
unexpected " [1<newline>"
expecting (, import, keyword, label, or literal
```

* Fix test failures

* Fix warnings
2019-10-27 03:34:33 +00:00
Gabriel Gonzalez
90315e9eda Fix dhall freeze to always re-freeze an import (#1471)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1470

`dhall freeze` no longer attempts to use the cache to fetch an import since
the cache might not match the underlying import any longer.  Instead,
`dhall freeze` now always attempts to fetch the underlying import to
compute the new hash.
2019-10-24 15:19:09 +00:00
Simon Jakobi
8f2c28a5dc
Move normalization code from Dhall.Core to a new module Dhall.Normalize (#1452)
Also try to decouple a few modules from Dhall.Core.

Closes #1127.
2019-10-24 00:01:02 +02:00
Simon Jakobi
6c2db48d42 Fix operator precedence in the parser (#1466)
Previously some operator expressions were associated incorrectly, e.g.

* a || b + c  -> (a || b) + c
* a // b == c -> (a // b) == c

Fixes #1457.
2019-10-23 19:50:17 +00:00
Michael Gilliland
16e6a12c3d Resolve #1451: fix format --check given STDIN input. (#1462)
* Resolve #1451: fix `format --check` given STDIN input.

I'm not really sure if this is the "best" approach so let me know if you
know a way to simplify this.

The issue was that `getExpressionAndHeader` was doing a second
`IO.getContents` (thus reading STDIN twice).

* Rename `Input` constructor.
2019-10-23 14:51:06 +00:00
Basile Henry
3c99d5c988 Fix precedence of the import alt operator (#1460)
* Add test for format precedence #1455

* Fix precedence of the import alt operator
2019-10-23 01:19:50 +00:00
Basile Henry
69b228454e Test that dhall format is idempotent (#1427) 2019-10-22 19:45:08 +02:00
Philip Potter
1fed252488 fix index in MismatchedListElements (#1448)
If you run `dhall --explain` to explain a type error from a list with
mismatched elements, the index of the offending term was wrong.  For a
minimal example, you can run:

    dhall --explain <<<'[0, True]'

The problem is that `i` is an index into the tail of the list, not into
the whole list.  The fix is just to add one to it to correct for the
missing head.
2019-10-20 22:34:00 +00:00
Gabriel Gonzalez
47383de623 Update Dhall.Tutorial module (#1439)
* Update `Dhall.Tutorial` module

This overhauls the `Dhall.Tutorial` module to reflect recent changes to
the language (and also to link to external documentation when possible).

* Fix doctests

* Rephrase import syntax caveat

... as suggested by @sjakobi

* Explain `<<<`

... as suggested by @sjakobi@

* Rephrase things

... as suggested by @sjakobi

* `s/The annotated/This/`

... as caught by @sjakobi

* Add commas to description of link to built-ins reference

... as caught by @sjakobi

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

* Remove paragraph describing role of Prelude

* Update dhall/src/Dhall/Tutorial.hs

... as suggested by @sjakobi

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>
2019-10-20 00:38:07 +00:00
Simon Jakobi
a944d12591 Add --file option for dhall hash (#1445)
To use the existing utilities in Dhall.Main more easily, I have moved
the implementation to Dhall.Main.
2019-10-19 22:38:44 +00:00
Simon Jakobi
bec6ce610f Move syntax things from Dhall.Core to a new module Dhall.Syntax (#1440)
This partially addresses #1127.
2019-10-19 20:13:22 +00:00
Steven Leiva
c284c19c11 Add --no-cache to dhall type. (#1441) 2019-10-19 13:47:27 +00:00
Simon Jakobi
301477de59 Rename Interpret to FromDhall, Inject to ToDhall (#1437)
* Rename Interpret to FromDhall

The "Interpret" name remains in `InterpretOptions`, which are
actually used for marshalling in both directions.

* s/injectThenInterpretIsIdentity/embedThenExtractIsIdentity

* s/Inject/ToDhall

* s/shouldInjectInto*/shouldEmbedAs*

* Keep Interpret and Inject as constraint synonyms for compatibility

… as suggested by @Gabriel439.
2019-10-19 03:24:49 +00:00
Steven Leiva
270adddf37 Add --no-cache flag to dhall resolve. (#1436) 2019-10-19 02:40:27 +00:00
Simon Jakobi
b75962a405 Use a more conventional spelling for "etags", mostly just use "tags" (#1432)
The previous "ETags" spelling was likely to cause confusion with HTTP ETags:
https://en.wikipedia.org/wiki/HTTP_ETag
2019-10-19 01:59:29 +00:00
Steven Leiva
9d739b553a Do not warn about cache on --no-cache. (#1434) 2019-10-18 20:33:53 +00:00
Gabriel Gonzalez
58fcc6fe90 Fix formatting in error message (#1429) 2019-10-17 08:51:56 +00:00
Gabriel Gonzalez
03ca91baca
Fix CI to properly reject incomplete haddocks (#1418)
My first attempt to do this in #1416 did not correctly reject incomplete
haddocks, which this change fixes
2019-10-16 19:49:44 -07:00
tenniscp25
a343b19a63 Marshalling HashMap (#1394) (#1426) 2019-10-16 15:53:33 +00:00
Frederik Ramcke
3f6a5ad8df Restore idempotency when formatting comments (#1415)
* Move prefix out of renderSrc

This reduces the complexity of renderSrc slightly without affecting
anything else much.

* Make formatting of comments idempotent

Fixes #1413. Previously the formatter would insert an additional line
break before some comments whilst preserving existing line breaks. In
order to restore idempotent behaviour, we need to strip a leading
newline character from the comment string in those cases, if present.

* Test idempotency when formatting comments

Test case taken from @AJChapman's bug report (#1413).

* Change argument order of renderSrc

Reads a bit more idiomatic, as suggested by @sjakobi.
2019-10-15 15:01:10 +00:00
Jie
1cd856a449 [#1392] Injecting Data.Map (#1412)
* [#1392] Injecting Data.Map

* injecting via Generic

* Explicit instance

* Cleanup code

* Minor code cleanup

* Property testing for Inject/Interpret

* Refactor test

* Adding TypeApplications to .cabal

* No more TypeApplications

* Simplified tests using extract

* Added test for Text amnf fixed Natural import

* Update dhall/dhall.cabal

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

* Update dhall/dhall.cabal

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>
2019-10-15 11:27:29 +00:00
Gabriel Gonzalez
17fb0e3c46
100% haddock coverage (#1416)
This updates the `dhall` package to have 100% haddock coverage and
also updates CI to enforce this going forward.

This also includes a change to deprecate the `X` type synonym, which
I noticed along the way
2019-10-13 22:22:39 -07:00
Gabriel Gonzalez
4b8b8cd730
Add new record completion operator (#1375)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/767
2019-10-11 08:26:51 -07:00
Jie
34f706ed93 [#1395] Marshalling Set and HashSet (#1405)
* [#1395] Marshalling Set and HashSet

* Update dhall/src/Dhall.hs

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

* Update dhall/src/Dhall.hs

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

* Added distinctList

* setFromDistinctList updates

* Doctests abour ordering

* both set and hashset can ignore or fail with duplicates

* Comments on instances

* Moved length computation deeper

* Little wibble

Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>
2019-10-10 16:31:44 +00:00
Dima
5b8ae442c8 Add tags subcommand (#1398)
Fixes #370.
2019-10-10 16:16:20 +02:00
Gabriel Gonzalez
a24ddfc3b9 Add support for leading separators (#1355)
* Add support for leading separators

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

Note that this does not yet change the formatter to use them

* Update `dhall-lang` submodule

* Fix `dhall.cabal` to mention new Prelude files

* Remove duplicate lines
2019-10-10 05:01:34 +00:00
Michael Gilliland
1dba96c2c8 Resolves #1408: Add more detail in --explain when toMap has the w… (#1411)
* Resolves #1408: Add more detail in `--explain` when `toMap` has the wrong type.

Specifically, add common reason of using `{}` for record value.

For example,
``` shell
echo 'toMap {}' | ~/.local/bin/dhall
```

Outputs

> Error: ❰toMap❱ expects a record value
>
> Explanation: You can apply ❰toMap❱ to any homogenous record, like this:
>
>
>     ┌─────────────────────────────────────────────────────────────────────┐
>     │ let record = { one = 1, two = 2 }
> │
>     │ in  toMap record : List { mapKey : Text, mapValue : Natural}
> │
>     └─────────────────────────────────────────────────────────────────────┘
>
>
> ... but the argument to ❰toMap❱ must be a record and not some other
> type.
>
> Some common reasons why you might get this error:
>
> ● You accidentally provide an empty record type instead of an empty
> record when
>   using ❰toMap❱:
>
>
>     ┌──────────┐
>     │ toMap {} │
>     └──────────┘
>             ⇧
>             This should be ❰{=}❱ instead
>
> ────────────────────────────────────────────────────────────────────────────────
>
> 1│ toMap {}
>
> (stdin):1:1

* Add type annotation to `toMap` suggestion.
2019-10-09 23:54:42 +00:00
Jie
3e5cb34922 [#1381] Word* types to Natural, not Integer (#1387)
* #1381 Word* to Natural

* Added instance for Word

* Got rid of linting issues

* Added docsets

* Added comments

* Revert Crypto to master version

* Spread the doctests

* Improve Docstring
2019-10-07 17:54:42 +00:00
Andika Demas Riyandi
bf40ec52a1 add --output options to dhall (#1399) 2019-10-07 09:51:30 +00:00
Simon Jakobi
5e7794c652
Update dhall-lang submodule (#1403)
This includes some simplifications/optimizations for the `ToTerm DhallDouble` instance.

Most notably we let `cborg` take care of the correct encoding of NaNs:
See `Codec.CBOR.Write.doubleMP`:
  977c0c0820/cborg/src/Codec/CBOR/Write.hs (L571-L573)
2019-10-07 10:39:59 +02:00
Andika Demas Riyandi
9de7ac51a8 dhall: make lazyText use strictText (#1401) 2019-10-06 14:00:22 +00:00
Jie
cc3e50eaf1 [#1378] instance Interpret () (#1388)
* [#1378] instance Interpret ()

* Remove instance from tests
2019-10-06 03:46:25 +00:00
Curtis
c8ddedcc8c [#1389] Change Interpret [a] to use list (#1397) 2019-10-06 02:02:08 +00:00
Simon Jakobi
d172e4b677 Add 'instance Interpret (Map k v)' (#1391)
… and helper 'Type's 'map' and 'pairFromMapEntry'
2019-10-05 16:37:58 +00:00
Simon Jakobi
613a44d512 Add Interpret and Inject instances for Void (#1382) 2019-10-04 06:06:38 +00:00
Simon Jakobi
94ff61b152 Fix formatting of multi-argument function applications (#1380)
merge-expressions with additional arguments are also formatted with
consistent indentation for all arguments. E.g.

    merge
      { x = Natural/even }
      < x >.x
      1111111111111111111111111111111111111111111111111111111111

Fixes a small regression introduced in 7634ee7.
2019-10-04 04:47:51 +00:00
Simon Jakobi
7538552a7f Always break annotated let-bindings (#1372)
Fixes #1370.
2019-10-04 03:42:15 +00:00
Simon Jakobi
7634ee740b Fix indentation for multiline Some-, toMap- and merge-expressions (#1377)
The loss of indentation for toMap and merge was due to
75e6cc5ca7. I have included Some for
consistency.

Fixes #1376.

Also improve format test failure messages
2019-10-03 22:59:42 +00:00
Simon Jakobi
6bc182a08a Move parser-pretty-printer note to D.Pretty.Internal (#1374)
I've toned it down a bit since the correspondence doesn't seem
to be as close anymore as it once was.

Fixes #1364.
2019-10-03 02:49:27 +00:00
Simon Jakobi
5a2ee1ca57 Improve type-inference of annotated list literals (#1366)
* Remove a redundant check of the type annotation.

* Replace dead code for processing the list elements
  with an error.

* Document the ListLit invariant.

Closes https://github.com/dhall-lang/dhall-haskell/issues/1359.
2019-10-02 05:17:03 +00:00