summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStiopa Koltsov <nga@meta.com>2024-09-28 06:15:53 -0700
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>2024-09-28 06:15:53 -0700
commit0d49f7a45fcf76abd5eaad18fe34491b4918b603 (patch)
treefe71a0a334ee99d1ff8e398b2c2b86b2a014a27b
parent04b8e222aabfdaf9153faad6071267bd65f82c24 (diff)
Simplify codegen
Summary: Copy a struct instead of copying fields. Reviewed By: JakobDegen Differential Revision: D63583462 fbshipit-source-id: 7cbaf27802bed17683ebaf207696b13e4c571ff4
-rw-r--r--starlark_derive/src/module/render/fun.rs39
-rw-r--r--starlark_derive/src/module/typ.rs4
2 files changed, 12 insertions, 31 deletions
diff --git a/starlark_derive/src/module/render/fun.rs b/starlark_derive/src/module/render/fun.rs
index b3c34033..ace14906 100644
--- a/starlark_derive/src/module/render/fun.rs
+++ b/starlark_derive/src/module/render/fun.rs
@@ -19,7 +19,6 @@ use proc_macro2::Ident;
use proc_macro2::TokenStream;
use quote::format_ident;
use quote::quote;
-use syn::Attribute;
use syn::Expr;
use syn::ExprLit;
use syn::Lit;
@@ -336,34 +335,24 @@ struct Bindings {
fn render_binding(x: &StarFun) -> Bindings {
match x.source {
StarFunSource::Arguments => {
- let StarArg {
- attrs, name, ty, ..
- } = &x.args[0];
+ let arg = &x.args[0];
Bindings {
prepare: TokenStream::new(),
bindings: vec![BindingArg {
- name: name.to_owned(),
- ty: ty.to_owned(),
- attrs: attrs.clone(),
- mutability: None,
+ arg: arg.clone(),
expr: syn::parse_quote! { parameters },
}],
}
}
StarFunSource::ThisArguments => {
- let StarArg {
- attrs, name, ty, ..
- } = &x.args[1];
+ let arg = &x.args[1];
let this = render_binding_arg(&x.args[0]);
Bindings {
prepare: TokenStream::new(),
bindings: vec![
this,
BindingArg {
- name: name.to_owned(),
- ty: ty.to_owned(),
- attrs: attrs.clone(),
- mutability: None,
+ arg: arg.clone(),
expr: syn::parse_quote! { parameters },
},
],
@@ -407,24 +396,19 @@ fn render_binding(x: &StarFun) -> Bindings {
struct BindingArg {
expr: syn::Expr,
-
- attrs: Vec<Attribute>,
- mutability: Option<syn::Token![mut]>,
- name: Ident,
- ty: syn::Type,
+ arg: StarArg,
}
impl BindingArg {
fn render_param_type(&self) -> syn::Type {
- let BindingArg { ty, .. } = self;
- ty.clone()
+ self.arg.ty.clone()
}
fn render_param(&self) -> syn::FnArg {
- let mutability = &self.mutability;
- let name = &self.name;
+ let mutability = &self.arg.mutable;
+ let name = &self.arg.name;
let ty = self.render_param_type();
- let attrs = &self.attrs;
+ let attrs = &self.arg.attrs;
syn::parse_quote! {
#( #attrs )*
#mutability #name: #ty
@@ -483,10 +467,7 @@ fn render_binding_arg(arg: &StarArg) -> BindingArg {
BindingArg {
expr: next,
- attrs: arg.attrs.clone(),
- mutability: arg.mutable,
- name: arg.name.to_owned(),
- ty: arg.ty.clone(),
+ arg: arg.clone(),
}
}
diff --git a/starlark_derive/src/module/typ.rs b/starlark_derive/src/module/typ.rs
index 1abd79b6..36f91d5a 100644
--- a/starlark_derive/src/module/typ.rs
+++ b/starlark_derive/src/module/typ.rs
@@ -142,7 +142,7 @@ pub(crate) enum StarArgPassStyle {
Arguments,
}
-#[derive(Debug)]
+#[derive(Debug, Clone)]
pub(crate) struct StarArg {
pub span: Span,
pub attrs: Vec<Attribute>,
@@ -154,7 +154,7 @@ pub(crate) struct StarArg {
pub source: StarArgSource,
}
-#[derive(Debug, PartialEq)]
+#[derive(Debug, PartialEq, Clone)]
pub(crate) enum StarArgSource {
Unknown,
This,