Commit Graph

1354 Commits

Author SHA1 Message Date
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
Gabriel Gonzalez
0256b35087 Update README to mention pre-built OS X executables (#1229)
* Update `README` to mention pre-built OS X executables

* Retain the reference to `brew`

... based on a question by @sjakobi
2019-08-09 23:01:47 +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
Gabriel Gonzalez
268c79631d Fix yaml-to-dhall support for empty objects (#1186)
* Fix `yaml-to-dhall` support for empty objects

`yaml-to-dhall` was decoding an empty object into:

```dhall
[] : { mapKey : Text, mapValue : Text }
```

... instead of:

```dhall
[] : List { mapKey : Text, mapValue : Text }
```

... which this change fixes

* Add missing test files

* Hopefully fix test failure on Windows

I suspect that the test failure is due to the locale for the test suite
not being set to UTF8
2019-08-09 18:21:40 +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
Frederik Ramcke
4c1736b154 Improve rendering of types when annotating lets (#1222)
Previously the annotated type would have too many line-breaks, e.g. when
the result of annotating
  let id = \(A : Type) -> \(a : A) -> a
was
  let id :   ∀ ( A
  : Type
  )
  → ∀ ( a
  : A
  )
  → A = \(A : Type) -> \(a : A) -> a
while it should be
  let id : ∀(A : Type) → ∀(a : A) → A = \(A : Type) -> \(a : A) -> a
2019-08-08 15:16: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
Frederik Ramcke
6609270fe4 Only underline link in import (#1217)
This restricts the clickable link part of an import to just the actual
link; previously we also underline hash and headers if those were
present.

Now:
./Bool/package.dhall sha256:7ee950e7c2142be5923f76d00263e536b71d96cb9c190d7743c1679501ddeb0a
~~~~~~~~~~~~~~~~~~~~

Previously:
./Bool/package.dhall sha256:7ee950e7c2142be5923f76d00263e536b71d96cb9c190d7743c1679501ddeb0a
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2019-08-08 13:42:49 +00:00
Simon Jakobi
a2118eaeee Tune the AppVeyor config some more (#1214)
* Try to cache the extra-deps from stack-lts-6.yaml

* Limit `stack bench` to the dhall package

For some reason `stack bench` triggers a rebuild of _all_ the local
packages, which we don't need.
2019-08-08 12:08:25 +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
Frederik Ramcke
5f3b05a8f2 dhall-lsp-server: Implement completion support (#1190)
* Implement completion support

Completes the following:
- environment variables
- local imports
- identifiers in scope (as well as built-ins)
- record projections
- union constructors

* Add support for general dependent types

Removes the non-dependent let path. Needed since #1164 added support for
general dependent types.

* Remove unused import

* Use monad instance to cast between `Expr Src _`

As suggested by @Gabriel439: Use `typeOf (do _ <- expr; holeExpr)`
instead of `fmap undefined expr`. In the absence of `Embed` constructors
(in this case `Import`s) the two are equivalent.

* Simplify completeFromContext

Caught by @Gabriel439

* Remove debug code

* Add 1s timeout to listDirectory call

As pointed out by @Gabriel439, listDirectory can be a potentially
expensive operation. Adding a timeout should improve the user
experience.

* Fix unclean merge
2019-08-07 14:11:59 +00:00
Frederik Ramcke
523861a92c dhall-lsp-server: Upgrade to haskell-lsp 0.15 (#1203)
* Clean up dhall-lsp-server.cabal

Removes unused dependencies.

* Upgrade to haskell-lsp-0.15.0.0

The stackage LTS version is still 0.8.2 so we need to add this as an
'extra-dep'.

* Display type information as plaintext rather than markdown

* Fix nix build

* Update nix haskell-lsp-types
2019-08-07 11:40:43 +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
e39650ce7f Try to improve AppVeyor's dependency caching (#1207)
* This might fix a syntax problem:
  https://www.appveyor.com/docs/build-cache/#configuring-cache-items
  says:

      Note the use of single quotes around the entire line, when
      environment variables are used.

* This adds the AppVeyor config to the files which invalidate the cache
  when changed.

Context: #1063.
2019-08-07 05:21:58 +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
Simon Jakobi
1d58840feb
dhall-json: Nesting: Support empty alternatives as contents (#1204)
Closes #1201.
2019-08-06 13:24:18 +02:00
Gabriel Gonzalez
d66d1db33f Fix --version flag handling for dhall-json package (#1199)
* Fix `--version` flag handling for `dhall-json` package

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

This changes version to be a separate constructor for options parsing,
in order to make invalid states unrepresentable and to fix issues like
the above one.

* Undo `allowImports` changed

This was a change I forgot to stash while working on the fix for the
`--version` flag

* Fix missing `Paths_dhall_json` in `dhall-json.cabal`
2019-08-06 06:28:46 +00: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
Gabriel Gonzalez
3abef4e3f0 Enable --records-strict by default for {json,yaml}-to-dhall (#1181)
This adds a new `--records-loose` flag and changes the default behavior
to `--records-strict`

The rationale for this change is so that this default behavior helps
more when users are still experimenting with the appropriate type to
use to decode a large and messy YAML file.

For example, suppose a user is trying to translate the following YAML
to Dhall:

```yaml
foo: 1
bar: true
```

... and they start with a empty Dhall type which they plan to fix in
response to error messages.  They'd get a surprising success:

```bash
$ yaml-to-dhall '{}' < ./example.yaml
{=}
```

... because the old default behavior is to ignore extra fields in the
YAML.  However, if we're strict by default then users don't have to
apply the `--records-strict` flag to get feedback on what they need
to change.
2019-08-02 19:56:09 +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
Javier Neira
4d0058b71d Use ghc-8.6.5 in default stack.yaml and make appveyor use it (#1182)
* Make it no buildable in windows as suggested by @sjakobi

* Use last lts resolver for ghc-8.6.5

* Remove unused stack yaml file

* Use default stack yaml
2019-08-01 13:01:16 +00:00
Frederik Ramcke
33275f308f Retire hard-coded version string (#1171)
Queries `Paths_dhall_lsp_server` (generated by cabal) for the up-to-date
version specified in the .cabal file. Addresses #1170.
2019-08-01 02:51:49 +00:00
Fabrizio Ferrai
b4c8bc2da3 Change cabal file so the release script picks up the version (#1166) 2019-08-01 01:58:28 +00:00
Simon Jakobi
42d80b057d
Include dhall-nix in stack and cabal project configs (#1178)
Note that `dhall-nix` cannot be built on Windows due to its transitive
dependency on the `unix` package.

Also:

* Nix: Enable `-Werror` for `dhall-nix`

* Add support for `toMap` in `dhall-nix`:

    \(x : { a : Bool }) -> toMap x

is translated as

    x:
      (kvs:
        map (k:
          {
            mapKey = k;
            mapValue = builtins.getAttr k kvs;
            }) (builtins.attrNames kvs)) x
2019-07-31 18:24:15 +02: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
Gabriel Gonzalez
1970aa3ef3
Fix CSS for dhall-lang.org in Safari (#1160)
Fixes https://github.com/dhall-lang/dhall-lang/issues/609

Safari requires a vertical alignment CSS directive in order to render the
input and output panes side-by-side
2019-07-28 06:53:43 -07: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