Skip to content
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

#![custom_mir]: Various improvements #104975

Merged
merged 4 commits into from
Dec 1, 2022
Merged

Conversation

JakobDegen
Copy link
Contributor

@JakobDegen JakobDegen commented Nov 27, 2022

This PR makes a bunch of improvements to #![custom_mir]. Ideally this would be 4 PRs, one for each commit, but those would take forever to get merged and be a pain to juggle. Should still be reviewed one commit at a time though.

Commit 1: Support arbitrary let

Before this change, all locals used in the body need to be declared at the top of the mir! invocation, which is rather annoying. We attempt to change that.

Unfortunately, we still have the requirement that the output of the mir! macro must resolve, typecheck, etc. Because of that, we can't just accept this in the THIR -> MIR parser because something like

{
    let x = 0;
    Goto(other)
}
other = {
    RET = x;
    Return()
}

will fail to resolve. Instead, the implementation does macro shenanigans to find the let declarations and extract them as part of the mir! macro. That works, but it is fairly complicated and degrades debuginfo by quite a bit. Specifically, the spans for any statements and declarations that are affected by this are completely wrong. My guess is that this is a net improvement though.

One way to recover some of the debuginfo would be to not support type annotations in the let statements, which would allow us to parse like let $stmt:stmt. That seems quite surprising though.

Commit 2: Parse consts

Reuses most of the const parsing from regular Mir building for building custom mir

Commit 3: Parse statics

Statics are slightly weird because the Mir primitive associated with them is a reference/pointer to them, so this is factored out separately.

Commit 4: Fix some spans

A bunch of the spans were non-ideal, so we adjust them to be much more helpful.

r? @oli-obk

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 27, 2022
@rustbot
Copy link
Collaborator

rustbot commented Nov 27, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@JakobDegen JakobDegen changed the title Support arbitrary let statements in custom mir #![custom_mir]: Various improvements Nov 28, 2022
Comment on lines 905 to 907
if self.is_custom_mir {
kind
} else {
ExprKind::Deref {
arg: self.thir.exprs.push(Expr {
ty,
temp_lifetime,
span: expr.span,
kind,
}),
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like this too much, can we revert it once &Static(Name) is a thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, actually, I can just revert it immediately. I can manually parse and ignore the deref instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reverted the changes to this part of the code and pushed an additional commit that has the alternative to this. Should be much better, not sure why I didn't do this in the first place

Copy link
Contributor

Choose a reason for hiding this comment

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

yea, I like this.

@oli-obk
Copy link
Contributor

oli-obk commented Nov 28, 2022

@bors delegate+

r=me with the new commit squashed into its parent

@bors
Copy link
Contributor

bors commented Nov 28, 2022

✌️ @JakobDegen can now approve this pull request

@bors
Copy link
Contributor

bors commented Nov 29, 2022

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

@JakobDegen
Copy link
Contributor Author

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Nov 30, 2022

📌 Commit 5a34dbf has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 30, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Dec 1, 2022
`#![custom_mir]`: Various improvements

This PR makes a bunch of improvements to `#![custom_mir]`. Ideally this would be 4 PRs, one for each commit, but those would take forever to get merged and be a pain to juggle. Should still be reviewed one commit at a time though.

### Commit 1: Support arbitrary `let`

Before this change, all locals used in the body need to be declared at the top of the `mir!` invocation, which is rather annoying. We attempt to change that.

Unfortunately, we still have the requirement that the output of the `mir!` macro must resolve, typecheck, etc. Because of that, we can't just accept this in the THIR -> MIR parser because something like
```rust
{
    let x = 0;
    Goto(other)
}
other = {
    RET = x;
    Return()
}
```
will fail to resolve. Instead, the implementation does macro shenanigans to find the let declarations and extract them as part of the `mir!` macro. That *works*, but it is fairly complicated and degrades debuginfo by quite a bit. Specifically, the spans for any statements and declarations that are affected by this are completely wrong. My guess is that this is a net improvement though.

One way to recover some of the debuginfo would be to not support type annotations in the `let` statements, which would allow us to parse like `let $stmt:stmt`. That seems quite surprising though.

### Commit 2: Parse consts

Reuses most of the const parsing from regular Mir building for building custom mir

### Commit 3: Parse statics

Statics are slightly weird because the Mir primitive associated with them is a reference/pointer to them, so this is factored out separately.

### Commit 4: Fix some spans

A bunch of the spans were non-ideal, so we adjust them to be much more helpful.

r? `@oli-obk`
@bors
Copy link
Contributor

bors commented Dec 1, 2022

⌛ Testing commit 5a34dbf with merge 9c0bc30...

@bors
Copy link
Contributor

bors commented Dec 1, 2022

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 9c0bc30 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 1, 2022
@bors bors merged commit 9c0bc30 into rust-lang:master Dec 1, 2022
@rustbot rustbot added this to the 1.67.0 milestone Dec 1, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (9c0bc30): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
5.0% [4.1%, 5.9%] 2
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.0% [2.0%, 2.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

@JakobDegen JakobDegen deleted the custom_mir_let branch December 4, 2022 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants