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 fa8d2ff
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 440 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.

5 changes: 1 addition & 4 deletions crates/rune/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,10 +478,7 @@ pub use rune_macros::module;
pub use self::any::Any;
pub use self::build::{prepare, Build, BuildError};
#[doc(inline)]
pub use self::compile::{
dynamic_fields::{DynamicFieldMode, DynamicFieldSearch},
Context, ContextError, Options,
};
pub use self::compile::{Context, ContextError, Options};
#[doc(inline)]
pub use self::diagnostics::Diagnostics;
pub use self::hash::{Hash, ToTypeHash};
Expand Down
20 changes: 0 additions & 20 deletions crates/rune/src/runtime/any_obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use crate::alloc::{self, Box};
use crate::any::Any;
use crate::hash::Hash;
use crate::runtime::{AnyTypeInfo, FullTypeOf, MaybeTypeOf, RawStr, TypeInfo};
#[cfg(feature = "dynamic_fields")]
use crate::{DynamicFieldMode, DynamicFieldSearch};

/// Errors raised during casting operations.
#[derive(Debug)]
Expand Down Expand Up @@ -84,8 +82,6 @@ impl AnyObj {
debug: debug_impl::<T>,
type_name: type_name_impl::<T>,
type_hash: type_hash_impl::<T>,
#[cfg(feature = "dynamic_fields")]
field_mode: T::DYNAMIC_FIELD_MODE,
},
data,
})
Expand Down Expand Up @@ -144,8 +140,6 @@ impl AnyObj {
debug: debug_ref_impl::<T>,
type_name: type_name_impl::<T>,
type_hash: type_hash_impl::<T>,
#[cfg(feature = "dynamic_fields")]
field_mode: T::DYNAMIC_FIELD_MODE,
},
data,
}
Expand Down Expand Up @@ -196,8 +190,6 @@ impl AnyObj {
debug: debug_ref_impl::<T::Target>,
type_name: type_name_impl::<T::Target>,
type_hash: type_hash_impl::<T::Target>,
#[cfg(feature = "dynamic_fields")]
field_mode: T::Target::DYNAMIC_FIELD_MODE,
},
data,
})
Expand Down Expand Up @@ -262,8 +254,6 @@ impl AnyObj {
debug: debug_mut_impl::<T>,
type_name: type_name_impl::<T>,
type_hash: type_hash_impl::<T>,
#[cfg(feature = "dynamic_fields")]
field_mode: T::DYNAMIC_FIELD_MODE,
},
data,
}
Expand Down Expand Up @@ -314,8 +304,6 @@ impl AnyObj {
debug: debug_mut_impl::<T::Target>,
type_name: type_name_impl::<T::Target>,
type_hash: type_hash_impl::<T::Target>,
#[cfg(feature = "dynamic_fields")]
field_mode: T::Target::DYNAMIC_FIELD_MODE,
},
data,
})
Expand Down Expand Up @@ -514,12 +502,6 @@ impl AnyObj {
(self.vtable.type_hash)(),
))
}

#[cfg(feature = "dynamic_fields")]
/// Access the dynamic field mode for the type.
pub fn field_mode(&self) -> DynamicFieldMode {
self.vtable.field_mode
}
}

impl MaybeTypeOf for AnyObj {
Expand Down Expand Up @@ -582,8 +564,6 @@ pub struct AnyObjVtable {
type_name: TypeNameFn,
/// Get the type hash of the stored type.
type_hash: TypeHashFn,
#[cfg(feature = "dynamic_fields")]
field_mode: DynamicFieldMode,
}

unsafe fn drop_impl<T>(this: *mut ()) {
Expand Down
13 changes: 0 additions & 13 deletions crates/rune/src/runtime/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use ::serde::{Deserialize, Serialize};
use crate::alloc::fmt::TryWrite;
use crate::alloc::prelude::*;
use crate::alloc::{self, String};
#[cfg(feature = "dynamic_fields")]
use crate::compile::dynamic_fields::DynamicFieldMode;
use crate::compile::ItemBuf;
use crate::runtime::vm::CallResult;
use crate::runtime::{
Expand Down Expand Up @@ -1213,17 +1211,6 @@ impl Value {
})
}

#[cfg(feature = "dynamic_fields")]
/// Function returns the method in which to search for fields within
/// the value.
pub(crate) fn field_mode(&self) -> Result<DynamicFieldMode, VmError> {
if let Value::Any(v) = self {
Ok(v.borrow_ref()?.field_mode())
} else {
Ok(DynamicFieldMode::Never)
}
}

/// Perform a partial equality test between two values.
///
/// This is the basis for the eq operation (`partial_eq` / '==').
Expand Down
Loading

0 comments on commit fa8d2ff

Please sign in to comment.