Commit Graph

1421 Commits

Author SHA1 Message Date
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
Frederik Ramcke
36379cec2e Fix import alternatives to recover from type errors (#1152)
Previously, `BAD="0 0" dhall <<< "env:BAD ? 0"` resulted in the
following error:
```
↳ env:BAD

Error: Not a function

1│ 0 0

BAD:1:1
```

According to the standard the above expression was supposed to evaluate
successfully to `0`. See #1146 for further discussion.
2019-07-25 18:05:55 -07:00
Gabriel Gonzalez
354346be91 Pretty-print output of {json,yaml}-to-dhall (#1150)
This enables syntax highlighting and formatted output for these two
programs
2019-07-24 13:33:41 +00:00
Frederik Ramcke
4faf25bbbe Load imports recursively (#1128)
* Load imports recursively

This is the big change that enables us to implement 'semi-semantic'
caching.

* Use `throwM` instead of `liftIO . throwIO`

* Fix build with __GHCJS__

* Fix exceptions in Dhall.Import

* Fix dhall-lsp-server

* Revert exception behaviour on typecheck errors

This is one for a separate pull request!

* Make sure loadImportFresh returns alpha-normal expression

As caught by @Gabriel439, `loadImportFresh` violated the invariant that
`ImportSemantics` should be alpha-beta-normal. This fix also means that
we don't have to alpha-normalise again in `loadImportWithSemanticCache`.

* Remove old comment

* Fix regression test for issue 216

Turns out the test was testing the wrong thing, because it was
pretty-printing an import. This worked previously because when importing
uncached expressions we would not alpha-normalise them.

* Restore `dhall freeze` bevhaviour

Newly frozen imports should also be present in the cache.
2019-07-23 16:11:33 +00:00
Ollie Charles
d55bf8f3a3 Add instance Lift (Expr s a) (#1119)
This allows Exprs to be lifted in template-haskell. This is useful to
build a [dhall||] quasiquoter
2019-07-21 12:10:53 -07: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
88d6671e38
Enable the fixed potPourri test (#1144)
Context: https://github.com/dhall-lang/dhall-lang/pull/655
2019-07-21 15:21:20 +02:00
Gabriel Gonzalez
0120f2650d Document that normalize is partial (#1140)
* Document that `normalize` is partial

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

* Document other partial functions

... as suggested by @sjakobi
2019-07-20 20:14:52 +00:00
Gabriel Gonzalez
0c61b0d048 Forbid invalid codepoints (#1104)
* Forbid invalid codepoints

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

* Don't validate code points outside of escape sequences

... as suggested by @sjakobi

It's not necessary (since the `text` package forbids invalid UTF8) and
slows down performance as verified by the `dhall-parser` comment parsing
benchmarks

* Restore `nonCharacter` parsing test
2019-07-20 19:41:18 +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
Gabriel Gonzalez
cbd6a6543d Support lens-family-core-2.0.0 (#1141)
Related to https://github.com/commercialhaskell/stackage/issues/4725
2019-07-20 12:18:49 +00:00
Simon Jakobi
8aa8add453 Catch errors in normalizeWithM when testing it (#1139)
Context: #1138
2019-07-20 04:30:42 +00:00
Simon Jakobi
482984eb6d Allow only valid HTTP(S) reg-names (#1124)
Corresponding change to the standard:
https://github.com/dhall-lang/dhall-lang/pull/627

The potPourri parser test remains disabled due to
https://github.com/dhall-lang/dhall-lang/pull/655.

Fixes https://github.com/dhall-lang/dhall-haskell/issues/1110.
2019-07-20 00:54:27 +00:00
Simon Jakobi
e40e847730 Always typecheck the type annotation on 'toMap' (#1132)
Previously, ill-typed expressions like this one got into normalization:

    toMap {=} : <>.x

Also:

* Tweak Expr's Arbitrary instance:
  - Boring nullary constructors don't need to be so frequent.
  - Large NaturalLits can cause normalization to OOM, which we don't
    want when running the testsuite.

* Add property test to check that all well-typed expressions can be
  normalized.
2019-07-19 23:14:01 +00:00
Gabriel Gonzalez
f0d017d7c5 Fix test suite to accept expected decoding failures (#1136)
This will be necessary for https://github.com/dhall-lang/dhall-lang/pull/640
2019-07-19 21:11:22 +00:00
Gabriel Gonzalez
a440c6cd28 Improve error message for missing constructor (#1137)
Fixes https://github.com/dhall-lang/dhall-haskell/issues/1130
2019-07-19 20:17:14 +00:00
Frederik Ramcke
7e9728f0e9 dhall-lsp-server: Freezing imports (#1123)
* Implement dhall.freezeImport and dhall.freezeAllImports

* Remove old (broken) test suite

* Rename `relativePosition` to `subtractPosition`

as suggested by @Gabriel439

* Add doctest for `subtractPosition`

as suggested by @Gabriel439

* Simplify getImportHashPosition

As spotted by @Gabriel439

* Use `forM` instead of `mapM` for prettier code

As suggested by @Gabriel439
2019-07-19 17:24:11 +00:00
Simon Jakobi
7dc7856d10 dhall-json: Allow empty alternative for Nesting.Inline (#1122)
Fixes #1092.
2019-07-19 16:19:19 +00:00
Simon Jakobi
b4f71b2aa2 Check normalizeWithM for consistency with normalize (#1126)
* Check normalizeWithM for consistency with normalize

* Implements constant folding of Natural/fold applications normalizeWithM.

* Changes the Arbitrary Var instance to generate only non-negative indices.
  Otherwise failures like this one would pop up:

    normalizeWithM should be consistent with normalize: FAIL (8.51s)
          *** Failed! Falsified (after 318133 tests and 6 shrinks):
          Let (Binding {variable = "", annotation = Nothing, value = List} :| []) (Var (V "" (-1)))
          Var (V "" (-1)) /= Var (V "" (-2))
          Use --quickcheck-replay=180244 to reproduce.

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

* QuickCheck tests: Specialize the 'natural' Gen to Naturals

Previously it could produce about any number, not just non-negative
ones.
2019-07-19 15:33:59 +00:00
quasicomputational
0df6362a9d Make the tests build with GHC 7.10. (#1134) 2019-07-18 23:11:51 +00:00
Gabriel Gonzalez
1a27cad137 Add --file option to dhall-json executables (#1107)
* Add `--file` option to `dhall-json` executables

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

* s/JSON/expression/

... as caught by @sjakobi

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

* s/expression/YAML expression/

... as caught by @sjakobi

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

* Change the program descriptions for `{json,yaml}-to-dhall`

... as suggested by @sjakobi
2019-07-18 19:08:47 +00:00
Simon Jakobi
40ec83743d Make isNormalized consistent with normalize (#1115)
To be more precise (citing the haddocks):

    Given a well-typed expression e, (isNormalized e) is equivalent to
    (e == normalize e).

    Given an ill-typed expression, isNormalized may return True or False.

An even closer correspondence between isNormalized and 'normalize' is
currently tricky to achieve as 'normalize' returns errors only for some
ill-typed expressions. Once 'normalize' is more principled in this
regard, isNormalized could be changed to return a (Maybe Bool).

This re-enables a property test checking this consistency. Since
'normalize' returns errors for some ill-typed expressions, we
catch have to catch these, which requires an NFData for Expr.
2019-07-17 22:19:41 +00:00
Frederik Ramcke
d5d0224bc3 Preparing Dhall.Import for "Semi-semantic" caching (#1113)
* Fix misleading comment

* Add `Chained` type to capture fully chained imports

Until now we used `Import` two mean two different things:
- The syntactic construct; e.g. `./a.dhall` corresponds to the following
  AST:
  ```
  Embed
    (Import
      (ImportHashed Nothing (Local Here (Directory ["."]) "a.dhall"))
      Code)
  ```

- The physical location the import is pointing to, computed by
'chaining' the syntactical import with the the 'physical' parent import.
For example the syntactic import `./a.dhall` might actually refer to the
remote file `http://host/directory/a.dhall`.

This commit adds a `Chained` newtype on top of `Import` to make this
distinction explicit at type level.

* Use `HTTPHeaders` alias for binary headers

I claim that `HTTPHeaders` is more readable and informative than the
unfolded type `(CI ByteString, ByteString)`.

* Typecheck and normalise http headers earlier

Previously we would typecheck and normalise http headers in
`exprFromImport`, i.e. while loading the import. This commit adds the
invariant that any headers in 'Chained' imports are already typechecked
and normalised, and moves this step into `loadWith` accordingly.

This causes a subtle difference in behaviour when importing remote files
with headers `as Location`: previously, nonsensical expressions like
`http://a using 0 0 as Location` were valid, while they would now cause
a type error.

* Fix dhall-lsp-server

* Fix Dhall.Import API regarding `Chained` imports

Do not expose the `Chained` constructor; we don't want external code
breaking our invariants! Also further clarifies the comment describing
the `Chained` type.

* Fix dhall-lsp-server

Since we are no longer able to construct `Chained` imports directly we
need to export a few additional helper functions from Dhall.Import.
Furthermore, since VSCode (and presumably the other editors out there
implementing the LSP protocol) does not support opening remote files
anyway we can get rid of some complications by dropping support for
remote files entirely on the back-end.

* Generalise decodeExpression, fixes TODO

* Fix tests

* Fix benchmarks

* Remove Travis cache for `~/.local/bin`

* Fix copy-pasted comment

Thanks to @Gabriel439 for spotting this!

* Add clarifying comment to `toHeaders`
2019-07-17 15:20:48 +00:00
Frederik Ramcke
6534ce85ed Fix incorrect Canonicalize law (#1118)
It is not the case that
    canonicalize (a <> b) = canonicalize a <> canonicalize b.
For example
    canonicalize (Directory ["asd"] <> Directory [".."])
    = Directory [],
but
    canonicalize (Directory ["asd"]) <> canonicalize (Directory [".."])
    = Directory ["..", "asd"].

The law we want instead is:
    canonicalize (a <> b)
    = canonicalize (canonicalize a <> canonicalize b)
2019-07-17 13:13:40 +00:00
Frederik Ramcke
33ebf7ee71 dhall-lsp-server: Turn imports into clickable links (#1121)
* Expose `localToPath` in Dhall.Import

Also modifies `localToPath` to return a relative path if the input was
relative, rather than resolving relative paths by appending the current
directory.

* Turn imports into clickable links

This implements a handler for 'Document Link' requests. As a result,
imports are now clickable!

* Recover original behaviour
2019-07-17 08:54:56 +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
Gabriel Gonzalez
81ef514652 Move more dhall-json test logic into data files (#1108)
* Move more `dhall-json` test logic into data files

... as suggested @sjakobi in https://github.com/dhall-lang/dhall-haskell/pull/1094#pullrequestreview-261053408

* Fix CI failure

... as caught by @sjakobi

* Fix missing import of `(<>)`

... as noted by @sjakobi
2019-07-15 17:08:38 +00: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
Fabrizio Ferrai
0506c13822
Build macOS binaries with Travis (#1101) 2019-07-15 09:43:59 +03:00
Simon Jakobi
b2cbc8227f Remove usage of legacy Optional syntax (#1091)
* Remove usage of legacy Optional syntax

* Dhall.JSON: Use multilet in examples

* Update dhall-json/src/Dhall/JSON.hs

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* Update dhall-json/src/Dhall/JSON.hs

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* Update dhall-json/src/Dhall/JSON.hs

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* Update dhall-nix/src/Dhall/Nix.hs

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* Update dhall-nix/src/Dhall/Nix.hs

Co-Authored-By: Gabriel Gonzalez <Gabriel439@gmail.com>

* Revert changes to travis.yml

* Lint travis.dhall
2019-07-14 18:36:41 +00:00
Gabriel Gonzalez
e49710166e
Add dhall-json support for unions as keys (#1094)
This is inspired by this StackOverflow question:

https://stackoverflow.com/questions/56967374/dynamic-records-key-type
2019-07-12 22:25:46 -07:00
Gabriel Gonzalez
e0bd21e25d
Update web page (#1079)
The main improvements are:

* Add one-line summary of what Dhall is

  This is based on user feedback that some people could not tell what
  Dhall was based on the home page

* Replace "Tough on messes" section with "Integration friendly" section

  This is based on user feedback that the nethack example wasn't working
  for them and also because of a large number of questions in online
  discussions about how to integrate Dhall

* Fix tutorial examples to put public/private keys under `~/.ssh`

* Link to newly-added Wiki pages
2019-07-09 11:15:07 -07:00
Gabriel Gonzalez
90b62ee9d7 Replace dhall-to-text with dhall text subcommand (#1090)
Fixes #1087
2019-07-08 17:18:09 +00:00