Skip to content

Commit

Permalink
Render more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Apr 4, 2023
1 parent 6d6c18b commit d96abed
Show file tree
Hide file tree
Showing 24 changed files with 1,017 additions and 805 deletions.
8 changes: 7 additions & 1 deletion crates/rune-macros/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ where
raw_str,
shared,
type_info,
any_type_info,
type_of,
unsafe_from_value,
unsafe_to_value,
Expand Down Expand Up @@ -436,12 +437,17 @@ where
#impl_named

impl #impl_generics #type_of for #ident #ty_generics #where_clause {
#[inline]
fn type_hash() -> #hash {
<Self as #any>::type_hash()
}

#[inline]
fn type_info() -> #type_info {
#type_info::Any(#raw_str::from_str(std::any::type_name::<Self>()))
#type_info::Any(#any_type_info::new(
#raw_str::from_str(std::any::type_name::<Self>()),
<Self as #any>::type_hash()
))
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/rune-macros/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,7 @@ impl Context {
token_stream: quote!(#module::macros::TokenStream),
tuple: quote!(#module::runtime::Tuple),
type_info: quote!(#module::runtime::TypeInfo),
any_type_info: quote!(#module::runtime::AnyTypeInfo),
type_of: quote!(#module::runtime::TypeOf),
unit_struct: quote!(#module::runtime::UnitStruct),
unsafe_from_value: quote!(#module::runtime::UnsafeFromValue),
Expand Down Expand Up @@ -686,6 +687,7 @@ pub(crate) struct Tokens {
pub(crate) token_stream: TokenStream,
pub(crate) tuple: TokenStream,
pub(crate) type_info: TokenStream,
pub(crate) any_type_info: TokenStream,
pub(crate) type_of: TokenStream,
pub(crate) unit_struct: TokenStream,
pub(crate) unsafe_from_value: TokenStream,
Expand Down
3 changes: 2 additions & 1 deletion crates/rune/src/any.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::compile::Named;
use crate::Hash;
use crate::hash::Hash;

pub use rune_macros::Any;

/// A trait which can be stored inside of an [AnyObj](crate::runtime::AnyObj).
Expand Down
8 changes: 5 additions & 3 deletions crates/rune/src/compile/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct PrivMeta {

impl PrivMeta {
pub(crate) fn new(
module: &Module,
#[cfg_attr(not(feature = "doc"), allow(unused))] module: &Module,
hash: Hash,
item: ItemBuf,
kind: meta::Kind,
Expand Down Expand Up @@ -288,6 +288,7 @@ impl Context {
}

/// Look up signature of function.
#[cfg(feature = "doc")]
pub(crate) fn lookup_signature(&self, hash: Hash) -> Option<&meta::Signature> {
self.functions_info.get(&hash)
}
Expand Down Expand Up @@ -604,6 +605,7 @@ impl Context {
};

let hash = assoc
.name
.kind
.hash(key.type_hash)
.with_parameters(key.parameters);
Expand All @@ -613,7 +615,7 @@ impl Context {
is_async: assoc.is_async,
args: assoc.args,
kind: meta::SignatureKind::Instance {
name: assoc.kind.clone(),
name: assoc.name.kind.clone(),
self_type_info: info.type_info.clone(),
},
};
Expand All @@ -639,7 +641,7 @@ impl Context {
//
// The other alternatives are protocol functions (which are not free)
// and plain hashes.
if let AssociatedFunctionKind::Instance(name) = &assoc.kind {
if let AssociatedFunctionKind::Instance(name) = &assoc.name.kind {
let item = info.item.extended(name);
self.names.insert(&item);

Expand Down
50 changes: 13 additions & 37 deletions crates/rune/src/compile/function_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ use crate::compile::module::{
AssocType, AssociatedFunctionKey, AsyncFunction, AsyncInstFn, Function, InstFn,
};
use crate::compile::{IntoComponent, ItemBuf, Named};
use crate::hash::{Hash, Params};
use crate::hash::Hash;
#[cfg(feature = "doc")]
use crate::runtime::TypeInfo;
use crate::runtime::{FunctionHandler, Protocol};

mod sealed {
use crate::hash::Params;
use crate::params::Params;
use crate::runtime::Protocol;

pub trait Sealed {}

impl Sealed for &str {}
impl Sealed for Protocol {}
impl<T, P> Sealed for Params<T, P> {}
impl<T, const N: usize> Sealed for Params<T, N> {}
}

/// Type used to collect and store function metadata through the
Expand Down Expand Up @@ -135,6 +137,8 @@ impl ToInstance for &str {
AssociatedFunctionName {
kind: AssociatedFunctionKind::Instance(self.into()),
parameters: Hash::EMPTY,
#[cfg(feature = "doc")]
parameter_type_infos: vec![],
}
}
}
Expand All @@ -145,40 +149,8 @@ impl ToFieldFunction for &str {
AssociatedFunctionName {
kind: AssociatedFunctionKind::FieldFn(protocol, self.into()),
parameters: Hash::EMPTY,
}
}
}

impl<T, P> ToInstance for Params<T, P>
where
T: ToInstance,
P: IntoIterator,
P::Item: std::hash::Hash,
{
#[inline]
fn to_instance(self) -> AssociatedFunctionName {
let info = self.name.to_instance();

AssociatedFunctionName {
kind: info.kind,
parameters: Hash::parameters(self.parameters),
}
}
}

impl<T, P> ToFieldFunction for Params<T, P>
where
T: ToFieldFunction,
P: IntoIterator,
P::Item: std::hash::Hash,
{
#[inline]
fn to_field_function(self, protocol: Protocol) -> AssociatedFunctionName {
let info = self.name.to_field_function(protocol);

AssociatedFunctionName {
kind: info.kind,
parameters: Hash::parameters(self.parameters),
#[cfg(feature = "doc")]
parameter_type_infos: vec![],
}
}
}
Expand All @@ -192,13 +164,17 @@ pub struct AssociatedFunctionName {
pub kind: AssociatedFunctionKind,
/// Parameters hash.
pub parameters: Hash,
#[cfg(feature = "doc")]
pub parameter_type_infos: Vec<TypeInfo>,
}

impl AssociatedFunctionName {
pub(crate) fn index(protocol: Protocol, index: usize) -> Self {
Self {
kind: AssociatedFunctionKind::IndexFn(protocol, index),
parameters: Hash::EMPTY,
#[cfg(feature = "doc")]
parameter_type_infos: vec![],
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions crates/rune/src/compile/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,18 @@ pub(crate) enum TypeSpecification {
#[derive(Clone)]
#[non_exhaustive]
pub struct AssociatedFunction {
/// Handle of the associated function.
pub(crate) handler: Arc<FunctionHandler>,
/// Type information of the associated function.
pub(crate) type_info: TypeInfo,
/// If the function is asynchronous.
pub is_async: bool,
pub(crate) is_async: bool,
/// Arguments the function receives.
pub args: Option<usize>,
/// The kind of the associated function.
pub kind: AssociatedFunctionKind,
pub(crate) args: Option<usize>,
/// The full name of the associated function.
pub(crate) name: AssociatedFunctionName,
/// The documentation of the associated function.
pub docs: Docs,
pub(crate) docs: Docs,
}

/// A key that identifies an associated function.
Expand Down Expand Up @@ -1071,7 +1073,7 @@ impl Module {
type_info: data.ty.type_info,
is_async: data.is_async,
args: data.args,
kind: data.name.kind,
name: data.name,
docs,
};

Expand Down
Loading

0 comments on commit d96abed

Please sign in to comment.