You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix dhall-to-nix encoding of symbols with special keys (#2426)
* Fix dhall-to-nix encoding of symbols with special keys
Symbols in nix can only consist of a very restricted amount of
characters, whereas in dhall they can be basically anything.
So let’s use an encoding scheme similar to what GHC uses to generate C
symbols. Code slightly changed (some GHC-specific cases removed).
I might have missed some cases of dhall symbols that are translated
verbatim.
* dhall-to-nix: Encode unions slightly differently for better symbol
Symbols in nix can only consist of a very restricted amount of
characters, whereas in dhall they can be basically anything.
When you want to get a value of a union, before it was generated into
```
{ Foo, Bar }: Foo
```
where `Foo` cannot be a complex symbol like `{ Foo/Baz, Bar }:
Foo/Baz`, because nix does not allow it in anonymous record arguments.
So now we generate it as
```
u: u."Foo/Baz"
```
which should always work and is equal (though it loses the information
of what other fields are there in the nix code).
Before I faultily encoded some of these symbols with a Z-encoding, but
that was wrong, so it was undone.
* dhall-to-nix: Quote field selection symbols
Another one I missed, when you have a field selector, you want to
quote it, in case it has some symbols nix does not know how to handle.
`x.Foo/bar` will now be `x."Foo/bar"`, which is valid nix.
* dhall-to-nix: prepare using Text.concatMap in Z-encoding
We copied the Z-encoding functions from GHC more or less verbatim, but
we can rewrite it in terms of `Text.concatMap`, which should perform
better.
In this first step, we change all the helper functions from `Char ->
String` to `Char -> Text`, and apply hlint warnings.
* dhall-to-nix: Z-encode symbols without going through String
We can drop the extra `any needsEncoding` check, since it should be
performant enough on its own when using `Text.concatMap` and
simplifies the code a bit.
* dhall-to-nix: Only double-quote symbols if they have symbols
A small improvement in the generation logic.
The hnix should really just do this for us.
0 commit comments