1
1
mirror of https://github.com/tweag/nickel.git synced 2024-09-11 11:47:03 +03:00
Commit Graph

4120 Commits

Author SHA1 Message Date
dependabot[bot]
2a5ca51a63
chore(deps): bump braces from 3.0.2 to 3.0.3 in /lsp/vscode-extension (#1953)
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-11 15:07:37 +00:00
Yann Hamdaoui
03cf743c5c
[release.sh] update to 1.7.0 (#1951) 2024-06-11 14:19:21 +00:00
Yann Hamdaoui
7f9eb5ab2a
Update the release.sh script (#1952)
Update the release script by adding some missing `git add`, which were
lost when switching to using Topiary from crates.io.

Doing so, we also remove the `--dry-run` step before publishing: the
usual workflow is to perform the dry run test, and if it succeeds,
immediately do the actual publication. This isn't very useful: if the
dry run fails, we could have run the actual publication as well, which
would have fail in the same way, so this makes no difference. However,
if the dry run succeeds, we recompile each package one more time from
scratch, performing the exact same work for publication, which is
wasteful. At this point of the release script, we clearly intend to
release and we should just use `cargo publish` normally.
2024-06-11 14:12:45 +00:00
Yann Hamdaoui
95967eb400
Add from/to_tag_and_arg (#1939)
* Add from/to_tag_and_arg

This commit adds two functions to convert enums to and back from
records, as a tag and an optional argument. Such functions are useful to
handle enums in a general, dynamic way, while pattern matching requires
to know in advance the possible tags.

Additionally, we also implement a `map` function, which can be derived
from the conversions above.

* Update core/stdlib/std.ncl

Co-authored-by: jneem <joeneeman@gmail.com>

* Update core/stdlib/std.ncl

Co-authored-by: jneem <joeneeman@gmail.com>

* Update core/stdlib/std.ncl

Co-authored-by: jneem <joeneeman@gmail.com>

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2024-06-10 16:51:31 +00:00
jneem
9fe8b981f7
Update dependencies in the background evaluator (#1948)
The background evaluator needs to track dependencies separately, because
it doesn't share file ids with the main cache. This updates the
background dependencies when the foreground ones get updated.
2024-06-10 16:41:36 +00:00
Yann Hamdaoui
c767d09860
flake.lock: Update (#1947)
Flake lock file updates:

• Updated input 'crane':
    'github:ipetkov/crane/480dff0be03dac0e51a8dfc26e882b0d123a450e?narHash=sha256-dIubLa56W9sNNz0e8jGxrX3CAkPXsq7snuFA/Ie6dn8%3D' (2024-05-29)
  → 'github:ipetkov/crane/55e7754ec31dac78980c8be45f8a28e80e370946?narHash=sha256-1hZ/txnbd/RmiBPNUs7i8UQw2N89uAK3UzrGAWdnFfU%3D' (2024-06-04)
• Updated input 'nix-input':
    'github:nixos/nix/802b4e403bb5ad34b26e36fbbe89dab91126d215?narHash=sha256-plqdBU6ySFf0whOcLlMramll1T5r38vC9dwF9RlEO0Y%3D' (2024-05-31)
  → 'github:nixos/nix/0ab9369572f64b1ab70a8db29f79ae730ff31ab6?narHash=sha256-DHM/6HZsuJO%2Bk32vBfPzzhEwgMVpYdHiMD5r6qoCk9k%3D' (2024-06-08)
• Updated input 'nix-input/nixpkgs':
    'github:NixOS/nixpkgs/b550fe4b4776908ac2a861124307045f8e717c8e?narHash=sha256-7kkJQd4rZ%2BvFrzWu8sTRtta5D1kBG0LSRYAfhtmMlSo%3D' (2024-02-28)
  → 'github:NixOS/nixpkgs/88269ab3044128b7c2f4c7d68448b2fb50456870?narHash=sha256-%2Bf9c4/ZX5MWDOuB1rKoWj%2BlBNm0z0rs4CK47HBLxy1o%3D' (2024-06-03)
• Added input 'nix-input/nixpkgs-23-11':
    'github:NixOS/nixpkgs/a62e6edd6d5e1fa0329b8653c801147986f8d446?narHash=sha256-oamiKNfr2MS6yH64rUn99mIZjc45nGJlj9eGth/3Xuw%3D' (2024-05-31)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/ad57eef4ef0659193044870c731987a6df5cf56b?narHash=sha256-SzDKxseEcHR5KzPXLwsemyTR/kaM9whxeiJohbL04rs%3D' (2024-05-29)
  → 'github:NixOS/nixpkgs/051f920625ab5aabe37c920346e3e69d7d34400e?narHash=sha256-4q0s6m0GUcN7q%2BY2DqD27iLvbcd1G50T2lv08kKxkSI%3D' (2024-06-07)
• Updated input 'pre-commit-hooks':
    'github:cachix/pre-commit-hooks.nix/0e8fcc54b842ad8428c9e705cb5994eaf05c26a0?narHash=sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA%3D' (2024-05-20)
  → 'github:cachix/pre-commit-hooks.nix/cc4d466cb1254af050ff7bdf47f6d404a7c646d1?narHash=sha256-7XfBuLULizXjXfBYy/VV%2BSpYMHreNRHk9nKMsm1bgb4%3D' (2024-06-06)
• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/ab69b67fac9a96709fbef0b899db308ca714a120?narHash=sha256-4gVhbC%2BNjSQ4c6cJvJGNCI1oTcD%2B8jRRNAnOF9faGCE%3D' (2024-06-01)
  → 'github:oxalica/rust-overlay/6dc3e45fe4aee36efeed24d64fc68b1f989d5465?narHash=sha256-wqbRwq3i7g5EHIui0bIi84mdqZ/It1AXBSLJ5tafD28%3D' (2024-06-08)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-06-10 15:44:15 +00:00
jneem
446128b567
Fix nls crash, and better refresh diagnostics. (#1944)
* Add a test

* Invalidate cached terms.

In nls, if `main.ncl` imports `dep.ncl` and `dep.ncl` changes, we need
to invalidate some cached data about `main.ncl` and re-check it.
Previously we were simply resetting `main.ncl` to the "parsed" state in
the cache, but this isn't sufficient because our cached term for
`main.ncl` might depend on `dep.ncl`. Specifically, import resolution of
`main.ncl` transforms the term in a way that depends on whether
`dep.ncl` parsed.

This commit does the most inefficient (but easiest to get correct)
thing: throwing out all the parsed data and re-parsing from scratch.
This can be optimized, but it probably isn't too much slower than the
status quo, because we were re-typechecking from scratch anyway.

* Re-do background evaluation for invalidated files.

When `main.ncl` imports `dep.ncl` and `dep.ncl` changes, we invalidate
`main.ncl` and re-do some checks. This commit adds background
invalidation to the list of checks that we re-do.

* Move the recursive invalidation into Cache

* Reinstate/reword comment
2024-06-10 14:28:53 +00:00
Yann Hamdaoui
c3c73891ce
Fix record.get_or on undefined field (#1946)
Perhaps surprisingly, `std.record.get_or "a" true {a}` would error out
instead of returning `true`. This commit fixes it by only fetching the
value from the record if the field is present AND it is defined.
2024-06-07 16:04:55 +00:00
Yann Hamdaoui
4c29726b98
Rename and re-organize primitive operators (#1937)
Primitive operators haven't got much love, as opposed to user-facing
interfaces like the stdlib, and they have grown organically since the
beginning of the very first Nickel prototype. As a result, the naming is
inconsistent, with several generations, both in the surface syntax of
Nickel and internally in the Rust codebase.

This PR makes a cleaning pass on primitive operators, by:

1. Use full worlds in the style of the current stdlib: `str` ->
   `string`, `num` -> `number`, etc.
2. Introduce pseudo-namespaces: instead of `str_foo` and `record_bar`,
   we use `/` as a separator for categories. The previous examples
   become `string/foo` and `record/bar`. We don't use `.`, to make it
   clear that it's not a normal record access, but just a nice way to
   dinstinguish the different categories
3. Align old operators on the current naming in the standard library.
2024-06-07 11:27:21 +00:00
Yann Hamdaoui
519c0228ba
Add documentation for extended patterns (#1924)
This commit update the manual to take into account the latest extensions
of pattern matching, namely wildcard patterns, constant patterns, array
patterns, pattern guards and or-patterns.

Doing so, we also update the examples (in the manual and in the
`examples` directory) to use pattern matching whenever it looks more
idiomatic and make the code more readable.

Co-authored-by: jneem <joeneeman@gmail.com>
2024-06-07 08:58:39 +00:00
Erin van der Veen
3b00223521
use Topiary's published crates over git (#1919)
Now that Topiary is published and crates.io (and tree-sitter-nickel as
well), we move away from git revision and use proper public versions for
those. Doing so, we can also crap the special casing that was done
during release to disable those dependencies and we'll now be able to
release on crates.io a version with formatting enabled.

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2024-06-06 16:58:44 +00:00
dependabot[bot]
b4a3fd9ddb
chore(deps): bump DeterminateSystems/update-flake-lock from 21 to 22 (#1938)
Bumps [DeterminateSystems/update-flake-lock](https://github.com/determinatesystems/update-flake-lock) from 21 to 22.
- [Release notes](https://github.com/determinatesystems/update-flake-lock/releases)
- [Commits](https://github.com/determinatesystems/update-flake-lock/compare/v21...v22)

---
updated-dependencies:
- dependency-name: DeterminateSystems/update-flake-lock
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-06-04 07:57:18 +00:00
Yann Hamdaoui
d4d864d25e
Add --version support to NLS, fix feature unif (#1936)
Add `--version` support for the nls binary, using the same scheme as for
the main `nickel` binary.

Doing so, we discovered some underlying feature unification issues that
weren't visible before - but were already there -, namely that the
little stunt we pull off for generating versions in different
environment (in the git repo, building for crates.io and the nixified
version) requires the `string` feature of clap. It just happened that it
was enabled previously for `nickel-lang-cli` by chance by feature
unification (through `comrak`), but in fact building `nickel-lang-cli`
without the default features was failing.

This commit fixes the compilation issue by adding the missing `string`
feature to the `clap` dependency for both the cli and the lsp.
`nickel-lang-lsp` also depends on `nickel-lang-core` without the default
features now (as most of them are useless for the LSP), and we fix the
another compilation error of `nickel-lang-cli` without default features
by making `nickel-lang-core` always export `eval_record_spine`, which
would only be included when the `doc` feature was enabled before, but is
actually used for other purposes now (namely the CLI customize mode).
2024-06-03 14:59:26 +00:00
Yann Hamdaoui
f622f11047
flake.lock: Update (#1928)
Flake lock file updates:

• Updated input 'crane':
    'github:ipetkov/crane/7443df1c478947bf96a2e699209f53b2db26209d?narHash=sha256-TjUX7WWRcrhuUxDHsR8pDR2N7jitqZehgCVSy3kBeS8%3D' (2024-05-19)
  → 'github:ipetkov/crane/480dff0be03dac0e51a8dfc26e882b0d123a450e?narHash=sha256-dIubLa56W9sNNz0e8jGxrX3CAkPXsq7snuFA/Ie6dn8%3D' (2024-05-29)
• Updated input 'nix-input':
    'github:nixos/nix/209d75529caaaf82a760056fc60156b9153af5c8?narHash=sha256-BSvldBxypiYGuVuYfrIZNoM%2BtlkDsgQdz9HKe9e57v8%3D' (2024-05-20)
  → 'github:nixos/nix/802b4e403bb5ad34b26e36fbbe89dab91126d215?narHash=sha256-plqdBU6ySFf0whOcLlMramll1T5r38vC9dwF9RlEO0Y%3D' (2024-05-31)
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/4a6b83b05df1a8bd7d99095ec4b4d271f2956b64?narHash=sha256-%2BNpbZRCRisUHKQJZF3CT%2Bxn14ZZQO%2BKjxIIanH3Pvn4%3D' (2024-05-17)
  → 'github:NixOS/nixpkgs/ad57eef4ef0659193044870c731987a6df5cf56b?narHash=sha256-SzDKxseEcHR5KzPXLwsemyTR/kaM9whxeiJohbL04rs%3D' (2024-05-29)
• Updated input 'pre-commit-hooks':
    'github:cachix/pre-commit-hooks.nix/fa606cccd7b0ccebe2880051208e4a0f61bfc8c1?narHash=sha256-nacSOeXtUEM77Gn0G4bTdEOeFIrkCBXiyyFZtdGwuH0%3D' (2024-05-16)
  → 'github:cachix/pre-commit-hooks.nix/0e8fcc54b842ad8428c9e705cb5994eaf05c26a0?narHash=sha256-xrsYFST8ij4QWaV6HEokCUNIZLjjLP1bYC60K8XiBVA%3D' (2024-05-20)
• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/04d61d14803854fd8453ec43c5c53a471e5407a8?narHash=sha256-lc7wOh5BjYUoxdhcPkeUY8BmuL2qtRaHlW1403RW48E%3D' (2024-05-20)
  → 'github:oxalica/rust-overlay/ab69b67fac9a96709fbef0b899db308ca714a120?narHash=sha256-4gVhbC%2BNjSQ4c6cJvJGNCI1oTcD%2B8jRRNAnOF9faGCE%3D' (2024-06-01)
• Updated input 'topiary':
    'github:tweag/topiary/ba4f44062299cfc45d3c383e9697c325bedd0078?narHash=sha256-5o5DvwUYAmODYlFCuDJwRvEkitgq2SFD9Wy0DRMjKsY%3D' (2024-05-15)
  → 'github:tweag/topiary/42f2630130c36d8b69615ed9b96b50196451c80b?narHash=sha256-DoaPSJEs/3EWdzrgQtdVKFIvHALtZipwUI9DqqoSWgI%3D' (2024-05-30)

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-06-03 09:04:21 +00:00
Jakub A. G
c69a48be39
Add stdlib function array.at_or (#1927)
* Add stdlib function array.at_or

This is to return value at given position of array or default in case
provided position is out of bound.

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@gmail.com>

* Update manual snippets and snapshot tests

---------

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@gmail.com>
2024-05-30 09:00:26 +00:00
jneem
b14aeea035
Tell lsp about variable bindings in match statements (#1926)
* Tell lsp about variable bindings in match statements

* Also handle unapplied matches

* insta review

* Add a test getting match branch completions from type inference
2024-05-27 03:08:19 +00:00
Yann Hamdaoui
ca0f78fdbf
Or patterns (#1916)
This commit introduces or-patterns, which allows to express alternatives
within patterns, including in a deep subpattern.

The compilation of or-patterns is rather simple: we simply try each
alternative until one matches, and use the corresponding bindings.

Typechecking of or-patterns can be done following the same process as
for typechecking a whole match expression (which is also a disjunction
of patterns), although the treatment of bound variables is a bit
different.

Most of the complexity of this commit comes from the fact that we don't
want to make `or` a reserved language keyword, which would break
backward compatibility. This is possible, because `or` in pattern can't
be confused with an identifier, but it requires some tweaking to make
our LALR(1) parser accept this.
2024-05-25 12:25:58 +00:00
Austin Theriault
928cf14278
move Assert and check to the stdlib (#1914)
Move the Assert and check function from the local test library to the
stdlib, under the name of `std.test.Assert` and `std.test.assert_all`.

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@gmail.com>
2024-05-24 22:39:26 +00:00
jneem
c8e840180d
Opaque values (#1913)
* Add opaque values

* Add a test

* Rename to ForeignId

* Add a type alias for the payload

* Add typeof support
2024-05-24 22:38:22 +00:00
Jakub A. G
145fffd85d
Add get field value from record with default (#1920) 2024-05-24 22:36:20 +00:00
dependabot[bot]
28370ef919
--- (#1923)
updated-dependencies:
- dependency-name: cachix/cachix-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-21 07:06:45 +00:00
jneem
ed815b1c83
Improve build script performance (#1921) 2024-05-20 08:30:03 +00:00
Yann Hamdaoui
2c7dd14b54
flake.lock: Update (#1733)
* flake.lock: Update

Flake lock file updates:

• Updated input 'crane':
    'github:ipetkov/crane/6849911446e18e520970cc6b7a691e64ee90d649' (2023-11-09)
  → 'github:ipetkov/crane/27025ab71bdca30e7ed0a16c88fd74c5970fc7f5' (2024-05-09)
• Updated input 'flake-utils':
    'github:numtide/flake-utils/ff7b65b44d01cf9ba6a71320833626af21126384' (2023-09-12)
  → 'github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a' (2024-03-11)
• Updated input 'nix-input':
    'github:nixos/nix/1d86bb4f70ee5c2d06810f21bf7cd057ed46712c' (2023-11-17)
  → 'github:nixos/nix/87ab3c0ea4e6f85e7b902050365bb75cf2836fbb' (2024-05-10)
• Added input 'nix-input/flake-parts':
    'github:hercules-ci/flake-parts/9126214d0a59633752a136528f5f3b9aa8565b7d' (2024-04-01)
• Added input 'nix-input/flake-parts/nixpkgs-lib':
    follows 'nix-input/nixpkgs'
• Added input 'nix-input/libgit2':
    'github:libgit2/libgit2/45fd9ed7ae1a9b74b957ef4f337bc3c8b3df01b5' (2023-10-18)
• Removed input 'nix-input/lowdown-src'
• Updated input 'nix-input/nixpkgs':
    'github:NixOS/nixpkgs/9eb24edd6a0027fed010ccfe300a9734d029983c' (2023-11-01)
  → 'github:NixOS/nixpkgs/b550fe4b4776908ac2a861124307045f8e717c8e' (2024-02-28)
• Added input 'nix-input/pre-commit-hooks':
    'github:cachix/pre-commit-hooks.nix/40e6053ecb65fcbf12863338a6dcefb3f55f1bf8' (2024-04-12)
• Added input 'nix-input/pre-commit-hooks/flake-compat':
    follows 'nix-input'
• Added input 'nix-input/pre-commit-hooks/flake-utils':
    'github:numtide/flake-utils/5aed5285a952e0b949eb3ba02c12fa4fcfef535f' (2022-11-02)
• Added input 'nix-input/pre-commit-hooks/gitignore':
    follows 'nix-input'
• Added input 'nix-input/pre-commit-hooks/nixpkgs':
    follows 'nix-input/nixpkgs'
• Added input 'nix-input/pre-commit-hooks/nixpkgs-stable':
    follows 'nix-input/nixpkgs'
• Updated input 'nixpkgs':
    'github:NixOS/nixpkgs/bf744fe90419885eefced41b3e5ae442d732712d' (2023-11-14)
  → 'github:NixOS/nixpkgs/f1010e0469db743d14519a1efd37e23f8513d714' (2024-05-09)
• Updated input 'pre-commit-hooks':
    'github:cachix/pre-commit-hooks.nix/e558068cba67b23b4fbc5537173dbb43748a17e8' (2023-11-15)
  → 'github:cachix/pre-commit-hooks.nix/2849da033884f54822af194400f8dff435ada242' (2024-04-30)
• Updated input 'pre-commit-hooks/flake-compat':
    'github:edolstra/flake-compat/35bb57c0c8d8b62bbfd284272c928ceb64ddbde9' (2023-01-17)
  → 'github:edolstra/flake-compat/0f9255e01c2351cc7d116c072cb317785dd33b33' (2023-10-04)
• Updated input 'pre-commit-hooks/gitignore':
    'github:hercules-ci/gitignore.nix/a20de23b925fd8264fd7fad6454652e142fd7f73' (2022-08-14)
  → 'github:hercules-ci/gitignore.nix/637db329424fd7e46cf4185293b9cc8c88c95394' (2024-02-28)
• Updated input 'pre-commit-hooks/nixpkgs-stable':
    'github:NixOS/nixpkgs/c37ca420157f4abc31e26f436c1145f8951ff373' (2023-06-03)
  → 'github:NixOS/nixpkgs/614b4613980a522ba49f0d194531beddbb7220d3' (2024-03-17)
• Updated input 'rust-overlay':
    'github:oxalica/rust-overlay/e3ebc177291f5de627d6dfbac817b4a661b15d1c' (2023-11-17)
  → 'github:oxalica/rust-overlay/8eb8671512cb0c72c748058506e50c54fb5d8e2b' (2024-05-11)
• Updated input 'topiary':
    'github:tweag/topiary/79b93527d9bd59533f9a79fe490567963193fafd' (2023-10-23)
  → 'github:tweag/topiary/82a94a9f57104b89d4316afaeeab271cc51f7698' (2024-04-09)
• Updated input 'topiary/advisory-db':
    'github:rustsec/advisory-db/5ceeefcbbabf4b510ef8ede121d6dc57d1a1f7f8' (2023-07-08)
  → 'github:rustsec/advisory-db/0bc9a77248be5cb5f2b51fe6aba8ba451d74c6bb' (2024-04-03)
• Updated input 'topiary/crane':
    'github:ipetkov/crane/8b08e96c9af8c6e3a2b69af5a7fa168750fcf88e' (2023-07-07)
  → 'github:ipetkov/crane/06a9ff255c1681299a87191c2725d9d579f28b82' (2024-04-03)
• Removed input 'topiary/crane/flake-compat'
• Removed input 'topiary/crane/flake-utils'
• Removed input 'topiary/crane/flake-utils/systems'
• Removed input 'topiary/crane/rust-overlay'
• Removed input 'topiary/crane/rust-overlay/flake-utils'
• Removed input 'topiary/crane/rust-overlay/nixpkgs'
• Updated input 'topiary/flake-utils':
    'github:numtide/flake-utils/dbabf0ca0c0c4bce6ea5eaf65af5cb694d2082c7' (2023-06-25)
  → 'github:numtide/flake-utils/b1d9ab70662946ef0850d488da1c9019f3a9752a' (2024-03-11)
• Updated input 'topiary/nix-filter':
    'github:numtide/nix-filter/d90c75e8319d0dd9be67d933d8eb9d0894ec9174' (2023-06-19)
  → 'github:numtide/nix-filter/3342559a24e85fc164b295c3444e8a139924675b' (2024-03-11)
• Updated input 'topiary/rust-overlay':
    'github:oxalica/rust-overlay/d7181bb2237035df17cab9295c95f987f5c527e6' (2023-07-11)
  → 'github:oxalica/rust-overlay/20e7895d1873cc64c14a9f024a8e04f5824bed28' (2024-04-04)
• Updated input 'topiary/rust-overlay/flake-utils':
    'github:numtide/flake-utils/cfacdce06f30d2b68473a46042957675eebb3401' (2023-04-11)
  → 'github:numtide/flake-utils/1ef2e671c3b0c19053962c07dbda38332dcebf26' (2024-01-15)
• Updated input 'topiary/rust-overlay/nixpkgs':
    'github:NixOS/nixpkgs/96ba1c52e54e74c3197f4d43026b3f3d92e83ff9' (2023-04-13)
  → 'github:NixOS/nixpkgs/90f456026d284c22b3e3497be980b2e47d0b28ac' (2024-01-29)

* Update flake lock + fix consequences

After a flake lock update, some errors needed fixes:

- Updated Topiary input and formatted Nickel files
- Merging manual: remove line number-dependent part of the error
- Upgrade markdownlint config file to schema change
- Fix flake.nix

* Update flake.nix

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-18 08:13:26 +00:00
dependabot[bot]
8d88d63ac3
chore(deps): bump cachix/install-nix-action from 25 to 27 (#1917)
Bumps [cachix/install-nix-action](https://github.com/cachix/install-nix-action) from 25 to 27.
- [Release notes](https://github.com/cachix/install-nix-action/releases)
- [Commits](https://github.com/cachix/install-nix-action/compare/v25...V27)

---
updated-dependencies:
- dependency-name: cachix/install-nix-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2024-05-17 13:11:47 +00:00
Luna Cloudberry
fa1813e373
Update README.md for nix profile install (#1918) 2024-05-16 15:39:12 +00:00
Yann Hamdaoui
3af21b0d08
Implement array patterns (#1912)
This commit adds a new calss of patterns: array patterns. This is a
natural extension, both syntactically and semantically, of existing data
structure patterns in Nickel (in particular of records). Similarly,
arrays pattern can also capture the rest of the pattern (the tail of the
array that hasn't been matched yet) and bind it to a variable.
2024-05-16 15:29:30 +00:00
Yann Hamdaoui
7225b729c2
Implement pattern guards (#1910)
* Implement pattern guards

This commit implement pattern guards, which are side conditions that can
be added to the branch of a match expression, following the pattern, to
further constrain the matching. This condition is introduced by the
(already existing) `if` keyword. For example:

`match { {list} if list != [] => body }` will match a record with a
unique field `list` that isn't empty.

The compilation is rather straightforward, as a pattern is already
compiled to a tree of if-then-else while also building the bindings
introduced by pattern variables. After all the conditions coming from
the pattern have been tested, we just additionally check for the guard
(injecting the bindings in the condition since the guard can - and most
often does - use variables bound by the pattern).

* Update core/src/term/mod.rs

Co-authored-by: jneem <joeneeman@gmail.com>

* Exclude guarded patterns from tag-only optimization

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2024-05-13 15:29:37 +00:00
Jakub A. G
aca39eff18
Allow other formats for singleton input (#1901) (#1902)
Guess input format based on extension similarly like in multiple input case.
2024-05-07 08:33:28 +00:00
Yann Hamdaoui
07cd7197e1
Uniformize destruct and pattern matching logic (#1907)
* Uniformize destruct and pattern matching logic

When patterns were first introduced, only let-destructuring existed, and
match expressions weren't a thing. Rather than to manually generate code
that would check that a pattern does match the destructured value, we
piggy-backed on contracts instead, which was easier and provided better
error messages. Up to now, this was still how destructuring worked: a
contract is elaborated from the pattern and applied to the matched
value, and should report any error if the value doesn't match. Then,
destructuring is desugared to a series of let-bindings that assume that
the destucture value has the right shape. The generated code is thus
quite simple, as it doesn't have any error handling to do.

When pattern matching landed, we kept the old destructuring
infrastructure, because it was there and worked well. However, there is
duplication: the compilation of match expressions does a work quite
similar to destructuring.

What's more, we're at risk of having a diverging semantics. Some
questions aren't trivial to answer for destructuring, in particular with
respect to lazyness: should `let _ = x in null` force `x`? What about
`let 'Foo _ = x in null`, or `let 'Foo 5 = x in null`?

After some discussion, we decided to give destructuring a simple
semantics in term of pattern matching: `let <pat> = <matched> in <body>`
should be strictly equivalent to `<matched> |> match { <pat> => <body>
}`. Indeed, `match` has a clear semantics around forcing values in lazy
languages. This also agrees with intuition, or at least gives a
reasonable semantics for most cases.

This commit implements this change in practice, by getting rid of the
ad-hoc desugaring of destructuring and rewriting let-destructuring to
actual pattern matching instead.

* Update core/src/term/pattern/compile.rs

Co-authored-by: jneem <joeneeman@gmail.com>

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2024-05-06 16:06:46 +00:00
Erin van der Veen
d1b42df083
Add new_from_sources function to Program (#1900)
* Add new_from_sources function to Program

This is similar to the new_from_path and new_from_paths function. A
new_from_source function already existed, but a new_from_sources was
still missing.

* Abstract the common parts of the Program::new_from functions

* Explain the `File` type parameter to `Input`
2024-05-06 07:27:21 +00:00
Yann Hamdaoui
e8e9a346b2
Wildcard patterns (#1904)
* Add wildcard patterns

This commit adds a special pattern that doesn't bind anything and match
any value, the wildcard pattern `_`. This pattern doesn't force the
value being matched on.

* Update core/src/typecheck/pattern.rs

Co-authored-by: jneem <joeneeman@gmail.com>

* Fix mishandling of wildcard in enum pattern match compilation

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2024-05-06 04:09:57 +00:00
Yann Hamdaoui
efbe86b453
Include field path in non serializable error (#1905)
When failing to serialize a value, the error sometimes doesn't point to
a usable location (that is, it points to the definition site of some
function somewhere, but it's impossible to know where this function was
actually used, which is usually where the issue is).

This commit enriches the error message of non-serializable errors with a
path, à la JSON pointer (such that it also integrates array indices),
whenever possible. This should make debugging non serializable error
much nicer.
2024-05-04 13:51:33 +00:00
Yann Hamdaoui
3b01e62864
Add support for constant pattern (#1897)
This commit adds support for constant patterns, that is patterns
matching specific booleans, strings, numbers or the null value.
2024-05-02 08:43:46 +00:00
Erin van der Veen
c09b4ca865
Fix typo in BlameError documentation (#1899) 2024-04-29 14:20:54 +00:00
Yann Hamdaoui
13fe12cb70
[release.sh] update to 1.6.0 (#1896) 2024-04-25 09:32:10 +00:00
Yann Hamdaoui
428447cbbe
Update to latest Topiary and tree-sitter-nickel (#1893)
For some reason, the version of Topiary and of the Nickel tree sitter
grammar were lagging behind, before the support for pattern matching was
added, which means current master wasn't able to format a file with
pattersn in it - maybe it was a rollback because of the Topiary install
issue (https://github.com/tweag/topiary/issues/690).

The former issue has been fixed, so this commit update to latest Topiary
in order to get formatting of patterns.
2024-04-23 09:12:01 +00:00
jneem
05343939b1
Force enum payloads (#1890)
* Force enum payloads

* Add tests
2024-04-15 14:15:24 +00:00
Yann Hamdaoui
b731a436a7
Fix LSP not showing types in untyped code (#1889)
Most of the time, hovering over a symbol in untyped code would show
`Dyn` even though the symbol has a type annotation - in particular for
records accessed via a non-trivial path, e.g. `foo.bar.baz`. This is an
issue because in particular, we don't get to see the right types for
stdlib symbols when hovering over them.

This commit fixes the issue by taking the type annotation instead of the
type provided by the typechecker when the latter is `Dyn`.
2024-04-12 16:48:24 +00:00
Yann Hamdaoui
63edc969e2
Leverage function contract information (#1888)
When a function is annotated with a function contract, use this
additional type information to enable completion in the LSP (and also
use the domain as the type of the function's argument in the typing
environment, even if we are in walk mode). Contract data are easy to
fetch during typechecking when available and use them improve the
developer experience by bringing in more static information.
2024-04-12 16:43:31 +00:00
jneem
34a99fd55a
Extend the symbol range to include the rhs (#1887)
* Extend the symbol range to include the rhs

* Review comments
2024-04-11 22:18:45 +00:00
Yann Hamdaoui
98f05f90ff
Allow multiple underscore to start identifiers (#1884)
Identifiers were required to start with at most one optional underscore,
followed by an alphabetic character (to avoid identifiers like _-'), and
then by any identifier character. This means that identifiers like
`__foo` were invalid.

There is no good reason for that, and is mostly an oversight when
writing the initial regular expression. This commit extends the lexer to
allow zero or more heading underscores before the first alphabetic
character.
2024-04-10 16:52:38 +00:00
jneem
1f40fcfb0f
Dedup diagnostics (#1883)
* Deduplicate diagnostics

* Test the diagnostics deduplication
2024-04-05 19:19:00 +00:00
jneem
262ac8fa36
Fix infinite recursion in doc symbols. (#1881) 2024-04-04 08:57:19 +00:00
Yann Hamdaoui
6e79f0db56
Fix missing newline in markdown output (#1880)
A recent commit fixed the `nickel doc` markdown output having spurious
backslashes introduced. However, it also re-introduced a previous issue
- which was why the problematic hard line breaks were introduced in the
first place - which is that the list of types and contracts of a field
and the custom documentation might be squashed together because the
renderer wouldn't properly insert a newline after the generated list.

After some investigation, it seems to be a bug in the comrak renderer.
However, this bug doesn't show when the markdown is parsed from an
actual source (instead of being programmatically generated). It turns
out comrak correctly inserting this required newline relies on the
unspoken assumption that every markdown list item content is wrapped as
a paragraph. This commit thus fixes the issue by inserting the missing
paragraph wrapper.
2024-04-03 21:01:52 +00:00
Yann Hamdaoui
b4b17797fc
doc generation: do not insert line breaks (#1879)
The code generating markdown documentation from a Nickel configuration
used to unconditionally insert hard line breaks between a field's
signature and the rest of its documentation. However, one can't insert a
hard line break immediately followed by a blocks in commonmark (or put
differently: it's not representable as a source), and those line breaks
were just rendered as spurious backslashes at best, or sometimes
interpreted differently (see #1706 for more details).

A bit of experimentation showed that what comes after this line break is
always a block in the sense of commonmark (even when it's simple
documentation text, it's wrapped as a Markdown paragraph). Thus this
commit just removes the line break altogether, which is not useful and
never legal anyway.
2024-04-03 11:40:51 +00:00
jneem
cb91eeb71f
Add a recursion limit to background evaluation (#1878)
* Add a recursion limit to eval_permissive

* Add a test

* Review comments
2024-03-29 18:35:54 +00:00
Yann Hamdaoui
b2e7713322
Add empty optional fields-aware record operator variants (#1876)
* Add fields_all primop (doesn't ignore empty opts)

* Add empty-opt aware record op variants to stdlib

The design guideline around empty optional fields has been to make most
normal record operation ignore them, to avoid issues like trying to list
the field of a record and access them just to fail on an empty optional
introduced by a contract, which we shouldn't care about.

However, in some cases (typically operating on record contracts), users
might want to actually take empty optional fields into account. Most
primops were already existing in two variants internally (ignore empty
opts and consider all fields). This commit just makes them available as
clearly documented stdlib functions.

* Add `has_field_all`, change `_all` -> `_with_opts`

The previous commit introducing variants of record operators that don't
ignore empty optional fields missed `has_field`, whose variant is added
by this commit.

As decided by the team in the weekly meeting, the `_all` suffix
introduced in the previous commit has been changed to `_with_opts`,
which is a bit longer but less confusing and more explicit.
2024-03-29 13:56:38 +00:00
Yann Hamdaoui
4dc7696a29
Fix typos in code comments (#1874) 2024-03-28 10:04:50 +00:00
Yann Hamdaoui
d0459a6471
Fix polymorphic field type error (#1872)
Using a polymorphic type annotation on a record field, as in
`{id : forall a. a -> a = std.function.id}` would unexpectedly file with
a failure to unify `forall a. a -> a` with `a -> a`, which indicates
that the type annotation wasn't properly instantiated before being used
to check the value of the field.

It turns out the typechecking of the field per se is fine, but the issue
comes from the recursive environment: in a recursive record, we need to
build an environment with types for all record fields _before_ we can
start to actually typecheck each field. When the field isn't annotated,
we use a fresh unification variable. When typechecking the corresponding
field, we unify what's in the type environment (the unification
variable, but which might have been unified with another type at this
point) with the type inferred for the field.

However, when the field has a type annotation, we use this annotation
for the recursive environment instead (which is important to keep
polymorphic types...polymorphic). In this case, we would unify a
polymorphic type with the inferred type, which is the place that was
missing the instantiation.

One possibility is to just add the missing instantiation, but in fact
this unification is useless when there is a type annotation: to avoid
this useless work, we rather remember which fields are annotated, and we
entirely skip the unification for them.
2024-03-28 08:45:02 +00:00
jneem
1caa77e0d8
Don't leak memory in background eval (#1869)
* Run a separate process for each background evaluation job

* Send over only the dependencies, not everything

* Remove ipc-channel

* Kill the child process if it times out

* Add some comments
2024-03-26 20:12:37 +00:00