Skip to content

Commit

Permalink
[RFC007] Improve/simplify record representation in the new AST (#2102)
Browse files Browse the repository at this point in the history
* Improve record representation in the new AST

Instead of elaborating piecewise definitions (such as `{foo.bar = 1,
foo.baz = 2}`) directly at the parsing stage, this commit makes the new
AST closer to the source language by making record a list of field
definition, where the field "name" can be a sequence of identifiers and
strings. This representation is used internally by the parser; we now
make it the default in the AST, such that the migration of the parser
won't have to do this elaboration at all. The elaboration is offloaded
to the conversion to `RichTerm`, which happens in the `ast::compat`
module.

This makes the AST closer to the source language.

The first motivation is that it'll be better for the LSP, where some
open issues on the tracker are caused by the inability to trace what the
LSP get back to the original piecewise definitions.

The second reason is that we can't actually elaborate a piecewise
definition while staying in the new AST correctly as of today: the new
AST only has one record variant, which is recursive by default, but this
doesn't match the way recursion and scoping work for piecewise
definition. For example, `{foo.bar = 1, baz.foo = foo + 1}` works fine
in today's Nickel (evaluate to `{foo = {bar = 1}, baz {foo = 2}}`), but
if we elaborate it in the new AST naively, we'll get an infinite
recursion: `{foo = {bar = 1}, baz = {foo = foo + 1}}`.

Mailine Nickel currently uses a non recursive `Record` for that, but we
don't want to introduce such "runtime dictionary" in the new AST as they
can't be expressed in the source language. Instead, we rather keep
record as defined piecewise and will do further elaboration when needed,
during typechecking, future compilation, or in the meantime when
converting the new AST representation to mainline Nickel.

* Use slice pattern to make function nicer
  • Loading branch information
yannham authored Nov 22, 2024
1 parent 41a3e64 commit f1c826d
Show file tree
Hide file tree
Showing 5 changed files with 654 additions and 319 deletions.
Loading

0 comments on commit f1c826d

Please sign in to comment.