Skip to content

Commit 4e56d7c

Browse files
committed
Auto merge of #153753 - Zalathar:rollup-Dq0luud, r=Zalathar
Rollup of 4 pull requests Successful merges: - #153432 (Fix some comments about dataflow analysis.) - #153694 (fix(query): Pass Query Key to `value_from_cycle_error`) - #153736 (add test that an incomplete feature emits a warning) - #153750 (rustc-dev-guide subtree update)
2 parents d1ee5e5 + 46c4d67 commit 4e56d7c

22 files changed

Lines changed: 204 additions & 66 deletions

File tree

compiler/rustc_feature/src/unstable.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ declare_features! (
257257
(internal, rustc_attrs, "1.0.0", None),
258258
/// Allows using the `#[stable]` and `#[unstable]` attributes.
259259
(internal, staged_api, "1.0.0", None),
260+
/// Perma-unstable, only used to test the `incomplete_features` lint.
261+
(incomplete, test_incomplete_feature, "CURRENT_RUSTC_VERSION", None),
260262
/// Added for testing unstable lints; perma-unstable.
261263
(internal, test_unstable_lint, "1.60.0", None),
262264
/// Use for stable + negative coherence and strict coherence depending on trait's

compiler/rustc_middle/src/mir/basic_blocks.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'tcx> BasicBlocks<'tcx> {
6565

6666
/// Returns basic blocks in a reverse postorder.
6767
///
68-
/// See [`traversal::reverse_postorder`]'s docs to learn what is preorder traversal.
68+
/// See [`traversal::reverse_postorder`]'s docs to learn what is postorder traversal.
6969
///
7070
/// [`traversal::reverse_postorder`]: crate::mir::traversal::reverse_postorder
7171
#[inline]

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,12 @@ pub struct QueryVTable<'tcx, C: QueryCache> {
136136
/// For `no_hash` queries, this function pointer is None.
137137
pub hash_value_fn: Option<fn(&mut StableHashingContext<'_>, &C::Value) -> Fingerprint>,
138138

139-
pub value_from_cycle_error:
140-
fn(tcx: TyCtxt<'tcx>, cycle_error: CycleError, guar: ErrorGuaranteed) -> C::Value,
139+
pub value_from_cycle_error: fn(
140+
tcx: TyCtxt<'tcx>,
141+
key: C::Key,
142+
cycle_error: CycleError,
143+
guar: ErrorGuaranteed,
144+
) -> C::Value,
141145
pub format_value: fn(&C::Value) -> String,
142146

143147
/// Formats a human-readable description of this query and its key, as

compiler/rustc_mir_dataflow/src/impls/initialized.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,21 @@ impl<'tcx> MaybePlacesSwitchIntData<'tcx> {
109109
/// ```rust
110110
/// struct S;
111111
/// #[rustfmt::skip]
112-
/// fn foo(pred: bool) { // maybe-init:
113-
/// // {}
114-
/// let a = S; let mut b = S; let c; let d; // {a, b}
112+
/// fn foo(p: bool) { // maybe-init:
113+
/// // {p}
114+
/// let a = S; let mut b = S; let c; let d; // {p, a, b}
115115
///
116-
/// if pred {
117-
/// drop(a); // { b}
118-
/// b = S; // { b}
116+
/// if p {
117+
/// drop(a); // {p, b}
118+
/// b = S; // {p, b}
119119
///
120120
/// } else {
121-
/// drop(b); // {a}
122-
/// d = S; // {a, d}
121+
/// drop(b); // {p, a}
122+
/// d = S; // {p, a, d}
123123
///
124-
/// } // {a, b, d}
124+
/// } // {p, a, b, d}
125125
///
126-
/// c = S; // {a, b, c, d}
126+
/// c = S; // {p, a, b, c, d}
127127
/// }
128128
/// ```
129129
///
@@ -199,11 +199,11 @@ impl<'a, 'tcx> HasMoveData<'tcx> for MaybeInitializedPlaces<'a, 'tcx> {
199199
/// ```rust
200200
/// struct S;
201201
/// #[rustfmt::skip]
202-
/// fn foo(pred: bool) { // maybe-uninit:
202+
/// fn foo(p: bool) { // maybe-uninit:
203203
/// // {a, b, c, d}
204204
/// let a = S; let mut b = S; let c; let d; // { c, d}
205205
///
206-
/// if pred {
206+
/// if p {
207207
/// drop(a); // {a, c, d}
208208
/// b = S; // {a, c, d}
209209
///
@@ -279,34 +279,36 @@ impl<'tcx> HasMoveData<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
279279
}
280280
}
281281

282-
/// `EverInitializedPlaces` tracks all places that might have ever been
283-
/// initialized upon reaching a particular point in the control flow
284-
/// for a function, without an intervening `StorageDead`.
282+
/// `EverInitializedPlaces` tracks all initializations that may have occurred
283+
/// upon reaching a particular point in the control flow for a function,
284+
/// without an intervening `StorageDead`.
285285
///
286286
/// This dataflow is used to determine if an immutable local variable may
287287
/// be assigned to.
288288
///
289289
/// For example, in code like the following, we have corresponding
290-
/// dataflow information shown in the right-hand comments.
290+
/// dataflow information shown in the right-hand comments. Underscored indices
291+
/// are used to distinguish between multiple initializations of the same local
292+
/// variable, e.g. `b_0` and `b_1`.
291293
///
292294
/// ```rust
293295
/// struct S;
294296
/// #[rustfmt::skip]
295-
/// fn foo(pred: bool) { // ever-init:
296-
/// // { }
297-
/// let a = S; let mut b = S; let c; let d; // {a, b }
297+
/// fn foo(p: bool) { // ever-init:
298+
/// // {p, }
299+
/// let a = S; let mut b = S; let c; let d; // {p, a, b_0, }
298300
///
299-
/// if pred {
300-
/// drop(a); // {a, b, }
301-
/// b = S; // {a, b, }
301+
/// if p {
302+
/// drop(a); // {p, a, b_0, }
303+
/// b = S; // {p, a, b_0, b_1, }
302304
///
303305
/// } else {
304-
/// drop(b); // {a, b, }
305-
/// d = S; // {a, b, d }
306+
/// drop(b); // {p, a, b_0, b_1, }
307+
/// d = S; // {p, a, b_0, b_1, d}
306308
///
307-
/// } // {a, b, d }
309+
/// } // {p, a, b_0, b_1, d}
308310
///
309-
/// c = S; // {a, b, c, d }
311+
/// c = S; // {p, a, b_0, b_1, c, d}
310312
/// }
311313
/// ```
312314
pub struct EverInitializedPlaces<'a, 'tcx> {

compiler/rustc_query_impl/src/execution.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,17 +125,18 @@ where
125125
fn mk_cycle<'tcx, C: QueryCache>(
126126
query: &'tcx QueryVTable<'tcx, C>,
127127
tcx: TyCtxt<'tcx>,
128+
key: C::Key,
128129
cycle_error: CycleError,
129130
) -> C::Value {
130131
let error = report_cycle(tcx.sess, &cycle_error);
131132
match query.cycle_error_handling {
132133
CycleErrorHandling::Error => {
133134
let guar = error.emit();
134-
(query.value_from_cycle_error)(tcx, cycle_error, guar)
135+
(query.value_from_cycle_error)(tcx, key, cycle_error, guar)
135136
}
136137
CycleErrorHandling::DelayBug => {
137138
let guar = error.delay_as_bug();
138-
(query.value_from_cycle_error)(tcx, cycle_error, guar)
139+
(query.value_from_cycle_error)(tcx, key, cycle_error, guar)
139140
}
140141
}
141142
}
@@ -219,6 +220,7 @@ where
219220
fn cycle_error<'tcx, C: QueryCache>(
220221
query: &'tcx QueryVTable<'tcx, C>,
221222
tcx: TyCtxt<'tcx>,
223+
key: C::Key,
222224
try_execute: QueryJobId,
223225
span: Span,
224226
) -> (C::Value, Option<DepNodeIndex>) {
@@ -229,7 +231,7 @@ fn cycle_error<'tcx, C: QueryCache>(
229231
.expect("failed to collect active queries");
230232

231233
let error = find_cycle_in_stack(try_execute, job_map, &current_query_job(), span);
232-
(mk_cycle(query, tcx, error.lift()), None)
234+
(mk_cycle(query, tcx, key, error.lift()), None)
233235
}
234236

235237
#[inline(always)]
@@ -274,7 +276,7 @@ fn wait_for_query<'tcx, C: QueryCache>(
274276

275277
(v, Some(index))
276278
}
277-
Err(cycle) => (mk_cycle(query, tcx, cycle.lift()), None),
279+
Err(cycle) => (mk_cycle(query, tcx, key, cycle.lift()), None),
278280
}
279281
}
280282

