Skip to content

Commit fc105ef

Browse files
committed
Auto merge of #2679 - RalfJung:clock_gettime, r=RalfJung
implement clock_gettime on macos and pull in rustc changes so we can test this against #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 {

0 commit comments

Comments
 (0)