Skip to content

Commit fc105ef

Browse files
committed
Auto merge of rust-lang#2679 - RalfJung:clock_gettime, r=RalfJung
implement clock_gettime on macos and pull in rustc changes so we can test this against rust-lang#103594. Fixes rust-lang/miri#2664
2 parents cf4da2d + 21321f5 commit fc105ef

File tree

105 files changed

+1148
-526
lines changed

Some content is hidden

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

105 files changed

+1148
-526
lines changed

compiler/rustc_ast_lowering/src/asm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use super::LoweringContext;
1111

1212
use rustc_ast::ptr::P;
1313
use rustc_ast::*;
14-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
14+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
1515
use rustc_hir as hir;
1616
use rustc_hir::def::{DefKind, Res};
1717
use rustc_hir::definitions::DefPathData;
@@ -71,7 +71,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
7171
.emit();
7272
}
7373

74-
let mut clobber_abis = FxHashMap::default();
74+
let mut clobber_abis = FxIndexMap::default();
7575
if let Some(asm_arch) = asm_arch {
7676
for (abi_name, abi_span) in &asm.clobber_abis {
7777
match asm::InlineAsmClobberAbi::parse(asm_arch, &self.tcx.sess.target, *abi_name) {

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -655,15 +655,40 @@ impl<'hir> LoweringContext<'_, 'hir> {
655655

656656
hir::ExprKind::Closure(c)
657657
};
658-
let generator = hir::Expr {
659-
hir_id: self.lower_node_id(closure_node_id),
660-
kind: generator_kind,
661-
span: self.lower_span(span),
658+
let parent_has_track_caller = self
659+
.attrs
660+
.values()
661+
.find(|attrs| attrs.into_iter().find(|attr| attr.has_name(sym::track_caller)).is_some())
662+
.is_some();
663+
let unstable_span =
664+
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
665+
666+
let hir_id = if parent_has_track_caller {
667+
let generator_hir_id = self.lower_node_id(closure_node_id);
668+
self.lower_attrs(
669+
generator_hir_id,
670+
&[Attribute {
671+
kind: AttrKind::Normal(ptr::P(NormalAttr {
672+
item: AttrItem {
673+
path: Path::from_ident(Ident::new(sym::track_caller, span)),
674+
args: MacArgs::Empty,
675+
tokens: None,
676+
},
677+
tokens: None,
678+
})),
679+
id: self.tcx.sess.parse_sess.attr_id_generator.mk_attr_id(),
680+
style: AttrStyle::Outer,
681+
span: unstable_span,
682+
}],
683+
);
684+
generator_hir_id
685+
} else {
686+
self.lower_node_id(closure_node_id)
662687
};
663688

689+
let generator = hir::Expr { hir_id, kind: generator_kind, span: self.lower_span(span) };
690+
664691
// `future::from_generator`:
665-
let unstable_span =
666-
self.mark_span_with_reason(DesugaringKind::Async, span, self.allow_gen_future.clone());
667692
let gen_future = self.expr_lang_item_path(
668693
unstable_span,
669694
hir::LangItem::FromGenerator,

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use super::{FnDeclKind, LoweringContext, ParamMode};
66
use rustc_ast::ptr::P;
77
use rustc_ast::visit::AssocCtxt;
88
use rustc_ast::*;
9-
use rustc_data_structures::fx::FxHashMap;
109
use rustc_data_structures::sorted_map::SortedMap;
1110
use rustc_hir as hir;
1211
use rustc_hir::def::{DefKind, Res};
@@ -67,7 +66,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
6766
// HirId handling.
6867
bodies: Vec::new(),
6968
attrs: SortedMap::default(),
70-
children: FxHashMap::default(),
69+
children: Vec::default(),
7170
current_hir_id_owner: hir::CRATE_OWNER_ID,
7271
item_local_id_counter: hir::ItemLocalId::new(0),
7372
node_id_to_local_id: Default::default(),
@@ -86,7 +85,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
8685
impl_trait_defs: Vec::new(),
8786
impl_trait_bounds: Vec::new(),
8887
allow_try_trait: Some([sym::try_trait_v2, sym::yeet_desugar_details][..].into()),
89-
allow_gen_future: Some([sym::gen_future][..].into()),
88+
allow_gen_future: Some([sym::gen_future, sym::closure_track_caller][..].into()),
9089
allow_into_future: Some([sym::into_future][..].into()),
9190
generics_def_id_map: Default::default(),
9291
};
@@ -534,12 +533,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
534533
for new_node_id in [id1, id2] {
535534
let new_id = self.local_def_id(new_node_id);
536535
let Some(res) = resolutions.next() else {
536+
debug_assert!(self.children.iter().find(|(id, _)| id == &new_id).is_none());
537537
// Associate an HirId to both ids even if there is no resolution.
538-
let _old = self.children.insert(
538+
self.children.push((
539539
new_id,
540-
hir::MaybeOwner::NonOwner(hir::HirId::make_owner(new_id)),
540+
hir::MaybeOwner::NonOwner(hir::HirId::make_owner(new_id))),
541541
);
542-
debug_assert!(_old.is_none());
543542
continue;
544543
};
545544
let ident = *ident;

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#![feature(let_chains)]
3535
#![feature(never_type)]
3636
#![recursion_limit = "256"]
37-
#![allow(rustc::potential_query_instability)]
3837
#![deny(rustc::untranslatable_diagnostic)]
3938
#![deny(rustc::diagnostic_outside_of_impl)]
4039

@@ -107,7 +106,7 @@ struct LoweringContext<'a, 'hir> {
107106
/// Attributes inside the owner being lowered.
108107
attrs: SortedMap<hir::ItemLocalId, &'hir [Attribute]>,
109108
/// Collect items that were created by lowering the current owner.
110-
children: FxHashMap<LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>>,
109+
children: Vec<(LocalDefId, hir::MaybeOwner<&'hir hir::OwnerInfo<'hir>>)>,
111110

112111
generator_kind: Option<hir::GeneratorKind>,
113112

@@ -611,8 +610,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
611610
self.impl_trait_defs = current_impl_trait_defs;
612611
self.impl_trait_bounds = current_impl_trait_bounds;
613612

614-
let _old = self.children.insert(def_id, hir::MaybeOwner::Owner(info));
615-
debug_assert!(_old.is_none())
613+
debug_assert!(self.children.iter().find(|(id, _)| id == &def_id).is_none());
614+
self.children.push((def_id, hir::MaybeOwner::Owner(info)));
616615
}
617616

618617
/// Installs the remapping `remap` in scope while `f` is being executed.
@@ -719,8 +718,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
719718

720719
assert_ne!(local_id, hir::ItemLocalId::new(0));
721720
if let Some(def_id) = self.opt_local_def_id(ast_node_id) {
722-
// Do not override a `MaybeOwner::Owner` that may already here.
723-
self.children.entry(def_id).or_insert(hir::MaybeOwner::NonOwner(hir_id));
721+
self.children.push((def_id, hir::MaybeOwner::NonOwner(hir_id)));
724722
self.local_id_to_def_id.insert(local_id, def_id);
725723
}
726724

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use rustc_infer::infer::{DefiningAnchor, InferCtxt};
77
use rustc_infer::traits::{Obligation, ObligationCause};
88
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
99
use rustc_middle::ty::visit::TypeVisitable;
10-
use rustc_middle::ty::{
11-
self, OpaqueHiddenType, OpaqueTypeKey, ToPredicate, Ty, TyCtxt, TypeFoldable,
12-
};
10+
use rustc_middle::ty::{self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable};
1311
use rustc_span::Span;
1412
use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt as _;
1513
use rustc_trait_selection::traits::ObligationCtxt;
@@ -256,8 +254,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
256254
// Require the hidden type to be well-formed with only the generics of the opaque type.
257255
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
258256
// hidden type is well formed even without those bounds.
259-
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()))
260-
.to_predicate(infcx.tcx);
257+
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()));
261258

262259
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id());
263260

