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

Interned strings don't have same identity as string literals #823

Closed
MichalStrehovsky opened this issue Mar 17, 2021 · 3 comments
Closed
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation

Comments

@MichalStrehovsky
Copy link
Member

Failing the System.Tests.StringTests.InternTest System.Runtime test.

We could probably fix this by walking the frozen objects region, looking for all strings in it and adding them to the intern table on first String.Intern call.

@MichalStrehovsky MichalStrehovsky added the area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation label Mar 17, 2021
@jkotas
Copy link
Member

jkotas commented Mar 28, 2021

NGen in .NET Framework did not guarantee this either and it have not ever showed up as a problem (except for empty string).

For example:

using System;

Console.WriteLine(object.ReferenceEquals(string.Intern(new string('a', 3)), "aaa"));

Prints true with JIT, but prints 'false' when ngened in .NET Framework.

I think we should make sure that this works for empty string, but otherwise move it into dotnet/runtime#69919

@MichalStrehovsky
Copy link
Member Author

Should we fix the test so that it only checks for string.Empty and nothing else?

I just realized that this is probably CompilationRelaxations.NoStringInterning - the C# compiler puts that attribute by default so this is a legal optimization for any runtime to do.

@jkotas
Copy link
Member

jkotas commented Mar 28, 2021

Should we fix the test so that it only checks for string.Empty and nothing else?

InternalTestAotSubset (that should be InternTestAotSubset) does that. I guess disable the test for native AOT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-NativeAOT-coreclr .NET runtime optimized for ahead of time compilation
Projects
None yet
Development

No branches or pull requests

2 participants