Skip to content

Commit 0d7ed3b

Browse files
committed
Auto merge of #110214 - compiler-errors:rollup-mkig4t6, r=compiler-errors
Rollup of 10 pull requests Successful merges: - #96971 (Initial support for loongarch64-unknown-linux-gnu) - #109894 (Remove Errors section from var_os docs) - #110000 (Rename tests/ui/unique to tests/ui/box/unit) - #110018 (Pass host linker to compiletest.) - #110104 ( Reword the docstring in todo! macro definition, fixing a typo) - #110113 (Fix `x test ui --target foo` when download-rustc is enabled) - #110126 (Support safe transmute in new solver) - #110155 (Fix typos in librustdoc, tools and config files) - #110162 (rustdoc: remove redundant expandSection code from main.js) - #110173 (kmc-solid: Implement `Socket::read_buf`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 13d1802 + 4c9cd9e commit 0d7ed3b

File tree

110 files changed

+1460
-243
lines changed

Some content is hidden

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

110 files changed

+1460
-243
lines changed

compiler/rustc_codegen_gcc/example/alloc_system.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
const MIN_ALIGN: usize = 8;
1616
#[cfg(any(target_arch = "x86_64",
1717
target_arch = "aarch64",
18+
target_arch = "loongarch64",
1819
target_arch = "mips64",
1920
target_arch = "s390x",
2021
target_arch = "sparc64"))]

compiler/rustc_codegen_ssa/src/back/metadata.rs

+5
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
127127
"msp430" => Architecture::Msp430,
128128
"hexagon" => Architecture::Hexagon,
129129
"bpf" => Architecture::Bpf,
130+
"loongarch64" => Architecture::LoongArch64,
130131
// Unsupported architecture.
131132
_ => return None,
132133
};
@@ -190,6 +191,10 @@ pub(crate) fn create_object_file(sess: &Session) -> Option<write::Object<'static
190191
}
191192
e_flags
192193
}
194+
Architecture::LoongArch64 => {
195+
// Source: https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_e_flags_identifies_abi_type_and_version
196+
elf::EF_LARCH_OBJABI_V1 | elf::EF_LARCH_ABI_DOUBLE_FLOAT
197+
}
193198
_ => 0,
194199
};
195200
// adapted from LLVM's `MCELFObjectTargetWriter::getOSABI`

