Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
310faea
feat(option): add logical Option/Unit foundation with typed host and …
fffonion Nov 10, 2026
7cc171b
test(sqlite): refine optional transaction query before member access
fffonion Nov 10, 2026
9d73237
feat(option): carry typed callable payloads through guest union schemas
fffonion Nov 10, 2026
1c4bf40
fix(host-schema): publish Unit for omitted callable returns
fffonion Nov 10, 2026
a974719
feat(option): add combinators, lexical try, and logical projection
fffonion Nov 11, 2026
1e51fbf
docs(option): document Option methods, conversions, and fallible proj…
fffonion Nov 11, 2026
0172f1c
fix(option): materialize omitted Option fields as explicit None
fffonion Nov 11, 2026
ab555b7
fix(option): materialize omitted Option fields at typed construction …
fffonion Nov 11, 2026
d21b6dc
fix(wasm): match logical projections with Option-qualified patterns
fffonion Nov 11, 2026
af36229
fix(option): retain method-lowered contextual record schemas
fffonion Nov 11, 2026
0e9bd53
fix(option): reject non-construction partial named records
fffonion Nov 11, 2026
288a9c7
fix(option): apply contextual callback results before strict merge
fffonion Nov 11, 2026
41f2e75
fix(option): carry expression-block local state through omission admi…
fffonion Nov 11, 2026
c0ccf5a
test(http): assert Unit mutator and absent-empty header contracts
fffonion Nov 11, 2026
55a8f16
test(io): pin typed absent-empty IO public contract
fffonion Nov 11, 2026
6420757
feat(sqlite): expose logical Option result absence and Unit close
fffonion Nov 11, 2026
cf74488
fix(io): keep the round-trip call count available to both IO backends
fffonion Nov 11, 2026
0aa5b0a
test(timer): pin non-nullable timer public contract
fffonion Nov 11, 2026
7dfb92c
feat(regex): expose logical Option find and captures contracts
fffonion Nov 11, 2026
7e2a93a
test(regex): pin the stdlib spec to logical Option results
fffonion Nov 11, 2026
72cc9db
feat(sqlite): complete public field logical Option contracts
fffonion Nov 11, 2026
aa78667
test(sqlite): assert mismatched logical payload rejection
fffonion Nov 11, 2026
73f35ae
test(sqlite): avoid a needless reference in the mismatch gate
fffonion Nov 11, 2026
a789af6
docs(sqlite): clarify logical Option field construction
fffonion Nov 11, 2026
c3708f4
test(standard): refresh catalog golden pins after logical Option cont…
fffonion Nov 11, 2026
f50302a
fix(io): declare the typed resource key on concrete IO handles
fffonion Nov 11, 2026
de89a44
test(vm): cover IO HTTP and SQLite in one exact catalog VM
fffonion Nov 11, 2026
a026db4
fix(rss): remove map keys explicitly and keep unit values
fffonion Nov 12, 2026
742a958
fix(rss): bound named json recursion and require object fields
fffonion Nov 12, 2026
91cc4dc
fix(rss): render logical values from checked presentation sites
fffonion Nov 12, 2026
c9c3d07
test(lsp): migrate sqlite fixture schema tags to Option
fffonion Nov 12, 2026
db16251
fix(compiler): keep unit map entries and reject record removal
fffonion Nov 12, 2026
748b20a
fix(json): resolve named schemas and admit unit fields
fffonion Nov 12, 2026
515026e
test(rss): cover map and json behavior across reload and no-std
fffonion Nov 12, 2026
e592678
style(stdlib): normalize parse.rss line endings
fffonion Nov 12, 2026
1901ad3
test(rss): keep a unit entry inserted through a generic map
fffonion Nov 12, 2026
bc0f9c3
fix(map): admit checked unit stores and keep legacy deletion
fffonion Nov 12, 2026
4d6b27f
fix(option): materialize omitted host fields before admission
fffonion Nov 12, 2026
bb97f7e
fix(map): keep non-null set fast path and cover the matrix
fffonion Nov 12, 2026
f58a28e
test(host): compare sqlite option compile and analyze
fffonion Nov 12, 2026
57a69ab
fix(compiler): encode type schemas without the vm runtime
fffonion Nov 12, 2026
83340be
style(fmt): normalize G-owned formatting
fffonion Nov 12, 2026
adedde7
fix(vm): honor public json::encode overrides from typed calls
fffonion Nov 12, 2026
44222a0
test(compiler): move Group A nullable fixtures onto legal seams
fffonion Nov 12, 2026
dea56b6
test(host): move Group B consumers onto GuestOption and unit
fffonion Nov 12, 2026
8c4256c
fix(host): restore typed json encode descriptor on yield retry
fffonion Nov 12, 2026
975a51d
fix(rss): migrate C20 consumers onto Option and Unit
fffonion Nov 12, 2026
5fbda69
fix(compiler): keep named record materialization joins
fffonion Nov 12, 2026
be8f5d7
test(typing): preserve local and return mismatch oracles
fffonion Nov 12, 2026
c5a4678
fix(parser): keep matching catalog print identity
fffonion Nov 12, 2026
0d87caf
docs(corpus): migrate shipped Option examples and coverage
fffonion Nov 12, 2026
ed7076a
fix(parser): keep same-frame locals direct in match arms
fffonion Nov 12, 2026
45d1ea4
fix(option): seed captured declaration schemas in named functions
fffonion Nov 12, 2026
ae0e77c
fix(parser): prefer imported catalog print identity over sugar
fffonion Nov 12, 2026
e768274
fix(compiler): close the RustScript host-output and typed JSON frontier
fffonion Nov 12, 2026
0d1e2b2
fix(runtime): restore canonical tag-only Some(Unit)
fffonion Nov 12, 2026
d930227
docs(option): describe the current no-null and typed JSON boundary
fffonion Nov 12, 2026
178fc45
test(compiler): cover the .rss import nullable boundary
fffonion Nov 12, 2026
071d402
test(wasm): keep the json decode lint fixture on the typed route
fffonion Nov 12, 2026
dea1959
fix(option): seed nested owner-local capture schemas in omitted-field…
fffonion Nov 13, 2026
6726cb5
fix(compiler): keep compiler-internal JSON helpers out of source lookup
fffonion Nov 13, 2026
74d64f1
style(test): format the JSON boundary regressions
fffonion Nov 13, 2026
2ac6f21
fix(runtime): replace deprecated atomic fetch_update with try_update
fffonion Nov 13, 2026
bd027a4
fix(vmbc): remove unused type-schema encode forward
fffonion Nov 13, 2026
8c5cd4d
refactor(schema): use key-based field ordering
fffonion Nov 13, 2026
d975ebf
refactor(compiler): simplify strict style and control-flow
fffonion Nov 13, 2026
ec32aca
refactor(runtime): simplify strict style and control-flow
fffonion Nov 13, 2026
5014f54
refactor(lsp): use ? for the entry document fallback
fffonion Nov 13, 2026
df67651
refactor(typing): pass DiagnosticSite through builtin argument valida…
fffonion Nov 13, 2026
93c492f
test(qualification): adapt downstream targets to strict qualification
fffonion Nov 13, 2026
acd2ce8
refactor(runtime): use the std no-op waker for blocking polls
fffonion Nov 13, 2026
24f0f36
docs(rustdoc): resolve strict intra-doc links
fffonion Nov 13, 2026
6380649
test(sqlite): compile close-lifecycle fixtures as unit
fffonion Nov 13, 2026
8fe518d
test(host): pin sqlite close catalog return as Unit
fffonion Nov 13, 2026
3f78240
test(wasm): type json and regex consumer fixtures
fffonion Nov 13, 2026
e034f69
fix(sqlite): surface deadline when a bounded lock wait returns busy
fffonion Nov 13, 2026
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
31 changes: 29 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl HostBindingKind {
pub(crate) const SQLITE_RESERVED_TOP_START: u16 = 0xFFFC;
pub(crate) const SQLITE_RESERVED_TOP_END: u16 = u16::MAX;
pub(crate) const ORDINARY_BLOCK_START: u16 = 0xFFA2;
pub(crate) const SPECIAL_CALL_BLOCK_START: u16 = 0xFF90;
pub(crate) const SPECIAL_CALL_BLOCK_START: u16 = 0xFF8C;
pub(crate) const SPECIAL_CALL_BLOCK_END: u16 = 0xFFA1;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
Expand Down Expand Up @@ -1100,6 +1100,12 @@ fn render_builtin_catalog(
.unwrap();
writeln!(&mut out, " match name {{").unwrap();
for entry in catalog {
// Internal entries are compiler-owned lowering helpers. Their source
// spellings must not resolve from guest source; trusted compiler and
// runtime consumers address them through the generated call index.
if entry.class == CatalogClass::Internal {
continue;
}
writeln!(
&mut out,
" {:?} => Some(Self::{}),",
Expand Down Expand Up @@ -1724,6 +1730,7 @@ pub(crate) fn callable_param_expr(label: &str) -> String {
match label {
"any" => "CallableParamType::Any".to_string(),
"null" => "CallableParamType::Null".to_string(),
"()" => "CallableParamType::Unit".to_string(),
"int" => "CallableParamType::Int".to_string(),
"float" => "CallableParamType::Float".to_string(),
"bool" => "CallableParamType::Bool".to_string(),
Expand Down Expand Up @@ -1793,6 +1800,10 @@ fn appended_builtin_order() -> &'static [&'static str] {
"__map_iter_close",
"__bind_callable",
"__detach_local",
"__json_decode_typed",
"__json_encode_typed",
"__logical_render",
"__map_edit",
]
}

Expand Down Expand Up @@ -2162,6 +2173,7 @@ fn callable_docs(name: &str, attrs: &[Attribute]) -> String {
fn emit_guest_result_schema_fixture(manifest: &Path, out: &Path) {
for (input, output) in [
("result_sdk_signature.rs", "result_sdk_build_schemas.rs"),
("option_sdk_signature.rs", "option_sdk_build_schemas.rs"),
(
"result_sdk_resource_signature.rs",
"result_sdk_resource_build_schemas.rs",
Expand Down Expand Up @@ -2216,6 +2228,11 @@ fn guest_schema_expr(shape: &pd_host_schema::GuestTypeShape<'_>) -> String {
guest_schema_expr(ok),
guest_schema_expr(err)
),
S::Option(inner) => format!(
"vm::HostTypeSchema::Option(Box::new({}))",
guest_schema_expr(inner)
),
S::Unit => "vm::HostTypeSchema::Unit".to_string(),
S::Optional(inner) => format!(
"vm::HostTypeSchema::Optional(Box::new({}))",
guest_schema_expr(inner)
Expand All @@ -2228,6 +2245,15 @@ fn guest_schema_expr(shape: &pd_host_schema::GuestTypeShape<'_>) -> String {
"vm::HostTypeSchema::Resource({})",
guest_resource_key_expr(spec)
),
S::Callable { params, result } => format!(
"vm::HostTypeSchema::Callable {{ params: vec![{}], result: Box::new({}) }}",
params
.iter()
.map(guest_schema_expr)
.collect::<Vec<_>>()
.join(", "),
guest_schema_expr(result)
),
S::Named(ty) => format!(
"<{} as vm::HostNamedStruct>::host_type_schema()",
rust_schema_type(ty)
Expand Down Expand Up @@ -2329,7 +2355,7 @@ pub(crate) fn render_guest_descriptor_model(function: &ItemFn) -> String {

fn return_type_label(output: &ReturnType) -> String {
match output {
ReturnType::Default => "null".to_string(),
ReturnType::Default => "()".to_string(),
ReturnType::Type(_, ty) => pd_host_schema::type_label(ty)
.unwrap_or_else(|message| panic!("unsupported callable return type: {message}")),
}
Expand All @@ -2342,6 +2368,7 @@ fn static_return_type_label(output: &ReturnType) -> String {
fn value_type_from_label(label: &str) -> &'static str {
match label {
"null" => "Null",
"()" => "Null",
"int" => "Int",
"float" => "Float",
"bool" => "Bool",
Expand Down
64 changes: 60 additions & 4 deletions crates/pd-host-schema/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ pub fn type_label(ty: &Type) -> Result<String, String> {
}
_ => Err("unsupported callable type".to_string()),
},
Type::Tuple(tuple) if tuple.elems.is_empty() => Ok("null".to_string()),
Type::Tuple(tuple) if tuple.elems.is_empty() => Ok("()".to_string()),
Type::Path(path) => {
let Some(segment) = path.path.segments.last() else {
return Err("unsupported callable type".to_string());
Expand All @@ -567,7 +567,7 @@ pub fn type_label(ty: &Type) -> Result<String, String> {
"ResourceOwned" => Err(
"ResourceOwned is input-only; it cannot be used as a return schema".to_string(),
),
"GuestResult" => Ok(guest_type_shape(ty)?.label()),
"GuestResult" | "GuestOption" => Ok(guest_type_shape(ty)?.label()),
"VmCallable" => callable_type_label(segment),
"Unknown" | "UnknownValue" => Ok("unknown".to_string()),
"CallOutcome" => Ok("unknown".to_string()),
Expand Down Expand Up @@ -614,9 +614,19 @@ fn parameter_type_label_inner(ty: &Type) -> Result<(String, bool), String> {
#[derive(Clone, Debug)]
pub enum GuestTypeShape<'a> {
Result(Box<Self>, Box<Self>),
Option(Box<Self>),
/// Logical guest `()`, physically carried by the internal Null value.
Unit,
Optional(Box<Self>),
Array(Box<Self>),
Resource(Box<ResourceSpec>),
/// A typed callable value: the signature is part of the public schema, the
/// value itself owns no resources. Dispatch identity stays with the VM
/// callable and its Program.
Callable {
params: Vec<Self>,
result: Box<Self>,
},
Scalar(&'static str),
Named(&'a Type),
}
Expand All @@ -625,9 +635,19 @@ impl GuestTypeShape<'_> {
pub fn label(&self) -> String {
match self {
Self::Result(ok, err) => format!("Result<{}, {}>", ok.label(), err.label()),
Self::Option(inner) => format!("Option<{}>", inner.label()),
Self::Unit => "()".into(),
Self::Optional(inner) => format!("{} | null", inner.label()),
Self::Array(inner) => format!("array<{}>", inner.label()),
Self::Resource(_) => "resource".into(),
Self::Callable { params, result } => {
let params = params
.iter()
.map(Self::label)
.collect::<Vec<_>>()
.join(", ");
format!("fn({params}) -> {}", result.label())
}
Self::Scalar(label) => (*label).into(),
Self::Named(ty) => path_last_ident(ty).expect("named path"),
}
Expand All @@ -641,8 +661,12 @@ impl GuestTypeShape<'_> {
out.extend(err.resources());
out
}
Self::Optional(inner) | Self::Array(inner) => inner.resources(),
Self::Option(inner) | Self::Optional(inner) | Self::Array(inner) => inner.resources(),
Self::Resource(spec) => vec![spec],
// A callable value transfers dispatch identity only; signature
// resource types describe invocation arguments, not values this
// payload owns.
Self::Callable { .. } => Vec::new(),
_ => Vec::new(),
}
}
Expand All @@ -668,6 +692,9 @@ pub fn guest_type_shape(ty: &Type) -> Result<GuestTypeShape<'_>, String> {
return Err("GuestResult schema exceeds nesting limit".into());
}
let ty = unwrap_surface(ty);
if matches!(ty, Type::Tuple(tuple) if tuple.elems.is_empty()) {
return Ok(GuestTypeShape::Unit);
}
if let Some((ok, err)) = guest_result_arguments(ty)? {
return Ok(GuestTypeShape::Result(
Box::new(walk(ok, depth + 1)?),
Expand All @@ -680,6 +707,34 @@ pub fn guest_type_shape(ty: &Type) -> Result<GuestTypeShape<'_>, String> {
if let Type::Path(path) = ty {
let segment = path.path.segments.last().ok_or("empty type path")?;
let ident = segment.ident.to_string();
if ident == "GuestOption" {
let argument = one_type_argument(segment, &ident)?;
let inner = walk(argument, depth + 1)?;
return Ok(GuestTypeShape::Option(Box::new(inner)));
}
if ident == "VmCallable" {
let PathArguments::AngleBracketed(args) = &segment.arguments else {
return Err("VmCallable requires a function signature".into());
};
let Some(GenericArgument::Type(Type::BareFn(function))) = args.args.first() else {
return Err("VmCallable requires fn(...) -> ...".into());
};
if args.args.len() != 1 {
return Err("VmCallable requires one function signature".into());
}
let mut params = Vec::with_capacity(function.inputs.len());
for input in &function.inputs {
params.push(walk(&input.ty, depth + 1)?);
}
let result = match &function.output {
syn::ReturnType::Default => GuestTypeShape::Unit,
syn::ReturnType::Type(_, ty) => walk(ty, depth + 1)?,
};
return Ok(GuestTypeShape::Callable {
params,
result: Box::new(result),
});
}
if ident == "Option" || ident == "Vec" {
let argument = one_type_argument(segment, &ident)?;
if ident == "Vec" && path_last_ident(argument).as_deref() == Some("u8") {
Expand Down Expand Up @@ -727,6 +782,7 @@ pub fn guest_result_shape(ty: &Type) -> Result<Option<GuestTypeShape<'_>>, Strin
match unwrap_surface(ty) {
Type::Path(path) => path.path.segments.last().is_some_and(|segment| {
segment.ident == "GuestResult"
|| segment.ident == "GuestOption"
|| matches!(segment.ident.to_string().as_str(), "Option" | "Vec")
&& one_type_argument(segment, &segment.ident.to_string())
.is_ok_and(contains)
Expand Down Expand Up @@ -794,7 +850,7 @@ fn callable_type_label(segment: &syn::PathSegment) -> Result<String, String> {
.map(|input| type_label(&input.ty))
.collect::<Result<Vec<_>, _>>()?;
let result = match &function.output {
syn::ReturnType::Default => "null".to_string(),
syn::ReturnType::Default => "()".to_string(),
syn::ReturnType::Type(_, ty) => type_label(ty)?,
};
Ok(format!("fn({}) -> {result}", params.join(", ")))
Expand Down
169 changes: 169 additions & 0 deletions crates/pd-host-schema/tests/guest_option.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
use pd_host_schema::{
GuestTypeShape, ResourceMode, guest_result_shape, guest_type_shape, type_label,
};
use syn::parse_quote;

#[derive(Debug)]
struct FakeResource;

fn shape(ty: &syn::Type) -> GuestTypeShape<'_> {
guest_type_shape(ty).expect("typed guest Option schema")
}

#[test]
fn guest_option_labels_are_distinct_from_legacy_nullable_option() {
let value: syn::Type = parse_quote!(GuestOption<Vec<i64>>);
let shape = shape(&value);
assert!(matches!(shape, GuestTypeShape::Option(_)));
assert_eq!(shape.label(), "Option<array<int>>");
assert_eq!(type_label(&value).unwrap(), "Option<array<int>>");

let nullable: syn::Type = parse_quote!(Option<i64>);
assert_eq!(type_label(&nullable).unwrap(), "int | null");
let (label, optional) = pd_host_schema::parameter_type_label(&nullable).unwrap();
assert_eq!(label, "int | null");
assert!(optional);
let (label, optional) = pd_host_schema::parameter_type_label(&value).unwrap();
assert_eq!(label, "Option<array<int>>");
assert!(!optional, "a guest Option is not an omitted argument");
}

#[test]
fn guest_option_nests_unit_result_and_nullable_payloads() {
let nested: syn::Type = parse_quote!(GuestOption<GuestOption<Option<Vec<bool>>>>);
let nested_shape = shape(&nested);
assert_eq!(nested_shape.label(), "Option<Option<array<bool> | null>>");
let unit: syn::Type = parse_quote!(GuestOption<()>);
let unit_shape = shape(&unit);
assert!(matches!(unit_shape, GuestTypeShape::Option(_)));
assert_eq!(unit_shape.label(), "Option<()>");
let unit_only: syn::Type = parse_quote!(());
assert!(matches!(shape(&unit_only), GuestTypeShape::Unit));
assert_eq!(shape(&unit_only).label(), "()");
assert_eq!(type_label(&unit_only).unwrap(), "()");

let result: syn::Type = parse_quote!(GuestOption<GuestResult<i64, String>>);
let result_shape = shape(&result);
assert_eq!(result_shape.label(), "Option<Result<int, string>>");
let nested_result: syn::Type = parse_quote!(GuestResult<GuestOption<i64>, String>);
assert_eq!(shape(&nested_result).label(), "Result<Option<int>, string>");
}

#[test]
fn guest_option_resources_keep_their_access_mode() {
let _ = FakeResource;
let owned: syn::Type = parse_quote!(GuestOption<ResourceOwned<FakeResource>>);
let owned_shape = shape(&owned);
let resources = owned_shape.resources();
assert_eq!(resources.len(), 1);
assert_eq!(resources[0].mode, ResourceMode::TakeOwned);
assert_eq!(
owned_shape.resource_mode().unwrap(),
Some(ResourceMode::TakeOwned)
);
assert_eq!(owned_shape.label(), "Option<resource>");

let borrowed: syn::Type = parse_quote!(GuestOption<ResourceRef<'_, FakeResource>>);
assert_eq!(
shape(&borrowed).resource_mode().unwrap(),
Some(ResourceMode::Borrow)
);
let mixed: syn::Type =
parse_quote!(GuestResult<ResourceRef<'_, FakeResource>, ResourceOwned<FakeResource>>);
assert!(
shape(&mixed).resource_mode().is_err(),
"mixed resource modes must remain refused"
);
let array: syn::Type = parse_quote!(GuestOption<Vec<ResourceOwned<FakeResource>>>);
let error = guest_type_shape(&array).unwrap_err();
assert!(error.contains("resource arrays"), "{error}");
}

#[test]
fn guest_option_callable_payload_uses_the_typed_callable_schema() {
let callable: syn::Type = parse_quote!(GuestOption<VmCallable<fn(i64, String) -> bool>>);
let option_shape = shape(&callable);
assert_eq!(option_shape.label(), "Option<fn(int, string) -> bool>");
let GuestTypeShape::Option(inner) = &option_shape else {
panic!("callable Option must keep the Option wrapper");
};
let GuestTypeShape::Callable { params, result } = inner.as_ref() else {
panic!("callable payload must use the Callable shape");
};
assert_eq!(params.len(), 2);
assert_eq!(params[1].label(), "string");
assert_eq!(result.label(), "bool");
assert!(
option_shape.resources().is_empty(),
"a callable value owns no resource"
);
assert_eq!(option_shape.resource_mode().unwrap(), None);

let unit: syn::Type = parse_quote!(GuestOption<VmCallable<fn() -> ()>>);
assert_eq!(shape(&unit).label(), "Option<fn() -> ()>");
// `fn()` and `fn() -> ()` are the same Rust function type: an omitted
// return publishes logical Unit, not the low-level Null spelling.
let defaulted: syn::Type = parse_quote!(GuestOption<VmCallable<fn()>>);
let defaulted_shape = shape(&defaulted);
assert_eq!(defaulted_shape.label(), "Option<fn() -> ()>");
let GuestTypeShape::Option(inner) = &defaulted_shape else {
panic!("bare callable Option must keep the Option wrapper");
};
let GuestTypeShape::Callable { params, result } = inner.as_ref() else {
panic!("bare callable payload must use the Callable shape");
};
assert!(params.is_empty());
assert!(matches!(result.as_ref(), GuestTypeShape::Unit));

let defaulted_typed: syn::Type = parse_quote!(GuestOption<VmCallable<fn(i64)>>);
let explicit_typed: syn::Type = parse_quote!(GuestOption<VmCallable<fn(i64) -> ()>>);
assert_eq!(shape(&defaulted_typed).label(), "Option<fn(int) -> ()>");
assert_eq!(
shape(&defaulted_typed).label(),
shape(&explicit_typed).label()
);

let nested: syn::Type = parse_quote!(GuestResult<GuestOption<VmCallable<fn() -> ()>>, String>);
assert_eq!(shape(&nested).label(), "Result<Option<fn() -> ()>, string>");
let nested_defaulted: syn::Type =
parse_quote!(GuestResult<GuestOption<VmCallable<fn()>>, String>);
assert_eq!(
shape(&nested_defaulted).label(),
"Result<Option<fn() -> ()>, string>"
);

let malformed: syn::Type = parse_quote!(GuestOption<VmCallable<i64>>);
let error = guest_type_shape(&malformed).unwrap_err();
assert!(error.contains("fn(...) ->"), "{error}");
}

#[test]
fn guest_option_shape_detection_and_arity_are_strict() {
let optional: syn::Type = parse_quote!(GuestOption<i64>);
assert!(
guest_result_shape(&optional)
.expect("valid guest Option")
.is_some()
);
let plain: syn::Type = parse_quote!(i64);
assert!(guest_result_shape(&plain).unwrap().is_none());
let missing: syn::Type = parse_quote!(GuestOption);
let error = guest_result_shape(&missing).unwrap_err();
assert!(error.contains("requires one"), "{error}");
let two: syn::Type = parse_quote!(GuestOption<i64, bool>);
let error = guest_type_shape(&two).unwrap_err();
assert!(error.contains("one generic argument"), "{error}");
let transport: syn::Type = parse_quote!(GuestOption<VmResult<i64>>);
let error = guest_type_shape(&transport).unwrap_err();
assert!(error.contains("transport results"), "{error}");
}

#[test]
fn callable_unit_labels_use_the_unit_spelling() {
let callable: syn::Type = parse_quote!(VmCallable<fn(i64) -> ()>);
assert_eq!(type_label(&callable).unwrap(), "fn(int) -> ()");
let bare: syn::Type = parse_quote!(VmCallable<fn()>);
assert_eq!(type_label(&bare).unwrap(), "fn() -> ()");
let optional_callable: syn::Type = parse_quote!(Option<VmCallable<fn() -> ()>>);
assert_eq!(type_label(&optional_callable).unwrap(), "fn() -> () | null");
}
Loading
Loading