turbo_tasks_macros/
lib.rs

1#![allow(internal_features)]
2#![feature(proc_macro_diagnostic)]
3#![feature(allow_internal_unstable)]
4#![feature(box_patterns)]
5
6mod assert_fields;
7mod derive;
8mod func;
9mod function_macro;
10mod generic_type_macro;
11mod primitive_macro;
12mod value_impl_macro;
13mod value_macro;
14mod value_trait_macro;
15
16extern crate proc_macro;
17
18use proc_macro::TokenStream;
19use proc_macro_error::proc_macro_error;
20
21#[proc_macro_derive(TraceRawVcs, attributes(turbo_tasks))]
22pub fn derive_trace_raw_vcs_attr(input: TokenStream) -> TokenStream {
23    derive::derive_trace_raw_vcs(input)
24}
25
26#[proc_macro_derive(ShrinkToFit, attributes(turbo_tasks))]
27pub fn derive_shrink_to_fit(input: TokenStream) -> TokenStream {
28    derive::derive_shrink_to_fit(input)
29}
30
31#[proc_macro_derive(NonLocalValue, attributes(turbo_tasks))]
32pub fn derive_non_local_value_attr(input: TokenStream) -> TokenStream {
33    derive::derive_non_local_value(input)
34}
35
36#[proc_macro_derive(OperationValue, attributes(turbo_tasks))]
37pub fn derive_operation_value_attr(input: TokenStream) -> TokenStream {
38    derive::derive_operation_value(input)
39}
40
41#[proc_macro_derive(ValueDebug, attributes(turbo_tasks))]
42pub fn derive_value_debug_attr(input: TokenStream) -> TokenStream {
43    derive::derive_value_debug(input)
44}
45
46#[proc_macro_derive(ValueDebugFormat, attributes(turbo_tasks))]
47pub fn derive_value_debug_format_attr(input: TokenStream) -> TokenStream {
48    derive::derive_value_debug_format(input)
49}
50
51#[proc_macro_derive(DeterministicHash, attributes(turbo_tasks))]
52pub fn derive_deterministic_hash(input: TokenStream) -> TokenStream {
53    derive::derive_deterministic_hash(input)
54}
55
56#[proc_macro_derive(TaskInput, attributes(turbo_tasks))]
57pub fn derive_task_input(input: TokenStream) -> TokenStream {
58    derive::derive_task_input(input)
59}
60
61/// Derives the `turbo_tasks::KeyValuePair` trait for a enum. Each variant need to have a `value`
62/// field which becomes part of the value enum and all remaining fields become part of the key.
63///
64/// Assuming the enum is called `Abc` it exposes `AbcKey` and `AbcValue` types for it too. The key
65/// enum will have `Debug, Clone, PartialEq, Eq, Hash` derived and the value enum will have `Debug,
66/// Clone` derived. It's expected that all fields implement these traits.
67#[proc_macro_derive(KeyValuePair)]
68pub fn derive_key_value_pair(input: TokenStream) -> TokenStream {
69    derive::derive_key_value_pair(input)
70}
71
72#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
73#[proc_macro_error]
74#[proc_macro_attribute]
75pub fn value(args: TokenStream, input: TokenStream) -> TokenStream {
76    value_macro::value(args, input)
77}
78
79/// Allows this trait to be used as part of a trait object inside of a value
80/// cell, in the form of `Vc<dyn MyTrait>`.
81///
82/// ## Arguments
83///
84/// Example: `#[turbo_tasks::value_trait(no_debug, resolved)]`
85///
86/// ### 'no_debug`
87///
88/// Disables the automatic implementation of [`turbo_tasks::debug::ValueDebug`].
89///
90/// Example: `#[turbo_tasks::value_trait(no_debug)]`
91///
92/// ### 'resolved`
93///
94/// Adds [`turbo_tasks::NonLocalValue`] as a supertrait of this trait.
95///
96/// Example: `#[turbo_tasks::value_trait(resolved)]`
97#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
98#[proc_macro_error]
99#[proc_macro_attribute]
100pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream {
101    value_trait_macro::value_trait(args, input)
102}
103
104#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
105#[proc_macro_error]
106#[proc_macro_attribute]
107pub fn function(args: TokenStream, input: TokenStream) -> TokenStream {
108    function_macro::function(args, input)
109}
110
111#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
112#[proc_macro_error]
113#[proc_macro_attribute]
114pub fn test_tt(_args: TokenStream, input: TokenStream) -> TokenStream {
115    derive::derive_value_debug(input)
116}
117
118#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
119#[proc_macro_error]
120#[proc_macro_attribute]
121pub fn value_impl(args: TokenStream, input: TokenStream) -> TokenStream {
122    value_impl_macro::value_impl(args, input)
123}
124
125#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
126#[proc_macro_error]
127#[proc_macro]
128pub fn primitive(input: TokenStream) -> TokenStream {
129    primitive_macro::primitive(input)
130}
131
132/// Registers a value type that is generic over the `Vc` it contains.
133///
134/// # Example
135///
136/// ```
137/// use crate::generic_type as __turbo_tasks_internal_generic_type;
138///
139/// __turbo_tasks_internal_generic_type!(<A, B>, GenericType<Vc<A>, Vc<B>>);
140///
141/// // Now you can do the following, for any `A` and `B` value types:
142///
143/// let vc: Vc<GenericType<Vc<u32>, Vc<RcStr>>> = Vc::cell(
144///     GenericType::new(
145///         Vc::cell(42),
146///         Vc::cell("hello".to_string())
147///     )
148/// );
149/// ```
150#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
151#[proc_macro_error]
152#[proc_macro]
153pub fn generic_type(input: TokenStream) -> TokenStream {
154    generic_type_macro::generic_type(input)
155}