Imported Upstream version 5.10.0.69

Former-commit-id: fc39669a0b707dd3c063977486506b6793da2890
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2018-01-29 19:03:06 +00:00
parent d8f8abd549
commit e2950ec768
6283 changed files with 453847 additions and 91879 deletions

View File

@@ -26,14 +26,14 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4B4AA59B-89F9-4A34-B3C3-C97EF531EE00}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{4B4AA59B-89F9-4A34-B3C3-C97EF531EE00}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{4B4AA59B-89F9-4A34-B3C3-C97EF531EE00}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{4B4AA59B-89F9-4A34-B3C3-C97EF531EE00}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{AEF718E9-D4FC-418F-A7AE-ED6B2C7B3787}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{AEF718E9-D4FC-418F-A7AE-ED6B2C7B3787}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{AEF718E9-D4FC-418F-A7AE-ED6B2C7B3787}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU
{AEF718E9-D4FC-418F-A7AE-ED6B2C7B3787}.Release|Any CPU.Build.0 = netcoreapp-Release|Any CPU
{4B4AA59B-89F9-4A34-B3C3-C97EF531EE00}.Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
{4B4AA59B-89F9-4A34-B3C3-C97EF531EE00}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{4B4AA59B-89F9-4A34-B3C3-C97EF531EE00}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{4B4AA59B-89F9-4A34-B3C3-C97EF531EE00}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{AEF718E9-D4FC-418F-A7AE-ED6B2C7B3787}.Debug|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Debug|Any CPU
{AEF718E9-D4FC-418F-A7AE-ED6B2C7B3787}.Debug|Any CPU.Build.0 = netcoreapp-Windows_NT-Debug|Any CPU
{AEF718E9-D4FC-418F-A7AE-ED6B2C7B3787}.Release|Any CPU.ActiveCfg = netcoreapp-Windows_NT-Release|Any CPU
{AEF718E9-D4FC-418F-A7AE-ED6B2C7B3787}.Release|Any CPU.Build.0 = netcoreapp-Windows_NT-Release|Any CPU
{33B6ACE2-0B53-4054-8BF6-482F9E0E9427}.Debug|Any CPU.ActiveCfg = netcoreapp-Debug|Any CPU
{33B6ACE2-0B53-4054-8BF6-482F9E0E9427}.Debug|Any CPU.Build.0 = netcoreapp-Debug|Any CPU
{33B6ACE2-0B53-4054-8BF6-482F9E0E9427}.Release|Any CPU.ActiveCfg = netcoreapp-Release|Any CPU

View File

@@ -2,9 +2,10 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<BuildConfigurations>
uap-Windows_NT;
netcoreapp-Unix;
netcoreapp-Windows_NT;
uapaot-Windows_NT;
netcoreapp;
uap-Windows_NT;
</BuildConfigurations>
</PropertyGroup>
</Project>

View File

@@ -565,4 +565,7 @@
<data name="SameKeyExistsInExpando" xml:space="preserve">
<value>An element with the same key '{0}' already exists in the ExpandoObject.</value>
</data>
<data name="Arg_KeyNotFoundWithKey" xml:space="preserve">
<value>The given key '{0}' was not present in the dictionary.</value>
</data>
</root>

View File

@@ -162,9 +162,6 @@
<Property Name="Current" Dynamic="Required"/>
</Type>
</Namespace>
<Namespace Name="System.Runtime.CompilerServices">
<Type Name="RuntimeWrappedException" Dynamic="Required All" Activate="Required All" />
</Namespace>
</Assembly>
<Assembly Name="System.Runtime">
<Type Name="System.Runtime.CompilerServices.StrongBox&lt;System.Object&gt;" Dynamic="Required All" />

View File

@@ -13,9 +13,10 @@
<DefineConstants Condition=" '$(IsInterpreting)' != 'true' ">$(DefineConstants);FEATURE_COMPILE</DefineConstants>
<DefineConstants Condition=" '$(FeatureInterpret)' == 'true' ">$(DefineConstants);FEATURE_INTERPRET</DefineConstants>
</PropertyGroup>
<!-- Default configurations to help VS understand the configurations -->
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netcoreapp-Unix-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uap-Windows_NT-Release|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'uapaot-Windows_NT-Debug|AnyCPU'" />
@@ -25,34 +26,17 @@
</PropertyGroup>
<ItemGroup Condition="'$(TargetGroup)' == 'uapaot'">
<EmbeddedResource Include="Resources\$(AssemblyName).rd.xml" />
<!-- Needed for DynamicDelegate -->
</ItemGroup>
<ItemGroup>
<ReferenceFromRuntime Include="System.Private.CoreLib" />
<!-- Causes us to use project references to avoid duplicate definitions that the ref assemblies would give us -->
<ProjectReference Include="..\..\System.Diagnostics.Tools\src\System.Diagnostics.Tools.csproj" />
<ProjectReference Include="..\..\System.Collections\src\System.Collections.csproj" />
<ProjectReference Include="..\..\System.Runtime\src\System.Runtime.csproj" />
<ProjectReference Include="..\..\System.Diagnostics.Tools\src\System.Diagnostics.Tools.csproj" />
<ProjectReference Include="..\..\System.Runtime.Extensions\src\System.Runtime.Extensions.csproj" />
<ProjectReference Include="..\..\System.ObjectModel\src\System.ObjectModel.csproj" />
<ProjectReference Include="..\..\System.Reflection.Primitives\src\System.Reflection.Primitives.csproj" />
<ProjectReference Include="..\..\System.Linq\src\System.Linq.csproj" />
</ItemGroup>
<ItemGroup Condition="'$(TargetGroup)' != 'uapaot'">
<Reference Include="System.Collections" />
<Reference Include="System.Diagnostics.Contracts" />
<Reference Include="System.Diagnostics.Debug" />
<Reference Include="System.Diagnostics.Tools" />
<Reference Include="System.Linq" />
<Reference Include="System.ObjectModel" />
<Reference Include="System.Reflection.Emit" />
<Reference Include="System.Reflection.Emit.ILGeneration" />
<Reference Include="System.Reflection.Emit.Lightweight" />
<Reference Include="System.Reflection.Primitives" />
<Reference Include="System.Resources.ResourceManager" />
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.Extensions" />
<Reference Include="System.Threading" />
</ItemGroup>
<ItemGroup>
<Compile Include="$(CommonPath)\System\Collections\Generic\ArrayBuilder.cs">
<Link>Common\System\Collections\Generic\ArrayBuilder.cs</Link>
@@ -261,4 +245,4 @@
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
</Project>
</Project>

