Skip to content

ifdef out unsupported Enum underlying types for nativeaot#79472

Merged
jkotas merged 6 commits into
dotnet:mainfrom
stephentoub:enumnativeaotifdef
Dec 15, 2022
Merged

ifdef out unsupported Enum underlying types for nativeaot#79472
jkotas merged 6 commits into
dotnet:mainfrom
stephentoub:enumnativeaotifdef

Conversation

@stephentoub

@stephentoub stephentoub commented Dec 9, 2022

Copy link
Copy Markdown
Member

@jkotas, worthwhile?

Contributes to #79437

@stephentoub
stephentoub requested a review from jkotas December 9, 2022 20:09
@ghost

ghost commented Dec 9, 2022

Copy link
Copy Markdown

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

jkotas commented Dec 12, 2022

Copy link
Copy Markdown
Member

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!

@jkotas
jkotas force-pushed the enumnativeaotifdef branch from 19fc751 to 7d8e2ac Compare December 13, 2022 04:30

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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@jkotas jkotas Dec 14, 2022

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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

jkotas commented Dec 13, 2022

Copy link
Copy Markdown
Member

@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.

@MichalStrehovsky MichalStrehovsky left a comment

Copy link
Copy Markdown
Member

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

jkotas commented Dec 14, 2022

Copy link
Copy Markdown
Member

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

jkotas commented Dec 14, 2022

Copy link
Copy Markdown
Member

Do we need a breaking change label for Mono?

@SamMonoRT How would like to handle that?

@jkotas

jkotas commented Dec 14, 2022

Copy link
Copy Markdown
Member

`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
Copy Markdown
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

jkotas commented Dec 15, 2022

Copy link
Copy Markdown
Member

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