Skip to content

Commit 82224f6

Browse files
committed
Auto merge of #147466 - jdonszelmann:rollup-swfblpr, r=jdonszelmann
Rollup of 5 pull requests Successful merges: - #146385 (rustdoc-search: redesign throbber to be less distracting) - #147390 (Use globals instead of metadata for std::autodiff) - #147445 (sort attribute targets for more consistent error messages) - #147448 (collect-license-metadata: update submodules before running) - #147451 (fix panic with extra-const-ub-checks) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5767910 + cf63f15 commit 82224f6

35 files changed

+294
-269
lines changed

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,20 @@ pub(crate) fn allowed_targets_applied(
198198
filter_targets(&mut allowed_targets, IMPL_LIKE, "impl blocks", target, &mut added_fake_targets);
199199
filter_targets(&mut allowed_targets, ADT_LIKE, "data types", target, &mut added_fake_targets);
200200

201+
let mut target_strings: Vec<_> = added_fake_targets
202+
.iter()
203+
.copied()
204+
.chain(allowed_targets.iter().map(|t| t.plural_name()))
205+
.map(|i| i.to_string())
206+
.collect();
207+
208+
// ensure a consistent order
209+
target_strings.sort();
210+
201211
// If there is now only 1 target left, show that as the only possible target
202-
(
203-
added_fake_targets
204-
.iter()
205-
.copied()
206-
.chain(allowed_targets.iter().map(|t| t.plural_name()))
207-
.map(|i| i.to_string())
208-
.collect(),
209-
allowed_targets.len() + added_fake_targets.len() == 1,
210-
)
212+
let only_target = target_strings.len() == 1;
213+
214+
(target_strings, only_target)
211215
}
212216

