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

ifdef out unsupported Enum underlying types for nativeaot #79472

Merged
merged 6 commits into from
Dec 15, 2022

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Dec 9, 2022

@jkotas, worthwhile?

Contributes to #79437

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label.

@jkotas
Copy link
Member

jkotas commented Dec 12, 2022

It looks fine to me. I would make a new #define for it at the top of the file to make it more self-documenting. We may want to enable the define on other targets where we care a lot about size a lot, like wasm. Thank you for looking for ways to fix the size regression!

@@ -1,6 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Rare enums types not expressible in C# are not supported in native AOT
#if !NATIVEAOT
#define RARE_ENUMS
Copy link
Contributor

Choose a reason for hiding this comment

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

@SamMonoRT @kotlarmilos should this also include all mobile/web targets?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, if we can include the mobile/web targets to mitigate the app size regressions, we should include those now, till we are able to identify and fix the Mono AOT compiler limitations.

Copy link
Member

Choose a reason for hiding this comment

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

I have pushed a commit to disable the rare enums support for Mono as well. Please take a look.

Copy link
Member

Choose a reason for hiding this comment

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

I've inspected native symbols of an iOS app and non-integral types except bool are supported in the Mono AOT engine.

Copy link
Member

@jkotas jkotas Dec 14, 2022

Choose a reason for hiding this comment

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

Ok, I am going to keep the rare enums enabled for Mono. I do not data to make the call on whether to disable it for Mono or not. It can be done later - it is two line change to enable/disable this for given config.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good, leave it enabled for now. We can run some measurements and see if it helps in size if we disable it.

Copy link
Member

Choose a reason for hiding this comment

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

It doesn't look to me like breaking change - by doing that we will restrict some theoretical or borderline cases. I would suggest excluding them as they are not expressible in C# and such change could mitigate the size regression. Some edge cases might fail where non-integral enums are created by using reflection, which is not recommended by the documentation.

Let's hear the other opinions as well. If it is a blocker, we can proceed and update it once we align.

@jkotas
Copy link
Member

jkotas commented Dec 13, 2022

@MichalStrehovsky PTLA

This fixes some of the size regression by ifdefing out support for rare enums, to match what we used to do in native AOT before the recent Enum changes.

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Looks good, although I've always been puzzled by our position on these. We care, but also we don't care.

I'd honestly just delete the reflection support for these and keep things simple, because it's either important and it was a bug that CoreCLR-AOT didn't have this, or it's not important and people won't miss it on CoreCLR-JIT either. (Unless there's something unique for CoreCLR-JIT, like C++/CLI support, that makes it needed there.)

Do we need a breaking change label for Mono?

@jkotas
Copy link
Member

jkotas commented Dec 14, 2022

unique for CoreCLR-JIT, like C++/CLI support

Yes, C++/CLI support, obfuscated code and compat for niche languages.

e.g. this compiles fine in C++/CLI:

enum MyEnum : intptr_t
{
	Red, Green, Blue
};

@jkotas
Copy link
Member

jkotas commented Dec 14, 2022

Do we need a breaking change label for Mono?

@SamMonoRT How would like to handle that?

@jkotas
Copy link
Member

jkotas commented Dec 14, 2022

`enum MyEnum : intptr_t { Red, Green, Blue };

This example is fine actually. C++/CLI will lower the underlying type to int32/int64. A better example:

enum MyEnum : bool
{
	Red, Blue
};

@SamMonoRT
Copy link
Member

Do we need a breaking change label for Mono?

@SamMonoRT How would like to handle that?

Adding @lambdageek and @vargaz for their opinion.

@jkotas
Copy link
Member

jkotas commented Dec 15, 2022

All known errors according to the build analysis.

@jkotas jkotas merged commit c63cd38 into dotnet:main Dec 15, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 14, 2023
@stephentoub stephentoub deleted the enumnativeaotifdef branch June 29, 2023 14:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants