Skip to content

Commit

Permalink
Trim down feature again
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Nov 1, 2023
1 parent c3aa230 commit 8329943
Show file tree
Hide file tree
Showing 14 changed files with 224 additions and 551 deletions.
3 changes: 0 additions & 3 deletions crates/rune-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ license = "MIT OR Apache-2.0"
keywords = ["language", "scripting", "scripting-language"]
categories = ["parser-implementations"]

[features]
dynamic_fields = []

[dependencies]
rune-core = { version = "=0.13.1", path = "../rune-core", features = ["std"] }
syn = { version = "2.0.16", features = ["full"] }
Expand Down
28 changes: 0 additions & 28 deletions crates/rune-macros/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,6 @@ where
mut_,
ref_,
vm_try,
dynamic_field_search,
dynamic_field_mode,
..
} = &tokens;

Expand Down Expand Up @@ -647,30 +645,6 @@ where
} else {
quote!(#hash::new(#type_hash))
};
#[cfg(feature = "dynamic_fields")]
let meta_fields = if let Some(meta_fields) = attr.meta_fields {
quote! {
#[automatically_derived]
impl #impl_generics #dynamic_field_search for #ident #type_generics #where_clause {
const DYNAMIC_FIELD_MODE: #dynamic_field_mode = #dynamic_field_mode::#meta_fields;
}
}
} else {
quote! {
#[automatically_derived]
impl #impl_generics #dynamic_field_search for #ident #type_generics #where_clause {
const DYNAMIC_FIELD_MODE: #dynamic_field_mode = #dynamic_field_mode::Never;
}
}
};

#[cfg(not(feature = "dynamic_fields"))]
let meta_fields = quote! {
#[automatically_derived]
impl #impl_generics #dynamic_field_search for #ident #type_generics #where_clause {
const DYNAMIC_FIELD_MODE: #dynamic_field_mode = #dynamic_field_mode::Never;
}
};

Some(quote! {
#[automatically_derived]
Expand All @@ -680,8 +654,6 @@ where
}
}

#meta_fields

#[automatically_derived]
impl #impl_generics #unsafe_to_ref for #ident #type_generics #where_clause {
type Guard = #raw_into_ref;
Expand Down
34 changes: 1 addition & 33 deletions crates/rune-macros/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::cell::RefCell;

use proc_macro2::Span;
use proc_macro2::TokenStream;
use quote::{format_ident, quote_spanned};
use quote::quote_spanned;
use quote::{quote, ToTokens};
use syn::parse::ParseStream;
use syn::punctuated::Punctuated;
Expand Down Expand Up @@ -86,10 +86,6 @@ pub(crate) struct TypeAttr {
pub(crate) from_value: Option<syn::Path>,
/// Method to use to convert from value.
pub(crate) from_value_params: Option<syn::punctuated::Punctuated<syn::Type, Token![,]>>,
#[cfg(feature = "dynamic_fields")]
/// `#[rune(meta_fields = never|first|last|only)]` to allow meta fields on a type
/// and when to access.
pub(crate) meta_fields: Option<syn::Ident>,
}

