Skip to content

Commit c3ad018

Browse files
chore: run fmt and fix clippy in moonbit test tooling
1 parent e859dd7 commit c3ad018

File tree

3 files changed

+24
-30
lines changed

3 files changed

+24
-30
lines changed

crates/moonbit/src/async_support.rs

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ use std::{
55

66
use heck::ToUpperCamelCase;
77
use wit_bindgen_core::{
8-
abi::{self, deallocate_lists_in_types, lift_from_memory, WasmSignature},
9-
dealias, uwriteln,
108
Direction, Files, Source,
9+
abi::{self, WasmSignature, deallocate_lists_in_types, lift_from_memory},
10+
dealias, uwriteln,
1111
wit_parser::{
1212
Function, LiftLowerAbi, ManglingAndAbi, Param, Type, TypeDefKind, TypeId, WasmImport,
1313
},
1414
};
1515

1616
use crate::pkg::ToMoonBitIdent;
17-
use crate::{ffi, indent, FunctionBindgen};
17+
use crate::{FunctionBindgen, ffi, indent};
1818

1919
use super::InterfaceGenerator;
2020

@@ -618,13 +618,8 @@ fn wasmLift{camel_name}{index}(stream_handle : Int) -> {lifted} {{
618618

619619
let lift_builtins = if let Some(inner_ty) = inner_type {
620620
let resolve = self.resolve.clone();
621-
let mut lift_bindgen = FunctionBindgen::new(
622-
self,
623-
Box::new([]),
624-
Direction::Import,
625-
true,
626-
false,
627-
);
621+
let mut lift_bindgen =
622+
FunctionBindgen::new(self, Box::new([]), Direction::Import, true, false);
628623
lift_bindgen.use_ffi(ffi::MALLOC);
629624
lift_bindgen.use_ffi(ffi::FREE);
630625

@@ -737,13 +732,8 @@ fn wasmLower{camel_name}{index}(stream : {lifted}) -> Int {{
737732
let lower_builtins = if let Some(inner_ty) = inner_type {
738733
let resolve = self.resolve.clone();
739734
let elem_type = self.world_gen.pkg_resolver.type_name(self.name, &inner_ty);
740-
let mut lower_bindgen = FunctionBindgen::new(
741-
self,
742-
Box::new([]),
743-
Direction::Export,
744-
true,
745-
false,
746-
);
735+
let mut lower_bindgen =
736+
FunctionBindgen::new(self, Box::new([]), Direction::Export, true, false);
747737
lower_bindgen.use_ffi(ffi::MALLOC);
748738
lower_bindgen.use_ffi(ffi::FREE);
749739

crates/moonbit/src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use wit_bindgen_core::{
1111
AsyncFilterSet, Direction, Files, InterfaceGenerator as CoreInterfaceGenerator, Ns, Source,
1212
WorldGenerator,
1313
abi::{self, AbiVariant, Bindgen, Bitcast, Instruction, LiftLower, WasmType},
14-
dealias,
15-
uwrite, uwriteln,
14+
dealias, uwrite, uwriteln,
1615
wit_parser::{
1716
Alignment, ArchitectureSize, Docs, Enum, Flags, FlagsRepr, Function, Handle, Int,
1817
InterfaceId, LiftLowerAbi, Mangling, ManglingAndAbi, Param, Record, Resolve,
@@ -858,6 +857,9 @@ impl InterfaceGenerator<'_> {
858857
#doc(hidden)
859858
pub fn {func_name}({params}) -> {result_type} {{
860859
{async_pkg}with_waitableset(async fn() {{
860+
// Intentionally run export body in a task-group child task.
861+
// MoonBit's structured concurrency model uses the task group
862+
// as an umbrella for async work started by the export.
861863
{async_pkg}with_task_group(async fn(task_group) {{
862864
{cleanup_list}
863865
{src}
@@ -1076,7 +1078,12 @@ impl InterfaceGenerator<'_> {
10761078
})
10771079
.collect::<Vec<_>>();
10781080

1079-
// For async exports, add taskgroup parameter (always Unit type)
1081+
// For async exports, add a task-group parameter.
1082+
//
1083+
// This is intentionally `TaskGroup[Unit]` even when the function result
1084+
// type is not `Unit`: this task group models the umbrella lifetime for
1085+
// export-side structured concurrency and cancellation, rather than the
1086+
// direct return payload type of the exported function.
10801087
if async_ && matches!(direction, Direction::Export) {
10811088
params.push("task_group : @async.TaskGroup[Unit]".to_string());
10821089
}
@@ -2945,11 +2952,11 @@ impl Bindgen for FunctionBindgen<'_, '_> {
29452952
match ty {
29462953
Type::Id(id) => match &self.interface_gen.resolve.types[*id].kind {
29472954
TypeDefKind::Handle(Handle::Own(_)) => {
2948-
let constructor =
2949-
self.interface_gen.world_gen.pkg_resolver.type_constructor(
2950-
self.interface_gen.name,
2951-
ty,
2952-
);
2955+
let constructor = self
2956+
.interface_gen
2957+
.world_gen
2958+
.pkg_resolver
2959+
.type_constructor(self.interface_gen.name, ty);
29532960
uwriteln!(self.src, "let _ = {constructor}::drop({op});");
29542961
}
29552962
TypeDefKind::Future(_) | TypeDefKind::Stream(_) => {

crates/test/src/moonbit.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{LanguageMethods, Runner};
2-
use anyhow::{bail, Context};
2+
use anyhow::{Context, bail};
33
use serde::Deserialize;
44
use std::process::Command;
55

@@ -103,10 +103,7 @@ impl LanguageMethods for MoonBit {
103103
.find(|path| path.exists())
104104
.cloned()
105105
.with_context(|| {
106-
format!(
107-
"failed to locate MoonBit output wasm, looked in: {:?}",
108-
artifact_candidates
109-
)
106+
format!("failed to locate MoonBit output wasm, looked in: {artifact_candidates:?}",)
110107
})?;
111108
// Embed WIT files
112109
let manifest_dir = compile.component.path.parent().unwrap();

0 commit comments

Comments
 (0)