Skip to main content

turbo_tasks_macros/
lib.rs

1#![allow(internal_features)]
2#![feature(proc_macro_diagnostic)]
3#![feature(allow_internal_unstable)]
4
5mod assert_fields;
6mod derive;
7mod func;
8mod function_macro;
9mod global_name;
10mod primitive_macro;
11mod task_input_attr_macro;
12mod value_impl_macro;
13mod value_macro;
14mod value_trait_macro;
15
16mod expand;
17mod ident;
18mod primitive_input;
19mod self_filter;
20mod turbofmt_macro;
21mod value_trait_arguments;
22
23use proc_macro::TokenStream;
24use proc_macro_error::proc_macro_error;
25
26#[proc_macro_derive(TraceRawVcs, attributes(turbo_tasks))]
27pub fn derive_trace_raw_vcs_attr(input: TokenStream) -> TokenStream {
28    derive::derive_trace_raw_vcs(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/// Derive macro for `ValueToString`. Also generates `ValueToStringify for &T`.
57#[doc = include_str!("../../turbo-tasks/FORMATTING.md")]
58#[proc_macro_derive(ValueToString, attributes(value_to_string))]
59pub fn derive_value_to_string(input: TokenStream) -> TokenStream {
60    derive::value_to_string_macro::derive_value_to_string(input)
61}
62
63/// <!--
64/// Documentation for this macro is available on the re-export:
65/// <https://turbopack-rust-docs.vercel.sh/rustdoc/turbo_tasks/attr.task_storage.html>
66/// -->
67#[proc_macro_attribute]
68pub fn task_storage(_args: TokenStream, input: TokenStream) -> TokenStream {
69    derive::task_storage(input)
70}
71
72/// <!--
73/// Documentation for this macro is available on the re-export:
74/// <https://turbopack-rust-docs.vercel.sh/rustdoc/turbo_tasks/attr.value.html>
75/// -->
76#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
77#[proc_macro_error]
78#[proc_macro_attribute]
79pub fn value(args: TokenStream, input: TokenStream) -> TokenStream {
80    value_macro::value(args, input)
81}
82
83#[proc_macro_attribute]
84pub fn task_input(args: TokenStream, input: TokenStream) -> TokenStream {
85    task_input_attr_macro::task_input(args, input)
86}
87
88/// <!--
89/// Documentation for this macro is available on the re-export:
90/// <https://turbopack-rust-docs.vercel.sh/rustdoc/turbo_tasks/attr.value_trait.html>
91/// -->
92#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
93#[proc_macro_error]
94#[proc_macro_attribute]
95pub fn value_trait(args: TokenStream, input: TokenStream) -> TokenStream {
96    value_trait_macro::value_trait(args, input)
97}
98
99#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
100#[proc_macro_error]
101#[proc_macro_attribute]
102pub fn function(args: TokenStream, input: TokenStream) -> TokenStream {
103    function_macro::function(args, input)
104}
105
106#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
107#[proc_macro_error]
108#[proc_macro_attribute]
109pub fn test_tt(_args: TokenStream, input: TokenStream) -> TokenStream {
110    derive::derive_value_debug(input)
111}
112
113#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
114#[proc_macro_error]
115#[proc_macro_attribute]
116pub fn value_impl(args: TokenStream, input: TokenStream) -> TokenStream {
117    value_impl_macro::value_impl(args, input)
118}
119
120#[allow_internal_unstable(min_specialization, into_future, trivial_bounds)]
121#[proc_macro_error]
122#[proc_macro]
123pub fn primitive(input: TokenStream) -> TokenStream {
124    primitive_macro::primitive(input)
125}
126
127/// Async format macro. Returns `impl Future<Output = Result<RcStr>>`.
128///
129/// ```ignore
130/// let s: RcStr = turbofmt!("asset {} in path {}", asset.ident(), base_path).await?;
131/// ```
132#[doc = include_str!("../../turbo-tasks/FORMATTING.md")]
133#[proc_macro]
134pub fn turbofmt(input: TokenStream) -> TokenStream {
135    turbofmt_macro::turbofmt(input)
136}
137
138/// Async bail macro. Resolves arguments then calls `anyhow::bail!()`.
139///
140/// ```ignore
141/// turbobail!("asset {} is not in path {}", asset.ident(), base_path);
142/// ```
143#[doc = include_str!("../../turbo-tasks/FORMATTING.md")]
144#[proc_macro]
145pub fn turbobail(input: TokenStream) -> TokenStream {
146    turbofmt_macro::turbobail(input)
147}