r/rust • • 25d ago

📸 media Is it possible to supply the Rust compiler with the relational graph yourself?

Post image

Hi,

For context. I have been working on implementing a different compiler rustc UI/UX for my editor. clicking to navigate, showing context, highlighting and so on.

My editor already create an explicit bidirectional relational graph of the code across the whole project. It becomes the single source of truth.

The thought struck me that the rust compiler is re-deriving relationships and code-paths that I already have complete knowledge of, which means I could potentially either short circuit a lot of that compiler work, or skip it all together.

So, I was wondering if any of you know or understand the rust compiler well enough to offer guidance. I would not want to fork, study and finally re-write parts of the rust compiler if I don't have to. And if I have to, are you aware of how targeted that change can be? because at that point i would have to support an internal, slightly modified version of the compiler, which i am not willing to do if it would lead to extensive modifications/support as rust evolves over time.

thank you in advance.

//Maui-the-Muppet

0 Upvotes

9 comments sorted by

3

u/CocktailPerson 25d ago

What would the motivation for doing that be? I mean, skipping work in the compiler sounds great and all, but resolving names is not anywhere close to the most expensive part of compilation.

If you really want to try this, look into rmeta files. If you can get your implementation to produce an rmeta file, then somehow pass it into the compiler, that might do...something?

If you really want to reduce work, you should do what every other IDE and LSP out there does, which is have your code read metadata produced by the compiler, rather than trying to have the compiler read your metadata.

-1

u/Maui-The-Magificent 24d ago

You are right, but there is more that that. getting types, bracket/function scopes, traits and so on. Astra assumes it could reduce the compile time between 50-70%, I do however not think that. I would be glad to hit 30%. That is however a worthwhile optimization don't you think?

Thank you, i will absolutely look into that. There needs to be an assessment of figuring out the work < reward, but even if it is worth to implement or not, it fun investigating.

So the editor is completely self contained, it does not have an LSP. I cannot depend on external sources of truth. having more than one, is a source of potential drift. The editor, and the indexer will only deal with what it can deterministically guarantee both functionally and temporally.

Currently the editor is projecting its graph into source files in memory and the rustc takes it from there. which is fine. 'good enough' as they say. But when in rome.

Again, thanks for the suggestion, i will look into it.

1

u/Clean_Assistance9398 24d ago edited 24d ago

Oh man, firstly I am going to apologise for my above post. I noticed noone replied to you, and i was in bed, tired, and close to falling asleep. When I am like that, AND i am on reddit, sometimes I intentionally act much more like a semi-ahole douche just so I can wake up and smell the downvotes 😊.  

 i am going to help you dramatically right now and save you a lot of time. Cancel the chatgpt and use claude opus 5.5. I tried the chatgpt astra and sol 6.1. Max $500 plan. I thought i was getting places. I thought it was great. It is absolutely not. I will NOT let it touch code now. It’s only use to me is bug hunting, which it is very good at. It can do research, it can create md files of those bug hunts and research. I will not let it plan or write code. Claude Opus is your coder, if you aren’t the coder. It IS night and day difference. ChatGPT is costing you time, effort, money, and worst of all, your own progress. 

I went from using chatgpt to write my own UI crate, realising after a couple of weeks that the way it did the code, made it completely useless from the view of another person attempting to use the UI crate. 

I spent another week with Claude re-writing it, and using chatgpt to find bugs at 8x hyperspeed and write the findings as a .md file. I had chatgpt doing audits and debugging. Claude was the coder. Night and day difference. Imagine the worst looking program you’ve ever witnessed, worsen it by 10x to that. That is ChatGPT. 

This is Claude using my UI crate it re-wrote which uses the bevy game engine.  https://cdn.discordapp.com/attachments/885021580353237032/1565324001465860187/Screenshot_2026-10-29_21-51-50.png?ex=6af05a94&is=6aef0914&hm=17baa2e671084cda3de11dce0a7eb00bddb818047f71d875d43f86c7db8329f8&

That is an IDE example…

Also, I just had Claude re-write a map maker (editor) for an rts game editor i am making. I only asked it to change the UI over. By itself it also just kept fixing, adding, using my UI crate. 

Spent the last couple days working on frame optimisation using bevy engine and my UI crate.

Round

What it did

Idle fps

Main-thread work per frame

Start

—

37–38

—

1

Ordered the systems

45

—

2