View File

@@ -20,19 +20,19 @@ namespace System.Dynamic
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix")]
public sealed class ExpandoObject : IDynamicMetaObjectProvider, IDictionary<string, object>, INotifyPropertyChanged
{
private static readonly MethodInfo ExpandoTryGetValue =
private static readonly MethodInfo s_expandoTryGetValue =
typeof(RuntimeOps).GetMethod(nameof(RuntimeOps.ExpandoTryGetValue));
private static readonly MethodInfo ExpandoTrySetValue =
private static readonly MethodInfo s_expandoTrySetValue =
typeof(RuntimeOps).GetMethod(nameof(RuntimeOps.ExpandoTrySetValue));
private static readonly MethodInfo ExpandoTryDeleteValue =
private static readonly MethodInfo s_expandoTryDeleteValue =
typeof(RuntimeOps).GetMethod(nameof(RuntimeOps.ExpandoTryDeleteValue));
private static readonly MethodInfo ExpandoPromoteClass =
private static readonly MethodInfo s_expandoPromoteClass =
typeof(RuntimeOps).GetMethod(nameof(RuntimeOps.ExpandoPromoteClass));
private static readonly MethodInfo ExpandoCheckVersion =
private static readonly MethodInfo s_expandoCheckVersion =
typeof(RuntimeOps).GetMethod(nameof(RuntimeOps.ExpandoCheckVersion));
internal readonly object LockObject; // the read-only field is used for locking the Expando object
@@ -793,7 +793,7 @@ namespace System.Dynamic
ParameterExpression value = Expression.Parameter(typeof(object), "value");
Expression tryGetValue = Expression.Call(
ExpandoTryGetValue,
s_expandoTryGetValue,
GetLimitedSelf(),
Expression.Constant(klass, typeof(object)),
AstUtils.Constant(index),
@@ -866,7 +866,7 @@ namespace System.Dynamic
originalClass,
new DynamicMetaObject(
Expression.Call(
ExpandoTrySetValue,
s_expandoTrySetValue,
GetLimitedSelf(),
Expression.Constant(klass, typeof(object)),
AstUtils.Constant(index),
@@ -886,7 +886,7 @@ namespace System.Dynamic
int index = Value.Class.GetValueIndex(binder.Name, binder.IgnoreCase, Value);
Expression tryDelete = Expression.Call(
ExpandoTryDeleteValue,
s_expandoTryDeleteValue,
GetLimitedSelf(),
Expression.Constant(Value.Class, typeof(object)),
AstUtils.Constant(index),
@@ -935,7 +935,7 @@ namespace System.Dynamic
ifTestSucceeds = Expression.Block(
Expression.Call(
null,
ExpandoPromoteClass,
s_expandoPromoteClass,
GetLimitedSelf(),
Expression.Constant(originalClass, typeof(object)),
Expression.Constant(klass, typeof(object))
@@ -948,7 +948,7 @@ namespace System.Dynamic
Expression.Condition(
Expression.Call(
null,
ExpandoCheckVersion,
s_expandoCheckVersion,
GetLimitedSelf(),
Expression.Constant(originalClass ?? klass, typeof(object))
),

View File

@@ -9,149 +9,6 @@ namespace System.Dynamic
internal static partial class UpdateDelegates
{
#if FEATURE_COMPILE
[Obsolete("pregenerated CallSite<T>.Update delegate", error: true)]
internal static TRet UpdateAndExecute0<TRet>(CallSite site)
{
//
// Declare the locals here upfront. It actually saves JIT stack space.
//
var @this = (CallSite<Func<CallSite, TRet>>)site;
Func<CallSite, TRet>[] applicable;
Func<CallSite, TRet> rule, originalRule = @this.Target;
TRet result;
//
// Create matchmaker and its site. We'll need them regardless.
//
site = CallSiteOps.CreateMatchmaker(@this);
//
// Level 1 cache lookup
//
if ((applicable = CallSiteOps.GetRules(@this)) != null)
{
for (int i = 0; i < applicable.Length; i++)
{
rule = applicable[i];
//
// Execute the rule
//
// if we've already tried it skip it...
if ((object)rule != (object)originalRule)
{
@this.Target = rule;
result = rule(site);
if (CallSiteOps.GetMatch(site))
{
CallSiteOps.UpdateRules(@this, i);
return result;
}
// Rule didn't match, try the next one
CallSiteOps.ClearMatch(site);
}
}
}
//
// Level 2 cache lookup
//
//
// Any applicable rules in level 2 cache?
//
var cache = CallSiteOps.GetRuleCache(@this);
applicable = cache.GetRules();
for (int i = 0; i < applicable.Length; i++)
{
rule = applicable[i];
//
// Execute the rule
//
@this.Target = rule;
try
{
result = rule(site);
if (CallSiteOps.GetMatch(site))
{
return result;
}
}
finally
{
if (CallSiteOps.GetMatch(site))
{
//
// Rule worked. Add it to level 1 cache
//
CallSiteOps.AddRule(@this, rule);
// and then move it to the front of the L2 cache
CallSiteOps.MoveRule(cache, rule, i);
}
}
// Rule didn't match, try the next one
CallSiteOps.ClearMatch(site);
}
//
// Miss on Level 0, 1 and 2 caches. Create new rule
//
rule = null;
var args = Array.Empty<object>();
for (; ; )
{
@this.Target = originalRule;
rule = @this.Target = @this.Binder.BindCore(@this, args);
//
// Execute the rule on the matchmaker site
//
try
{
result = rule(site);
if (CallSiteOps.GetMatch(site))
{
return result;
}
}
finally
{
if (CallSiteOps.GetMatch(site))
{
//
// The rule worked. Add it to level 1 cache.
//
CallSiteOps.AddRule(@this, rule);
}
}
// Rule we got back didn't work, try another one
CallSiteOps.ClearMatch(site);
}
}
[Obsolete("pregenerated CallSite<T>.Update delegate", error: true)]
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters")]
internal static TRet NoMatch0<TRet>(CallSite site)
{
site._match = false;
return default(TRet);
}
[Obsolete("pregenerated CallSite<T>.Update delegate", error: true)]
internal static TRet UpdateAndExecute1<T0, TRet>(CallSite site, T0 arg0)
{

View File

@@ -16,7 +16,7 @@ namespace System.Dynamic
{
#if FEATURE_COMPILE
<#
for (int i = 0; i <= 10; i++)
for (int i = 1; i <= 10; i++)
{
string genericParameters = string.Join(", ", Enumerable.Range(0, i).Select(j => "T" + j).Concat(new[] { "TRet" }));
string parameters = string.Join(", ", new[] { "CallSite site" }.Concat(Enumerable.Range(0, i).Select(j => "T" + j + " arg" + j)));

View File

@@ -11,127 +11,127 @@ namespace System.Linq.Expressions
internal static partial class CachedReflectionInfo
{
private static MethodInfo s_String_Format_String_ObjectArray;
public static MethodInfo String_Format_String_ObjectArray =>
public static MethodInfo String_Format_String_ObjectArray =>
s_String_Format_String_ObjectArray ??
(s_String_Format_String_ObjectArray = typeof(string).GetMethod(nameof(string.Format), new Type[] { typeof(string), typeof(object[]) }));
private static ConstructorInfo s_InvalidCastException_Ctor_String;
public static ConstructorInfo InvalidCastException_Ctor_String =>
public static ConstructorInfo InvalidCastException_Ctor_String =>
s_InvalidCastException_Ctor_String ??
(s_InvalidCastException_Ctor_String = typeof(InvalidCastException).GetConstructor(new Type[] { typeof(string) }));
private static MethodInfo s_CallSiteOps_SetNotMatched;
public static MethodInfo CallSiteOps_SetNotMatched =>
public static MethodInfo CallSiteOps_SetNotMatched =>
s_CallSiteOps_SetNotMatched ??
(s_CallSiteOps_SetNotMatched = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.SetNotMatched)));
private static MethodInfo s_CallSiteOps_CreateMatchmaker;
public static MethodInfo CallSiteOps_CreateMatchmaker =>
public static MethodInfo CallSiteOps_CreateMatchmaker =>
s_CallSiteOps_CreateMatchmaker ??
(s_CallSiteOps_CreateMatchmaker = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.CreateMatchmaker)));
private static MethodInfo s_CallSiteOps_GetMatch;
public static MethodInfo CallSiteOps_GetMatch =>
public static MethodInfo CallSiteOps_GetMatch =>
s_CallSiteOps_GetMatch ??
(s_CallSiteOps_GetMatch = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.GetMatch)));
private static MethodInfo s_CallSiteOps_ClearMatch;
public static MethodInfo CallSiteOps_ClearMatch =>
public static MethodInfo CallSiteOps_ClearMatch =>
s_CallSiteOps_ClearMatch ??
(s_CallSiteOps_ClearMatch = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.ClearMatch)));
private static MethodInfo s_CallSiteOps_UpdateRules;
public static MethodInfo CallSiteOps_UpdateRules =>
public static MethodInfo CallSiteOps_UpdateRules =>
s_CallSiteOps_UpdateRules ??
(s_CallSiteOps_UpdateRules = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.UpdateRules)));
private static MethodInfo s_CallSiteOps_GetRules;
public static MethodInfo CallSiteOps_GetRules =>
public static MethodInfo CallSiteOps_GetRules =>
s_CallSiteOps_GetRules ??
(s_CallSiteOps_GetRules = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.GetRules)));
private static MethodInfo s_CallSiteOps_GetRuleCache;
public static MethodInfo CallSiteOps_GetRuleCache =>
public static MethodInfo CallSiteOps_GetRuleCache =>
s_CallSiteOps_GetRuleCache ??
(s_CallSiteOps_GetRuleCache = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.GetRuleCache)));
private static MethodInfo s_CallSiteOps_GetCachedRules;
public static MethodInfo CallSiteOps_GetCachedRules =>
public static MethodInfo CallSiteOps_GetCachedRules =>
s_CallSiteOps_GetCachedRules ??
(s_CallSiteOps_GetCachedRules = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.GetCachedRules)));
private static MethodInfo s_CallSiteOps_AddRule;
public static MethodInfo CallSiteOps_AddRule =>
public static MethodInfo CallSiteOps_AddRule =>
s_CallSiteOps_AddRule ??
(s_CallSiteOps_AddRule = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.AddRule)));
private static MethodInfo s_CallSiteOps_MoveRule;
public static MethodInfo CallSiteOps_MoveRule =>
public static MethodInfo CallSiteOps_MoveRule =>
s_CallSiteOps_MoveRule ??
(s_CallSiteOps_MoveRule = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.MoveRule)));
private static MethodInfo s_CallSiteOps_Bind;
public static MethodInfo CallSiteOps_Bind =>
public static MethodInfo CallSiteOps_Bind =>
s_CallSiteOps_Bind ??
(s_CallSiteOps_Bind = typeof(CallSiteOps).GetMethod(nameof(CallSiteOps.Bind)));
private static MethodInfo s_DynamicObject_TryGetMember;
public static MethodInfo DynamicObject_TryGetMember =>
public static MethodInfo DynamicObject_TryGetMember =>
s_DynamicObject_TryGetMember ??
(s_DynamicObject_TryGetMember = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TryGetMember)));
private static MethodInfo s_DynamicObject_TrySetMember;
public static MethodInfo DynamicObject_TrySetMember =>
public static MethodInfo DynamicObject_TrySetMember =>
s_DynamicObject_TrySetMember ??
(s_DynamicObject_TrySetMember = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TrySetMember)));
private static MethodInfo s_DynamicObject_TryDeleteMember;
public static MethodInfo DynamicObject_TryDeleteMember =>
public static MethodInfo DynamicObject_TryDeleteMember =>
s_DynamicObject_TryDeleteMember ??
(s_DynamicObject_TryDeleteMember = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TryDeleteMember)));
private static MethodInfo s_DynamicObject_TryGetIndex;
public static MethodInfo DynamicObject_TryGetIndex =>
public static MethodInfo DynamicObject_TryGetIndex =>
s_DynamicObject_TryGetIndex ??
(s_DynamicObject_TryGetIndex = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TryGetIndex)));
private static MethodInfo s_DynamicObject_TrySetIndex;
public static MethodInfo DynamicObject_TrySetIndex =>
public static MethodInfo DynamicObject_TrySetIndex =>
s_DynamicObject_TrySetIndex ??
(s_DynamicObject_TrySetIndex = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TrySetIndex)));
private static MethodInfo s_DynamicObject_TryDeleteIndex;
public static MethodInfo DynamicObject_TryDeleteIndex =>
public static MethodInfo DynamicObject_TryDeleteIndex =>
s_DynamicObject_TryDeleteIndex ??
(s_DynamicObject_TryDeleteIndex = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TryDeleteIndex)));
private static MethodInfo s_DynamicObject_TryConvert;
public static MethodInfo DynamicObject_TryConvert =>
public static MethodInfo DynamicObject_TryConvert =>
s_DynamicObject_TryConvert ??
(s_DynamicObject_TryConvert = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TryConvert)));
private static MethodInfo s_DynamicObject_TryInvoke;
public static MethodInfo DynamicObject_TryInvoke =>
public static MethodInfo DynamicObject_TryInvoke =>
s_DynamicObject_TryInvoke ??
(s_DynamicObject_TryInvoke = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TryInvoke)));
private static MethodInfo s_DynamicObject_TryInvokeMember;
public static MethodInfo DynamicObject_TryInvokeMember =>
public static MethodInfo DynamicObject_TryInvokeMember =>
s_DynamicObject_TryInvokeMember ??
(s_DynamicObject_TryInvokeMember = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TryInvokeMember)));
private static MethodInfo s_DynamicObject_TryBinaryOperation;
public static MethodInfo DynamicObject_TryBinaryOperation =>
public static MethodInfo DynamicObject_TryBinaryOperation =>
s_DynamicObject_TryBinaryOperation ??
(s_DynamicObject_TryBinaryOperation = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TryBinaryOperation)));
private static MethodInfo s_DynamicObject_TryUnaryOperation;
public static MethodInfo DynamicObject_TryUnaryOperation =>
public static MethodInfo DynamicObject_TryUnaryOperation =>
s_DynamicObject_TryUnaryOperation ??
(s_DynamicObject_TryUnaryOperation = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TryUnaryOperation)));
private static MethodInfo s_DynamicObject_TryCreateInstance;
public static MethodInfo DynamicObject_TryCreateInstance =>
public static MethodInfo DynamicObject_TryCreateInstance =>
s_DynamicObject_TryCreateInstance ??
(s_DynamicObject_TryCreateInstance = typeof(DynamicObject).GetMethod(nameof(DynamicObject.TryCreateInstance)));
}

