Skip to content
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
2 changes: 1 addition & 1 deletion crates/mun_codegen/src/code_gen/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ fn get_function_definition_array<'ink, 'a>(
),
}
})
.as_value(context)
.into_value(context)
.into_const_private_global("fn.get_info.functions", context)
}

Expand Down
6 changes: 2 additions & 4 deletions crates/mun_codegen/src/ir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,13 +721,11 @@ impl<'db, 'ink, 't> BodyIrGenerator<'db, 'ink, 't> {
) -> Option<BasicValueEnum<'ink>> {
let lhs: IntValue = self
.gen_expr(lhs_expr)
.map(|value| self.opt_deref_value(lhs_expr, value))
.expect("no lhs value")
.map(|value| self.opt_deref_value(lhs_expr, value))?
.into_int_value();
let rhs: IntValue = self
.gen_expr(rhs_expr)
.map(|value| self.opt_deref_value(rhs_expr, value))
.expect("no rhs value")
.map(|value| self.opt_deref_value(rhs_expr, value))?
.into_int_value();
match op {
BinaryOp::ArithOp(op) => Some(self.gen_arith_bin_op_bool(lhs, rhs, op).into()),
Expand Down
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 @@ -342,7 +342,7 @@ impl<'db, 'ink, 't> TypeTableBuilder<'db, 'ink, 't> {
type_info_to_index.insert(type_info, index);
ptr
})
.as_value(self.value_context);
.into_value(self.value_context);

