Skip to content

Commit e369d87

Browse files
committed
Auto merge of #65422 - tmandry:rollup-r5u3mlc, r=tmandry
Rollup of 10 pull requests Successful merges: - #65170 (rustc_metadata: Privatize private code and remove dead code) - #65260 (Optimize `LexicalResolve::expansion`.) - #65261 (Remove `Option` from `TokenStream`) - #65332 (std::fmt: reorder docs) - #65340 (Several changes to the codegen backend organization) - #65365 (Include const generic arguments in metadata) - #65398 (Bring attention to suggestions when the only difference is capitalization) - #65410 (syntax: add parser recovery for intersection- / and-patterns `p1 @ p2`) - #65415 (Remove an outdated test output file) - #65416 (Minor sync changes) Failed merges: r? @ghost
2 parents e413dc3 + 9422feb commit e369d87

File tree

98 files changed

+1099
-1049
lines changed

Some content is hidden

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

98 files changed

+1099
-1049
lines changed

src/liballoc/fmt.rs

+175-191
Large diffs are not rendered by default.

src/librustc/infer/lexical_region_resolve/mod.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
304304
}
305305

306306
fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
307-
self.iterate_until_fixed_point("Expansion", |constraint| {
307+
self.iterate_until_fixed_point(|constraint| {
308308
debug!("expansion: constraint={:?}", constraint);
309309
let (a_region, b_vid, b_data, retain) = match *constraint {
310310
Constraint::RegSubVar(a_region, b_vid) => {
@@ -360,13 +360,21 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
360360
match *b_data {
361361
VarValue::Value(cur_region) => {
362362
// Identical scopes can show up quite often, if the fixed point
363-
// iteration converges slowly, skip them
363+
// iteration converges slowly. Skip them. This is purely an
364+
// optimization.
364365
if let (ReScope(a_scope), ReScope(cur_scope)) = (a_region, cur_region) {
365366
if a_scope == cur_scope {
366367
return false;
367368
}
368369
}
369370

371+
// This is a specialized version of the `lub_concrete_regions`
372+
// check below for a common case, here purely as an
373+
// optimization.
374+
if let ReEmpty = a_region {
375+
return false;
376+
}
377+
370378
let mut lub = self.lub_concrete_regions(a_region, cur_region);
371379
if lub == cur_region {
372380
return false;
@@ -407,8 +415,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
407415

408416
/// Returns the smallest region `c` such that `a <= c` and `b <= c`.
409417
fn lub_concrete_regions(&self, a: Region<'tcx>, b: Region<'tcx>) -> Region<'tcx> {
410-
let tcx = self.tcx();
411-
412418
match (a, b) {
413419
(&ty::ReClosureBound(..), _)
414420
| (_, &ty::ReClosureBound(..))
@@ -468,15 +474,15 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
468474

469475
// otherwise, we don't know what the free region is,
470476
// so we must conservatively say the LUB is static:
471-
tcx.lifetimes.re_static
477+
self.tcx().lifetimes.re_static
472478
}
473479

474480
(&ReScope(a_id), &ReScope(b_id)) => {
475481
// The region corresponding to an outer block is a
476482
// subtype of the region corresponding to an inner
477483
// block.
478484
let lub = self.region_rels.region_scope_tree.nearest_common_ancestor(a_id, b_id);
479-
tcx.mk_region(ReScope(lub))
485+
self.tcx().mk_region(ReScope(lub))
480486
}
481487

482488
(&ReEarlyBound(_), &ReEarlyBound(_))
@@ -490,7 +496,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
490496
if a == b {
491497
a
492498
} else {
493-
tcx.lifetimes.re_static
499+
self.tcx().lifetimes.re_static
494500
}
495501
}
496502
}
@@ -860,7 +866,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
860866
}
861867
}
862868

863-
fn iterate_until_fixed_point<F>(&self, tag: &str, mut body: F)
869+
fn iterate_until_fixed_point<F>(&self, mut body: F)
864870
where
865871
F: FnMut(&Constraint<'tcx>) -> (bool, bool),
866872
{
@@ -870,7 +876,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
870876
while changed {
871877
changed = false;
872878
iteration += 1;
873-
debug!("---- {} Iteration {}{}", "#", tag, iteration);
879+
debug!("---- Expansion iteration {}", iteration);
874880
constraints.retain(|constraint| {
875881
let (edge_changed, retain) = body(constraint);
876882
if edge_changed {
@@ -880,7 +886,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
880886
retain
881887
});
882888
}
883-
debug!("---- {} Complete after {} iteration(s)", tag, iteration);
889+
debug!("---- Expansion complete after {} iteration(s)", iteration);
884890
}
885891

886892
fn bound_is_met(

src/librustc/middle/cstore.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ pub struct CrateSource {
3232
pub rmeta: Option<(PathBuf, PathKind)>,
3333
}
3434

35+
impl CrateSource {
36+
pub fn paths(&self) -> impl Iterator<Item = &PathBuf> {
37+
self.dylib.iter().chain(self.rlib.iter()).chain(self.rmeta.iter()).map(|p| &p.0)
38+
}
39+
}
40+
3541
#[derive(RustcEncodable, RustcDecodable, Copy, Clone,
3642
Ord, PartialOrd, Eq, PartialEq, Debug, HashStable)]
3743
pub enum DepKind {
@@ -208,7 +214,6 @@ pub trait CrateStore {
208214
fn crate_is_private_dep_untracked(&self, cnum: CrateNum) -> bool;
209215
fn crate_disambiguator_untracked(&self, cnum: CrateNum) -> CrateDisambiguator;
210216
fn crate_hash_untracked(&self, cnum: CrateNum) -> Svh;
211-
fn extern_mod_stmt_cnum_untracked(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
212217
fn item_generics_cloned_untracked(&self, def: DefId, sess: &Session) -> ty::Generics;
213218
fn postorder_cnums_untracked(&self) -> Vec<CrateNum>;
214219

src/librustc/session/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use syntax::feature_gate::UnstableFeatures;
2323
use syntax::source_map::SourceMap;
2424

2525
use errors::emitter::HumanReadableErrorType;
26-
use errors::{ColorConfig, FatalError, Handler};
26+
use errors::{ColorConfig, FatalError, Handler, SourceMapperDyn};
2727

2828
use getopts;
2929

@@ -1857,6 +1857,7 @@ struct NullEmitter;
18571857

18581858
impl errors::emitter::Emitter for NullEmitter {
18591859
fn emit_diagnostic(&mut self, _: &errors::Diagnostic) {}
1860+
fn source_map(&self) -> Option<&Lrc<SourceMapperDyn>> { None }
18601861
}
18611862

18621863
// Converts strings provided as `--cfg [cfgspec]` into a `crate_cfg`.

src/librustc/ty/context.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use crate::ty::subst::{UserSubsts, GenericArgKind};
4343
use crate::ty::{BoundVar, BindingMode};
4444
use crate::ty::CanonicalPolyFnSig;
4545
use crate::util::common::ErrorReported;
46-
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet};
46+
use crate::util::nodemap::{DefIdMap, DefIdSet, ItemLocalMap, ItemLocalSet, NodeMap};
4747
use crate::util::nodemap::{FxHashMap, FxHashSet};
4848
use crate::util::profiling::SelfProfilerRef;
4949

@@ -1051,6 +1051,9 @@ pub struct GlobalCtxt<'tcx> {
10511051
/// Common consts, pre-interned for your convenience.
10521052
pub consts: CommonConsts<'tcx>,
10531053

1054+
/// Resolutions of `extern crate` items produced by resolver.
1055+
extern_crate_map: NodeMap<CrateNum>,
1056+
10541057
/// Map indicating what traits are in scope for places where this
10551058
/// is relevant; generated by resolve.
10561059
trait_map: FxHashMap<DefIndex,
@@ -1274,6 +1277,7 @@ impl<'tcx> TyCtxt<'tcx> {
12741277
types: common_types,
12751278
lifetimes: common_lifetimes,
12761279
consts: common_consts,
1280+
extern_crate_map: resolutions.extern_crate_map,
12771281
trait_map,
12781282
export_map: resolutions.export_map.into_iter().map(|(k, v)| {
12791283
let exports: Vec<_> = v.into_iter().map(|e| {
@@ -2951,7 +2955,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
29512955
};
29522956
providers.extern_mod_stmt_cnum = |tcx, id| {
29532957
let id = tcx.hir().as_local_node_id(id).unwrap();
2954-
tcx.cstore.extern_mod_stmt_cnum_untracked(id)
2958+
tcx.extern_crate_map.get(&id).cloned()
29552959
};
29562960
providers.all_crate_nums = |tcx, cnum| {
29572961
assert_eq!(cnum, LOCAL_CRATE);

src/librustc/ty/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::ty::subst::{Subst, InternalSubsts, SubstsRef};
2828
use crate::ty::util::{IntTypeExt, Discr};
2929
use crate::ty::walk::TypeWalker;
3030
use crate::util::captures::Captures;
31-
use crate::util::nodemap::{NodeSet, DefIdMap, FxHashMap};
31+
use crate::util::nodemap::{NodeMap, NodeSet, DefIdMap, FxHashMap};
3232
use arena::SyncDroplessArena;
3333
use crate::session::DataTypeKind;
3434

@@ -121,6 +121,7 @@ mod sty;
121121

122122
#[derive(Clone)]
123123
pub struct Resolutions {
124+
pub extern_crate_map: NodeMap<CrateNum>,
124125
pub trait_map: TraitMap,
125126
pub maybe_unused_trait_imports: NodeSet,
126127
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,

src/librustc_codegen_llvm/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ const UNNAMED: *const c_char = EMPTY_C_STR.as_ptr();
5252

5353
impl BackendTypes for Builder<'_, 'll, 'tcx> {
5454
type Value = <CodegenCx<'ll, 'tcx> as BackendTypes>::Value;
55+
type Function = <CodegenCx<'ll, 'tcx> as BackendTypes>::Function;
5556
type BasicBlock = <CodegenCx<'ll, 'tcx> as BackendTypes>::BasicBlock;
5657
type Type = <CodegenCx<'ll, 'tcx> as BackendTypes>::Type;
5758
type Funclet = <CodegenCx<'ll, 'tcx> as BackendTypes>::Funclet;

src/librustc_codegen_llvm/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn get_fn(
3333
assert!(!instance.substs.has_param_types());
3434

3535
let sig = instance.fn_sig(cx.tcx());
36-
if let Some(&llfn) = cx.instances().borrow().get(&instance) {
36+
if let Some(&llfn) = cx.instances.borrow().get(&instance) {
3737
return llfn;
3838
}
3939

src/librustc_codegen_llvm/common.rs

+20-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//! Code that is useful in various codegen modules.
44
5-
use crate::llvm::{self, True, False, Bool, BasicBlock, OperandBundleDef};
5+
use crate::llvm::{self, True, False, Bool, BasicBlock, OperandBundleDef, ConstantInt};
66
use crate::abi;
77
use crate::consts;
88
use crate::type_::Type;
@@ -86,6 +86,8 @@ impl Funclet<'ll> {
8686

8787
impl BackendTypes for CodegenCx<'ll, 'tcx> {
8888
type Value = &'ll Value;
89+
type Function = &'ll Value;
90+
8991
type BasicBlock = &'ll BasicBlock;
9092
type Type = &'ll Type;
9193
type Funclet = Funclet<'ll>;
@@ -243,33 +245,23 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
243245
struct_in_context(self.llcx, elts, packed)
244246
}
245247

246-
fn const_to_uint(&self, v: &'ll Value) -> u64 {
247-
unsafe {
248+
fn const_to_opt_uint(&self, v: &'ll Value) -> Option<u64> {
249+
try_as_const_integral(v).map(|v| unsafe {
248250
llvm::LLVMConstIntGetZExtValue(v)
249-
}
250-
}
251-
252-
fn is_const_integral(&self, v: &'ll Value) -> bool {
253-
unsafe {
254-
llvm::LLVMIsAConstantInt(v).is_some()
255-
}
251+
})
256252
}
257253

258254
fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option<u128> {
259-
unsafe {
260-
if self.is_const_integral(v) {
261-
let (mut lo, mut hi) = (0u64, 0u64);
262-
let success = llvm::LLVMRustConstInt128Get(v, sign_ext,
263-
&mut hi, &mut lo);
264-
if success {
265-
Some(hi_lo_to_u128(lo, hi))
266-
} else {
267-
None
268-
}
255+
try_as_const_integral(v).and_then(|v| unsafe {
256+
let (mut lo, mut hi) = (0u64, 0u64);
257+
let success = llvm::LLVMRustConstInt128Get(v, sign_ext,
258+
&mut hi, &mut lo);
259+
if success {
260+
Some(hi_lo_to_u128(lo, hi))
269261
} else {
270262
None
271263
}
272-
}
264+
})
273265
}
274266

275267
fn scalar_to_backend(
@@ -305,7 +297,7 @@ impl ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
305297
}
306298
}
307299
Some(GlobalAlloc::Function(fn_instance)) => {
308-
self.get_fn(fn_instance)
300+
self.get_fn_addr(fn_instance)
309301
}
310302
Some(GlobalAlloc::Static(def_id)) => {
311303
assert!(self.tcx.is_static(def_id));
@@ -386,3 +378,9 @@ pub fn struct_in_context(
386378
fn hi_lo_to_u128(lo: u64, hi: u64) -> u128 {
387379
((hi as u128) << 64) | (lo as u128)
388380
}
381+
382+
fn try_as_const_integral(v: &'ll Value) -> Option<&'ll ConstantInt> {
383+
unsafe {
384+
llvm::LLVMIsAConstantInt(v)
385+
}
386+
}

src/librustc_codegen_llvm/context.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use rustc::ty::layout::{
2020
use rustc::ty::{self, Ty, TyCtxt, Instance};
2121
use rustc::util::nodemap::FxHashMap;
2222
use rustc_target::spec::{HasTargetSpec, Target};
23-
use rustc_codegen_ssa::callee::resolve_and_get_fn;
2423
use rustc_codegen_ssa::base::wants_msvc_seh;
2524
use crate::callee::get_fn;
2625

@@ -327,11 +326,11 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
327326
&self.vtables
328327
}
329328

330-
fn instances(&self) -> &RefCell<FxHashMap<Instance<'tcx>, &'ll Value>> {
331-
&self.instances
329+
fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value {
330+
get_fn(self, instance)
332331
}
333332

334-
fn get_fn(&self, instance: Instance<'tcx>) -> &'ll Value {
333+
fn get_fn_addr(&self, instance: Instance<'tcx>) -> &'ll Value {
335334
get_fn(self, instance)
336335
}
337336

@@ -362,7 +361,14 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
362361
let tcx = self.tcx;
363362
let llfn = match tcx.lang_items().eh_personality() {
364363
Some(def_id) if !wants_msvc_seh(self.sess()) => {
365-
resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]))
364+
self.get_fn_addr(
365+
ty::Instance::resolve(
366+
tcx,
367+
ty::ParamEnv::reveal_all(),
368+
def_id,
369+
tcx.intern_substs(&[]),
370+
).unwrap()
371+
)
366372
}
367373
_ => {
368374
let name = if wants_msvc_seh(self.sess()) {
@@ -390,7 +396,14 @@ impl MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> {
390396
let tcx = self.tcx;
391397
assert!(self.sess().target.target.options.custom_unwind_resume);
392398
if let Some(def_id) = tcx.lang_items().eh_unwind_resume() {
393-
let llfn = resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]));
399+
let llfn = self.get_fn_addr(
400+
ty::Instance::resolve(
401+
tcx,
402+
ty::ParamEnv::reveal_all(),
403+
def_id,
404+
tcx.intern_substs(&[]),
405+
).unwrap()
406+
);
394407
unwresume.set(Some(llfn));
395408
return llfn;
396409
}

src/librustc_codegen_llvm/error_codes.rs

-38
This file was deleted.

src/librustc_codegen_llvm/intrinsic.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
2020
use rustc::hir;
2121
use syntax::ast::{self, FloatTy};
2222

23+
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
2324
use rustc_codegen_ssa::traits::*;
2425

25-
use rustc::session::Session;
2626
use syntax_pos::Span;
2727

2828
use std::cmp::Ordering;
@@ -1026,10 +1026,6 @@ fn get_rust_try_fn<'ll, 'tcx>(
10261026
rust_try
10271027
}
10281028

1029-
fn span_invalid_monomorphization_error(a: &Session, b: Span, c: &str) {
1030-
span_err!(a, b, E0511, "{}", c);
1031-
}
1032-
10331029
fn generic_simd_intrinsic(
10341030
bx: &mut Builder<'a, 'll, 'tcx>,
10351031
name: &str,

0 commit comments

Comments
 (0)