Open FranklinChen opened 10 years ago
Looks awesome, also hard. I think it would be possible to implement this using a syntax extension, but it is a lot more work than a small library like this.
Now that I've played around with syntax extensions, I'm fairly sure that something like this is possible to implement, but it would be tricky since macros do not have access to type information, so it would have to be a purely syntactic transformation.
@reem are the compiler plugins basically just the same as syntax extensions or is there some additional generality there somewhere? I haven't tried them yet and couldn't quite tell from the docs. If accessing the type information through plugins just isn't possible at all, do you think it would be feasible to extend rustc to support such a thing? Seems like it would be very useful to have that.
@darinmorrison compiler plugins also covers lints and deriving. Deriving is a glorified macro, but since lints run after everything they have access to types and such, however, by then it's too late to actually make changes (type and borrow checking etc. has already run).
The issue with extending rustc is that syntax extensions run before everything is even fully parsed, so long before name resolution, type checking, etc. You'd have to do something pretty radical to get it to work, if it's even possible.
I realized earlier today that the same issue that occurs with recursive lazy data structures in the style supported by this crate (which leads to the outer layer being strict) is the same as the problem with recursive reference counting or garbage collection (the outer layer is not allocated or counted).
I ran into this issue trying to create a lazy reference counted linked list. The constructs introduced in the paper surrounding suspensions are actually very similar to the operations readily available with smart pointers. defer
is placement new and force
is like deref.
Any interest in implementing something like the following (which is in SML/NJ and OCaml): http://www.cs.rice.edu/~taha/publications/conference/sml98.pdf
(Syntactic sugar for lazy types, function evaluation.)