Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 17 additions & 0 deletions compiler/rustc_ast/src/expand/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,23 @@ pub enum AllocatorTy {
Usize,
}

/// Some allocator methods are known to the compiler: they act more like
/// intrinsics/language primitives than library-defined functions.
/// FIXME: ideally this would be derived from attributes like `#[rustc_allocator]`,
/// so we don't have two sources of truth.
#[derive(Copy, Clone, Debug)]
pub enum SpecialAllocatorMethod {
Alloc,
AllocZeroed,
Dealloc,
Realloc,
}

/// A method that will be codegened in the allocator shim.
#[derive(Copy, Clone)]
pub struct AllocatorMethod {
pub name: Symbol,
pub special: Option<SpecialAllocatorMethod>,
pub inputs: &'static [AllocatorMethodInput],
pub output: AllocatorTy,
}
Expand All @@ -47,11 +60,13 @@ pub struct AllocatorMethodInput {
pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
AllocatorMethod {
name: sym::alloc,
special: Some(SpecialAllocatorMethod::Alloc),
inputs: &[AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout }],
output: AllocatorTy::ResultPtr,
},
AllocatorMethod {
name: sym::dealloc,
special: Some(SpecialAllocatorMethod::Dealloc),
inputs: &[
AllocatorMethodInput { name: "ptr", ty: AllocatorTy::Ptr },
AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout },
Expand All @@ -60,6 +75,7 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
},
AllocatorMethod {
name: sym::realloc,
special: Some(SpecialAllocatorMethod::Realloc),
inputs: &[
AllocatorMethodInput { name: "ptr", ty: AllocatorTy::Ptr },
AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout },
Expand All @@ -69,6 +85,7 @@ pub static ALLOCATOR_METHODS: &[AllocatorMethod] = &[
},
AllocatorMethod {
name: sym::alloc_zeroed,
special: Some(SpecialAllocatorMethod::AllocZeroed),
inputs: &[AllocatorMethodInput { name: "layout", ty: AllocatorTy::Layout }],
output: AllocatorTy::ResultPtr,
},
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
type Item;
/// A function that converts individual items (of type [`Item`](Self::Item)) into the final attribute.
///
/// For example, individual representations fomr `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`,
/// For example, individual representations from `#[repr(...)]` attributes into an `AttributeKind::Repr(x)`,
/// where `x` is a vec of these individual reprs.
const CONVERT: ConvertFn<Self::Item>;

Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_codegen_llvm/src/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use libc::c_uint;
use rustc_ast::expand::allocator::{
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, default_fn_name, global_fn_name,
AllocatorMethod, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE, SpecialAllocatorMethod,
default_fn_name, global_fn_name,
};
use rustc_codegen_ssa::traits::BaseTypeCodegenMethods as _;
use rustc_middle::bug;
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
use rustc_middle::ty::TyCtxt;
use rustc_session::config::{DebugInfo, OomStrategy};
use rustc_span::sym;
use rustc_symbol_mangling::mangle_internal_symbol;

use crate::attributes::llfn_attrs_from_instance;
Expand Down Expand Up @@ -65,12 +65,12 @@ pub(crate) unsafe fn codegen(
let from_name = mangle_internal_symbol(tcx, &global_fn_name(method.name));
let to_name = mangle_internal_symbol(tcx, &default_fn_name(method.name));

let alloc_attr_flag = match method.name {
sym::alloc => CodegenFnAttrFlags::ALLOCATOR,
sym::dealloc => CodegenFnAttrFlags::DEALLOCATOR,
sym::realloc => CodegenFnAttrFlags::REALLOCATOR,
sym::alloc_zeroed => CodegenFnAttrFlags::ALLOCATOR_ZEROED,
_ => CodegenFnAttrFlags::empty(),
let alloc_attr_flag = match method.special {
Some(SpecialAllocatorMethod::Alloc) => CodegenFnAttrFlags::ALLOCATOR,
Some(SpecialAllocatorMethod::Dealloc) => CodegenFnAttrFlags::DEALLOCATOR,
Some(SpecialAllocatorMethod::Realloc) => CodegenFnAttrFlags::REALLOCATOR,
Some(SpecialAllocatorMethod::AllocZeroed) => CodegenFnAttrFlags::ALLOCATOR_ZEROED,
None => CodegenFnAttrFlags::empty(),
};

let mut attrs = CodegenFnAttrs::new();
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,7 @@ pub fn allocator_shim_contents(tcx: TyCtxt<'_>, kind: AllocatorKind) -> Vec<Allo
if tcx.alloc_error_handler_kind(()).unwrap() == AllocatorKind::Default {
methods.push(AllocatorMethod {
name: ALLOC_ERROR_HANDLER,
special: None,
inputs: &[],
output: AllocatorTy::Never,
});
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/graph/scc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ enum NodeState<N, S, A: Annotation> {
#[derive(Copy, Clone, Debug)]
enum WalkReturn<S, A: Annotation> {
/// The walk found a cycle, but the entire component is not known to have
/// been fully walked yet. We only know the minimum depth of this
/// been fully walked yet. We only know the minimum depth of this
/// component in a minimum spanning tree of the graph. This component
/// is tentatively represented by the state of the first node of this
/// cycle we met, which is at `min_depth`.
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1651,9 +1651,7 @@ fn check_method_receiver<'tcx>(

// If the receiver already has errors reported, consider it valid to avoid
// unnecessary errors (#58712).
if receiver_ty.references_error() {
return Ok(());
}
receiver_ty.error_reported()?;

let arbitrary_self_types_level = if tcx.features().arbitrary_self_types_pointers() {
Some(ArbitrarySelfTypesLevel::WithPointers)
Expand Down
8 changes: 3 additions & 5 deletions compiler/rustc_hir_analysis/src/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ fn check_impl<'tcx>(

// Skip impls where one of the self type is an error type.
// This occurs with e.g., resolve failures (#30589).
if trait_ref.references_error() {
return Ok(());
}
trait_ref.error_reported()?;

enforce_trait_manually_implementable(tcx, impl_def_id, trait_ref.def_id, trait_def)
.and(enforce_empty_impls_for_marker_traits(tcx, impl_def_id, trait_ref.def_id, trait_def))
Expand Down Expand Up @@ -188,9 +186,9 @@ fn check_object_overlap<'tcx>(
) -> Result<(), ErrorGuaranteed> {
let trait_def_id = trait_ref.def_id;

if trait_ref.references_error() {
if let Err(guar) = trait_ref.error_reported() {
debug!("coherence: skipping impl {:?} with error {:?}", impl_def_id, trait_ref);
return Ok(());
return Err(guar);
}

// check for overlap with the automatic `impl Trait for dyn Trait`
Expand Down
37 changes: 9 additions & 28 deletions compiler/rustc_hir_analysis/src/impl_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,10 @@ pub(crate) fn enforce_impl_lifetime_params_are_constrained(
impl_def_id: LocalDefId,
) -> Result<(), ErrorGuaranteed> {
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
if impl_self_ty.references_error() {
// Don't complain about unconstrained type params when self ty isn't known due to errors.
// (#36836)
tcx.dcx().span_delayed_bug(
tcx.def_span(impl_def_id),
format!(
"potentially unconstrained type parameters weren't evaluated: {impl_self_ty:?}",
),
);
// This is super fishy, but our current `rustc_hir_analysis::check_crate` pipeline depends on
// `type_of` having been called much earlier, and thus this value being read from cache.
// Compilation must continue in order for other important diagnostics to keep showing up.
return Ok(());
}

// Don't complain about unconstrained type params when self ty isn't known due to errors.
// (#36836)
impl_self_ty.error_reported()?;

let impl_generics = tcx.generics_of(impl_def_id);
let impl_predicates = tcx.predicates_of(impl_def_id);
Expand Down Expand Up @@ -174,20 +164,11 @@ pub(crate) fn enforce_impl_non_lifetime_params_are_constrained(
impl_def_id: LocalDefId,
) -> Result<(), ErrorGuaranteed> {
let impl_self_ty = tcx.type_of(impl_def_id).instantiate_identity();
if impl_self_ty.references_error() {
// Don't complain about unconstrained type params when self ty isn't known due to errors.
// (#36836)
tcx.dcx().span_delayed_bug(
tcx.def_span(impl_def_id),
format!(
"potentially unconstrained type parameters weren't evaluated: {impl_self_ty:?}",
),
);
// This is super fishy, but our current `rustc_hir_analysis::check_crate` pipeline depends on
// `type_of` having been called much earlier, and thus this value being read from cache.
// Compilation must continue in order for other important diagnostics to keep showing up.
return Ok(());
}

// Don't complain about unconstrained type params when self ty isn't known due to errors.
// (#36836)
impl_self_ty.error_reported()?;

let impl_generics = tcx.generics_of(impl_def_id);
let impl_predicates = tcx.predicates_of(impl_def_id);
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).map(ty::EarlyBinder::instantiate_identity);
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,9 +685,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
});
let ty =
self.check_expr_with_expectation_and_needs(oprnd, hint, Needs::maybe_mut_place(mutbl));
if let Err(guar) = ty.error_reported() {
return Ty::new_error(self.tcx, guar);
}

match kind {
_ if ty.references_error() => Ty::new_misc_error(self.tcx),
hir::BorrowKind::Raw => {
self.check_named_place_expr(oprnd);
Ty::new_ptr(self.tcx, ty, mutbl)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_sanitizers/src/cfi/typeid/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ bitflags! {
const GENERALIZE_REPR_C = 2;
/// Normalizes integers for compatibility with Clang
/// `-fsanitize-cfi-icall-experimental-normalize-integers` option for cross-language LLVM
/// CFI and KCFI support.
/// CFI and KCFI support.
const NORMALIZE_INTEGERS = 4;
/// Do not perform self type erasure for attaching a secondary type id to methods with their
/// concrete self so they can be used as function pointers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
pub struct OnUnimplementedFormatString {
/// Symbol of the format string, i.e. `"content"`
symbol: Symbol,
///The span of the format string, i.e. `"content"`
/// The span of the format string, i.e. `"content"`
span: Span,
is_diagnostic_namespace_variant: bool,
}
Expand Down
11 changes: 11 additions & 0 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ dependencies = [
"rustc-std-workspace-core",
]

[[package]]
name = "moto-rt"
version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "058a2807a30527bee4c30df7ababe971cdde94372d4dbd1ff145bb403381436c"
dependencies = [
"rustc-std-workspace-alloc",
"rustc-std-workspace-core",
]

[[package]]
name = "object"
version = "0.37.3"
Expand Down Expand Up @@ -316,6 +326,7 @@ dependencies = [
"hermit-abi",
"libc",
"miniz_oxide",
"moto-rt",
"object",
"panic_abort",
"panic_unwind",
Expand Down
3 changes: 3 additions & 0 deletions library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ fortanix-sgx-abi = { version = "0.6.1", features = [
'rustc-dep-of-std',
], public = true }

[target.'cfg(target_os = "motor")'.dependencies]
moto-rt = { version = "0.15", features = ['rustc-dep-of-std'], public = true }

[target.'cfg(target_os = "hermit")'.dependencies]
hermit-abi = { version = "0.5.0", features = [
'rustc-dep-of-std',
Expand Down
1 change: 1 addition & 0 deletions library/std/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn main() {
|| target_os == "windows"
|| target_os == "fuchsia"
|| (target_vendor == "fortanix" && target_env == "sgx")
|| target_os == "motor"
|| target_os == "hermit"
|| target_os == "trusty"
|| target_os == "l4re"
Expand Down
22 changes: 20 additions & 2 deletions library/std/src/os/fd/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#![stable(feature = "io_safety", since = "1.63.0")]
#![deny(unsafe_op_in_unsafe_fn)]

#[cfg(target_os = "motor")]
use moto_rt::libc;

use super::raw::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
#[cfg(not(target_os = "trusty"))]
use crate::fs;
Expand All @@ -12,7 +15,8 @@ use crate::mem::ManuallyDrop;
target_arch = "wasm32",
target_env = "sgx",
target_os = "hermit",
target_os = "trusty"
target_os = "trusty",
target_os = "motor"
)))]
use crate::sys::cvt;
#[cfg(not(target_os = "trusty"))]
Expand Down Expand Up @@ -95,7 +99,12 @@ impl OwnedFd {
impl BorrowedFd<'_> {
/// Creates a new `OwnedFd` instance that shares the same underlying file
/// description as the existing `BorrowedFd` instance.
#[cfg(not(any(target_arch = "wasm32", target_os = "hermit", target_os = "trusty")))]
#[cfg(not(any(
target_arch = "wasm32",
target_os = "hermit",
target_os = "trusty",
target_os = "motor"
)))]
#[stable(feature = "io_safety", since = "1.63.0")]
pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedFd> {
// We want to atomically duplicate this file descriptor and set the
Expand Down Expand Up @@ -123,6 +132,15 @@ impl BorrowedFd<'_> {
pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedFd> {
Err(crate::io::Error::UNSUPPORTED_PLATFORM)
}

/// Creates a new `OwnedFd` instance that shares the same underlying file
/// description as the existing `BorrowedFd` instance.
#[cfg(target_os = "motor")]
#[stable(feature = "io_safety", since = "1.63.0")]
pub fn try_clone_to_owned(&self) -> crate::io::Result<OwnedFd> {
let fd = moto_rt::fs::duplicate(self.as_raw_fd()).map_err(crate::sys::map_motor_error)?;
Ok(unsafe { OwnedFd::from_raw_fd(fd) })
}
}

#[stable(feature = "io_safety", since = "1.63.0")]
Expand Down
10 changes: 7 additions & 3 deletions library/std/src/os/fd/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@

#[cfg(target_os = "hermit")]
use hermit_abi as libc;
#[cfg(target_os = "motor")]
use moto_rt::libc;

#[cfg(target_os = "motor")]
use super::owned::OwnedFd;
#[cfg(not(target_os = "trusty"))]
use crate::fs;
use crate::io;
#[cfg(target_os = "hermit")]
use crate::os::hermit::io::OwnedFd;
#[cfg(not(target_os = "hermit"))]
#[cfg(all(not(target_os = "hermit"), not(target_os = "motor")))]
use crate::os::raw;
#[cfg(all(doc, not(target_arch = "wasm32")))]
use crate::os::unix::io::AsFd;
Expand All @@ -23,10 +27,10 @@ use crate::sys_common::{AsInner, FromInner, IntoInner};

/// Raw file descriptors.
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(not(target_os = "hermit"))]
#[cfg(all(not(target_os = "hermit"), not(target_os = "motor")))]
pub type RawFd = raw::c_int;
#[stable(feature = "rust1", since = "1.0.0")]
#[cfg(target_os = "hermit")]
#[cfg(any(target_os = "hermit", target_os = "motor"))]
pub type RawFd = i32;

/// A trait to extract the raw file descriptor from an underlying object.
Expand Down
11 changes: 10 additions & 1 deletion library/std/src/os/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ pub mod ios;
pub mod l4re;
#[cfg(target_os = "macos")]
pub mod macos;
#[cfg(target_os = "motor")]
pub mod motor;
#[cfg(target_os = "netbsd")]
pub mod netbsd;
#[cfg(target_os = "nto")]
Expand Down Expand Up @@ -182,7 +184,14 @@ pub mod vxworks;
#[cfg(target_os = "xous")]
pub mod xous;

#[cfg(any(unix, target_os = "hermit", target_os = "trusty", target_os = "wasi", doc))]
#[cfg(any(
unix,
target_os = "hermit",
target_os = "trusty",
target_os = "wasi",
target_os = "motor",
doc
))]
pub mod fd;

#[cfg(any(target_os = "linux", target_os = "android", target_os = "cygwin", doc))]
Expand Down
Loading
Loading