Commit Graph

37 Commits

Author SHA1 Message Date
Simon Jakobi
7c91dd5f48 Fix Expr's Eq instance via a newtype wrapper for Doubles (#1347)
See the haddocks in Dhall.Core for details.

Fixes #1341.
2019-09-28 14:56:37 +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
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
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
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
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
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
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
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
Simon Jakobi
b9375fc9c7 Implement "Simplify ⫽ when its arguments are equivalent" (#1196)
…as standardized in https://github.com/dhall-lang/dhall-lang/pull/684
2019-08-08 00:14:08 +00:00
Simon Jakobi
0871fcd857 Prevent "Natural/subtract 0" from causing a panic (#1208)
Previously, normalizing `Natural/subtract 0` would result in this
error:

    ⊢ Natural/subtract 0

    Error: Compiler bug

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

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

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

This updates the dhall-lang submodule to include a new testcase added
in https://github.com/dhall-lang/dhall-lang/pull/692.
2019-08-07 02:38:56 +00:00
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
Gabriel Gonzalez
7f2f57f975
Add support for dependent types (#1164) 2019-08-03 21:38:01 -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
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
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
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
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
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
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
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
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
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
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
Gabriel Gonzalez
411726a3eb
Reject wrong type annotation for record/union literals/types (#965)
Fixes #959
2019-05-23 08:37:19 -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
AndrasKovacs
931dc50522 Fix alpha normalization (#931)
Fixes #929
2019-05-02 13:50:17 -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
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