Stream: t-compiler/wg-rls-2.0

Topic: a question on unexported types


pcpthm (Mar 14 2019 at 12:32, on Zulip):

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.

matklad (Mar 14 2019 at 12:35, on Zulip):

It's just that we haven't thought about HIR API a lot.

matklad (Mar 14 2019 at 12:36, on Zulip):

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.

matklad (Mar 14 2019 at 12:38, on Zulip):

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...

matklad (Mar 14 2019 at 12:39, on Zulip):

So, if something is missing, feel free to add it!

pcpthm (Mar 14 2019 at 12:40, on Zulip):

So only code_model_api module is what meant to be exposed?

matklad (Mar 14 2019 at 12:44, on Zulip):

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

matklad (Mar 14 2019 at 12:45, on Zulip):

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

matklad (Mar 14 2019 at 12:46, on Zulip):

Or perhaps the body approach is good, but should be made more general

pcpthm (Mar 14 2019 at 12:46, on Zulip):

I understand. Thank you! I'm not sure about API either. Probably I can do some thinking.

matklad (Mar 14 2019 at 12:47, on Zulip):

I mean, currently you need to ask resolver specifically for funciton bodies (or for generics). I think this can be abstracted away.

Last update: Nov 19 2019 at 17:40UTC