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

4212 Commits

Author SHA1 Message Date
Yann Hamdaoui
8e96d375ac
Move enum type parsing into its own rule (#1791) 2024-01-30 17:14:37 +00:00
Yann Hamdaoui
45fa3cd55e
Move constr_unify to trait and rename (#1790)
Small refactoring as a follow-up of the initial ADT introduction commit:
as constr_unify is now implemented for both enum rows and record rows,
it's cleaner to put it in a trait. It's also renamed for a bit more
clarity.
2024-01-30 17:05:37 +00:00
Yann Hamdaoui
d8c745649e
Fix expressions evaluated multiple times (#1789)
This commit fixes an issue that has been introduced by the removal of
generated variables, together with the `should_update` optimization,
which tries to avoid thunk update that are unnecessary.

However, as detailed in the added documentation for should_update, this
didn't work well with the removal of generated variables, which would
materialize by not sharing inner expressions for variables whose value
was already a data structure in weak head normal form (arrays, records
or now enum variants). Inner expressions would be recomputed.

This commit fixes the issue by adding a condition that datastructure
that aren't yet closurized shouldn't eschew thunk update.

Doing so, this commit also adds the missing closurization of ADTs, which
caused enum variant's arguments to also be potentially re-evaluated many
time.

Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>
2024-01-30 17:02:24 +00:00
Yann Hamdaoui
8fc5563e23
Implement missing equality on ADTs (enum variants) (#1787)
Implement the missing case of the `==` operator for newly introduced
ADTs (enum variants), together with basic tests.

Co-authored-by: jneem <joeneeman@gmail.com>
2024-01-30 16:43:02 +00:00
Yann Hamdaoui
bbc56d0f54
Structural ADTs: first step (#1770)
* Add term variant for ADTs

This commit is a very first step toward adding structural Algebraic Data
Types to Nickel. This commit adds a new node in the AST for an enum tag
with an argument (a variant), and fill the blanks/compiler errors from
there.

A temporary syntax, choosen mostly to be obscure, ugly, easy to add and
to not conflict with existing syntax has been added for further testing
and experimentation: 'SomeTag..(argument).

* Add typechecking capabilities for ADTs

This commit extend enum row types to accept a variant, that is to handle
types such as `[| 'Foo Number, 'Bar {foo : String} |]`, which are
basically structural ADTs.

The bulk of the work consist to extend most function operating on enum
rows to now take into account the fact that enum rows can have types
inside, much as record rows. That is, the code handling enum rows and
record rows is much more similar than before; the main difference being
that for now, enum rows have an optional type argument (the variant,
which can be there or not), while a record row always have a type
assignment.

At this point, no elimination forms for ADTs have been introduced yet
(that is, you can't match on/unwrap ADTs). This part is intentionally on
the side for the time being.

* Fix tests

* Add syntax for ADTs enum types

Add missing surface syntax to write enum rows with a variant (an
argument). Fix some pretty printing shortcomings as well.

* Extend mk_xxx macros for ADTs, fix rustc errors

* Add error reporting for enum row mismatch

Extend various typechecker internal error types with new cases for
augmented (with variants) enum rows

* Fix typo in code comment

* Fix incorrect code documentation

* Small fix to tests and compilation

* Add passing tests for ADTs MVP

* Adapt test infra to new type errors

* Pretty printing of enum variants: match current syntax

* Add test of failure cases of typechecking ADTs

* Remove dead comments, minor comment rewording

* Update core/src/typecheck/eq.rs

* Update core/src/typecheck/mod.rs

* Update core/src/typecheck/unif.rs

* Update core/src/parser/grammar.lalrpop

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

* Improve description of EnumVariant

* Update obsolete description of EnumRowF

* Update core/src/typecheck/unif.rs

Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>

---------

Co-authored-by: jneem <joeneeman@gmail.com>
Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>
2024-01-30 16:08:58 +00:00
jneem
2c5f2b0f73
Improve the FieldResolver api (#1782)
* Improve the FieldWalker api

* Update lsp/nls/src/field_walker.rs

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

---------

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2024-01-29 17:34:00 +00:00
Yann Hamdaoui
a16833ba52
Backport master/1.4.1 (#1781)
* Make base branch configurable in release script

Instead of hardcoding master as the base branch for a new release, put
it inside a shell variable than can be overriden (at least by modifying
the script) for patch releases, where it's more common to start off a
specific branch which isn't master (but the previous release + selected
bug fixes).

Additionally, add a missing phase before releasing to crates.io: get rid
of `lsp-harness` dependencies in the LSP.

* [release.sh] update to 1.4.1

* Update scripts/release.sh
2024-01-28 09:51:48 +00:00
Taeer Bar-Yam
220733cfa6
correctly drop Array::IntoIter (#1773)
* correctly drop Array::IntoIter

If you called Array::into_iter() you could leak elements in two circumstances:
1. If you did not iterate through all elements before dropping, since they had been converted to `ManuallyDrop`
2. If the Array had multiple references when the iterator was created, but the other references were dropped before the iterator was dropped, then the existence of the iterator would prevent those Rcs from dropping their contents, but then because the iterator is of type ManuallyDrop, it wouldn't drop those elements either

* eta reduction

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

* update comments and fix eta-reduction error

---------

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2024-01-24 21:02:42 +00:00
Yann Hamdaoui
266f609547
Fix --field not applying pending contracts (#1778)
The `--field` argument has been added in 1.3 to act only on a specific
field of the configuration. However, pending contracts (contracts
attached to the field by metadata annotations or propagated through
merging) weren't properly applied, leading to illegal values being
accepted.

This commit fixes the issue by adding the missing contract application
step. A snapshot test is added as a regression test. While it's not
ideal (we don't encode in the test what is the expected result), it's
the best we can do currently for CLI-only tests.
2024-01-24 13:31:37 +00:00
Yann Hamdaoui
4f84cf05e8
Proper error variant for non exhaustive match (#1772)
Argument to match expressions that wouldn't match any of the branches
used to have a pretty bad error message ("expecting Enum, found Enum").
This commit creates a proper variant for non-matching expressions,
pointing to the match expression and to the value the argument evaluated
to.

Currently, one position that might be lost in translation is where the
match expression was applied. It's a bit harder to track; for now, this
commit is a trivial change and is a strict improvement over the previous
situation. Let's reconsider later if this is insufficient.
2024-01-23 12:45:33 +00:00
Yann Hamdaoui
8a1e5387d5
Allow metadata keywords in field position (#1768)
Metadata keywords (optional, default, etc.) are numerous and they can't
clash with field names, because they don't appear in the same positions.
Thus, to avoid having user to quote their fields, this commit allows
unambiguously the usage of metadata keyword in field position.
2024-01-19 11:15:57 +00:00
Yann Hamdaoui
7d61228791
Add more space to contract error messages (#1767)
Craming "error: contract broken by ...", a potential addendum for
parametric contracts, and the contract's custom error message into the
main error label of a contract error proved to be hard to read.

This PR simply introduces some spacing to make it better (mostly new
lines and indentation), while keeping the same error structure.

Co-authored-by: Viktor Kleen <viktor.kleen@tweag.io>
2024-01-19 11:03:12 +00:00
Viktor Kleen
22a02743b2
Check if stderr is a terminal for error messages (#1766)
Prveiusly we checked whether `stdout` is a terminal to make our coloring
decision, and then we proceeded to happily assume the same state applies
to `stderr` for ad mctual error messages. However, if someone redirects
`stdout` to capture evaluation results, `stderr` may still be a terminal
and should receive colored output in this case. This PR omplements this
behavior and makes the choice of which output stream to check explicit.
2024-01-18 14:17:36 +00:00
dependabot[bot]
28b6c71905
chore(deps): bump cachix/cachix-action from 13 to 14 (#1762)
Bumps [cachix/cachix-action](https://github.com/cachix/cachix-action) from 13 to 14.
- [Release notes](https://github.com/cachix/cachix-action/releases)
- [Commits](https://github.com/cachix/cachix-action/compare/v13...v14)

---
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-01-15 09:40:07 +00:00
dependabot[bot]
c8ab7fb931
chore(deps): bump cachix/install-nix-action from 24 to 25 (#1761)
Bumps [cachix/install-nix-action](https://github.com/cachix/install-nix-action) from 24 to 25.
- [Release notes](https://github.com/cachix/install-nix-action/releases)
- [Commits](https://github.com/cachix/install-nix-action/compare/v24...v25)

---
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-01-15 09:39:47 +00:00
Viktor Kleen
ad00647462
Stop using spot instances for release builds (#1760)
We now had a failure to build release binaries due to a spot instance
getting canceled early for the second time. For now, I propose not using
a spot instance. While this will increase the cost, with it only getting
run once per release, I don't think there's cause for concern.

This change is change is already deployed to the AWS account to build
the 1.4 release artifacts.
2024-01-12 15:04:25 +00:00
jneem
0870523194
Add "goto definition" support for the import term (#1756)
* Make goto definition work for the import term

* Add a test
2024-01-11 18:13:54 +00:00
Yann Hamdaoui
6015c8c0cb
Backport 1.4 release to master (#1755)
* Only update relevant deps in Cargo.lock

The release script needs to update Cargo.lock after having updated
Cargo.toml with the new version of various Nickel crates.

Indeed, we are running some checks via Nix, and Nix builds are sandboxed
without network access. This requires the Nix build to use `cargo
--frozen --offline`, which in turns require the Cargo.lock file to be
up-to-date or it will fail.

The previous version of the release script would do a simple `cargo
update`, which has the default of updating all dependencies. This commit
changes that to only udpate dependencies which we might have bumped.

* Add pause to commit release notes in release script

* Fix release script for LSP

The release script was missing a part: the removal of `lsp-harness` (a
local, unpublished util crates) from the nickel-lang-lsp package priori
to publication to crates.io.

Passing by, other small improvements and fixes are included as well.

* [release.sh] update to 1.4.0

* Specify 'do not commit' when updating release notes

* release guide: add missing step for lsp-harness removal
2024-01-11 09:15:16 +00:00
jneem
ebbb4f294d
Completion in arrays (#1746)
* Rename FieldHaver -> Container and add an Array variant

* Support arrays in the field resolver

* Add a test

* Do better on the renaming

* Don't look at pending_contracts
2024-01-09 18:08:40 +00:00
Yann Hamdaoui
f6227ce18c
Update Topiary to handle (.) curried op (#1753)
The curried version of the field access operator `(.)` wasn't handled
properly by the Nickel tree-sitter grammar, and thus Topiary, and thus
`nickel format`.

This commit simply updates to the latest version of Topiary. We also
switch from using tree-sitter-nickel from crates.io to using the same
version as Topiary (from the repository).
2024-01-09 12:44:17 +00:00
Yann Hamdaoui
6ffa6ac0a1
Fix the order of argument in (.) (#1752)
* Fix order of arguments for curried dot operator

* Add std.record.get to stdlib

* Update release note with breaking changes for (.)

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

* Remove snapshot test for std.record.get

Unfortunately, the output of the error message shows a closure address
(in practice, a memory address), which makes it non-determinstic and
thus unfit for a snpashot test.

Instead, it's been replaced with an integration test, which
Unfortunately won't allow to detect a deterioriation in error reporting,
but at least ensure that the contract of `std.record.get` works as
expected.

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2024-01-09 10:11:48 +00:00
Yann Hamdaoui
1dd4deb9ec
Add a release script (#1748)
* Add a release script

First draft of a release script to automate most of the painful details
of releasing a new version of Nickel and associated crates.

* Update the releasing guide with new script

* Minor fixes to release script

* Change casing, use namerefs and other small improvements

* Make sure to checkout master before release process

* Make release.sh executable

* Shellcheck pass

* Various fixes and improvement

* More polishing of the release script

* Try sed-based Cargo.toml modifications

* WIP

* Fix cleanup actions after using it add

* Improve confirmation printing

* Fix undefined variable and cleanup actions

* Fix cleanup of ./Cargo.toml

* Fix jq invocation and circular reference warning

* Run cargo update during release script to fix Nix flake check

* Add cargo as requirement for release.sh

* Comment out effectful commands, fix Cargo.lock cleanup

* Add topiary cleaning to the release script

* [TODROP] disable nix flake check for rapid iteration

* [TODROP] Disable cleanup for debugging purpose

* Tentative fix of the remove Topiary dep step

* Avoid trailing commas when removing Topiary

* Improve output of removing topiary dependencies

* Fix issues with format removal step

* More fixing of the format removal step

* Put back actual git commands and cleanup

* Move release script to its own directory

* Make release script re-entrant once release branch exists

* Cd to the root git dir in the release script

* Disable some shellcheck warnings, remove trailing spaces, add missing git switch

* Run checks even if the release branch exists

* Describe Topiary removal in the releasing guide

* Update RELEASING.md

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

* Cosmetic improvements to release script

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2024-01-08 14:52:09 +00:00
Yann Hamdaoui
25cba8c21e
Fix clippy 1.75 warnings (#1750) 2024-01-07 17:32:34 +00:00
Yann Hamdaoui
77b9c5791a
format: don't fail silently on invalid input anymore (#1749) 2024-01-05 14:32:21 +00:00
dependabot[bot]
29f4464aa1
chore(deps): bump unsafe-libyaml from 0.2.9 to 0.2.10 (#1747)
Bumps [unsafe-libyaml](https://github.com/dtolnay/unsafe-libyaml) from 0.2.9 to 0.2.10.
- [Release notes](https://github.com/dtolnay/unsafe-libyaml/releases)
- [Commits](https://github.com/dtolnay/unsafe-libyaml/compare/0.2.9...0.2.10)

---
updated-dependencies:
- dependency-name: unsafe-libyaml
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-22 09:53:49 +00:00
Yann Hamdaoui
957305c678
Add unstability warning for --error-format (#1744) 2023-12-20 16:21:53 +00:00
Yann Hamdaoui
09035ca620
Update commands and examples from README (#1743) 2023-12-20 09:31:07 +00:00
Yann Hamdaoui
4e3a030b5b
Add discord link to READMEs (#1742) 2023-12-20 09:30:58 +00:00
Yann Hamdaoui
d35baaee1c
Add --error-format flag to serialize err diagnostics (#1740)
* Add --error-format flag to serialize err diagnostics

* Make other CLI errors follow --error-format as well
2023-12-19 15:36:57 +00:00
Michał Kukieła
44ac62f938
Fix swapped links in "Turing completeness" section (#1741) 2023-12-19 04:06:09 +00:00
dependabot[bot]
e1113af368
chore(deps): bump zerocopy from 0.7.18 to 0.7.31 (#1739)
Bumps [zerocopy](https://github.com/google/zerocopy) from 0.7.18 to 0.7.31.
- [Release notes](https://github.com/google/zerocopy/releases)
- [Changelog](https://github.com/google/zerocopy/blob/main/CHANGELOG.md)
- [Commits](https://github.com/google/zerocopy/compare/v0.7.18...v0.7.31)

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

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-12-15 12:59:12 +00:00
silverraven691
2819b4b28a
Fix typo in doc/manual/syntax.md (#1737)
* Fix typo in doc/manual/syntax.md

* Update doc/manual/syntax.md

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2023-12-07 22:53:33 +00:00
Quantum64
7fe5946a61
Support importing txt files as strings (#1734)
* Support importing txt files as strings

* Change String to Raw
2023-12-05 08:43:27 +00:00
jneem
b55626bc20
Add kcl comparison (#1730)
* Add kcl comparison

* Extend the blurb and add it to the tables

* Update README.md

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

* Update README.md

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

* Update RATIONALE.md

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>

---------

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2023-12-04 10:59:01 +00:00
Yann Hamdaoui
5c4298f685
Print something when nickel doc succeeds (#1729)
The doc subcommand has been reported to be a bit confusing, because it
generates file in a default location but just returns without further
details upon success. This commits add a print statement that says where
the document has been generated instead.
2023-12-01 10:05:15 +00:00
Yann Hamdaoui
b52687760a
Update Nickel IM channel from Matrix to Discord (#1728) 2023-11-29 18:09:34 +00:00
jneem
2c8cdfc1c4
Fix hover on assignments to subrecords (#1725) 2023-11-29 17:42:13 +00:00
dependabot[bot]
f4f866f960
chore(deps): bump cachix/cachix-action from 12 to 13 (#1727)
Bumps [cachix/cachix-action](https://github.com/cachix/cachix-action) from 12 to 13.
- [Release notes](https://github.com/cachix/cachix-action/releases)
- [Commits](https://github.com/cachix/cachix-action/compare/v12...v13)

---
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>
2023-11-29 09:10:48 +00:00
dependabot[bot]
f0cf3967b8
chore(deps): bump cachix/install-nix-action from 23 to 24 (#1726)
Bumps [cachix/install-nix-action](https://github.com/cachix/install-nix-action) from 23 to 24.
- [Release notes](https://github.com/cachix/install-nix-action/releases)
- [Commits](https://github.com/cachix/install-nix-action/compare/v23...v24)

---
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>
2023-11-29 09:10:24 +00:00
jneem
a6dca6ad8f
Add a cli param to specify the search path (#1721)
* Add a cli param to specify the search path

* Change the names around
2023-11-28 15:09:57 +00:00
Viktor Kleen
761f6f425a
release infrastructure: disable nodejs16 support for the GitHub runner (#1724)
The nixpkgs derivation for the GitHub runner has removed support for
nodejs16 and with recent versions that support isn't needed anymore.
2023-11-28 13:45:33 +00:00
jneem
f7ffe31697
Search for imports in NICKEL_PATH (#1716)
* Search for imports in NICKEL_PATH

* Move the env variable part to the cli

* Add a test

* Add a failing test
2023-11-22 16:56:58 +00:00
jneem
95d952fb65
Bump flake lock (manually) (#1720)
* Bump flake lock (manually)

* clippy
2023-11-21 15:33:27 +00:00
Yann Hamdaoui
8d7725da77
Fix flake commands for 1.3.0 new CLI (#1715) 2023-11-16 18:10:55 +00:00
Yann Hamdaoui
22e94cff46
1.3.0 release (#1714)
* Bump version numbers for 1.3 release

* Add release notes (part 1)

* Bump latest version mentioned in READMEs to 1.3

* Bump latest version mentioned in manual to 1.3

* Update RELEASING guide
2023-11-16 17:52:59 +00:00
Yann Hamdaoui
eda326f92b
Add a --field argument to subcommands whenever it makes sense (#1712)
* Factor out extract_field() from query()

* Add selectable field to Program

* Add --field to supported commands

This commit finishes the series on adding `--field` argument to the CLI.
This argument is factorized as a new Customize implementer which
regroups commands that don't support general customization (overriding)
but still support selecting a specific field from the configuration.
It's added to the full customization as well.

In consequence, commands that didn't support selecting particular field
before now generically support the `--field` argument. The `--path`
argument for `--query` is removed and is just a `--field` argument for
`nickel query`.

* Fix not taking the --field into account when not customizing

* Formatting

* Fix tests for new --field argument

* Fix clippy warning

* Fix compilation errors, tests, and improve error messages

* Avoid duplicating 'field' declaration in clap
2023-11-16 11:37:54 +00:00
Yann Hamdaoui
f186e0e169
New syntax for customize mode (#1709)
* Customize mode new assignment syntax, part 1

* Add StaticPathField parsing rule

* Add cli assignment parsing rule

* Use new assignment parsing rule, refactor common code

* Fix compilation warnings

* Improve the output of `-- list` including type and contracts

* Remove unused datatype

* Formatting

* Fix old tests and add new for customize mode

* Reword documentation of FieldInterface::is_input

* Pass on code documentation

* Remove obsolete comment

* Update cli/tests/snapshot/inputs/customize-mode/unknown_override.ncl

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

* Update cli/tests/snapshot/inputs/customize-mode/unkonwn_field_path.ncl

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

* Update cli/src/customize/interface.rs

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

* Fix typos in snapshot tests

* Add suggestion for customize mode unknown field errors

* Update snapshot tests with new output

* Get rid of '-- show', hint at using query instead

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2023-11-16 10:26:39 +00:00
Yann Hamdaoui
c0729415e4
Add suggestions when misspelling a record field (#1710)
* Add strsim dependency

* Move error module into its own directory

* Add error::suggest module and fn to find best suggestion

* Add field_names() method to RecordData

* Make find_match more generic

* Add conversion identifier/nickel string

* Add suggestion to missing field errors

* Fix tests and rename item

* Add snapshot test for field suggestion

* Remove debug println and fix code comment

* Review suggestion: improve missing field error message

* Formatting
2023-11-13 17:17:35 +00:00
Yann Hamdaoui
28672ee45b
Update malachite 3.x -> 4.x (and other crates) (#1705) 2023-10-30 09:03:50 +00:00
Yann Hamdaoui
11c8fab020
Fix unsound contract equality fast check (#1703)
* Fix unsound ptr eq check in contract equality

For performance reason, the contract equality checker performs a quick
pointer check to see if the two terms to compare are physically equal.
In this case, it used to return `true` directly, eschewing more costly
recursive checks.

However, this is unsound, because the same term (physically) might be in two
different environments, and have two different values. This is typically
the case with function application: when evaluating `f 1` and `f 2`,
both terms will physically point to the body of `f`, but in a different
environment. Thus, we also need to ensure that environment are equals as
well in this quick check.

This commit adds a fast `ptr_eq` check to the environment as well, and
now checks that both terms and their respective environments are
pairwise physically equals.

Passing by, this commits also fix unrelated clippy warning, after the
udpate to clippy 1.73.

* Add regression test for #1700

* Implement env equality during typechecking

* Cosmetic renaming and slight rework of comments

* Fix contract test by deeply evaluating it

* Remove confusing comments
2023-10-29 12:21:14 +00:00