-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add ability to disable reflection emit for testing #39806
Comments
@eerhardt @vitek-karas Would it make sense to make this linker and feature switch bundle, similar to what we are doing elsewhere? |
I’m not sure using the linker would result in the end-user experience being asked for here. Someone would need to run the linker on the tests - it only runs during publish - and the app/test would need to be self contained.
You could do this today with the linker. You would just need to pass a substitution file to the linker that had the following: runtime/src/mono/netcore/System.Private.CoreLib/src/ILLink/ILLink.Substitutions.wasm.xml Lines 9 to 10 in 3a4298c
|
The end to end here it so be able to have confidence to run on a platform like unity. That's why I think it should be a runtime mode. Something I can turn on in tests with an environment variable or something. Though, maybe It'll break the test runner as well 😄 |
I agree that exposing it only via linker would not help. That's why I have said linked and feature switch bundle, for example like the binary serialization switch. You can turn the feature off via AppContext, you can tell linker to strip the feature code, and some platforms have the feature turned off unconditionally. |
Probably a naive question, but why not test it directly on unity? That’s probably the only way you’d have confidence it works on that platform. Ref emit is just one of many things that will be different. |
I agree with @eerhardt that running on Unity is the only way to be 100% certain. But there is something very nice about being able to use our existing dev environment for rapid prototyping. Assuming our normal dev environment would detect a significant percentage (50%? 90%?) of these problems I'd consider that a win. |
The same reason I don't want to test on Xamarin, it requires a new toolchain, setup, sometimes devices. The idea here is to get closer to what the actual target device/environment is without needing one. Sure you can say "if I don't test on the platform then I can't know it'll work there" but given my experience 90% of the code just works and there are known missing capabilities of the underlying platform that we workaround (the code even works in WASM and we don't explicit test there!). I also think running tests after linking is super important as part of this overall story |
The feature switch solution as @jkotas suggested should work nicely. Whether it's bound to linker or not is secondary (but if we do it, we should do it for linker as well, just for completeness). It should just mean defining a new runtime property and wiring it into the |
Yes even if |
Moving to future; this week is the last week before ask mode. |
Evaluated - keeping in future; considered lower priority. The likely approach is:
|
I will look to implement this in the next couple weeks. We have identified a couple areas where this functionality will be helpful for ASP.NET. Do we have an idea for a name of the feature switch? Names I could imagine are:
The |
I think it should be Feature switch names have been trying to mirror managed API names. There are several cases where we even have both managed API and feature switch of the same name (e.g. |
I agree with @jkotas |
@jkotas @marek-safar @lambdageek @vargaz - Should the Mono runtime also support this feature switch? My assumption is "yes", but I wanted to check first before doing the work. There will be scenarios where this feature switch won't work. For example: When in "AOT" (either NativeAOT or Mono AOT), and setting the switch to Scenarios where the switch will work:
In these scenarios, IsDynamicCodeSupported is hard-coded to |
One more "requirements" question - Should this switch actually make |
These switches already exist, i.e.: runtime/src/mono/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeFeature.Mono.cs Line 7 in 517698d
|
The ask is to be able to configure the values of these switches. For example, run using CoreCLR's (or Mono's) JIT runtime, but with |
It's doable in mono with not much work i think. |
Yes |
This adds the ability to disable reflection emit for testing. It also allows for applications/libraries to simulate NativeAOT behavior (like switching on RuntimeFeature.IsDynamicCodeSupported) without actually publishing for NativeAOT. Fix dotnet#39806
We (Eric, Zoltan and I) discussed support for this in Mono on Discord. The approach we will try is:
The complication is scenarios like profiled AOT. In profiled AOT normally |
I see good arguments for both doing this (allow certain mistakes to be caught earlier) and not doing this (this instrumentation is not 100% reliable - we won't be able to instrument APIs like What would you propose? |
My proposal is that it throws |
* Add IsDynamicCodeSupported Feature Switch This adds the ability to disable reflection emit for testing. It also allows for applications/libraries to simulate NativeAOT behavior (like switching on RuntimeFeature.IsDynamicCodeSupported) without actually publishing for NativeAOT. Fix #39806 * Add IsDynamicCodeSupported feature switch support for Mono * Remove featuredefault for IsDynamicCodeSupported so it isn't substituted during CoreLib's build. * Add Intrinsic attribute back for Mono
With the new feature switch added in dotnet#39806, calling LambdaExpression.Compile is throwing a PlatformNotSupportedException. Instead, LambdaExpression should respect IsDynamicCodeSupported and switch to using the interpreter when IsDynamicCodeSupported is false.
…#80759) * LambdaExpression.CanCompileToIL should respect IsDynamicCodeSupported With the new feature switch added in #39806, calling LambdaExpression.Compile is throwing a PlatformNotSupportedException. Instead, LambdaExpression should respect IsDynamicCodeSupported and switch to using the interpreter when IsDynamicCodeSupported is false. * Add tests
…dotnet#80759) * LambdaExpression.CanCompileToIL should respect IsDynamicCodeSupported With the new feature switch added in dotnet#39806, calling LambdaExpression.Compile is throwing a PlatformNotSupportedException. Instead, LambdaExpression should respect IsDynamicCodeSupported and switch to using the interpreter when IsDynamicCodeSupported is false. * Add tests
When trying to target platforms without ref emit support, it would be nice to run CoreCLR in a mode with it disabled so it would be possible to write unit tests to see if your library breaks or not. This mode should also cause
RuntimeFeature.IsDynamicCodeCompiled
to return false.cc @jkotas
The text was updated successfully, but these errors were encountered: