1
1
mirror of https://github.com/tweag/nickel.git synced 2024-10-05 15:47:33 +03:00
Commit Graph

14 Commits

Author SHA1 Message Date
Yann Hamdaoui
1ac48b8436
Re-introduce unified representation for custom contracts, migrate builtin contracts (#1987)
* Split builtin contracts as immediate/delayed

This commit split the builtin contracts into explicitely separated
immediate and delayed part, as per the contract design introduced in a
previous commit. This incur broad changes, as this impact the internals
module of the stdlib, the stdlib itself, and the code generating
contracts from static types.

* Change custom contract representation (again)

After converting the builtin contracts to the immediate/delayed split
representation, a number of complications appeared. Nothing that can't
be overcome, but requiring unsatisfying ad-hoc treatments or a more
complex contract interface that wasn't easy to explain in the
documentation.

In particular, passing information between the immediate
part and the delayed part is cumbersome. Splitting the logic in two
different functions is arguably harder to understand. Contract
composition, while preserving the immediate and delayed parts, is
cumbersome as well.

In the end, it occurred that switching back to one implementation for
the whole contract, but which can return a value of type `[| 'Ok Dyn,
'Error {..} |]` achieves the same (makes the immediate part and delayed
part separable) while being much simpler both for us maintainers and for
users writing and manipulating contracts. This commit implements this
simplified representation.

* Update stdlib for new ctr repr

Update the stdlib for the new two-in-one custom contract representation
which returns an enum.

* Update tests, examples and doc for new ctr repr

After having introduced a single representation for custom contracts
(instead of a split delayed/immediate), update the various Nickel
snippets in the tests, examples and the documentation to follow this new
API.

* Record contracts and apply_as_custom

This commit adapts builtin record contracts, and thus merge in contract
mode as well, to follow the new contract representation: that is, this
commit makes record contract application to return either `'Error` for
immediate errors (the argument isn't a record or there are extra fields)
instead of blaming or an `'Ok`-wrapped result.

We also add a `apply_as_custom` operator, which preserves the
`'Ok`/`'Error` result (as opposed to `apply`) which is useful to
preserve the immediate checks when calling a contract from another
contract.

* 'Ok -> 'Ok value, use apply_as_custom instead of apply whenever mandated

* Update manual for apply vs apply_as_custom

* Fix usage of renamed of internals

* Fix double contract/custom wrapping failing tests

* Fix some failing tests

* Fix signature of std.contract.custom

* Update test snapshots

* Finish implementation of apply_as_custom

* Small broken test fixes

* Fix typing of contract/custom

* Fix manual snippets

* Fix clippy warning (useless into())

* Apply suggestions from code review

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

* Apply suggestions from code review

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

* Simplify documentation of contract.apply

---------

Co-authored-by: jneem <joeneeman@gmail.com>
2024-07-17 09:57:55 +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
suimong
249f1e79d9
fixed std.array.split_at behavior at right boundary. (#1803)
* fixed IndexedArrayFun behavior at right boundary.

* fixed typo.

* fix code block annotation.

* parameterized IndexedArrayFun contract.

* corrected contract annotation position.

* updated snapshots.

* Fixed doc test due to line number change in std.ncl

---------

Co-authored-by: Ben Yang <ben@ya.ng>
2024-02-08 08:30:02 +00:00
Viktor Kleen
78e7a8814b
Rename and move workspace crates (#1399)
* Rename and move workspace crates

nickel-lang -> nickel-lang-cli in cli/
nickel-lang-lib -> nickel-lang-core in core/
nickel-lang-utilities -> nickel-lang-utils in utils/
nickel-repl -> nickel-repl in wasm-repl/

* Finish renaming in rust sources

* Update RELEASING.md

* Move to workspace dependencies

* Rename nickel-repl -> nickel-wasm-repl

* Update RELEASING.md

Co-authored-by: Taeer Bar-Yam <Radvendii@users.noreply.github.com>

* Address suggestions from code review

* Update HACKING.md

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

* Elaborate on the versioning scheme in RELEASING.md

---------

Co-authored-by: Taeer Bar-Yam <Radvendii@users.noreply.github.com>
Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2023-06-26 16:58:40 +00:00
Viktor Kleen
3e03cc7909
Move the CLI into its own crate (#1351)
* Fetch the wasm-bindgen-cli version from Cargo.lock instead of Cargo.toml

* Move the Nickel CLI to a separate crate

* Fix snapshot tests

* Rename the nickel flake output to nickel-lang-cli for consistency

* Move the nickel-lang crate into a subdirectory

* Update documentation for the new crate split

* Tweak snapshot test instructions

* Use project_root instead of ad-hoc environment variables

* Remove the library from nickel-lang-cli for now

* Rename nickel-lang to nickel-lang-lib and nickel-lang-cli to nickel-lang

* Apply suggestions from code review

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

* Tweak documentation for nickel_lang_utilities::project_root

* Use MacOS 13 github runner because of https://github.com/cachix/install-nix-action/issues/183

---------

Co-authored-by: Yann Hamdaoui <yann.hamdaoui@tweag.io>
2023-06-16 16:34:13 +00:00
Yann Hamdaoui
030c71eed7
Use long names for string and numbers
Rename the builtin `Num` and `Str` types to `Number` and `String`, and
use long names on a number of related functions and stdlib modules for
consistency. This is a breaking syntax change.
2023-03-08 16:36:13 +01:00
Andreas Deininger
0f192ea0ae Fixes typos 2023-02-02 11:20:09 +01:00
matthew healy
bff8451f7e
Add snapshot testing infrastructure (#1034)
* Update regex crate to 1.7

We want to use the regex filtering feature of the insta snapshot testing
library. That has a dependency on a newer version of the regex crate
than Nickel currently does, so this commit updates the Nickel version to
a more recent compatible version.

* Add insta dependency

* Add cargo-insta to dev shells

* Add snapshot testing infrastructure

This uses the insta crate to implement snapshot testing.

Each snapshot test invokes the debug nickel binary with some set of
arguments, then captures the output & compares it to a file in the
snapshots directory

* Add nixpkgs-fmt to dev shell

This makes it possible to easily reformat flake.nix from within a dev
shell.

* Update HACKING.md

* Add snapshot testing README
2023-01-09 11:32:40 +01:00
matthew healy
8e3fcba0f1
Update HACKING.md to cover current testing practices (#1001) 2022-12-15 18:25:39 +01:00
Julien Debon
62128a642f
Migrate Nix build from import-cargo to Crane (#963)
* Refactor flake inputs because it's been annoying me for weeks now
* Fix a long-standing bug in mk_uniftype.rs
Can be reproduced by running `cargo test --workspace`.
This was never noticed before in CI because the `--workspace` flag is not passed.
This will be addressed in the Crane migration
* Remove utilities/Cargo.lock
This is probably a fragment of the past, back when Nickel did not use Cargo workspaces.
* Fix Clippy issues in tests
* Rustfmt and clippy are no longer in preview
* Update README with Nix flake shell command
* Migrate from import-cargo to crane for Nickel
Nickel WASM build is intentionally left intact and still uses the old
import-cargo.
This is because the change is already massive, and in practice the WASM build
relies more on `wasm-pack` than Cargo (even though under the hood, `wasm-pack`
uses Cargo).

If Crane looks good, both for DX and for CI, we will consider migrating Nickel
WASM to Crane too in a future PR.
* Remove support for Rust nightly channel
* Only Nix check for Rust `stable` channel
* Fix deprecated Nix build documentation commands
* Fix completion test
2022-12-05 17:28:45 +01:00
matthew healy
b0119f149e
Restructure integration tests into a single crate (#954)
* Restructure integration tests into a single crate

This commit replaces our multi-crate integration test setup with a
single crate that contains all tests, inspired by [this
blog](https://matklad.github.io/2021/02/27/delete-cargo-integration-tests.html).

This has dual benefits:
1. it should reduce the amount of time tests take to compile, as we're
   only producing a single binary,
2. it should reduce the amount of time tests take to run, as cargo
   schedules individual test binaries to run sequentially whereas tests
   within a binary can run in parallel.

* Update test references in HACKING.md

* Add README explaining test structure
2022-11-30 11:26:29 +01:00
Yann Hamdaoui
fe6ff26b5b Fix markdown lint warnings for HACKING.md 2022-08-04 18:37:00 +02:00
Yann Hamdaoui
3064766333
Update documentation with simplified WASM build 2022-06-15 16:59:08 +02:00
Yann Hamdaoui
8c66cb96cd
Move dev setup instructions to a separate HACKING.md document 2022-04-11 13:35:24 +02:00