Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit ca97a51

Browse files
committed
Porting more internal changes to the Open
1 parent 28949a4 commit ca97a51

File tree

54 files changed

+1113
-580
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1113
-580
lines changed

src/Common/src/System/Dynamic/Utils/DelegateHelpers.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@ namespace System.Dynamic.Utils
1818
{
1919
internal static partial class DelegateHelpers
2020
{
21-
public delegate object VBCallSiteDelegate0<T>(T callSite, object instance);
22-
public delegate object VBCallSiteDelegate1<T>(T callSite, object instance, ref object arg1);
23-
public delegate object VBCallSiteDelegate2<T>(T callSite, object instance, ref object arg1, ref object arg2);
24-
public delegate object VBCallSiteDelegate3<T>(T callSite, object instance, ref object arg1, ref object arg2, ref object arg3);
25-
public delegate object VBCallSiteDelegate4<T>(T callSite, object instance, ref object arg1, ref object arg2, ref object arg3, ref object arg4);
26-
public delegate object VBCallSiteDelegate5<T>(T callSite, object instance, ref object arg1, ref object arg2, ref object arg3, ref object arg4, ref object arg5);
27-
public delegate object VBCallSiteDelegate6<T>(T callSite, object instance, ref object arg1, ref object arg2, ref object arg3, ref object arg4, ref object arg5, ref object arg6);
28-
public delegate object VBCallSiteDelegate7<T>(T callSite, object instance, ref object arg1, ref object arg2, ref object arg3, ref object arg4, ref object arg5, ref object arg6, ref object arg7);
29-
3021
internal static Delegate CreateObjectArrayDelegate(Type delegateType, System.Func<object[], object> handler)
3122
{
3223
#if !FEATURE_DYNAMIC_DELEGATE

src/Common/src/System/Linq/Expressions/Compiler/DelegateHelpers.Generated.cs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ private static TypeInfo NextTypeInfo(Type initialArg, TypeInfo curTypeInfo)
4040
}
4141

4242
#if !FEATURE_CORECLR
43+
44+
public delegate object VBCallSiteDelegate0<T>(T callSite, object instance);
45+
public delegate object VBCallSiteDelegate1<T>(T callSite, object instance, ref object arg1);
46+
public delegate object VBCallSiteDelegate2<T>(T callSite, object instance, ref object arg1, ref object arg2);
47+
public delegate object VBCallSiteDelegate3<T>(T callSite, object instance, ref object arg1, ref object arg2, ref object arg3);
48+
public delegate object VBCallSiteDelegate4<T>(T callSite, object instance, ref object arg1, ref object arg2, ref object arg3, ref object arg4);
49+
public delegate object VBCallSiteDelegate5<T>(T callSite, object instance, ref object arg1, ref object arg2, ref object arg3, ref object arg4, ref object arg5);
50+
public delegate object VBCallSiteDelegate6<T>(T callSite, object instance, ref object arg1, ref object arg2, ref object arg3, ref object arg4, ref object arg5, ref object arg6);
51+
public delegate object VBCallSiteDelegate7<T>(T callSite, object instance, ref object arg1, ref object arg2, ref object arg3, ref object arg4, ref object arg5, ref object arg6, ref object arg7);
52+
53+
4354
private static Type TryMakeVBStyledCallSite(Type[] types)
4455
{
4556
// Shape of VB CallSiteDelegates is CallSite * (instance : obj) * [arg-n : byref obj] -> obj
@@ -61,14 +72,14 @@ private static Type TryMakeVBStyledCallSite(Type[] types)
6172

6273
switch (types.Length - 1)
6374
{
64-
case 2: return typeof(Dynamic.Utils.DelegateHelpers.VBCallSiteDelegate0<>).MakeGenericType(types[0]);
65-
case 3: return typeof(Dynamic.Utils.DelegateHelpers.VBCallSiteDelegate1<>).MakeGenericType(types[0]);
66-
case 4: return typeof(Dynamic.Utils.DelegateHelpers.VBCallSiteDelegate2<>).MakeGenericType(types[0]);
67-
case 5: return typeof(Dynamic.Utils.DelegateHelpers.VBCallSiteDelegate3<>).MakeGenericType(types[0]);
68-
case 6: return typeof(Dynamic.Utils.DelegateHelpers.VBCallSiteDelegate4<>).MakeGenericType(types[0]);
69-
case 7: return typeof(Dynamic.Utils.DelegateHelpers.VBCallSiteDelegate5<>).MakeGenericType(types[0]);
70-
case 8: return typeof(Dynamic.Utils.DelegateHelpers.VBCallSiteDelegate6<>).MakeGenericType(types[0]);
71-
case 9: return typeof(Dynamic.Utils.DelegateHelpers.VBCallSiteDelegate7<>).MakeGenericType(types[0]);
75+
case 2: return typeof(VBCallSiteDelegate0<>).MakeGenericType(types[0]);
76+
case 3: return typeof(VBCallSiteDelegate1<>).MakeGenericType(types[0]);
77+
case 4: return typeof(VBCallSiteDelegate2<>).MakeGenericType(types[0]);
78+
case 5: return typeof(VBCallSiteDelegate3<>).MakeGenericType(types[0]);
79+
case 6: return typeof(VBCallSiteDelegate4<>).MakeGenericType(types[0]);
80+
case 7: return typeof(VBCallSiteDelegate5<>).MakeGenericType(types[0]);
81+
case 8: return typeof(VBCallSiteDelegate6<>).MakeGenericType(types[0]);
82+
case 9: return typeof(VBCallSiteDelegate7<>).MakeGenericType(types[0]);
7283
default: return null;
7384
}
7485
}

src/System.Dynamic.Runtime/src/Resources/System.Dynamic.Runtime.rd.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,21 @@
1212
<Type Name="CallSite&lt;T&gt;" Dynamic="Required Public">
1313
<GenericParameter Name="T" Dynamic="Public"/>
1414
</Type>
15+
<Type Name="RuleCache&lt;T&gt;" Dynamic="Required Public">
16+
<GenericParameter Name="T" Dynamic="Public"/>
17+
</Type>
1518
<Type Name="CallSiteOps">
1619
<Method Name="SetNotMatched" Dynamic="Required"/>
20+
<Method Name="GetMatch" Dynamic="Required"/>
21+
<Method Name="ClearMatch" Dynamic="Required"/>
22+
<MethodInstantiation Name="CreateMatchmaker" Arguments="System.Delegate" Dynamic="Required" />
23+
<MethodInstantiation Name="AddRule" Arguments="System.Delegate" Dynamic="Required" />
24+
<MethodInstantiation Name="UpdateRules" Arguments="System.Delegate" Dynamic="Required" />
25+
<MethodInstantiation Name="GetRules" Arguments="System.Delegate" Dynamic="Required" />
26+
<MethodInstantiation Name="GetRuleCache" Arguments="System.Delegate" Dynamic="Required" />
27+
<MethodInstantiation Name="MoveRule" Arguments="System.Delegate" Dynamic="Required" />
28+
<MethodInstantiation Name="GetCachedRules" Arguments="System.Delegate" Dynamic="Required" />
29+
<MethodInstantiation Name="Bind" Arguments="System.Delegate" Dynamic="Required" />
1730
</Type>
1831
<Type Name="RuntimeOps">
1932
<Method Name="ExpandoTryGetValue" Dynamic="Required"/>

src/System.Dynamic.Runtime/src/System.Dynamic.Runtime.csproj

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
<Compile Include="$(CommonPath)\System\Dynamic\Utils\TypeUtils.cs">
5757
<Link>Common\System\Dynamic\Utils\TypeUtils.cs</Link>
5858
</Compile>
59+
<Compile Include="$(CommonPath)\System\Dynamic\Utils\CollectionExtensions.Map.cs">
60+
<Link>Common\System\Dynamic\Utils\CollectionExtensions.Map.cs</Link>
61+
</Compile>
5962
<Compile Include="$(CommonPath)\System\Linq\Expressions\Compiler\DelegateHelpers.cs">
6063
<Link>Common\System\Linq\Expressions\Compiler\DelegateHelpers.cs</Link>
6164
</Compile>
@@ -114,20 +117,13 @@
114117
<Compile Include="System\Runtime\CompilerServices\RuntimeOps.cs" />
115118
</ItemGroup>
116119
<ItemGroup Condition=" '$(IsInterpreting)' != 'true' ">
117-
<Compile Include="$(CommonPath)\System\Dynamic\Utils\CollectionExtensions.Map.cs">
118-
<Link>Common\System\Dynamic\Utils\CollectionExtensions.Map.cs</Link>
119-
</Compile>
120120
<Compile Include="$(CommonPath)\System\Linq\Expressions\Compiler\AssemblyGen.cs">
121121
<Link>Common\System\Linq\Expressions\Compiler\AssemblyGen.cs</Link>
122122
</Compile>
123123

124124
<None Include="project.json" />
125125
</ItemGroup>
126126
<ItemGroup Condition=" '$(IsInterpreting)' == 'true' ">
127-
<Compile Include="$(CommonPath)\System\Dynamic\Utils\DelegateHelpers.cs">
128-
<Link>Common\System\Dynamic\Utils\DelegateHelpers.cs</Link>
129-
</Compile>
130-
131127
<None Include="projectInterpreting.json" />
132128
</ItemGroup>
133129
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />

src/System.Dynamic.Runtime/src/System/Dynamic/UpdateDelegates.Generated.cs

Lines changed: 0 additions & 173 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,179 +2996,6 @@ internal static void NoMatchVoid10<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9>(CallS
29962996
site._match = false;
29972997
return;
29982998
}
2999-
3000-
#else
3001-
3002-
internal static object UpdateAndExecuteGeneric(object[] args)
3003-
{
3004-
//
3005-
// Declare the locals here upfront. It actually saves JIT stack space.
3006-
//
3007-
var @this = (CallSite)args[0];
3008-
Delegate[] applicable;
3009-
Delegate rule, originalRule = @this.TargetProp;
3010-
object result;
3011-
3012-
//
3013-
// Create matchmaker and its site. We'll need them regardless.
3014-
//
3015-
CallSite site = @this.CreateMatchMaker();
3016-
site._match = true;
3017-
object[] matchmakerArgs = new object[args.Length];
3018-
matchmakerArgs[0] = site;
3019-
for (int i = 1; i < args.Length; i++)
3020-
{
3021-
matchmakerArgs[i] = args[i];
3022-
}
3023-
3024-
//
3025-
// Level 1 cache lookup
3026-
//
3027-
if ((applicable = @this.RulesProp) != null)
3028-
{
3029-
for (int i = 0; i < applicable.Length; i++)
3030-
{
3031-
rule = applicable[i];
3032-
3033-
//
3034-
// Execute the rule
3035-
//
3036-
3037-
// if we've already tried it skip it...
3038-
if ((object)rule != (object)originalRule)
3039-
{
3040-
@this.TargetProp = rule;
3041-
try
3042-
{
3043-
result = rule.DynamicInvoke(matchmakerArgs);
3044-
}
3045-
catch (System.Reflection.TargetInvocationException e)
3046-
{
3047-
throw e.InnerException; // TODO: preserve stacktrace?
3048-
}
3049-
3050-
if (site._match)
3051-
{
3052-
@this.MoveRule(i);
3053-
return result;
3054-
}
3055-
3056-
// Rule didn't match, try the next one
3057-
site._match = true;
3058-
}
3059-
}
3060-
}
3061-
3062-
//
3063-
// Level 2 cache lookup
3064-
//
3065-
3066-
//
3067-
// Any applicable rules in level 2 cache?
3068-
//
3069-
3070-
var cache = @this.GetRuleCache();
3071-
3072-
applicable = cache.GetRules();
3073-
for (int i = 0; i < applicable.Length; i++)
3074-
{
3075-
rule = applicable[i];
3076-
3077-
//
3078-
// Execute the rule
3079-
//
3080-
@this.TargetProp = rule;
3081-
3082-
try
3083-
{
3084-
try
3085-
{
3086-
result = rule.DynamicInvoke(matchmakerArgs);
3087-
}
3088-
catch (System.Reflection.TargetInvocationException e)
3089-
{
3090-
throw e.InnerException; // TODO: preserve stacktrace?
3091-
}
3092-
if (site._match)
3093-
{
3094-
return result;
3095-
}
3096-
}
3097-
finally
3098-
{
3099-
if (site._match)
3100-
{
3101-
//
3102-
// Rule worked. Add it to level 1 cache
3103-
//
3104-
@this.AddRule(rule);
3105-
// and then move it to the front of the L2 cache
3106-
3107-
cache.MoveRule(rule, i);
3108-
}
3109-
}
3110-
3111-
// Rule didn't match, try the next one
3112-
site._match = true;
3113-
}
3114-
3115-
//
3116-
// Miss on Level 0, 1 and 2 caches. Create new rule
3117-
//
3118-
3119-
rule = null;
3120-
var bindArgs = new object[args.Length - 1];
3121-
for (int i = 0; i < bindArgs.Length; i++)
3122-
{
3123-
bindArgs[i] = args[i + 1];
3124-
}
3125-
3126-
for (; ;)
3127-
{
3128-
@this.TargetProp = originalRule;
3129-
rule = @this.TargetProp = @this.BindCore(bindArgs);
3130-
3131-
//
3132-
// Execute the rule on the matchmaker site
3133-
//
3134-
3135-
try
3136-
{
3137-
try
3138-
{
3139-
result = rule.DynamicInvoke(args);
3140-
}
3141-
catch (System.Reflection.TargetInvocationException e)
3142-
{
3143-
throw e.InnerException; // TODO: preserve stacktrace?
3144-
}
3145-
if (site._match)
3146-
{
3147-
return result;
3148-
}
3149-
}
3150-
finally
3151-
{
3152-
if (site._match)
3153-
{
3154-
//
3155-
// The rule worked. Add it to level 1 cache.
3156-
//
3157-
@this.AddRule(rule);
3158-
}
3159-
}
3160-
3161-
// Rule we got back didn't work, try another one
3162-
site._match = true;
3163-
}
3164-
}
3165-
3166-
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters")]
3167-
internal static object NoMatchGeneric(object[] args)
3168-
{
3169-
((CallSite)args[0])._match = false;
3170-
return null;
3171-
}
31722999
#endif
31733000
}
31743001
}

0 commit comments

Comments
 (0)