Hello, while trying to use ra_hir, I found that many types returned from public methods are not exported publicly.
For example, an enum
ra_hir::expr::Expr which can be obtained from e.g.
function.body(db).exprs() but can't be named from outside and thus can't be
matched. Is this restriction intended? I don't have an idea of the difference of what is exported vs what is not.
It's just that we haven't thought about HIR API a lot.
Currently, the only client of HIR is
ra_ide_api, so hir tries to provide a nice API (see code_model_api), but this is done on best effort basis.
I think, long term, hir will become the "systems boundary" between "compiler guts" and "tools", but that's not yet the case. Really, we should maybe try to split hir into separate crates soon...
So, if something is missing, feel free to add it!
code_model_api module is what meant to be exposed?
roughtly, yeah. Currently, code_model exports only top-level items, it doesn't export item bodies, but that's oversight. It would be cool to figure out the nice API for things like expressions. The current
hir::Expr is a representation convenient for implementation, I am not sure it's a good API as well
For example, I think for the public API we might want to bundle
hir::Expr and the corresponding function together, so that you don't have to do deal with
Body maps at all, and instead can just call methods on expr
Or perhaps the body approach is good, but should be made more general
I understand. Thank you! I'm not sure about API either. Probably I can do some thinking.
I mean, currently you need to ask resolver specifically for funciton bodies (or for generics). I think this can be abstracted away.