View File

@@ -152,6 +152,5 @@ namespace System.Dynamic.Utils
}
#endif
}
}

View File

@@ -314,5 +314,13 @@ namespace System.Dynamic.Utils
return true;
}
public static void ValidateArgumentCount(this LambdaExpression lambda)
{
if (((IParameterProvider)lambda).ParameterCount >= ushort.MaxValue)
{
throw Error.InvalidProgram();
}
}
}
}

View File

@@ -68,9 +68,7 @@ namespace System.Dynamic.Utils
if (!pic.TryGetValue(method, out ParameterInfo[] pis))
{
pis = method.GetParameters();
Type t = method.DeclaringType;
if (t != null && t.CanCache())
if (method.DeclaringType?.IsCollectible == false)
{
pic[method] = pis;
}

View File

@@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
@@ -10,6 +11,11 @@ namespace System.Dynamic.Utils
{
internal static class TypeUtils
{
private static readonly Type[] s_arrayAssignableInterfaces = typeof(int[]).GetInterfaces()
.Where(i => i.IsGenericType)
.Select(i => i.GetGenericTypeDefinition())
.ToArray();
public static Type GetNonNullableType(this Type type) => IsNullableType(type) ? type.GetGenericArguments()[0] : type;
public static Type GetNullableType(this Type type)
@@ -231,7 +237,7 @@ namespace System.Dynamic.Utils
// nonbool==>bool and nonbool==>bool? which are only legal from
// bool-backed enums.
return IsConvertible(source) && IsConvertible(dest)
&& (GetNonNullableType(dest) != typeof(bool)
&& (GetNonNullableType(dest) != typeof(bool)
|| source.IsEnum && source.GetEnumUnderlyingType() == typeof(bool));
}
@@ -274,8 +280,139 @@ namespace System.Dynamic.Utils
return true;
}
// Object conversion
return source == typeof(object) || dest == typeof(object);
// Object conversion handled by assignable above.
Debug.Assert(source != typeof(object) && dest != typeof(object));
return (source.IsArray || dest.IsArray) && StrictHasReferenceConversionTo(source, dest, true);
}
private static bool StrictHasReferenceConversionTo(this Type source, Type dest, bool skipNonArray)
{
// HasReferenceConversionTo was both too strict and too lax. It was too strict in prohibiting
// some valid conversions involving arrays, and too lax in allowing casts between interfaces
// and sealed classes that don't implement them. Unfortunately fixing the lax cases would be
// a breaking change, especially since such expressions will even work if only given null
// arguments.
// This method catches the cases that were incorrectly disallowed, but when it needs to
// examine possible conversions of element or type parameters it applies stricter rules.
for(;;)
{
if (!skipNonArray) // Skip if we just came from HasReferenceConversionTo and have just tested these
{
if (source.IsValueType | dest.IsValueType)
{
return false;
}
// Includes to case of either being typeof(object)
if (source.IsAssignableFrom(dest) || dest.IsAssignableFrom(source))
{
return true;
}
if (source.IsInterface)
{
if (dest.IsInterface || dest.IsClass && !dest.IsSealed)
{
return true;
}
}
else if (dest.IsInterface)
{
if (source.IsClass && !source.IsSealed)
{
return true;
}
}
}
if (source.IsArray)
{
if (dest.IsArray)
{
if (source.GetArrayRank() != dest.GetArrayRank() || source.IsSZArray != dest.IsSZArray)
{
return false;
}
source = source.GetElementType();
dest = dest.GetElementType();
skipNonArray = false;
}
else
{
return HasArrayToInterfaceConversion(source, dest);
}
}
else if (dest.IsArray)
{
if (HasInterfaceToArrayConversion(source, dest))
{
return true;
}
return IsImplicitReferenceConversion(typeof(Array), source);
}
else
{
return IsLegalExplicitVariantDelegateConversion(source, dest);
}
}
}
private static bool HasArrayToInterfaceConversion(Type source, Type dest)
{
Debug.Assert(source.IsArray);
if (!source.IsSZArray || !dest.IsInterface || !dest.IsGenericType)
{
return false;
}
Type[] destParams = dest.GetGenericArguments();
if (destParams.Length != 1)
{
return false;
}
Type destGen = dest.GetGenericTypeDefinition();
foreach (Type iface in s_arrayAssignableInterfaces)
{
if (AreEquivalent(destGen, iface))
{
return StrictHasReferenceConversionTo(source.GetElementType(), destParams[0], false);
}
}
return false;
}
private static bool HasInterfaceToArrayConversion(Type source, Type dest)
{
Debug.Assert(dest.IsSZArray);
if (!dest.IsSZArray || !source.IsInterface || !source.IsGenericType)
{
return false;
}
Type[] sourceParams = source.GetGenericArguments();
if (sourceParams.Length != 1)
{
return false;
}
Type sourceGen = source.GetGenericTypeDefinition();
foreach (Type iface in s_arrayAssignableInterfaces)
{
if (AreEquivalent(sourceGen, iface))
{
return StrictHasReferenceConversionTo(sourceParams[0], dest.GetElementType(), false);
}
}
return false;
}
private static bool IsCovariant(Type t)
@@ -689,7 +826,7 @@ namespace System.Dynamic.Utils
{
do
{
MethodInfo result = type.GetAnyStaticMethodValidated(name, new[] {type});
MethodInfo result = type.GetAnyStaticMethodValidated(name, new[] { type });
if (result != null && result.IsSpecialName && !result.ContainsGenericParameters)
{
return result;
@@ -727,12 +864,12 @@ namespace System.Dynamic.Utils
{
if (!allowByRef && type.IsByRef)
{
throw Error.TypeMustNotBeByRef(paramName);
throw System.Linq.Expressions.Error.TypeMustNotBeByRef(paramName);
}
if (!allowPointer && type.IsPointer)
{
throw Error.TypeMustNotBePointer(paramName);
throw System.Linq.Expressions.Error.TypeMustNotBePointer(paramName);
}
}
}
@@ -747,48 +884,8 @@ namespace System.Dynamic.Utils
if (type.ContainsGenericParameters)
{
throw type.IsGenericTypeDefinition
? Error.TypeIsGeneric(type, paramName, index)
: Error.TypeContainsGenericParameters(type, paramName, index);
}
return true;
}
private static Assembly s_mscorlib;
private static Assembly MsCorLib => s_mscorlib ?? (s_mscorlib = typeof(object).Assembly);
/// <summary>
/// We can cache references to types, as long as they aren't in
/// collectible assemblies. Unfortunately, we can't really distinguish
/// between different flavors of assemblies. But, we can at least
/// create a cache for types in mscorlib (so we get the primitives, etc).
/// </summary>
public static bool CanCache(this Type t)
{
// Note: we don't have to scan base or declaring types here.
// There's no way for a type in mscorlib to derive from or be
// contained in a type from another assembly. The only thing we
// need to look at is the generic arguments, which are the thing
// that allows mscorlib types to be specialized by types in other
// assemblies.
Assembly asm = t.Assembly;
if (asm != MsCorLib)
{
// Not in mscorlib or our assembly
return false;
}
if (t.IsGenericType)
{
foreach (Type g in t.GetGenericArguments())
{
if (!g.CanCache())
{
return false;
}
}
? System.Linq.Expressions.Error.TypeIsGeneric(type, paramName, index)
: System.Linq.Expressions.Error.TypeContainsGenericParameters(type, paramName, index);
}
return true;
@@ -836,6 +933,5 @@ namespace System.Dynamic.Utils
}
#endif
}
}