@@ -282,6 +279,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
282279
}
283280

284281
ocx.register_obligation(Obligation::misc(
282+
infcx.tcx,
285283
instantiated_ty.span,
286284
body_id,
287285
param_env,

compiler/rustc_borrowck/src/type_check/canonical.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
9292
trait_ref,
9393
constness: ty::BoundConstness::NotConst,
9494
polarity: ty::ImplPolarity::Positive,
95-
}))
96-
.to_predicate(self.tcx()),
95+
})),
9796
locations,
9897
category,
9998
);
@@ -122,26 +121,26 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
122121

123122
pub(super) fn prove_predicates(
124123
&mut self,
125-
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
124+
predicates: impl IntoIterator<
125+
Item = impl ToPredicate<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug,
126+
>,
126127
locations: Locations,
127128
category: ConstraintCategory<'tcx>,
128129
) {
129130
for predicate in predicates {
130-
let predicate = predicate.to_predicate(self.tcx());
131-
debug!("prove_predicates(predicate={:?}, locations={:?})", predicate, locations,);
132-
133131
self.prove_predicate(predicate, locations, category);
134132
}
135133
}
136134

137135
#[instrument(skip(self), level = "debug")]
138136
pub(super) fn prove_predicate(
139137
&mut self,
140-
predicate: ty::Predicate<'tcx>,
138+
predicate: impl ToPredicate<'tcx, ty::Predicate<'tcx>> + std::fmt::Debug,
141139
locations: Locations,
142140
category: ConstraintCategory<'tcx>,
143141
) {
144142
let param_env = self.param_env;
143+
let predicate = predicate.to_predicate(self.tcx());
145144
self.fully_perform_op(
146145
locations,
147146
category,

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ use rustc_middle::ty::subst::{SubstsRef, UserSubsts};
3333
use rustc_middle::ty::visit::TypeVisitable;
3434
use rustc_middle::ty::{
3535
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, Dynamic,
36-
OpaqueHiddenType, OpaqueTypeKey, RegionVid, ToPredicate, Ty, TyCtxt, UserType,
37-
UserTypeAnnotationIndex,
36+
OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
3837
};
3938
use rustc_span::def_id::CRATE_DEF_ID;
4039
use rustc_span::{Span, DUMMY_SP};
@@ -1069,8 +1068,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10691068
}
10701069

10711070
self.prove_predicate(
1072-
ty::Binder::dummy(ty::PredicateKind::WellFormed(inferred_ty.into()))
1073-
.to_predicate(self.tcx()),
1071+
ty::Binder::dummy(ty::PredicateKind::WellFormed(inferred_ty.into())),
10741072
Locations::All(span),
10751073
ConstraintCategory::TypeAnnotation,
10761074
);

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
732732
polarity: ty::ImplPolarity::Positive,
733733
});
734734
let obligation =
735-
Obligation::new(ObligationCause::dummy(), param_env, poly_trait_pred);
735+
Obligation::new(tcx, ObligationCause::dummy(), param_env, poly_trait_pred);
736736

