Skip to content

Commit 9688594

Browse files
authored
Rollup merge of #97385 - oli-obk:smir-tool-lib, r=pnkfelix
Add WIP stable MIR crate r? ``@pnkfelix`` Discussion about this happend in the SMIR meeting yesterday. Some info can be found at https://rust-lang.zulipchat.com/#narrow/stream/320896-project-stable-mir/topic/dev.20plan.20mtg/near/283774691
2 parents 537920e + 7cba9ed commit 9688594

File tree

9 files changed

+180
-0
lines changed

9 files changed

+180
-0
lines changed

Cargo.lock

+16
Original file line numberDiff line numberDiff line change
@@ -3440,6 +3440,7 @@ dependencies = [
34403440
"jemalloc-sys",
34413441
"rustc_codegen_ssa",
34423442
"rustc_driver",
3443+
"rustc_smir",
34433444
]
34443445

34453446
[[package]]
@@ -4437,6 +4438,21 @@ dependencies = [
44374438
"tracing",
44384439
]
44394440

4441+
[[package]]
4442+
name = "rustc_smir"
4443+
version = "0.0.0"
4444+
dependencies = [
4445+
"rustc_borrowck",
4446+
"rustc_driver",
4447+
"rustc_hir",
4448+
"rustc_interface",
4449+
"rustc_middle",
4450+
"rustc_mir_dataflow",
4451+
"rustc_mir_transform",
4452+
"rustc_serialize",
4453+
"rustc_trait_selection",
4454+
]
4455+
44404456
[[package]]
44414457
name = "rustc_span"
44424458
version = "0.0.0"

compiler/rustc/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ rustc_driver = { path = "../rustc_driver" }
99
# Make sure rustc_codegen_ssa ends up in the sysroot, because this
1010
# crate is intended to be used by codegen backends, which may not be in-tree.
1111
rustc_codegen_ssa = { path = "../rustc_codegen_ssa" }
12+
# Make sure rustc_smir ends up in the sysroot, because this
13+
# crate is intended to be used by stable MIR consumers, which are not in-tree
14+
rustc_smir = { path = "../rustc_smir" }
1215

1316
[dependencies.jemalloc-sys]
1417
version = "0.5.0"

compiler/rustc_smir/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target

compiler/rustc_smir/Cargo.toml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
[package]
2+
name = "rustc_smir"
3+
version = "0.0.0"
4+
edition = "2021"
5+
6+
[dependencies]
7+
rustc_borrowck = { path = "../rustc_borrowck", optional = true }
8+
rustc_driver = { path = "../rustc_driver", optional = true }
9+
rustc_hir = { path = "../rustc_hir", optional = true }
10+
rustc_interface = { path = "../rustc_interface", optional = true }
11+
rustc_middle = { path = "../rustc_middle", optional = true }
12+
rustc_mir_dataflow = { path = "../rustc_mir_dataflow", optional = true }
13+
rustc_mir_transform = { path = "../rustc_mir_transform", optional = true }
14+
rustc_serialize = { path = "../rustc_serialize", optional = true }
15+
rustc_trait_selection = { path = "../rustc_trait_selection", optional = true }
16+
17+
[features]
18+
default = [
19+
"rustc_borrowck",
20+
"rustc_driver",
21+
"rustc_hir",
22+
"rustc_interface",
23+
"rustc_middle",
24+
"rustc_mir_dataflow",
25+
"rustc_mir_transform",
26+
"rustc_serialize",
27+
"rustc_trait_selection",
28+
]