View File

@@ -13,30 +13,30 @@ namespace System.Linq.Expressions
private static ConstructorInfo s_Nullable_Boolean_Ctor;
public static ConstructorInfo Nullable_Boolean_Ctor
=> s_Nullable_Boolean_Ctor ?? (s_Nullable_Boolean_Ctor = typeof(bool?).GetConstructor(new[] {typeof(bool)}));
=> s_Nullable_Boolean_Ctor ?? (s_Nullable_Boolean_Ctor = typeof(bool?).GetConstructor(new[] { typeof(bool) }));
private static ConstructorInfo s_Decimal_Ctor_Int32;
public static ConstructorInfo Decimal_Ctor_Int32 =>
public static ConstructorInfo Decimal_Ctor_Int32 =>
s_Decimal_Ctor_Int32 ??
(s_Decimal_Ctor_Int32 = typeof(decimal).GetConstructor(new[] { typeof(int) }));
private static ConstructorInfo s_Decimal_Ctor_UInt32;
public static ConstructorInfo Decimal_Ctor_UInt32 =>
public static ConstructorInfo Decimal_Ctor_UInt32 =>
s_Decimal_Ctor_UInt32 ??
(s_Decimal_Ctor_UInt32 = typeof(decimal).GetConstructor(new[] { typeof(uint) }));
private static ConstructorInfo s_Decimal_Ctor_Int64;
public static ConstructorInfo Decimal_Ctor_Int64 =>
public static ConstructorInfo Decimal_Ctor_Int64 =>
s_Decimal_Ctor_Int64 ??
(s_Decimal_Ctor_Int64 = typeof(decimal).GetConstructor(new[] { typeof(long) }));
private static ConstructorInfo s_Decimal_Ctor_UInt64;
public static ConstructorInfo Decimal_Ctor_UInt64 =>
public static ConstructorInfo Decimal_Ctor_UInt64 =>
s_Decimal_Ctor_UInt64 ??
(s_Decimal_Ctor_UInt64 = typeof(decimal).GetConstructor(new[] { typeof(ulong) }));
private static ConstructorInfo s_Decimal_Ctor_Int32_Int32_Int32_Bool_Byte;
public static ConstructorInfo Decimal_Ctor_Int32_Int32_Int32_Bool_Byte =>
public static ConstructorInfo Decimal_Ctor_Int32_Int32_Int32_Bool_Byte =>
s_Decimal_Ctor_Int32_Int32_Int32_Bool_Byte ??
(s_Decimal_Ctor_Int32_Int32_Int32_Bool_Byte = typeof(decimal).GetConstructor(new[] { typeof(int), typeof(int), typeof(int), typeof(bool), typeof(byte) }));
@@ -65,97 +65,97 @@ namespace System.Linq.Expressions
=> s_DateTime_MinValue ?? (s_DateTime_MinValue = typeof(DateTime).GetField(nameof(DateTime.MinValue)));
private static MethodInfo s_MethodBase_GetMethodFromHandle_RuntimeMethodHandle;
public static MethodInfo MethodBase_GetMethodFromHandle_RuntimeMethodHandle =>
public static MethodInfo MethodBase_GetMethodFromHandle_RuntimeMethodHandle =>
s_MethodBase_GetMethodFromHandle_RuntimeMethodHandle ??
(s_MethodBase_GetMethodFromHandle_RuntimeMethodHandle = typeof(MethodBase).GetMethod(nameof(MethodBase.GetMethodFromHandle), new[] { typeof(RuntimeMethodHandle) }));
private static MethodInfo s_MethodBase_GetMethodFromHandle_RuntimeMethodHandle_RuntimeTypeHandle;
public static MethodInfo MethodBase_GetMethodFromHandle_RuntimeMethodHandle_RuntimeTypeHandle =>
public static MethodInfo MethodBase_GetMethodFromHandle_RuntimeMethodHandle_RuntimeTypeHandle =>
s_MethodBase_GetMethodFromHandle_RuntimeMethodHandle_RuntimeTypeHandle ??
(s_MethodBase_GetMethodFromHandle_RuntimeMethodHandle_RuntimeTypeHandle = typeof(MethodBase).GetMethod(nameof(MethodBase.GetMethodFromHandle), new[] { typeof(RuntimeMethodHandle), typeof(RuntimeTypeHandle) }));
private static MethodInfo s_MethodInfo_CreateDelegate_Type_Object;
public static MethodInfo MethodInfo_CreateDelegate_Type_Object =>
public static MethodInfo MethodInfo_CreateDelegate_Type_Object =>
s_MethodInfo_CreateDelegate_Type_Object ??
(s_MethodInfo_CreateDelegate_Type_Object = typeof(MethodInfo).GetMethod(nameof(MethodInfo.CreateDelegate), new[] { typeof(Type), typeof(object) }));
private static MethodInfo s_String_op_Equality_String_String;
public static MethodInfo String_op_Equality_String_String =>
public static MethodInfo String_op_Equality_String_String =>
s_String_op_Equality_String_String ??
(s_String_op_Equality_String_String = typeof(string).GetMethod("op_Equality", new[] { typeof(string), typeof(string) }));
private static MethodInfo s_String_Equals_String_String;
public static MethodInfo String_Equals_String_String =>
public static MethodInfo String_Equals_String_String =>
s_String_Equals_String_String ??
(s_String_Equals_String_String = typeof(string).GetMethod("Equals", new[] { typeof(string), typeof(string) }));
private static MethodInfo s_DictionaryOfStringInt32_Add_String_Int32;
public static MethodInfo DictionaryOfStringInt32_Add_String_Int32 =>
public static MethodInfo DictionaryOfStringInt32_Add_String_Int32 =>
s_DictionaryOfStringInt32_Add_String_Int32 ??
(s_DictionaryOfStringInt32_Add_String_Int32 = typeof(Dictionary<string, int>).GetMethod(nameof(Dictionary<string, int>.Add), new[] { typeof(string), typeof(int) }));
private static ConstructorInfo s_DictionaryOfStringInt32_Ctor_Int32;
public static ConstructorInfo DictionaryOfStringInt32_Ctor_Int32 =>
public static ConstructorInfo DictionaryOfStringInt32_Ctor_Int32 =>
s_DictionaryOfStringInt32_Ctor_Int32 ??
(s_DictionaryOfStringInt32_Ctor_Int32 = typeof(Dictionary<string, int>).GetConstructor(new[] { typeof(int) }));
private static MethodInfo s_Type_GetTypeFromHandle;
public static MethodInfo Type_GetTypeFromHandle =>
public static MethodInfo Type_GetTypeFromHandle =>
s_Type_GetTypeFromHandle ??
(s_Type_GetTypeFromHandle = typeof(Type).GetMethod(nameof(Type.GetTypeFromHandle)));
private static MethodInfo s_Object_GetType;
public static MethodInfo Object_GetType =>
public static MethodInfo Object_GetType =>
s_Object_GetType ??
(s_Object_GetType = typeof(object).GetMethod(nameof(object.GetType)));
private static MethodInfo s_Decimal_op_Implicit_Byte;
public static MethodInfo Decimal_op_Implicit_Byte =>
public static MethodInfo Decimal_op_Implicit_Byte =>
s_Decimal_op_Implicit_Byte ??
(s_Decimal_op_Implicit_Byte = typeof(decimal).GetMethod("op_Implicit", new[] { typeof(byte) }));
private static MethodInfo s_Decimal_op_Implicit_SByte;
public static MethodInfo Decimal_op_Implicit_SByte =>
public static MethodInfo Decimal_op_Implicit_SByte =>
s_Decimal_op_Implicit_SByte ??
(s_Decimal_op_Implicit_SByte = typeof(decimal).GetMethod("op_Implicit", new[] { typeof(sbyte) }));
private static MethodInfo s_Decimal_op_Implicit_Int16;
public static MethodInfo Decimal_op_Implicit_Int16 =>
public static MethodInfo Decimal_op_Implicit_Int16 =>
s_Decimal_op_Implicit_Int16 ??
(s_Decimal_op_Implicit_Int16 = typeof(decimal).GetMethod("op_Implicit", new[] { typeof(short) }));
private static MethodInfo s_Decimal_op_Implicit_UInt16;
public static MethodInfo Decimal_op_Implicit_UInt16 =>
public static MethodInfo Decimal_op_Implicit_UInt16 =>
s_Decimal_op_Implicit_UInt16 ??
(s_Decimal_op_Implicit_UInt16 = typeof(decimal).GetMethod("op_Implicit", new[] { typeof(ushort) }));
private static MethodInfo s_Decimal_op_Implicit_Int32;
public static MethodInfo Decimal_op_Implicit_Int32 =>
public static MethodInfo Decimal_op_Implicit_Int32 =>
s_Decimal_op_Implicit_Int32 ??
(s_Decimal_op_Implicit_Int32 = typeof(decimal).GetMethod("op_Implicit", new[] { typeof(int) }));
private static MethodInfo s_Decimal_op_Implicit_UInt32;
public static MethodInfo Decimal_op_Implicit_UInt32 =>
public static MethodInfo Decimal_op_Implicit_UInt32 =>
s_Decimal_op_Implicit_UInt32 ??
(s_Decimal_op_Implicit_UInt32 = typeof(decimal).GetMethod("op_Implicit", new[] { typeof(uint) }));
private static MethodInfo s_Decimal_op_Implicit_Int64;
public static MethodInfo Decimal_op_Implicit_Int64 =>
public static MethodInfo Decimal_op_Implicit_Int64 =>
s_Decimal_op_Implicit_Int64 ??
(s_Decimal_op_Implicit_Int64 = typeof(decimal).GetMethod("op_Implicit", new[] { typeof(long) }));
private static MethodInfo s_Decimal_op_Implicit_UInt64;
public static MethodInfo Decimal_op_Implicit_UInt64 =>
public static MethodInfo Decimal_op_Implicit_UInt64 =>
s_Decimal_op_Implicit_UInt64 ??
(s_Decimal_op_Implicit_UInt64 = typeof(decimal).GetMethod("op_Implicit", new[] { typeof(ulong) }));
private static MethodInfo s_Decimal_op_Implicit_Char;
public static MethodInfo Decimal_op_Implicit_Char =>
public static MethodInfo Decimal_op_Implicit_Char =>
s_Decimal_op_Implicit_Char ??
(s_Decimal_op_Implicit_Char = typeof(decimal).GetMethod("op_Implicit", new[] { typeof(char) }));
private static MethodInfo s_Math_Pow_Double_Double;
public static MethodInfo Math_Pow_Double_Double =>
public static MethodInfo Math_Pow_Double_Double =>
s_Math_Pow_Double_Double ??
(s_Math_Pow_Double_Double = typeof(Math).GetMethod(nameof(Math.Pow), new[] { typeof(double), typeof(double) }));

