Commit Graph

627 Commits

Author SHA1 Message Date
quasicomputational
e8724ed306
Fix some performance issues (#420)
* Speed up type-checking large expressions bound with let

In #69, `let` was changed to substitute in the value of the bound
variable. However, if that value was large (e.g., the `constructor` of
a 300-constructor union), this has a very adverse impact on
performance where that value has to be re-typechecked at each use
rather than once when it is bound, leading to #412.

We can do better. #69 only changed anything when a type is being
bound. So we can check the type of the type being bound and change
strategy depending on whether it is `Type` or `Kind`: if it is a
`Type` we can get away with treating it like the pre-#69 behaviour; in
other cases, we fall back to substituting the value in.

* Remove a slow toList call in a hot-spot.

toList from insert-ordered-containers does some work to ensure that
the elements do follow insertion order. In this instance, insertion
order doesn't matter: we only need to peek at each element to make
sure it is well-typed. If there are multiple type errors, it does not
matter which gets reported first here.

This is less of a win than the previous commit, but it is still a
significant performance improvement.

* Omit re-typechecking variables at use sites.
2018-06-04 17:49:50 +01:00
quasicomputational
798d6627e3
Benchmark for #412's performance issue. (#419) 2018-06-02 07:54:25 +01:00
Fintan Halpenny
8bd410f8f5
Use Strict Text for Parsing. (#422)
* Benchmark Prelude files

* Add issue 108 example

* Some cleaning up

* Remove printing of files

* Add bounds

* Clean cabal formatting

* Using strict Text instead of lazy Text

* Fixing compilation errors

* Update tests

* Cleanup

* Revert benchmark merge

* Update comments to replace the mention of Builder to Text
2018-06-01 11:54:07 -06:00
Fintan Halpenny
6f626c96bc
Add Benchmarking (#415)
* Benchmark Prelude files

* Add issue 108 example

* Some cleaning up

* Remove printing of files

* Add bounds

* Clean cabal formatting

* Add benchmark examples to extra source files

* Add Nix support for benchmarks

* This doesn't (yet) run or build the benchmarks in CI due to the long time
to execute all of them, but this does add them to the `shell.nix` so that
they can be run using local development
2018-06-01 11:39:30 -06:00
quasicomputational
25d86e8e5d Remove the Parent constructor from FilePrefix. (#407)
The 'Parent' constructor is entirely subsumed by 'Here'; having it
only leads to redundant representations.

Closes #406.
2018-05-27 17:25:44 -07:00
Gabriel Gonzalez
508327d56f
Add back tests for List/indexed (#405)
This adds back the missing tests for `List/indexed` (and fixes the
test failures)
2018-05-27 06:39:21 -07:00
Gabriel Gonzalez
8a7f221c18
Fix canonicalization bug (#403)
Fixes #402

The simplest way to summarize this bug is the following incorrect behavior
before this change:

```
>>> Dhall.Import.canonicalize (Directory {components = ["..",".."]})
Directory {components = []}
```

After this change the behavior is correct

```
>>> Dhall.Import.canonicalize (Directory {components = ["..",".."]})
Directory {components = ["..",".."]}
```
2018-05-25 10:03:50 -07:00
Gabriel Gonzalez
1955ba3a9c
Depth-first import algorithm (#396)
The standard specifies a depth-first import algorithm for resolving
imports but the Haskell implementation was using a breadth-first import
algorithm, which this change fixes
2018-05-22 18:50:54 -07:00
Gabriel Gonzalez
3e8c93d709
Fix haddocks for Directory type (#401)
Fixes #399
2018-05-22 18:36:33 -07:00
Gabriel Gonzalez
e177d9bdfa
Align then/else when formatting if expressions (#398)
Fixes #397
2018-05-21 10:43:17 -07:00
Gabriel Gonzalez
dddfb1a8ea
Version 1.13.1 → 1.14.0 (#386) 2018-05-19 09:55:43 -07:00
Gabriel Gonzalez
17b4409a70
Update Prelude references to latest version (#395) 2018-05-19 09:34:07 -07:00
Gabriel Gonzalez
433e178000
Fix α-equivalence bug when type-checking merge (#394)
Fixes #391

... as standardized in https://github.com/dhall-lang/dhall-lang/pull/156
2018-05-19 07:43:48 -07:00
Greg Pfeil
429aeaffb8 Normalize each import before it is cached. (#392)
In tests on Dhall configs we use at work, I saw speedups between 33–90% on
extremely complicated configs with this change.

It mostly just adds a line calling `normalize`, but also threads the Normalizer
through a bunch of places to make sure we normalize properly for the context.
2018-05-17 08:07:46 -07:00
Gabriel Gonzalez
544b863cbc
Add a pwd derivation force status updates by Hydra (#393)
Hydra doesn't update a pull request if the derivation hasn't changed
since the last revision (i.e. a cache hit).  This change adds a `pwd`
derivation which depends trivially on the current directory to force a
cache miss and status update
2018-05-17 08:01:00 -07:00
Gabriel Gonzalez
a4c577997a
Update import logic to more closely match standard (#390)
This is one step in a series of commits to update the Haskell
implementation to match the import semantics standardized in:

https://github.com/dhall-lang/dhall-lang/pull/127

This is a BREAKING CHANGE mostly due to restricting the grammar for
valid file paths and URLs.  However, in practice most existing code
should still work after these changes.

Specifically, this change:

* Updates the grammar for file paths and URLs
* Simplifies and cleans up the semantics for canonicalizing paths (and
  chains of paths)

The main difference in the grammar is that file paths and URL paths are
unified to have the same syntax and they are both more restricted than
before.

For example, the following URLs are no longer valid:

* `http://example.com` (missing a path to a file)
* `http://example.com/()` (invalid path characters)

... and the following paths are no longer valid:

* `/?#` (invalid path characters)

Note that this actually deviates from the standard in one way: file
paths no longer permit `?` and `#` characters (whereas the standard
allows them).  However, in the course of testing these changes I
realized that if file paths permit `?` and `#` characters and you unify
URLs to also permit them then you get an ambiguous grammar where a `?`
or `#` in a URL could be interpreted as either part of a path component
or part of a query parameter or fragment.

The semantics for canonicalizing paths is a straightforward translation
of the standard to Haskell code.
2018-05-16 17:14:15 -07:00
Greg Pfeil
5da4544ad8 Cache imports that contain imports. (#388)
Relevant to #362.

Previously, if an import contained additional imports, it wouldn’t get
cached. This fixes that, with a couple related changes:
- type checking happens in the failed-lookup branch, rather than having to
return a `cached` boolean,
- the normalized form of the import is used more consistently (although this
doesn’t fix the related normalization problem around `../`)
2018-05-15 18:22:55 -07:00
Greg Pfeil
607cb6f366 Add non-Haskell dependencies to stack.yaml. (#389)
Not sure if this is a change you’re interested in. IMO, it’s nice for stack
users even if they don’t use Nix, since it makes the dependencies explicit.
2018-05-15 17:56:06 -07:00
Gabriel Gonzalez
e21f989cd7
Drop support for importing directories (#384)
Dhall used to support importing a directory, which would default to
importing a file named `@` underneath that directory (similar to how
`default.nix` works in Nix).  This change drops support for that since
there is no plan to standardize that feature.  I view this as sort of
a mis-feature that Dhall inherited from Morte because it it confusing
magic that deteriorates error messages when importing files.  Support
for `@` also complicates the standardization of the import system, so
I prefer to just drop support for it to keep things simple.
2018-05-14 09:10:24 -07:00
Gabriel Gonzalez
c7d595954c
Include path to the failed import in HashMismatch errors (#385)
Fixes #383

Dhall has a standard way to report where hash mismatch failure occur but
I forgot to use this reporting system when implementing the hash
mismatch failure.

For example, using this file:

```bash
$ cat example.dhall
./Prelude/List/replicate sha256:b0e3ec1797b32c80c0bcb7e8254b08c7e9e35e75e6b410c7ac21477ab90167ae
```

... the error message you would get before this change was:

```bash
$ dhall <<< './example.dhall'

Error: Import integrity check failed

Expected hash:

↳ b0e3ec1797b32c80c0bcb7e8254b08c7e9e35e75e6b410c7ac21477ab90167ae

Actual hash:

↳ b0e3ec1797b32c80c0bcb7e8254b08c7e9e35e75e6b410c7ac21477ab90167ad
```

... and the error message you get after this change is:

```bash
$ dist/build/dhall/dhall <<< './example.dhall'

↳ ./example.dhall
  ↳ ./Prelude/List/replicate sha256:b0e3ec1797b32c80c0bcb7e8254b08c7e9e35e75e6b410c7ac21477ab90167ae

Error: Import integrity check failed

Expected hash:

↳ b0e3ec1797b32c80c0bcb7e8254b08c7e9e35e75e6b410c7ac21477ab90167ae

Actual hash:

↳ b0e3ec1797b32c80c0bcb7e8254b08c7e9e35e75e6b410c7ac21477ab90167ad
```
2018-05-13 17:20:41 -07:00
Gabriel Gonzalez
019ca728f6
Build against tasty-1.1 (#382)
See: https://github.com/fpco/stackage/issues/3620
2018-05-13 09:04:21 -07:00
Gabriel Gonzalez
2e631db47a
Switch grammar of Natural and Integer (#381)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/141

Now `Natural`s no longer require a leading `+` and non-negative `Integer`s
require a leading `+`

This also adds a `doctest` test suite to prevent regressions in haddock
examples
2018-05-12 09:20:08 -07:00
Gabriel Gonzalez
fa4569eaaf
Rename Path{,Mode,Hashed,Type} to Import{,Mode,Hashed,Type} (#376)
This updates the data types to match the terminology used in the
standard.  Specifically, "path" specifically refers to a directory or
file, whereas "import" is a broader term encapsulating URLs and
environment variables.

This is a breaking change but an easy one to adapt to.  Most downstream
consumers of the API just use the `Path` type, and this change includes
a `Path` type synonym for backwards compatibility.
2018-05-11 08:58:06 -07:00
Javier Neira
40302dac5b set minor version of insert-ordered-containers dep to 0.2.1.0 (#377) 2018-05-11 08:52:10 -07:00
Gabriel Gonzalez
a38e1a5081
Version 1.13.0 → 1.13.1 (#375) 2018-05-04 07:13:08 -07:00
Gabriel Gonzalez
855e06a1fe
Increase upper bound on ansi-terminal and megaparsec (#373) 2018-04-30 21:27:17 -07:00
Gabriel Gonzalez
c635f1f77b
Pin nixpkgs (#372)
This pins `nixpkgs` to a recent revision from the `release-18.03`
2018-04-30 08:40:29 -07:00
Gabriel Gonzalez
3fb4d0e758
Version 1.12.0 → 1.13.0 (#368) 2018-04-28 07:51:15 -07:00
Gabriel Gonzalez
e65aface58
Allow whitespace before interpolated expression (#369)
As standardized in https://github.com/dhall-lang/dhall-lang/pull/132
2018-04-28 06:29:54 -07:00
Gabriel Gonzalez
85ed73e749
Fix typo (#358) 2018-04-25 17:18:01 -07:00
Gabriel Gonzalez
cffcfc257b
Document that dhall now always formats output (#366)
Fixes #364
2018-04-24 17:36:13 -07:00
Hardy Jones
8f88d7d8e8 Fix documentation for UnionLit (#360)
This was a typo from long ago.
We construct `UnionLit`s without tuples.
The documentation reflects that now.
2018-04-15 16:50:14 -07:00
Gabriel Gonzalez
ac68adc14e
Trim unnecessary extensions from Dhall.Context (#353)
The `GeneralizedNewtypeDeriving` extension was not being used at all

The `BangPatterns` extension was not necessary because the argument `n` was
already being forced before each modification
2018-04-08 20:37:47 -07:00
Gabriel Gonzalez
a0a2ac12eb
Remove unused base16-bytestring dependency (#355) 2018-04-08 20:32:56 -07:00
Gabriel Gonzalez
50a10f69d1
Add sub-commands for each interpreter phase (#352)
This adds new `dhall version`, `dhall resolve`, `dhall type`, and
`dhall normalize` subcommands.  The latter three subcommands can be used
to run just one phase of the interpreter.

If you omit the subcommand then the executable behaves the same as
before.
2018-04-07 07:10:30 -07:00
Javier Neira
8c0f09fb4d Support for ghc-7.10.3 / lts-6.27 (#340) 2018-04-06 14:39:21 -07:00
Gabriel Gonzalez
a07424a81b
Use optparse-applicative instead of optparse-generic (#351)
There are two motivations for this change:

* To slim down `dhall`'s dependency footprint
* To allow greater control over option customization
2018-04-05 07:28:35 -07:00
Gabriel Gonzalez
4f2103a769
Add support for projecting a subset of record fields (#350)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/126
2018-04-05 07:13:12 -07:00
Oliver Charles
14b083ba76 Add RecordType, record and field (#338) 2018-04-05 07:08:17 -07:00
Gabriel Gonzalez
9b5be7b223
Add whitespace before and after REPL output (#347)
This adds an additional newline before and after each output line in the
REPL so that it's easier to visually separate commands from their
results
2018-04-04 17:42:49 -07:00
Gabriel Gonzalez
d473f83ef5
Fix derived Inject instance for sum types (#348)
Related to #346

This fixes the `GenericInject` instance for a sum type with two
constructors to include the type of the alternative constructor.  For
example, before this change you would get the following incorrect
conversion:

```
$ cabal repl lib:dhall
>>> :set -XDeriveGeneric
>>> :set -XDeriveAnyClass
>>> data Amount = Debit Scientific | Credit Scientific deriving (Show, Generic, Inject, Interpret)
>>> Dhall.Core.pretty (embed inject (Debit 5.45))
"< Debit = { _1 = 5.45 } >"
```

... which is missing the `Credit` alternative.

After this change you get the correct result:

```
< Debit = { _1 = 5.45 } | Credit : { _1 : Double } >
```
2018-04-01 17:48:18 -07:00
Gabriel Gonzalez
5d99c18e29
Change :type to only print type in dhall-repl (#344) 2018-04-01 10:43:11 -07:00
Gabriel Gonzalez
b1c40fa616
Fix semantic integrity hashes (#345)
This fixes both the parsing and rendering of semantic hashes, which were
failing due to missing conversions to and from base16-encoded
bytestrings
2018-04-01 10:31:26 -07:00
Gabriel Gonzalez
21355e7858
Fix pretty-printing of source positions (#343)
This fixes the `Buildable` instance for `Src` to use
`Text.Megaparsec.sourcePosPretty` instead of `Show` to give a
nicer-looking file/line/column position for error messages
2018-03-31 08:51:10 -07:00
Gabriel Gonzalez
9cb89df6d6
Add new operator for merging record types (#342)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/117
2018-03-31 08:43:36 -07:00
Gabriel Gonzalez
4b2e428d06
Add concise types diffs to error messages (#336)
Fixes #207

This expands Dhall's error messages to include concise "type diffs"
whenever an actual type doesn't match an expected type.  For example,
here is an example diff for some small changes to a very large (6,159
lines) type:

```
dhall <<< '../dhall-to-cabal/dhall-to-cabal.dhall : ./type.dhall'

Use "dhall --explain" for detailed errors

Error: Expression doesn't match annotation

{ - license2 : …
, + license : …
,   library : …
              (   ∀(… : { arch :   ∀(… : < S390 : - Bool
                                                  + {}
                                         | …
                                         >
                                   )
                                 → …
                        , …
                        }
                  )
                → { build-tools : …
                                  { - version2 : …
                                  , + version : …
                                  , …
                                  }
                  , default-extensions : …
                                         < - NamedWildCards2 : …
                                         | - UnboxedSums : …
                                         | + DataKinds : …
                                         | + NamedWildCards : …
                                         | …
                                         >
                  , …
                  }
              )
, …
}

../dhall-to-cabal/dhall-to-cabal.dhall : ./type.dhall
```

These type diffs are always emitted (i.e. present even if the user does
not supply the `--explain` flag).
2018-03-28 08:43:24 -07:00
Oliver Charles
922e20e6ab Replace trifecta with megaparsec (#268)
The long-term motivation for this change is so that we can eventually use a
separate `attoparsec`-based lexing step to greatly increase parsing speed since
the `trifecta`/`parsers` API doesn't allow tokens other than `Char`.

The secondary motivation for this is that `megaparsec` is a smaller dependency
that is more actively maintained.
2018-03-27 09:09:20 -07:00
Gabriel Gonzalez
0ffe854d6d
Restrict records to forbid storing both types and terms (#335)
... as standardized in https://github.com/dhall-lang/dhall-lang/pull/120
2018-03-25 18:16:11 -07:00
Gabriel Gonzalez
7d7b8590b5
Version 1.11.1 → 1.12.0 (#334) 2018-03-24 09:51:45 -07:00
Gabriel Gonzalez
ed2041ee77
Make dhall -Wcompat clean (#331)
This fixes Dhall to exactly match the guidance given in
https://prime.haskell.org/wiki/Libraries/Proposals/SemigroupMonoid for
compatibility with GHC 8.4
2018-03-19 19:24:01 -07:00