-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Get rid of most of the RefCells in librustc_typeck/check #25247
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
Conversation
It turns out not to have ever been written to, so visit_object_cast_map never actually processed any items.
(rust_highfive has picked a reviewer for you, use r? to override) |
Wow! Nice! I don't personally work much in these crates though, so I'll defer to @nikomatsakis or @pnkfelix r? @pnkfelix |
couldn't you just take FnCtxt by mutable reference? |
@arielb1 Not in general, because it has to be shared in a number of places (e.g. the |
I couldn't find any Typing in upvar.rs |
@arielb1 https://github.com/rust-lang/rust/pull/25247/files#diff-193820a23727493def60049c0b6af47eR443 (might be called |
You could still pass it as a mutable reference in most places, though, and just split it up into two internal structures when necessary (as it is there), which is the potential refactoring I alluded to above. This is the approach I'm taking from the getgo in the trans patch. |
I am afraid your splitting creates lots of ugly duplication. |
@arielb1 Yes, like I said above, it can be done, but I didn't want to make the patch too much larger. In particular, adding such a method would also require us to make the I agree that the duplication is unfortunate; a lot of it could probably be resolved with a macro like the |
The current patch seems rather large and ugly to me (passing FnCtxt and CheckEnv through all of typeck's methods - half of them already have rather more parameters than optimal). |
I didn't have time to read this today, but I have been wanting to refactor a lot of these refcells away for some time, so this at least sounds great! |
@arielb1 #25332 is the trans patch and passes a mutable reference like you were asking about. Unfortunately, a lot of the time in order to actually use it I had to end up splitting the parameters immediately on function entry and then join them together for subsequent calls, which I feel like kinds of defeats the purpose of having multiple parameters. Then again, trans is probably a little different, since there we are dealing with multiple blocks, each of which references a single context, while here we can probably just treat it as one context for all intents and purposes. So maybe I actually should have taken the double-parameter approach in trans, and the single-parameter approach here, rather than the other way around. |
☔ The latest upstream changes (presumably #25320) made this pull request unmergeable. Please resolve the merge conflicts. |
☔ The latest upstream changes (presumably #24619) made this pull request unmergeable. Please resolve the merge conflicts. |
I started a discuss thread to discuss this approach, since it seems to have some pros and cons: https://internals.rust-lang.org/t/prs-removing-refcells-longer-term-plans/2099 @pythonesque I'm sorry for the slow feedback...it's been a bit crazy last few weeks. |
cmt: &mc::cmt<'tcx>, | ||
move_reason: MoveReason) | ||
-> ConsumeMode | ||
where T: mc::Typer<'tcx> |
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.
Why make this more generic?
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.
Oh, I see, Typer is no longer object-safe. I think I'd prefer that Typer stay object-safe; pity we don't have a good solution for passing FnOnce() closurs as objects yet.
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, I remember the issue I had now. Yeah, there was literally no way to add a closure (that I could see) without breaking object safety.
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.
Doing a re-review of these changes, this doesn't matter anymore I axed the Typer interface last week.
@nikomatsakis @jroesch how would this change interact with the recently discussed revisions to the compiler infrastructure? I am basically wondering if I should push through a review of this PR (and then presumably request it be rebased, assuming it passes review), or if we should put this aside for now until after other refactorings take place? From what I remember, it seems like this PR should probably help more than it hurts future refactorings. |
@pnkfelix While on vacation, I was thinking about these PRs and asking myself the same question. I'm not really clear on how these PR fit into the plans we were discussing. I think I have to get the various refactorings reloaded a bit into my head before I can evaluate the impact. |
I've been meaning to review this work as well, will sit down after lunch and read it over. |
Currently my feeling though is that we are pursuing a lot of refactorings -- flattening contexts, breaking up tables to be more local, incremental compilation, MIR -- and that it's we should leave things as they are under the assumption that they are going to be dismembered and put back together, and when we do this we will try to make best use of our type system. |
Based on the inactivity and @nikomatsakis' comment, I'm going to close this PR. Feel free to disagree! |
There are two that I didn't touch that are kind of irksome to get rid of. Though I do want to do it, I also don't want to make this commit too much larger.
I may also try to refactor this to see if I can get rid of some of the extra structures / function parameters; it was helpful as an intermediate step, but I think most of the time we can get away with just passing one context around.