Skip to content

feat: Compute closure captures - #14470

Merged
bors merged 1 commit into
rust-lang:masterfrom
hkalbasi:mir
Apr 10, 2023
Merged

feat: Compute closure captures#14470
bors merged 1 commit into
rust-lang:masterfrom
hkalbasi:mir

Conversation

@hkalbasi

@hkalbasi hkalbasi commented Apr 2, 2023

Copy link
Copy Markdown
Member

This PR:

  • Computes closure captures and the trait it implements (Fn, FnMut or FnOnce)
  • Computes data layout of closures
  • Adds support for closure MIR lowering
  • Changes the closure type display from |arg1: ty1, arg2: ty| -> ret to impl FnX(arg1: ty1, arg2: ty2) -> ret

fix #12297

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 2, 2023
@hkalbasi
hkalbasi force-pushed the mir branch 3 times, most recently from e47135b to a611b26 Compare April 2, 2023 20:49
@hkalbasi

hkalbasi commented Apr 3, 2023

Copy link
Copy Markdown
Member Author

Is there a way in salsa to get a query result only if it is calculated before? Currently, the display code for closure calls db.infer, which works, but if we try to use it in the middle of infer (for example for print debugging, or due some future bug) we will get cycle panic, which is worse than fallback to a simpler display.

@bors

bors commented Apr 5, 2023

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #14436) made this pull request unmergeable. Please resolve the merge conflicts.

@hkalbasi
hkalbasi force-pushed the mir branch 2 times, most recently from 136f1cd to ca56f2c Compare April 5, 2023 23:20

@Veykril Veykril left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't looked over everything yet, but as this is a rather big PR again, could you try splitting out the derive macro expansion change as its own PR? And if possible also the Forces reborrow of mutable references in method receiver, part

Comment thread crates/hir-def/src/body/lower.rs Outdated
Comment thread crates/hir-def/src/body/lower.rs
@bors

bors commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #14509) made this pull request unmergeable. Please resolve the merge conflicts.

@lowr

lowr commented Apr 6, 2023

Copy link
Copy Markdown
Contributor

I think #12297 should be linked?

I don't have too strong opinion here, but I'd rather have inlay hints rendering for closures configurable. I pretty much agree with this comment in that I don't usually care what Fn* traits closures implement. Current pseudo-Rust notation |T, U| -> R is not valid Rust, but I find it concise which I value for stuffs shown in my editor all the time.

On the other hand, I'd love to see the information on hover!

@hkalbasi

hkalbasi commented Apr 6, 2023

Copy link
Copy Markdown
Member Author

Ah, I forgot that it was controversial last time. Will make it configurable.

bors added a commit that referenced this pull request Apr 6, 2023
Always reborrow mutable reference receiver in methods

Dependency of #14470
bors added a commit that referenced this pull request Apr 7, 2023
Add bounds for fields in derive macro

Dependency of #14470
@hkalbasi
hkalbasi force-pushed the mir branch 3 times, most recently from 070a734 to 7bb6683 Compare April 7, 2023 22:33
@hkalbasi

Copy link
Copy Markdown
Member Author

@bors r+

@bors

bors commented Apr 10, 2023

Copy link
Copy Markdown
Contributor

📌 Commit 59b6f2d has been approved by HKalbasi

It is now in the queue for this repository.

@bors

bors commented Apr 10, 2023

Copy link
Copy Markdown
Contributor

⌛ Testing commit 59b6f2d with merge 44cf8ef...

@bors

bors commented Apr 10, 2023

Copy link
Copy Markdown
Contributor

☀️ Test successful - checks-actions
Approved by: HKalbasi
Pushing 44cf8ef to master...

@bors
bors merged commit 44cf8ef into rust-lang:master Apr 10, 2023
@Veykril

Veykril commented Apr 11, 2023

Copy link
Copy Markdown
Member

This absolutely ruined type inference on self (unknown types)
image

@hkalbasi

Copy link
Copy Markdown
Member Author

Ah sorry, I should check these always. Will look at it.

@Veykril

Veykril commented Apr 11, 2023

Copy link
Copy Markdown
Member

Ah I think this is in part due to the dangling temporary Expr::Missing we are allocating now, though we do have some changes to the pattern types as well

@hkalbasi

Copy link
Copy Markdown
Member Author

Type inference for nested closures is broken it seems. Still looking.

@Veykril

Veykril commented Apr 11, 2023

Copy link
Copy Markdown
Member

Should we revert this PR for now (so you don't have the stress of having to fix this immediately?), and maybe just pick the hir-def pieces and what not that don't break things yet

@hkalbasi

Copy link
Copy Markdown
Member Author

Since this is big, and I have some uncommited changes on top of it, reverting it makes some git headache for me. I will file a revert tomorrow if the fix is not trivial.

bors added a commit that referenced this pull request Apr 11, 2023
Fix inference in nested closures

fix #14470 (comment)
@hkalbasi

Copy link
Copy Markdown
Member Author

@Veykril it looks like metric is now back, but I didn't change anything related to the dangling Missing. Was it just a guess, or did you see something about it?

@Veykril

Veykril commented Apr 11, 2023

Copy link
Copy Markdown
Member

Just an assumption thoug I mightve misunderstood parts of the code. Do note thoug that we are not fully back to prior this PR in terms on unknown types, so it would be nice to figure out what else regressed here.

@lnicola lnicola changed the title Compute closure captures feat: Compute closure captures Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

impl Fn, impl FnMut, ... as inlay hint for closures

5 participants