Stream: t-compiler/wg-rls-2.0

Topic: IDE resilience


matklad (Mar 15 2019 at 08:14, on Zulip):

An interesting example illustrating the difference between compiler and IDE requirements in terms of error handling:

macro_rules! foo {
    ($($tt:tt)*) => { foo!($($tt)*, $($tt)*); }
}

foo!(KABOOM);

fn main() {}

Here, rustc just dies with OOM, and that is sort of expected behavior. An explicit error message would be better, but this is a nice-to-have, not a requirement.

IDE, otoh, has to handle this case gracefully, for two reasons:

matklad (Apr 21 2019 at 21:32, on Zulip):

cc @Edwin Cheng this might actually be a fun test-case!

Edwin Cheng (Apr 21 2019 at 21:34, on Zulip):

Yeah, here is another case :
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=839b39d24d1ba81ae911cad8ccb8833f

matklad (Apr 21 2019 at 21:42, on Zulip):

I wonder how we should handle this in salsa?

If I weren't using salsa, I would implement some kind of a "fuel" system, which bounds not only the depth, but also the width of the expansion.

(random realization: "fuel" idea is deeper than I thought: it's exactly the device we use to turn arbitrary recursive function into a primitive recursive one)

However doing fuel in salsa is hard: if you just add it as a parameter, you loose incrementality... Perhaps we should a query for "deeply" expanding the macros, which internally repeatedly runs non-salsa fuel based shallow expansion?

Edwin Cheng (Apr 21 2019 at 21:46, on Zulip):

So do you mean we should add a separate salsa database about current execute context ?

matklad (Apr 21 2019 at 21:47, on Zulip):

Probably no

matklad (Apr 21 2019 at 21:48, on Zulip):

though, trough to be told, I don't have a clear idea about this

matklad (Apr 21 2019 at 21:48, on Zulip):

So currently we have a query which expands a single macro

matklad (Apr 21 2019 at 21:48, on Zulip):

if in the result there's another macro invocation, we'll call the query again, and again, and again, etc

matklad (Apr 21 2019 at 21:49, on Zulip):

Adding stack depth to such a query would work

matklad (Apr 21 2019 at 21:49, on Zulip):

Adding fuel wouldn't

matklad (Apr 21 2019 at 21:49, on Zulip):

So, I wonder if we can implement fuel outside of the queries?

matklad (Apr 21 2019 at 21:50, on Zulip):

Hm, perhaps we should just add some counter to DefCollector?

Edwin Cheng (Apr 21 2019 at 21:50, on Zulip):

I did do that

matklad (Apr 21 2019 at 21:50, on Zulip):

For depth, IIRC

matklad (Apr 21 2019 at 21:50, on Zulip):

but we can have a similar counter for width

Edwin Cheng (Apr 21 2019 at 21:50, on Zulip):

But the problem is we have to send an empty result in salsa

matklad (Apr 21 2019 at 21:51, on Zulip):

Why "empty result" is a problem?

Edwin Cheng (Apr 21 2019 at 21:51, on Zulip):

Only bypass it in DefCollector would not work

matklad (Apr 21 2019 at 21:51, on Zulip):

we cal always generate an empty file or something like that?

Edwin Cheng (Apr 21 2019 at 21:52, on Zulip):

Because another code will query salsa for that macro again.

matklad (Apr 21 2019 at 21:53, on Zulip):

Hm, could we store a list of "poisoned" macro calls in CrateDefMap?

matklad (Apr 21 2019 at 21:53, on Zulip):

when other code tries to construct MacroCallId for expansion, it'll check if it is poisoned in CrateDefMap

matklad (Apr 21 2019 at 21:54, on Zulip):

Hm, another though: what if we have stupid static fuel, which just restricts the maximum length of macro call to 65536 tokens?

matklad (Apr 21 2019 at 21:55, on Zulip):

That is, I think, to hit diverging behavior, we either need big depth (which is checkable by adding depth to MacroCallLoc), or wide macro invocations (which is checkable on each invocation).

Edwin Cheng (Apr 21 2019 at 21:56, on Zulip):

I like both idea.

matklad (Apr 21 2019 at 21:57, on Zulip):

I'd probably started with static width: seems easier to impl, b/c we don't have to store anything

Edwin Cheng (Apr 21 2019 at 21:58, on Zulip):

Yeah, i will do it tmr. (Here is 6:00 am now :) )

Edwin Cheng (Apr 21 2019 at 21:58, on Zulip):

[Out of Topic] have you see https://github.com/rust-analyzer/rust-analyzer/issues/1188 ?

matklad (Apr 21 2019 at 22:01, on Zulip):

Seen, but haven't looked into yat

matklad (Apr 21 2019 at 22:02, on Zulip):

Bye!

Last update: Nov 19 2019 at 18:10UTC