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

Enable dedup optimization in FullAOT mode only #20687

Merged
merged 12 commits into from
Jun 7, 2024

Conversation

kotlarmilos
Copy link
Contributor

@kotlarmilos kotlarmilos commented Jun 5, 2024

Description

This PR enables the dedup optimization in FullAOT mode only. The optimization can only run in FullAOT mode with complete application context. Without it, the AOT compiler may fail to collect all generic instances, and the runtime can't find them as they are searched in the dedup assembly.

Changes

This PR updates the SDK targets to enable dedup optimization in FullAOT mode only. This change doesn't depend on any runtime changes.

Verification

This PR also introduces partial AOT tests. They inspect the bundle for aot-instances.dll, which shouldn't be generated in a partial AOT compilation setup. Additionally, basic functionality is tested by asserting at app startup.

Additional notes

This change should be backported to .NET 8 as well.

Fixes dotnet/runtime#99248

@kotlarmilos kotlarmilos added the bug If an issue is a bug or a pull request a bug fix label Jun 5, 2024
@kotlarmilos kotlarmilos added this to the .NET 9 milestone Jun 5, 2024
@kotlarmilos kotlarmilos self-assigned this Jun 5, 2024
Comment on lines 1939 to 1940
var dllPath = Path.Combine (appPath, "aot-instances.dll");
Assert.That (dllPath, Does.Not.Exist, "Dedup optimization shouldn't been enabled for partial AOT compilation");
Copy link
Member

Choose a reason for hiding this comment

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

This will always pass on macOS and Mac Catalyst, because assemblies are in a subdirectory of the app bundle (Contents/MonoBundle/*.dll).

I think I would just list all the files in the app bundle, and assert that none of them are named 'aot-instances.dll'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you. I wasn't sure if there was the existing function for .dll search, so I added a new one.

Comment on lines 1964 to 1965
var dllPath = Path.Combine (appPath, "aot-instances.dll");
Assert.That (dllPath, Does.Not.Exist, "Dedup optimization shouldn't been enabled for partial AOT compilation");
Copy link
Member

Choose a reason for hiding this comment

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

Same as above.

Comment on lines 1942 to 1943
var appExecutable = GetNativeExecutable (platform, appPath);
ExecuteWithMagicWordAndAssert (platform, runtimeIdentifiers, appExecutable);
Copy link
Member

Choose a reason for hiding this comment

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

This needs to check if we can execute first, like this:

if (CanExecute (platform, runtimeIdentifiers)) {
var output = ExecuteWithMagicWordAndAssert (appExecutable);
Assert.That (output, Does.Contain ("42"), "Execution");
}

Otherwise ExecuteWithMagicWordAndAssert will try to run iOS and tvOS executables on macOS.

Copy link
Contributor

github-actions bot commented Jun 5, 2024

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

}
catch (Exception ex)
{
Console.WriteLine($"An error occurred: {ex.Message}");
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to ignore any exceptions? Wouldn't it be better to just let exceptions flow, which would eventually fail the test? This seems like it could end up hiding problems at some point.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

Copy link
Contributor

@ivanpovazan ivanpovazan left a comment

Choose a reason for hiding this comment

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

LGTM, I only left two minor comments.

[Test]
[TestCase (ApplePlatform.iOS, "ios-arm64;")]
[TestCase (ApplePlatform.MacOSX, "osx-arm64;osx-x64")]
[TestCase (ApplePlatform.MacCatalyst, "maccatalyst-x64;")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we test maccatalyst-arm64 as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added. I didn't add simulators since we already test this on physical devices.

var project_path = GetProjectPath (project, runtimeIdentifiers: runtimeIdentifiers, platform: platform, out var appPath);
Clean (project_path);
var properties = GetDefaultProperties (runtimeIdentifiers);
properties ["MtouchInterpreter"] = "-all,System.Private.CoreLib.dll";
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Just a thought. As far as I can see the added two test methods only differ by this setting, maybe it could have been an additional parameter to a single test method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, thanks.

Copy link
Contributor

github-actions bot commented Jun 6, 2024

⚠️ Your code has been reformatted. ⚠️

If this is not desired, add the actions-disable-autoformat label, and revert the reformatting commit.

If files unrelated to your change were modified, try reverting the reformatting commit + merging with the target branch (and push those changes).

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2
Copy link
Collaborator

📚 [PR Build] Artifacts 📚

Packages generated

View packages

Pipeline on Agent
Hash: [PR build]

@vs-mobiletools-engineering-service2
Copy link
Collaborator

✅ API diff for current PR / commit

Legacy Xamarin (No breaking changes)
  • iOS (no change detected)
  • tvOS (no change detected)
  • watchOS (no change detected)
  • macOS (no change detected)
NET (empty diffs)
  • iOS: (empty diff detected)
  • tvOS: (empty diff detected)
  • MacCatalyst: (empty diff detected)
  • macOS: (empty diff detected)

✅ API diff vs stable

Legacy Xamarin (No breaking changes)
.NET (No breaking changes)
Legacy Xamarin (stable) vs .NET

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: 9863d03b6a6e88af5aa15255fba28b92c79a5584 [PR build]

@rolfbjarne rolfbjarne merged commit 603781b into main Jun 7, 2024
88 checks passed
@rolfbjarne
Copy link
Member

/sudo backport release/8.0.1xx-xcode15.1

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Backport Job to branch release/8.0.1xx-xcode15.1 Created! The magic is happening here

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Oh no! Backport failed! Please see https://devdiv.visualstudio.com/DevDiv/_build/results?buildId=9694077 for more details.

rolfbjarne pushed a commit that referenced this pull request Jun 19, 2024
… only (#20701)

## Description

This PR enables the dedup optimization in FullAOT mode only. The optimization can only run in FullAOT mode with complete application context. Without it, the AOT compiler may fail to collect all generic instances, and the runtime can't find them as they are searched in the dedup assembly.

## Changes

This PR updates the SDK targets to enable dedup optimization in FullAOT mode only. This change doesn't depend on any runtime changes.

## Verification

This PR also introduces partial AOT tests. They inspect the bundle for `aot-instances.dll`, which shouldn't be generated in a partial AOT compilation setup. Additionally, basic functionality is tested by asserting at app startup.

## Additional notes

This change should be backported to .NET 8 as well.

Fixes dotnet/runtime#99248

Backport of #20687

---------

Co-authored-by: Milos Kotlar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug If an issue is a bug or a pull request a bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Excluding a library from interpreter would result in a crash
5 participants