Skip to content

Commit e643f59

Browse files
committed
Auto merge of rust-lang#139482 - Zalathar:rollup-h2ht1y6, r=Zalathar
Rollup of 9 pull requests Successful merges: - rust-lang#139035 (Add new `PatKind::Missing` variants) - rust-lang#139108 (Simplify `thir::PatKind::ExpandedConstant`) - rust-lang#139112 (Implement `super let`) - rust-lang#139365 (Default auto traits: fix perf) - rust-lang#139397 (coverage: Build the CGU's global file table as late as possible) - rust-lang#139455 ( Remove support for `extern "rust-intrinsic"` blocks) - rust-lang#139461 (Stop calling `source_span` query in significant drop order code) - rust-lang#139465 (add sret handling for scalar autodiff) - rust-lang#139466 (Trivial tweaks to stop tracking source span directly) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8fb32ab + 6e0b674 commit e643f59

File tree

166 files changed

+1799
-1645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+1799
-1645
lines changed

Diff for: compiler/rustc_abi/src/extern_abi.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ pub enum ExternAbi {
6060
System {
6161
unwind: bool,
6262
},
63-
RustIntrinsic,
6463
RustCall,
6564
/// *Not* a stable ABI, just directly use the Rust types to describe the ABI for LLVM. Even
6665
/// normally ABI-compatible Rust types can become ABI-incompatible with this ABI!
@@ -128,7 +127,6 @@ abi_impls! {
128127
RiscvInterruptS =><= "riscv-interrupt-s",
129128
RustCall =><= "rust-call",
130129
RustCold =><= "rust-cold",
131-
RustIntrinsic =><= "rust-intrinsic",
132130
Stdcall { unwind: false } =><= "stdcall",
133131
Stdcall { unwind: true } =><= "stdcall-unwind",
134132
System { unwind: false } =><= "system",
@@ -199,7 +197,7 @@ impl ExternAbi {
199197
/// - are subject to change between compiler versions
200198
pub fn is_rustic_abi(self) -> bool {
201199
use ExternAbi::*;
202-
matches!(self, Rust | RustCall | RustIntrinsic | RustCold)
200+
matches!(self, Rust | RustCall | RustCold)
203201
}
204202

205203
pub fn supports_varargs(self) -> bool {

Diff for: compiler/rustc_ast/src/ast.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,7 @@ impl Pat {
563563
/// This is intended for use by diagnostics.
564564
pub fn to_ty(&self) -> Option<P<Ty>> {
565565
let kind = match &self.kind {
566+
PatKind::Missing => unreachable!(),
566567
// In a type expression `_` is an inference variable.
567568
PatKind::Wild => TyKind::Infer,
568569
// An IDENT pattern with no binding mode would be valid as path to a type. E.g. `u32`.
@@ -625,7 +626,8 @@ impl Pat {
625626
| PatKind::Guard(s, _) => s.walk(it),
626627

627628
// These patterns do not contain subpatterns, skip.
628-
PatKind::Wild
629+
PatKind::Missing
630+
| PatKind::Wild
629631
| PatKind::Rest
630632
| PatKind::Never
631633
| PatKind::Expr(_)
@@ -676,6 +678,7 @@ impl Pat {
676678
/// Return a name suitable for diagnostics.
677679
pub fn descr(&self) -> Option<String> {
678680
match &self.kind {
681+
PatKind::Missing => unreachable!(),
679682
PatKind::Wild => Some("_".to_string()),
680683
PatKind::Ident(BindingMode::NONE, ident, None) => Some(format!("{ident}")),
681684
PatKind::Ref(pat, mutbl) => pat.descr().map(|d| format!("&{}{d}", mutbl.prefix_str())),
@@ -769,6 +772,9 @@ pub enum RangeSyntax {
769772
// Adding a new variant? Please update `test_pat` in `tests/ui/macros/stringify.rs`.
770773
#[derive(Clone, Encodable, Decodable, Debug)]
771774
pub enum PatKind {
775+
/// A missing pattern, e.g. for an anonymous param in a bare fn like `fn f(u32)`.
776+
Missing,
777+
772778
/// Represents a wildcard pattern (`_`).
773779
Wild,
774780

@@ -1169,6 +1175,7 @@ pub enum MacStmtStyle {
11691175
#[derive(Clone, Encodable, Decodable, Debug)]
11701176
pub struct Local {
11711177
pub id: NodeId,
1178+
pub super_: Option<Span>,
11721179
pub pat: P<Pat>,
11731180
pub ty: Option<P<Ty>>,
11741181
pub kind: LocalKind,
@@ -3926,7 +3933,7 @@ mod size_asserts {
39263933
static_assert_size!(Item, 144);
39273934
static_assert_size!(ItemKind, 80);
39283935
static_assert_size!(LitKind, 24);
3929-
static_assert_size!(Local, 80);
3936+
static_assert_size!(Local, 96);
39303937
static_assert_size!(MetaItemLit, 40);
39313938
static_assert_size!(Param, 40);
39323939
static_assert_size!(Pat, 72);

Diff for: compiler/rustc_ast/src/expand/autodiff_attrs.rs

+6
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ pub struct AutoDiffAttrs {
9292
pub input_activity: Vec<DiffActivity>,
9393
}
9494

95+
impl AutoDiffAttrs {
96+
pub fn has_primal_ret(&self) -> bool {
97+
matches!(self.ret_activity, DiffActivity::Active | DiffActivity::Dual)
98+
}
99+
}
100+
95101
impl DiffMode {
96102
pub fn is_rev(&self) -> bool {
97103
matches!(self, DiffMode::Reverse)

Diff for: compiler/rustc_ast/src/mut_visit.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,8 @@ fn walk_parenthesized_parameter_data<T: MutVisitor>(vis: &mut T, args: &mut Pare
704704
}
705705

706706
fn walk_local<T: MutVisitor>(vis: &mut T, local: &mut P<Local>) {
707-
let Local { id, pat, ty, kind, span, colon_sp, attrs, tokens } = local.deref_mut();
707+
let Local { id, super_, pat, ty, kind, span, colon_sp, attrs, tokens } = local.deref_mut();
708+
visit_opt(super_, |sp| vis.visit_span(sp));
708709
vis.visit_id(id);
709710
visit_attrs(vis, attrs);
710711
vis.visit_pat(pat);
@@ -1587,7 +1588,7 @@ pub fn walk_pat<T: MutVisitor>(vis: &mut T, pat: &mut P<Pat>) {
15871588
vis.visit_id(id);
15881589
match kind {
15891590
PatKind::Err(_guar) => {}
1590-
PatKind::Wild | PatKind::Rest | PatKind::Never => {}
1591+
PatKind::Missing | PatKind::Wild | PatKind::Rest | PatKind::Never => {}
15911592
PatKind::Ident(_binding_mode, ident, sub) => {
15921593
vis.visit_ident(ident);
15931594
visit_opt(sub, |sub| vis.visit_pat(sub));

Diff for: compiler/rustc_ast/src/visit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub fn walk_crate<'a, V: Visitor<'a>>(visitor: &mut V, krate: &'a Crate) -> V::R
323323
}
324324

325325
pub fn walk_local<'a, V: Visitor<'a>>(visitor: &mut V, local: &'a Local) -> V::Result {
326-
let Local { id: _, pat, ty, kind, span: _, colon_sp: _, attrs, tokens: _ } = local;
326+
let Local { id: _, super_: _, pat, ty, kind, span: _, colon_sp: _, attrs, tokens: _ } = local;
327327
walk_list!(visitor, visit_attribute, attrs);
328328
try_visit!(visitor.visit_pat(pat));
329329
visit_opt!(visitor, visit_ty, ty);
@@ -750,7 +750,7 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res
750750
try_visit!(visitor.visit_pat(subpattern));
751751
try_visit!(visitor.visit_expr(guard_condition));
752752
}
753-
PatKind::Wild | PatKind::Rest | PatKind::Never => {}
753+
PatKind::Missing | PatKind::Wild | PatKind::Rest | PatKind::Never => {}
754754
PatKind::Err(_guar) => {}
755755
PatKind::Tuple(elems) | PatKind::Slice(elems) | PatKind::Or(elems) => {
756756
walk_list!(visitor, visit_pat, elems);

Diff for: compiler/rustc_ast_lowering/src/block.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
9595

9696
fn lower_local(&mut self, l: &Local) -> &'hir hir::LetStmt<'hir> {
9797
// Let statements are allowed to have impl trait in bindings.
98+
let super_ = l.super_;
9899
let ty = l.ty.as_ref().map(|t| {
99100
self.lower_ty(t, self.impl_trait_in_bindings_ctxt(ImplTraitPosition::Variable))
100101
});
@@ -109,7 +110,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
109110
let span = self.lower_span(l.span);
110111
let source = hir::LocalSource::Normal;
111112
self.lower_attrs(hir_id, &l.attrs, l.span);
112-
self.arena.alloc(hir::LetStmt { hir_id, ty, pat, init, els, span, source })
113+
self.arena.alloc(hir::LetStmt { hir_id, super_, ty, pat, init, els, span, source })
113114
}
114115

115116
fn lower_block_check_mode(&mut self, b: &BlockCheckMode) -> hir::BlockCheckMode {

Diff for: compiler/rustc_ast_lowering/src/lib.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1496,18 +1496,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
14961496

14971497
fn lower_fn_params_to_names(&mut self, decl: &FnDecl) -> &'hir [Option<Ident>] {
14981498
self.arena.alloc_from_iter(decl.inputs.iter().map(|param| match param.pat.kind {
1499-
PatKind::Ident(_, ident, _) => {
1500-
if ident.name != kw::Empty {
1501-
Some(self.lower_ident(ident))
1502-
} else {
1503-
None
1504-
}
1505-
}
1499+
PatKind::Missing => None,
1500+
PatKind::Ident(_, ident, _) => Some(self.lower_ident(ident)),
15061501
PatKind::Wild => Some(Ident::new(kw::Underscore, self.lower_span(param.pat.span))),
15071502
_ => {
15081503
self.dcx().span_delayed_bug(
15091504
param.pat.span,
1510-
"non-ident/wild param pat must trigger an error",
1505+
"non-missing/ident/wild param pat must trigger an error",
15111506
);
15121507
None
15131508
}
@@ -2223,6 +2218,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22232218
self.attrs.insert(hir_id.local_id, a);
22242219
}
22252220
let local = hir::LetStmt {
2221+
super_: None,
22262222
hir_id,
22272223
init,
22282224
pat,

Diff for: compiler/rustc_ast_lowering/src/pat.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2626
let pat_hir_id = self.lower_node_id(pattern.id);
2727
let node = loop {
2828
match &pattern.kind {
29+
PatKind::Missing => break hir::PatKind::Missing,
2930
PatKind::Wild => break hir::PatKind::Wild,
3031
PatKind::Never => break hir::PatKind::Never,
3132
PatKind::Ident(binding_mode, ident, sub) => {

Diff for: compiler/rustc_ast_lowering/src/stability.rs

-4
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,6 @@ pub fn extern_abi_stability(abi: ExternAbi) -> Result<(), UnstableAbi> {
7979
| ExternAbi::SysV64 { .. }
8080
| ExternAbi::System { .. }
8181
| ExternAbi::EfiApi => Ok(()),
82-
// implementation details
83-
ExternAbi::RustIntrinsic => {
84-
Err(UnstableAbi { abi, feature: sym::intrinsics, explain: GateReason::ImplDetail })
85-
}
8682
ExternAbi::Unadjusted => {
8783
Err(UnstableAbi { abi, feature: sym::abi_unadjusted, explain: GateReason::ImplDetail })
8884
}

Diff for: compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'a> AstValidator<'a> {
244244
fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) {
245245
for Param { pat, .. } in &decl.inputs {
246246
match pat.kind {
247-
PatKind::Ident(BindingMode::NONE, _, None) | PatKind::Wild => {}
247+
PatKind::Missing | PatKind::Ident(BindingMode::NONE, _, None) | PatKind::Wild => {}
248248
PatKind::Ident(BindingMode::MUT, ident, None) => {
249249
report_err(pat.span, Some(ident), true)
250250
}

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,9 @@ impl<'a> State<'a> {
13361336
self.print_outer_attributes(&loc.attrs);
13371337
self.space_if_not_bol();
13381338
self.ibox(INDENT_UNIT);
1339+
if loc.super_.is_some() {
1340+
self.word_nbsp("super");
1341+
}
13391342
self.word_nbsp("let");
13401343

13411344
self.ibox(INDENT_UNIT);
@@ -1622,9 +1625,9 @@ impl<'a> State<'a> {
16221625
fn print_pat(&mut self, pat: &ast::Pat) {
16231626
self.maybe_print_comment(pat.span.lo());
16241627
self.ann.pre(self, AnnNode::Pat(pat));
1625-
/* Pat isn't normalized, but the beauty of it
1626-
is that it doesn't matter */
1628+
/* Pat isn't normalized, but the beauty of it is that it doesn't matter */
16271629
match &pat.kind {
1630+
PatKind::Missing => unreachable!(),
16281631
PatKind::Wild => self.word("_"),
16291632
PatKind::Never => self.word("!"),
16301633
PatKind::Ident(BindingMode(by_ref, mutbl), ident, sub) => {
@@ -1946,12 +1949,7 @@ impl<'a> State<'a> {
19461949
if let Some(eself) = input.to_self() {
19471950
self.print_explicit_self(&eself);
19481951
} else {
1949-
let invalid = if let PatKind::Ident(_, ident, _) = input.pat.kind {
1950-
ident.name == kw::Empty
1951-
} else {
1952-
false
1953-
};
1954-
if !invalid {
1952+
if !matches!(input.pat.kind, PatKind::Missing) {
19551953
self.print_pat(&input.pat);
19561954
self.word(":");
19571955
self.space();

Diff for: compiler/rustc_borrowck/src/region_infer/mod.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex,
2222
use rustc_mir_dataflow::points::DenseLocationMap;
2323
use rustc_span::hygiene::DesugaringKind;
2424
use rustc_span::{DUMMY_SP, Span};
25-
use tracing::{debug, instrument, trace};
25+
use tracing::{Level, debug, enabled, instrument, trace};
2626

2727
use crate::BorrowckInferCtxt;
2828
use crate::constraints::graph::{self, NormalConstraintGraph, RegionGraph};
@@ -327,11 +327,13 @@ fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
327327
let mut var_to_origin_sorted = var_to_origin.clone().into_iter().collect::<Vec<_>>();
328328
var_to_origin_sorted.sort_by_key(|vto| vto.0);
329329

330-
let mut reg_vars_to_origins_str = "region variables to origins:\n".to_string();
331-
for (reg_var, origin) in var_to_origin_sorted.into_iter() {
332-
reg_vars_to_origins_str.push_str(&format!("{reg_var:?}: {origin:?}\n"));
330+
if enabled!(Level::DEBUG) {
331+
let mut reg_vars_to_origins_str = "region variables to origins:\n".to_string();
332+
for (reg_var, origin) in var_to_origin_sorted.into_iter() {
333+
reg_vars_to_origins_str.push_str(&format!("{reg_var:?}: {origin:?}\n"));
334+
}
335+
debug!("{}", reg_vars_to_origins_str);
333336
}
334-
debug!("{}", reg_vars_to_origins_str);
335337

336338
let num_components = sccs.num_sccs();
337339
let mut components = vec![FxIndexSet::default(); num_components];
@@ -342,16 +344,18 @@ fn sccs_info<'tcx>(infcx: &BorrowckInferCtxt<'tcx>, sccs: &ConstraintSccs) {
342344
components[scc_idx.as_usize()].insert((reg_var, *origin));
343345
}
344346

345-
let mut components_str = "strongly connected components:".to_string();
346-
for (scc_idx, reg_vars_origins) in components.iter().enumerate() {
347-
let regions_info = reg_vars_origins.clone().into_iter().collect::<Vec<_>>();
348-
components_str.push_str(&format!(
349-
"{:?}: {:?},\n)",
350-
ConstraintSccIndex::from_usize(scc_idx),
351-
regions_info,
352-
))
347+
if enabled!(Level::DEBUG) {
348+
let mut components_str = "strongly connected components:".to_string();
349+
for (scc_idx, reg_vars_origins) in components.iter().enumerate() {
350+
let regions_info = reg_vars_origins.clone().into_iter().collect::<Vec<_>>();
351+
components_str.push_str(&format!(
352+
"{:?}: {:?},\n)",
353+
ConstraintSccIndex::from_usize(scc_idx),
354+
regions_info,
355+
))
356+
}
357+
debug!("{}", components_str);
353358
}
354-
debug!("{}", components_str);
355359

356360
// calculate the best representative for each component
357361
let components_representatives = components

Diff for: compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//! Codegen of intrinsics. This includes `extern "rust-intrinsic"`,
2-
//! functions marked with the `#[rustc_intrinsic]` attribute
1+
//! Codegen of intrinsics. This includes functions marked with the `#[rustc_intrinsic]` attribute
32
//! and LLVM intrinsics that have symbol names starting with `llvm.`.
43
54
macro_rules! intrinsic_args {

Diff for: compiler/rustc_codegen_llvm/src/builder/autodiff.rs

+22-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,23 @@ fn compute_enzyme_fn_ty<'ll>(
201201
}
202202

203203
if attrs.width == 1 {
204-
todo!("Handle sret for scalar ad");
204+
// Enzyme returns a struct of style:
205+
// `{ original_ret(if requested), float, float, ... }`
206+
let mut struct_elements = vec![];
207+
if attrs.has_primal_ret() {
208+
struct_elements.push(inner_ret_ty);
209+
}
210+
// Next, we push the list of active floats, since they will be lowered to `enzyme_out`,
211+
// and therefore part of the return struct.
212+
let param_tys = cx.func_params_types(fn_ty);
213+
for (act, param_ty) in attrs.input_activity.iter().zip(param_tys) {
214+
if matches!(act, DiffActivity::Active) {
215+
// Now find the float type at position i based on the fn_ty,
216+
// to know what (f16/f32/f64/...) to add to the struct.
217+
struct_elements.push(param_ty);
218+
}
219+
}
220+
ret_ty = cx.type_struct(&struct_elements, false);
205221
} else {
206222
// First we check if we also have to deal with the primal return.
207223
match attrs.mode {
@@ -388,7 +404,11 @@ fn generate_enzyme_call<'ll>(
388404
// now store the result of the enzyme call into the sret pointer.
389405
let sret_ptr = outer_args[0];
390406
let call_ty = cx.val_ty(call);
391-
assert_eq!(cx.type_kind(call_ty), TypeKind::Array);
407+
if attrs.width == 1 {
408+
assert_eq!(cx.type_kind(call_ty), TypeKind::Struct);
409+
} else {
410+
assert_eq!(cx.type_kind(call_ty), TypeKind::Array);
411+
}
392412
llvm::LLVMBuildStore(&builder.llbuilder, call, sret_ptr);
393413
}
394414
builder.ret_void();

0 commit comments

Comments
 (0)