compiler/rustc_smir/README.md

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
This crate is regularly synced with its mirror in the rustc repo at `compiler/rustc_smir`.
2+
3+
We use `git subtree` for this to preserve commits and allow the rustc repo to
4+
edit these crates without having to touch this repo. This keeps the crates compiling
5+
while allowing us to independently work on them here. The effort of keeping them in
6+
sync is pushed entirely onto us, without affecting rustc workflows negatively.
7+
This may change in the future, but changes to policy should only be done via a
8+
compiler team MCP.
9+
10+
## Instructions for working on this crate locally
11+
12+
Since the crate is the same in the rustc repo and here, the dependencies on rustc_* crates
13+
will only either work here or there, but never in both places at the same time. Thus we use
14+
optional dependencies on the rustc_* crates, requiring local development to use
15+
16+
```
17+
cargo build --no-default-features -Zavoid-dev-deps
18+
```
19+
20+
in order to compile successfully.
21+
22+
## Instructions for syncing
23+
24+
### Updating this repository
25+
26+
In the rustc repo, execute
27+
28+
```
29+
git subtree push --prefix=compiler/rustc_smir url_to_your_fork_of_project_stable_mir some_feature_branch
30+
```
31+
32+
and then open a PR of your `some_feature_branch` against https://github.com/rust-lang/project-stable-mir
33+
34+
### Updating the rustc library
35+
36+
First we need to bump our stack limit, as the rustc repo otherwise quickly hits that:
37+
38+
```
39+
ulimit -s 60000
40+
```
41+
42+
#### Maximum function recursion depth (1000) reached
43+
44+
Then we need to disable `dash` as the default shell for sh scripts, as otherwise we run into a
45+
hard limit of a recursion depth of 1000:
46+
47+
```
48+
sudo dpkg-reconfigure dash
49+
```
50+
51+
and then select `No` to disable dash.
52+
53+
54+
#### Patching your `git worktree`
55+
56+
The regular git worktree does not scale to repos of the size of the rustc repo.
57+
So download the `git-subtree.sh` from https://github.com/gitgitgadget/git/pull/493/files and run
58+
59+
```
60+
sudo cp --backup /path/to/patched/git-subtree.sh /usr/lib/git-core/git-subtree
61+
sudo chmod --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree
62+
sudo chown --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree
63+
```
64+
65+
#### Actually doing a sync
66+
67+
In the rustc repo, execute
68+
69+
```
70+
git subtree pull --prefix=compiler/rustc_smir https://github.com/rust-lang/project-stable-mir smir
71+
```
72+
73+
Note: only ever sync to rustc from the project-stable-mir's `smir` branch. Do not sync with your own forks.
74+
75+
Then open a PR against rustc just like a regular PR.
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "nightly-2022-06-01"
3+
components = [ "rustfmt", "rustc-dev" ]

compiler/rustc_smir/src/lib.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! The WIP stable interface to rustc internals.
2+
//!
3+
//! For more information see https://github.com/rust-lang/project-stable-mir
4+
//!
5+
//! # Note
6+
//!
7+
//! This API is still completely unstable and subject to change.
8+
9+
#![doc(
10+
html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/",
11+
test(attr(allow(unused_variables), deny(warnings)))
12+
)]
13+
#![cfg_attr(not(feature = "default"), feature(rustc_private))]
14+
15+
pub mod mir;
16+
17+
pub mod very_unstable;

compiler/rustc_smir/src/mir.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub use crate::very_unstable::middle::mir::{
2+
visit::MutVisitor, AggregateKind, AssertKind, BasicBlock, BasicBlockData, BinOp, BindingForm,
3+
BlockTailInfo, Body, BorrowKind, CastKind, ClearCrossCrate, Constant, ConstantKind,
4+
CopyNonOverlapping, Coverage, FakeReadCause, Field, GeneratorInfo, ImplicitSelfKind,
5+
InlineAsmOperand, Local, LocalDecl, LocalInfo, LocalKind, Location, MirPhase, MirSource,
6+
NullOp, Operand, Place, PlaceRef, ProjectionElem, ProjectionKind, Promoted, RetagKind, Rvalue,
7+
Safety, SourceInfo, SourceScope, SourceScopeData, SourceScopeLocalData, Statement,
8+
StatementKind, UnOp, UserTypeProjection, UserTypeProjections, VarBindingForm, VarDebugInfo,
9+
VarDebugInfoContents,
10+
};
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! This module reexports various crates and modules from unstable rustc APIs.
2+
//! Add anything you need here and it will get slowly transferred to a stable API.
3+
//! Only use rustc_smir in your dependencies and use the reexports here instead of
4+
//! directly referring to the unstable crates.
5+
6+
macro_rules! crates {
7+
($($rustc_name:ident -> $name:ident,)*) => {
8+
$(
9+
#[cfg(not(feature = "default"))]
10+
pub extern crate $rustc_name as $name;
11+
#[cfg(feature = "default")]
12+
pub use $rustc_name as $name;
13+
)*
14+
}
15+
}
16+
17+
crates! {
18+
rustc_borrowck -> borrowck,
19+
rustc_driver -> driver,
20+
rustc_hir -> hir,
21+
rustc_interface -> interface,
22+
rustc_middle -> middle,
23+
rustc_mir_dataflow -> dataflow,
24+
rustc_mir_transform -> transform,
25+
rustc_serialize -> serialize,
26+
rustc_trait_selection -> trait_selection,
27+
}

0 commit comments

Comments
 (0)