-
Notifications
You must be signed in to change notification settings - Fork 107
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
Skip checking COM objects on AOT #1662
Conversation
5a6f46a
to
fa86472
Compare
// Built-in COM interop isn't supported in AOT environments, | ||
// so this method can only ever return false. Just inline it. | ||
if (!RuntimeFeature.IsDynamicCodeCompiled) | ||
{ | ||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much does this really save? !IsDynamicCodeCompiled ==> built-in COM is not supported
is a pretty major leap that might burn you in the future. What you'd want is Marshal.IsBuiltInComInteropSupported
but such API doesn't exist.
This is basically assuming that IsDynamicCodeCompiled
approximates IsNativeAot
and that native AOT will never have built-in COM interop.
This approximation might be broken today if you put <PublishAot>true</PublishAot>
and <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
to the project file and F5 launch the app (not Publish). In this configuration, RuntimeFeature.IsDynamicCodeCompiled
is false, but built-in COM works. It is a terrible configuration to set, but it's possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree. I think adding some public check is possible. I also tend to agree with @MichalStrehovsky here, what is this actually saving in practice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This wasn't so much to save binary size per se, but rather to make the AOT-safe version of CsWinRT "stricter" and simpler. We have several parts of the code that we kept for backwards-compatibility (including built-in COM support), like being able to use old generated projections that are not fully trim-safe, etc.
Starting from .NET 8, we're saying that all that only applies to non-AOT scenarios. If you enable AOT, you also opt-in into the stricter mode, where we require you to only use updated projections everywhere (old projections wouldn't work with AOT anyway), and disable some more leftover features. Dropping built-in COM support entirely is part of that. We've added support for interop with generated COM interfaces starting with the .NET 8 TFM instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The .NET 8 WinRT.Runtime (which implements generated COM interfaces) hasn't shipped though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember that AOT support hasn't shipped at all either, it's all experimental. We'll get there 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As long as we're in agreement that !RuntimeFeature.IsDynamicCodeCompiled
doesn't imply built-in COM is disabled (neither today, nor in the future), consider this resolved.
There will never be COM objects on AOT anyway. Also minor optimization to copying vtables.