From f4579367aa8bdaf56830b33feed468b97d3eedf2 Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Tue, 19 Dec 2023 13:04:54 +0100 Subject: [PATCH 1/3] bump: rust --- crates/mun_abi/src/struct_info.rs | 8 +- crates/mun_codegen/src/ir/type_table.rs | 2 +- crates/mun_codegen/src/value/float_value.rs | 4 +- crates/mun_codegen/src/value/pointer_value.rs | 6 +- crates/mun_codegen/tests/abi.rs | 4 +- .../src/state/workspace.rs | 2 +- crates/mun_runtime/src/lib.rs | 2 +- crates/mun_runtime/tests/memory.rs | 55 +++----- crates/mun_runtime_capi/src/function.rs | 20 +-- crates/mun_runtime_capi/src/gc.rs | 8 +- crates/mun_runtime_capi/src/runtime.rs | 42 +++--- crates/mun_skeptic/src/lib.rs | 2 +- .../mun_syntax/src/parsing/lexer/classes.rs | 12 +- crates/mun_syntax/src/tests/lexer.rs | 36 ++--- crates/mun_syntax/src/tests/parser.rs | 124 +++++++++--------- crates/mun_target/src/lib.rs | 2 +- rust-toolchain | 2 +- 17 files changed, 156 insertions(+), 175 deletions(-) diff --git a/crates/mun_abi/src/struct_info.rs b/crates/mun_abi/src/struct_info.rs index ff48f0a6b..9e8f0fff9 100644 --- a/crates/mun_abi/src/struct_info.rs +++ b/crates/mun_abi/src/struct_info.rs @@ -28,9 +28,11 @@ pub struct StructDefinition<'a> { #[repr(u8)] #[derive(Debug, Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[derive(Default)] pub enum StructMemoryKind { /// A garbage collected struct is allocated on the heap and uses reference semantics when passed /// around. + #[default] Gc, /// A value struct is allocated on the stack and uses value semantics when passed around. @@ -78,12 +80,6 @@ impl<'a> StructDefinition<'a> { } } -impl Default for StructMemoryKind { - fn default() -> Self { - StructMemoryKind::Gc - } -} - impl<'a> PartialEq for StructDefinition<'a> { fn eq(&self, other: &Self) -> bool { self.guid == other.guid diff --git a/crates/mun_codegen/src/ir/type_table.rs b/crates/mun_codegen/src/ir/type_table.rs index 82d7d15b2..1c5e13765 100644 --- a/crates/mun_codegen/src/ir/type_table.rs +++ b/crates/mun_codegen/src/ir/type_table.rs @@ -203,7 +203,7 @@ impl<'db, 'ink, 't> TypeTableBuilder<'db, 'ink, 't> { /// Constructs a `TypeTable` from all *used* types. pub fn build(self) -> TypeTable<'ink> { - let mut entries = Vec::from_iter(self.entries.into_iter()); + let mut entries = Vec::from_iter(self.entries); entries.sort_by(|a, b| a.name.cmp(&b.name)); let type_info_to_index = entries diff --git a/crates/mun_codegen/src/value/float_value.rs b/crates/mun_codegen/src/value/float_value.rs index 92859b06e..bb56e97d6 100644 --- a/crates/mun_codegen/src/value/float_value.rs +++ b/crates/mun_codegen/src/value/float_value.rs @@ -28,7 +28,7 @@ impl<'ink> PointerValueType<'ink> for f32 { context: &IrTypeContext<'ink, '_>, address_space: Option, ) -> PointerType<'ink> { - Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default())) + Self::get_ir_type(context).ptr_type(address_space.unwrap_or_default()) } } impl<'ink> PointerValueType<'ink> for f64 { @@ -36,7 +36,7 @@ impl<'ink> PointerValueType<'ink> for f64 { context: &IrTypeContext<'ink, '_>, address_space: Option, ) -> PointerType<'ink> { - Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default())) + Self::get_ir_type(context).ptr_type(address_space.unwrap_or_default()) } } diff --git a/crates/mun_codegen/src/value/pointer_value.rs b/crates/mun_codegen/src/value/pointer_value.rs index bccabd2ec..1e22cb046 100644 --- a/crates/mun_codegen/src/value/pointer_value.rs +++ b/crates/mun_codegen/src/value/pointer_value.rs @@ -25,7 +25,7 @@ impl<'ink> PointerValueType<'ink> for *const std::ffi::c_void { context: &IrTypeContext<'ink, '_>, address_space: Option, ) -> PointerType<'ink> { - Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default())) + Self::get_ir_type(context).ptr_type(address_space.unwrap_or_default()) } } @@ -53,7 +53,7 @@ impl<'ink, T: PointerValueType<'ink>> PointerValueType<'ink> for *mut T { context: &IrTypeContext<'ink, '_>, address_space: Option, ) -> PointerType<'ink> { - Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default())) + Self::get_ir_type(context).ptr_type(address_space.unwrap_or_default()) } } @@ -62,7 +62,7 @@ impl<'ink, T: PointerValueType<'ink>> PointerValueType<'ink> for *const T { context: &IrTypeContext<'ink, '_>, address_space: Option, ) -> PointerType<'ink> { - Self::get_ir_type(context).ptr_type(address_space.unwrap_or(AddressSpace::default())) + Self::get_ir_type(context).ptr_type(address_space.unwrap_or_default()) } } diff --git a/crates/mun_codegen/tests/abi.rs b/crates/mun_codegen/tests/abi.rs index 10990a670..e5ef864cb 100644 --- a/crates/mun_codegen/tests/abi.rs +++ b/crates/mun_codegen/tests/abi.rs @@ -29,7 +29,7 @@ fn test_abi_compatibility() { assert_eq!(abi::ABI_VERSION, unsafe { lib.get_abi_version() }); insta::assert_ron_snapshot!(unsafe { lib.get_info() }, - @r###" + @r#" AssemblyInfo( symbols: ModuleInfo( path: "mod", @@ -175,5 +175,5 @@ fn test_abi_compatibility() { ], dependencies: [], ) - "###); + "#); } diff --git a/crates/mun_language_server/src/state/workspace.rs b/crates/mun_language_server/src/state/workspace.rs index c84aca70b..f79803ee3 100644 --- a/crates/mun_language_server/src/state/workspace.rs +++ b/crates/mun_language_server/src/state/workspace.rs @@ -82,7 +82,7 @@ impl LanguageServerState { let monitor_config = mun_vfs::MonitorConfig { watch: match self.config.watcher { FilesWatcher::Client => vec![], - FilesWatcher::Notify => (0..entries_to_load.len()).into_iter().collect(), + FilesWatcher::Notify => (0..entries_to_load.len()).collect(), }, load: entries_to_load, }; diff --git a/crates/mun_runtime/src/lib.rs b/crates/mun_runtime/src/lib.rs index 7a9aeeb47..9fa156adc 100644 --- a/crates/mun_runtime/src/lib.rs +++ b/crates/mun_runtime/src/lib.rs @@ -695,7 +695,7 @@ impl<'name, T: InvokeArgs> InvokeErr<'name, T> { Output: 'o + ReturnTypeReflection + Marshal<'o>, 'r: 'o, { - #[allow(clippy::cast_ref_to_mut)] + #[allow(invalid_reference_casting, invalid_reference_casting)] let runtime = &mut *(runtime as *const Runtime as *mut Runtime); eprintln!("{}", self.msg); diff --git a/crates/mun_runtime/tests/memory.rs b/crates/mun_runtime/tests/memory.rs index 43d76a2f8..3dcfdd97c 100644 --- a/crates/mun_runtime/tests/memory.rs +++ b/crates/mun_runtime/tests/memory.rs @@ -689,12 +689,9 @@ fn map_array_to_array_different_array_to_primitive_different() { assert_eq!(b_array.iter().count(), 3); - b_array - .iter() - .zip([b, a, b].into_iter()) - .for_each(|(lhs, rhs)| { - assert_eq!(lhs, rhs as i64); - }); + b_array.iter().zip([b, a, b]).for_each(|(lhs, rhs)| { + assert_eq!(lhs, rhs as i64); + }); assert_eq!( foo_struct.as_ref(&driver.runtime).get::("c").unwrap(), @@ -748,12 +745,9 @@ fn map_array_to_array_different_array_to_primitive_same() { assert_eq!(b_array.iter().count(), 3); - b_array - .iter() - .zip([b, a, b].into_iter()) - .for_each(|(lhs, rhs)| { - assert_eq!(lhs, rhs); - }); + b_array.iter().zip([b, a, b]).for_each(|(lhs, rhs)| { + assert_eq!(lhs, rhs); + }); assert_eq!( foo_struct.as_ref(&driver.runtime).get::("c").unwrap(), @@ -955,16 +949,13 @@ fn map_array_to_array_different_primitive_to_array_different() { assert_eq!(b_array.iter().count(), 3); - b_array - .iter() - .zip([b, a, b].into_iter()) - .for_each(|(lhs, rhs)| { - assert_eq!(lhs.iter().count(), 1); - assert_eq!( - lhs.iter().next().expect("Array must have a value."), - rhs as i64 - ); - }); + b_array.iter().zip([b, a, b]).for_each(|(lhs, rhs)| { + assert_eq!(lhs.iter().count(), 1); + assert_eq!( + lhs.iter().next().expect("Array must have a value."), + rhs as i64 + ); + }); assert_eq!( foo_struct.as_ref(&driver.runtime).get::("c").unwrap(), @@ -1018,13 +1009,10 @@ fn map_array_to_array_different_primitive_to_array_same() { assert_eq!(b_array.iter().count(), 3); - b_array - .iter() - .zip([b, a, b].into_iter()) - .for_each(|(lhs, rhs)| { - assert_eq!(lhs.iter().count(), 1); - assert_eq!(lhs.iter().next().expect("Array must have a value."), rhs); - }); + b_array.iter().zip([b, a, b]).for_each(|(lhs, rhs)| { + assert_eq!(lhs.iter().count(), 1); + assert_eq!(lhs.iter().next().expect("Array must have a value."), rhs); + }); assert_eq!( foo_struct.as_ref(&driver.runtime).get::("c").unwrap(), @@ -1078,12 +1066,9 @@ fn map_array_to_array_different_primitive_to_primitive() { assert_eq!(b_array.iter().count(), 3); - b_array - .iter() - .zip([b, a, b].into_iter()) - .for_each(|(lhs, rhs)| { - assert_eq!(lhs, rhs as i64); - }); + b_array.iter().zip([b, a, b]).for_each(|(lhs, rhs)| { + assert_eq!(lhs, rhs as i64); + }); assert_eq!( foo_struct.as_ref(&driver.runtime).get::("c").unwrap(), diff --git a/crates/mun_runtime_capi/src/function.rs b/crates/mun_runtime_capi/src/function.rs index f948ef6c6..86f077b9a 100644 --- a/crates/mun_runtime_capi/src/function.rs +++ b/crates/mun_runtime_capi/src/function.rs @@ -192,14 +192,14 @@ pub(crate) mod tests { fn test_function_release_invalid_fn_info() { assert_error_snapshot!( unsafe { mun_function_release(Function::null()) }, - @r###""invalid argument \'function\': null pointer""###); + @r#""invalid argument \'function\': null pointer""#); } #[test] fn test_function_add_reference_invalid_fn_info() { assert_error_snapshot!( unsafe { mun_function_add_reference(Function::null()) }, - @r###""invalid argument \'function\': null pointer""###); + @r#""invalid argument \'function\': null pointer""#); } #[test] @@ -245,10 +245,10 @@ pub(crate) mod tests { let mut ptr = MaybeUninit::uninit(); assert_error_snapshot!( unsafe { mun_function_fn_ptr(Function::null(), ptr.as_mut_ptr()) }, - @r###""invalid argument \'function\': null pointer""###); + @r#""invalid argument \'function\': null pointer""#); assert_error_snapshot!( unsafe { mun_function_fn_ptr(function, ptr::null_mut()) }, - @r###""invalid argument \'ptr\': null pointer""###); + @r#""invalid argument \'ptr\': null pointer""#); assert!(unsafe { mun_function_release(function) }.is_ok()); } @@ -276,10 +276,10 @@ pub(crate) mod tests { let mut ptr = MaybeUninit::uninit(); assert_error_snapshot!( unsafe { mun_function_name(Function::null(), ptr.as_mut_ptr()) }, - @r###""invalid argument \'function\': null pointer""###); + @r#""invalid argument \'function\': null pointer""#); assert_error_snapshot!( unsafe { mun_function_name(function, ptr::null_mut()) }, - @r###""invalid argument \'name\': null pointer""###); + @r#""invalid argument \'name\': null pointer""#); assert!(unsafe { mun_function_release(function) }.is_ok()); } @@ -309,10 +309,10 @@ pub(crate) mod tests { let mut ptr = MaybeUninit::uninit(); assert_error_snapshot!(unsafe { mun_function_argument_types(Function::null(), ptr.as_mut_ptr()) - }, @r###""invalid argument \'function\': null pointer""###); + }, @r#""invalid argument \'function\': null pointer""#); assert_error_snapshot!( unsafe { mun_function_argument_types(function, ptr::null_mut()) }, - @r###""invalid argument \'arg_types\': null pointer""###); + @r#""invalid argument \'arg_types\': null pointer""#); assert!(unsafe { mun_function_release(function) }.is_ok()); } @@ -359,10 +359,10 @@ pub(crate) mod tests { let mut ptr = MaybeUninit::uninit(); assert_error_snapshot!( unsafe { mun_function_return_type(Function::null(), ptr.as_mut_ptr()) }, - @r###""invalid argument \'function\': null pointer""###); + @r#""invalid argument \'function\': null pointer""#); assert_error_snapshot!( unsafe { mun_function_return_type(function, ptr::null_mut()) }, - @r###""invalid argument \'ty\': null pointer""###); + @r#""invalid argument \'ty\': null pointer""#); assert!(unsafe { mun_function_release(function) }.is_ok()); } diff --git a/crates/mun_runtime_capi/src/gc.rs b/crates/mun_runtime_capi/src/gc.rs index 3395e04e8..48cea642e 100644 --- a/crates/mun_runtime_capi/src/gc.rs +++ b/crates/mun_runtime_capi/src/gc.rs @@ -156,7 +156,7 @@ mod tests { assert_error_snapshot!( unsafe { mun_gc_alloc(driver.runtime, Type::null(), ptr::null_mut()) }, - @r###""invalid argument \'obj\': null pointer""### + @r#""invalid argument \'obj\': null pointer""# ); } @@ -179,7 +179,7 @@ mod tests { assert_error_snapshot!( unsafe { mun_gc_alloc(driver.runtime, ty, ptr::null_mut()) }, - @r###""invalid argument \'obj\': null pointer""### + @r#""invalid argument \'obj\': null pointer""# ); } @@ -220,7 +220,7 @@ mod tests { let raw_ptr: RawGcPtr = ptr::null(); mun_gc_ptr_type(driver.runtime, raw_ptr.into(), ptr::null_mut()) }, - @r###""invalid argument \'ty\': null pointer""### + @r#""invalid argument \'ty\': null pointer""# ); } @@ -294,7 +294,7 @@ mod tests { assert_error_snapshot!( unsafe { mun_gc_collect(driver.runtime, ptr::null_mut()) }, - @r###""invalid argument \'reclaimed\': null pointer""### + @r#""invalid argument \'reclaimed\': null pointer""# ); } } diff --git a/crates/mun_runtime_capi/src/runtime.rs b/crates/mun_runtime_capi/src/runtime.rs index 21fe25e49..c4568c3c6 100644 --- a/crates/mun_runtime_capi/src/runtime.rs +++ b/crates/mun_runtime_capi/src/runtime.rs @@ -347,7 +347,7 @@ mod tests { fn test_runtime_create_invalid_lib_path() { assert_error_snapshot!( unsafe { mun_runtime_create(ptr::null(), RuntimeOptions::default(), ptr::null_mut()) }, - @r###""invalid argument \'library_path\': null pointer""### + @r#""invalid argument \'library_path\': null pointer""# ); } @@ -363,7 +363,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'library_path\': invalid UTF-8 encoded""### + @r#""invalid argument \'library_path\': invalid UTF-8 encoded""# ); } @@ -379,7 +379,7 @@ mod tests { let mut handle = MaybeUninit::uninit(); assert_error_snapshot!( unsafe { mun_runtime_create(lib_path.into_raw(), options, handle.as_mut_ptr()) }, - @r###""invalid argument: \'functions\' is null pointer.""### + @r#""invalid argument: \'functions\' is null pointer.""# ); } @@ -391,7 +391,7 @@ mod tests { unsafe { mun_runtime_create(lib_path.into_raw(), RuntimeOptions::default(), ptr::null_mut()) }, - @r###""invalid argument \'handle\': null pointer""### + @r#""invalid argument \'handle\': null pointer""# ); } @@ -416,7 +416,7 @@ mod tests { let mut handle = MaybeUninit::uninit(); assert_error_snapshot!( unsafe { mun_runtime_create(lib_path.into_raw(), options, handle.as_mut_ptr()) }, - @r###""invalid function name: null pointer""### + @r#""invalid function name: null pointer""# ); } @@ -442,7 +442,7 @@ mod tests { let mut handle = MaybeUninit::uninit(); assert_error_snapshot!( unsafe { mun_runtime_create(lib_path.into_raw(), options, handle.as_mut_ptr()) }, - @r###""invalid function name: invalid UTF-8 encoded""### + @r#""invalid function name: invalid UTF-8 encoded""# ); } @@ -467,7 +467,7 @@ mod tests { let mut handle = MaybeUninit::uninit(); assert_error_snapshot!( unsafe { mun_runtime_create(lib_path.into_raw(), options, handle.as_mut_ptr()) }, - @r###""invalid function \'foobar\': \'return_type\': null pointer""### + @r#""invalid function \'foobar\': \'return_type\': null pointer""# ); } @@ -493,7 +493,7 @@ mod tests { let mut handle = MaybeUninit::uninit(); assert_error_snapshot!( unsafe { mun_runtime_create(lib_path.into_raw(), options, handle.as_mut_ptr()) }, - @r###""invalid function \'foobar\': \'arg_types\' is null pointer.""### + @r#""invalid function \'foobar\': \'arg_types\' is null pointer.""# ); } @@ -520,7 +520,7 @@ mod tests { let mut handle = MaybeUninit::uninit(); assert_error_snapshot!( unsafe { mun_runtime_create(lib_path.into_raw(), options, handle.as_mut_ptr()) }, - @r###""invalid function \'foobar\': argument #1: null pointer""### + @r#""invalid function \'foobar\': argument #1: null pointer""# ); } @@ -542,7 +542,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'fn_name\': null pointer""### + @r#""invalid argument \'fn_name\': null pointer""# ); } @@ -565,7 +565,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'fn_name\': invalid UTF-8 encoded""### + @r#""invalid argument \'fn_name\': invalid UTF-8 encoded""# ); } @@ -588,7 +588,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'has_fn_info\': null pointer""### + @r#""invalid argument \'has_fn_info\': null pointer""# ); } @@ -612,7 +612,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'fn_info\': null pointer""### + @r#""invalid argument \'fn_info\': null pointer""# ); } @@ -671,7 +671,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'type_name\': null pointer""### + @r#""invalid argument \'type_name\': null pointer""# ); } @@ -693,7 +693,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'type_name\': invalid UTF-8 encoded""### + @r#""invalid argument \'type_name\': invalid UTF-8 encoded""# ); } @@ -715,7 +715,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'has_type_info\': null pointer""### + @r#""invalid argument \'has_type_info\': null pointer""# ); } @@ -738,7 +738,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'type_info\': null pointer""### + @r#""invalid argument \'type_info\': null pointer""# ); } @@ -795,7 +795,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'type_id\': null pointer""### + @r#""invalid argument \'type_id\': null pointer""# ); } @@ -817,7 +817,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'has_type_info\': null pointer""### + @r#""invalid argument \'has_type_info\': null pointer""# ); } @@ -840,7 +840,7 @@ mod tests { ptr::null_mut(), ) }, - @r###""invalid argument \'type_info\': null pointer""### + @r#""invalid argument \'type_info\': null pointer""# ); } @@ -890,7 +890,7 @@ mod tests { assert_error_snapshot!( unsafe { mun_runtime_update(driver.runtime, ptr::null_mut()) }, - @r###""invalid argument \'updated\': null pointer""### + @r#""invalid argument \'updated\': null pointer""# ); } diff --git a/crates/mun_skeptic/src/lib.rs b/crates/mun_skeptic/src/lib.rs index 75849aef8..fed6ce224 100644 --- a/crates/mun_skeptic/src/lib.rs +++ b/crates/mun_skeptic/src/lib.rs @@ -73,7 +73,7 @@ pub fn generate_doc_tests_from_mdbook(book_root: impl Into) { .map(ToString::to_string) }) .map(|file_stem| sanitize_test_name(&file_stem)) - .unwrap_or_else(String::new), + .unwrap_or_default(), ) }) .collect::>(); diff --git a/crates/mun_syntax/src/parsing/lexer/classes.rs b/crates/mun_syntax/src/parsing/lexer/classes.rs index 9a1ffa537..a42cec0c5 100644 --- a/crates/mun_syntax/src/parsing/lexer/classes.rs +++ b/crates/mun_syntax/src/parsing/lexer/classes.rs @@ -5,20 +5,20 @@ pub fn is_whitespace(c: char) -> bool { } pub fn is_ident_start(c: char) -> bool { - ('a'..='z').contains(&c) - || ('A'..='Z').contains(&c) + c.is_ascii_lowercase() + || c.is_ascii_uppercase() || c == '_' || (c > '\x7f' && UnicodeXID::is_xid_start(c)) } pub fn is_ident_continue(c: char) -> bool { - ('a'..='z').contains(&c) - || ('A'..='Z').contains(&c) - || ('0'..='9').contains(&c) + c.is_ascii_lowercase() + || c.is_ascii_uppercase() + || c.is_ascii_digit() || c == '_' || (c > '\x7f' && UnicodeXID::is_xid_continue(c)) } pub fn is_dec_digit(c: char) -> bool { - ('0'..='9').contains(&c) + c.is_ascii_digit() } diff --git a/crates/mun_syntax/src/tests/lexer.rs b/crates/mun_syntax/src/tests/lexer.rs index cbafc77e1..3ad764d5e 100644 --- a/crates/mun_syntax/src/tests/lexer.rs +++ b/crates/mun_syntax/src/tests/lexer.rs @@ -28,7 +28,7 @@ fn numbers() { 100_000 0x3a_u32 1f32 - 0o71234"#), @r###" + 0o71234"#), @r#" WHITESPACE 5 "\n " FLOAT_NUMBER 4 "1.34" WHITESPACE 5 "\n " @@ -43,7 +43,7 @@ fn numbers() { INT_NUMBER 4 "1f32" WHITESPACE 5 "\n " INT_NUMBER 7 "0o71234" - "###); + "#); } #[test] @@ -57,7 +57,7 @@ fn comments() { line comment */ /* /* nested */ */ - /* unclosed comment"#), @r###" + /* unclosed comment"#), @r#" WHITESPACE 5 "\n " COMMENT 16 "// hello, world!" WHITESPACE 5 "\n " @@ -70,7 +70,7 @@ fn comments() { COMMENT 18 "/* /* nested */ */" WHITESPACE 5 "\n " COMMENT 19 "/* unclosed comment" - "###); + "#); } #[test] @@ -80,7 +80,7 @@ fn whitespace() { h e ll o w - o r l d"#), @r###" + o r l d"#), @r#" WHITESPACE 5 "\n " IDENT 1 "h" WHITESPACE 1 " " @@ -99,7 +99,7 @@ fn whitespace() { IDENT 1 "l" WHITESPACE 3 " " IDENT 1 "d" - "###); + "#); } #[test] @@ -107,7 +107,7 @@ fn ident() { insta::assert_snapshot!(dump_text_tokens( r#" hello world_ _a2 _ __ x 即可编著课程 - "#), @r###" + "#), @r#" WHITESPACE 5 "\n " IDENT 5 "hello" WHITESPACE 1 " " @@ -123,7 +123,7 @@ fn ident() { WHITESPACE 1 " " IDENT 18 "即可编著课程" WHITESPACE 5 "\n " - "###); + "#); } #[test] @@ -148,7 +148,7 @@ fn symbols() { ^ ^= : :: -> - "#), @r###" + "#), @r##" WHITESPACE 5 "\n " HASH 1 "#" WHITESPACE 1 " " @@ -267,7 +267,7 @@ fn symbols() { MINUS 1 "-" GT 1 ">" WHITESPACE 5 "\n " - "###); + "##); } #[test] @@ -280,7 +280,7 @@ fn strings() { "\"\\" "multi line" - "#), @r###" + "#), @r#" WHITESPACE 5 "\n " STRING 15 "\"Hello, world!\"" WHITESPACE 5 "\n " @@ -292,7 +292,7 @@ fn strings() { WHITESPACE 5 "\n " STRING 16 "\"multi\n line\"" WHITESPACE 5 "\n " - "###); + "#); } #[test] @@ -302,7 +302,7 @@ fn keywords() { break do else false for fn if in nil return true while let mut struct class never loop pub super self package type - "#), @r###" + "#), @r#" WHITESPACE 5 "\n " BREAK_KW 5 "break" WHITESPACE 1 " " @@ -350,7 +350,7 @@ fn keywords() { WHITESPACE 1 " " TYPE_KW 4 "type" WHITESPACE 5 "\n " - "###); + "#); } #[test] @@ -358,10 +358,10 @@ fn unclosed_string() { insta::assert_snapshot!(dump_text_tokens( r#" "test - "#), @r###" + "#), @r#" WHITESPACE 5 "\n " STRING 10 "\"test\n " - "###); + "#); } #[test] @@ -372,7 +372,7 @@ fn binary_cmp() { a ==b a== b a == b - "#), @r###" + "#), @r#" WHITESPACE 5 "\n " IDENT 1 "a" EQ 1 "=" @@ -398,5 +398,5 @@ fn binary_cmp() { WHITESPACE 1 " " IDENT 1 "b" WHITESPACE 5 "\n " - "###); + "#); } diff --git a/crates/mun_syntax/src/tests/parser.rs b/crates/mun_syntax/src/tests/parser.rs index e99c74766..ffc669aa7 100644 --- a/crates/mun_syntax/src/tests/parser.rs +++ b/crates/mun_syntax/src/tests/parser.rs @@ -7,7 +7,7 @@ fn array_type() { fn main(a: [int]) { let a:[[bool]]; }"#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..54 FUNCTION_DEF@0..54 WHITESPACE@0..5 "\n " @@ -57,7 +57,7 @@ fn array_type() { SEMI@47..48 ";" WHITESPACE@48..53 "\n " R_CURLY@53..54 "}" - "### + "# ) } @@ -72,7 +72,7 @@ fn index_expr() { a[0] = c; let a = { [3,4,5] }[1]; }"#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..142 FUNCTION_DEF@0..142 WHITESPACE@0..5 "\n " @@ -212,7 +212,7 @@ fn index_expr() { SEMI@135..136 ";" WHITESPACE@136..141 "\n " R_CURLY@141..142 "}" - "### + "# ) } @@ -226,7 +226,7 @@ fn array_expr() { let a = [call(123)] let a = [Struct { }, Struct { }] }"#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..135 FUNCTION_DEF@0..135 WHITESPACE@0..5 "\n " @@ -338,7 +338,7 @@ fn array_expr() { R_BRACKET@128..129 "]" WHITESPACE@129..134 "\n " R_CURLY@134..135 "}" - "### + "# ) } @@ -349,7 +349,7 @@ fn missing_field_expr() { fn foo() { var. }"#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..34 FUNCTION_DEF@0..34 WHITESPACE@0..5 "\n " @@ -374,7 +374,7 @@ fn missing_field_expr() { WHITESPACE@28..33 "\n " R_CURLY@33..34 "}" error Offset(28): expected field name or number - "###); + "#); } #[test] @@ -395,7 +395,7 @@ fn function() { pub fn d() {} pub fn c()->never {} fn b(value:number)->number {}"#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..189 WHITESPACE@0..5 "\n " COMMENT@5..27 "// Source file comment" @@ -503,7 +503,7 @@ fn function() { BLOCK_EXPR@187..189 L_CURLY@187..188 "{" R_CURLY@188..189 "}" - "###); + "#); } #[test] @@ -515,7 +515,7 @@ fn block() { let b:i32; let c:string; }"#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..77 FUNCTION_DEF@0..77 WHITESPACE@0..5 "\n " @@ -567,7 +567,7 @@ fn block() { SEMI@70..71 ";" WHITESPACE@71..76 "\n " R_CURLY@76..77 "}" - "###); + "#); } #[test] @@ -582,7 +582,7 @@ fn literals() { let e = "Hello, world!" } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..144 FUNCTION_DEF@0..139 WHITESPACE@0..5 "\n " @@ -663,7 +663,7 @@ fn literals() { WHITESPACE@133..138 "\n " R_CURLY@138..139 "}" WHITESPACE@139..144 "\n " - "###); + "#); } #[test] @@ -690,7 +690,7 @@ fn struct_def() { struct Foo(f64,); struct Foo(f64, i32) "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..468 WHITESPACE@0..5 "\n " STRUCT_DEF@5..15 @@ -906,7 +906,7 @@ fn struct_def() { error Offset(87): expected a declaration error Offset(178): expected a field declaration error Offset(366): expected a type - "###); + "#); } #[test] @@ -918,7 +918,7 @@ fn unary_expr() { let b = !!true; } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..71 FUNCTION_DEF@0..66 WHITESPACE@0..5 "\n " @@ -969,7 +969,7 @@ fn unary_expr() { WHITESPACE@60..65 "\n " R_CURLY@65..66 "}" WHITESPACE@66..71 "\n " - "###); + "#); } #[test] @@ -981,7 +981,7 @@ fn binary_expr() { let b = 3*4+10/2 } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..73 FUNCTION_DEF@0..68 WHITESPACE@0..5 "\n " @@ -1042,7 +1042,7 @@ fn binary_expr() { WHITESPACE@62..67 "\n " R_CURLY@67..68 "}" WHITESPACE@68..73 "\n " - "###); + "#); } #[test] @@ -1058,7 +1058,7 @@ fn expression_statement() { -3 } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..148 FUNCTION_DEF@0..143 WHITESPACE@0..5 "\n " @@ -1154,7 +1154,7 @@ fn expression_statement() { WHITESPACE@137..142 "\n " R_CURLY@142..143 "}" WHITESPACE@143..148 "\n " - "###); + "#); } #[test] @@ -1166,7 +1166,7 @@ fn function_calls() { bar(i+1) } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..74 FUNCTION_DEF@0..25 WHITESPACE@0..5 "\n " @@ -1236,7 +1236,7 @@ fn function_calls() { WHITESPACE@63..68 "\n " R_CURLY@68..69 "}" WHITESPACE@69..74 "\n " - "###); + "#); } #[test] @@ -1248,7 +1248,7 @@ fn patterns() { let _ = a; } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..71 FUNCTION_DEF@0..66 WHITESPACE@0..5 "\n " @@ -1302,7 +1302,7 @@ fn patterns() { WHITESPACE@60..65 "\n " R_CURLY@65..66 "}" WHITESPACE@66..71 "\n " - "###); + "#); } #[test] @@ -1322,7 +1322,7 @@ fn arithmetic_operands() { let _ = a ^ b; } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..259 FUNCTION_DEF@0..254 WHITESPACE@0..5 "\n " @@ -1579,7 +1579,7 @@ fn arithmetic_operands() { WHITESPACE@248..253 "\n " R_CURLY@253..254 "}" WHITESPACE@254..259 "\n " - "###); + "#); } #[test] @@ -1600,7 +1600,7 @@ fn assignment_operands() { a ^= b; } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..208 FUNCTION_DEF@0..203 WHITESPACE@0..5 "\n " @@ -1803,7 +1803,7 @@ fn assignment_operands() { WHITESPACE@197..202 "\n " R_CURLY@202..203 "}" WHITESPACE@203..208 "\n " - "###); + "#); } #[test] @@ -1820,7 +1820,7 @@ fn compare_operands() { let _ = a >= b; } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..193 FUNCTION_DEF@0..188 WHITESPACE@0..5 "\n " @@ -2005,7 +2005,7 @@ fn compare_operands() { WHITESPACE@182..187 "\n " R_CURLY@187..188 "}" WHITESPACE@188..193 "\n " - "###); + "#); } #[test] @@ -2017,7 +2017,7 @@ fn logic_operands() { let _ = a && b; } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..75 FUNCTION_DEF@0..70 WHITESPACE@0..5 "\n " @@ -2082,7 +2082,7 @@ fn logic_operands() { WHITESPACE@64..69 "\n " R_CURLY@69..70 "}" WHITESPACE@70..75 "\n " - "###); + "#); } #[test] @@ -2096,7 +2096,7 @@ fn if_expr() { if {true} {} else {} } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..148 FUNCTION_DEF@0..143 WHITESPACE@0..5 "\n " @@ -2197,7 +2197,7 @@ fn if_expr() { WHITESPACE@137..142 "\n " R_CURLY@142..143 "}" WHITESPACE@143..148 "\n " - "###); + "#); } #[test] @@ -2208,7 +2208,7 @@ fn block_expr() { {3} } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..38 FUNCTION_DEF@0..33 WHITESPACE@0..5 "\n " @@ -2231,7 +2231,7 @@ fn block_expr() { WHITESPACE@27..32 "\n " R_CURLY@32..33 "}" WHITESPACE@33..38 "\n " - "###); + "#); } #[test] @@ -2243,7 +2243,7 @@ fn return_expr() { return 50; } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..61 FUNCTION_DEF@0..56 WHITESPACE@0..5 "\n " @@ -2273,7 +2273,7 @@ fn return_expr() { WHITESPACE@50..55 "\n " R_CURLY@55..56 "}" WHITESPACE@56..61 "\n " - "###); + "#); } #[test] @@ -2283,7 +2283,7 @@ fn loop_expr() { fn foo() { loop {} }"#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..37 FUNCTION_DEF@0..37 WHITESPACE@0..5 "\n " @@ -2306,7 +2306,7 @@ fn loop_expr() { R_CURLY@30..31 "}" WHITESPACE@31..36 "\n " R_CURLY@36..37 "}" - "###); + "#); } #[test] @@ -2319,7 +2319,7 @@ fn break_expr() { if break 4 { 3; } } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..91 FUNCTION_DEF@0..86 WHITESPACE@0..5 "\n " @@ -2379,7 +2379,7 @@ fn break_expr() { WHITESPACE@80..85 "\n " R_CURLY@85..86 "}" WHITESPACE@86..91 "\n " - "###); + "#); } #[test] @@ -2391,7 +2391,7 @@ fn while_expr() { while { true } {}; } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..76 FUNCTION_DEF@0..71 WHITESPACE@0..5 "\n " @@ -2439,7 +2439,7 @@ fn while_expr() { WHITESPACE@65..70 "\n " R_CURLY@70..71 "}" WHITESPACE@71..76 "\n " - "###); + "#); } #[test] @@ -2456,7 +2456,7 @@ fn struct_lit() { T(1.23, 4,) } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..171 FUNCTION_DEF@0..166 WHITESPACE@0..5 "\n " @@ -2606,7 +2606,7 @@ fn struct_lit() { WHITESPACE@160..165 "\n " R_CURLY@165..166 "}" WHITESPACE@166..171 "\n " - "###); + "#); } #[test] @@ -2624,7 +2624,7 @@ fn struct_field_index() { foo.a.0 } "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..177 FUNCTION_DEF@0..172 WHITESPACE@0..5 "\n " @@ -2737,7 +2737,7 @@ fn struct_field_index() { WHITESPACE@166..171 "\n " R_CURLY@171..172 "}" WHITESPACE@172..177 "\n " - "###); + "#); } #[test] @@ -2750,7 +2750,7 @@ fn memory_type_specifier() { struct() Err1 {}; // error: expected memory type specifier struct(foo) Err2 {}; // error: expected memory type specifier "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..205 WHITESPACE@0..5 "\n " STRUCT_DEF@5..19 @@ -2830,7 +2830,7 @@ fn memory_type_specifier() { WHITESPACE@200..205 "\n " error Offset(80): expected memory type specifier error Offset(146): expected memory type specifier - "###); + "#); } #[test] @@ -2843,7 +2843,7 @@ fn visibility() { pub(package) fn bar() {} pub fn baz() {} "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..140 WHITESPACE@0..5 "\n " STRUCT_DEF@5..23 @@ -2935,7 +2935,7 @@ fn visibility() { L_CURLY@133..134 "{" R_CURLY@134..135 "}" WHITESPACE@135..140 "\n " - "###); + "#); } #[test] @@ -2944,7 +2944,7 @@ fn extern_fn() { r#" pub extern fn foo(); "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..30 FUNCTION_DEF@0..25 WHITESPACE@0..5 "\n " @@ -2963,7 +2963,7 @@ fn extern_fn() { R_PAREN@23..24 ")" SEMI@24..25 ";" WHITESPACE@25..30 "\n " - "###); + "#); } #[test] @@ -2973,7 +2973,7 @@ fn type_alias_def() { type Foo = i32; type Bar = Foo; "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..45 WHITESPACE@0..5 "\n " TYPE_ALIAS_DEF@5..20 @@ -3006,7 +3006,7 @@ fn type_alias_def() { IDENT@36..39 "Foo" SEMI@39..40 ";" WHITESPACE@40..45 "\n " - "###); + "#); } #[test] fn function_return_path() { @@ -3017,7 +3017,7 @@ fn function_return_path() { fn main2() -> package::Foo {} fn main3() -> package::foo::Foo {} "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..156 FUNCTION_DEF@0..34 WHITESPACE@0..9 "\n " @@ -3129,7 +3129,7 @@ fn function_return_path() { L_CURLY@149..150 "{" R_CURLY@150..151 "}" WHITESPACE@151..156 "\n " - "###); + "#); } #[test] @@ -3164,7 +3164,7 @@ fn use_() { }; use Foo as _; "#, - ).debug_dump(), @r###" + ).debug_dump(), @r#" SOURCE_FILE@0..726 WHITESPACE@0..9 "\n " COMMENT@9..24 "// Simple paths" @@ -3496,5 +3496,5 @@ fn use_() { error Offset(367): expected a declaration error Offset(368): expected a declaration error Offset(369): expected a declaration - "###); + "#); } diff --git a/crates/mun_target/src/lib.rs b/crates/mun_target/src/lib.rs index 535e5eedb..8ed1a008c 100644 --- a/crates/mun_target/src/lib.rs +++ b/crates/mun_target/src/lib.rs @@ -17,5 +17,5 @@ pub fn host_triple() -> &'static str { // Instead of grabbing the host triple (for the current host), we grab (at // compile time) the target triple that this rustc is built with and // calling that (at runtime) the host triple. - (option_env!("CFG_COMPILER_HOST_TRIPLE")).expect("CFG_COMPILER_HOST_TRIPLE") + env!("CFG_COMPILER_HOST_TRIPLE") } diff --git a/rust-toolchain b/rust-toolchain index 65ee09598..5e3a42566 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.67.0 +1.73.0 From 1bf607de8cc6d4a865afffd517fef5166ad43918 Mon Sep 17 00:00:00 2001 From: Bas Zalmstra Date: Tue, 19 Dec 2023 13:16:23 +0100 Subject: [PATCH 2/3] fix: clippy errors --- crates/mun_codegen/src/code_gen/context.rs | 5 +++-- crates/mun_codegen/src/db.rs | 7 ++++--- crates/mun_codegen/src/value/global.rs | 5 +---- crates/mun_codegen/src/value/mod.rs | 4 ++-- crates/mun_hir/src/arena.rs | 2 +- crates/mun_hir/src/ids.rs | 16 +++++++++++----- crates/mun_hir/src/item_tree.rs | 7 +++---- crates/mun_memory/src/diff.rs | 4 ++-- crates/mun_memory/src/gc/mark_sweep.rs | 22 ++++++++++++++-------- crates/mun_memory/src/mapping.rs | 11 +++++++---- 10 files changed, 48 insertions(+), 35 deletions(-) diff --git a/crates/mun_codegen/src/code_gen/context.rs b/crates/mun_codegen/src/code_gen/context.rs index d961dbf90..556c5d22a 100644 --- a/crates/mun_codegen/src/code_gen/context.rs +++ b/crates/mun_codegen/src/code_gen/context.rs @@ -1,6 +1,7 @@ use crate::{ir::ty::HirTypeCache, CodeGenDatabase}; use inkwell::{context::Context, module::Module, targets::TargetMachine, types::StructType}; -use std::{cell::RefCell, collections::HashMap, sync::Arc}; +use std::rc::Rc; +use std::{cell::RefCell, collections::HashMap}; pub struct CodeGenContext<'db, 'ink> { /// The current LLVM context @@ -19,7 +20,7 @@ pub struct CodeGenContext<'db, 'ink> { pub optimization_level: inkwell::OptimizationLevel, /// The target to generate code for - pub target_machine: Arc, + pub target_machine: Rc, } impl<'db, 'ink> CodeGenContext<'db, 'ink> { diff --git a/crates/mun_codegen/src/db.rs b/crates/mun_codegen/src/db.rs index a3df4603b..2f65ae565 100644 --- a/crates/mun_codegen/src/db.rs +++ b/crates/mun_codegen/src/db.rs @@ -1,6 +1,7 @@ use crate::{AssemblyIr, ModuleGroupId, ModulePartition, TargetAssembly}; use by_address::ByAddress; use inkwell::targets::{CodeModel, InitializationConfig, RelocMode, Target, TargetTriple}; +use std::rc::Rc; use std::sync::Arc; /// The `CodeGenDatabase` enables caching of code generation stages. Inkwell/LLVM objects are not @@ -23,7 +24,7 @@ pub trait CodeGenDatabase: /// Returns the inkwell target machine that completely describes the code generation target. All /// target-specific information should be accessible through this interface. - fn target_machine(&self) -> ByAddress>; + fn target_machine(&self) -> ByAddress>; /// Returns a file containing the IR for the specified module. #[salsa::invoke(crate::assembly::build_assembly_ir)] @@ -36,7 +37,7 @@ pub trait CodeGenDatabase: /// Constructs the primary interface to the complete machine description for the target machine. All /// target-specific information should be accessible through this interface. -fn target_machine(db: &dyn CodeGenDatabase) -> ByAddress> { +fn target_machine(db: &dyn CodeGenDatabase) -> ByAddress> { // Get the HIR target let target = db.target(); @@ -61,5 +62,5 @@ fn target_machine(db: &dyn CodeGenDatabase) -> ByAddress { impl<'ink, T: ?Sized> Clone for Global<'ink, T> { fn clone(&self) -> Self { - Global { - value: self.value, - data: self.data, - } + *self } } diff --git a/crates/mun_codegen/src/value/mod.rs b/crates/mun_codegen/src/value/mod.rs index 14a6ff692..c78791d7c 100644 --- a/crates/mun_codegen/src/value/mod.rs +++ b/crates/mun_codegen/src/value/mod.rs @@ -221,7 +221,7 @@ macro_rules! impl_value_type_value { } } -impl_value_type_value! ( +impl_value_type_value!( inkwell::types::IntType<'ink> => inkwell::values::IntValue<'ink>, inkwell::types::FloatType<'ink> => inkwell::values::FloatValue<'ink>, inkwell::types::ArrayType<'ink> => inkwell::values::ArrayValue<'ink>, @@ -333,7 +333,7 @@ impl<'ink, T: ConcreteValueType<'ink> + ?Sized> AsValue<'ink, T> for Value<'ink, impl<'ink, T: ConcreteValueType<'ink> + ?Sized> Clone for Value<'ink, T> { fn clone(&self) -> Self { - Value { value: self.value } + *self } } diff --git a/crates/mun_hir/src/arena.rs b/crates/mun_hir/src/arena.rs index 212c5c622..97bbddfaf 100644 --- a/crates/mun_hir/src/arena.rs +++ b/crates/mun_hir/src/arena.rs @@ -63,7 +63,7 @@ impl Hash for Idx { impl PartialOrd for Idx { fn partial_cmp(&self, other: &Self) -> Option { - self.raw.partial_cmp(&other.raw) + Some(self.cmp(other)) } } diff --git a/crates/mun_hir/src/ids.rs b/crates/mun_hir/src/ids.rs index ea1b1cab5..bc1b8d763 100644 --- a/crates/mun_hir/src/ids.rs +++ b/crates/mun_hir/src/ids.rs @@ -16,6 +16,7 @@ impl PartialEq for ItemLoc { self.id == other.id } } + impl Eq for ItemLoc {} impl Hash for ItemLoc { @@ -26,9 +27,10 @@ impl Hash for ItemLoc { impl Clone for ItemLoc { fn clone(&self) -> ItemLoc { - ItemLoc { id: self.id } + *self } } + impl Copy for ItemLoc {} #[derive(Debug)] @@ -39,10 +41,7 @@ pub struct AssocItemLoc { impl Clone for AssocItemLoc { fn clone(&self) -> Self { - Self { - module: self.module, - id: self.id, - } + *self } } @@ -105,6 +104,7 @@ pub struct ModuleId { #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)] pub struct FunctionId(salsa::InternId); + pub(crate) type FunctionLoc = AssocItemLoc; impl_intern!( FunctionId, @@ -115,11 +115,13 @@ impl_intern!( #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct StructId(salsa::InternId); + pub(crate) type StructLoc = AssocItemLoc; impl_intern!(StructId, StructLoc, intern_struct, lookup_intern_struct); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct TypeAliasId(salsa::InternId); + pub(crate) type TypeAliasLoc = AssocItemLoc; impl_intern!( TypeAliasId, @@ -152,21 +154,25 @@ impl From for ItemDefinitionId { ItemDefinitionId::ModuleId(id) } } + impl From for ItemDefinitionId { fn from(id: FunctionId) -> Self { ItemDefinitionId::FunctionId(id) } } + impl From for ItemDefinitionId { fn from(id: StructId) -> Self { ItemDefinitionId::StructId(id) } } + impl From for ItemDefinitionId { fn from(id: TypeAliasId) -> Self { ItemDefinitionId::TypeAliasId(id) } } + impl From for ItemDefinitionId { fn from(id: PrimitiveType) -> Self { ItemDefinitionId::PrimitiveType(id) diff --git a/crates/mun_hir/src/item_tree.rs b/crates/mun_hir/src/item_tree.rs index 463cbd44e..f59eab20b 100644 --- a/crates/mun_hir/src/item_tree.rs +++ b/crates/mun_hir/src/item_tree.rs @@ -139,12 +139,10 @@ pub struct LocalItemTreeId { impl Clone for LocalItemTreeId { fn clone(&self) -> Self { - Self { - index: self.index, - _p: PhantomData, - } + *self } } + impl Copy for LocalItemTreeId {} impl PartialEq for LocalItemTreeId { @@ -152,6 +150,7 @@ impl PartialEq for LocalItemTreeId { self.index == other.index } } + impl Eq for LocalItemTreeId {} impl Hash for LocalItemTreeId { diff --git a/crates/mun_memory/src/diff.rs b/crates/mun_memory/src/diff.rs index a471f262a..0d95f6752 100644 --- a/crates/mun_memory/src/diff.rs +++ b/crates/mun_memory/src/diff.rs @@ -266,7 +266,7 @@ fn append_struct_mapping( // Any remaining unused deletions must have been deleted. used_deletions .into_iter() - .zip(deletions.into_iter()) + .zip(deletions) .for_each(|(used, (_, old_index, ty, _))| { if !used { mapping.push(StructDiff::Delete { @@ -279,7 +279,7 @@ fn append_struct_mapping( // Any remaining unused insertions must have been inserted. used_insertions .into_iter() - .zip(insertions.into_iter()) + .zip(insertions) .for_each(|(used, (_, new_index, ty, _))| { if !used { mapping.push(StructDiff::Insert { diff --git a/crates/mun_memory/src/gc/mark_sweep.rs b/crates/mun_memory/src/gc/mark_sweep.rs index a61483af9..088223b0f 100644 --- a/crates/mun_memory/src/gc/mark_sweep.rs +++ b/crates/mun_memory/src/gc/mark_sweep.rs @@ -104,7 +104,7 @@ impl TraceEvent { struct_type: ty.into_owned(), field_index: 0, })) - } + }; } TypeKind::Array(_) => Some(TraceEvent::Reference(ptr.cast())), } @@ -324,7 +324,12 @@ impl ArrayHandle { unsafe { NonNull::new_unchecked( - (self.obj.as_ref().data.array.as_ptr().cast::() as *mut u8) + self.obj + .as_ref() + .data + .array + .as_ptr() + .cast::() .add(padded_header_size), ) } @@ -934,8 +939,8 @@ where mapping::Action::StructMapFromGc { old_ty, old_offset } => { let conversion = conversions.get(old_ty).unwrap_or_else(|| { panic!( - "If the struct changed, there must also be a conversion for type: {old_ty:#?}.", - ) + "If the struct changed, there must also be a conversion for type: {old_ty:#?}.", + ) }); // Safety: we already hold a write lock on `objects`, so this is legal. @@ -960,8 +965,8 @@ where let conversion = conversions.get(old_ty).unwrap_or_else(|| { panic!( - "If the struct changed, there must also be a conversion for type: {old_ty:#?}.", - ) + "If the struct changed, there must also be a conversion for type: {old_ty:#?}.", + ) }); // Map in-memory struct to heap-allocated struct @@ -986,8 +991,8 @@ where mapping::Action::StructMapInPlace { old_ty, old_offset } => { let conversion = conversions.get(old_ty).unwrap_or_else(|| { panic!( - "If the struct changed, there must also be a conversion for type: {old_ty:#?}.", - ) + "If the struct changed, there must also be a conversion for type: {old_ty:#?}.", + ) }); map_struct( @@ -1063,6 +1068,7 @@ union ObjectInfoData { /// An `ObjectInfo` is thread-safe. unsafe impl Send for ObjectInfo {} + unsafe impl Sync for ObjectInfo {} impl From for *const ObjectInfo { diff --git a/crates/mun_memory/src/mapping.rs b/crates/mun_memory/src/mapping.rs index 2cfcb6f23..684d2dd78 100644 --- a/crates/mun_memory/src/mapping.rs +++ b/crates/mun_memory/src/mapping.rs @@ -6,6 +6,7 @@ use crate::{ r#type::Type, ArrayType, TypeKind, }; +use itertools::Itertools; use std::collections::{HashMap, HashSet}; /// The type mapping needed to convert an old into a new set of unique and ordered values. @@ -177,8 +178,9 @@ impl Mapping { pub unsafe fn field_mapping(old_ty: &Type, new_ty: &Type, diff: &[FieldDiff]) -> StructMapping { let old_fields = old_ty .as_struct() - .map(|s| s.fields().iter().collect()) - .unwrap_or_else(Vec::new); + .into_iter() + .flat_map(|s| s.fields().iter()) + .collect_vec(); let deletions: HashSet = diff .iter() @@ -284,8 +286,9 @@ pub unsafe fn field_mapping(old_ty: &Type, new_ty: &Type, diff: &[FieldDiff]) -> let new_fields = new_ty .as_struct() - .map(|s| Vec::from_iter(s.fields().iter())) - .unwrap_or_else(Vec::new); + .into_iter() + .flat_map(|s| s.fields().iter()) + .collect_vec(); StructMapping { field_mapping: mapping .into_iter() From 897ae259589dc9a933f42f67a8bec2ed5e27682c Mon Sep 17 00:00:00 2001 From: Wodann Date: Tue, 19 Dec 2023 07:55:00 -0600 Subject: [PATCH 3/3] misc: apply review suggestion --- crates/mun_abi/src/struct_info.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/mun_abi/src/struct_info.rs b/crates/mun_abi/src/struct_info.rs index 9e8f0fff9..481bd036a 100644 --- a/crates/mun_abi/src/struct_info.rs +++ b/crates/mun_abi/src/struct_info.rs @@ -26,9 +26,8 @@ pub struct StructDefinition<'a> { /// Represents the kind of memory management a struct uses. #[repr(u8)] -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize))] -#[derive(Default)] pub enum StructMemoryKind { /// A garbage collected struct is allocated on the heap and uses reference semantics when passed /// around.