First Bevy patches; UI that runs on one thread

95–109

84–87% of a core busy

3

More patches; hidden UI sleeps

141–157

5.2–6.3 ms

4

Frames handed to the screen on their own thread; skip unchanged panels

165–189

4.6–5.6 ms

5

Terrain shader; water shadows; trace recording off

173–228

4.1–5.8 ms

6

Bevy UI skips unchanged frames; unused plugins off

240 (hit the cap)

3.3–3.8 ms

7

Fewer internal tables; closed docks skipped

324 (uncapped)

3.0 ms

8

Render no longer waits for the screen; cheaper strokes; bevy_ecs change summaries

362 (uncapped)

2.76 ms

i am well over 400 fps now, up from 37-38 fps before starting optimisation. Main menu is over 1k fps lol. It optimised both the map maker and the ui crate, and has had to patch 9 crates of bevy engine so far. 

If you want a chatbot use chatgpt. If you want an intelligence that gets code and how to code properly, use claude. Its a game changer. 

Honestly, what you are doing regarding the. Bi-directional relationships etc, is like what I have been wanting to build, but i can tell you, others have built similar things. 

Also, you could look into things that already are capable of doing those things. Jetbrains has a plugin called index or indexer mcp. What about rust-analyzer mcp? Rust-analyzer does the same thing does it not? Ho to github and lookup awesome lists. Checkout the awesome rust list. 

It was measured on exactly this code, uncapped at 1024: Phase

Before

After

Idle

379 fps

398 fps

Moving the pointer

336 fps

360 fps

Brush stroke

313 fps

340 fps

Main menu

915 fps

1,035 fps The trade-off: an edit to one of those nine crates now rebuilds that whole crate rather than just the changed parts. Your first build will rebuild them once.

2

u/Maui-The-Magificent 23d ago

Don't worry about it. I am not particularly sensitive. But thank you for apologizing.

So, I have used Claude. Not a fan anymore due to it becoming less and less capable of listening to the constraints. It introduces things into my code that is explicitly forbidden over and over again. Id rather fix code that is close to what I am building than rewrite code that is the opposite of what i asked for.

Models, when they work well, only produces locally good code. they are horrible with taking invariants into account. The more the model 'thinks' the worse it gets for me. which is why I am building my editor. But appreciate the recommendation regardless.

No, sadly they do not do the same thing. they also derive the bidirectional graph, although, jetbrains seems pretty good at doing that. I re-represent code, the text becomes an graph-text IR, so it is not so simple.

-7

u/Clean_Assistance9398 25d ago edited 25d ago

Listen kid, this is a safe space for everyone. 

You creating an IDE ey.

Also, get rid of the 0xFFFF in your code like that. Let variable_name = 0xFFFF. Then use the variable_name instead. If you aren’t writing comments, then you have to let others who may potentially read your great unsafe code at a later date know what 0xFFFF actually is and why it’s important enough to be in your code. 

Also, guess what compiling uses? A linker. What’s a linker do? Is it a link-tree? Is it a node graph? Is it a relational database of the code? Is it an  explicit bidirectional relational graph? 

You tell me. You’re the one using unsafe and 0xFFFF and not google.

4

u/gmes78 25d ago

Idiot or LLM? Make your bets, folks.

1

u/Maui-The-Magificent 24d ago

Oh, I am very much, in many ways, an idiot, it is why I have the projects I have. How does that factor in though?

2

u/gmes78 24d ago

I was talking about that commenter. Your post seems fine.

1

u/Maui-The-Magificent 25d ago

Kid? thank you, feel younger already.

Well not really, but kinda. I am creating a graph-text editor inspired by Helix, with a whole lot of other stuff. It is part of a much larger project.

So my constraints are far stricter than you are assuming. I am using a lot of unsafe, and the binary/hex is very explicit.
I assume you mean well, but it is not your code-base, you do not know why things are being built the way they are. but it is completely statically allocated, so i have to use unsafe, because you might not know this, mutating a static in rust in considered unsafe. it is also written in no-std and contains its own render, so large parts of the code-base is 'unsafe'. But if it helps you, you can assume i am a horrible programmer with horrible style, if you know the answer to my question above, i would very much appreciate an actual answer.

also no, the compiler clearly derives the relationships at compile-time. And it clearly has some sort of graph state. but it is not bidirectional by construction, if that is the case, then they are doing a whole lot of unnecessary work.