/// Parsed variant attributes.
Expand Down Expand Up @@ -478,30 +474,6 @@ impl Context {
syn::bracketed!(content in meta.input);
attr.from_value_params =
Some(syn::punctuated::Punctuated::parse_terminated(&content)?);
} else if meta.path == META_FIELDS {
#[cfg(not(feature = "dynamic_fields"))]
return Err(syn::Error::new_spanned(
&meta.path,
"Dynamic fields feature flag \"dynamic_fields\" is not enabled",
));
#[cfg(feature = "dynamic_fields")]
{
meta.input.parse::<Token![=]>()?;
let ty: syn::Ident = meta.input.parse()?;
let value = match ty.to_string().as_str() {
"never" => Some(format_ident!("Never")),
"first" => Some(format_ident!("First")),
"last" => Some(format_ident!("Last")),
"only" => Some(format_ident!("Only")),
_ => {
return Err(syn::Error::new_spanned(
&meta.path,
"Expected `never`, `only`, `first` or `last`",
))
}
};
attr.meta_fields = value;
}
} else {
return Err(syn::Error::new_spanned(
&meta.path,
Expand Down Expand Up @@ -632,8 +604,6 @@ impl Context {
from_value: path(m, ["runtime", "FromValue"]),
full_type_of: path(m, ["runtime", "FullTypeOf"]),
hash: path(m, ["Hash"]),
dynamic_field_search: path(m, ["DynamicFieldSearch"]),
dynamic_field_mode: path(m, ["DynamicFieldMode"]),
id: path(m, ["parse", "Id"]),
install_with: path(m, ["__private", "InstallWith"]),
into_iterator: path(&core, ["iter", "IntoIterator"]),
Expand Down Expand Up @@ -726,8 +696,6 @@ pub(crate) struct Tokens {
pub(crate) from_value: syn::Path,
pub(crate) full_type_of: syn::Path,
pub(crate) hash: syn::Path,
pub(crate) dynamic_field_search: syn::Path,
pub(crate) dynamic_field_mode: syn::Path,
pub(crate) id: syn::Path,
pub(crate) install_with: syn::Path,
pub(crate) into_iterator: syn::Path,
Expand Down
1 change: 0 additions & 1 deletion crates/rune-macros/src/internals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub const STATIC_TYPE: Symbol = Symbol("static_type");
pub const FROM_VALUE: Symbol = Symbol("from_value");
pub const FROM_VALUE_PARAMS: Symbol = Symbol("from_value_params");

pub const META_FIELDS: Symbol = Symbol("meta_fields");
pub const GET: Symbol = Symbol("get");
pub const SET: Symbol = Symbol("set");
pub const COPY: Symbol = Symbol("copy");
Expand Down
4 changes: 2 additions & 2 deletions crates/rune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ categories = ["parser-implementations"]
default = ["emit", "std"]
emit = ["std", "codespan-reporting"]
bench = []
workspace = ["std", "toml", "semver", "relative-path", "serde-hashkey", "linked-hash-map", "dynamic_fields"]
workspace = ["std", "toml", "semver", "relative-path", "serde-hashkey", "linked-hash-map"]
doc = ["std", "rust-embed", "handlebars", "pulldown-cmark", "syntect", "sha2", "base64", "rune-core/doc", "relative-path"]
cli = ["std", "emit", "doc", "bincode", "atty", "tracing-subscriber", "clap", "webbrowser", "capture-io", "disable-io", "languageserver", "fmt", "similar", "rand"]
languageserver = ["std", "lsp", "ropey", "percent-encoding", "url", "serde_json", "tokio", "workspace", "doc", "fmt"]
Expand All @@ -27,7 +27,7 @@ disable-io = ["alloc"]
fmt = ["alloc"]
std = ["alloc", "num/std", "serde/std", "rune-core/std", "rune-alloc/std", "musli/std", "musli-storage/std", "once_cell/std", "anyhow/std"]
alloc = ["anyhow", "rune-alloc/alloc", "rune-core/alloc", "once_cell/alloc", "serde/alloc"]
dynamic_fields = ["rune-macros/dynamic_fields"]
dynamic_fields = []

[dependencies]
rune-macros = { version = "=0.13.1", path = "../rune-macros" }
Expand Down
3 changes: 1 addition & 2 deletions crates/rune/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub use rune_macros::Any;

use crate::compile::Named;
use crate::hash::Hash;
use crate::DynamicFieldSearch;

/// A trait which can be stored inside of an [AnyObj](crate::runtime::AnyObj).
///
Expand All @@ -74,7 +73,7 @@ use crate::DynamicFieldSearch;
/// }
/// ```

pub trait Any: Named + DynamicFieldSearch + any::Any {
pub trait Any: Named + any::Any {
/// The type hash of the type.
///
/// TODO: make const field when `TypeId::of` is const.
Expand Down
1 change: 0 additions & 1 deletion crates/rune/src/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ mod unit_builder;
pub(crate) mod v1;

mod compile;
pub(crate) mod dynamic_fields;
mod location;
pub mod meta;
mod named;
Expand Down
23 changes: 0 additions & 23 deletions crates/rune/src/compile/dynamic_fields.rs

This file was deleted.

Loading

0 comments on commit 8329943

Please sign in to comment.