View File

@@ -35,12 +35,7 @@ namespace System.Linq.Expressions.Compiler
{
var name = new AssemblyName("Snippets");
// mark the assembly transparent so that it works in partial trust:
CustomAttributeBuilder[] attributes = new[] {
new CustomAttributeBuilder(typeof(SecurityTransparentAttribute).GetConstructor(Type.EmptyTypes), Array.Empty<object>())
};
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run, attributes);
AssemblyBuilder myAssembly = AssemblyBuilder.DefineDynamicAssembly(name, AssemblyBuilderAccess.Run);
_myModule = myAssembly.DefineDynamicModule(name.Name);
}

View File

@@ -24,7 +24,7 @@ namespace System.Linq.Expressions.Compiler
/// ends up using a JIT temp and defeats the purpose of caching the
/// value in a local)
/// </summary>
private struct TypedConstant : IEquatable<TypedConstant>
private readonly struct TypedConstant : IEquatable<TypedConstant>
{
internal readonly object Value;
internal readonly Type Type;

View File

@@ -76,11 +76,12 @@ namespace System.Linq.Expressions.Compiler
if (!curTypeInfo.TypeChain.TryGetValue(lookingUp, out nextTypeInfo))
{
nextTypeInfo = new TypeInfo();
if (lookingUp.CanCache())
if (!lookingUp.IsCollectible)
{
curTypeInfo.TypeChain[lookingUp] = nextTypeInfo;
}
}
return nextTypeInfo;
}

