Skip to content

Commit

Permalink
Delete reflection-free mode (dotnet#109857)
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalStrehovsky authored Nov 15, 2024
1 parent c20fe5f commit fe0803f
Show file tree
Hide file tree
Showing 19 changed files with 6 additions and 550 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ The .NET Foundation licenses this file to you under the MIT license.

<!-- Set up default feature switches -->
<PropertyGroup>
<UseSystemResourceKeys Condition="$(IlcDisableReflection) == 'true'">true</UseSystemResourceKeys>
<EventSourceSupport Condition="$(IlcDisableReflection) == 'true'">false</EventSourceSupport>
<EventSourceSupport Condition="$(EventSourceSupport) == ''">false</EventSourceSupport>
<UseWindowsThreadPool Condition="'$(UseWindowsThreadPool)' == '' and '$(_targetOS)' == 'win'">true</UseWindowsThreadPool>
<DynamicCodeSupport Condition="'$(DynamicCodeSupport)' == ''">false</DynamicCodeSupport>
Expand Down Expand Up @@ -108,8 +106,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<AutoInitializedAssemblies Include="System.Private.CoreLib" />
<AutoInitializedAssemblies Include="System.Private.StackTraceMetadata" Condition="$(StackTraceSupport) != 'false'" />
<AutoInitializedAssemblies Include="System.Private.TypeLoader" />
<AutoInitializedAssemblies Include="System.Private.Reflection.Execution" Condition="$(IlcDisableReflection) != 'true'" />
<AutoInitializedAssemblies Include="System.Private.DisabledReflection" Condition="$(IlcDisableReflection) == 'true'" />
<AutoInitializedAssemblies Include="System.Private.Reflection.Execution" />
</ItemGroup>

<ItemDefinitionGroup>
Expand Down Expand Up @@ -258,15 +255,12 @@ The .NET Foundation licenses this file to you under the MIT license.
<IlcArg Condition="$(ServerGarbageCollection) == 'true'" Include="--runtimeopt:gcServer=1" />
<IlcArg Condition="$(IlcGenerateCompleteTypeMetadata) == 'true'" Include="--completetypemetadata" />
<IlcArg Condition="$(StackTraceSupport) != 'false'" Include="--stacktracedata" />
<IlcArg Condition="$(IlcScanReflection) != 'false' and $(IlcDisableReflection) != 'true'" Include="--scanreflection" />
<IlcArg Condition="$(IlcScanReflection) != 'false'" Include="--scanreflection" />
<IlcArg Condition="$(IlcFoldIdenticalMethodBodies) == 'true' or $(StackTraceSupport) == 'false'" Include="--methodbodyfolding" />
<IlcArg Condition="$(Optimize) == 'true' and $(OptimizationPreference) == 'Size'" Include="--Os" />
<IlcArg Condition="$(Optimize) == 'true' and $(OptimizationPreference) == 'Speed'" Include="--Ot" />
<IlcArg Condition="'$(_linuxLibcFlavor)' == 'bionic'" Include="--noinlinetls" />
<IlcArg Condition="$(IlcInstructionSet) != ''" Include="--instruction-set:$(IlcInstructionSet)" />
<IlcArg Condition="$(IlcDisableReflection) == 'true'" Include="--reflectiondata:none" />
<IlcArg Condition="$(IlcDisableReflection) == 'true'" Include="--feature:System.Collections.Generic.DefaultComparers=false" />
<IlcArg Condition="$(IlcDisableReflection) == 'true'" Include="--feature:System.Reflection=false" />
<IlcArg Condition="$(IlcMaxVectorTBitWidth) != ''" Include="--max-vectort-bitwidth:$(IlcMaxVectorTBitWidth)" />
<IlcArg Condition="$(IlcSingleThreaded) == 'true'" Include="--parallelism:1" />
<IlcArg Condition="$(IlcSystemModule) != ''" Include="--systemmodule:$(IlcSystemModule)" />
Expand All @@ -291,8 +285,6 @@ The .NET Foundation licenses this file to you under the MIT license.
<IlcArg Condition="$(IlcResilient) != 'false'" Include="--resilient" />
<IlcArg Include="@(UnmanagedEntryPointsAssembly->'--generateunmanagedentrypoints:%(Identity)')" />

<IlcArg Condition="$(IlcDisableReflection) == 'true'" Include="--feature:System.Reflection.IsReflectionExecutionAvailable=false" />

<!-- The managed debugging support in libraries is unused - trim it -->
<IlcArg Condition="'$(DebuggerSupport)' != 'true'" Include="--feature:System.Diagnostics.Debugger.IsSupported=false" />

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
</ItemGroup>

<ItemGroup>
<ILLinkSubstitutionsXmls Include="ILLink\ILLink.Substitutions.xml" />
<ILLinkLinkAttributesXmls Include="ILLink\ILLink.LinkAttributes.xml" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsUnix)'=='true'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace System.Collections.Generic
{
public abstract partial class Comparer<T> : IComparer, IComparer<T>
{
[FeatureSwitchDefinition("System.Collections.Generic.DefaultComparers")]
private static bool SupportsGenericIComparableInterfaces => true;

[Intrinsic]
private static Comparer<T> Create()
{
Expand All @@ -24,11 +21,7 @@ private static Comparer<T> Create()
// This body serves as a fallback when instantiation-specific implementation is unavailable.
// If that happens, the compiler ensures we generate data structures to make the fallback work
// when this method is compiled.
if (SupportsGenericIComparableInterfaces)
{
return Unsafe.As<Comparer<T>>(ComparerHelpers.GetComparer(typeof(T).TypeHandle));
}
return new ObjectComparer<T>();
return Unsafe.As<Comparer<T>>(ComparerHelpers.GetComparer(typeof(T).TypeHandle));
}

public static Comparer<T> Default { [Intrinsic] get; } = Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ namespace System.Collections.Generic
{
public abstract partial class EqualityComparer<T> : IEqualityComparer, IEqualityComparer<T>
{
[FeatureSwitchDefinition("System.Collections.Generic.DefaultComparers")]
private static bool SupportsGenericIEquatableInterfaces => true;

[Intrinsic]
private static EqualityComparer<T> Create()
{
Expand All @@ -30,11 +27,7 @@ private static EqualityComparer<T> Create()
return Unsafe.As<EqualityComparer<T>>(new StringEqualityComparer());
}

if (SupportsGenericIEquatableInterfaces)
{
return Unsafe.As<EqualityComparer<T>>(EqualityComparerHelpers.GetComparer(typeof(T).TypeHandle));
}
return new ObjectEqualityComparer<T>();
return Unsafe.As<EqualityComparer<T>>(EqualityComparerHelpers.GetComparer(typeof(T).TypeHandle));
}

public static EqualityComparer<T> Default { [Intrinsic] get; } = Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ internal void Free()
RuntimeImports.RhHandleFree(_runtimeTypeInfoHandle);
}

private static bool IsReflectionDisabled => false;

private static bool DoNotThrowForNames => AppContext.TryGetSwitch("Switch.System.Reflection.Disabled.DoNotThrowForNames", out bool doNotThrow) && doNotThrow;
private static bool DoNotThrowForAssembly => AppContext.TryGetSwitch("Switch.System.Reflection.Disabled.DoNotThrowForAssembly", out bool doNotThrow) && doNotThrow;
private static bool DoNotThrowForAttributes => AppContext.TryGetSwitch("Switch.System.Reflection.Disabled.DoNotThrowForAttributes", out bool doNotThrow) && doNotThrow;

internal MethodTable* ToMethodTableMayBeNull() => _pUnderlyingEEType;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -72,9 +66,6 @@ internal RuntimeTypeInfo GetRuntimeTypeInfo()
[MethodImpl(MethodImplOptions.NoInlining)]
private RuntimeTypeInfo InitializeRuntimeTypeInfoHandle()
{
if (IsReflectionDisabled)
throw new NotSupportedException(SR.Reflection_Disabled);

RuntimeTypeInfo runtimeTypeInfo = ExecutionDomain.GetRuntimeTypeInfo(_pUnderlyingEEType);

// We assume that the RuntimeTypeInfo unifiers pick a winner when multiple threads
Expand Down Expand Up @@ -648,9 +639,6 @@ public override bool IsInstanceOfType([NotNullWhen(true)] object? o)

public override string ToString()
{
if (IsReflectionDisabled)
return "0x" + ((nuint)_pUnderlyingEEType).ToString("x");

return GetRuntimeTypeInfo().ToString();
}

Expand Down Expand Up @@ -799,46 +787,31 @@ public override bool IsDefined(Type attributeType, bool inherit)

public override object[] GetCustomAttributes(bool inherit)
{
if (IsReflectionDisabled && DoNotThrowForAttributes)
return Array.Empty<object>();

return GetRuntimeTypeInfo().GetCustomAttributes(inherit);
}

public override object[] GetCustomAttributes(Type attributeType, bool inherit)
{
if (IsReflectionDisabled && DoNotThrowForAttributes)
return Array.Empty<object>();

return GetRuntimeTypeInfo().GetCustomAttributes(attributeType, inherit);
}

public override IEnumerable<CustomAttributeData> CustomAttributes
{
get
{
if (IsReflectionDisabled && DoNotThrowForAttributes)
return Array.Empty<CustomAttributeData>();

return GetRuntimeTypeInfo().CustomAttributes;
}
}

public override IList<CustomAttributeData> GetCustomAttributesData()
{
if (IsReflectionDisabled && DoNotThrowForAttributes)
return Array.Empty<CustomAttributeData>();

return GetRuntimeTypeInfo().GetCustomAttributesData();
}

public override string Name
{
get
{
if (IsReflectionDisabled && DoNotThrowForNames)
return ToString();

return GetRuntimeTypeInfo().Name;
}
}
Expand All @@ -847,9 +820,6 @@ public override string? Namespace
{
get
{
if (IsReflectionDisabled && DoNotThrowForNames)
return null;

return GetRuntimeTypeInfo().Namespace;
}
}
Expand All @@ -862,9 +832,6 @@ public override Assembly Assembly
{
get
{
if (IsReflectionDisabled && DoNotThrowForAssembly)
return Assembly.GetExecutingAssembly();

return GetRuntimeTypeInfo().Assembly;
}
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit fe0803f

Please sign in to comment.