11using System ;
2+ using System . Linq ;
23using System . Reflection ;
34using System . Runtime . CompilerServices ;
45using System . Threading . Tasks ;
56
67using BenchmarkDotNet . Extensions ;
78using BenchmarkDotNet . Running ;
89
9- using JetBrains . Annotations ;
10-
1110namespace BenchmarkDotNet . Toolchains . InProcess . NoEmit
1211{
1312 /// <summary>Helper class that creates <see cref="BenchmarkAction"/> instances. </summary>
@@ -29,9 +28,40 @@ private static BenchmarkAction CreateCore(
2928 if ( resultType == typeof ( void ) )
3029 return new BenchmarkActionVoid ( resultInstance , targetMethod , unrollFactor ) ;
3130
31+ if ( resultType == typeof ( void * ) )
32+ return new BenchmarkActionVoidPointer ( resultInstance , targetMethod , unrollFactor ) ;
33+
34+ if ( resultType . IsPointer )
35+ return Create (
36+ typeof ( BenchmarkActionPointer < > ) . MakeGenericType ( resultType . GetElementType ( ) ) ,
37+ resultInstance ,
38+ targetMethod ,
39+ unrollFactor ) ;
40+
41+ if ( resultType . IsByRef )
42+ {
43+ var returnParameter = targetMethod ? . ReturnParameter ?? fallbackIdleSignature . ReturnParameter ;
44+ // System.Runtime.CompilerServices.IsReadOnlyAttribute is part of .NET Standard 2.1, we can't use it here..
45+ if ( returnParameter . GetCustomAttributes ( ) . Any ( attribute => attribute . GetType ( ) . Name == "IsReadOnlyAttribute" ) )
46+ return Create (
47+ typeof ( BenchmarkActionByRefReadonly < > ) . MakeGenericType ( resultType . GetElementType ( ) ) ,
48+ resultInstance ,
49+ targetMethod ,
50+ unrollFactor ) ;
51+
52+ return Create (
53+ typeof ( BenchmarkActionByRef < > ) . MakeGenericType ( resultType . GetElementType ( ) ) ,
54+ resultInstance ,
55+ targetMethod ,
56+ unrollFactor ) ;
57+ }
58+
3259 if ( resultType == typeof ( Task ) )
3360 return new BenchmarkActionTask ( resultInstance , targetMethod , unrollFactor ) ;
3461
62+ if ( resultType == typeof ( ValueTask ) )
63+ return new BenchmarkActionValueTask ( resultInstance , targetMethod , unrollFactor ) ;
64+
3565 if ( resultType . GetTypeInfo ( ) . IsGenericType )
3666 {
3767 var genericType = resultType . GetGenericTypeDefinition ( ) ;
@@ -51,10 +81,6 @@ private static BenchmarkAction CreateCore(
5181 unrollFactor ) ;
5282 }
5383
54- if ( targetMethod == null && resultType . GetTypeInfo ( ) . IsValueType )
55- // for Idle: we return int because creating bigger ValueType could take longer than benchmarked method itself.
56- resultType = typeof ( int ) ;
57-
5884 return Create (
5985 typeof ( BenchmarkAction < > ) . MakeGenericType ( resultType ) ,
6086 resultInstance ,
@@ -88,6 +114,10 @@ private static void PrepareInstanceAndResultType(
88114 if ( isUsingAsyncKeyword )
89115 throw new NotSupportedException ( "Async void is not supported by design." ) ;
90116 }
117+ else if ( resultType . IsByRefLike ( ) )
118+ {
119+ throw new NotSupportedException ( "InProcessNoEmitToolchain does not support consuming ByRefLike return types." ) ;
120+ }
91121 }
92122
93123 /// <summary>Helper to enforce .ctor signature.</summary>
0 commit comments