213217
fn filter_targets(

compiler/rustc_codegen_llvm/src/builder/autodiff.rs

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use tracing::debug;
1212
use crate::builder::{Builder, PlaceRef, UNNAMED};
1313
use crate::context::SimpleCx;
1414
use crate::declare::declare_simple_fn;
15-
use crate::llvm::{self, Metadata, TRUE, Type, Value};
15+
use crate::llvm::{self, TRUE, Type, Value};
1616

1717
pub(crate) fn adjust_activity_to_abi<'tcx>(
1818
tcx: TyCtxt<'tcx>,
@@ -143,9 +143,9 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>(
143143
cx: &SimpleCx<'ll>,
144144
builder: &mut Builder<'_, 'll, 'tcx>,
145145
width: u32,
146-
args: &mut Vec<&'ll llvm::Value>,
146+
args: &mut Vec<&'ll Value>,
147147
inputs: &[DiffActivity],
148-
outer_args: &[&'ll llvm::Value],
148+
outer_args: &[&'ll Value],
149149
) {
150150
debug!("matching autodiff arguments");
151151
// We now handle the issue that Rust level arguments not always match the llvm-ir level
@@ -157,32 +157,36 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>(
157157
let mut outer_pos: usize = 0;
158158
let mut activity_pos = 0;
159159

160-
let enzyme_const = cx.create_metadata(b"enzyme_const");
161-
let enzyme_out = cx.create_metadata(b"enzyme_out");
162-
let enzyme_dup = cx.create_metadata(b"enzyme_dup");
163-
let enzyme_dupv = cx.create_metadata(b"enzyme_dupv");
164-
let enzyme_dupnoneed = cx.create_metadata(b"enzyme_dupnoneed");
165-
let enzyme_dupnoneedv = cx.create_metadata(b"enzyme_dupnoneedv");
160+
// We used to use llvm's metadata to instruct enzyme how to differentiate a function.
161+
// In debug mode we would use incremental compilation which caused the metadata to be
162+
// dropped. This is prevented by now using named globals, which are also understood
163+
// by Enzyme.
164+
let global_const = cx.declare_global("enzyme_const", cx.type_ptr());
165+
let global_out = cx.declare_global("enzyme_out", cx.type_ptr());
166+
let global_dup = cx.declare_global("enzyme_dup", cx.type_ptr());
167+
let global_dupv = cx.declare_global("enzyme_dupv", cx.type_ptr());
168+
let global_dupnoneed = cx.declare_global("enzyme_dupnoneed", cx.type_ptr());
169+
let global_dupnoneedv = cx.declare_global("enzyme_dupnoneedv", cx.type_ptr());
166170

167171
while activity_pos < inputs.len() {
168172
let diff_activity = inputs[activity_pos as usize];
169173
// Duplicated arguments received a shadow argument, into which enzyme will write the
170174
// gradient.
171-
let (activity, duplicated): (&Metadata, bool) = match diff_activity {
175+
let (activity, duplicated): (&Value, bool) = match diff_activity {
172176
DiffActivity::None => panic!("not a valid input activity"),
173-
DiffActivity::Const => (enzyme_const, false),
174-
DiffActivity::Active => (enzyme_out, false),
175-
DiffActivity::ActiveOnly => (enzyme_out, false),
176-
DiffActivity::Dual => (enzyme_dup, true),
177-
DiffActivity::Dualv => (enzyme_dupv, true),
178-
DiffActivity::DualOnly => (enzyme_dupnoneed, true),
179-
DiffActivity::DualvOnly => (enzyme_dupnoneedv, true),
180-
DiffActivity::Duplicated => (enzyme_dup, true),
181-
DiffActivity::DuplicatedOnly => (enzyme_dupnoneed, true),
182-
DiffActivity::FakeActivitySize(_) => (enzyme_const, false),
177+
DiffActivity::Const => (global_const, false),
178+
DiffActivity::Active => (global_out, false),
179+
DiffActivity::ActiveOnly => (global_out, false),
180+
DiffActivity::Dual => (global_dup, true),
181+
DiffActivity::Dualv => (global_dupv, true),
182+
DiffActivity::DualOnly => (global_dupnoneed, true),
183+
DiffActivity::DualvOnly => (global_dupnoneedv, true),
184+
DiffActivity::Duplicated => (global_dup, true),
185+
DiffActivity::DuplicatedOnly => (global_dupnoneed, true),
186+
DiffActivity::FakeActivitySize(_) => (global_const, false),
183187
};
184188
let outer_arg = outer_args[outer_pos];
185-
args.push(cx.get_metadata_value(activity));
189+
args.push(activity);
186190
if matches!(diff_activity, DiffActivity::Dualv) {
187191
let next_outer_arg = outer_args[outer_pos + 1];
188192
let elem_bytes_size: u64 = match inputs[activity_pos + 1] {
@@ -242,7 +246,7 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>(
242246
assert_eq!(cx.type_kind(next_outer_ty3), TypeKind::Integer);
243247
args.push(next_outer_arg2);
244248
}
245-
args.push(cx.get_metadata_value(enzyme_const));
249+
args.push(global_const);
246250
args.push(next_outer_arg);
247251
outer_pos += 2 + 2 * iterations;
248252
activity_pos += 2;
@@ -351,13 +355,13 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
351355
let mut args = Vec::with_capacity(num_args as usize + 1);
352356
args.push(fn_to_diff);
353357

354-
let enzyme_primal_ret = cx.create_metadata(b"enzyme_primal_return");
358+
let global_primal_ret = cx.declare_global("enzyme_primal_return", cx.type_ptr());
355359
if matches!(attrs.ret_activity, DiffActivity::Dual | DiffActivity::Active) {
356-
args.push(cx.get_metadata_value(enzyme_primal_ret));
360+
args.push(global_primal_ret);
357361
}
358362
if attrs.width > 1 {
359-
let enzyme_width = cx.create_metadata(b"enzyme_width");
360-
args.push(cx.get_metadata_value(enzyme_width));
363+
let global_width = cx.declare_global("enzyme_width", cx.type_ptr());
364+
args.push(global_width);
361365
args.push(cx.get_const_int(cx.type_i64(), attrs.width as u64));
362366
}
363367

compiler/rustc_const_eval/messages.ftl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,10 @@ const_eval_validation_null_box = {$front_matter}: encountered a {$maybe ->
481481
[true] maybe-null
482482
*[false] null
483483
} box
484-
const_eval_validation_null_fn_ptr = {$front_matter}: encountered a null function pointer
484+
const_eval_validation_null_fn_ptr = {$front_matter}: encountered a {$maybe ->
485+
[true] maybe-null
486+
*[false] null
487+
} function pointer
485488
const_eval_validation_null_ref = {$front_matter}: encountered a {$maybe ->
486489
[true] maybe-null
487490
*[false] null

compiler/rustc_const_eval/src/errors.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
666666
PartialPointer => const_eval_validation_partial_pointer,
667667
MutableRefToImmutable => const_eval_validation_mutable_ref_to_immutable,
668668
MutableRefInConst => const_eval_validation_mutable_ref_in_const,
669-
NullFnPtr => const_eval_validation_null_fn_ptr,
669+
NullFnPtr { .. } => const_eval_validation_null_fn_ptr,
670670
NeverVal => const_eval_validation_never_val,
671671
NonnullPtrMaybeNull { .. } => const_eval_validation_nonnull_ptr_out_of_range,
672672
PtrOutOfRange { .. } => const_eval_validation_ptr_out_of_range,
@@ -820,12 +820,11 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
820820
err.arg("vtable_dyn_type", vtable_dyn_type.to_string());
821821
err.arg("expected_dyn_type", expected_dyn_type.to_string());
822822
}
823-
NullPtr { maybe, .. } => {
823+
NullPtr { maybe, .. } | NullFnPtr { maybe } => {
824824
err.arg("maybe", maybe);
825825
}
826826
MutableRefToImmutable
827827
| MutableRefInConst
828-
| NullFnPtr
829828
| NonnullPtrMaybeNull
830829
| NeverVal
831830
| UnsafeCellInImmutable

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -757,14 +757,12 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
757757
);
758758
// FIXME: Check if the signature matches
759759
} else {
760-
// Otherwise (for standalone Miri), we have to still check it to be non-null.
760+
// Otherwise (for standalone Miri and for `-Zextra-const-ub-checks`),
761+
// we have to still check it to be non-null.
761762
if self.ecx.scalar_may_be_null(scalar)? {
762763
let maybe =
763764
!M::Provenance::OFFSET_IS_ADDR && matches!(scalar, Scalar::Ptr(..));
764-
// This can't be a "maybe-null" pointer since the check for this being
765-
// a fn ptr at all already ensures that the pointer is inbounds.
766-
assert!(!maybe);
767-
throw_validation_failure!(self.path, NullFnPtr);
765+
throw_validation_failure!(self.path, NullFnPtr { maybe });
768766
}
769767
}
770768
if self.reset_provenance_and_padding {

compiler/rustc_middle/src/mir/interpret/error.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,10 @@ pub enum ValidationErrorKind<'tcx> {
497497
MutableRefToImmutable,
498498
UnsafeCellInImmutable,
499499
MutableRefInConst,
500-
NullFnPtr,
500+
NullFnPtr {
501+
/// Records whether this pointer is definitely null or just may be null.
502+
maybe: bool,
503+
},
501504
NeverVal,
502505
NonnullPtrMaybeNull,
503506
PtrOutOfRange {

src/bootstrap/src/core/build_steps/run.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use std::path::PathBuf;
77

88
use build_helper::exit;
9+
use build_helper::git::get_git_untracked_files;
910
use clap_complete::{Generator, shells};
1011

1112
use crate::core::build_steps::dist::distdir;
@@ -208,6 +209,16 @@ impl Step for CollectLicenseMetadata {
208209

209210
let dest = builder.src.join("license-metadata.json");
210211

212+
if !builder.config.dry_run() {
213+
builder.require_and_update_all_submodules();
214+
if let Ok(Some(untracked)) = get_git_untracked_files(None) {
215+
eprintln!(
216+
"Warning: {} untracked files may cause the license report to be incorrect.",
217+
untracked.len()
218+
);
219+
}
220+
}
221+
211222
let mut cmd = builder.tool_cmd(Tool::CollectLicenseMetadata);
212223
cmd.env("REUSE_EXE", reuse);
213224
cmd.env("DEST", &dest);

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 13 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,12 +1987,10 @@ a.tooltip:hover::after {
19871987
color: inherit;
19881988
}
19891989
#search-tabs button:not(.selected) {
1990-
--search-tab-button-background: var(--search-tab-button-not-selected-background);
19911990
background-color: var(--search-tab-button-not-selected-background);
19921991
border-top-color: var(--search-tab-button-not-selected-border-top-color);
19931992
}
19941993
#search-tabs button:hover, #search-tabs button.selected {
1995-
--search-tab-button-background: var(--search-tab-button-selected-background);
19961994
background-color: var(--search-tab-button-selected-background);
19971995
border-top-color: var(--search-tab-button-selected-border-top-color);
19981996
}
@@ -2008,66 +2006,27 @@ a.tooltip:hover::after {
20082006
color: transparent;
20092007
}
20102008

2011-
.search-form.loading {
2012-
--search-tab-button-background: var(--button-background-color);
2013-
}
2014-
2015-
#search-tabs .count.loading::before,
2016-
.search-form.loading::before
2017-
{
2018-
width: 16px;
2019-
height: 16px;
2020-
border-radius: 16px;
2021-
background: radial-gradient(
2022-
var(--search-tab-button-background) 0 50%,
2023-
transparent 50% 100%
2024-
), conic-gradient(
2025-
var(--code-highlight-kw-color) 0deg 30deg,
2026-
var(--code-highlight-prelude-color) 30deg 60deg,
2027-
var(--code-highlight-number-color) 90deg 120deg,
2028-
var(--code-highlight-lifetime-color ) 120deg 150deg,
2029-
var(--code-highlight-comment-color) 150deg 180deg,
2030-
var(--code-highlight-self-color) 180deg 210deg,
2031-
var(--code-highlight-attribute-color) 210deg 240deg,
2032-
var(--code-highlight-literal-color) 210deg 240deg,
2033-
var(--code-highlight-macro-color) 240deg 270deg,
2034-
var(--code-highlight-question-mark-color) 270deg 300deg,
2035-
var(--code-highlight-prelude-val-color) 300deg 330deg,
2036-
var(--code-highlight-doc-comment-color) 330deg 360deg
2037-
);
2038-
content: "";
2039-
position: absolute;
2040-
left: 2px;
2041-
top: 2px;
2042-
animation: rotating 1.25s linear infinite;
2043-
}
2044-
#search-tabs .count.loading::after,
20452009
.search-form.loading::after
20462010
{
20472011
width: 18px;
20482012
height: 18px;
20492013
border-radius: 18px;
2050-
background: conic-gradient(
2051-
var(--search-tab-button-background) 0deg 180deg,
2052-
transparent 270deg 360deg
2053-
);
2054-
content: "";
2014+
/* hourglass */
2015+
content: url('data:image/svg+xml,\
2016+
<svg width="16" height="16" viewBox="0 0 8 8" xmlns="http://www.w3.org/2000/svg">\
2017+
<g fill="none">\
2018+
<path d="m3.019 1.496v1.496l0.5878 1.018-0.5751 0.996v1.494" stroke="%233f3f3f"/>\
2019+
<path d="m5.003 1.496v1.496l-0.5878 1.018 0.5751 0.996v1.494" stroke="%233f3f3f"/>\
2020+
<path d="m2.006 1.5h3.978" stroke="%23000"/>\
2021+
<path d="m2.006 6.49h3.993" stroke="%23000"/>\
2022+
</g>\
2023+
<path d="m4.005 5.301-0.3987 0.6905h0.7977z" fill="%237f7f7f"/>\
2024+
<path d="m4.011 3.712-0.3987-0.6905h0.7977z" fill="%237f7f7f"/>\
2025+
</svg>');
20552026
position: absolute;
2056-
left: 1px;
2057-
top: 1px;
2058-
animation: rotating 0.66s linear infinite;
2059-
}
2060-
2061-
.search-form.loading::before {
2062-
left: auto;
2063-
right: 9px;
2064-
top: 8px;
2065-
}
2066-
2067-
.search-form.loading::after {
2068-
left: auto;
20692027
right: 8px;
20702028
top: 8px;
2029+
filter: var(--settings-menu-filter);
20712030
}
20722031

20732032
#search .error code {

src/librustdoc/html/static/js/search.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ignore-tidy-filelength
2-
/* global addClass, getNakedUrl, getVar, nonnull, getSettingValue */
2+
/* global addClass, getNakedUrl, getVar, getSettingValue, hasClass, nonnull */
33
/* global onEachLazy, removeClass, searchState, browserSupportsHistoryApi */
44

55
"use strict";
@@ -4804,6 +4804,15 @@ function printTab(nb) {
48044804
if (nb === iter) {
48054805
addClass(elem, "selected");
48064806
foundCurrentTab = true;
4807+
onEachLazy(document.querySelectorAll(
4808+
".search-form",
4809+
), form => {
4810+
if (hasClass(elem.firstElementChild, "loading")) {
4811+
addClass(form, "loading");
4812+
} else {
4813+
removeClass(form, "loading");
4814+
}
4815+
});
48074816
} else {
48084817
removeClass(elem, "selected");
48094818
}
@@ -5019,7 +5028,9 @@ ${obj.displayPath}<span class="${type}">${name}</span>\
50195028
await Promise.all(descList);
50205029
// need to make sure the element is shown before
50215030
// running this callback
5022-
yieldToBrowser().then(() => finishedCallback(count, output));
5031+
yieldToBrowser().then(() => {
5032+
finishedCallback(count, output);
5033+
});
50235034
}
50245035
});
50255036
};
@@ -5156,6 +5167,7 @@ function makeTab(tabNb, text, results, query, isTypeSearch, goToFirst) {
51565167
count < 100 ? `\u{2007}(${count})\u{2007}` : `\u{2007}(${count})`;
51575168
tabCount.innerHTML = fmtNbElems;
51585169
tabCount.className = "count";
5170+
printTab(window.searchState.currentTab);
51595171
}, isTypeSearch),
51605172
];
51615173
}
@@ -5215,9 +5227,12 @@ async function showResults(docSearch, results, goToFirst, filterCrates) {
52155227
resultsElem.id = "results";
52165228

52175229
search.innerHTML = "";
5218-
for (const [tab, output] of tabs) {
5230+
for (const [tabNb, [tab, output]] of tabs.entries()) {
52195231
tabsElem.appendChild(tab);
5232+
const isCurrentTab = window.searchState.currentTab === tabNb;
52205233
const placeholder = document.createElement("div");
5234+
placeholder.className = isCurrentTab ? "search-results active" : "search-results";
5235+
placeholder.innerHTML = "Loading...";
52215236
output.then(output => {
52225237
if (placeholder.parentElement) {
52235238
placeholder.parentElement.replaceChild(output, placeholder);
@@ -5474,11 +5489,6 @@ if (ROOT_PATH === null) {
54745489
const database = await Stringdex.loadDatabase(hooks);
54755490
if (typeof window !== "undefined") {
54765491
docSearch = new DocSearch(ROOT_PATH, database);
5477-
onEachLazy(document.querySelectorAll(
5478-
".search-form.loading",
5479-
), form => {
5480-
removeClass(form, "loading");
5481-
});
54825492
registerSearchEvents();
54835493
// If there's a search term in the URL, execute the search now.
54845494
if (window.searchState.getQueryStringParams().search !== undefined) {

0 commit comments

Comments
 (0)