Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
lann committed Aug 25, 2023
1 parent eb7dc0c commit 8538ac9
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 695 deletions.
52 changes: 31 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,11 @@ debug-assertions = false
# Omit integer overflow checks, which include failure messages which require
# string initializers.
overflow-checks = false

[patch.crates-io]
wasm-metadata = { git = "https://github.com/lann/wasm-tools.git", branch = "remove-union" }
wasmparser = { git = "https://github.com/lann/wasm-tools.git", branch = "remove-union" }
wasmprinter = { git = "https://github.com/lann/wasm-tools.git", branch = "remove-union" }
wit-component = { git = "https://github.com/lann/wasm-tools.git", branch = "remove-union" }
wit-parser = { git = "https://github.com/lann/wasm-tools.git", branch = "remove-union" }
wit-bindgen = { git = "https://github.com/lann/wit-bindgen.git", branch = "remove-union" }
24 changes: 0 additions & 24 deletions crates/component-macro/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ mod kw {
pub enum VariantStyle {
Variant,
Enum,
Union,
}

impl fmt::Display for VariantStyle {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(match self {
Self::Variant => "variant",
Self::Enum => "enum",
Self::Union => "union",
})
}
}
Expand Down Expand Up @@ -70,9 +68,6 @@ impl Parse for Style {
} else if lookahead.peek(Token![enum]) {
input.parse::<Token![enum]>()?;
Ok(Style::Variant(VariantStyle::Enum))
} else if lookahead.peek(Token![union]) {
input.parse::<Token![union]>()?;
Ok(Style::Variant(VariantStyle::Union))
} else if input.peek(kw::flags) {
Err(input.error(
"`flags` not allowed here; \
Expand Down Expand Up @@ -238,7 +233,6 @@ fn expand_variant(
match style {
VariantStyle::Variant => "at most one unnamed field each",
VariantStyle::Enum => "no fields",
VariantStyle::Union => "exactly one unnamed field each",
}
),
))
Expand Down Expand Up @@ -443,7 +437,6 @@ impl Expander for LiftExpander {
let interface_type_variant = match style {
VariantStyle::Variant => quote!(Variant),
VariantStyle::Enum => quote!(Enum),
VariantStyle::Union => quote!(Union),
};

for (index, VariantCase { ident, ty, .. }) in cases.iter().enumerate() {
Expand All @@ -456,7 +449,6 @@ impl Expander for LiftExpander {
VariantStyle::Variant => {
quote!(ty.cases[#index].ty.unwrap_or_else(#internal::bad_type_info))
}
VariantStyle::Union => quote!(ty.types[#index]),
VariantStyle::Enum => unreachable!(),
};
lifts.extend(
Expand Down Expand Up @@ -618,7 +610,6 @@ impl Expander for LowerExpander {
let interface_type_variant = match style {
VariantStyle::Variant => quote!(Variant),
VariantStyle::Enum => quote!(Enum),
VariantStyle::Union => quote!(Union),
};

for (index, VariantCase { ident, ty, .. }) in cases.iter().enumerate() {
Expand All @@ -637,7 +628,6 @@ impl Expander for LowerExpander {
VariantStyle::Variant => {
quote!(ty.cases[#index].ty.unwrap_or_else(#internal::bad_type_info))
}
VariantStyle::Union => quote!(ty.types[#index]),
VariantStyle::Enum => unreachable!(),
};
pattern = quote!(Self::#ident(value));
Expand Down Expand Up @@ -768,13 +758,6 @@ impl Expander for ComponentTypeExpander {
for (index, VariantCase { attrs, ident, ty }) in cases.iter().enumerate() {
let rename = find_rename(attrs)?;

if let (Some(_), VariantStyle::Union) = (&rename, style) {
return Err(Error::new(
ident.span(),
"renaming `union` cases is not permitted; only the type is used",
));
}

let name = rename.unwrap_or_else(|| syn::LitStr::new(&ident.to_string(), ident.span()));

if let Some(ty) = ty {
Expand All @@ -784,9 +767,6 @@ impl Expander for ComponentTypeExpander {
VariantStyle::Variant => {
quote!((#name, Some(<#ty as wasmtime::component::ComponentType>::typecheck)),)
}
VariantStyle::Union => {
quote!(<#ty as wasmtime::component::ComponentType>::typecheck,)
}
VariantStyle::Enum => {
return Err(Error::new(
ident.span(),
Expand All @@ -810,9 +790,6 @@ impl Expander for ComponentTypeExpander {
VariantStyle::Variant => {
quote!((#name, None),)
}
VariantStyle::Union => {
quote!(<() as wasmtime::component::ComponentType>::typecheck,)
}
VariantStyle::Enum => quote!(#name,),
});
lower_payload_case_declarations.extend(quote!(#ident: [wasmtime::ValRaw; 0],));
Expand All @@ -821,7 +798,6 @@ impl Expander for ComponentTypeExpander {

let typecheck = match style {
VariantStyle::Variant => quote!(typecheck_variant),
VariantStyle::Union => quote!(typecheck_union),
VariantStyle::Enum => quote!(typecheck_enum),
};

Expand Down
66 changes: 0 additions & 66 deletions crates/component-macro/tests/codegen/unions.wit

This file was deleted.

11 changes: 0 additions & 11 deletions crates/component-macro/tests/codegen/variants.wit
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,10 @@ interface variants {
e1-arg: func(x: e1)
e1-result: func() -> e1

union u1 {
u32,
float32,
}

u1-arg: func(x: u1)
u1-result: func() -> u1

record empty {}

variant v1 {
a,
b(u1),
c(e1),
d(string),
e(empty),
Expand All @@ -40,7 +31,6 @@ interface variants {
c: option<u32>,
d: option<e1>,
e: option<float32>,
f: option<u1>,
g: option<option<bool>>,
)
option-result: func() -> tuple<
Expand All @@ -49,7 +39,6 @@ interface variants {
option<u32>,
option<e1>,
option<float32>,
option<u1>,
option<option<bool>>,
>

Expand Down
Loading

0 comments on commit 8538ac9

Please sign in to comment.