@@ -337,7 +339,7 @@ fn try_execute_query<'tcx, C: QueryCache, const INCR: bool>(
337339

338340
// If we are single-threaded we know that we have cycle error,
339341
// so we just return the error.
340-
cycle_error(query, tcx, id, span)
342+
cycle_error(query, tcx, key, id, span)
341343
}
342344
}
343345
ActiveKeyStatus::Poisoned => FatalError.raise(),

compiler/rustc_query_impl/src/from_cycle_error.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,34 @@ use rustc_middle::query::erase::erase_val;
1515
use rustc_middle::ty::layout::{LayoutError, TyAndLayout};
1616
use rustc_middle::ty::{self, Ty, TyCtxt};
1717
use rustc_middle::{bug, span_bug};
18-
use rustc_span::def_id::LocalDefId;
18+
use rustc_span::def_id::{DefId, LocalDefId};
1919
use rustc_span::{ErrorGuaranteed, Span};
2020

2121
use crate::job::report_cycle;
2222

2323
pub(crate) fn specialize_query_vtables<'tcx>(vtables: &mut QueryVTables<'tcx>) {
2424
vtables.type_of.value_from_cycle_error =
25-
|tcx, _, guar| erase_val(ty::EarlyBinder::bind(Ty::new_error(tcx, guar)));
25+
|tcx, _, _, guar| erase_val(ty::EarlyBinder::bind(Ty::new_error(tcx, guar)));
2626

2727
vtables.type_of_opaque_hir_typeck.value_from_cycle_error =
28-
|tcx, _, guar| erase_val(ty::EarlyBinder::bind(Ty::new_error(tcx, guar)));
28+
|tcx, _, _, guar| erase_val(ty::EarlyBinder::bind(Ty::new_error(tcx, guar)));
2929

3030
vtables.erase_and_anonymize_regions_ty.value_from_cycle_error =
31-
|tcx, _, guar| erase_val(Ty::new_error(tcx, guar));
31+
|tcx, _, _, guar| erase_val(Ty::new_error(tcx, guar));
3232

33-
vtables.fn_sig.value_from_cycle_error = |tcx, cycle, guar| erase_val(fn_sig(tcx, cycle, guar));
33+
vtables.fn_sig.value_from_cycle_error = |tcx, key, _, guar| erase_val(fn_sig(tcx, key, guar));
3434

3535
vtables.check_representability.value_from_cycle_error =
36-
|tcx, cycle, guar| check_representability(tcx, cycle, guar);
36+
|tcx, _, cycle, guar| check_representability(tcx, cycle, guar);
3737

3838
vtables.check_representability_adt_ty.value_from_cycle_error =
39-
|tcx, cycle, guar| check_representability(tcx, cycle, guar);
39+
|tcx, _, cycle, guar| check_representability(tcx, cycle, guar);
4040

4141
vtables.variances_of.value_from_cycle_error =
42-
|tcx, cycle, guar| erase_val(variances_of(tcx, cycle, guar));
42+
|tcx, _, cycle, guar| erase_val(variances_of(tcx, cycle, guar));
4343

4444
vtables.layout_of.value_from_cycle_error =
45-
|tcx, cycle, guar| erase_val(layout_of(tcx, cycle, guar));
45+
|tcx, _, cycle, guar| erase_val(layout_of(tcx, cycle, guar));
4646
}
4747