compiler/rustc_llvm/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const OPTIONAL_COMPONENTS: &[&str] = &[
1010
"aarch64",
1111
"amdgpu",
1212
"avr",
13+
"loongarch",
1314
"m68k",
1415
"mips",
1516
"powerpc",

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) {
146146
#define SUBTARGET_HEXAGON
147147
#endif
148148

149+
#ifdef LLVM_COMPONENT_LOONGARCH
150+
#define SUBTARGET_LOONGARCH SUBTARGET(LoongArch)
151+
#else
152+
#define SUBTARGET_LOONGARCH
153+
#endif
154+
149155
#define GEN_SUBTARGETS \
150156
SUBTARGET_X86 \
151157
SUBTARGET_ARM \
@@ -159,6 +165,7 @@ extern "C" void LLVMTimeTraceProfilerFinish(const char* FileName) {
159165
SUBTARGET_SPARC \
160166
SUBTARGET_HEXAGON \
161167
SUBTARGET_RISCV \
168+
SUBTARGET_LOONGARCH \
162169

163170
#define SUBTARGET(x) \
164171
namespace llvm { \

compiler/rustc_llvm/src/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ pub fn initialize_available_targets() {
102102
LLVMInitializeM68kAsmPrinter,
103103
LLVMInitializeM68kAsmParser
104104
);
105+
init_target!(
106+
llvm_component = "loongarch",
107+
LLVMInitializeLoongArchTargetInfo,
108+
LLVMInitializeLoongArchTarget,
109+
LLVMInitializeLoongArchTargetMC,
110+
LLVMInitializeLoongArchAsmPrinter,
111+
LLVMInitializeLoongArchAsmParser
112+
);
105113
init_target!(
106114
llvm_component = "mips",
107115
LLVMInitializeMipsTargetInfo,

compiler/rustc_middle/src/ty/visit.rs

+3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ pub trait TypeVisitableExt<'tcx>: TypeVisitable<TyCtxt<'tcx>> {
8383
| TypeFlags::HAS_CT_PLACEHOLDER,
8484
)
8585
}
86+
fn has_non_region_placeholders(&self) -> bool {
87+
self.has_type_flags(TypeFlags::HAS_TY_PLACEHOLDER | TypeFlags::HAS_CT_PLACEHOLDER)
88+
}
8689
fn needs_subst(&self) -> bool {
8790
self.has_type_flags(TypeFlags::NEEDS_SUBST)
8891
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use crate::spec::{Target, TargetOptions};
2+
3+
pub fn target() -> Target {
4+
Target {
5+
llvm_target: "loongarch64-unknown-linux-gnu".into(),
6+
pointer_width: 64,
7+
data_layout: "e-m:e-p:64:64-i64:64-i128:128-n64-S128".into(),
8+
arch: "loongarch64".into(),
9+
options: TargetOptions {
10+
cpu: "generic".into(),
11+
features: "+f,+d".into(),
12+
llvm_abiname: "lp64d".into(),
13+
max_atomic_width: Some(64),
14+
..super::linux_gnu_base::opts()
15+
},
16+
}
17+
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,7 @@ supported_targets! {
10211021
("x86_64-unknown-linux-gnux32", x86_64_unknown_linux_gnux32),
10221022
("i686-unknown-linux-gnu", i686_unknown_linux_gnu),
10231023
("i586-unknown-linux-gnu", i586_unknown_linux_gnu),
1024+
("loongarch64-unknown-linux-gnu", loongarch64_unknown_linux_gnu),
10241025
("m68k-unknown-linux-gnu", m68k_unknown_linux_gnu),
10251026
("mips-unknown-linux-gnu", mips_unknown_linux_gnu),
10261027
("mips64-unknown-linux-gnuabi64", mips64_unknown_linux_gnuabi64),

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<TyCtxt<'tcx>> + Copy + Eq {
225225
ecx: &mut EvalCtxt<'_, 'tcx>,
226226
goal: Goal<'tcx, Self>,
227227
) -> QueryResult<'tcx>;
228+
229+
fn consider_builtin_transmute_candidate(
230+
ecx: &mut EvalCtxt<'_, 'tcx>,
231+
goal: Goal<'tcx, Self>,
232+
) -> QueryResult<'tcx>;
228233
}
229234

230235
impl<'tcx> EvalCtxt<'_, 'tcx> {
@@ -373,6 +378,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
373378
G::consider_builtin_discriminant_kind_candidate(self, goal)
374379
} else if lang_items.destruct_trait() == Some(trait_def_id) {
375380
G::consider_builtin_destruct_candidate(self, goal)
381+
} else if lang_items.transmute_trait() == Some(trait_def_id) {
382+
G::consider_builtin_transmute_candidate(self, goal)
376383
} else {
377384
Err(NoSolution)
378385
};

compiler/rustc_trait_selection/src/solve/eval_ctxt.rs

+21
Original file line numberDiff line numberDiff line change
@@ -639,4 +639,25 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
639639
crate::traits::wf::unnormalized_obligations(self.infcx, param_env, arg)
640640
.map(|obligations| obligations.into_iter().map(|obligation| obligation.into()))
641641
}
642+
643+
pub(super) fn is_transmutable(
644+
&self,
645+
src_and_dst: rustc_transmute::Types<'tcx>,
646+
scope: Ty<'tcx>,
647+
assume: rustc_transmute::Assume,
648+
) -> Result<Certainty, NoSolution> {
649+
// FIXME(transmutability): This really should be returning nested goals for `Answer::If*`
650+
match rustc_transmute::TransmuteTypeEnv::new(self.infcx).is_transmutable(
651+
ObligationCause::dummy(),
652+
ty::Binder::dummy(src_and_dst),
653+
scope,
654+
assume,
655+
) {
656+
rustc_transmute::Answer::Yes => Ok(Certainty::Yes),
657+
rustc_transmute::Answer::No(_)
658+
| rustc_transmute::Answer::IfTransmutable { .. }
659+
| rustc_transmute::Answer::IfAll(_)
660+
| rustc_transmute::Answer::IfAny(_) => Err(NoSolution),
661+
}
662+
}
642663
}

compiler/rustc_trait_selection/src/solve/project_goals.rs

+7
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
524524
) -> QueryResult<'tcx> {
525525
bug!("`Destruct` does not have an associated type: {:?}", goal);
526526
}
527+
528+
fn consider_builtin_transmute_candidate(
529+
_ecx: &mut EvalCtxt<'_, 'tcx>,
530+
goal: Goal<'tcx, Self>,
531+
) -> QueryResult<'tcx> {
532+
bug!("`BikeshedIntrinsicFrom` does not have an associated type: {:?}", goal)
533+
}
527534
}
528535

