coalton-lang / coalton

Coalton is an efficient, statically typed functional programming language that supercharges Common Lisp.
https://coalton-lang.github.io/
MIT License
1.15k stars 70 forks source link

Add node-block and node-return-from for inlining functions with node-return #1203

Closed amorphedstar closed 2 months ago

amorphedstar commented 2 months ago

Inlining bodies of functions with return nodes would make it so they returned to the most recent non-inlined function, which is wrong. This PR creates node-block and node-return-from and implements a traversal to fix this.

amorphedstar commented 2 months ago

This is looking slick. Is it about ready for merging?

Would be nice to add a simple test for some things, including a test that would trip up the inliner with the returns.

I added two simple tests, but wasn't quite sure the best place to put them. And I think it should be about ready to merge if you think it's fine having all these extra blocks now in the codegen output, and potentially unclearer return names in a few places that had special codegen behavior, like node-bind in the case when node-bind-expr is a node-abstraction.

stylewarning commented 2 months ago

This is looking slick. Is it about ready for merging?

Would be nice to add a simple test for some things, including a test that would trip up the inliner with the returns.

I added two simple tests, but wasn't quite sure the best place to put them. And I think it should be about ready to merge if you think it's fine having all these extra blocks now in the codegen output, and potentially unclearer return names in a few places that had special codegen behavior, like node-bind in the case when node-bind-expr is a node-abstraction.

Since blocks are only useful if there's a lexically apparent return, maybe we can (either in this PR or future) only emit a block when needed.