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

Skip checking COM objects on AOT #1662

Merged
merged 2 commits into from
Jul 9, 2024

Conversation

Sergio0694
Copy link
Member

There will never be COM objects on AOT anyway. Also minor optimization to copying vtables.

@Sergio0694 Sergio0694 added the AOT label Jul 4, 2024
@Sergio0694 Sergio0694 requested a review from manodasanW July 4, 2024 03:43
@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/minor-aot-tweaks branch from 5a6f46a to fa86472 Compare July 8, 2024 20:15
@Sergio0694 Sergio0694 merged commit 8576896 into staging/AOT Jul 9, 2024
10 checks passed
Comment on lines +575 to +581
// 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;
}

Copy link
Member

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.

Cc @jkoritzinsky @AaronRobinsonMSFT

Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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 🙂

Copy link
Member

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.

@Sergio0694 Sergio0694 deleted the user/sergiopedri/minor-aot-tweaks branch July 17, 2024 02:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants