Skip to content

Commit 81a4c1d

Browse files
committed
Auto merge of rust-lang#2891 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 44de0ee + 97d3e4e commit 81a4c1d

File tree

203 files changed

+4783
-1588
lines changed

Some content is hidden

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

203 files changed

+4783
-1588
lines changed

Cargo.lock

+7-16
Original file line numberDiff line numberDiff line change
@@ -741,7 +741,7 @@ dependencies = [
741741
"tracing-subscriber",
742742
"unified-diff",
743743
"walkdir",
744-
"windows 0.46.0",
744+
"windows",
745745
]
746746

747747
[[package]]
@@ -1647,7 +1647,7 @@ dependencies = [
16471647
"iana-time-zone-haiku",
16481648
"js-sys",
16491649
"wasm-bindgen",
1650-
"windows 0.48.0",
1650+
"windows",
16511651
]
16521652

16531653
[[package]]
@@ -3259,7 +3259,7 @@ dependencies = [
32593259
"tempfile",
32603260
"thorin-dwp",
32613261
"tracing",
3262-
"windows 0.46.0",
3262+
"windows",
32633263
]
32643264

32653265
[[package]]
@@ -3315,7 +3315,7 @@ dependencies = [
33153315
"tempfile",
33163316
"thin-vec",
33173317
"tracing",
3318-
"windows 0.46.0",
3318+
"windows",
33193319
]
33203320

33213321
[[package]]
@@ -3376,7 +3376,7 @@ dependencies = [
33763376
"rustc_ty_utils",
33773377
"serde_json",
33783378
"tracing",
3379-
"windows 0.46.0",
3379+
"windows",
33803380
]
33813381

33823382
[[package]]
@@ -3426,7 +3426,7 @@ dependencies = [
34263426
"termize",
34273427
"tracing",
34283428
"unicode-width",
3429-
"windows 0.46.0",
3429+
"windows",
34303430
]
34313431

34323432
[[package]]
@@ -4096,7 +4096,7 @@ dependencies = [
40964096
"smallvec",
40974097
"termize",
40984098
"tracing",
4099-
"windows 0.46.0",
4099+
"windows",
41004100
]
41014101

41024102
[[package]]
@@ -5498,15 +5498,6 @@ version = "0.4.0"
54985498
source = "registry+https://github.com/rust-lang/crates.io-index"
54995499
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
55005500

5501-
[[package]]
5502-
name = "windows"
5503-
version = "0.46.0"
5504-
source = "registry+https://github.com/rust-lang/crates.io-index"
5505-
checksum = "cdacb41e6a96a052c6cb63a144f24900236121c6f63f4f8219fef5977ecb0c25"
5506-
dependencies = [
5507-
"windows-targets 0.42.2",
5508-
]
5509-
55105501
[[package]]
55115502
name = "windows"
55125503
version = "0.48.0"

compiler/rustc_borrowck/src/def_use.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub fn categorize(context: PlaceContext) -> Option<DefUse> {
5555
// `PlaceMention` and `AscribeUserType` both evaluate the place, which must not
5656
// contain dangling references.
5757
PlaceContext::NonMutatingUse(NonMutatingUseContext::PlaceMention) |
58-
PlaceContext::NonUse(NonUseContext::AscribeUserTy) |
58+
PlaceContext::NonUse(NonUseContext::AscribeUserTy(_)) |
5959

6060
PlaceContext::MutatingUse(MutatingUseContext::AddressOf) |
6161
PlaceContext::NonMutatingUse(NonMutatingUseContext::AddressOf) |

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
777777
Inspect | Copy | Move | PlaceMention | SharedBorrow | ShallowBorrow | UniqueBorrow
778778
| AddressOf | Projection,
779779
) => ty::Covariant,
780-
PlaceContext::NonUse(AscribeUserTy) => ty::Covariant,
780+
PlaceContext::NonUse(AscribeUserTy(variance)) => variance,
781781
}
782782
}
783783

compiler/rustc_builtin_macros/src/concat_idents.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn expand_concat_idents<'cx>(
1919
}
2020

2121
let mut res_str = String::new();
22-
for (i, e) in tts.into_trees().enumerate() {
22+
for (i, e) in tts.trees().enumerate() {
2323
if i & 1 == 1 {
2424
match e {
2525
TokenTree::Token(Token { kind: token::Comma, .. }, _) => {}

compiler/rustc_builtin_macros/src/trace_macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub fn expand_trace_macros(
88
sp: Span,
99
tt: TokenStream,
1010
) -> Box<dyn base::MacResult + 'static> {
11-
let mut cursor = tt.into_trees();
11+
let mut cursor = tt.trees();
1212
let mut err = false;
1313
let value = match &cursor.next() {
1414
Some(TokenTree::Token(token, _)) if token.is_keyword(kw::True) => true,

compiler/rustc_codegen_llvm/src/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ pub fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) ->
9494
// LLVM will prefix the name with `__imp_`. Ideally, we'd like the
9595
// existing logic below to set the Storage Class, but it has an
9696
// exemption for MinGW for backwards compatability.
97-
let llfn = cx.declare_fn(&common::i686_decorated_name(&dllimport, common::is_mingw_gnu_toolchain(&tcx.sess.target), true), fn_abi);
97+
let llfn = cx.declare_fn(&common::i686_decorated_name(&dllimport, common::is_mingw_gnu_toolchain(&tcx.sess.target), true), fn_abi, Some(instance));
9898
unsafe { llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport); }
9999
llfn
100100
} else {
101-
cx.declare_fn(sym, fn_abi)
101+
cx.declare_fn(sym, fn_abi, Some(instance))
102102
};
103103
debug!("get_fn: not casting pointer!");
104104

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance<
207207
)),
208208
ty::List::empty(),
209209
),
210+
None,
210211
);
211212

212213
llvm::set_linkage(llfn, llvm::Linkage::PrivateLinkage);

compiler/rustc_codegen_llvm/src/declare.rs

+47-17
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@ use crate::llvm::AttributePlace::Function;
1919
use crate::type_::Type;
2020
use crate::value::Value;
2121
use rustc_codegen_ssa::traits::TypeMembershipMethods;
22-
use rustc_middle::ty::Ty;
23-
use rustc_symbol_mangling::typeid::{kcfi_typeid_for_fnabi, typeid_for_fnabi, TypeIdOptions};
22+
use rustc_middle::ty::{Instance, Ty};
23+
use rustc_symbol_mangling::typeid::{
24+
kcfi_typeid_for_fnabi, kcfi_typeid_for_instance, typeid_for_fnabi, typeid_for_instance,
25+
TypeIdOptions,
26+
};
2427
use smallvec::SmallVec;
2528

2629
/// Declare a function.
@@ -116,7 +119,12 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
116119
///
117120
/// If there’s a value with the same name already declared, the function will
118121
/// update the declaration and return existing Value instead.
119-
pub fn declare_fn(&self, name: &str, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> &'ll Value {
122+
pub fn declare_fn(
123+
&self,
124+
name: &str,
125+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
126+
instance: Option<Instance<'tcx>>,
127+
) -> &'ll Value {
120128
debug!("declare_rust_fn(name={:?}, fn_abi={:?})", name, fn_abi);
121129

122130
// Function addresses in Rust are never significant, allowing functions to
@@ -132,18 +140,35 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
132140
fn_abi.apply_attrs_llfn(self, llfn);
133141

134142
if self.tcx.sess.is_sanitizer_cfi_enabled() {
135-
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::empty());
136-
self.set_type_metadata(llfn, typeid);
137-
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::GENERALIZE_POINTERS);
138-
self.add_type_metadata(llfn, typeid);
139-
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::NORMALIZE_INTEGERS);
140-
self.add_type_metadata(llfn, typeid);
141-
let typeid = typeid_for_fnabi(
142-
self.tcx,
143-
fn_abi,
144-
TypeIdOptions::GENERALIZE_POINTERS | TypeIdOptions::NORMALIZE_INTEGERS,
145-
);
146-
self.add_type_metadata(llfn, typeid);
143+
if let Some(instance) = instance {
144+
let typeid = typeid_for_instance(self.tcx, &instance, TypeIdOptions::empty());
145+
self.set_type_metadata(llfn, typeid);
146+
let typeid =
147+
typeid_for_instance(self.tcx, &instance, TypeIdOptions::GENERALIZE_POINTERS);
148+
self.add_type_metadata(llfn, typeid);
149+
let typeid =
150+
typeid_for_instance(self.tcx, &instance, TypeIdOptions::NORMALIZE_INTEGERS);
151+
self.add_type_metadata(llfn, typeid);
152+
let typeid = typeid_for_instance(
153+
self.tcx,
154+
&instance,
155+
TypeIdOptions::GENERALIZE_POINTERS | TypeIdOptions::NORMALIZE_INTEGERS,
156+
);
157+
self.add_type_metadata(llfn, typeid);
158+
} else {
159+
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::empty());
160+
self.set_type_metadata(llfn, typeid);
161+
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::GENERALIZE_POINTERS);
162+
self.add_type_metadata(llfn, typeid);
163+
let typeid = typeid_for_fnabi(self.tcx, fn_abi, TypeIdOptions::NORMALIZE_INTEGERS);
164+
self.add_type_metadata(llfn, typeid);
165+
let typeid = typeid_for_fnabi(
166+
self.tcx,
167+
fn_abi,
168+
TypeIdOptions::GENERALIZE_POINTERS | TypeIdOptions::NORMALIZE_INTEGERS,
169+
);
170+
self.add_type_metadata(llfn, typeid);
171+
}
147172
}
148173

149174
if self.tcx.sess.is_sanitizer_kcfi_enabled() {
@@ -156,8 +181,13 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> {
156181
options.insert(TypeIdOptions::NORMALIZE_INTEGERS);
157182
}
158183

159-
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi, options);
160-
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
184+
if let Some(instance) = instance {
185+
let kcfi_typeid = kcfi_typeid_for_instance(self.tcx, &instance, options);
186+
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
187+
} else {
188+
let kcfi_typeid = kcfi_typeid_for_fnabi(self.tcx, fn_abi, options);
189+
self.set_kcfi_type_metadata(llfn, kcfi_typeid);
190+
}
161191
}
162192

163193
llfn

compiler/rustc_codegen_llvm/src/intrinsic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,7 @@ fn gen_fn<'ll, 'tcx>(
772772
) -> (&'ll Type, &'ll Value) {
773773
let fn_abi = cx.fn_abi_of_fn_ptr(rust_fn_sig, ty::List::empty());
774774
let llty = fn_abi.llvm_type(cx);
775-
let llfn = cx.declare_fn(name, fn_abi);
775+
let llfn = cx.declare_fn(name, fn_abi, None);
776776
cx.set_frame_pointer_type(llfn);
777777
cx.apply_target_cpu_attr(llfn);
778778
// FIXME(eddyb) find a nicer way to do this.

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,9 @@ pub type InlineAsmDiagHandlerTy = unsafe extern "C" fn(&SMDiagnostic, *const c_v
680680
pub mod coverageinfo {
681681
use super::coverage_map;
682682

683-
/// Aligns with [llvm::coverage::CounterMappingRegion::RegionKind](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L209-L230)
683+
/// Corresponds to enum `llvm::coverage::CounterMappingRegion::RegionKind`.
684+
///
685+
/// Must match the layout of `LLVMRustCounterMappingRegionKind`.
684686
#[derive(Copy, Clone, Debug)]
685687
#[repr(C)]
686688
pub enum RegionKind {
@@ -714,7 +716,9 @@ pub mod coverageinfo {
714716
/// array", encoded separately), and source location (start and end positions of the represented
715717
/// code region).
716718
///
717-
/// Matches LLVMRustCounterMappingRegion.
719+
/// Corresponds to struct `llvm::coverage::CounterMappingRegion`.
720+
///
721+
/// Must match the layout of `LLVMRustCounterMappingRegion`.
718722
#[derive(Copy, Clone, Debug)]
719723
#[repr(C)]
720724
pub struct CounterMappingRegion {

compiler/rustc_codegen_llvm/src/mono_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'_, 'tcx> {
5151
assert!(!instance.substs.has_infer());
5252

5353
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
54-
let lldecl = self.declare_fn(symbol_name, fn_abi);
54+
let lldecl = self.declare_fn(symbol_name, fn_abi, Some(instance));
5555
unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) };
5656
let attrs = self.tcx.codegen_fn_attrs(instance.def_id());
5757
base::set_link_section(lldecl, attrs);

compiler/rustc_codegen_ssa/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@ default-features = false
5151
features = ["read_core", "elf", "macho", "pe", "unaligned", "archive", "write"]
5252

5353
[target.'cfg(windows)'.dependencies.windows]
54-
version = "0.46.0"
54+
version = "0.48.0"
5555
features = ["Win32_Globalization"]

compiler/rustc_codegen_ssa/src/back/link.rs

+70-5
Original file line numberDiff line numberDiff line change
@@ -546,12 +546,38 @@ fn link_staticlib<'a>(
546546

547547
ab.build(out_filename);
548548

549-
if !all_native_libs.is_empty() {
550-
if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
551-
print_native_static_libs(sess, &all_native_libs);
549+
let crates = codegen_results.crate_info.used_crates.iter();
550+
551+
let fmts = codegen_results
552+
.crate_info
553+
.dependency_formats
554+
.iter()
555+
.find_map(|&(ty, ref list)| if ty == CrateType::Staticlib { Some(list) } else { None })
556+
.expect("no dependency formats for staticlib");
557+
558+
let mut all_rust_dylibs = vec![];
559+
for &cnum in crates {
560+
match fmts.get(cnum.as_usize() - 1) {
561+
Some(&Linkage::Dynamic) => {}
562+
_ => continue,
563+
}
564+
let crate_name = codegen_results.crate_info.crate_name[&cnum];
565+
let used_crate_source = &codegen_results.crate_info.used_crate_source[&cnum];
566+
if let Some((path, _)) = &used_crate_source.dylib {
567+
all_rust_dylibs.push(&**path);
568+
} else {
569+
if used_crate_source.rmeta.is_some() {
570+
sess.emit_fatal(errors::LinkRlibError::OnlyRmetaFound { crate_name });
571+
} else {
572+
sess.emit_fatal(errors::LinkRlibError::NotFound { crate_name });
573+
}
552574
}
553575
}
554576

577+
if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
578+
print_native_static_libs(sess, &all_native_libs, &all_rust_dylibs);
579+
}
580+
555581
Ok(())
556582
}
557583

@@ -1370,8 +1396,12 @@ enum RlibFlavor {
13701396
StaticlibBase,
13711397
}
13721398

1373-
fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
1374-
let lib_args: Vec<_> = all_native_libs
1399+
fn print_native_static_libs(
1400+
sess: &Session,
1401+
all_native_libs: &[NativeLib],
1402+
all_rust_dylibs: &[&Path],
1403+
) {
1404+
let mut lib_args: Vec<_> = all_native_libs
13751405
.iter()
13761406
.filter(|l| relevant_lib(sess, l))
13771407
.filter_map(|lib| {
@@ -1401,6 +1431,41 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
14011431
}
14021432
})
14031433
.collect();
1434+
for path in all_rust_dylibs {
1435+
// FIXME deduplicate with add_dynamic_crate
1436+
1437+
// Just need to tell the linker about where the library lives and
1438+
// what its name is
1439+
let parent = path.parent();
1440+
if let Some(dir) = parent {
1441+
let dir = fix_windows_verbatim_for_gcc(dir);
1442+
if sess.target.is_like_msvc {
1443+
let mut arg = String::from("/LIBPATH:");
1444+
arg.push_str(&dir.display().to_string());
1445+
lib_args.push(arg);
1446+
} else {
1447+
lib_args.push("-L".to_owned());
1448+
lib_args.push(dir.display().to_string());
1449+
}
1450+
}
1451+
let stem = path.file_stem().unwrap().to_str().unwrap();
1452+
// Convert library file-stem into a cc -l argument.
1453+
let prefix = if stem.starts_with("lib") && !sess.target.is_like_windows { 3 } else { 0 };
1454+
let lib = &stem[prefix..];
1455+
let path = parent.unwrap_or_else(|| Path::new(""));
1456+
if sess.target.is_like_msvc {
1457+
// When producing a dll, the MSVC linker may not actually emit a
1458+
// `foo.lib` file if the dll doesn't actually export any symbols, so we
1459+
// check to see if the file is there and just omit linking to it if it's
1460+
// not present.
1461+
let name = format!("{}.dll.lib", lib);
1462+
if path.join(&name).exists() {
1463+
lib_args.push(name);
1464+
}
1465+
} else {
1466+
lib_args.push(format!("-l{}", lib));
1467+
}
1468+
}
14041469
if !lib_args.is_empty() {
14051470
sess.emit_note(errors::StaticLibraryNativeArtifacts);
14061471
// Prefix for greppability

0 commit comments

Comments
 (0)