From 8452841f3c67a35278e03242f996cce606606156 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 08:48:14 +0000 Subject: [PATCH 1/5] Documentation never hurts --- src/lib.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 405ee13..a867520 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,10 @@ //! The WIP stable interface to rustc internals. +//! +//! For more information see https://github.com/rust-lang/project-stable-mir +//! +//! # Note +//! +//! This API is still completely unstable and subject to change. #![doc( html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/", From bd30f920eeeb52087d84b895b37357d865999e4f Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 09:06:12 +0000 Subject: [PATCH 2/5] Update instructions --- README.md | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index de35894..92eb926 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,38 @@ git subtree push --prefix=compiler/rustc_smir url_to_your_fork_of_project_stable and then open a PR of your `some_feature_branch` against https://github.com/rust-lang/project-stable-mir -### Updating the rustc librar +### Updating the rustc library +First we need to bump our stack limit, as the rustc repo otherwise quickly hits that: + +``` +ulimit -s 60000 +``` + +#### Maximum function recursion depth (1000) reached + +Then we need to disable `dash` as the default shell for sh scripts, as otherwise we run into a +hard limit of a recursion depth of 1000: + +``` +sudo dpkg-reconfigure dash +``` + +and then select `No` to disable dash. + + +#### Patching your `git worktree` + +The regular git worktree does not scale to repos of the size of the rustc repo. +So download the `git-subtree.sh` from https://github.com/gitgitgadget/git/pull/493/files and run + +``` +sudo cp --backup /path/to/patched/git-subtree.sh /usr/lib/git-core/git-subtree +sudo chmod --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree +sudo chown --reference=/usr/lib/git-core/git-subtree~ /usr/lib/git-core/git-subtree +``` + +#### Actually doing a sync In the rustc repo, execute From 6ac01b0d79abd00ff44a679ac300549d8f325921 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 25 May 2022 09:11:09 +0000 Subject: [PATCH 3/5] Rustfmt --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a867520..2b1c2bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ //! The WIP stable interface to rustc internals. -//! +//! //! For more information see https://github.com/rust-lang/project-stable-mir -//! +//! //! # Note //! //! This API is still completely unstable and subject to change. From 72a30299ec305072d6489d442160a32f59f63285 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 2 Jun 2022 09:54:57 +0000 Subject: [PATCH 4/5] record which nightly we support --- rust-toolchain.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 rust-toolchain.toml diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..7b696fc --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly-2022-06-01" +components = [ "rustfmt", "rustc-dev" ] From 98a817da427fa521affa82587f3f729e259d5269 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 2 Jun 2022 09:55:54 +0000 Subject: [PATCH 5/5] Make the crate work both in rustc and locally --- .gitignore | 1 + Cargo.toml | 11 +++++++---- README.md | 12 ++++++++++++ src/lib.rs | 2 ++ src/mir.rs | 2 +- src/very_unstable.rs | 31 ++++++++++++++++++++++--------- 6 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb5a316 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target diff --git a/Cargo.toml b/Cargo.toml index 0c5a19d..bc0cac5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,10 @@ version = "0.0.0" edition = "2021" [dependencies] -rustc_middle = { path = "../rustc_middle" } -rustc_driver = { path = "../rustc_driver" } -rustc_borrowck = { path = "../rustc_borrowck" } -rustc_interface = { path = "../rustc_interface" } +rustc_middle = { path = "../rustc_middle", optional = true } +rustc_driver = { path = "../rustc_driver", optional = true } +rustc_borrowck = { path = "../rustc_borrowck", optional = true } +rustc_interface = { path = "../rustc_interface", optional = true } + +[features] +default = ["rustc_middle", "rustc_driver", "rustc_borrowck", "rustc_interface"] diff --git a/README.md b/README.md index 92eb926..ae49098 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,18 @@ sync is pushed entirely onto us, without affecting rustc workflows negatively. This may change in the future, but changes to policy should only be done via a compiler team MCP. +## Instructions for working on this crate locally + +Since the crate is the same in the rustc repo and here, the dependencies on rustc_* crates +will only either work here or there, but never in both places at the same time. Thus we use +optional dependencies on the rustc_* crates, requiring local development to use + +``` +cargo build --no-default-features -Zavoid-dev-deps +``` + +in order to compile successfully. + ## Instructions for syncing ### Updating this repository diff --git a/src/lib.rs b/src/lib.rs index 2b1c2bb..decdae9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,6 +11,8 @@ test(attr(allow(unused_variables), deny(warnings))) )] +#![cfg_attr(not(feature = "default"), feature(rustc_private))] + pub mod mir; pub mod very_unstable; diff --git a/src/mir.rs b/src/mir.rs index 97969be..855605b 100644 --- a/src/mir.rs +++ b/src/mir.rs @@ -1,4 +1,4 @@ -pub use rustc_middle::mir::{ +pub use crate::very_unstable::middle::mir::{ visit::MutVisitor, AggregateKind, AssertKind, BasicBlock, BasicBlockData, BinOp, BindingForm, BlockTailInfo, Body, BorrowKind, CastKind, ClearCrossCrate, Constant, ConstantKind, CopyNonOverlapping, Coverage, FakeReadCause, Field, GeneratorInfo, ImplicitSelfKind, diff --git a/src/very_unstable.rs b/src/very_unstable.rs index dacdabf..12ba133 100644 --- a/src/very_unstable.rs +++ b/src/very_unstable.rs @@ -3,12 +3,25 @@ //! Only use rustc_smir in your dependencies and use the reexports here instead of //! directly referring to the unstable crates. -pub use rustc_borrowck as borrowck; -pub use rustc_driver as driver; -pub use rustc_hir as hir; -pub use rustc_interface as interface; -pub use rustc_middle as middle; -pub use rustc_mir_dataflow as dataflow; -pub use rustc_mir_transform as transform; -pub use rustc_serialize as serialize; -pub use rustc_trait_selection as trait_selection; +macro_rules! crates { + ($($rustc_name:ident -> $name:ident,)*) => { + $( + #[cfg(not(feature = "default"))] + pub extern crate $rustc_name as $name; + #[cfg(feature = "default")] + pub use $rustc_name as $name; + )* + } +} + +crates! { + rustc_borrowck -> borrowck, + rustc_driver -> driver, + rustc_hir -> hir, + rustc_interface -> interface, + rustc_middle -> middle, + rustc_mir_dataflow -> dataflow, + rustc_mir_transform -> transform, + rustc_serialize -> serialize, + rustc_trait_selection -> trait_selection, +}