529536
/// This behavior is also implemented in `rustc_ty_utils` and in the old `project` code.

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+29
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,35 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
598598
Err(NoSolution)
599599
}
600600
}
601+
602+
fn consider_builtin_transmute_candidate(
603+
ecx: &mut EvalCtxt<'_, 'tcx>,
604+
goal: Goal<'tcx, Self>,
605+
) -> QueryResult<'tcx> {
606+
// `rustc_transmute` does not have support for type or const params
607+
if goal.has_non_region_placeholders() {
608+
return Err(NoSolution);
609+
}
610+
611+
// Erase regions because we compute layouts in `rustc_transmute`,
612+
// which will ICE for region vars.
613+
let substs = ecx.tcx().erase_regions(goal.predicate.trait_ref.substs);
614+
615+
let Some(assume) = rustc_transmute::Assume::from_const(
616+
ecx.tcx(),
617+
goal.param_env,
618+
substs.const_at(3),
619+
) else {
620+
return Err(NoSolution);
621+
};
622+
623+
let certainty = ecx.is_transmutable(
624+
rustc_transmute::Types { dst: substs.type_at(0), src: substs.type_at(1) },
625+
substs.type_at(2),
626+
assume,
627+
)?;
628+
ecx.evaluate_added_goals_and_make_canonical_response(certainty)
629+
}
601630
}
602631

603632
impl<'tcx> EvalCtxt<'_, 'tcx> {

config.example.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ changelog-seen = 2
8888
# the resulting rustc being unable to compile for the disabled architectures.
8989
#
9090
# To add support for new targets, see https://rustc-dev-guide.rust-lang.org/building/new-target.html.
91-
#targets = "AArch64;ARM;BPF;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86"
91+
#targets = "AArch64;ARM;BPF;Hexagon;LoongArch;MSP430;Mips;NVPTX;PowerPC;RISCV;Sparc;SystemZ;WebAssembly;X86"
9292

9393
# LLVM experimental targets to build support for. These targets are specified in
9494
# the same format as above, but since these targets are experimental, they are
@@ -257,7 +257,7 @@ changelog-seen = 2
257257
#python = "python"
258258

259259
# The path to the REUSE executable to use. Note that REUSE is not required in
260-
# most cases, as our tooling relies on a cached (and shrinked) copy of the
260+
# most cases, as our tooling relies on a cached (and shrunk) copy of the
261261
# REUSE output present in the git repository and in our source tarballs.
262262
#
263263
# REUSE is only needed if your changes caused the overall licensing of the

