From 7a8b96f89d40aeba3bdfdd517acc47a179fe7d98 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Fri, 3 Jun 2022 03:28:19 -0400 Subject: [PATCH 1/8] Make `std::mem::needs_drop` accept `?Sized` --- example/mini_core.rs | 2 +- example/mini_core_hello_world.rs | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/example/mini_core.rs b/example/mini_core.rs index 8da705e0cb06..489259d1a6bc 100644 --- a/example/mini_core.rs +++ b/example/mini_core.rs @@ -567,7 +567,7 @@ pub mod intrinsics { pub fn copy(src: *const T, dst: *mut T, count: usize); pub fn transmute(e: T) -> U; pub fn ctlz_nonzero(x: T) -> T; - pub fn needs_drop() -> bool; + pub fn needs_drop() -> bool; pub fn bitreverse(x: T) -> T; pub fn bswap(x: T) -> T; pub fn write_bytes(dst: *mut T, val: u8, count: usize); diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 85ca908d0a26..059f62f7bf8a 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -55,6 +55,11 @@ struct NoisyDrop { inner: NoisyDropInner, } +struct NoisyDropUnsized { + text: str, + inner: NoisyDropInner, +} + struct NoisyDropInner; impl Drop for NoisyDrop { @@ -170,7 +175,9 @@ fn main() { assert_eq!(intrinsics::min_align_of_val(&a) as u8, intrinsics::min_align_of::<&str>() as u8); assert!(!intrinsics::needs_drop::()); + assert!(!intrinsics::needs_drop::<[u8]>()); assert!(intrinsics::needs_drop::()); + assert!(intrinsics::needs_drop::()); Unique { pointer: NonNull(1 as *mut &str), From eb5f23737bb8fd70f52b4359c9b6acd81f3d7909 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Fri, 3 Jun 2022 12:58:36 -0400 Subject: [PATCH 2/8] Fix unsized field order --- example/mini_core_hello_world.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/mini_core_hello_world.rs b/example/mini_core_hello_world.rs index 059f62f7bf8a..0f1245c2758e 100644 --- a/example/mini_core_hello_world.rs +++ b/example/mini_core_hello_world.rs @@ -56,8 +56,8 @@ struct NoisyDrop { } struct NoisyDropUnsized { - text: str, inner: NoisyDropInner, + text: str, } struct NoisyDropInner; From ce2b3a9b4c6084eddc4d1c61436b9d41bb1483e5 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 10 Jun 2022 11:18:06 +1000 Subject: [PATCH 3/8] Rename the `ConstS::val` field as `kind`. And likewise for the `Const::val` method. Because its type is called `ConstKind`. Also `val` is a confusing name because `ConstKind` is an enum with seven variants, one of which is called `Value`. Also, this gives consistency with `TyS` and `PredicateS` which have `kind` fields. The commit also renames a few `Const` variables from `val` to `c`, to avoid confusion with the `ConstKind::Value` variant. --- src/base.rs | 2 +- src/constant.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/base.rs b/src/base.rs index 07136e1b76a9..fbe830b2b103 100644 --- a/src/base.rs +++ b/src/base.rs @@ -710,7 +710,7 @@ fn codegen_stmt<'tcx>( let times = fx .monomorphize(times) .eval(fx.tcx, ParamEnv::reveal_all()) - .val() + .kind() .try_to_bits(fx.tcx.data_layout.pointer_size) .unwrap(); if operand.layout().size.bytes() == 0 { diff --git a/src/constant.rs b/src/constant.rs index 7d2e3e52f344..3d14a0eca52b 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -45,7 +45,7 @@ pub(crate) fn check_constants(fx: &mut FunctionCx<'_, '_, '_>) -> bool { ConstantKind::Ty(ct) => ct, ConstantKind::Val(..) => continue, }; - match const_.val() { + match const_.kind() { ConstKind::Value(_) => {} ConstKind::Unevaluated(unevaluated) => { if let Err(err) = @@ -126,7 +126,7 @@ pub(crate) fn codegen_constant<'tcx>( ConstantKind::Ty(ct) => ct, ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty), }; - let const_val = match const_.val() { + let const_val = match const_.kind() { ConstKind::Value(const_val) => const_val, ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) if fx.tcx.is_static(def.did) => @@ -469,7 +469,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( match operand { Operand::Constant(const_) => match const_.literal { ConstantKind::Ty(const_) => { - fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).val().try_to_value() + fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).kind().try_to_value() } ConstantKind::Val(val, _) => Some(val), }, From 9096b3e44f6261791e79af851172eebf89a0c2cc Mon Sep 17 00:00:00 2001 From: b-naber Date: Wed, 16 Feb 2022 10:56:01 +0100 Subject: [PATCH 4/8] implement valtrees as the type-system representation for constant values --- src/constant.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/constant.rs b/src/constant.rs index 3d14a0eca52b..ef72e6efb946 100644 --- a/src/constant.rs +++ b/src/constant.rs @@ -127,7 +127,7 @@ pub(crate) fn codegen_constant<'tcx>( ConstantKind::Val(val, ty) => return codegen_const_value(fx, val, ty), }; let const_val = match const_.kind() { - ConstKind::Value(const_val) => const_val, + ConstKind::Value(valtree) => fx.tcx.valtree_to_const_val((const_.ty(), valtree)), ConstKind::Unevaluated(ty::Unevaluated { def, substs, promoted }) if fx.tcx.is_static(def.did) => { @@ -468,9 +468,10 @@ pub(crate) fn mir_operand_get_const_val<'tcx>( ) -> Option> { match operand { Operand::Constant(const_) => match const_.literal { - ConstantKind::Ty(const_) => { - fx.monomorphize(const_).eval(fx.tcx, ParamEnv::reveal_all()).kind().try_to_value() - } + ConstantKind::Ty(const_) => fx + .monomorphize(const_) + .eval_for_mir(fx.tcx, ParamEnv::reveal_all()) + .try_to_value(fx.tcx), ConstantKind::Val(val, _) => Some(val), }, // FIXME(rust-lang/rust#85105): Casts like `IMM8 as u32` result in the const being stored From fc0c753c2d876b981cbd646b7eb9336844fa08ae Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 14 Jun 2022 15:11:14 +0000 Subject: [PATCH 5/8] Remove src_files and remove_file They only apply to the main source archive and their role can be fulfilled through the skip argument of add_archive too. --- src/archive.rs | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index a099e8b3a6af..4822c7e03a99 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -61,19 +61,6 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { } } - fn src_files(&mut self) -> Vec { - self.entries.iter().map(|(name, _)| String::from_utf8(name.clone()).unwrap()).collect() - } - - fn remove_file(&mut self, name: &str) { - let index = self - .entries - .iter() - .position(|(entry_name, _)| entry_name == name.as_bytes()) - .expect("Tried to remove file not existing in src archive"); - self.entries.remove(index); - } - fn add_file(&mut self, file: &Path) { self.entries.push(( file.file_name().unwrap().to_str().unwrap().to_string().into_bytes(), From 6d8c45064b0772814d931df4f274246060cb8acc Mon Sep 17 00:00:00 2001 From: Maybe Waffle Date: Thu, 16 Jun 2022 19:39:39 +0400 Subject: [PATCH 6/8] Move/rename `lazy::Sync{OnceCell,Lazy}` to `sync::{Once,Lazy}Lock` --- src/driver/jit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/driver/jit.rs b/src/driver/jit.rs index 1b01f4edbb3f..a56a91000596 100644 --- a/src/driver/jit.rs +++ b/src/driver/jit.rs @@ -13,7 +13,7 @@ use rustc_span::Symbol; use cranelift_jit::{JITBuilder, JITModule}; -// FIXME use std::lazy::SyncOnceCell once it stabilizes +// FIXME use std::sync::OnceLock once it stabilizes use once_cell::sync::OnceCell; use crate::{prelude::*, BackendConfig}; From abb9b60f0965fe1cdc412369219d100022f39273 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Sat, 18 Jun 2022 17:55:24 +0000 Subject: [PATCH 7/8] Fix "Remove src_files and remove_file" --- src/archive.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/archive.rs b/src/archive.rs index 4822c7e03a99..e9b074e18379 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -92,7 +92,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { Ok(()) } - fn build(mut self) { + fn build(mut self) -> bool { enum BuilderKind { Bsd(ar::Builder), Gnu(ar::GnuBuilder), @@ -191,6 +191,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { ) }; + let any_members = !entries.is_empty(); + // Add all files for (entry_name, data) in entries.into_iter() { let header = ar::Header::new(entry_name, data.len() as u64); @@ -216,6 +218,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { self.sess.fatal(&format!("Ranlib exited with code {:?}", status.code())); } } + + any_members } fn inject_dll_import_lib( From 73b3ae0b8a5f84a231ec8fa850711ab5d6c027a3 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Tue, 14 Jun 2022 15:16:51 +0000 Subject: [PATCH 8/8] Remove the source archive functionality of ArchiveWriter We now build archives through strictly additive means rather than taking an existing archive and potentially substracting parts. --- src/archive.rs | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/src/archive.rs b/src/archive.rs index e9b074e18379..0812f930b5de 100644 --- a/src/archive.rs +++ b/src/archive.rs @@ -30,25 +30,7 @@ pub(crate) struct ArArchiveBuilder<'a> { } impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { - fn new(sess: &'a Session, output: &Path, input: Option<&Path>) -> Self { - let (src_archives, entries) = if let Some(input) = input { - let read_cache = ReadCache::new(File::open(input).unwrap()); - let archive = ArchiveFile::parse(&read_cache).unwrap(); - let mut entries = Vec::new(); - - for entry in archive.members() { - let entry = entry.unwrap(); - entries.push(( - entry.name().to_vec(), - ArchiveEntry::FromArchive { archive_index: 0, file_range: entry.file_range() }, - )); - } - - (vec![read_cache.into_inner()], entries) - } else { - (vec![], Vec::new()) - }; - + fn new(sess: &'a Session, output: &Path) -> Self { ArArchiveBuilder { sess, dst: output.to_path_buf(), @@ -56,8 +38,8 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { // FIXME fix builtin ranlib on macOS no_builtin_ranlib: sess.target.is_like_osx, - src_archives, - entries, + src_archives: vec![], + entries: vec![], } }