Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions compiler/rustc_attr_parsing/src/target_checking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,20 @@ pub(crate) fn allowed_targets_applied(
filter_targets(&mut allowed_targets, IMPL_LIKE, "impl blocks", target, &mut added_fake_targets);
filter_targets(&mut allowed_targets, ADT_LIKE, "data types", target, &mut added_fake_targets);

let mut target_strings: Vec<_> = added_fake_targets
.iter()
.copied()
.chain(allowed_targets.iter().map(|t| t.plural_name()))
.map(|i| i.to_string())
.collect();

// ensure a consistent order
target_strings.sort();

// If there is now only 1 target left, show that as the only possible target
(
added_fake_targets
.iter()
.copied()
.chain(allowed_targets.iter().map(|t| t.plural_name()))
.map(|i| i.to_string())
.collect(),
allowed_targets.len() + added_fake_targets.len() == 1,
)
let only_target = target_strings.len() == 1;

(target_strings, only_target)
}

fn filter_targets(
Expand Down
56 changes: 30 additions & 26 deletions compiler/rustc_codegen_llvm/src/builder/autodiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing::debug;
use crate::builder::{Builder, PlaceRef, UNNAMED};
use crate::context::SimpleCx;
use crate::declare::declare_simple_fn;
use crate::llvm::{self, Metadata, TRUE, Type, Value};
use crate::llvm::{self, TRUE, Type, Value};

pub(crate) fn adjust_activity_to_abi<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -143,9 +143,9 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>(
cx: &SimpleCx<'ll>,
builder: &mut Builder<'_, 'll, 'tcx>,
width: u32,
args: &mut Vec<&'ll llvm::Value>,
args: &mut Vec<&'ll Value>,
inputs: &[DiffActivity],
outer_args: &[&'ll llvm::Value],
outer_args: &[&'ll Value],
) {
debug!("matching autodiff arguments");
// We now handle the issue that Rust level arguments not always match the llvm-ir level
Expand All @@ -157,32 +157,36 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>(
let mut outer_pos: usize = 0;
let mut activity_pos = 0;

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

while activity_pos < inputs.len() {
let diff_activity = inputs[activity_pos as usize];
// Duplicated arguments received a shadow argument, into which enzyme will write the
// gradient.
let (activity, duplicated): (&Metadata, bool) = match diff_activity {
let (activity, duplicated): (&Value, bool) = match diff_activity {
DiffActivity::None => panic!("not a valid input activity"),
DiffActivity::Const => (enzyme_const, false),
DiffActivity::Active => (enzyme_out, false),
DiffActivity::ActiveOnly => (enzyme_out, false),
DiffActivity::Dual => (enzyme_dup, true),
DiffActivity::Dualv => (enzyme_dupv, true),
DiffActivity::DualOnly => (enzyme_dupnoneed, true),
DiffActivity::DualvOnly => (enzyme_dupnoneedv, true),
DiffActivity::Duplicated => (enzyme_dup, true),
DiffActivity::DuplicatedOnly => (enzyme_dupnoneed, true),
DiffActivity::FakeActivitySize(_) => (enzyme_const, false),
DiffActivity::Const => (global_const, false),
DiffActivity::Active => (global_out, false),
DiffActivity::ActiveOnly => (global_out, false),
DiffActivity::Dual => (global_dup, true),
DiffActivity::Dualv => (global_dupv, true),
DiffActivity::DualOnly => (global_dupnoneed, true),
DiffActivity::DualvOnly => (global_dupnoneedv, true),
DiffActivity::Duplicated => (global_dup, true),
DiffActivity::DuplicatedOnly => (global_dupnoneed, true),
DiffActivity::FakeActivitySize(_) => (global_const, false),
};
let outer_arg = outer_args[outer_pos];
args.push(cx.get_metadata_value(activity));
args.push(activity);
if matches!(diff_activity, DiffActivity::Dualv) {
let next_outer_arg = outer_args[outer_pos + 1];
let elem_bytes_size: u64 = match inputs[activity_pos + 1] {
Expand Down Expand Up @@ -242,7 +246,7 @@ fn match_args_from_caller_to_enzyme<'ll, 'tcx>(
assert_eq!(cx.type_kind(next_outer_ty3), TypeKind::Integer);
args.push(next_outer_arg2);
}
args.push(cx.get_metadata_value(enzyme_const));
args.push(global_const);
args.push(next_outer_arg);
outer_pos += 2 + 2 * iterations;
activity_pos += 2;
Expand Down Expand Up @@ -351,13 +355,13 @@ pub(crate) fn generate_enzyme_call<'ll, 'tcx>(
let mut args = Vec::with_capacity(num_args as usize + 1);
args.push(fn_to_diff);

let enzyme_primal_ret = cx.create_metadata(b"enzyme_primal_return");
let global_primal_ret = cx.declare_global("enzyme_primal_return", cx.type_ptr());
if matches!(attrs.ret_activity, DiffActivity::Dual | DiffActivity::Active) {
args.push(cx.get_metadata_value(enzyme_primal_ret));
args.push(global_primal_ret);
}
if attrs.width > 1 {
let enzyme_width = cx.create_metadata(b"enzyme_width");
args.push(cx.get_metadata_value(enzyme_width));
let global_width = cx.declare_global("enzyme_width", cx.type_ptr());
args.push(global_width);
args.push(cx.get_const_int(cx.type_i64(), attrs.width as u64));
}

Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,10 @@ const_eval_validation_null_box = {$front_matter}: encountered a {$maybe ->
[true] maybe-null
*[false] null
} box
const_eval_validation_null_fn_ptr = {$front_matter}: encountered a null function pointer
const_eval_validation_null_fn_ptr = {$front_matter}: encountered a {$maybe ->
[true] maybe-null
*[false] null
} function pointer
const_eval_validation_null_ref = {$front_matter}: encountered a {$maybe ->
[true] maybe-null
*[false] null
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
PartialPointer => const_eval_validation_partial_pointer,
MutableRefToImmutable => const_eval_validation_mutable_ref_to_immutable,
MutableRefInConst => const_eval_validation_mutable_ref_in_const,
NullFnPtr => const_eval_validation_null_fn_ptr,
NullFnPtr { .. } => const_eval_validation_null_fn_ptr,
NeverVal => const_eval_validation_never_val,
NonnullPtrMaybeNull { .. } => const_eval_validation_nonnull_ptr_out_of_range,
PtrOutOfRange { .. } => const_eval_validation_ptr_out_of_range,
Expand Down Expand Up @@ -820,12 +820,11 @@ impl<'tcx> ReportErrorExt for ValidationErrorInfo<'tcx> {
err.arg("vtable_dyn_type", vtable_dyn_type.to_string());
err.arg("expected_dyn_type", expected_dyn_type.to_string());
}
NullPtr { maybe, .. } => {
NullPtr { maybe, .. } | NullFnPtr { maybe } => {
err.arg("maybe", maybe);
}
MutableRefToImmutable
| MutableRefInConst
| NullFnPtr
| NonnullPtrMaybeNull
| NeverVal
| UnsafeCellInImmutable
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,14 +757,12 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
);
// FIXME: Check if the signature matches
} else {
// Otherwise (for standalone Miri), we have to still check it to be non-null.
// Otherwise (for standalone Miri and for `-Zextra-const-ub-checks`),
// we have to still check it to be non-null.
if self.ecx.scalar_may_be_null(scalar)? {
let maybe =
!M::Provenance::OFFSET_IS_ADDR && matches!(scalar, Scalar::Ptr(..));
// This can't be a "maybe-null" pointer since the check for this being
// a fn ptr at all already ensures that the pointer is inbounds.
assert!(!maybe);
throw_validation_failure!(self.path, NullFnPtr);
throw_validation_failure!(self.path, NullFnPtr { maybe });
}
}
if self.reset_provenance_and_padding {
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,10 @@ pub enum ValidationErrorKind<'tcx> {
MutableRefToImmutable,
UnsafeCellInImmutable,
MutableRefInConst,
NullFnPtr,
NullFnPtr {
/// Records whether this pointer is definitely null or just may be null.
maybe: bool,
},
NeverVal,
NonnullPtrMaybeNull,
PtrOutOfRange {
Expand Down
11 changes: 11 additions & 0 deletions src/bootstrap/src/core/build_steps/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use std::path::PathBuf;

use build_helper::exit;
use build_helper::git::get_git_untracked_files;
use clap_complete::{Generator, shells};

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

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

if !builder.config.dry_run() {
builder.require_and_update_all_submodules();
if let Ok(Some(untracked)) = get_git_untracked_files(None) {
eprintln!(
"Warning: {} untracked files may cause the license report to be incorrect.",
untracked.len()
);
}
}

let mut cmd = builder.tool_cmd(Tool::CollectLicenseMetadata);
cmd.env("REUSE_EXE", reuse);
cmd.env("DEST", &dest);
Expand Down
67 changes: 13 additions & 54 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -1987,12 +1987,10 @@ a.tooltip:hover::after {
color: inherit;
}
#search-tabs button:not(.selected) {
--search-tab-button-background: var(--search-tab-button-not-selected-background);
background-color: var(--search-tab-button-not-selected-background);
border-top-color: var(--search-tab-button-not-selected-border-top-color);
}
#search-tabs button:hover, #search-tabs button.selected {
--search-tab-button-background: var(--search-tab-button-selected-background);
background-color: var(--search-tab-button-selected-background);
border-top-color: var(--search-tab-button-selected-border-top-color);
}
Expand All @@ -2008,66 +2006,27 @@ a.tooltip:hover::after {
color: transparent;
}

.search-form.loading {
--search-tab-button-background: var(--button-background-color);
}

#search-tabs .count.loading::before,
.search-form.loading::before
{
width: 16px;
height: 16px;
border-radius: 16px;
background: radial-gradient(
var(--search-tab-button-background) 0 50%,
transparent 50% 100%
), conic-gradient(
var(--code-highlight-kw-color) 0deg 30deg,
var(--code-highlight-prelude-color) 30deg 60deg,
var(--code-highlight-number-color) 90deg 120deg,
var(--code-highlight-lifetime-color ) 120deg 150deg,
var(--code-highlight-comment-color) 150deg 180deg,
var(--code-highlight-self-color) 180deg 210deg,
var(--code-highlight-attribute-color) 210deg 240deg,
var(--code-highlight-literal-color) 210deg 240deg,
var(--code-highlight-macro-color) 240deg 270deg,
var(--code-highlight-question-mark-color) 270deg 300deg,
var(--code-highlight-prelude-val-color) 300deg 330deg,
var(--code-highlight-doc-comment-color) 330deg 360deg
);
content: "";
position: absolute;
left: 2px;
top: 2px;
animation: rotating 1.25s linear infinite;
}
#search-tabs .count.loading::after,
.search-form.loading::after
{
width: 18px;
height: 18px;
border-radius: 18px;
background: conic-gradient(
var(--search-tab-button-background) 0deg 180deg,
transparent 270deg 360deg
);
content: "";
/* hourglass */
content: url('data:image/svg+xml,\
<svg width="16" height="16" viewBox="0 0 8 8" xmlns="http://www.w3.org/2000/svg">\
<g fill="none">\
<path d="m3.019 1.496v1.496l0.5878 1.018-0.5751 0.996v1.494" stroke="%233f3f3f"/>\
<path d="m5.003 1.496v1.496l-0.5878 1.018 0.5751 0.996v1.494" stroke="%233f3f3f"/>\
<path d="m2.006 1.5h3.978" stroke="%23000"/>\
<path d="m2.006 6.49h3.993" stroke="%23000"/>\
</g>\
<path d="m4.005 5.301-0.3987 0.6905h0.7977z" fill="%237f7f7f"/>\
<path d="m4.011 3.712-0.3987-0.6905h0.7977z" fill="%237f7f7f"/>\
</svg>');
position: absolute;
left: 1px;
top: 1px;
animation: rotating 0.66s linear infinite;
}

.search-form.loading::before {
left: auto;
right: 9px;
top: 8px;
}

.search-form.loading::after {
left: auto;
right: 8px;
top: 8px;
filter: var(--settings-menu-filter);
}

#search .error code {
Expand Down
26 changes: 18 additions & 8 deletions src/librustdoc/html/static/js/search.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ignore-tidy-filelength
/* global addClass, getNakedUrl, getVar, nonnull, getSettingValue */
/* global addClass, getNakedUrl, getVar, getSettingValue, hasClass, nonnull */
/* global onEachLazy, removeClass, searchState, browserSupportsHistoryApi */

"use strict";
Expand Down Expand Up @@ -4804,6 +4804,15 @@ function printTab(nb) {
if (nb === iter) {
addClass(elem, "selected");
foundCurrentTab = true;
onEachLazy(document.querySelectorAll(
".search-form",
), form => {
if (hasClass(elem.firstElementChild, "loading")) {
addClass(form, "loading");
} else {
removeClass(form, "loading");
}
});
} else {
removeClass(elem, "selected");
}
Expand Down Expand Up @@ -5019,7 +5028,9 @@ ${obj.displayPath}<span class="${type}">${name}</span>\
await Promise.all(descList);
// need to make sure the element is shown before
// running this callback
yieldToBrowser().then(() => finishedCallback(count, output));
yieldToBrowser().then(() => {
finishedCallback(count, output);
});
}
});
};
Expand Down Expand Up @@ -5156,6 +5167,7 @@ function makeTab(tabNb, text, results, query, isTypeSearch, goToFirst) {
count < 100 ? `\u{2007}(${count})\u{2007}` : `\u{2007}(${count})`;
tabCount.innerHTML = fmtNbElems;
tabCount.className = "count";
printTab(window.searchState.currentTab);
}, isTypeSearch),
];
}
Expand Down Expand Up @@ -5215,9 +5227,12 @@ async function showResults(docSearch, results, goToFirst, filterCrates) {
resultsElem.id = "results";

search.innerHTML = "";
for (const [tab, output] of tabs) {
for (const [tabNb, [tab, output]] of tabs.entries()) {
tabsElem.appendChild(tab);
const isCurrentTab = window.searchState.currentTab === tabNb;
const placeholder = document.createElement("div");
placeholder.className = isCurrentTab ? "search-results active" : "search-results";
placeholder.innerHTML = "Loading...";
output.then(output => {
if (placeholder.parentElement) {
placeholder.parentElement.replaceChild(output, placeholder);
Expand Down Expand Up @@ -5474,11 +5489,6 @@ if (ROOT_PATH === null) {
const database = await Stringdex.loadDatabase(hooks);
if (typeof window !== "undefined") {
docSearch = new DocSearch(ROOT_PATH, database);
onEachLazy(document.querySelectorAll(
".search-form.loading",
), form => {
removeClass(form, "loading");
});
registerSearchEvents();
// If there's a search term in the URL, execute the search now.
if (window.searchState.getQueryStringParams().search !== undefined) {
Expand Down
Loading
Loading