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 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
9 changes: 2 additions & 7 deletions crates/mun_abi/src/struct_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ 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))]
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 +79,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 @@ impl<'ink> PointerValueType<'ink> for f32 {
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())
}
}
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())
}
}

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

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 @@ impl<'ink> PointerValueType<'ink> for *const std::ffi::c_void {
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 @@ impl<'ink, T: PointerValueType<'ink>> PointerValueType<'ink> for *mut T {
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 All @@ -62,7 +62,7 @@ impl<'ink, T: PointerValueType<'ink>> PointerValueType<'ink> for *const T {
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> Hash for Idx<T> {

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

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 @@ impl<N: ItemTreeNode> PartialEq for ItemLoc<N> {
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> Hash for ItemLoc<N> {

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

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

#[derive(Debug)]
Expand All @@ -39,10 +41,7 @@ pub struct AssocItemLoc<N: ItemTreeNode> {

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 @@ pub struct ModuleId {

#[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 @@ impl_intern!(

#[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 @@ impl From<ModuleId> for ItemDefinitionId {
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 @@ pub struct LocalItemTreeId<N: ItemTreeNode> {

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

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 @@ 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,
};
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 @@ impl TraceEvent {
struct_type: ty.into_owned(),
field_index: 0,
}))
}
};
}
TypeKind::Array(_) => Some(TraceEvent::Reference(ptr.cast())),
}
Expand Down Expand Up @@ -324,7 +324,12 @@ impl ArrayHandle {

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 @@ 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.
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -1063,6 +1068,7 @@ union ObjectInfoData {

/// 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