You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: accepted/2023/feature-switch-attributes.md
+7-8Lines changed: 7 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
.NET has [feature switches](https://github.com/dotnet/designs/blob/main/accepted/2020/feature-switch.md) which can be set to turn on/off areas of functionality in our libraries, with optional support for removing unused features when trimming or native AOT compiling. What we describe overall as "feature switches" have many pieces which fit together to enable this:
4
4
5
5
- MSBuild property
6
-
-RuntimHostConfigurationOption MSBuild ItemGroup
6
+
-RuntimeHostConfigurationOption MSBuild ItemGroup
7
7
-`runtimeconfig.json` setting
8
8
- AppContext feature setting
9
9
-**ILLink.Substitutions.xml**
@@ -30,7 +30,7 @@ We'll use the following terms to describe specific bits of functionality related
30
30
31
31
We'll say that a "feature switch property" is also necessarily a "feature guard property" for its defining feature, but not all "feature guard properties" are "feature switch properties".
32
32
33
-
A "feature switch property" may also be a "feature guard property" for a feature _other than_ the defining feature. For example, we introduced the feature switch property `StartupHookProvider.IsSupported`, which is defined by the feature switch named `"System.StartupHookProvider.IsSupported"`, but additionally serves as a guard for code in the implementation that has `RequiresUnreferencedCodeAttribute`. Startup hook support is disabled whenever we trim out unreferenced code, but may alse be disabled independently by the feature switch.
33
+
A "feature switch property" may also be a "feature guard property" for a feature _other than_ the defining feature. For example, we introduced the feature switch property `StartupHookProvider.IsSupported`, which is defined by the feature switch named `"System.StartupHookProvider.IsSupported"`, but additionally serves as a guard for code in the implementation that has `RequiresUnreferencedCodeAttribute`. Startup hook support is disabled whenever we trim out unreferenced code, but may also be disabled independently by the feature switch.
34
34
35
35
Similarly, one could imagine introducing a feature switch for `IsDynamicCodeCompiled`.
36
36
@@ -187,7 +187,7 @@ We may also want to add support for such validation in ILLink and ILCompiler, th
187
187
188
188
### Feature guards and constant propagation
189
189
190
-
ILLink performs interprocedural constant propagation, but ILCompiler does not. To treat a property as a feature guard, ILCompiler curently requires substitution XML to eliminate guarded branches. A natural use of the attribute-based feature guards is to influence ILCompiler's constant propagation, replacing the use of substitution XML for properties that are feature guards only.
190
+
ILLink performs interprocedural constant propagation, but ILCompiler does not. To treat a property as a feature guard, ILCompiler currently requires substitution XML to eliminate guarded branches. A natural use of the attribute-based feature guards is to influence ILCompiler's constant propagation, replacing the use of substitution XML for properties that are feature guards only.
191
191
192
192
A separate concept is still required to replace the substitution XML for properties that are feature switches in addition to being feature guards.
193
193
@@ -245,7 +245,7 @@ A feature switch is also a feature guard for the feature it is defined by. We co
245
245
246
246
### Feature guards _may_ also be feature switches
247
247
248
-
A feature guard might also come with its own independent feature switch. We shoud be careful to avoid violating the assumptions of the feature guard by controlling the property via a feature switch.
248
+
A feature guard might also come with its own independent feature switch. We should be careful to avoid violating the assumptions of the feature guard by controlling the property via a feature switch.
249
249
250
250
For example, if we had a separate feature switch for `IsDynamicCodeCompiled`, this would allow setting `IsDynamicCodeCompiled` to `true` even when `IsDynamicCodeSupported` is `false`.
251
251
@@ -340,7 +340,7 @@ Similarly, not all features come with an attribute. Some features don't tie into
340
340
-`GlobalizationMode.Invariant` property
341
341
-`"System.Globalization.Invariant"`
342
342
343
-
No warnings are produced just because these features are enabled/disabled. Instead, they are designed to be used to change the behavior, and possibly remove unneccessary code when publishing. It's easy to imagine adding an attribute like `RequiresVariantGlobalization` that would be used to annotate APIs that rely on globalization support, such that analysis warnings would prevent accidentally pulling in the globalization stack from code that is supposed to be using invariant globalization. We don't want to do this for every feature; typically we only do this for features that represent large cross-cutting concerns, and are not available with certain app models (trimming, AOT compilation, single-file publishing).
343
+
No warnings are produced just because these features are enabled/disabled. Instead, they are designed to be used to change the behavior, and possibly remove unneccessary code when publishing. It's easy to imagine adding an attribute like `RequiresCultureData` that would be used to annotate APIs that rely on globalization support, such that analysis warnings would prevent accidentally pulling in the globalization stack from code that is supposed to be using invariant globalization. We don't want to do this for every feature; typically we only do this for features that represent large cross-cutting concerns, and are not available with certain app models (trimming, AOT compilation, single-file publishing).
344
344
345
345
However, any attribute-based model that we pick to represent features should be able to tie in with all three representations.
@@ -487,7 +486,7 @@ The platform compatibility analyzer is semantically very similar to the behavior
487
486
488
487
The analyzer has built-in knowledge of fact that `IsAndroid` corresponds to the `SupportedOSPlatform("android")`. ThisissimilartotheILLinkanalyzer'scurrenthard-codedknowledgeofthefactthat `IsDynamicCodeSupported` correspondsto `RequiresDynamicCodeAttribute`.
0 commit comments