Skip to content

Commit e5162c9

Browse files
Auto merge of #150944 - Zalathar:revert, r=<try>
[EXPERIMENT] Revert things to investigate long job times try-job: x86_64-gnu-aux
2 parents f57eac1 + aa9709a commit e5162c9

26 files changed

Lines changed: 129 additions & 702 deletions

File tree

compiler/rustc_ast/src/ast.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,9 +2117,10 @@ pub struct MacroDef {
21172117

21182118
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic, Walkable)]
21192119
pub struct EiiExternTarget {
2120-
/// path to the extern item we're targeting
2120+
/// path to the extern item we're targetting
21212121
pub extern_item_path: Path,
21222122
pub impl_unsafe: bool,
2123+
pub span: Span,
21232124
}
21242125

21252126
#[derive(Clone, Encodable, Decodable, Debug, Copy, Hash, Eq, PartialEq)]
@@ -3812,19 +3813,6 @@ pub struct Fn {
38123813
pub struct EiiImpl {
38133814
pub node_id: NodeId,
38143815
pub eii_macro_path: Path,
3815-
/// This field is an implementation detail that prevents a lot of bugs.
3816-
/// See <https://github.com/rust-lang/rust/issues/149981> for an example.
3817-
///
3818-
/// The problem is, that if we generate a declaration *together* with its default,
3819-
/// we generate both a declaration and an implementation. The generated implementation
3820-
/// uses the same mechanism to register itself as a user-defined implementation would,
3821-
/// despite being invisible to users. What does happen is a name resolution step.
3822-
/// The invisible default implementation has to find the declaration.
3823-
/// Both are generated at the same time, so we can skip that name resolution step.
3824-
///
3825-
/// This field is that shortcut: we prefill the extern target to skip a name resolution step,
3826-
/// making sure it never fails. It'd be awful UX if we fail name resolution in code invisible to the user.
3827-
pub known_eii_macro_resolution: Option<EiiExternTarget>,
38283816
pub impl_safety: Safety,
38293817
pub span: Span,
38303818
pub inner_span: Span,

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 41 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_abi::ExternAbi;
22
use rustc_ast::visit::AssocCtxt;
33
use rustc_ast::*;
44
use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
5-
use rustc_hir::attrs::{AttributeKind, EiiDecl, EiiImplResolution};
5+
use rustc_hir::attrs::{AttributeKind, EiiDecl};
66
use rustc_hir::def::{DefKind, PerNS, Res};
77
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
88
use rustc_hir::{
@@ -134,56 +134,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
134134
}
135135
}
136136

137-
fn lower_eii_extern_target(
138-
&mut self,
139-
id: NodeId,
140-
eii_name: Ident,
141-
EiiExternTarget { extern_item_path, impl_unsafe }: &EiiExternTarget,
142-
) -> Option<EiiDecl> {
143-
self.lower_path_simple_eii(id, extern_item_path).map(|did| EiiDecl {
144-
eii_extern_target: did,
145-
impl_unsafe: *impl_unsafe,
146-
name: eii_name,
147-
})
148-
}
149-
150-
fn lower_eii_impl(
151-
&mut self,
152-
EiiImpl {
153-
node_id,
154-
eii_macro_path,
155-
impl_safety,
156-
span,
157-
inner_span,
158-
is_default,
159-
known_eii_macro_resolution,
160-
}: &EiiImpl,
161-
) -> hir::attrs::EiiImpl {
162-
let resolution = if let Some(target) = known_eii_macro_resolution
163-
&& let Some(decl) = self.lower_eii_extern_target(
164-
*node_id,
165-
// the expect is ok here since we always generate this path in the eii macro.
166-
eii_macro_path.segments.last().expect("at least one segment").ident,
167-
target,
168-
) {
169-
EiiImplResolution::Known(decl)
170-
} else if let Some(macro_did) = self.lower_path_simple_eii(*node_id, eii_macro_path) {
171-
EiiImplResolution::Macro(macro_did)
172-
} else {
173-
EiiImplResolution::Error(
174-
self.dcx().span_delayed_bug(*span, "eii never resolved without errors given"),
175-
)
176-
};
177-
178-
hir::attrs::EiiImpl {
179-
span: self.lower_span(*span),
180-
inner_span: self.lower_span(*inner_span),
181-
impl_marked_unsafe: self.lower_safety(*impl_safety, hir::Safety::Safe).is_unsafe(),
182-
is_default: *is_default,
183-
resolution,
184-
}
185-
}
186-
187137
fn generate_extra_attrs_for_item_kind(
188138
&mut self,
189139
id: NodeId,
@@ -193,14 +143,49 @@ impl<'hir> LoweringContext<'_, 'hir> {
193143
ItemKind::Fn(box Fn { eii_impls, .. }) if eii_impls.is_empty() => Vec::new(),
194144
ItemKind::Fn(box Fn { eii_impls, .. }) => {
195145
vec![hir::Attribute::Parsed(AttributeKind::EiiImpls(
196-
eii_impls.iter().map(|i| self.lower_eii_impl(i)).collect(),
146+
eii_impls
147+
.iter()
148+
.flat_map(
149+
|EiiImpl {
150+
node_id,
151+
eii_macro_path,
152+
impl_safety,
153+
span,
154+
inner_span,
155+
is_default,
156+
}| {
157+
self.lower_path_simple_eii(*node_id, eii_macro_path).map(|did| {
158+
hir::attrs::EiiImpl {
159+
eii_macro: did,
160+
span: self.lower_span(*span),
161+
inner_span: self.lower_span(*inner_span),
162+
impl_marked_unsafe: self
163+
.lower_safety(*impl_safety, hir::Safety::Safe)
164+
.is_unsafe(),
165+
is_default: *is_default,
166+
}
167+
})
168+
},
169+
)
170+
.collect(),
197171
))]
198172
}
199-
ItemKind::MacroDef(name, MacroDef { eii_extern_target: Some(target), .. }) => self
200-
.lower_eii_extern_target(id, *name, target)
201-
.map(|decl| vec![hir::Attribute::Parsed(AttributeKind::EiiExternTarget(decl))])
173+
ItemKind::MacroDef(
174+
_,
175+
MacroDef {
176+
eii_extern_target: Some(EiiExternTarget { extern_item_path, impl_unsafe, span }),
177+
..
178+
},
179+
) => self
180+
.lower_path_simple_eii(id, extern_item_path)
181+
.map(|did| {
182+
vec![hir::Attribute::Parsed(AttributeKind::EiiExternTarget(EiiDecl {
183+
eii_extern_target: did,
184+
impl_unsafe: *impl_unsafe,
185+
span: self.lower_span(*span),
186+
}))]
187+
})
202188
.unwrap_or_default(),
203-
204189
ItemKind::ExternCrate(..)
205190
| ItemKind::Use(..)
206191
| ItemKind::Static(..)

compiler/rustc_builtin_macros/src/eii.rs

Lines changed: 10 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -103,19 +103,19 @@ fn eii_(
103103

104104
// span of the declaring item without attributes
105105
let item_span = func.sig.span;
106+
// span of the eii attribute and the item below it, i.e. the full declaration
107+
let decl_span = eii_attr_span.to(item_span);
106108
let foreign_item_name = func.ident;
107109

108110
let mut return_items = Vec::new();
109111

110112
if func.body.is_some() {
111113
return_items.push(Box::new(generate_default_impl(
112-
ecx,
113114
&func,
114115
impl_unsafe,
115116
macro_name,
116117
eii_attr_span,
117118
item_span,
118-
foreign_item_name,
119119
)))
120120
}
121121

@@ -133,6 +133,7 @@ fn eii_(
133133
macro_name,
134134
foreign_item_name,
135135
impl_unsafe,
136+
decl_span,
136137
)));
137138

138139
return_items.into_iter().map(wrap_item).collect()
@@ -186,13 +187,11 @@ fn filter_attrs_for_multiple_eii_attr(
186187
}
187188

188189
fn generate_default_impl(
189-
ecx: &mut ExtCtxt<'_>,
190190
func: &ast::Fn,
191191
impl_unsafe: bool,
192192
macro_name: Ident,
193193
eii_attr_span: Span,
194194
item_span: Span,
195-
foreign_item_name: Ident,
196195
) -> ast::Item {
197196
// FIXME: re-add some original attrs
198197
let attrs = ThinVec::new();
@@ -209,21 +208,6 @@ fn generate_default_impl(
209208
},
210209
span: eii_attr_span,
211210
is_default: true,
212-
known_eii_macro_resolution: Some(ast::EiiExternTarget {
213-
extern_item_path: ast::Path {
214-
span: foreign_item_name.span,
215-
segments: thin_vec![
216-
ast::PathSegment {
217-
ident: Ident::from_str_and_span("super", foreign_item_name.span,),
218-
id: DUMMY_NODE_ID,
219-
args: None
220-
},
221-
ast::PathSegment { ident: foreign_item_name, id: DUMMY_NODE_ID, args: None },
222-
],
223-
tokens: None,
224-
},
225-
impl_unsafe,
226-
}),
227211
});
228212

229213
ast::Item {
@@ -252,66 +236,18 @@ fn generate_default_impl(
252236
stmts: thin_vec![ast::Stmt {
253237
id: DUMMY_NODE_ID,
254238
kind: ast::StmtKind::Item(Box::new(ast::Item {
255-
attrs: ThinVec::new(),
239+
attrs,
256240
id: DUMMY_NODE_ID,
257241
span: item_span,
258242
vis: ast::Visibility {
259-
span: item_span,
243+
span: eii_attr_span,
260244
kind: ast::VisibilityKind::Inherited,
261245
tokens: None
262246
},
263-
kind: ItemKind::Mod(
264-
ast::Safety::Default,
265-
Ident::from_str_and_span("dflt", item_span),
266-
ast::ModKind::Loaded(
267-
thin_vec![
268-
Box::new(ast::Item {
269-
attrs: thin_vec![ecx.attr_nested_word(
270-
sym::allow,
271-
sym::unused_imports,
272-
item_span
273-
),],
274-
id: DUMMY_NODE_ID,
275-
span: item_span,
276-
vis: ast::Visibility {
277-
span: eii_attr_span,
278-
kind: ast::VisibilityKind::Inherited,
279-
tokens: None
280-
},
281-
kind: ItemKind::Use(ast::UseTree {
282-
prefix: ast::Path::from_ident(
283-
Ident::from_str_and_span(
284-
"super", item_span,
285-
)
286-
),
287-
kind: ast::UseTreeKind::Glob,
288-
span: item_span,
289-
}),
290-
tokens: None,
291-
}),
292-
Box::new(ast::Item {
293-
attrs,
294-
id: DUMMY_NODE_ID,
295-
span: item_span,
296-
vis: ast::Visibility {
297-
span: eii_attr_span,
298-
kind: ast::VisibilityKind::Inherited,
299-
tokens: None
300-
},
301-
kind: ItemKind::Fn(Box::new(default_func)),
302-
tokens: None,
303-
}),
304-
],
305-
ast::Inline::Yes,
306-
ast::ModSpans {
307-
inner_span: item_span,
308-
inject_use_span: item_span,
309-
}
310-
)
311-
),
247+
kind: ItemKind::Fn(Box::new(default_func)),
312248
tokens: None,
313249
})),
314-
span: eii_attr_span,
250+
span: eii_attr_span
315251
}],
316252
id: DUMMY_NODE_ID,
317253
rules: ast::BlockCheckMode::Default,
@@ -416,6 +352,7 @@ fn generate_attribute_macro_to_implement(
416352
macro_name: Ident,
417353
foreign_item_name: Ident,
418354
impl_unsafe: bool,
355+
decl_span: Span,
419356
) -> ast::Item {
420357
let mut macro_attrs = ThinVec::new();
421358

@@ -457,6 +394,7 @@ fn generate_attribute_macro_to_implement(
457394
eii_extern_target: Some(ast::EiiExternTarget {
458395
extern_item_path: ast::Path::from_ident(foreign_item_name),
459396
impl_unsafe,
397+
span: decl_span,
460398
}),
461399
},
462400
),
@@ -513,7 +451,7 @@ pub(crate) fn eii_extern_target(
513451
false
514452
};
515453

516-
d.eii_extern_target = Some(EiiExternTarget { extern_item_path, impl_unsafe });
454+
d.eii_extern_target = Some(EiiExternTarget { extern_item_path, impl_unsafe, span });
517455

518456
// Return the original item and the new methods.
519457
vec![item]
@@ -570,7 +508,6 @@ pub(crate) fn eii_shared_macro(
570508
impl_safety: meta_item.unsafety,
571509
span,
572510
is_default,
573-
known_eii_macro_resolution: None,
574511
});
575512

576513
vec![item]

compiler/rustc_codegen_llvm/src/mono_item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl CodegenCx<'_, '_> {
111111
}
112112
}
113113

