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

Allow unsafe through inline const #105147

Merged
merged 7 commits into from
Dec 14, 2022
Merged

Conversation

nbdd0121
Copy link
Contributor

@nbdd0121 nbdd0121 commented Dec 1, 2022

Handle similar to closures.

Address #104087 (comment)

Note that this PR does not fix the issue for unsafe { [0; function_requiring_unsafe()] }. This is fundamentally unfixable for MIR unsafeck IMO.

This PR also does not fix unsafety checking for inline const in pattern position. It actually breaks it, allowing unsafe functions to be used in inline const in pattern position without unsafe blocks. Inline const in pattern position is not visible in MIR so ignored by MIR unsafety checking (currently it is also not checked by borrow checker, which is the reason why it's considered an incomplete feature).

@rustbot label: +T-lang +F-inline_const

@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 2022

r? @nagisa

(rustbot has picked a reviewer for you, use r? to override)

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

rustbot commented Dec 1, 2022

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Dec 1, 2022
@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

RalfJung commented Dec 3, 2022

Note that this PR does not fix the issue for unsafe { [0; function_requiring_unsafe()] }. This is fundamentally unfixable for MIR unsafeck IMO.

Why is that any harder than having unsafe propagate into closures? Both are completely separate MIR bodies after all. So somehow the MIR body for the closure is informed that is "lives" in an unsafe block, and the same could happen with array lengths?

EDIT: Either way that is separate from inline consts, so I opened a new issue at #105204.

@nbdd0121
Copy link
Contributor Author

nbdd0121 commented Dec 4, 2022

Why is that any harder than having unsafe propagate into closures? Both are completely separate MIR bodies after all. So somehow the MIR body for the closure is informed that is "lives" in an unsafe block, and the same could happen with array lengths?

The difficulty arises precisely from the fact that they are separate MIR bodies. For closures (and after this PR, inline consts), their use is visible in the MIR of the containing body -- closures appear as a Rvalue::Aggregate and inline consts appear as Operand::Constant. However the same thing cannot be said for array length. Because array length feeds into the type system, it was (and needs to be) simplified and evaluated before the MIR is built, and the MIR built will reference these constants anymore.

So the issue for anon consts cannot easily be resolved with MIR unsafeck. It should be solvable, though, once we move to THIR unsafeck.

@nagisa
Copy link
Member

nagisa commented Dec 11, 2022

r? @oli-obk

I can’t even begin to guess whether we actually want to do this…

@rustbot rustbot assigned oli-obk and unassigned nagisa Dec 11, 2022
This is handled similar to closures
The closure handling code is changed slightly to avoid allocation
when THIR building failed.
MIR unsafety checking requires this to be valid
All bodies are unsafe checked anyway. Current MIR unsafeck also just
returns for closures.
@oli-obk
Copy link
Contributor

oli-obk commented Dec 13, 2022

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Dec 13, 2022
@bors
Copy link
Contributor

bors commented Dec 13, 2022

⌛ Trying commit d6dc912 with merge 26e606eb2c7253f83a3db16651f9ed5443c7d61d...

@bors
Copy link
Contributor

bors commented Dec 13, 2022

☀️ Try build successful - checks-actions
Build commit: 26e606eb2c7253f83a3db16651f9ed5443c7d61d (26e606eb2c7253f83a3db16651f9ed5443c7d61d)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (26e606eb2c7253f83a3db16651f9ed5443c7d61d): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.1% [1.0%, 1.2%] 2
Regressions ❌
(secondary)
2.3% [2.1%, 2.7%] 6
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.1% [1.0%, 1.2%] 2

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)
3.4% [2.9%, 3.8%] 2
Regressions ❌
(secondary)
2.3% [2.3%, 2.3%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.0% [-2.0%, -2.0%] 1
All ❌✅ (primary) 3.4% [2.9%, 3.8%] 2

Cycles

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

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 13, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Dec 13, 2022

These regressions are just noise, the exact same regression is happening on unrelated other PRs.

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Dec 13, 2022

📌 Commit d6dc912 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 Dec 13, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 13, 2022
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#105147 (Allow unsafe through inline const)
 - rust-lang#105438 (Move some codegen-y methods from `rustc_hir_analysis::collect` -> `rustc_codegen_ssa`)
 - rust-lang#105464 (Support #[track_caller] on async closures)
 - rust-lang#105476 (Change pattern borrowing suggestions to be verbose and remove invalid suggestion)
 - rust-lang#105500 (Make some diagnostics not depend on the source of what they reference being available)
 - rust-lang#105628 (Small doc fixes)
 - rust-lang#105659 (Don't require owned data in `MaybeStorageLive`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 7357cfb into rust-lang:master Dec 14, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 14, 2022
@nbdd0121 nbdd0121 deleted the inline_const_unsafe branch December 14, 2022 01:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-inline_const Inline constants (aka: const blocks, const expressions, anonymous constants) perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants