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

bump: rust 1.73 #541

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 2 additions & 6 deletions crates/mun_abi/src/struct_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Wodann marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions crates/mun_codegen/src/code_gen/context.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,7 +20,7 @@ pub struct CodeGenContext<'db, 'ink> {
pub optimization_level: inkwell::OptimizationLevel,

/// The target to generate code for
pub target_machine: Arc<TargetMachine>,
pub target_machine: Rc<TargetMachine>,
}

impl<'db, 'ink> CodeGenContext<'db, 'ink> {
Expand Down
7 changes: 4 additions & 3 deletions crates/mun_codegen/src/db.rs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<Arc<inkwell::targets::TargetMachine>>;
fn target_machine(&self) -> ByAddress<Rc<inkwell::targets::TargetMachine>>;

/// Returns a file containing the IR for the specified module.
#[salsa::invoke(crate::assembly::build_assembly_ir)]
Expand All @@ -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<Arc<inkwell::targets::TargetMachine>> {
fn target_machine(db: &dyn CodeGenDatabase) -> ByAddress<Rc<inkwell::targets::TargetMachine>> {
// Get the HIR target
let target = db.target();

Expand All @@ -61,5 +62,5 @@ fn target_machine(db: &dyn CodeGenDatabase) -> ByAddress<Arc<inkwell::targets::T
)
.expect("could not create llvm target machine");

ByAddress(Arc::new(target_machine))
ByAddress(Rc::new(target_machine))
}
2 changes: 1 addition & 1 deletion crates/mun_codegen/src/ir/type_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions crates/mun_codegen/src/value/float_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> 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())

Check warning on line 31 in crates/mun_codegen/src/value/float_value.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_codegen/src/value/float_value.rs#L31

Added line #L31 was not covered by tests
}
}
impl<'ink> PointerValueType<'ink> for f64 {
fn get_ptr_type(
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> 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())

Check warning on line 39 in crates/mun_codegen/src/value/float_value.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_codegen/src/value/float_value.rs#L39

Added line #L39 was not covered by tests
}
}

Expand Down
5 changes: 1 addition & 4 deletions crates/mun_codegen/src/value/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ pub struct Global<'ink, T: ?Sized> {

impl<'ink, T: ?Sized> Clone for Global<'ink, T> {
fn clone(&self) -> Self {
Global {
value: self.value,
data: self.data,
}
*self
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/mun_codegen/src/value/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
}
}

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>,
Expand Down Expand Up @@ -333,7 +333,7 @@

impl<'ink, T: ConcreteValueType<'ink> + ?Sized> Clone for Value<'ink, T> {
fn clone(&self) -> Self {
Value { value: self.value }
*self

Check warning on line 336 in crates/mun_codegen/src/value/mod.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_codegen/src/value/mod.rs#L336

Added line #L336 was not covered by tests
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/mun_codegen/src/value/pointer_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> 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())
}
}

Expand Down Expand Up @@ -53,7 +53,7 @@
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> 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())

Check warning on line 56 in crates/mun_codegen/src/value/pointer_value.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_codegen/src/value/pointer_value.rs#L56

Added line #L56 was not covered by tests
}
}

Expand All @@ -62,7 +62,7 @@
context: &IrTypeContext<'ink, '_>,
address_space: Option<AddressSpace>,
) -> 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())
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/mun_codegen/tests/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -175,5 +175,5 @@ fn test_abi_compatibility() {
],
dependencies: [],
)
"###);
"#);
}
2 changes: 1 addition & 1 deletion crates/mun_hir/src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

impl<T> PartialOrd for Idx<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.raw.partial_cmp(&other.raw)
Some(self.cmp(other))

Check warning on line 66 in crates/mun_hir/src/arena.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_hir/src/arena.rs#L66

Added line #L66 was not covered by tests
}
}

Expand Down
16 changes: 11 additions & 5 deletions crates/mun_hir/src/ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
self.id == other.id
}
}

impl<N: ItemTreeNode> Eq for ItemLoc<N> {}

