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

Use mir constant in thir instead of ty::Const #94255

Merged
merged 9 commits into from
Apr 13, 2022

Conversation

b-naber
Copy link
Contributor

@b-naber b-naber commented Feb 22, 2022

This is blocked on #94059 (does include its changes, the first two commits in this PR correspond to those changes) and #93800 being reinstated (which had to be reverted). Mainly opening since @lcnr offered to give some feedback and maybe also for a perf-run (if necessary).

This currently contains a lot of duplication since some of the logic of ty::Const had to be copied to mir::ConstantKind, but with the introduction of valtrees a lot of that functionality will disappear from ty::Const.

Only the last commit contains changes that need to be reviewed here. Did leave some FIXME comments regarding future implementation decisions and some things that might be incorrectly implemented.

r? @oli-obk

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Feb 22, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 22, 2022
@@ -200,14 +200,17 @@ impl<'tcx> AbstractConst<'tcx> {
Ok(inner.map(|inner| AbstractConst { inner, substs: uv.substs }))
}

pub fn from_const(
pub fn from_constant(
Copy link
Member

Choose a reason for hiding this comment

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

ConstantKind::Value is for non type system stuff isnt it? all of the stuff in this file is to do with type level constants so it seems kinda sus to be taking a ConstantKind here instead of a Const. I'm not all that familiar with mir::Constant so I may be off here 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes ConstantKind::Value isn't meant to be seen by the type system, but I don't think this is a problem here since we basically discard those here and only care about unevaluated constants. I think this is unlikely to change given the purpose of AbstractConst.

Copy link
Contributor

Choose a reason for hiding this comment

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

we don't want this, should never need an AbstractConst for mir constants. These are only used to unify constants in the type system

@Dylan-DPC Dylan-DPC added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 25, 2022
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

will get to the rest of this PR next week. We originally intended to also use valtrees in pattern, as they should simplify exhaustiveness checking.

Currently trying to figure out what exactly our plan should be for that and more generally how to deal with structural equality going forward

compiler/rustc_const_eval/src/const_eval/mod.rs Outdated Show resolved Hide resolved
}

#[instrument(skip(tcx), level = "debug")]
pub fn try_eval_lit_or_param(
Copy link
Contributor

@lcnr lcnr Feb 24, 2022

Choose a reason for hiding this comment

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

that shouldn't be needed, you can always keep mir constants as unevaluated. We maybe have to change it so that mir constants are always eagerly normalized, but we shouldn't have to special case them here

Copy link
Contributor

Choose a reason for hiding this comment

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

Mir constants do not need eager normalization per se, but it can be helpful for perf if mir opts can trust that they don't even need to attempt to eval them, because all evaluable ones have been evaluated

Copy link
Contributor

@lcnr lcnr Mar 28, 2022

Choose a reason for hiding this comment

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

can you remove this function and instead eagerly call tcx.const_eval_resolve on the DefId with its identity substs before building the mir constants?

@oli-obk
Copy link
Contributor

oli-obk commented Feb 26, 2022

. We originally intended to also use valtrees in pattern, as they should simplify exhaustiveness checking.

Yea. My plan was "evaluate to valtree and if that fails, keep the constant opaque". I'm not sure we can fall back to "always be opaque" without a breaking change. And keeping around the deref/field infrastructure for mir constants is a cost I'd rather avoid.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

Changing the thir stuff partially back to ty::Const isn't strictly necessary and is probably easier once valtrees are fully set up.

Changing Node::Leaf back to ty::Const is important to me as these are constants we use in the type system

compiler/rustc_middle/src/ty/consts/kind.rs Show resolved Hide resolved
compiler/rustc_mir_build/src/build/matches/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/matches/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/thir.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs Outdated Show resolved Hide resolved
/// String literals. Strings are not quite the same as `&[u8]` so we treat them separately.
Str(ty::Const<'tcx>),
Str(mir::ConstantKind<'tcx>),
Copy link
Contributor

Choose a reason for hiding this comment

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

as we structurally match strings, we should use ty::Const<'tcx> here

Copy link
Contributor

Choose a reason for hiding this comment

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

or tbh, probably we should use Str(Valtree) 😅 not sure what's the best way to do this

Copy link
Contributor

Choose a reason for hiding this comment

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

&'tcx [u8] would be the least ambiguous, but may require some conversions or interning later. Right now you can get it right from the Allocation

@@ -200,14 +200,17 @@ impl<'tcx> AbstractConst<'tcx> {
Ok(inner.map(|inner| AbstractConst { inner, substs: uv.substs }))
}

pub fn from_const(
pub fn from_constant(
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't want this, should never need an AbstractConst for mir constants. These are only used to unify constants in the type system

compiler/rustc_middle/src/thir/abstract_const.rs Outdated Show resolved Hide resolved
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@b-naber b-naber force-pushed the use-mir-constant-in-thir branch 2 times, most recently from c1169e5 to 647211a Compare March 28, 2022 09:11
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

compiler/rustc_middle/src/mir/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_const_eval/src/const_eval/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_const_eval/src/const_eval/mod.rs Outdated Show resolved Hide resolved
}

#[instrument(skip(tcx), level = "debug")]
pub fn try_eval_lit_or_param(
Copy link
Contributor

@lcnr lcnr Mar 28, 2022

Choose a reason for hiding this comment

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

can you remove this function and instead eagerly call tcx.const_eval_resolve on the DefId with its identity substs before building the mir constants?

compiler/rustc_middle/src/thir/visit.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/thir/cx/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/thir/pattern/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/thir/pattern/mod.rs Outdated Show resolved Hide resolved
@bors
Copy link
Contributor

bors commented Mar 30, 2022

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

@rust-log-analyzer

This comment has been minimized.

@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-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Apr 12, 2022
@bors
Copy link
Contributor

bors commented Apr 12, 2022

⌛ Testing commit 3be987e with merge 2562bc2236f1ef40d35cd8c776c080524c0f4717...

@bors
Copy link
Contributor

bors commented Apr 12, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 12, 2022
@rust-log-analyzer
Copy link
Collaborator

The job i686-msvc-1 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [ui] src/test\ui-fulldeps\stdio-from.rs stdout ----

error: test run failed!
status: exit code: 101
command: PATH="D:\a\rust\rust\build\i686-pc-windows-msvc\stage2\lib\rustlib\i686-pc-windows-msvc\lib;C:\Program Files (x86)\Windows Kits\10\bin\x64;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64;C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX64\x86;D:\a\rust\rust\build\i686-pc-windows-msvc\stage0-bootstrap-tools\i686-pc-windows-msvc\release\deps;D:\a\rust\rust\build\i686-pc-windows-msvc\stage0\bin;D:\a\rust\rust\ninja;D:\a\rust\rust\msys2\mingw32\bin;C:\hostedtoolcache\windows\Python\3.10.4\x64\Scripts;C:\hostedtoolcache\windows\Python\3.10.4\x64;C:\msys64\usr\bin;D:\a\rust\rust\sccache;C:\Program Files\MongoDB\Server\5.0\bin;C:\aliyun-cli;C:\vcpkg;C:\cf-cli;C:\Program Files (x86)\NSIS;C:\tools\zstd;C:\Program Files\Mercurial;C:\hostedtoolcache\windows\stack\2.7.5\x64;C:\cabal\bin;C:\ghcup\bin;C:\tools\ghc-9.2.2\bin;C:\Program Files\dotnet;C:\mysql\bin;C:\Program Files\R\R-4.1.3\bin\x64;C:\SeleniumWebDrivers\GeckoDriver;C:\Program Files (x86)\sbt\bin;C:\Program Files (x86)\GitHub CLI;C:\Program Files\Git\bin;C:\Program Files (x86)\pipx_bin;C:\hostedtoolcache\windows\go\1.15.15\x64\bin;C:\hostedtoolcache\windows\Python\3.7.9\x64\Scripts;C:\hostedtoolcache\windows\Python\3.7.9\x64;C:\hostedtoolcache\windows\Ruby\2.5.9\x64\bin;C:\tools\kotlinc\bin;C:\hostedtoolcache\windows\Java_Temurin-Hotspot_jdk\8.0.322-6\x64\bin;C:\npm\prefix;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\ProgramData\kind;C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\ProgramData\Chocolatey\bin;C:\Program Files\Docker;C:\Program Files\PowerShell\7;C:\Program Files\Microsoft\Web Platform Installer;C:\Program Files\dotnet;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn;C:\Program Files (x86)\Windows Kits\10\Windows Performance Toolkit;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\130\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\140\DTS\Binn;C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn;C:\Program Files\nodejs;C:\Program Files\OpenSSL\bin;C:\Strawberry\c\bin;C:\Strawberry\perl\site\bin;C:\Strawberry\perl\bin;C:\ProgramData\chocolatey\lib\pulumi\tools\Pulumi\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\CMake\bin;C:\ProgramData\chocolatey\lib\maven\apache-maven-3.8.5\bin;C:\Program Files\Microsoft Service Fabric\bin\Fabric\Fabric.Code;C:\Program Files\Microsoft SDKs\Service Fabric\Tools\ServiceFabricLocalClusterManager;C:\Program Files\Git\cmd;C:\Program Files\Git\mingw64\bin;C:\Program Files\Git\usr\bin;C:\Program Files\GitHub CLI;C:\tools\php;C:\Program Files (x86)\sbt\bin;C:\SeleniumWebDrivers\ChromeDriver;C:\SeleniumWebDrivers\EdgeDriver;C:\Program Files\Amazon\AWSCLIV2;C:\Program Files\Amazon\SessionManagerPlugin\bin;C:\Program Files\Amazon\AWSSAMCLI\bin;C:\Program Files (x86)\Google\Cloud SDK\google-cloud-sdk\bin;C:\Program Files (x86)\Microsoft BizTalk Server;C:\Program Files\LLVM\bin;C:\Users\runneradmin\.dotnet\tools;C:\Users\runneradmin\.cargo\bin;C:\Users\runneradmin\AppData\Local\Microsoft\WindowsApps" "D:\\a\\rust\\rust\\build\\i686-pc-windows-msvc\\test\\ui-fulldeps\\stdio-from\\a.exe"
stdout: none
--- stderr -------------------------------
I/O error: operation failed to complete synchronously
thread 'main' panicked at 'assertion failed: child2.wait()?.success()', D:\a\rust\rust\src/test\ui-fulldeps\stdio-from.rs:50:5
------------------------------------------




failures:
    [ui] src/test\ui-fulldeps\stdio-from.rs

test result: FAILED. 65 passed; 1 failed; 1 ignored; 0 measured; 0 filtered out; finished in 24.31s

Some tests failed in compiletest suite=ui-fulldeps mode=ui host=i686-pc-windows-msvc target=i686-pc-windows-msvc
Build completed unsuccessfully in 0:33:16
make: *** [Makefile:72: ci-subset-1] Error 1

@oli-obk
Copy link
Contributor

oli-obk commented Apr 12, 2022

@bors retry msvc fulldeps test failure: I/O error: operation failed to complete synchronously

@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 Apr 12, 2022
@bors
Copy link
Contributor

bors commented Apr 12, 2022

⌛ Testing commit 3be987e with merge 52abb2fa4028f997c9d3887e089674e9dfda1902...

@bors
Copy link
Contributor

bors commented Apr 12, 2022

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 12, 2022
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@oli-obk
Copy link
Contributor

oli-obk commented Apr 13, 2022

@bors retry no output

@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 Apr 13, 2022
@bors
Copy link
Contributor

bors commented Apr 13, 2022

⌛ Testing commit 3be987e with merge e3c43e6...

@bors
Copy link
Contributor

bors commented Apr 13, 2022

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 13, 2022
@bors bors merged commit e3c43e6 into rust-lang:master Apr 13, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 13, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (e3c43e6): comparison url.

Summary:

  • Primary benchmarks: 😿 relevant regressions found
  • Secondary benchmarks: 😿 relevant regressions found
Regressions 😿
(primary)
Regressions 😿
(secondary)
Improvements 🎉
(primary)
Improvements 🎉
(secondary)
All 😿 🎉
(primary)
count1 2 12 0 0 2
mean2 0.2% 0.4% N/A N/A 0.2%
max 0.2% 0.5% N/A N/A 0.2%

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression

Footnotes

  1. number of relevant changes

  2. the arithmetic mean of the percent change

@pnkfelix
Copy link
Member

Visiting for weekly performance triage. This caused a 0.2% regression on the primary benchmarks webrender-2022 check (full) and cargo-0.60.0 check (incr-full). An earlier perf run, on I think the same commit series as what was eventually merged, showed no primary regressions at all.

A number of secondary benchmarks regressed, but they are all stress test microbenchmarks, and should not block landing work of this nature.

So, I'm chalking the minor amount of regression that was observed up to noise.

@rustbot label +perf-regression-triaged

@rustbot rustbot added the perf-regression-triaged The performance regression has been triaged. label Apr 19, 2022
flip1995 pushed a commit to flip1995/rust that referenced this pull request Apr 21, 2022
…li-obk

Use mir constant in thir instead of ty::Const

This is blocked on rust-lang#94059 (does include its changes, the first two commits in this PR correspond to those changes) and rust-lang#93800 being reinstated (which had to be reverted). Mainly opening since `@lcnr` offered to give some feedback and maybe also for a perf-run (if necessary).

This currently contains a lot of duplication since some of the logic of `ty::Const` had to be copied to `mir::ConstantKind`, but with the introduction of valtrees a lot of that functionality will disappear from `ty::Const`.

Only the last commit contains changes that need to be reviewed here. Did leave some `FIXME` comments regarding future implementation decisions and some things that might be incorrectly implemented.

r? `@oli-obk`
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. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.