would like advise on creating a minimal rust implementation #3768
-
First off, thank you for creating such a wonderful project. That said, I'm interested in creating a minimistic version of CUE in rust primarily intended for embedding. In the initial use case, I'm looking at validation and transformation. I did see there was a ticket for As this is a minimalistic version, I'd love to understand which features will take a disproportionate amount of time to implement relative to the value they would provide to validation/transformation use case. For example, I understand that you could reduce |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
When I started working here, I attempted a toy implementation. The goals were to learn how to implement CUE, in as few as lines of code as possible, and not caring at all about performance. I worked on this for a month or two. It was extremely useful for thinking about and learning CUE. It is very difficult to offer advice, other than just go for it. It is not at all easy. There are also several different ways of thinking about CUE and different representations, and if I was starting again now I would make different design decisions than before. Thinking about evaluation strategy is useful - although the main implementation is not, I am certain that CUE can be implemented using call-by-need semantics. Gaining experience with that via toy haskell / lambda-calculus implementations is handy. There's a lovely series at https://github.com/sdiehl/write-you-a-haskell which I've studied before in depth. But you don't have to go that route at all. Things to keep in mind:
Fun examples to think about that should not error:
Closedness is also really hard and the subject of much debate internally. I would recommend not implementing closedness to start with. If you're anything like me (I'm so sorry!), be prepared to try lots of stuff and throw it away. If I had the time to start again now, I would invest weeks in building a framework that allows me to easily inspect and debug the state of the interpreter, before implementing much in the way of semantics. This is the result of spending hours and hours working through traces of the interpreter, with pencil and paper, trying to understand what's actually going on, and where the mistake is. You will frequently find that reversing the order of two lines of code will have a terrifying impact on performance and correctness. It often took me days of thinking to try to understand why. Finally, IMO, simplification of bounds (as you mentioned), is of no importance to the language whatsoever. I would relegate that feature to a side effect of outputting the state of the interpreter - I think it's better to think of that as a property of the serialization of the interpreter than anything core to the interpreter. Hopefully this comes across more as "red rag to a bull" and not dissuasion - we would all definitely benefit from more implementations of CUE - especially with a diversity of implementation approaches and design. Good luck! |
Beta Was this translation helpful? Give feedback.
-
zig is most likely way more minimal than a rust implementation. both in codebase size, compilation time, and syntax complexity. there's likely lots of overlap between zig compiler and cue evaluation. not that we have access to the zig compiler source. but compile times in rust are bloating as far as i can see and zig's main goal is minimal compile times for minimal syntax. JIT cue compilations/evaluations likely to be faster via zig for that reason. since cue is very 'one-shot focused', this seems to be the correct path. you don't need a bunch of special syntax and constructs to make sure that memory is safe. just do your job as a mathematician lol. especially if cue was actually part of the compilation layer. just my humble 2c. |
Beta Was this translation helpful? Give feedback.
-
i am doing prep work for this re-implementation in zig if anyone wants to collab. after i get the base stuff i need in the go api working so i can use my tool, i'll be wrapping libcue and transitioning to using cuelang at zig build/compile time to guarantee types. then after that a total re-write in zig to fuse with a game engine. |
Beta Was this translation helpful? Give feedback.
When I started working here, I attempted a toy implementation. The goals were to learn how to implement CUE, in as few as lines of code as possible, and not caring at all about performance. I worked on this for a month or two. It was extremely useful for thinking about and learning CUE.
It is very difficult to offer advice, other than just go for it. It is not at all easy. There are also several different ways of thinking about CUE and different representations, and if I was starting again now I would make different design decisions than before. Thinking about evaluation strategy is useful - although the main implementation is not, I am certain that CUE can be implemented using call-by-ne…