-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: MIR episode 2 #14232
feat: MIR episode 2 #14232
Conversation
When running |
I'm ... pretty sure std is resolved in |
I'm not getting a |
Can confirm that I am getting nresolved macros as well for current r-a, that's odd ... |
Oh I know why :) Diagnostics is still using the default cargo config without the cargo_config.sysroot = match self.no_sysroot {
true => None,
false => Some(RustcSource::Discover),
}; part that is now necessary. |
☔ The latest upstream changes (presumably #14222) made this pull request unmergeable. Please resolve the merge conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loving the introduction of bindings, handling bindings through binding patterns was always a pain
crates/hir-ty/src/infer.rs
Outdated
/// Type of the result of `.into_iter()` on the for. `ExprId` is the one of the whole for loop. | ||
pub type_of_for_iterator: ArenaMap<ExprId, Ty>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels odd to have, though I gues we don't really have a lot of options here since we don't desugar so there is nothing to refer to for the resolver into iter type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though we definitely don't want this to be an ArenaMap, as that will allocate a lot due to it being backed by a Vec. That is if we were to insert the expr id 152, we allocate a vec of length 152 where the first 151 elements are unmapped. So this should be an FxHashMap
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes that's wrong. Between FxHashMap
and NoHashHashMap
which one would be better here?
About desugaring, it would also help in simplifing MIR lowering which currently is ugly (and this field is used there) and type inference. Currently both need to find IntoIterator
related things via lang items, but with desugaring it would be unified in one place. But it probably has it's own cons too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is very rarely populated with keys I'd say NoHashHashMap
.
Though I am wondering whether we should get rid of that hashmap type again. I assumed that hashbrown has no problems with sequential hashes but I believe that was wrong (forgot where I saw that), so that type most likely has no perf gain for our usual use cases with IDs. Would need to investigate.
I was wondering about HIR desugaring in r-a, there is almost (if any at all) no desugaring happening and I am unsure whether there is a reason for that aside from the usual "there was no need for it so far".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NoHashHashMap
didn't work for some reason, so I used FxHashMap
.
Experimenting with HIR desugaring can be started with ? operator
, as it would solve real problems like #12247
match &body[self.pat_id] { | ||
Pat::Bind { name, .. } => name.clone(), | ||
_ => { | ||
stdx::never!("hir::Local is missing a name!"); | ||
Name::missing() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Finally this is gone :)
There was a false positive for For |
|
☔ The latest upstream changes (presumably #14261) made this pull request unmergeable. Please resolve the merge conflicts. |
IMO we should only start out with a diagnostic being non-experimental of we are really sure that it's not going to have false positives. (And if we're going to have more false positives once more of MIR gets implemented, that's also not good.) |
Yes I agree, I assumed the |
I made So I think it doesn't need to be experimental, but if you think it needs, I can change it. |
I also have some questions about performance, things about the query system is not clear to me. What would become invalidated (hir, hir source map, infer result, mir, diagnostics) in these changes?
And how much time we are allowed to put on the diagnostics, what will happen if we spend more? Another question is that I saw some profiling infrastructure on the inference code, should I add them to the MIR and borrow checking as well? And where is the result of that profiling available? |
An item is pretty much the smallest unit we have in a sense, so changing a character in a function should invalidate the body, meaning hir gets redone for it and all that follows from that afaik. (diagnostics aren't even a query I think so thats just recalculated on every change). This mainly goes for the function body, if the function signature is changed, this will have wider implications obviously, as the signature can be observed by other things.
This I am not actually sure about, we assign ids to nodes in breadth first order which allows us to not having to recalculate anything item related when changing things inside of an item, but adding a single character between items is parsed as a macro call I believe which should invaldiated all items below if I am not mistaken?
Anything that depends on those definition (transitively). In short, salsa will check dependency queries for whether they are still fresh or not. A query might have to be re-evaluated because its dependencies changed, but if the result of the query is equal to the previous result it will be marked as not having changed I think stopping the "dirtyness" in propagating (not 100% sure if this always works that way though). |
This is not very clear to me. For example: struct Foe(u8); // change Foe to Foo
fn x() {
let y = Foo(2);
}
|
Changing the name of an item changes the crate def map, which invalidates everything that depended on it including all type check results in the crate. |
On the other hand, changing |
Hmm, so adding an item will also invalidate everything, right? That's more invalidating than what I initially thought. So the performance of MIR lowering can become important. Do you think it needs some action? |
Adding items should be rare enough for it not to matter, though now I wonder how |
Use items will also invalidate the def map, I think. At least pub ones have to anyway. |
I added some profiling. The result from Anything else to do on this before merge? |
It's also worth noting that (these kinds of) diagnostics are only ever calculated for the open buffers in the editor and not project-wide so its unlikely to be problematic for now. Let's get this merged now then since its still early in the week. |
☀️ Test successful - checks-actions |
This PR adds:
need-mut
andunused-mut
diagnosticsView mir
command which shows MIR for the body under cursor, useful for debugging