library/core/src/macros/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -712,8 +712,8 @@ macro_rules! unimplemented {
712712

713713
/// Indicates unfinished code.
714714
///
715-
/// This can be useful if you are prototyping and are just looking to have your
716-
/// code typecheck.
715+
/// This can be useful if you are prototyping and just
716+
/// want a placeholder to let your code pass type analysis.
717717
///
718718
/// The difference between [`unimplemented!`] and `todo!` is that while `todo!` conveys
719719
/// an intent of implementing the functionality later and the message is "not yet

library/std/src/env.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -236,21 +236,14 @@ fn _var(key: &OsStr) -> Result<String, VarError> {
236236
}
237237

238238
/// Fetches the environment variable `key` from the current process, returning
239-
/// [`None`] if the variable isn't set or there's another error.
239+
/// [`None`] if the variable isn't set or if there is another error.
240240
///
241-
/// Note that the method will not check if the environment variable
242-
/// is valid Unicode. If you want to have an error on invalid UTF-8,
243-
/// use the [`var`] function instead.
244-
///
245-
/// # Errors
246-
///
247-
/// This function returns an error if the environment variable isn't set.
248-
///
249-
/// This function may return an error if the environment variable's name contains
241+
/// It may return `None` if the environment variable's name contains
250242
/// the equal sign character (`=`) or the NUL character.
251243
///
252-
/// This function may return an error if the environment variable's value contains
253-
/// the NUL character.
244+
/// Note that this function will not check if the environment variable
245+
/// is valid Unicode. If you want to have an error on invalid UTF-8,
246+
/// use the [`var`] function instead.
254247
///
255248
/// # Examples
256249
///
@@ -895,6 +888,7 @@ pub mod consts {
895888
/// - x86_64
896889
/// - arm
897890
/// - aarch64
891+
/// - loongarch64
898892
/// - m68k
899893
/// - mips
900894
/// - mips64

library/std/src/os/linux/raw.rs

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ mod arch {
231231
}
232232

233233
#[cfg(any(
234+
target_arch = "loongarch64",
234235
target_arch = "mips64",
235236
target_arch = "s390x",
236237
target_arch = "sparc64",

library/std/src/personality/gcc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ const UNWIND_DATA_REG: (i32, i32) = (0, 1); // R0, R1
7777
#[cfg(any(target_arch = "riscv64", target_arch = "riscv32"))]
7878
const UNWIND_DATA_REG: (i32, i32) = (10, 11); // x10, x11
7979

80+
#[cfg(target_arch = "loongarch64")]
81+
const UNWIND_DATA_REG: (i32, i32) = (4, 5); // a0, a1
82+
8083
// The following code is based on GCC's C and C++ personality routines. For reference, see:
8184
// https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/libsupc++/eh_personality.cc
8285
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c

library/std/src/sys/common/alloc.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub const MIN_ALIGN: usize = 8;
2222
#[cfg(any(
2323
target_arch = "x86_64",
2424
target_arch = "aarch64",
25+
target_arch = "loongarch64",
2526
target_arch = "mips64",
2627
target_arch = "s390x",
2728
target_arch = "sparc64",

library/std/src/sys/solid/net.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::abi;
22
use crate::{
33
cmp,
44
ffi::CStr,
5-
io::{self, ErrorKind, IoSlice, IoSliceMut},
5+
io::{self, BorrowedBuf, BorrowedCursor, ErrorKind, IoSlice, IoSliceMut},
66
mem,
77
net::{Shutdown, SocketAddr},
88
ptr, str,
@@ -294,19 +294,30 @@ impl Socket {
294294
self.0.duplicate().map(Socket)
295295
}
296296

297-
fn recv_with_flags(&self, buf: &mut [u8], flags: c_int) -> io::Result<usize> {
297+
fn recv_with_flags(&self, mut buf: BorrowedCursor<'_>, flags: c_int) -> io::Result<()> {
298298
let ret = cvt(unsafe {
299-
netc::recv(self.0.raw(), buf.as_mut_ptr() as *mut c_void, buf.len(), flags)
299+
netc::recv(self.0.raw(), buf.as_mut().as_mut_ptr().cast(), buf.capacity(), flags)
300300
})?;
301-
Ok(ret as usize)
301+
unsafe {
302+
buf.advance(ret as usize);
303+
}
304+
Ok(())
302305
}
303306

304307
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
305-
self.recv_with_flags(buf, 0)
308+
let mut buf = BorrowedBuf::from(buf);
309+
self.recv_with_flags(buf.unfilled(), 0)?;
310+
Ok(buf.len())
306311
}
307312

308313
pub fn peek(&self, buf: &mut [u8]) -> io::Result<usize> {
309-
self.recv_with_flags(buf, MSG_PEEK)
314+
let mut buf = BorrowedBuf::from(buf);
315+
self.recv_with_flags(buf.unfilled(), MSG_PEEK)?;
316+
Ok(buf.len())
317+
}
318+
319+
pub fn read_buf(&self, buf: BorrowedCursor<'_>) -> io::Result<()> {
320+
self.recv_with_flags(buf, 0)
310321
}
311322

312323
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {

library/unwind/src/libunwind.rs

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ pub const unwinder_private_data_size: usize = 20;
7575
#[cfg(all(target_arch = "hexagon", target_os = "linux"))]
7676
pub const unwinder_private_data_size: usize = 35;
7777

78+
#[cfg(target_arch = "loongarch64")]
79+
pub const unwinder_private_data_size: usize = 2;
80+
7881
#[repr(C)]
7982
pub struct _Unwind_Exception {
8083
pub exception_class: _Unwind_Exception_Class,

src/bootstrap/bootstrap.py

+1
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def default_build_triple(verbose):
304304
'i486': 'i686',
305305
'i686': 'i686',
306306
'i786': 'i686',
307+
'loongarch64': 'loongarch64',
307308
'm68k': 'm68k',
308309
'powerpc': 'powerpc',
309310
'powerpc64': 'powerpc64',

src/bootstrap/channel.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub fn read_commit_info_file(root: &Path) -> Option<Info> {
139139
sha: sha.to_owned(),
140140
short_sha: short_sha.to_owned(),
141141
},
142-
_ => panic!("the `git-comit-info` file is malformed"),
142+
_ => panic!("the `git-commit-info` file is malformed"),
143143
};
144144
Some(info)
145145
} else {

src/bootstrap/compile.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ impl Step for Std {
8383
let target = self.target;
8484
let compiler = self.compiler;
8585

86-
// These artifacts were already copied (in `impl Step for Sysroot`).
87-
// Don't recompile them.
86+
// When using `download-rustc`, we already have artifacts for the host available
87+
// (they were copied in `impl Step for Sysroot`). Don't recompile them.
8888
// NOTE: the ABI of the beta compiler is different from the ABI of the downloaded compiler,
8989
// so its artifacts can't be reused.
90-
if builder.download_rustc() && compiler.stage != 0 {
90+
if builder.download_rustc() && compiler.stage != 0 && target == builder.build.build {
9191
return;
9292
}
9393

src/bootstrap/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ const EXTRA_CHECK_CFGS: &[(Option<Mode>, &'static str, Option<&[&'static str]>)]
129129
/* Extra values not defined in the built-in targets yet, but used in std */
130130
(Some(Mode::Std), "target_env", Some(&["libnx"])),
131131
// (Some(Mode::Std), "target_os", Some(&[])),
132-
(Some(Mode::Std), "target_arch", Some(&["asmjs", "spirv", "nvptx", "xtensa"])),
132+
// #[cfg(bootstrap)] loongarch64
133+
(Some(Mode::Std), "target_arch", Some(&["asmjs", "spirv", "nvptx", "xtensa", "loongarch64"])),
133134
/* Extra names used by dependencies */
134135
// FIXME: Used by serde_json, but we should not be triggering on external dependencies.
135136
(Some(Mode::Rustc), "no_btreemap_remove_entry", None),

src/bootstrap/llvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl Step for Llvm {
291291
let llvm_targets = match &builder.config.llvm_targets {
292292
Some(s) => s,
293293
None => {
294-
"AArch64;ARM;BPF;Hexagon;MSP430;Mips;NVPTX;PowerPC;RISCV;\
294+
"AArch64;ARM;BPF;Hexagon;LoongArch;MSP430;Mips;NVPTX;PowerPC;RISCV;\
295295
Sparc;SystemZ;WebAssembly;X86"
296296
}
297297
};

0 commit comments

Comments
 (0)