// If there are types, introduce a special global that contains all the TypeInfos
if !type_info_ptrs.is_empty() {
Expand Down
8 changes: 4 additions & 4 deletions crates/mun_codegen/src/value/array_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub trait IterAsIrValue<'ink, E: SizedValueType<'ink>, T: AsValue<'ink, E>>:
IntoIterator<Item = T>
{
/// Returns a `Value<[E]>` that contains all values converted to `Value<E>`.
fn as_value(self, context: &IrValueContext<'ink, '_, '_>) -> Value<'ink, [E]>;
fn into_value(self, context: &IrValueContext<'ink, '_, '_>) -> Value<'ink, [E]>;

/// Constructs a const private global and returns a pointer to it.
fn into_const_private_pointer<S: AsRef<str>>(
Expand All @@ -129,7 +129,7 @@ pub trait IterAsIrValue<'ink, E: SizedValueType<'ink>, T: AsValue<'ink, E>>:
E: PointerValueType<'ink>,
Self: Sized,
{
self.as_value(context)
self.into_value(context)
.into_const_private_global(name, context)
.as_value(context)
}
Expand All @@ -150,7 +150,7 @@ pub trait IterAsIrValue<'ink, E: SizedValueType<'ink>, T: AsValue<'ink, E>>:
{
let mut iter = self.into_iter().peekable();
if iter.peek().is_some() {
iter.as_value(context)
iter.into_value(context)
.into_const_private_global(name, context)
.as_value(context)
} else {
Expand All @@ -164,7 +164,7 @@ impl<'ink, E: SizedValueType<'ink>, T: AsValue<'ink, E>, I: IntoIterator<Item =
where
E::Value: ConstArrayValue<'ink>,
{
fn as_value(self, context: &IrValueContext<'ink, '_, '_>) -> Value<'ink, [E]> {
fn into_value(self, context: &IrValueContext<'ink, '_, '_>) -> Value<'ink, [E]> {
let element_type = E::get_ir_type(context.type_context);
// eprintln!("constructing array of type {:?}", element_type);
let elements: Vec<E::Value> = self
Expand Down
62 changes: 31 additions & 31 deletions crates/mun_hir/src/package_defs/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,48 +494,48 @@ struct ModCollectorContext<'a, 'db> {
impl<'a> ModCollectorContext<'a, '_> {
fn collect(&mut self, items: &[ModItem]) {
for &item in items {
let definition = match item {
let DefData {
id,
name,
visibility,
has_constructor,
} = match item {
ModItem::Function(id) => self.collect_function(id),
ModItem::Struct(id) => self.collect_struct(id),
ModItem::TypeAlias(id) => self.collect_type_alias(id),
ModItem::Import(id) => self.collect_import(id),
ModItem::Import(id) => {
self.collect_import(id);
continue;
}
};

if let Some(DefData {
id,
name,
visibility,
has_constructor,
}) = definition
{
self.def_collector.package_defs.modules[self.module_id].add_definition(id);
let visibility = self
.def_collector
.package_defs
.module_tree
.resolve_visibility(self.def_collector.db, self.module_id, visibility);
self.def_collector.package_defs.modules[self.module_id].add_resolution(
name.clone(),
PerNs::from_definition(id, visibility, has_constructor),
);
}
self.def_collector.package_defs.modules[self.module_id].add_definition(id);
let visibility = self
.def_collector
.package_defs
.module_tree
.resolve_visibility(self.def_collector.db, self.module_id, visibility);
self.def_collector.package_defs.modules[self.module_id].add_resolution(
name.clone(),
PerNs::from_definition(id, visibility, has_constructor),
);
}
}

/// Collects the definition data from an import statement.
fn collect_import(&mut self, id: LocalItemTreeId<item_tree::Import>) -> Option<DefData<'a>> {
fn collect_import(&mut self, id: LocalItemTreeId<item_tree::Import>) {
self.def_collector.unresolved_imports.push(ImportDirective {
module_id: self.module_id,
import: Import::from_use(&self.item_tree, InFile::new(self.file_id, id)),
status: PartiallyResolvedImport::Unresolved,
});
None
}

/// Collects the definition data from a `Function`
fn collect_function(&self, id: LocalItemTreeId<Function>) -> Option<DefData<'a>> {
#[warn(clippy::unnecessary_wraps)]
fn collect_function(&self, id: LocalItemTreeId<Function>) -> DefData<'a> {
let func = &self.item_tree[id];
Some(DefData {
DefData {
id: FunctionLoc {
module: ModuleId {
package: self.def_collector.package_id,
Expand All @@ -548,13 +548,13 @@ impl<'a> ModCollectorContext<'a, '_> {
name: &func.name,
visibility: &self.item_tree[func.visibility],
has_constructor: false,
})
}
}

/// Collects the definition data from a `Struct`
fn collect_struct(&self, id: LocalItemTreeId<Struct>) -> Option<DefData<'a>> {
fn collect_struct(&self, id: LocalItemTreeId<Struct>) -> DefData<'a> {
let adt = &self.item_tree[id];
Some(DefData {
DefData {
id: StructLoc {
module: ModuleId {
package: self.def_collector.package_id,
Expand All @@ -567,13 +567,13 @@ impl<'a> ModCollectorContext<'a, '_> {
name: &adt.name,
visibility: &self.item_tree[adt.visibility],
has_constructor: adt.kind != StructDefKind::Record,
})
}
}

/// Collects the definition data from a `TypeAlias`
fn collect_type_alias(&self, id: LocalItemTreeId<TypeAlias>) -> Option<DefData<'a>> {
fn collect_type_alias(&self, id: LocalItemTreeId<TypeAlias>) -> DefData<'a> {
let type_alias = &self.item_tree[id];
Some(DefData {
DefData {
id: TypeAliasLoc {
module: ModuleId {
package: self.def_collector.package_id,
Expand All @@ -586,7 +586,7 @@ impl<'a> ModCollectorContext<'a, '_> {
name: &type_alias.name,
visibility: &self.item_tree[type_alias.visibility],
has_constructor: false,
})
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions crates/mun_hir/src/ty/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ macro_rules! ty_app {
})
};
($ctor:pat) => {
$crate::Ty::Apply($crate::ApplicationTy {
ctor: $ctor,
..
})
$crate::Ty::Apply($crate::ApplicationTy { ctor: $ctor, .. })
};
}

Expand Down
2 changes: 2 additions & 0 deletions crates/mun_language_server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl LanguageServerState {
}

/// Handles a task sent by another async task
#[allow(clippy::unnecessary_wraps)]
fn handle_task(&mut self, task: Task) -> anyhow::Result<()> {
match task {
Task::Notify(notification) => {
Expand All @@ -198,6 +199,7 @@ impl LanguageServerState {
}

/// Handles a change to the underlying virtual file system.
#[allow(clippy::unnecessary_wraps)]
fn handle_vfs_task(&mut self, mut task: vfs::MonitorMessage) -> anyhow::Result<()> {
loop {
match task {
Expand Down
46 changes: 21 additions & 25 deletions crates/mun_language_server/src/state/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ impl LanguageServerState {
&mut self,
params: lsp_types::DidOpenTextDocumentParams,
) -> anyhow::Result<()> {
if let Ok(path) = from_lsp::abs_path(&params.text_document.uri) {
self.open_docs.insert(path.clone());
self.vfs
.write()
.set_file_contents(&path, Some(params.text_document.text.into_bytes()));
}
let path = from_lsp::abs_path(&params.text_document.uri)?;
self.open_docs.insert(path.clone());
self.vfs
.write()
.set_file_contents(&path, Some(params.text_document.text.into_bytes()));
Ok(())
}

Expand All @@ -32,18 +31,17 @@ impl LanguageServerState {
text_document,
content_changes,
} = params;
if let Ok(path) = from_lsp::abs_path(&text_document.uri) {
let vfs = &mut *self.vfs.write();
let file_id = vfs
.file_id(&path)
.expect("we already checked that the file_id exists!");
let mut text = vfs
.file_contents(file_id)
.and_then(|contents| String::from_utf8(contents.to_vec()).ok())
.expect("if the file_id exists it must be valid utf8");
apply_document_changes(&mut text, content_changes);
vfs.set_file_contents(&path, Some(text.into_bytes()));
}
let path = from_lsp::abs_path(&text_document.uri)?;
let vfs = &mut *self.vfs.write();
let file_id = vfs
.file_id(&path)
.expect("we already checked that the file_id exists!");
let mut text = vfs
.file_contents(file_id)
.and_then(|contents| String::from_utf8(contents.to_vec()).ok())
.expect("if the file_id exists it must be valid utf8");
apply_document_changes(&mut text, content_changes);
vfs.set_file_contents(&path, Some(text.into_bytes()));
Ok(())
}

Expand All @@ -52,10 +50,9 @@ impl LanguageServerState {
&mut self,
params: lsp_types::DidCloseTextDocumentParams,
) -> anyhow::Result<()> {
if let Ok(path) = from_lsp::abs_path(&params.text_document.uri) {
self.open_docs.remove(&path);
self.vfs_monitor.reload(&path);
}
let path = from_lsp::abs_path(&params.text_document.uri)?;
self.open_docs.remove(&path);
self.vfs_monitor.reload(&path);
Ok(())
}

Expand All @@ -65,9 +62,8 @@ impl LanguageServerState {
params: lsp_types::DidChangeWatchedFilesParams,
) -> anyhow::Result<()> {
for change in params.changes {
if let Ok(path) = from_lsp::abs_path(&change.uri) {
self.vfs_monitor.reload(&path);
}
let path = from_lsp::abs_path(&change.uri)?;
self.vfs_monitor.reload(&path);
}
Ok(())
}
Expand Down
12 changes: 8 additions & 4 deletions crates/mun_memory/src/diff/myers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,14 @@ pub fn diff_length<T: Eq>(old: &[T], new: &[T]) -> usize {
v[idx - 1] + 1
};
let mut y = (x as isize - k) as usize;
while x < num_old && y < num_new && old[x] == new[y] {
x += 1;
y += 1;
}
let shortest_equal = old
.iter()
.skip(x)
.zip(new.iter().skip(y))
.take_while(|(a, b)| a == b)
.count();
x += shortest_equal;
y += shortest_equal;
v[idx] = x;
if x == num_old && y == num_new {
return d as usize;
Expand Down
15 changes: 3 additions & 12 deletions crates/mun_syntax/src/parsing/grammar/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,7 @@ fn postfix_expr(
loop {
lhs = match p.current() {
T!['('] => call_expr(p, lhs),
T![.] => match postfix_dot_expr(p, lhs) {
Ok(it) => it,
Err(it) => {
lhs = it;
break;
}
},
T![.] => postfix_dot_expr(p, lhs),
INDEX => field_expr(p, lhs),
_ => break,
}
Expand Down Expand Up @@ -251,16 +245,13 @@ fn arg_list(p: &mut Parser) {
m.complete(p, ARG_LIST);
}

fn postfix_dot_expr(
p: &mut Parser,
lhs: CompletedMarker,
) -> Result<CompletedMarker, CompletedMarker> {
fn postfix_dot_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
assert!(p.at(T![.]));
if p.nth(1) == IDENT && p.nth(2) == T!['('] {
unimplemented!("Method calls are not supported yet.");
}

Ok(field_expr(p, lhs))
field_expr(p, lhs)
}

fn field_expr(p: &mut Parser, lhs: CompletedMarker) -> CompletedMarker {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.49.0
1.50.0