impl<N: ItemTreeNode> Hash for ItemLoc<N> {
Expand All @@ -26,9 +27,10 @@

impl<N: ItemTreeNode> Clone for ItemLoc<N> {
fn clone(&self) -> ItemLoc<N> {
ItemLoc { id: self.id }
*self

Check warning on line 30 in crates/mun_hir/src/ids.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_hir/src/ids.rs#L30

Added line #L30 was not covered by tests
}
}

impl<N: ItemTreeNode> Copy for ItemLoc<N> {}

#[derive(Debug)]
Expand All @@ -39,10 +41,7 @@

impl<N: ItemTreeNode> Clone for AssocItemLoc<N> {
fn clone(&self) -> Self {
Self {
module: self.module,
id: self.id,
}
*self
}
}

Expand Down Expand Up @@ -105,6 +104,7 @@

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
pub struct FunctionId(salsa::InternId);

pub(crate) type FunctionLoc = AssocItemLoc<Function>;
impl_intern!(
FunctionId,
Expand All @@ -115,11 +115,13 @@

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct StructId(salsa::InternId);

pub(crate) type StructLoc = AssocItemLoc<Struct>;
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<TypeAlias>;
impl_intern!(
TypeAliasId,
Expand Down Expand Up @@ -152,21 +154,25 @@
ItemDefinitionId::ModuleId(id)
}
}

impl From<FunctionId> for ItemDefinitionId {
fn from(id: FunctionId) -> Self {
ItemDefinitionId::FunctionId(id)
}
}

impl From<StructId> for ItemDefinitionId {
fn from(id: StructId) -> Self {
ItemDefinitionId::StructId(id)
}
}

impl From<TypeAliasId> for ItemDefinitionId {
fn from(id: TypeAliasId) -> Self {
ItemDefinitionId::TypeAliasId(id)
}
}

impl From<PrimitiveType> for ItemDefinitionId {
fn from(id: PrimitiveType) -> Self {
ItemDefinitionId::PrimitiveType(id)
Expand Down
7 changes: 3 additions & 4 deletions crates/mun_hir/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,19 +139,18 @@

impl<N: ItemTreeNode> Clone for LocalItemTreeId<N> {
fn clone(&self) -> Self {
Self {
index: self.index,
_p: PhantomData,
}
*self

Check warning on line 142 in crates/mun_hir/src/item_tree.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_hir/src/item_tree.rs#L142

Added line #L142 was not covered by tests
}
}

impl<N: ItemTreeNode> Copy for LocalItemTreeId<N> {}

impl<N: ItemTreeNode> PartialEq for LocalItemTreeId<N> {
fn eq(&self, other: &Self) -> bool {
self.index == other.index
}
}

impl<N: ItemTreeNode> Eq for LocalItemTreeId<N> {}

impl<N: ItemTreeNode> Hash for LocalItemTreeId<N> {
Expand Down
2 changes: 1 addition & 1 deletion crates/mun_language_server/src/state/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
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(),

Check warning on line 85 in crates/mun_language_server/src/state/workspace.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_language_server/src/state/workspace.rs#L85

Added line #L85 was not covered by tests
},
load: entries_to_load,
};
Expand Down
4 changes: 2 additions & 2 deletions crates/mun_memory/src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
22 changes: 14 additions & 8 deletions crates/mun_memory/src/gc/mark_sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
struct_type: ty.into_owned(),
field_index: 0,
}))
}
};
}
TypeKind::Array(_) => Some(TraceEvent::Reference(ptr.cast())),
}
Expand Down Expand Up @@ -324,7 +324,12 @@

unsafe {
NonNull::new_unchecked(
(self.obj.as_ref().data.array.as_ptr().cast::<u8>() as *mut u8)
self.obj
.as_ref()
.data
.array
.as_ptr()
.cast::<u8>()
.add(padded_header_size),
)
}
Expand Down Expand Up @@ -934,8 +939,8 @@
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:#?}.",
)

Check warning on line 943 in crates/mun_memory/src/gc/mark_sweep.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_memory/src/gc/mark_sweep.rs#L942-L943

Added lines #L942 - L943 were not covered by tests
});

// Safety: we already hold a write lock on `objects`, so this is legal.
Expand All @@ -960,8 +965,8 @@

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:#?}.",
)

Check warning on line 969 in crates/mun_memory/src/gc/mark_sweep.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_memory/src/gc/mark_sweep.rs#L968-L969

Added lines #L968 - L969 were not covered by tests
});

// Map in-memory struct to heap-allocated struct
Expand All @@ -986,8 +991,8 @@
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:#?}.",
)

Check warning on line 995 in crates/mun_memory/src/gc/mark_sweep.rs

View check run for this annotation

Codecov / codecov/patch

crates/mun_memory/src/gc/mark_sweep.rs#L994-L995

Added lines #L994 - L995 were not covered by tests
});

map_struct(
Expand Down Expand Up @@ -1063,6 +1068,7 @@

/// An `ObjectInfo` is thread-safe.
unsafe impl Send for ObjectInfo {}

unsafe impl Sync for ObjectInfo {}

impl From<GcPtr> for *const ObjectInfo {
Expand Down
Loading
Loading