Skip to content

Commit 99b441a

Browse files
committed
Auto merge of #127079 - GuillaumeGomez:rollup-ciimias, r=GuillaumeGomez
Rollup of 10 pull requests Successful merges: - #123714 (Add test for fn pointer duplication.) - #124091 (Update AST validation module docs) - #126963 (Add basic Serde serialization capabilities to Stable MIR) - #127015 (Switch back `non_local_definitions` lint to allow-by-default) - #127016 (docs: check if the disambiguator matches its suffix) - #127029 (Fix Markdown tables in platform-support.md) - #127032 (Enable const casting for `f16` and `f128`) - #127041 (Migrate `run-make/override-aliased-flags` to `rmake.rs`) - #127045 (Rename `super_predicates_of` and similar queries to `explicit_*` to note that they're not elaborated) - #127075 (rustc_data_structures: Explicitly check for 64-bit atomics support) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 99f77a2 + 613e3df commit 99b441a

File tree

76 files changed

+1135
-393
lines changed

Some content is hidden

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

76 files changed

+1135
-393
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -5263,6 +5263,7 @@ name = "stable_mir"
52635263
version = "0.1.0-preview"
52645264
dependencies = [
52655265
"scoped-tls",
5266+
"serde",
52665267
]
52675268

52685269
[[package]]

compiler/rustc_ast_passes/src/ast_validation.rs

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
1-
// Validate AST before lowering it to HIR.
2-
//
3-
// This pass is supposed to catch things that fit into AST data structures,
4-
// but not permitted by the language. It runs after expansion when AST is frozen,
5-
// so it can check for erroneous constructions produced by syntax extensions.
6-
// This pass is supposed to perform only simple checks not requiring name resolution
7-
// or type checking or some other kind of complex analysis.
1+
//! Validate AST before lowering it to HIR.
2+
//!
3+
//! This pass intends to check that the constructed AST is *syntactically valid* to allow the rest
4+
//! of the compiler to assume that the AST is valid. These checks cannot be performed during parsing
5+
//! because attribute macros are allowed to accept certain pieces of invalid syntax such as a
6+
//! function without body outside of a trait definition:
7+
//!
8+
//! ```ignore (illustrative)
9+
//! #[my_attribute]
10+
//! mod foo {
11+
//! fn missing_body();
12+
//! }
13+
//! ```
14+
//!
15+
//! These checks are run post-expansion, after AST is frozen, to be able to check for erroneous
16+
//! constructions produced by proc macros. This pass is only intended for simple checks that do not
17+
//! require name resolution or type checking, or other kinds of complex analysis.
818
919
use itertools::{Either, Itertools};
1020
use rustc_ast::ptr::P;

compiler/rustc_const_eval/src/interpret/cast.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::assert_matches::assert_matches;
22

