Skip to content

Commit

Permalink
Rename and re-organize primitive operators
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
yannham committed Jun 7, 2024
1 parent 519c022 commit c1be53e
Show file tree
Hide file tree
Showing 53 changed files with 1,092 additions and 1,082 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# capture = 'stderr'
# command = ['eval']
let f | forall r. { ; r } -> { x: Number; r } = fun r => %record_insert% "x" r 1 in f { x = 0 }
let f | forall r. { ; r } -> { x: Number; r } = fun r => %record/insert% "x" r 1 in f { x = 0 }
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# capture = 'stderr'
# command = ['eval']
let f | forall r. { ; r } -> { x: Number; r } = fun r => %record_insert% "x" r 1 in (f { x = 0 } : _)
let f | forall r. { ; r } -> { x: Number; r } = fun r => %record/insert% "x" r 1 in (f { x = 0 } : _)
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,25 @@ error: contract broken by the caller
field not allowed in tail: `x`
┌─ [INPUTS_PATH]/errors/record_forall_constraints_contract.ncl:3:19
3let f | forall r. { ; r } -> { x: Number; r } = fun r => %record_insert% "x" r 1 in f { x = 0 }
3let f | forall r. { ; r } -> { x: Number; r } = fun r => %record/insert% "x" r 1 in f { x = 0 }
------- --------- evaluated to this expression
│ │
expected type of the argument provided by the caller

note:
┌─ [INPUTS_PATH]/errors/record_forall_constraints_contract.ncl:3:58
3let f | forall r. { ; r } -> { x: Number; r } = fun r => %record_insert% "x" r 1 in f { x = 0 }
3let f | forall r. { ; r } -> { x: Number; r } = fun r => %record/insert% "x" r 1 in f { x = 0 }
^^^^^^^^^^^^^^^^^^^^^^^ While calling to r

note:
┌─ [INPUTS_PATH]/errors/record_forall_constraints_contract.ncl:3:85
3let f | forall r. { ; r } -> { x: Number; r } = fun r => %record_insert% "x" r 1 in f { x = 0 }
3let f | forall r. { ; r } -> { x: Number; r } = fun r => %record/insert% "x" r 1 in f { x = 0 }
----------- (1) calling f

note:
┌─ [INPUTS_PATH]/errors/record_forall_constraints_contract.ncl:3:49
3let f | forall r. { ; r } -> { x: Number; r } = fun r => %record_insert% "x" r 1 in f { x = 0 }
3let f | forall r. { ; r } -> { x: Number; r } = fun r => %record/insert% "x" r 1 in f { x = 0 }
-------------------------------- (2) calling <func>


Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: err
error: multiple record row declarations
┌─ [INPUTS_PATH]/errors/record_forall_constraints_typecheck.ncl:3:88
3let f | forall r. { ; r } -> { x: Number; r } = fun r => %record_insert% "x" r 1 in (f { x = 0 } : _)
3let f | forall r. { ; r } -> { x: Number; r } = fun r => %record/insert% "x" r 1 in (f { x = 0 } : _)
^^^^^^^^^ this expression
= Found an expression with the row `x : _a`
Expand All @@ -15,5 +15,3 @@ error: multiple record row declarations
note: while matching types
= Expected type { ; r }
= With inferred type { x : _a }


4 changes: 2 additions & 2 deletions core/src/eval/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ pub fn merge<C: Cache>(
// printed out when reporting the error.
let contract_for_display = mk_app!(
mk_term::op1(
UnaryOp::StaticAccess("Equal".into()),
UnaryOp::RecordAccess("Equal".into()),
Term::Var("contract".into()),
),
// We would need to substitute variables inside `t1` to make it useful to print,
Expand Down Expand Up @@ -233,7 +233,7 @@ pub fn merge<C: Cache>(
// exactly the same, but can't be shadowed.
let eq_contract = mk_app!(stdlib::internals::stdlib_contract_equal(), t1);
let result = mk_app!(
mk_term::op2(BinaryOp::ApplyContract(), eq_contract, Term::Lbl(label)),
mk_term::op2(BinaryOp::ContractApply, eq_contract, Term::Lbl(label)),
t2
)
.with_pos(pos_op);
Expand Down
12 changes: 6 additions & 6 deletions core/src/eval/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,10 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
// corresponding polymorphic contract has been violated: a function tried to
// use a polymorphic sealed value.
match stack_item {
Some(OperationCont::Op2Second(BinaryOp::Unseal(), _, _, _)) => {
Some(OperationCont::Op2Second(BinaryOp::Unseal, _, _, _)) => {
self.continuate_operation(closure)?
}
Some(OperationCont::Op1(UnaryOp::Seq(), _)) => {
Some(OperationCont::Op1(UnaryOp::Seq, _)) => {
// Then, evaluate / `Seq` the inner value.
Closure { body: inner, env }
}
Expand Down Expand Up @@ -662,7 +662,7 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
});

Closure {
body: RichTerm::new(Term::Op1(UnaryOp::ChunksConcat(), arg), pos),
body: RichTerm::new(Term::Op1(UnaryOp::ChunksConcat, arg), pos),
env,
}
}
Expand Down Expand Up @@ -721,9 +721,9 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
// extensions
//
// ```
// %record_insert% exp1
// %record/insert% exp1
// (...
// (%record_insert% expn {stat1 = val1, ..., statn = valn} dyn_valn)
// (%record/insert% expn {stat1 = val1, ..., statn = valn} dyn_valn)
// ...)
// dyn_val1
//
Expand Down Expand Up @@ -751,7 +751,7 @@ impl<R: ImportResolver, C: Cache> VirtualMachine<R, C> {
} = field;

let extend = mk_term::op2(
BinaryOp::DynExtend {
BinaryOp::RecordInsert {
metadata,
pending_contracts,
ext_kind,
Expand Down
Loading

0 comments on commit c1be53e

Please sign in to comment.