@@ -245,37 +245,8 @@ fn create(
245245 impl_params_t. params . push ( t. clone ( ) ) ;
246246 type_params_t. params . push ( t. clone ( ) ) ;
247247
248- // Prepare validations.
249248 let prefix = trait_. as_ref ( ) . map ( |name| quote ! { #name for } ) ;
250- let validations: Vec < _ > = methods. iter ( ) . map ( create_validation) . collect ( ) ;
251- let validate = if !methods. is_empty ( ) {
252- quote ! {
253- let mut this = #maybe_cloned;
254- constraint. validate( |call| match & call. 0 { #( #validations, ) * } )
255- }
256- } else {
257- quote ! { true }
258- } ;
259- let validate_with_id = if !methods. is_empty ( ) {
260- quote ! {
261- let mut this = #maybe_cloned;
262- constraint. validate_with_id(
263- |call| match & call. 0 { #( #validations, ) * } ,
264- id,
265- )
266- }
267- } else {
268- quote ! { true }
269- } ;
270-
271- // Prepare replying.
272- let immutable = methods. iter ( ) . all ( |m| !m. mutable ) ;
273- let replays = methods. iter ( ) . map ( create_replay) ;
274- let replay = ( !immutable) . then ( || {
275- quote ! {
276- constraint. replay( |call| match & call. 0 { #( #replays, ) * } ) ;
277- }
278- } ) ;
249+ let calls: Vec < _ > = methods. iter ( ) . map ( create_call) . collect ( ) ;
279250
280251 // Prepare variants and wrapper methods.
281252 let wrapper_methods = methods
@@ -284,32 +255,20 @@ fn create(
284255 . map ( |m| create_wrapper ( m, false ) ) ;
285256 let wrapper_methods_mut = methods. iter ( ) . map ( |m| create_wrapper ( m, true ) ) ;
286257
287- let constraint = if immutable {
288- quote ! { ImmutableConstraint }
289- } else {
290- quote ! { MutableConstraint }
291- } ;
292-
293258 Ok ( quote ! {
294- impl #impl_params :: comemo:: Track for #ty #where_clause { }
295-
296- impl #impl_params :: comemo:: Validate for #ty #where_clause {
297- type Constraint = :: comemo:: internal:: #constraint<__ComemoCall>;
259+ impl #impl_params :: comemo:: Track for #ty #where_clause {
260+ type Call = __ComemoCall;
298261
299262 #[ inline]
300- fn validate( & self , constraint: & Self :: Constraint ) -> bool {
301- #validate
263+ fn call( & self , call: Self :: Call ) -> u128 {
264+ let mut this = #maybe_cloned;
265+ match call. 0 { #( #calls, ) * }
302266 }
303267
304268 #[ inline]
305- fn validate_with_id( & self , constraint: & Self :: Constraint , id: usize ) -> bool {
306- #validate_with_id
307- }
308-
309- #[ inline]
310- #[ allow( unused_variables) ]
311- fn replay( & mut self , constraint: & Self :: Constraint ) {
312- #replay
269+ fn call_mut( & mut self , call: Self :: Call ) -> u128 {
270+ let mut this = self ;
271+ match call. 0 { #( #calls, ) * }
313272 }
314273 }
315274
@@ -371,35 +330,19 @@ fn create_variant(method: &Method) -> TokenStream {
371330}
372331
373332/// Produce a constraint validation for a method.
374- fn create_validation ( method : & Method ) -> TokenStream {
333+ fn create_call ( method : & Method ) -> TokenStream {
375334 let name = & method. sig . ident ;
376335 let args = & method. args ;
377336 let prepared = method. args . iter ( ) . zip ( & method. kinds ) . map ( |( arg, kind) | match kind {
378337 Kind :: Normal => quote ! { #arg. to_owned( ) } ,
379338 Kind :: Reference => quote ! { #arg } ,
380339 } ) ;
381340 quote ! {
382- __ComemoVariant:: #name( #( #args) , * )
341+ __ComemoVariant:: #name( #( ref #args) , * )
383342 => :: comemo:: internal:: hash( & this. #name( #( #prepared) , * ) )
384343 }
385344}
386345
387- /// Produce a constraint validation for a method.
388- fn create_replay ( method : & Method ) -> TokenStream {
389- let name = & method. sig . ident ;
390- let args = & method. args ;
391- let prepared = method. args . iter ( ) . zip ( & method. kinds ) . map ( |( arg, kind) | match kind {
392- Kind :: Normal => quote ! { #arg. to_owned( ) } ,
393- Kind :: Reference => quote ! { #arg } ,
394- } ) ;
395- let body = method. mutable . then ( || {
396- quote ! {
397- self . #name( #( #prepared) , * ) ;
398- }
399- } ) ;
400- quote ! { __ComemoVariant:: #name( #( #args) , * ) => { #body } }
401- }
402-
403346/// Produce a wrapped surface method.
404347fn create_wrapper ( method : & Method , tracked_mut : bool ) -> TokenStream {
405348 let name = & method. sig . ident ;
@@ -417,16 +360,18 @@ fn create_wrapper(method: &Method, tracked_mut: bool) -> TokenStream {
417360 #[ track_caller]
418361 #[ inline]
419362 #vis #sig {
420- let __comemo_variant = __ComemoVariant :: #name ( # ( #args . to_owned ( ) ) , * ) ;
421- let ( __comemo_value , __comemo_constraint ) = :: comemo :: internal :: #to_parts ;
422- let output = __comemo_value . #name( #( #args, ) * ) ;
423- if let Some ( constraint ) = __comemo_constraint {
424- constraint . push (
363+ let ( __comemo_value , __comemo_sink ) = :: comemo :: internal :: #to_parts ;
364+ if let Some ( __comemo_sink ) = __comemo_sink {
365+ let __comemo_variant = __ComemoVariant :: #name( #( #args. to_owned ( ) ) , * ) ;
366+ let output = __comemo_value . #name ( # ( #args , ) * ) ;
367+ __comemo_sink (
425368 __ComemoCall( __comemo_variant) ,
426369 :: comemo:: internal:: hash( & output) ,
427370 ) ;
371+ output
372+ } else {
373+ __comemo_value. #name( #( #args, ) * )
428374 }
429- output
430375 }
431376 }
432377}
0 commit comments