View File

@@ -9,7 +9,6 @@ using System.Dynamic.Utils;
namespace System.Linq.Expressions.Compiler
{
// Suppose we have something like:
//
// (string s)=>()=>s.

View File

@@ -32,6 +32,7 @@ namespace System.Linq.Expressions.Compiler
internal static void EmitLoadArg(this ILGenerator il, int index)
{
Debug.Assert(index >= 0);
Debug.Assert(index < ushort.MaxValue);
switch (index)
{
@@ -54,7 +55,8 @@ namespace System.Linq.Expressions.Compiler
}
else
{
il.Emit(OpCodes.Ldarg, index);
// cast to short, result is correct ushort.
il.Emit(OpCodes.Ldarg, (short)index);
}
break;
}
@@ -63,6 +65,7 @@ namespace System.Linq.Expressions.Compiler
internal static void EmitLoadArgAddress(this ILGenerator il, int index)
{
Debug.Assert(index >= 0);
Debug.Assert(index < ushort.MaxValue);
if (index <= byte.MaxValue)
{
@@ -70,13 +73,15 @@ namespace System.Linq.Expressions.Compiler
}
else
{
il.Emit(OpCodes.Ldarga, index);
// cast to short, result is correct ushort.
il.Emit(OpCodes.Ldarga, (short)index);
}
}
internal static void EmitStoreArg(this ILGenerator il, int index)
{
Debug.Assert(index >= 0);
Debug.Assert(index < ushort.MaxValue);
if (index <= byte.MaxValue)
{
@@ -84,7 +89,8 @@ namespace System.Linq.Expressions.Compiler
}
else
{
il.Emit(OpCodes.Starg, index);
// cast to short, result is correct ushort.
il.Emit(OpCodes.Starg, (short)index);
}
}
@@ -737,15 +743,15 @@ namespace System.Linq.Expressions.Compiler
switch (tf)
{
case TypeCode.Byte: method = Decimal_op_Implicit_Byte; break;
case TypeCode.SByte: method = Decimal_op_Implicit_SByte; break;
case TypeCode.Int16: method = Decimal_op_Implicit_Int16; break;
case TypeCode.Byte: method = Decimal_op_Implicit_Byte; break;
case TypeCode.SByte: method = Decimal_op_Implicit_SByte; break;
case TypeCode.Int16: method = Decimal_op_Implicit_Int16; break;
case TypeCode.UInt16: method = Decimal_op_Implicit_UInt16; break;
case TypeCode.Int32: method = Decimal_op_Implicit_Int32; break;
case TypeCode.Int32: method = Decimal_op_Implicit_Int32; break;
case TypeCode.UInt32: method = Decimal_op_Implicit_UInt32; break;
case TypeCode.Int64: method = Decimal_op_Implicit_Int64; break;
case TypeCode.Int64: method = Decimal_op_Implicit_Int64; break;
case TypeCode.UInt64: method = Decimal_op_Implicit_UInt64; break;
case TypeCode.Char: method = Decimal_op_Implicit_Char; break;
case TypeCode.Char: method = Decimal_op_Implicit_Char; break;
default:
throw ContractUtils.Unreachable;
}

View File

@@ -117,7 +117,7 @@ namespace System.Linq.Expressions.Compiler
Debug.Assert(TypeUtils.AreReferenceAssignable(p1.Type, b.Left.Type.GetNonNullableType()));
Debug.Assert(TypeUtils.AreReferenceAssignable(p2.Type, b.Right.Type.GetNonNullableType()));
EmitLift(b.NodeType, resultType, mc, new[] {p1, p2}, new[] {b.Left, b.Right});
EmitLift(b.NodeType, resultType, mc, new[] { p1, p2 }, new[] { b.Left, b.Right });
}
else
{

Some files were not shown because too many files have changed in this diff Show More