3-
use rustc_apfloat::ieee::{Double, Single};
3+
use rustc_apfloat::ieee::{Double, Half, Quad, Single};
44
use rustc_apfloat::{Float, FloatConvert};
55
use rustc_middle::mir::interpret::{InterpResult, PointerArithmetic, Scalar};
66
use rustc_middle::mir::CastKind;
@@ -187,10 +187,10 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
187187
bug!("FloatToFloat/FloatToInt cast: source type {} is not a float type", src.layout.ty)
188188
};
189189
let val = match fty {
190-
FloatTy::F16 => unimplemented!("f16_f128"),
190+
FloatTy::F16 => self.cast_from_float(src.to_scalar().to_f16()?, cast_to.ty),
191191
FloatTy::F32 => self.cast_from_float(src.to_scalar().to_f32()?, cast_to.ty),
192192
FloatTy::F64 => self.cast_from_float(src.to_scalar().to_f64()?, cast_to.ty),
193-
FloatTy::F128 => unimplemented!("f16_f128"),
193+
FloatTy::F128 => self.cast_from_float(src.to_scalar().to_f128()?, cast_to.ty),
194194
};
195195
Ok(ImmTy::from_scalar(val, cast_to))
196196
}
@@ -296,18 +296,18 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
296296
Float(fty) if signed => {
297297
let v = v as i128;
298298
match fty {
299-
FloatTy::F16 => unimplemented!("f16_f128"),
299+
FloatTy::F16 => Scalar::from_f16(Half::from_i128(v).value),
300300
FloatTy::F32 => Scalar::from_f32(Single::from_i128(v).value),
301301
FloatTy::F64 => Scalar::from_f64(Double::from_i128(v).value),
302-
FloatTy::F128 => unimplemented!("f16_f128"),
302+
FloatTy::F128 => Scalar::from_f128(Quad::from_i128(v).value),
303303
}
304304
}
305305
// unsigned int -> float
306306
Float(fty) => match fty {
307-
FloatTy::F16 => unimplemented!("f16_f128"),
307+
FloatTy::F16 => Scalar::from_f16(Half::from_u128(v).value),
308308
FloatTy::F32 => Scalar::from_f32(Single::from_u128(v).value),
309309
FloatTy::F64 => Scalar::from_f64(Double::from_u128(v).value),
310-
FloatTy::F128 => unimplemented!("f16_f128"),
310+
FloatTy::F128 => Scalar::from_f128(Quad::from_u128(v).value),
311311
},
312312

