Commit Graph

236 Commits

Author SHA1 Message Date
Gabriel Gonzalez
f5819dd6d6 Improve performance of type-checking record literals (#1048)
While benchmarking the example from #769 I saw that a significant
amount of time was spent benchmarking record literals.  When I looked
at the code more closely I saw that the first key in the record literal
was being type-checked twice (once to figure out the record's associated
type-checking constant and once as part of the `process` loop).

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

Before:

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

After:

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

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

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

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

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

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

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

There were two error constructors related to invalid field types:

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

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

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

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

For example:

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

Error: Invalid input

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

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

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

... producing the following diff:

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

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

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

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

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

```
  λ(… :   …
        → …)
→ …@…
  …
```
2019-06-14 09:43:30 -07:00
Gabriel Gonzalez
53f5fa158e
Fix --file option (#1004)
The `--file` option was essentially broken since it passed in the
file path instead of the directory, meaning that transitive imports
would not be computed correctly (they'd be off by one path component).
2019-06-14 08:50:37 -07:00
Gabriel Gonzalez
154d1c52cf
Remove support for old-style List-like Optional literals (#1002)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/572
2019-06-13 17:59:49 -07:00
Gabriel Gonzalez
188ebc8f26
Implement new Unicode braced escape sequence (#987)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/580
2019-06-11 17:27:40 -07:00
Frederik Ramcke
801e9bc7ab Fix linting of unused let bindings (#1001)
* Find unused bindings inside nested lets

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

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

* Don't export implementation details

* Fix `freeIn` to correctly handle de Briujn indices

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

* Fix `removeUnusedBindings` to update de Bruijn indices

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

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

The fix is easy: use `Integer` instead of `Natural` for the accumulator
of the fold and the bug disappears.
2019-06-05 18:48:10 -07:00
Gabriel Gonzalez
e8ac5e3bd0
Add new --cache flag to dhall freeze (#980)
Part of https://github.com/dhall-lang/dhall-lang/issues/563

This flag freezes imports in the same way as the Prelude by providing a
fallback unprotected import without an integrity check.  The primary use
case for this is caching imports with a graceful fallback, which is why
the flag is named `--cache`
2019-06-01 09:44:01 -07:00
Gabriel Gonzalez
8dc52fa3d2
Add support for improved using behavior (#967)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/560
2019-06-01 08:27:26 -07:00
Gabriel Gonzalez
7410f8d3bd
Update to latest version of standard (#976) 2019-05-30 22:40:05 -07:00
Gabriel Gonzalez
3c08c627e8
Support projection by record type (#958)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/499
2019-05-27 20:54:42 -07:00
Valery V. Vorotyntsev
6d363ce734 Dhall.Tutorial: fix shell output formatting (#972)
Fixes #971
2019-05-27 20:05:27 -07:00
Gabriel Gonzalez
a9bacbecfe
Add :clear command to dhall repl (#966)
Fixes #860
2019-05-24 09:39:19 -07:00
Gabriel Gonzalez
411726a3eb
Reject wrong type annotation for record/union literals/types (#965)
Fixes #959
2019-05-23 08:37:19 -07:00
quasicomputational
d77e174ab7 CPP out Monad.fail definition. (#961)
As Dhall's bounds don't allow base 4.13, this doesn't actually affect
anyone running in a supported configuration (i.e., without
--allow-newer). Further note that base 4.13 (i.e., GHC 8.8) isn't
tested in CI at present.

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

However, it's also possible that dependencies might bundle together
breaking changes with 8.8 support, in which case adaptations will
still need to be made.
2019-05-22 18:48:31 -07:00
quasicomputational
7e6ac01810 Add chunkExprs. (#954) 2019-05-15 08:51:31 -07:00
Gabriel Gonzalez
0bbfe6f14c
Move customization documentation into Haskell package (#951)
Related to https://github.com/dhall-lang/dhall-lang/issues/544
2019-05-14 17:55:15 -07:00
Greg Pfeil
de8e7639df Fix diff output to not double-print key-value separators. (#952)
E.g.,
```
{ unit :   …
```
was being printed as
```
{ unit : :   …
```
2019-05-14 08:00:02 -07:00
Gabriel Gonzalez
20f6d8c316
Add --file flag (#949)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/882

This allows users to supply the Dhall expression by path instead of via
standard input.  This also ensures that transitive imports are resolved
appropriately relative to the file's path.

In other words, instead of this:

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

Users can now do:

```
$ dhall --file foo/bar.dhall
```
2019-05-13 09:26:38 -07:00
Gabriel Gonzalez
d788b780a2
Update to latest version of language standard (#948)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/947
2019-05-13 08:23:46 -07:00
quasicomputational
48c73f3ef9 Add and expose genericInject. (#940)
This is a counterpart to `genericAuto`, which is useful for dealing
with types coming from a library without orphan instances.
2019-05-05 20:21:50 -07:00
Gabriel Gonzalez
7d56778350
Fix another α-normalization bug (#938)
This was caught by the following test:

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

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

For example, this file:

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

+ 1
]
```

... now produces this error message:

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

↳ ./example.dhall

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

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

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

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

* https://github.com/dhall-lang/dhall-lang/pull/481
* https://github.com/dhall-lang/dhall-lang/pull/488
* https://github.com/dhall-lang/dhall-lang/pull/489
* https://github.com/dhall-lang/dhall-lang/pull/497
2019-04-25 15:05:02 -07:00
Gabriel Gonzalez
7d31506be4
Automatically discover tests (#897)
This adds a new `Dhall.Test.Util.discover` utility for auto-generating
a `TestTree` from a directory tree.  This simplifies keeping up to date
with changes to the standard test suite.
2019-04-24 13:01:46 -07:00
AndrasKovacs
fcca883e00 Add a new environment machine normalizer (#876)
- Dhall.Eval: new evaluator, conversion checker and normalizer.
  There is no standalone alpha normalizer yet.
- There is a new option "new-normalize" for dhall executable, which uses
  the new normalizer.
- Type checker is unchanged.
- new implementation: alphaNormalize, judgmentallyEqual, normalize
- normalizeWith takes a Maybe ReifiedNormalizer argument now, and switches to
  the new evaluator whenever the input normalizer is Nothing
- QuickCheck test for isNormalized removed, because we don't support evaluation
  of ill-typed terms, which the test would require.
2019-04-17 16:41:04 -07:00
Fabrizio Ferrai
58ae94df0e
Fix typechecking of Sorts in records (#881)
As standardized in dhall-lang/dhall-lang#453
2019-04-07 14:50:49 +03:00
Gabriel Gonzalez
ba55d55307
Add support for fields named after built-ins (#875)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/437
2019-03-30 11:50:26 -07:00
Gabriel Gonzalez
fe5d100226
Fix parsing of identifiers that overlap with imports (#870)
Fixes https://github.com/dhall-lang/dhall-lang/issues/446
2019-03-28 08:51:01 -07:00
Gabriel Gonzalez
2a78ac06b7
Define expression equality as CBOR equality (#866)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/426

This adds two new `ToTerm`/`FromTerm` classes in order to minimize
code disruption.  The main disruption is due to renaming the old
`encode`/`decode` to `encodeExpression`/`decodeExpression`
2019-03-27 18:26:02 -07:00
Gabriel Gonzalez
a2ab6a59ec
Add support for empty alternatives (#863)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/438

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

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

```haskell
-- ./example.dhall

let Role = < Wizard | Fighter | Rogue >

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

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

`Dhall.Binary.unApply` was failing to uncurry functions due to the presence of
`Note` constructors.  This caused `dhall encode` to produce different
results from `dhall hash` since the latter was normalizing the expression
(and therefore removing `Note` constructors) whereas the former was not.
2019-03-24 13:18:21 -07:00
Gabriel Gonzalez
c900081a34
Remove deprecated Path constructor (#858)
The `Path` constructor was deprecated a long time ago, so it's pretty
safe to remove now
2019-03-24 12:21:08 -07:00
Gabriel Gonzalez
ff3dc7f9e7
Add --help information for --annotate flag (#856) 2019-03-24 11:42:27 -07:00
Gabriel Gonzalez
c3ba33a80a
Add unit tests (#854)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/416
2019-03-24 11:01:43 -07:00
Gabriel Gonzalez
dce46fc6c8
Add --alpha flag to α-normalize output (#855)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/853

... as suggested by @singpolyma
2019-03-16 11:20:19 -07:00
Justin Le
35513e715a Fix for UnionType (#857)
Fix the type equality check by using judgmental equality
2019-03-16 10:12:55 -07:00
Gabriel Gonzalez
bffe2ed2a1
Remove support for URL fragments (#851)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/406
2019-03-14 07:23:23 -07:00
Gabriel Gonzalez
4b7bdd458c
Add CORS support (#846)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/411
2019-03-12 18:36:38 -07:00
Gabriel Gonzalez
1e3c2a1c84
Be more strict when decoding variables named "_" (#847)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/407
2019-03-07 22:09:41 -08:00
Gabriel Gonzalez
2efed4b4a5
Expand the set of valid quoted labels (#840)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/408
2019-03-07 21:42:57 -08:00
Gabriel Gonzalez
05d9405d29
Simplify import resolution logic (#833)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/391

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

The second to last branch was always `True`:

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

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

This includes two changes:

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

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

These allow one to enable or disable command-line options

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

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

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

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

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

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

For example, if the original expression had been:

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

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

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

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

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

This adds source position information to missing imports

Before:

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

↳ ./foo

Error: Missing file …/foo
```

After:

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

↳ ./foo

Error: Missing file …/foo

(stdin):1:1
```
2019-02-08 07:32:00 -08:00
Gabriel Gonzalez
2cdaf91636
Add --check flag to dhall format (#810)
Fixes #809

This allows the user to check if the input is formatted instead of formatting
the input
2019-02-06 18:19:25 -08:00
Gabriel Gonzalez
2f26dac1ff
Add support for Unicode path components (#800)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/353
2019-02-04 19:14:07 -08:00
Gabriel Gonzalez
04ec45803d
Remove version tag from encoded expressions (#805)
* Remove version tag from encoded expressions

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

This includes backwards compatibility for older encoded expressions
2019-02-03 21:17:41 -08:00
Gabriel Gonzalez
15d0b8d063
Change dhall freeze to only freeze Remote imports (#808)
The motivation behind this change is so that users can freeze remote imports
(like the Prelude) but ignore local imports so that subsequent runs of the
interpreter reflect changes to local files and environment variables.

The reasoning behind this is that there are two primary benefits of integrity
checks:

* Improved security
* Caching

... and one downside which is that updates to those imports are not pulled in
until the integrity check is updated or removed.

However, environment variables and local file paths do not benefit from
improved security or caching, so there is only a downside to freezing them.

Specifically:

* Environment variables and local file paths are both cheap to resolve

  ... so they don't really benefit from caching.

  To be precise, they *could* benefit from caching if the cache expression is
  cheaper to parse and normalize compared to the original file.  For those
  cases there is still an `--all` flag to freeze all imports.

* Environment variables and local file paths are trusted

  For example, when a user runs the `dhall` executable they are implicitly
  trusting their filesystem which provides that executable.  Similarly, when
  they run `dhall` without an absolute path they are implicitly trusting that
  their `PATH` environment variable has not been compromised to point to a
  malicious executable.

  Up until now, Dhall's threat model has always been that local imports are
  trusted but remote imports are not, so this is consistent with that threat
  model.

... so as far as environment variables and local files are concerned there are
only downsides to freezing them and no up-side.  This is why this change
no longer freezes them.

This also renames `hashImport` to `freezeImport` for more terminology
consistency.
2019-02-01 07:46:03 -08:00
Ville Tirronen
b2514ff8bf Add --immediate-dependencies flag to resolve mode (#803)
This is useful for integrating dhall to build systems where dhall
expressions (e.g. of type `Text`) are build products.

This also renames the `--list` flag to `--transitive-dependencies`
2019-01-31 15:24:17 -08:00
Gabriel Gonzalez
1a94f5558e
Fix parser for natural-raw (#804)
Fixes https://github.com/dhall-lang/dhall-lang/issues/357

This uses `Text.Megaparsec.Char.Lexer.decimal` which matches the Dhall
grammar.  The previous `decimal` parser was also accepting non-standard
hex and octal literals.
2019-01-31 13:05:19 -08:00
Basile Henry
29375ad462 Add :hash command to the repl (#806)
Signed-off-by: Basile Henry <bjm.henry@gmail.com>
2019-01-31 12:12:05 -08:00
Ville Tirronen
3fbd0d72f8 Add --list flag to dhall resolve (#795)
This commit adds a flag for producing a machine readable listing of
dependencies of a dhall expression.

This flag can be used to integrate dhall more easily to file watchers or
build systems which require such lists of dependencies.
2019-01-28 21:43:37 -08:00
Gabriel Gonzalez
2d2c897e3f
Include standard version in dhall version output (#793)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/791
2019-01-25 09:01:55 -08:00
Mario Lang
0460f28a38 Fix a typo (#792) 2019-01-23 14:57:06 -08:00
Gabriel Gonzalez
095ee6db61
Don't fail if $HOME environment variable is unset (#789)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/788

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

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

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

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

in  let Configs = List Config

in  replicate 10 Text "!"
```

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

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

According to the standard a non-empty list with a type annotation should
not be encoded with the type annotation alongside the list elements.  The
type annotation should be parsed and encoded as a separate constructor.
2019-01-16 20:28:12 -08:00
Gabriel Gonzalez
f5928e4472
Fix Nix build to reinstate -Werror (#781)
A refactor of the Nix build accidentally removed the `-Werror` flag, which
caused some warnings to get past CI.  This change fixes that and removes the
warnings.
2019-01-16 19:39:51 -08:00
Javier Neira
3f004ff9bb Fix test errors in windows caused by encoding (#782) 2019-01-16 19:15:57 -08:00
Justin Le
ec48c20f04 UnionType and UnionInputType, analogues of RecordType and RecordInputType (#775) 2019-01-15 16:55:56 -08:00
Gabriel Gonzalez
162dde95ac
Add inputNormalizer field to InterpretOptions (#777)
This fixes the problem found in https://github.com/dhall-lang/dhall-lang/issues/166#issuecomment-452766374

This ensures that the functions marshalled into Haskell can correctly take
advantage of user-supplied language extensions
2019-01-11 08:29:40 -08:00
Nicholas Scheel
78ca289335 Update standard version to 5.0.0 in Binary.hs (#771) 2018-12-31 10:48:17 -06:00
Basile Henry
528ea42407 Fix error message for not-equal when type checking (#768)
According to the standard https://github.com/dhall-lang/dhall-lang/blob/master/standard/dhall.abnf\#L399 the correct operator is `!=`
2018-12-28 13:47:11 -06:00
Gabriel Gonzalez
0b3fd4b624
Prenormalize substituted expressions (#765)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/764

This pre-normalizes expressions before substituting them to
avoid duplicated work.  This also fixes the space leak from the
above issue.
2018-12-24 09:35:56 -06:00
Gabriel Gonzalez
ca78d7977d
Fix type-checking bug for unions (#763)
The Haskell implementation was not matching the specification for
type-checking union types:

* The inferred type of union types was (incorrectly) always returning `Type`
* Unions of mixed alternative types were not being properly rejected

I also discovered several mistakes in the error messages, which I fixed along
the way.
2018-12-22 08:39:26 -06:00
Adam Sandberg Eriksson
026db247f7 Fix haddock syntax (#761) 2018-12-19 07:19:07 -08:00
Fintan Halpenny
a95acd5b2a Add Unordered Map Traversal (#749) 2018-12-10 10:46:46 -08:00
Gabriel Gonzalez
2a30c7f4fc
Update binary encoding/decoding for imports (#728)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/308

This adds support for encoding/decoding custom headers and integrity checks.
2018-12-08 10:25:07 -08:00
Gabriel Gonzalez
6ab5df4d49
Implement standardized support for multi-line literals (#726)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/307

Note that this a breaking change because:

* Newlines are now mandatory after the opening `''` of a multi-line
  literal
* The spaces before the trailing `''` count towards the leading
  indentation computation
2018-12-08 08:49:08 -08:00
Georges Dubus
f308ca29b0 Fix diff so that an empty list is equal to itself (#740)
* Test with QuickCheck that an expression is always the same as itself

I noticed cases where the diffing code returns that an expression is not the
same as itself (for example, an empty list). This commit adds a QuickCheck test
to illustrate it, and maybe other cases.

Sadly, I had to expose some internals from Dhall.Diff for the test, which makes
the interface less nice.

* Fix diff so that an empty list is the same as itself
2018-12-07 09:07:47 -08:00
Gabriel Gonzalez
cf69f5a953
Add "Try Dhall" project (#739)
This adds three new Nix build products:

* `try-dhall-static` - The static assets for "Try Dhall"
* `try-dhall-server` - A script which serves the static assets for local
   debugging
* `tarball-try-dhall` - A tarball of the static assets

This is powered by a new small `dhall-try` package which is also included
in this change.
2018-12-06 18:00:03 -08:00
Basile Henry
fa9cbff5ad
Autocomplete for dhall repl (#727)
* Autocomplete repl commands

* Autocomplete imports (file and environment)

* Improve autocomplete separators

* Autocomplete records fields

* Remove use of TypeApplications

* Improve file path completion

* Autocomplete union alternatives

* Import missing (<>)

* Improve parsing of assignment in repl commands

* Remove no-longer-used `foldl'`

* Fix record field autocomplete and improve command autocomplete

* Fix definition order in repl environment

* Autocomplete variables in scope and all reserved identifiers
2018-12-02 19:26:43 +01:00
Gabriel Gonzalez
56d795dfe0
Change how dhall repl handles prior definitions (#729)
The motivation for this change is so that more code type-checks
within a REPL session.

For example, before this change the following session fails:

```haskell
⊢ :let Either = λ(a : Type) → λ(b : Type) → < Left : a | Right : b >
⊢ :let Example = < Left : Natural | Right : Bool >

Example : Type

⊢ Example.Left

Example : Type

Error: Not a record or a union

Example.Left
(stdin):1:1
```

After this change, the same session works:

```
[⊢ :let Example = < Left : Natural | Right : Bool >

Example : Type

⊢ Example.Left

λ(Left : Natural) → < Left = Left | Right : Bool >

```

The difference is in how we incorporate prior definitions when
type-checking code.  Before this change prior definitions were added
to the context, which leads to type-checking failures because type
synonyms don't work when used in this way.  After this change we
incorporate them as extra `let` definitions (same as normalization).
2018-12-02 05:25:21 -08:00
Kevin Wallace
bafab770fd Add :quit repl command (#719)
* Prefer `throwIO` to `throw`
2018-11-29 07:30:15 -08:00
Gabriel Gonzalez
abdd442814
Restore Parent constructor for Local (#718)
This is essentially a revert of 25d86e8e5d

The primary motivation for this is so that paths beginning with `../`
don't get reformatted to begin `./../`.

The secondary motivation for this is to more closely match the standard.
There are fewer special cases in the logic if there is a dedicated
constructor for the `Parent` case.
2018-11-28 19:30:38 -08:00
Gabriel Gonzalez
bfda055420
Add encoding/decoding logic for as Text (#712)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/303
2018-11-28 18:10:04 -08:00
Gabriel Gonzalez
a671e9c2f5
Add --json flag for dhall {decode,encode} (#717)
Fixes #714

This adds a `--json` flag that `dhall decode` and `dhall encode` can use to
read/write the equivalent JSON representation of the CBOR.  This comes in
handy for the parsing compliance tests which use this CBOR-as-JSON as the
standard representation of the abstract syntax tree.
2018-11-28 17:51:20 -08:00
Gabriel Gonzalez
103e2e637a
Add dhall lint support for removing constructors (#701)
Now that `constructors x` is the same as `x` we can have `dhall lint`
safely strip all uses of `constructors` in preparation for removing the
keyword entirely.
2018-11-27 14:32:33 -08:00
Gabriel Gonzalez
92a68efcd3
Add support for records of records of types (#700)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/300

Fixes https://github.com/dhall-lang/dhall-haskell/issues/692
2018-11-27 13:36:15 -08:00
Fintan Halpenny
5a0d671f95 constructors === id (#693) 2018-11-27 11:53:20 -08:00
Gabriel Gonzalez
653932e112
Simplify import error handling logic (#711)
The first two cases of the `handler₀` function are just special cases
of the last case
2018-11-26 23:36:46 -08:00
Basile Henry
65f5377f0c
Unique dependencies in dot graph (#713)
* Add dotgen to stack.yaml

* Generate strict dot graph (prune redundant connections)
2018-11-26 17:19:02 +01:00
Gabriel Gonzalez
85ccf2ff0a
Improve HTTP error messages (#710)
Fixes #509

The `Dhall.Import.HTTP` module had logic for pretty-printing HTTP error
message, but this logic wasn't being used anywhere!  This change fixes
that and also polishes the error messages a little bit.
2018-11-26 07:53:22 -08:00
Basile Henry
c8dc585430
Generate dot graph to visualize import graph (#698)
* Add dotgen as a dependency

Signed-off-by: Basile Henry <bjm.henry@gmail.com>

* Build up dot graph while resolving imports

Signed-off-by: Basile Henry <bjm.henry@gmail.com>

* Add --dot option to resolve in CLI

Signed-off-by: Basile Henry <bjm.henry@gmail.com>

* Handle diamond dependencies in dot graph

* Refactor dot graph generation
2018-11-26 07:24:20 +02:00
Gabriel Gonzalez
99fabea38a
Fix import caching (#702)
This fixes an apparently very old bug in import caching caught by @basile-henry

Before this change the import resolution algorithm was:

1. Retrieving the cache
2. Transitively resolving all imports
3. Setting the new cache to be current import insert into the cache retrieved in
   step 1

The bug is that all of the transitive imports resolved in step 2 added
entries of their own to the cache and those new cache entries were being
clobbered by step 3.

The fix is simple: don't use the cache retrieved in step 1 to compute
the updated cache in step 3.  Rather, use `modify` instead of `put` to
create the new cache so that we preserve newly-added cache entries.
2018-11-24 08:52:30 -08:00
Gabriel Gonzalez
203a22818e
Fix bug when linting multi-let expressions (#703)
`dhall lint` was incorrectly deleting `let` bindings that are being used
due to not checking other `let` bindings within the same multi-`let`
expression for free variable occurrences.

This change fixes that and adds the first regression test for `dhall
lint`
2018-11-24 08:32:04 -08:00
Gabriel Gonzalez
53ae87c8e2
Version 1.18.0 → 1.19.0 (#691) 2018-11-21 19:10:32 -08:00
Gabriel Gonzalez
bacb82480c
Fixed mixed field access (#694)
Fixes #692

The standard permits a user to access a constructor from a type stored inside
a record, but the Haskell implementation had a mistake which prevented this.
Specifically, the Haskell implementation was not normalizing the union type
as the standard specified before attempting to access the constructor, leading
to an unexpected type error.
2018-11-21 18:31:55 -08:00
Gabriel Gonzalez
8bc595be7f
Add support for quoted path components (#690)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/293
2018-11-20 18:08:43 -08:00
David Virgilio
adf94a6503 Encode doubles as Double, do bounds checks, and add support for NaN and Infinity values (#667) 2018-11-20 15:07:08 -08:00
Gabriel Gonzalez
3ed5f4d293
Prevent Hurkens' paradox (#680)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/272
2018-11-15 19:49:57 -08:00
Oliver Charles
9d3e493f69 Allow custom normalization to be entered top-down (#684) 2018-11-15 18:25:30 -08:00
Gabriel Gonzalez
8a5bfaa3b9
Add support for multi-let (#675)
... as standardized in: https://github.com/dhall-lang/dhall-lang/pull/266

This also adds `dhall lint` support for consolidating nested `let` expressions
2018-11-13 08:01:59 -08:00
Gabriel Gonzalez
b3968f681a
Preserve Unicode characters (#679)
Fixes https://github.com/dhall-lang/dhall-lang/issues/267

According to the standard, Unicode characters up to `0x10FFFF` do not
require escaping.  See:

33cab24f8e/standard/dhall.abnf (L192)

... so we can preserve them when pretty-printing Dhall expressions.

Note that the current code still does not comply with the standard for Unicode
characters beyond `0x10FFFF`, but I'll defer fixing that to a subsequent
change.
2018-11-12 09:46:33 -08:00
Alexander Biehl
096c03936e Introduce normalizeWithM for monadic normalization (#371) 2018-11-05 20:21:29 -08:00
Dan Burton
7aba79118c Use an Ordered Set for Project (#670) 2018-11-05 19:59:01 -08:00
Sofia Rose
9d0fd42d95 Fix parsing of //\\ (#666)
The issue was that the parser was attempting to parse // first, which
will succeed on the prefix of //\\, then the parser will get an error
because it expects a sub expression but the input is \\.
2018-10-29 20:28:50 -07:00
Gabriel Gonzalez
aecfbc9acc
Migrate dhall-{bash,json,text} into this repository (#661)
The motivation for this change is:

* To catch build failures in downstream packages whenever we make a breaking
  change to the `dhall` API
* To reduce the amount of work I need in order to cut a release for all of
  these packages
* To better share Nix/CI-related logic between the projects

Note that I have not yet migrated `dhall-nix` in.  I'm waiting for
https://github.com/dhall-lang/dhall-nix/issues/17 to be fixed since
`dhall-nix` is incompatible with later versions of `megaparsec` due to
`hnix`.
2018-10-28 17:32:51 -07:00