114-
/// A definition or declaration can be assumed to be local to a group of
114+
/// Whether a definition or declaration can be assumed to be local to a group of
115115
/// libraries that form a single DSO or executable.
116116
/// Marks the local as DSO if so.
117117
pub(crate) fn assume_dso_local(&self, llval: &llvm::Value, is_declaration: bool) -> bool {
@@ -153,7 +153,7 @@ impl CodegenCx<'_, '_> {
153153
return false;
154154
}
155155

156-
// With pie relocation model, calls of functions defined in the translation
156+
// With pie relocation model calls of functions defined in the translation
157157
// unit can use copy relocations.
158158
if self.tcx.sess.relocation_model() == RelocModel::Pie && !is_declaration {
159159
return true;

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ use std::str::FromStr;
33
use rustc_abi::{Align, ExternAbi};
44
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
55
use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
6-
use rustc_hir::attrs::{
7-
AttributeKind, EiiImplResolution, InlineAttr, Linkage, RtsanSetting, UsedBy,
8-
};
6+
use rustc_hir::attrs::{AttributeKind, InlineAttr, Linkage, RtsanSetting, UsedBy};
97
use rustc_hir::def::DefKind;
108
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
119
use rustc_hir::{self as hir, Attribute, LangItem, find_attr, lang_items};
@@ -287,23 +285,11 @@ fn process_builtin_attrs(
287285
}
288286
AttributeKind::EiiImpls(impls) => {
289287
for i in impls {
290-
let extern_item = match i.resolution {
291-
EiiImplResolution::Macro(def_id) => {
292-
let Some(extern_item) = find_attr!(
293-
tcx.get_all_attrs(def_id),
294-
AttributeKind::EiiExternTarget(target) => target.eii_extern_target
295-
) else {
296-
tcx.dcx().span_delayed_bug(
297-
i.span,
298-
"resolved to something that's not an EII",
299-
);
300-
continue;
301-
};
302-
extern_item
303-
}
304-
EiiImplResolution::Known(decl) => decl.eii_extern_target,
305-
EiiImplResolution::Error(_eg) => continue,
306-
};
288+
let extern_item = find_attr!(
289+
tcx.get_all_attrs(i.eii_macro),
290+
AttributeKind::EiiExternTarget(target) => target.eii_extern_target
291+
)
292+
.expect("eii should have declaration macro with extern target attribute");
307293

308294
// this is to prevent a bug where a single crate defines both the default and explicit implementation
309295
// for an EII. In that case, both of them may be part of the same final object file. I'm not 100% sure
@@ -316,7 +302,7 @@ fn process_builtin_attrs(
316302
// iterate over all implementations *in the current crate*
317303
// (this is ok since we generate codegen fn attrs in the local crate)
318304
// if any of them is *not default* then don't emit the alias.
319-
&& tcx.externally_implementable_items(LOCAL_CRATE).get(&extern_item).expect("at least one").1.iter().any(|(_, imp)| !imp.is_default)
305+
&& tcx.externally_implementable_items(LOCAL_CRATE).get(&i.eii_macro).expect("at least one").1.iter().any(|(_, imp)| !imp.is_default)
320306
{
321307
continue;
322308
}

0 commit comments

Comments
 (0)