Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use FeatureSwitchDefinition in a few places #106564

Merged
merged 10 commits into from
Aug 27, 2024

Conversation

sbomer
Copy link
Member

@sbomer sbomer commented Aug 16, 2024

This replaces much of our ILLink.Substitutions.xml with nearly equivalent FeatureSwitchDefinitionAttribute. The minor difference is that both true and false are substituted (when the feature switch is set accordingly), whereas some of our substitution xmls only defined a substitution for the false case.

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

Copy link
Contributor

Tagging subscribers to this area: @dotnet/interop-contrib
See info in area-owners.md if you want to be subscribed.

Copy link
Member

@jkoritzinsky jkoritzinsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interop-related switches LGTM

- IsReflectionExecutionAvaliable shouldn't have used FeatureSwitchDefinitionAttribute
  because it's not a property
- Added missing FeatureSwitchDefinitionAttribute to MetadataUpdater.IsSupported
@sbomer sbomer marked this pull request as ready for review August 23, 2024 16:33
Comment on lines 49 to 50
[FeatureSwitchDefinition("System.Reflection")]
private static bool IsReflectionDisabled => false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this property reflect the negated value of that feature switch? Does this account for that somehow?

  <type fullname="System.RuntimeType" feature="System.Reflection" featurevalue="false">
    <method signature="System.Boolean get_IsReflectionDisabled()" body="stub" value="true" />
  </type>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, great catch, that one can't be handled by FeatureSwitchDefinition. I'm surprised this didn't cause test failures in ci. @MichalStrehovsky

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, great catch, that one can't be handled by FeatureSwitchDefinition. I'm surprised this didn't cause test failures in ci. @MichalStrehovsky

We don't test things with reflection disabled since that mode is unsupported. So if this enabled reflection unconditionally, I'm not surprised it wasn't caught. I'd be surprised if it was the other way and nothing failed.

Copy link
Member

@jtschuster jtschuster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo comments, thank you!

…viceProvider.cs

Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
@@ -24,6 +24,10 @@
<Compile Include="$(CoreLibSharedDir)System\Runtime\Versioning\RequiresPreviewFeaturesAttribute.cs" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp' or $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '9.0'))">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<ItemGroup Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp' or $([MSBuild]::VersionLessThan('$(TargetFrameworkVersion)', '9.0'))">
<ItemGroup Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0')">

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took this condition from the matching section in src/System.Text.Json.csproj - I'd rather keep them the same in this change.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do the System.SR one as well (obviously in a separate PR)?

private static readonly bool s_usingResourceKeys = GetUsingResourceKeysSwitchValue();
// This method is a target of ILLink substitution.
private static bool GetUsingResourceKeysSwitchValue() => AppContext.TryGetSwitch("System.Resources.UseSystemResourceKeys", out bool usingResourceKeys) ? usingResourceKeys : false;

@sbomer
Copy link
Member Author

sbomer commented Aug 23, 2024

Can we do the System.SR one as well

I'll look into that as a follow-up, thanks!

@sbomer
Copy link
Member Author

sbomer commented Aug 27, 2024

/ba-g "timeout"

@sbomer sbomer merged commit 0fcba3f into dotnet:main Aug 27, 2024
152 of 158 checks passed
jtschuster added a commit to jtschuster/runtime that referenced this pull request Sep 17, 2024
This replaces much of our ILLink.Substitutions.xml with nearly
equivalent FeatureSwitchDefinitionAttribute. The minor difference is
that both true and false are substituted (when the feature switch is
set accordingly), whereas some of our substitution xmls only defined a
substitution for the false case.

---------

Co-authored-by: Jackson Schuster <36744439+jtschuster@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Oct 6, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants