garritfra / qbe-rs

QBE IR in natural Rust data structures
https://c9x.me/compile
Other
80 stars 7 forks source link

`Function::add_block()` doesn't return added block? #17

Closed icefoxen closed 2 years ago

icefoxen commented 2 years ago

The docstring for Function::add_block() says Adds a new empty block with a specified label and returns it, but the function doesn't return anything and you need to call last_block() instead. Is the function wrong, or the doc?

Oh, also last_block() doesn't return a mutable reference, so you can't do add_block() then last_block() and modify that block. The Function type's contents are transparent, so you can just do it manually, but it's surprising.

garritfra commented 2 years ago

Thanks for pointing this out! I don't think it would be a problem to return a mut ref to that block if the user needs it.

On that note, I don't think we really need the last_block function, as it's just a wrapper around self.blocks.last(_mut)().unwrap(). I'll add a deprecation warning to it.

garritfra commented 2 years ago

Feel free to look over the linked PR (#18). I'd love to hear your thoughts.