4848
pub(crate) fn default<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError, query_name: &str) -> ! {
@@ -57,15 +57,12 @@ pub(crate) fn default<'tcx>(tcx: TyCtxt<'tcx>, cycle_error: CycleError, query_na
5757

5858
fn fn_sig<'tcx>(
5959
tcx: TyCtxt<'tcx>,
60-
cycle_error: CycleError,
60+
def_id: DefId,
6161
guar: ErrorGuaranteed,
6262
) -> ty::EarlyBinder<'tcx, ty::PolyFnSig<'tcx>> {
6363
let err = Ty::new_error(tcx, guar);
6464

65-
let arity = if let Some(info) = cycle_error.cycle.get(0)
66-
&& info.frame.dep_kind == DepKind::fn_sig
67-
&& let Some(def_id) = info.frame.def_id
68-
&& let Some(node) = tcx.hir_get_if_local(def_id)
65+
let arity = if let Some(node) = tcx.hir_get_if_local(def_id)
6966
&& let Some(sig) = node.fn_sig()
7067
{
7168
sig.decl.inputs.len()

compiler/rustc_query_impl/src/plumbing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ macro_rules! define_queries {
487487
#[cfg(not($cache_on_disk))]
488488
is_loadable_from_disk_fn: |_tcx, _key, _index| false,
489489

490-
value_from_cycle_error: |tcx, cycle, _| {
490+
value_from_cycle_error: |tcx, _, cycle, _| {
491491
$crate::from_cycle_error::default(tcx, cycle, stringify!($name))
492492
},
493493

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,7 @@ symbols! {
20062006
test_2018_feature,
20072007
test_accepted_feature,
20082008
test_case,
2009+
test_incomplete_feature,
20092010
test_removed_feature,
20102011
test_runner,
20112012
test_unstable_lint,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c78a29473a68f07012904af11c92ecffa68fcc75
1+
eda4fc7733ee89e484d7120cafbd80dcb2fce66e

src/doc/rustc-dev-guide/src/autodiff/installation.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,50 @@
11
# Installation
22

3-
In the near future, `std::autodiff` should become available in nightly builds for users. As a contributor however, you will still need to build rustc from source. Please be aware that the msvc target is not supported at the moment, all other tier 1 targets should work. Please open an issue if you encounter any problems on a supported tier 1 target, or if you successfully build this project on a tier2/tier3 target.
3+
In the near future, `std::autodiff` should become available for users via rustup. As a rustc/enzyme/autodiff contributor however, you will still need to build rustc from source.
4+
For the meantime, you can download up-to-date builds to enable `std::autodiff` on your latest nightly toolchain, if you are using either of:
5+
**Linux**, with `x86_64-unknown-linux-gnu` or `aarch64-unknown-linux-gnu`
6+
**Windows**, with `x86_64-llvm-mingw` or `aarch64-llvm-mingw`
7+
8+
You can also download slightly outdated builds for **Apple** (aarch64-apple), which should generally work for now.
9+
10+
If you need any other platform, you can build rustc including autodiff from source. Please open an issue if you want to help enabling automatic builds for your prefered target.
11+
12+
## Installation guide
13+
14+
If you want to use `std::autodiff` and don't plan to contribute PR's to the project, then we recommend to just use your existing nightly installation and download the missing component. In the future, rustup will be able to do it for you.
15+
For now, you'll have to manually download and copy it.
16+
17+
1) On our github repository, find the last merged PR: [`Repo`]
18+
2) Scroll down to the lower end of the PR, where you'll find a rust-bors message saying `Test successful` with a `CI` link.
19+
3) Click on the `CI` link, and grep for your target. E.g. `dist-x86_64-linux` or `dist-aarch64-llvm-mingw` and click `Load summary`.
20+
4) Under the `CI artifacts` section, find the `enzyme-nightly` artifact, download, and unpack it.
21+
5) Copy the artifact (libEnzyme-22.so for linux, libEnzyme-22.dylib for apple, etc.), which should be in a folder named `enzyme-preview`, to your rust toolchain directory. E.g. for linux: `cp ~/Downloads/enzyme-nightly-x86_64-unknown-linux-gnu/enzyme-preview/lib/rustlib/x86_64-unknown-linux-gnu/lib/libEnzyme-22.so ~/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib`
22+
23+
Apple support was temporarily reverted, due to downstream breakages. If you want to download autodiff for apple, please look at the artifacts from this [`run`].
24+
25+
## Installation guide for Nix user.
26+
27+
This setup was recommended by a nix and autodiff user. It uses [`Overlay`]. Please verify for yourself if you are comfortable using that repository.
28+
In that case you might use the following nix configuration to get a rustc that supports `std::autodiff`.
29+
```nix
30+
{
31+
enzymeLib = pkgs.fetchzip {
32+
url = "https://ci-artifacts.rust-lang.org/rustc-builds/ec818fda361ca216eb186f5cf45131bd9c776bb4/enzyme-nightly-x86_64-unknown-linux-gnu.tar.xz";
33+
sha256 = "sha256-Rnrop44vzS+qmYNaRoMNNMFyAc3YsMnwdNGYMXpZ5VY=";
34+
};
35+
36+
rustToolchain = pkgs.symlinkJoin {
37+
name = "rust-with-enzyme";
38+
paths = [pkgs.rust-bin.nightly.latest.default];
39+
nativeBuildInputs = [pkgs.makeWrapper];
40+
postBuild = ''
41+
libdir=$out/lib/rustlib/x86_64-unknown-linux-gnu/lib
42+
cp ${enzymeLib}/enzyme-preview/lib/rustlib/x86_64-unknown-linux-gnu/lib/libEnzyme-22.so $libdir/
43+
wrapProgram $out/bin/rustc --add-flags "--sysroot $out"
44+
'';
45+
};
46+
}
47+
```
448

549
## Build instructions
650

@@ -87,3 +131,6 @@ ninja
87131
```
88132
This will build Enzyme, and you can find it in `Enzyme/enzyme/build/lib/<LLD/Clang/LLVM/lib>Enzyme.so`. (Endings might differ based on your OS).
89133

134+
[`Repo`]: https://github.com/rust-lang/rust/
135+
[`run`]: https://github.com/rust-lang/rust/pull/153026#issuecomment-3950046599
136+
[`Overlay`]: https://github.com/oxalica/rust-overlay

0 commit comments

Comments
 (0)