Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 6 pull requests #136850

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7ae198b
don't use partial ordering on types that support total ordering
yotamofek Jan 18, 2025
ce0b72a
use slice patterns for checking for elements of slice
yotamofek Jan 18, 2025
68ff0f1
std: replace the `FromInner` implementation for addresses with privat…
joboet Feb 7, 2025
5932b2f
tests/assembly: make windows ABI test cross-compile
workingjubilee Feb 9, 2025
b3464fa
tests/assembly: make typed-swap test much less fragile
workingjubilee Feb 9, 2025
ee111b2
tests/assembly: use -Copt-level=3 instead of -O
workingjubilee Feb 9, 2025
833f070
tests/assembly: cross-compile x86-return-float
workingjubilee Feb 9, 2025
3580698
tests: issue-122805 -> dont-shuffle-bswaps
workingjubilee Feb 10, 2025
d42d20d
tests: simplify dont-shuffle-bswaps test
workingjubilee Feb 10, 2025
2ea7953
tests/codegen: use -Copt-level=3 instead of -O
workingjubilee Feb 9, 2025
f94ada1
Add cygwin target.
Berrysoft Jan 1, 2025
33d0f38
Apply suggestions
Berrysoft Feb 5, 2025
8e5207e
Reformat files
Berrysoft Feb 10, 2025
17716be
compiler: die immediately instead of handling unknown target codegen
workingjubilee Feb 10, 2025
fd58652
cg_gcc: stop caring about compiling for unknown targets
workingjubilee Feb 10, 2025
77f434f
Rollup merge of #134999 - Berrysoft:dev/new-cygwin-target, r=chenyuka…
jhpratt Feb 11, 2025
bd691f9
Rollup merge of #135677 - yotamofek:resolve-cleanups2, r=compiler-errors
jhpratt Feb 11, 2025
08b6596
Rollup merge of #136699 - joboet:netaddr_from_inner, r=cuviper
jhpratt Feb 11, 2025
18c31bd
Rollup merge of #136758 - workingjubilee:specify-opt-level-for-tests,…
jhpratt Feb 11, 2025
083ecb6
Rollup merge of #136761 - workingjubilee:specify-opt-level-for-codege…
jhpratt Feb 11, 2025
f5ef201
Rollup merge of #136833 - workingjubilee:let-the-impossible-be-imposs…
jhpratt Feb 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
conv: Conv::C,
can_unwind: false,
};
fn_abi.adjust_for_foreign_abi(self.cx, ExternAbi::C { unwind: false }).unwrap();
fn_abi.adjust_for_foreign_abi(self.cx, ExternAbi::C { unwind: false });

let ret_indirect = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });

Expand Down
10 changes: 0 additions & 10 deletions compiler/rustc_const_eval/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use rustc_middle::mir::interpret::{
};
use rustc_middle::ty::{self, Mutability, Ty};
use rustc_span::{Span, Symbol};
use rustc_target::callconv::AdjustForForeignAbiError;

use crate::interpret::InternKind;

Expand Down Expand Up @@ -936,9 +935,6 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
InvalidProgramInfo::TooGeneric => const_eval_too_generic,
InvalidProgramInfo::AlreadyReported(_) => const_eval_already_reported,
InvalidProgramInfo::Layout(e) => e.diagnostic_message(),
InvalidProgramInfo::FnAbiAdjustForForeignAbi(_) => {
rustc_middle::error::middle_adjust_for_foreign_abi_error
}
}
}
fn add_args<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
Expand All @@ -953,12 +949,6 @@ impl<'tcx> ReportErrorExt for InvalidProgramInfo<'tcx> {
}
dummy_diag.cancel();
}
InvalidProgramInfo::FnAbiAdjustForForeignAbi(
AdjustForForeignAbiError::Unsupported { arch, abi },
) => {
diag.arg("arch", arch);
diag.arg("abi", abi.name());
}
}
}
}
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ impl<'tcx, M: Machine<'tcx>> FnAbiOfHelpers<'tcx> for InterpCx<'tcx, M> {
) -> InterpErrorKind<'tcx> {
match err {
FnAbiError::Layout(err) => err_inval!(Layout(err)),
FnAbiError::AdjustForForeignAbi(err) => {
err_inval!(FnAbiAdjustForForeignAbi(err))
}
}
}
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_middle/src/mir/interpret/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,6 @@ pub enum InvalidProgramInfo<'tcx> {
AlreadyReported(ReportedErrorInfo),
/// An error occurred during layout computation.
Layout(layout::LayoutError<'tcx>),
/// An error occurred during FnAbi computation: the passed --target lacks FFI support
/// (which unfortunately typeck does not reject).
/// Not using `FnAbiError` as that contains a nested `LayoutError`.
FnAbiAdjustForForeignAbi(rustc_target::callconv::AdjustForForeignAbiError),
}

/// Details of why a pointer had to be in-bounds.
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use rustc_target::spec::{
use tracing::debug;
use {rustc_abi as abi, rustc_hir as hir};

use crate::error::UnsupportedFnAbi;
use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::query::TyCtxtAt;
use crate::ty::normalize_erasing_regions::NormalizationError;
Expand Down Expand Up @@ -1275,18 +1274,12 @@ pub fn fn_can_unwind(tcx: TyCtxt<'_>, fn_def_id: Option<DefId>, abi: ExternAbi)
pub enum FnAbiError<'tcx> {
/// Error produced by a `layout_of` call, while computing `FnAbi` initially.
Layout(LayoutError<'tcx>),

/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
AdjustForForeignAbi(rustc_target::callconv::AdjustForForeignAbiError),
}

impl<'a, 'b, G: EmissionGuarantee> Diagnostic<'a, G> for FnAbiError<'b> {
fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, G> {
match self {
Self::Layout(e) => e.into_diagnostic().into_diag(dcx, level),
Self::AdjustForForeignAbi(
rustc_target::callconv::AdjustForForeignAbiError::Unsupported { arch, abi },
) => UnsupportedFnAbi { arch, abi: abi.name() }.into_diag(dcx, level),
}
}
}
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_passes/src/abi_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,6 @@ fn unwrap_fn_abi<'tcx>(
span: tcx.def_span(item_def_id),
});
}
Err(FnAbiError::AdjustForForeignAbi(e)) => {
// Sadly there seems to be no `into_diagnostic` for this case... and I am not sure if
// this can even be reached. Anyway this is a perma-unstable debug attribute, an ICE
// isn't the worst thing. Also this matches what codegen does.
span_bug!(
tcx.def_span(item_def_id),
"error computing fn_abi_of_instance, cannot adjust for foreign ABI: {e:?}",
)
}
}
}

Expand Down
15 changes: 8 additions & 7 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1127,7 +1127,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
});

// Make sure error reporting is deterministic.
suggestions.sort_by(|a, b| a.candidate.as_str().partial_cmp(b.candidate.as_str()).unwrap());
suggestions.sort_by(|a, b| a.candidate.as_str().cmp(b.candidate.as_str()));

match find_best_match_for_name(
&suggestions.iter().map(|suggestion| suggestion.candidate).collect::<Vec<Symbol>>(),
Expand Down Expand Up @@ -2256,14 +2256,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
mut path: Vec<Segment>,
parent_scope: &ParentScope<'ra>,
) -> Option<(Vec<Segment>, Option<String>)> {
match (path.get(0), path.get(1)) {
match path[..] {
// `{{root}}::ident::...` on both editions.
// On 2015 `{{root}}` is usually added implicitly.
(Some(fst), Some(snd))
if fst.ident.name == kw::PathRoot && !snd.ident.is_path_segment_keyword() => {}
[first, second, ..]
if first.ident.name == kw::PathRoot && !second.ident.is_path_segment_keyword() => {}
// `ident::...` on 2018.
(Some(fst), _)
if fst.ident.span.at_least_rust_2018() && !fst.ident.is_path_segment_keyword() =>
[first, ..]
if first.ident.span.at_least_rust_2018()
&& !first.ident.is_path_segment_keyword() =>
{
// Insert a placeholder that's later replaced by `self`/`super`/etc.
path.insert(0, Segment::from_ident(Ident::empty()));
Expand Down Expand Up @@ -2374,7 +2375,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
// 2) `std` suggestions before `core` suggestions.
let mut extern_crate_names =
self.extern_prelude.keys().map(|ident| ident.name).collect::<Vec<_>>();
extern_crate_names.sort_by(|a, b| b.as_str().partial_cmp(a.as_str()).unwrap());
extern_crate_names.sort_by(|a, b| b.as_str().cmp(a.as_str()));

for name in extern_crate_names.into_iter() {
// Replace first ident with a crate name and check if that is valid.
Expand Down
25 changes: 3 additions & 22 deletions compiler/rustc_target/src/callconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use rustc_abi::{
Size, TyAbiInterface, TyAndLayout,
};
use rustc_macros::HashStable_Generic;
use rustc_span::Symbol;

use crate::spec::{HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, WasmCAbi};

Expand Down Expand Up @@ -623,19 +622,8 @@ impl<'a, Ty: fmt::Display> fmt::Debug for FnAbi<'a, Ty> {
}
}

/// Error produced by attempting to adjust a `FnAbi`, for a "foreign" ABI.
#[derive(Copy, Clone, Debug, HashStable_Generic)]
pub enum AdjustForForeignAbiError {
/// Target architecture doesn't support "foreign" (i.e. non-Rust) ABIs.
Unsupported { arch: Symbol, abi: ExternAbi },
}

impl<'a, Ty> FnAbi<'a, Ty> {
pub fn adjust_for_foreign_abi<C>(
&mut self,
cx: &C,
abi: ExternAbi,
) -> Result<(), AdjustForForeignAbiError>
pub fn adjust_for_foreign_abi<C>(&mut self, cx: &C, abi: ExternAbi)
where
Ty: TyAbiInterface<'a, C> + Copy,
C: HasDataLayout + HasTargetSpec + HasWasmCAbiOpt + HasX86AbiOpt,
Expand All @@ -644,7 +632,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
if let Some(arg) = self.args.first_mut() {
arg.pass_by_stack_offset(None);
}
return Ok(());
return;
}

let spec = cx.target_spec();
Expand Down Expand Up @@ -719,15 +707,8 @@ impl<'a, Ty> FnAbi<'a, Ty> {
}
"wasm64" => wasm::compute_c_abi_info(cx, self),
"bpf" => bpf::compute_abi_info(self),
arch => {
return Err(AdjustForForeignAbiError::Unsupported {
arch: Symbol::intern(arch),
abi,
});
}
arch => panic!("no lowering implemented for {arch}"),
}

Ok(())
}

pub fn adjust_for_rust_abi<C>(&mut self, cx: &C, abi: ExternAbi)
Expand Down
46 changes: 46 additions & 0 deletions compiler/rustc_target/src/spec/base/cygwin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
use std::borrow::Cow;

use crate::spec::{Cc, DebuginfoKind, LinkerFlavor, Lld, SplitDebuginfo, TargetOptions, cvs};

pub(crate) fn opts() -> TargetOptions {
let mut pre_link_args = TargetOptions::link_args(
LinkerFlavor::Gnu(Cc::No, Lld::No),
&["--disable-dynamicbase", "--enable-auto-image-base"],
);
crate::spec::add_link_args(
&mut pre_link_args,
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
&["-Wl,--disable-dynamicbase", "-Wl,--enable-auto-image-base"],
);
let cygwin_libs = &["-lcygwin", "-lgcc", "-lcygwin", "-luser32", "-lkernel32", "-lgcc_s"];
let mut late_link_args =
TargetOptions::link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), cygwin_libs);
crate::spec::add_link_args(
&mut late_link_args,
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
cygwin_libs,
);
TargetOptions {
os: "cygwin".into(),
vendor: "pc".into(),
// FIXME(#13846) this should be enabled for cygwin
function_sections: false,
linker: Some("gcc".into()),
dynamic_linking: true,
dll_prefix: "".into(),
dll_suffix: ".dll".into(),
exe_suffix: ".exe".into(),
families: cvs!["unix"],
is_like_windows: true,
allows_weak_linkage: false,
pre_link_args,
late_link_args,
abi_return_struct_as_int: true,
emit_debug_gdb_scripts: false,
requires_uwtable: true,
eh_frame_header: false,
debuginfo_kind: DebuginfoKind::Dwarf,
supported_split_debuginfo: Cow::Borrowed(&[SplitDebuginfo::Off]),
..Default::default()
}
}
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/base/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub(crate) mod android;
pub(crate) mod apple;
pub(crate) mod avr_gnu;
pub(crate) mod bpf;
pub(crate) mod cygwin;
pub(crate) mod dragonfly;
pub(crate) mod freebsd;
pub(crate) mod fuchsia;
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,7 @@ supported_targets! {
("riscv64imac-unknown-nuttx-elf", riscv64imac_unknown_nuttx_elf),
("riscv64gc-unknown-nuttx-elf", riscv64gc_unknown_nuttx_elf),

("x86_64-pc-cygwin", x86_64_pc_cygwin),
}

/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]>
Expand Down Expand Up @@ -3001,8 +3002,8 @@ impl Target {
);
check_eq!(
self.is_like_windows,
self.os == "windows" || self.os == "uefi",
"`is_like_windows` must be set if and only if `os` is `windows` or `uefi`"
self.os == "windows" || self.os == "uefi" || self.os == "cygwin",
"`is_like_windows` must be set if and only if `os` is `windows`, `uefi` or `cygwin`"
);
check_eq!(
self.is_like_wasm,
Expand Down
24 changes: 24 additions & 0 deletions compiler/rustc_target/src/spec/targets/x86_64_pc_cygwin.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use crate::spec::{Cc, LinkerFlavor, Lld, Target, base};

pub(crate) fn target() -> Target {
let mut base = base::cygwin::opts();
base.cpu = "x86-64".into();
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::No, Lld::No), &["-m", "i386pep"]);
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-m64"]);
base.max_atomic_width = Some(64);
base.linker = Some("x86_64-pc-cygwin-gcc".into());
Target {
llvm_target: "x86_64-pc-cygwin".into(),
pointer_width: 64,
data_layout:
"e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
arch: "x86_64".into(),
options: base,
metadata: crate::spec::TargetMetadata {
description: Some("64-bit x86 Cygwin".into()),
tier: Some(3),
host_tools: Some(false),
std: None,
},
}
}
12 changes: 4 additions & 8 deletions compiler/rustc_ty_utils/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ fn fn_abi_new_uncached<'tcx>(
conv,
can_unwind: fn_can_unwind(cx.tcx(), fn_def_id, sig.abi),
};
fn_abi_adjust_for_abi(cx, &mut fn_abi, sig.abi, fn_def_id)?;
fn_abi_adjust_for_abi(cx, &mut fn_abi, sig.abi, fn_def_id);
debug!("fn_abi_new_uncached = {:?}", fn_abi);
fn_abi_sanity_check(cx, &fn_abi, sig.abi);
Ok(tcx.arena.alloc(fn_abi))
Expand All @@ -662,7 +662,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
fn_abi: &mut FnAbi<'tcx, Ty<'tcx>>,
abi: ExternAbi,
fn_def_id: Option<DefId>,
) -> Result<(), &'tcx FnAbiError<'tcx>> {
) {
if abi == ExternAbi::Unadjusted {
// The "unadjusted" ABI passes aggregates in "direct" mode. That's fragile but needed for
// some LLVM intrinsics.
Expand All @@ -682,7 +682,7 @@ fn fn_abi_adjust_for_abi<'tcx>(
for arg in fn_abi.args.iter_mut() {
unadjust(arg);
}
return Ok(());
return;
}

let tcx = cx.tcx();
Expand Down Expand Up @@ -723,12 +723,8 @@ fn fn_abi_adjust_for_abi<'tcx>(
}
}
} else {
fn_abi
.adjust_for_foreign_abi(cx, abi)
.map_err(|err| &*tcx.arena.alloc(FnAbiError::AdjustForForeignAbi(err)))?;
fn_abi.adjust_for_foreign_abi(cx, abi);
}

Ok(())
}

#[tracing::instrument(level = "debug", skip(cx))]
Expand Down
29 changes: 0 additions & 29 deletions library/std/src/net/ip_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,3 @@ pub use core::net::IpAddr;
pub use core::net::Ipv6MulticastScope;
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::net::{Ipv4Addr, Ipv6Addr};

use crate::sys::net::netc as c;
use crate::sys_common::{FromInner, IntoInner};

impl IntoInner<c::in_addr> for Ipv4Addr {
#[inline]
fn into_inner(self) -> c::in_addr {
// `s_addr` is stored as BE on all machines and the array is in BE order.
// So the native endian conversion method is used so that it's never swapped.
c::in_addr { s_addr: u32::from_ne_bytes(self.octets()) }
}
}
impl FromInner<c::in_addr> for Ipv4Addr {
fn from_inner(addr: c::in_addr) -> Ipv4Addr {
Ipv4Addr::from(addr.s_addr.to_ne_bytes())
}
}

impl IntoInner<c::in6_addr> for Ipv6Addr {
fn into_inner(self) -> c::in6_addr {
c::in6_addr { s6_addr: self.octets() }
}
}
impl FromInner<c::in6_addr> for Ipv6Addr {
#[inline]
fn from_inner(addr: c::in6_addr) -> Ipv6Addr {
Ipv6Addr::from(addr.s6_addr)
}
}
Loading
Loading