Stream: t-compiler

Topic: after_expansion callback


Igor Matuszewski (Jul 14 2019 at 15:08, on Zulip):

Hey @Zoxc, I'm trying to only run expansion as part of the rustc routine and I'm having some trouble driving it myself without panicking the compiler and I'm not sure I'm doing things right

Igor Matuszewski (Jul 14 2019 at 15:10, on Zulip):

Right now there are only after_parsing and after_analysis callbacks available - I figured I'd just do register_plugins() and expansion() but it seems that I can't really do these in callbacks since that already sets thread locals and panics afterwards

Igor Matuszewski (Jul 14 2019 at 15:11, on Zulip):

reason behind it is I want to expand the crate so I know every input file used in the compilation so I can associate it with a given crate (incl. name, disambiguator and edition)

Zoxc (Jul 14 2019 at 15:12, on Zulip):

Is this for RLS?

Igor Matuszewski (Jul 14 2019 at 15:15, on Zulip):

yes

Igor Matuszewski (Jul 14 2019 at 15:16, on Zulip):

ideally I wouldn't copy-paste most of the code from librustc_driver into the RLS if that would help avoid the ordering problems

Igor Matuszewski (Jul 14 2019 at 15:16, on Zulip):

I'm also not sure the approach is correct, please correct me if I'm wrong

Igor Matuszewski (Jul 14 2019 at 15:18, on Zulip):

right now we collect the file -> (crate, disambiguator, edition) mapping in after_analysis but this leads to a weird case where we don't invoke the callback when compilation fails (e.g. due to a type mismatch) and we need the file edition data to correctly format them with rustfmt

Igor Matuszewski (Jul 14 2019 at 15:18, on Zulip):

(so currently code has to compile in order to be able to being formatted which is... less than ideal)

Igor Matuszewski (Jul 14 2019 at 15:20, on Zulip):

(and after_parsing isn't enough, since code can invoke a macro_rules! include_my_mod { () => { mod some_mod; }; } and then some_mod.rs isn't included in the list)

Zoxc (Jul 14 2019 at 15:27, on Zulip):

You could probably just add another callback for RLS.

Igor Matuszewski (Jul 14 2019 at 15:36, on Zulip):

okay, I'll look into it.

Igor Matuszewski (Jul 14 2019 at 15:38, on Zulip):

By the way, maybe it'd be more readable to move Compilation into interface and use this instead as the return type in the callbacks? Returning true seems somewhat vague and I found myself commenting what it does

Zoxc (Jul 14 2019 at 16:22, on Zulip):

Yeah, that could be used instead of the bools

Igor Matuszewski (Jul 14 2019 at 20:03, on Zulip):

Done, filed https://github.com/rust-lang/rust/pull/62679

Last update: Nov 16 2019 at 02:20UTC