* Fix parsing of variables with keyword prefixes
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1583
Note that one prefix is not yet supported: `missing`, since fixing that is
not easy for the current parsing implementation (as far as I can tell).
* Add regression test
... as suggested by @sjakobi
I'm not upstreaming this into the standard test suite yet because the
current parser cannot handle `missing`, which would be necessary to
generate the corresponding CBOR
While looking at some core I noticed that `null` for Dhall.Map used
the default `foldr`-based definition. I fixed that and added a few
more small optimizations.
* Use foldl' over foldl
As suggested by @sjakobi. Germans banding together in the fight against
laziness!
* Add missing foldl' imports
* Ups, forgot one!
* Fix swallowed whitespace in Src annotations
The parser annotated application expressions incorrectly: whitespace
between function and argument was swallowed when constructing the Src
annotation. This bug resulted in strange behaviour in the hovering
functionality in dhall-lsp-server.
As an example, previously the Dhall expression `0 0` would be parsed as
```
Note (Src {..., srcText = "00"})
(App (Note (Src {..., srcText = "0"}) (NaturalLit 0))
(Note (Src {..., srcText = "0"}) (NaturalLit 0)))
```
while we now get
```
Note (Src {..., srcText = "0 0"})
(App (Note (Src {..., srcText = "0"}) (NaturalLit 0))
(Note (Src {..., srcText = "0"}) (NaturalLit 0)))
```
as expected.
* Use foldl' over foldl
As suggested by @sjakobi. Note that there are quite a few more
occurences of foldl where we don't actually need laziness, but I leave
that for someone else to fix :)
* Revert "Use foldl' over foldl"
This reverts commit 1bd9a5424cf06a60f20b6e408fba186952cbb9d1.
This patch improves some of the error messages:
1) Bad field names on record completion:
```
echo "{Type = {x : Integer, y : Bool}, Default = {y = True}}::{x = 5}" |stack exec dhall
Use "dhall --explain" for detailed errors
Error: Completion record is missing a field: default
1│ {Type = {x : Integer, y : Bool}, Default = {y = True}}::{x = 5}
(stdin):1:1
```
2) Trying to complete non-records:
```
Use "dhall --explain" for detailed errors
Error: You can only complete records
1│ True::{x = 5}
(stdin):1:1
```
3) Possibly better short message on if predicates
```
echo "if 1 then 2 else 3" |stack exec dhall
Use "dhall --explain" for detailed errors
Error: Invalid predicate for ❰if❱: Natural
1│ if 1 then 2 else 3
(stdin):1:1
```
4) Possibly better short message on list annotations. This is probably
superfluous
```
echo "[] : Bool" |stack exec dhall
Use "dhall --explain" for detailed errors
Error: Invalid type for ❰List❱: Bool
1│ [] : Bool
```
5) Better short message on missing constructors:
```
echo "<Foo : Bool>.Boo True" |stack exec dhall
Use "dhall --explain" for detailed errors
Error: Missing constructor: Boo
1│ <Foo : Bool>.Boo
(stdin):1:1
```
6) Better short messages on missing handlers
… by moving any leading whitespace on the _last_ line into a string interpolation.
This ensures that the parser can find the correct indentation level, no matter
what the other lines contain.
The additional null-check in prettyChunks is necessary to preserve formatting
idempotence. Otherwise
"\n "
is first formatted as
''
${" "}''
but turns into
"\n${" "}"
on re-formatting.
Fixes#1545.
Since control characters like '\b' cannot be escaped directly in
multi-line strings, we move them into string interpolations. E.g.
"\n\b"
is formatted as
''
${"\b"}''
This partially addresses the malformatting of the Prelude.Text.show
example discovered in https://github.com/dhall-lang/dhall-lang/pull/822.
This sample string is now malformatted due to #1545 though.
This raises the lower bound on prettyprinter to 1.5.1 since
`removeTrailingWhitespace` is buggy in earlier versions.
This jailbreaks hnix, which isn't compatible with prettyprinter-1.5.1 yet.
Fixes#183, #1400, #1525.
Co-authored-by: Gabriel Gonzalez <Gabriel439@gmail.com>
* Simplify the doctest invocation
This doesn't change the number of tests covered.
Fixes#1431.
* Try to fix doctests on Hydra
* Fix doctests with cabal v1-test and try to explain how
* Don't target the Dhall module directly
Dhall.Tutorial already depends on it.
* Add `dhall lint` support for fixing parent-anchored paths
* Fix haddocks to be consistent
... as caught by @sjakobi
Co-Authored-By: Simon Jakobi <simon.jakobi@gmail.com>
* Fix import resolution performance regression
Related to https://github.com/dhall-lang/dhall-haskell/issues/1511
This fixes a performance regression introduced in #1159 where `newManager`
was being called on every remote import. This fixes that by going back to
caching the `Manager` created by the first request.
This leads to *dramatic* performance improvements for import-rich packages
(like the Prelude or `dhall-kubernetes`) on the first import. For example,
here are the performance numbers for importing the Prelude for a cold cache
before and after this change:
Before:
```
$ XDG_CACHE_HOME=.cache time dhall hash <<< 'https://prelude.dhall-lang.org/package.dhall'
sha256:99462c205117931c0919f155a6046aec140c70fb8876d208c7c77027ab19c2fa
64.10 real 10.83 user 2.73 sys
```
After:
```
$ XDG_CACHE_HOME=.cache2 time dhall hash <<< 'https://prelude.dhall-lang.org/package.dhall'
sha256:99462c205117931c0919f155a6046aec140c70fb8876d208c7c77027ab19c2fa
4.39 real 0.49 user 0.15 sys
```
That's ~16x faster!
The improvement for `dhall-kubernetes` is smaller, but still significant:
Before:
```
$ XDG_CACHE_HOME=.cache3 time dhall hash <<< ~/proj/dhall-kubernetes-charts/stable/jenkins/index.dhall
sha256:04ebd960f6af331c49c3ccaedb353ac8269032b54fe0a29bd167febcd7104d4f
833.59 real 145.36 user 36.16 sys
After:
```
$ XDG_CACHE_HOME=.cache4 time dhall hash <<< ~/proj/dhall-kubernetes-charts/stable/jenkins/index.dhall
sha256:04ebd960f6af331c49c3ccaedb353ac8269032b54fe0a29bd167febcd7104d4f
381.41 real 8.41 user 1.91 sys
```
... or ~2-3x improvement.
* Fix `-f-with-http` build
* Remove unnecessary `CPP`
... as caught by @sjakobi
This causes text literals to be formatted as multi-line strings
whenever they contain at least one newline and at least one non-newline
character. "Spacers" like `"\n\n"` continue be formatted as single-line
strings. If the heuristic turns out to be too eager to choose a
multi-line layout, we can refine it later.
This partially addresses #1496.
Also
* update some variable names
* use 80-column "smart" layout consistently
* 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
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>
* 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`
... 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
* 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
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.
* 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
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.