737737
let implsrc = {
738738
let infcx = tcx.infer_ctxt().build();
@@ -816,6 +816,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
816816

817817
if !nonconst_call_permission {
818818
let obligation = Obligation::new(
819+
tcx,
819820
ObligationCause::dummy_with_span(*fn_span),
820821
param_env,
821822
tcx.mk_predicate(

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
6262
}
6363

6464
fn is_async(&self) -> bool {
65-
self.tcx.asyncness(self.def_id()) == hir::IsAsync::Async
65+
self.tcx.asyncness(self.def_id()).is_async()
6666
}
6767
}
6868

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
147147
}
148148
Adt(..) => {
149149
let obligation = Obligation::new(
150+
tcx,
150151
ObligationCause::dummy(),
151152
param_env,
152153
Binder::dummy(TraitPredicate {

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ impl Qualif for NeedsNonConstDrop {
156156
let destruct = cx.tcx.require_lang_item(LangItem::Destruct, None);
157157

158158
let obligation = Obligation::new(
159+
cx.tcx,
159160
ObligationCause::dummy(),
160161
cx.param_env,
161162
ty::Binder::dummy(ty::TraitPredicate {
@@ -351,7 +352,11 @@ where
351352
// FIXME(valtrees): check whether const qualifs should behave the same
352353
// way for type and mir constants.
353354
let uneval = match constant.literal {
354-
ConstantKind::Ty(ct) if matches!(ct.kind(), ty::ConstKind::Param(_)) => None,
355+
ConstantKind::Ty(ct)
356+
if matches!(ct.kind(), ty::ConstKind::Param(_) | ty::ConstKind::Error(_)) =>
357+
{
358+
None
359+
}
355360
ConstantKind::Ty(c) => bug!("expected ConstKind::Param here, found {:?}", c),
356361
ConstantKind::Unevaluated(uv, _) => Some(uv),
357362
ConstantKind::Val(..) => None,

compiler/rustc_hir/src/hir.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2720,6 +2720,12 @@ pub enum IsAsync {
27202720
NotAsync,
27212721
}
27222722

2723+
impl IsAsync {
2724+
pub fn is_async(self) -> bool {
2725+
self == IsAsync::Async
2726+
}
2727+
}
2728+
27232729
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, Encodable, Decodable, HashStable_Generic)]
27242730
pub enum Defaultness {
27252731
Default { has_value: bool },

compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use rustc_middle::middle::stability::EvalResult;
1919
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
2020
use rustc_middle::ty::subst::GenericArgKind;
2121
use rustc_middle::ty::util::{Discr, IntTypeExt};
22-
use rustc_middle::ty::{
23-
self, ParamEnv, ToPredicate, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
24-
};
22+
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable};
2523
use rustc_session::lint::builtin::{UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS};
2624
use rustc_span::symbol::sym;
2725
use rustc_span::{self, Span};
@@ -464,9 +462,8 @@ fn check_opaque_meets_bounds<'tcx>(
464462
// Additionally require the hidden type to be well-formed with only the generics of the opaque type.
465463
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
466464
// hidden type is well formed even without those bounds.
467-
let predicate =
468-
ty::Binder::dummy(ty::PredicateKind::WellFormed(hidden_ty.into())).to_predicate(tcx);
469-
ocx.register_obligation(Obligation::new(misc_cause, param_env, predicate));
465+
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(hidden_ty.into()));
466+
ocx.register_obligation(Obligation::new(tcx, misc_cause, param_env, predicate));
470467

471468
// Check that all obligations are satisfied by the implementation's
472469
// version.

compiler/rustc_hir_analysis/src/check/compare_method.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn compare_predicate_entailment<'tcx>(
238238
kind: impl_m.kind,
239239
},
240240
);
241-
ocx.register_obligation(traits::Obligation::new(cause, param_env, predicate));
241+
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate));
242242
}
243243

244244
// We now need to check that the signature of the impl method is
@@ -521,7 +521,13 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
521521
let num_trait_substs = trait_to_impl_substs.len();
522522
let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len();
523523
let ty = tcx.fold_regions(ty, |region, _| {
524-
let (ty::ReFree(_) | ty::ReEarlyBound(_)) = region.kind() else { return region; };
524+
match region.kind() {
525+
// Remap all free regions, which correspond to late-bound regions in the function.
526+
ty::ReFree(_) => {}
527+
// Remap early-bound regions as long as they don't come from the `impl` itself.
528+
ty::ReEarlyBound(ebr) if tcx.parent(ebr.def_id) != impl_m.container_id(tcx) => {}
529+
_ => return region,
530+
}
525531
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
526532
else {
527533
tcx
@@ -605,6 +611,7 @@ impl<'tcx> TypeFolder<'tcx> for ImplTraitInTraitCollector<'_, 'tcx> {
605611
);
606612

607613
self.ocx.register_obligation(traits::Obligation::new(
614+
self.tcx(),
608615
ObligationCause::new(
609616
self.span,
610617
self.body_id,
@@ -681,9 +688,7 @@ fn report_trait_method_mismatch<'tcx>(
681688
// Suggestion to change output type. We do not suggest in `async` functions
682689
// to avoid complex logic or incorrect output.
683690
match tcx.hir().expect_impl_item(impl_m.def_id.expect_local()).kind {
684-
ImplItemKind::Fn(ref sig, _)
685-
if sig.header.asyncness == hir::IsAsync::NotAsync =>
686-
{
691+
ImplItemKind::Fn(ref sig, _) if !sig.header.asyncness.is_async() => {
687692
let msg = "change the output type to match the trait";
688693
let ap = Applicability::MachineApplicable;
689694
match sig.decl.output {
@@ -1579,7 +1584,7 @@ fn compare_type_predicate_entailment<'tcx>(
15791584
},
15801585
);
15811586
ocx.register_obligations(obligations);
1582-
ocx.register_obligation(traits::Obligation::new(cause, param_env, predicate));
1587+
ocx.register_obligation(traits::Obligation::new(tcx, cause, param_env, predicate));
15831588
}
15841589

15851590
// Check that all obligations are satisfied by the implementation's
@@ -1784,7 +1789,7 @@ pub fn check_type_bounds<'tcx>(
17841789
.subst_iter_copied(tcx, rebased_substs)
17851790
.map(|(concrete_ty_bound, span)| {
17861791
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
1787-
traits::Obligation::new(mk_cause(span), param_env, concrete_ty_bound)
1792+
traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)
17881793
})
17891794
.collect();
17901795
debug!("check_type_bounds: item_bounds={:?}", obligations);

0 commit comments

Comments
 (0)