313313
// u8 -> char
@@ -321,7 +321,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
321321
/// Low-level cast helper function. Converts an apfloat `f` into int or float types.
322322
fn cast_from_float<F>(&self, f: F, dest_ty: Ty<'tcx>) -> Scalar<M::Provenance>
323323
where
324-
F: Float + Into<Scalar<M::Provenance>> + FloatConvert<Single> + FloatConvert<Double>,
324+
F: Float
325+
+ Into<Scalar<M::Provenance>>
326+
+ FloatConvert<Half>
327+
+ FloatConvert<Single>
328+
+ FloatConvert<Double>
329+
+ FloatConvert<Quad>,
325330
{
326331
use rustc_type_ir::TyKind::*;
327332

@@ -358,10 +363,12 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
358363
}
359364
// float -> float
360365
Float(fty) => match fty {
361-
FloatTy::F16 => unimplemented!("f16_f128"),
366+
FloatTy::F16 => Scalar::from_f16(adjust_nan(self, f, f.convert(&mut false).value)),
362367
FloatTy::F32 => Scalar::from_f32(adjust_nan(self, f, f.convert(&mut false).value)),
363368
FloatTy::F64 => Scalar::from_f64(adjust_nan(self, f, f.convert(&mut false).value)),
364-
FloatTy::F128 => unimplemented!("f16_f128"),
369+
FloatTy::F128 => {
370+
Scalar::from_f128(adjust_nan(self, f, f.convert(&mut false).value))
371+
}
365372
},
366373
// That's it.
367374
_ => span_bug!(self.cur_span(), "invalid float to {} cast", dest_ty),

compiler/rustc_data_structures/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ libc = "0.2"
5050
memmap2 = "0.2.1"
5151
# tidy-alphabetical-end
5252

53-
[target.'cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))'.dependencies]
53+
[target.'cfg(not(target_has_atomic = "64"))'.dependencies]
5454
portable-atomic = "1.5.1"
5555

5656
[features]

compiler/rustc_data_structures/src/marker.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,13 @@ cfg_match! {
147147
[crate::owned_slice::OwnedSlice]
148148
);
149149

150-
// MIPS, PowerPC and SPARC platforms with 32-bit pointers do not
151-
// have AtomicU64 type.
152-
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc", target_arch = "sparc")))]
150+
// Use portable AtomicU64 for targets without native 64-bit atomics
151+
#[cfg(target_has_atomic = "64")]
153152
already_sync!(
154153
[std::sync::atomic::AtomicU64]
155154
);
156155

157-
#[cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))]
156+
#[cfg(not(target_has_atomic = "64"))]
158157
already_sync!(
159158
[portable_atomic::AtomicU64]
160159
);

compiler/rustc_data_structures/src/sync.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,11 @@ cfg_match! {
270270

271271
pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32};
272272

273-
// MIPS, PowerPC and SPARC platforms with 32-bit pointers do not
274-
// have AtomicU64 type.
275-
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc")))]
273+
// Use portable AtomicU64 for targets without native 64-bit atomics
274+
#[cfg(target_has_atomic = "64")]
276275
pub use std::sync::atomic::AtomicU64;
277276

278-
#[cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))]
277+
#[cfg(not(target_has_atomic = "64"))]
279278
pub use portable_atomic::AtomicU64;
280279

281280
pub use std::sync::Arc as Lrc;

compiler/rustc_hir_analysis/src/collect.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ pub fn provide(providers: &mut Providers) {
7070
predicates_of: predicates_of::predicates_of,
7171
predicates_defined_on,
7272
explicit_predicates_of: predicates_of::explicit_predicates_of,
73-
super_predicates_of: predicates_of::super_predicates_of,
74-
implied_predicates_of: predicates_of::implied_predicates_of,
75-
super_predicates_that_define_assoc_item:
76-
predicates_of::super_predicates_that_define_assoc_item,
73+
explicit_super_predicates_of: predicates_of::explicit_super_predicates_of,
74+
explicit_implied_predicates_of: predicates_of::explicit_implied_predicates_of,
75+
explicit_supertraits_containing_assoc_item:
76+
predicates_of::explicit_supertraits_containing_assoc_item,
7777
trait_explicit_predicates_and_bounds: predicates_of::trait_explicit_predicates_and_bounds,
7878
type_param_predicates: predicates_of::type_param_predicates,
7979
trait_def,
@@ -691,14 +691,14 @@ fn lower_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
691691
hir::ItemKind::Trait(..) => {
692692
tcx.ensure().generics_of(def_id);
693693
tcx.ensure().trait_def(def_id);
694-
tcx.at(it.span).super_predicates_of(def_id);
694+
tcx.at(it.span).explicit_super_predicates_of(def_id);
695695
tcx.ensure().predicates_of(def_id);
696696
tcx.ensure().associated_items(def_id);
697697
}
698698
hir::ItemKind::TraitAlias(..) => {
699699
tcx.ensure().generics_of(def_id);
700-
tcx.at(it.span).implied_predicates_of(def_id);
701-
tcx.at(it.span).super_predicates_of(def_id);
700+
tcx.at(it.span).explicit_implied_predicates_of(def_id);
701+
tcx.at(it.span).explicit_super_predicates_of(def_id);
702702
tcx.ensure().predicates_of(def_id);
703703
}
704704
hir::ItemKind::Struct(struct_def, _) | hir::ItemKind::Union(struct_def, _) => {

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -519,21 +519,21 @@ pub(super) fn explicit_predicates_of<'tcx>(
519519
/// Ensures that the super-predicates of the trait with a `DefId`
520520
/// of `trait_def_id` are lowered and stored. This also ensures that
521521
/// the transitive super-predicates are lowered.
522-
pub(super) fn super_predicates_of(
522+
pub(super) fn explicit_super_predicates_of(
523523
tcx: TyCtxt<'_>,
524524
trait_def_id: LocalDefId,
525525
) -> ty::GenericPredicates<'_> {
526526
implied_predicates_with_filter(tcx, trait_def_id.to_def_id(), PredicateFilter::SelfOnly)
527527
}
528528

529-
pub(super) fn super_predicates_that_define_assoc_item(
529+
pub(super) fn explicit_supertraits_containing_assoc_item(
530530
tcx: TyCtxt<'_>,
531531
(trait_def_id, assoc_name): (DefId, Ident),
532532
) -> ty::GenericPredicates<'_> {
533533
implied_predicates_with_filter(tcx, trait_def_id, PredicateFilter::SelfThatDefines(assoc_name))
534534
}
535535

536-
pub(super) fn implied_predicates_of(
536+
pub(super) fn explicit_implied_predicates_of(
537537
tcx: TyCtxt<'_>,
538538
trait_def_id: LocalDefId,
539539
) -> ty::GenericPredicates<'_> {
@@ -560,7 +560,7 @@ pub(super) fn implied_predicates_with_filter(
560560
// if `assoc_name` is None, then the query should've been redirected to an
561561
// external provider
562562
assert!(matches!(filter, PredicateFilter::SelfThatDefines(_)));
563-
return tcx.super_predicates_of(trait_def_id);
563+
return tcx.explicit_super_predicates_of(trait_def_id);
564564
};
565565

566566
let Node::Item(item) = tcx.hir_node_by_def_id(trait_def_id) else {
@@ -601,7 +601,7 @@ pub(super) fn implied_predicates_with_filter(
601601
if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder()
602602
&& bound.polarity == ty::PredicatePolarity::Positive
603603
{
604-
tcx.at(span).super_predicates_of(bound.def_id());
604+
tcx.at(span).explicit_super_predicates_of(bound.def_id());
605605
}
606606
}
607607
}
@@ -611,7 +611,7 @@ pub(super) fn implied_predicates_with_filter(
611611
if let ty::ClauseKind::Trait(bound) = pred.kind().skip_binder()
612612
&& bound.polarity == ty::PredicatePolarity::Positive
613613
{
614-
tcx.at(span).implied_predicates_of(bound.def_id());
614+
tcx.at(span).explicit_implied_predicates_of(bound.def_id());
615615
}
616616
}
617617
}

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1760,7 +1760,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
17601760
if let Some(assoc_item) = trait_defines_associated_item_named(def_id) {
17611761
break Some((bound_vars.into_iter().collect(), assoc_item));
17621762
}
1763-
let predicates = tcx.super_predicates_that_define_assoc_item((def_id, assoc_name));
1763+
let predicates = tcx.explicit_supertraits_containing_assoc_item((def_id, assoc_name));
17641764
let obligations = predicates.predicates.iter().filter_map(|&(pred, _)| {
17651765
let bound_predicate = pred.kind();
17661766
match bound_predicate.skip_binder() {

compiler/rustc_infer/src/traits/util.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,10 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
275275
}
276276
// Get predicates implied by the trait, or only super predicates if we only care about self predicates.
277277
let predicates = match self.mode {
278-
Filter::All => tcx.implied_predicates_of(data.def_id()),
279-
Filter::OnlySelf => tcx.super_predicates_of(data.def_id()),
278+
Filter::All => tcx.explicit_implied_predicates_of(data.def_id()),
279+
Filter::OnlySelf => tcx.explicit_super_predicates_of(data.def_id()),
280280
Filter::OnlySelfThatDefines(ident) => {
281-
tcx.super_predicates_that_define_assoc_item((data.def_id(), ident))
281+
tcx.explicit_supertraits_containing_assoc_item((data.def_id(), ident))
282282
}
283283
};
284284

@@ -420,7 +420,7 @@ pub fn transitive_bounds<'tcx>(
420420

421421
/// A specialized variant of `elaborate` that only elaborates trait references that may
422422
/// define the given associated item with the name `assoc_name`. It uses the
423-
/// `super_predicates_that_define_assoc_item` query to avoid enumerating super-predicates that
423+
/// `explicit_supertraits_containing_assoc_item` query to avoid enumerating super-predicates that
424424
/// aren't related to `assoc_item`. This is used when resolving types like `Self::Item` or
425425
/// `T::Item` and helps to avoid cycle errors (see e.g. #35237).
426426
pub fn transitive_bounds_that_define_assoc_item<'tcx>(

compiler/rustc_lint/src/multiple_supertrait_upcastable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for MultipleSupertraitUpcastable {
4545
{
4646
let direct_super_traits_iter = cx
4747
.tcx
48-
.super_predicates_of(def_id)
48+
.explicit_super_predicates_of(def_id)
4949
.predicates
5050
.into_iter()
5151
.filter_map(|(pred, _)| pred.as_trait_clause());

compiler/rustc_lint/src/non_local_def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ declare_lint! {
5050
/// All nested bodies (functions, enum discriminant, array length, consts) (expect for
5151
/// `const _: Ty = { ... }` in top-level module, which is still undecided) are checked.
5252
pub NON_LOCAL_DEFINITIONS,
53-
Warn,
53+
Allow,
5454
"checks for non-local definitions",
5555
report_in_external_macro
5656
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ provide! { tcx, def_id, other, cdata,
211211
explicit_predicates_of => { table }
212212
generics_of => { table }
213213
inferred_outlives_of => { table_defaulted_array }
214-
super_predicates_of => { table }
215-
implied_predicates_of => { table }
214+
explicit_super_predicates_of => { table }
215+
explicit_implied_predicates_of => { table }
216216
type_of => { table }
217217
type_alias_is_lazy => { cdata.root.tables.type_alias_is_lazy.get(cdata, def_id.index) }
218218
variances_of => { table }

compiler/rustc_metadata/src/rmeta/encoder.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1431,17 +1431,17 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
14311431
}
14321432
if let DefKind::Trait = def_kind {
14331433
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
1434-
record!(self.tables.super_predicates_of[def_id] <- self.tcx.super_predicates_of(def_id));
1435-
record!(self.tables.implied_predicates_of[def_id] <- self.tcx.implied_predicates_of(def_id));
1434+
record!(self.tables.explicit_super_predicates_of[def_id] <- self.tcx.explicit_super_predicates_of(def_id));
1435+
record!(self.tables.explicit_implied_predicates_of[def_id] <- self.tcx.explicit_implied_predicates_of(def_id));
14361436

14371437
let module_children = self.tcx.module_children_local(local_id);
14381438
record_array!(self.tables.module_children_non_reexports[def_id] <-
14391439
module_children.iter().map(|child| child.res.def_id().index));
14401440
}
14411441
if let DefKind::TraitAlias = def_kind {
14421442
record!(self.tables.trait_def[def_id] <- self.tcx.trait_def(def_id));
1443-
record!(self.tables.super_predicates_of[def_id] <- self.tcx.super_predicates_of(def_id));
1444-
record!(self.tables.implied_predicates_of[def_id] <- self.tcx.implied_predicates_of(def_id));
1443+
record!(self.tables.explicit_super_predicates_of[def_id] <- self.tcx.explicit_super_predicates_of(def_id));
1444+
record!(self.tables.explicit_implied_predicates_of[def_id] <- self.tcx.explicit_implied_predicates_of(def_id));
14451445
}
14461446
if let DefKind::Trait | DefKind::Impl { .. } = def_kind {
14471447
let associated_item_def_ids = self.tcx.associated_item_def_ids(def_id);

compiler/rustc_metadata/src/rmeta/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -416,10 +416,10 @@ define_tables! {
416416
lookup_deprecation_entry: Table<DefIndex, LazyValue<attr::Deprecation>>,
417417
explicit_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
418418
generics_of: Table<DefIndex, LazyValue<ty::Generics>>,
419-
super_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
419+
explicit_super_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
420420
// As an optimization, we only store this for trait aliases,
421-
// since it's identical to super_predicates_of for traits.
422-
implied_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
421+
// since it's identical to explicit_super_predicates_of for traits.
422+
explicit_implied_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
423423
type_of: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, Ty<'static>>>>,
424424
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
425425
fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, ty::PolyFnSig<'static>>>>,

0 commit comments

Comments
 (0)