Skip to content

Commit 8423230

Browse files
committed
Auto merge of #50027 - oli-obk:const_signed_pat_beta, r=kennytm
[beta] backport various PRs original PRs: * #49949 (not yet merged at the time of writing) * #49947 (long running const eval error -> warning) * #49833 (static recursion) * #49876 (no clippy in stable rls) * #49904 (Work around LLVM debuginfo problem in librustc_driver. )
2 parents 32a2a12 + 0f4bb2f commit 8423230

File tree

26 files changed

+374
-356
lines changed

26 files changed

+374
-356
lines changed

src/bootstrap/tool.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,8 @@ tool_extended!((self, builder),
564564
target: self.target,
565565
extra_features: Vec::new(),
566566
});
567-
if clippy.is_some() {
567+
let channel = &builder.config.channel;
568+
if clippy.is_some() && channel != "stable" && channel != "beta" {
568569
self.extra_features.push("clippy".to_owned());
569570
}
570571
builder.ensure(native::Openssl {

src/librustc/hir/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2280,6 +2280,7 @@ bitflags! {
22802280
const NAKED = 0b0001_0000;
22812281
const NO_MANGLE = 0b0010_0000;
22822282
const RUSTC_STD_INTERNAL_SYMBOL = 0b0100_0000;
2283+
const NO_DEBUG = 0b1000_0000;
22832284
}
22842285
}
22852286

src/librustc/ich/impls_ty.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -380,12 +380,12 @@ impl_stable_hash_for!(struct mir::interpret::MemoryPointer {
380380

381381
enum AllocDiscriminant {
382382
Alloc,
383-
ExternStatic,
383+
Static,
384384
Function,
385385
}
386386
impl_stable_hash_for!(enum self::AllocDiscriminant {
387387
Alloc,
388-
ExternStatic,
388+
Static,
389389
Function
390390
});
391391

@@ -396,24 +396,25 @@ impl<'a> HashStable<StableHashingContext<'a>> for mir::interpret::AllocId {
396396
hasher: &mut StableHasher<W>,
397397
) {
398398
ty::tls::with_opt(|tcx| {
399+
trace!("hashing {:?}", *self);
399400
let tcx = tcx.expect("can't hash AllocIds during hir lowering");
400-
if let Some(alloc) = tcx.interpret_interner.get_alloc(*self) {
401+
if let Some(def_id) = tcx.interpret_interner.get_static(*self) {
402+
AllocDiscriminant::Static.hash_stable(hcx, hasher);
403+
trace!("hashing {:?} as static {:?}", *self, def_id);
404+
def_id.hash_stable(hcx, hasher);
405+
} else if let Some(alloc) = tcx.interpret_interner.get_alloc(*self) {
401406
AllocDiscriminant::Alloc.hash_stable(hcx, hasher);
402407
if hcx.alloc_id_recursion_tracker.insert(*self) {
403-
tcx
404-
.interpret_interner
405-
.get_corresponding_static_def_id(*self)
406-
.hash_stable(hcx, hasher);
408+
trace!("hashing {:?} as alloc {:#?}", *self, alloc);
407409
alloc.hash_stable(hcx, hasher);
408410
assert!(hcx.alloc_id_recursion_tracker.remove(self));
411+
} else {
412+
trace!("skipping hashing of {:?} due to recursion", *self);
409413
}
410414
} else if let Some(inst) = tcx.interpret_interner.get_fn(*self) {
415+
trace!("hashing {:?} as fn {:#?}", *self, inst);
411416
AllocDiscriminant::Function.hash_stable(hcx, hasher);
412417
inst.hash_stable(hcx, hasher);
413-
} else if let Some(def_id) = tcx.interpret_interner
414-
.get_corresponding_static_def_id(*self) {
415-
AllocDiscriminant::ExternStatic.hash_stable(hcx, hasher);
416-
def_id.hash_stable(hcx, hasher);
417418
} else {
418419
bug!("no allocation for {}", self);
419420
}
@@ -532,7 +533,6 @@ for ::mir::interpret::EvalError<'gcx> {
532533
InvalidPointerMath |
533534
ReadUndefBytes |
534535
DeadLocal |
535-
ExecutionTimeLimitReached |
536536
StackFrameLimitReached |
537537
OutOfTls |
538538
TlsOutOfBounds |

src/librustc/mir/interpret/error.rs

-3
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ pub enum EvalErrorKind<'tcx> {
6565
Intrinsic(String),
6666
OverflowingMath,
6767
InvalidChar(u128),
68-
ExecutionTimeLimitReached,
6968
StackFrameLimitReached,
7069
OutOfTls,
7170
TlsOutOfBounds,
@@ -188,8 +187,6 @@ impl<'tcx> Error for EvalError<'tcx> {
188187
"mir not found",
189188
InvalidChar(..) =>
190189
"tried to interpret an invalid 32-bit value as a char",
191-
ExecutionTimeLimitReached =>
192-
"the expression was too complex to be evaluated or resulted in an infinite loop",
193190
StackFrameLimitReached =>
194191
"reached the configured maximum number of stack frames",
195192
OutOfTls =>

src/librustc/mir/interpret/mod.rs

+23-40
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,12 @@ pub struct AllocId(pub u64);
154154
impl ::rustc_serialize::UseSpecializedEncodable for AllocId {}
155155
impl ::rustc_serialize::UseSpecializedDecodable for AllocId {}
156156

157-
pub const ALLOC_DISCRIMINANT: usize = 0;
158-
pub const FN_DISCRIMINANT: usize = 1;
159-
pub const EXTERN_STATIC_DISCRIMINANT: usize = 2;
160-
pub const SHORTHAND_START: usize = 3;
157+
#[derive(RustcDecodable, RustcEncodable)]
158+
enum AllocKind {
159+
Alloc,
160+
Fn,
161+
Static,
162+
}
161163

162164
pub fn specialized_encode_alloc_id<
163165
'a, 'tcx,
@@ -166,26 +168,18 @@ pub fn specialized_encode_alloc_id<
166168
encoder: &mut E,
167169
tcx: TyCtxt<'a, 'tcx, 'tcx>,
168170
alloc_id: AllocId,
169-
shorthand: Option<usize>,
170171
) -> Result<(), E::Error> {
171-
if let Some(shorthand) = shorthand {
172-
return shorthand.encode(encoder);
173-
}
174172
if let Some(alloc) = tcx.interpret_interner.get_alloc(alloc_id) {
175173
trace!("encoding {:?} with {:#?}", alloc_id, alloc);
176-
ALLOC_DISCRIMINANT.encode(encoder)?;
174+
AllocKind::Alloc.encode(encoder)?;
177175
alloc.encode(encoder)?;
178-
// encode whether this allocation is the root allocation of a static
179-
tcx.interpret_interner
180-
.get_corresponding_static_def_id(alloc_id)
181-
.encode(encoder)?;
182176
} else if let Some(fn_instance) = tcx.interpret_interner.get_fn(alloc_id) {
183177
trace!("encoding {:?} with {:#?}", alloc_id, fn_instance);
184-
FN_DISCRIMINANT.encode(encoder)?;
178+
AllocKind::Fn.encode(encoder)?;
185179
fn_instance.encode(encoder)?;
186-
} else if let Some(did) = tcx.interpret_interner.get_corresponding_static_def_id(alloc_id) {
187-
// extern "C" statics don't have allocations, just encode its def_id
188-
EXTERN_STATIC_DISCRIMINANT.encode(encoder)?;
180+
} else if let Some(did) = tcx.interpret_interner.get_static(alloc_id) {
181+
// referring to statics doesn't need to know about their allocations, just about its DefId
182+
AllocKind::Static.encode(encoder)?;
189183
did.encode(encoder)?;
190184
} else {
191185
bug!("alloc id without corresponding allocation: {}", alloc_id);
@@ -196,53 +190,42 @@ pub fn specialized_encode_alloc_id<
196190
pub fn specialized_decode_alloc_id<
197191
'a, 'tcx,
198192
D: Decoder,
199-
CACHE: FnOnce(&mut D, usize, AllocId),
200-
SHORT: FnOnce(&mut D, usize) -> Result<AllocId, D::Error>
193+
CACHE: FnOnce(&mut D, AllocId),
201194
>(
202195
decoder: &mut D,
203196
tcx: TyCtxt<'a, 'tcx, 'tcx>,
204-
pos: usize,
205197
cache: CACHE,
206-
short: SHORT,
207198
) -> Result<AllocId, D::Error> {
208-
match usize::decode(decoder)? {
209-
ALLOC_DISCRIMINANT => {
199+
match AllocKind::decode(decoder)? {
200+
AllocKind::Alloc => {
210201
let alloc_id = tcx.interpret_interner.reserve();
211-
trace!("creating alloc id {:?} at {}", alloc_id, pos);
202+
trace!("creating alloc id {:?}", alloc_id);
212203
// insert early to allow recursive allocs
213-
cache(decoder, pos, alloc_id);
204+
cache(decoder, alloc_id);
214205

215206
let allocation = Allocation::decode(decoder)?;
216207
trace!("decoded alloc {:?} {:#?}", alloc_id, allocation);
217208
let allocation = tcx.intern_const_alloc(allocation);
218209
tcx.interpret_interner.intern_at_reserved(alloc_id, allocation);
219210

220-
if let Some(glob) = Option::<DefId>::decode(decoder)? {
221-
tcx.interpret_interner.cache(glob, alloc_id);
222-
}
223-
224211
Ok(alloc_id)
225212
},
226-
FN_DISCRIMINANT => {
227-
trace!("creating fn alloc id at {}", pos);
213+
AllocKind::Fn => {
214+
trace!("creating fn alloc id");
228215
let instance = ty::Instance::decode(decoder)?;
229216
trace!("decoded fn alloc instance: {:?}", instance);
230217
let id = tcx.interpret_interner.create_fn_alloc(instance);
231218
trace!("created fn alloc id: {:?}", id);
232-
cache(decoder, pos, id);
219+
cache(decoder, id);
233220
Ok(id)
234221
},
235-
EXTERN_STATIC_DISCRIMINANT => {
236-
trace!("creating extern static alloc id at {}", pos);
222+
AllocKind::Static => {
223+
trace!("creating extern static alloc id at");
237224
let did = DefId::decode(decoder)?;
238-
let alloc_id = tcx.interpret_interner.reserve();
239-
tcx.interpret_interner.cache(did, alloc_id);
225+
let alloc_id = tcx.interpret_interner.cache_static(did);
226+
cache(decoder, alloc_id);
240227
Ok(alloc_id)
241228
},
242-
shorthand => {
243-
trace!("loading shorthand {}", shorthand);
244-
short(decoder, shorthand)
245-
},
246229
}
247230
}
248231

src/librustc/session/mod.rs

-3
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ pub struct Session {
108108

109109
/// The maximum number of stackframes allowed in const eval
110110
pub const_eval_stack_frame_limit: Cell<usize>,
111-
/// The maximum number miri steps per constant
112-
pub const_eval_step_limit: Cell<usize>,
113111

114112
/// The metadata::creader module may inject an allocator/panic_runtime
115113
/// dependency if it didn't already find one, and this tracks what was
@@ -1146,7 +1144,6 @@ pub fn build_session_(
11461144
recursion_limit: Cell::new(64),
11471145
type_length_limit: Cell::new(1048576),
11481146
const_eval_stack_frame_limit: Cell::new(100),
1149-
const_eval_step_limit: Cell::new(1_000_000),
11501147
next_node_id: Cell::new(NodeId::new(1)),
11511148
injected_allocator: Cell::new(None),
11521149
allocator_kind: Cell::new(None),

src/librustc/ty/context.rs

+16-23
Original file line numberDiff line numberDiff line change
@@ -935,18 +935,16 @@ struct InterpretInternerInner<'tcx> {
935935
/// Allows obtaining const allocs via a unique identifier
936936
alloc_by_id: FxHashMap<interpret::AllocId, &'tcx interpret::Allocation>,
937937

938-
/// Reverse map of `alloc_cache`
939-
global_cache: FxHashMap<interpret::AllocId, DefId>,
938+
/// Allows obtaining static def ids via a unique id
939+
statics: FxHashMap<interpret::AllocId, DefId>,
940940

941941
/// The AllocId to assign to the next new regular allocation.
942942
/// Always incremented, never gets smaller.
943943
next_id: interpret::AllocId,
944944

945-
/// Allows checking whether a static already has an allocation
946-
///
947-
/// This is only important for detecting statics referring to themselves
948-
// FIXME(oli-obk) move it to the EvalContext?
949-
alloc_cache: FxHashMap<DefId, interpret::AllocId>,
945+
/// Inverse map of `statics`
946+
/// Used so we don't allocate a new pointer every time we need one
947+
static_cache: FxHashMap<DefId, interpret::AllocId>,
950948

951949
/// A cache for basic byte allocations keyed by their contents. This is used to deduplicate
952950
/// allocations for string and bytestring literals.
@@ -980,30 +978,25 @@ impl<'tcx> InterpretInterner<'tcx> {
980978
self.inner.borrow().alloc_by_id.get(&id).cloned()
981979
}
982980

983-
pub fn get_cached(
984-
&self,
985-
static_id: DefId,
986-
) -> Option<interpret::AllocId> {
987-
self.inner.borrow().alloc_cache.get(&static_id).cloned()
988-
}
989-
990-
pub fn cache(
981+
pub fn cache_static(
991982
&self,
992983
static_id: DefId,
993-
alloc_id: interpret::AllocId,
994-
) {
995-
let mut inner = self.inner.borrow_mut();
996-
inner.global_cache.insert(alloc_id, static_id);
997-
if let Some(old) = inner.alloc_cache.insert(static_id, alloc_id) {
998-
bug!("tried to cache {:?}, but was already existing as {:#?}", static_id, old);
984+
) -> interpret::AllocId {
985+
if let Some(alloc_id) = self.inner.borrow().static_cache.get(&static_id).cloned() {
986+
return alloc_id;
999987
}
988+
let alloc_id = self.reserve();
989+
let mut inner = self.inner.borrow_mut();
990+
inner.static_cache.insert(static_id, alloc_id);
991+
inner.statics.insert(alloc_id, static_id);
992+
alloc_id
1000993
}
1001994

1002-
pub fn get_corresponding_static_def_id(
995+
pub fn get_static(
1003996
&self,
1004997
ptr: interpret::AllocId,
1005998
) -> Option<DefId> {
1006-
self.inner.borrow().global_cache.get(&ptr).cloned()
999+
self.inner.borrow().statics.get(&ptr).cloned()
10071000
}
10081001

10091002
pub fn intern_at_reserved(

0 commit comments

Comments
 (0)