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

Add support for Trimming/AOT/SingleFile #80

Open
lilith opened this issue Jan 30, 2024 · 7 comments
Open

Add support for Trimming/AOT/SingleFile #80

lilith opened this issue Jan 30, 2024 · 7 comments
Labels
enhancement New feature or request PR welcome User contribution/PR is welcome

Comments

@lilith
Copy link
Contributor

lilith commented Jan 30, 2024

While certain runtime serializations are pretty hard to do under AOT/Trim, I think most functionality could remain with it enabled, and the rest could work via a source analyzer. Either way, it would be good to annotate the source code into the AOT-compatible and not portions. Drop these into Tomlyn.props (and consider adding a net8.0) target to see the warnings - there aren't many, but they may be essential.

    <EnableTrimAnalyzer>true</EnableTrimAnalyzer>
    <EnableSingleFileAnalyzer>true</EnableSingleFileAnalyzer>
    <EnableAotAnalyzer>true</EnableAotAnalyzer>

I went about the codebase adding [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicMethods)] to Types passed around, but I think there might need to be a little refactoring to prevent unlimited spread of those annotations.

There's also another option - System.Text.Json already supports source generation and allows turning a JsonNode (tree) into a custom object. I'm unsure how exact the mapping between toml and json is, but converting the parsed toml tree to a jsonnode could be a workaround for some.

@xoofx xoofx added enhancement New feature or request PR welcome User contribution/PR is welcome labels Jan 31, 2024
@lilith
Copy link
Contributor Author

lilith commented Jan 31, 2024

I would say that the first step would be adding a .NET 8 target across the projects and to CI, then adding some failing tests that explore exactly what is currently broken under trimming. Would you want to keep .NET 7 or replace it with .NET 6? I see lots of .NET 6 ifdefs. .NET 6 EOL is November 12, 2024, .NET 7 EOL is May 14, 2024.

I don't have deep enough knowledge of the code architecture to refactor what is needed for direct custom model support - the design seems to be partly supportive of the changes but I would likely take it an unhelpful direction without knowing your goals/philosophy. I also don't have that bandwidth, and while my new docker images currently use TOML, I could see switching to JSON as being less costly.

Adding JsonNode translation would introduce a new dependency (although perhaps not on .NET 8?), but could be isolated in code path to allow it to be trimmed out. I'd either do a separate package or make the feature .NET 8 only.

@lilith
Copy link
Contributor Author

lilith commented Jan 31, 2024

I opened a separate issue for .NET 8: #82

@xoofx
Copy link
Owner

xoofx commented Feb 1, 2024

I went about the codebase adding [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields | DynamicallyAccessedMemberTypes.PublicMethods)] to Types passed around, but I think there might need to be a little refactoring to prevent unlimited spread of those annotations.

I dunno how much trouble it will be for Tomlyn, as I forgot the details about the codebase. I tried to do similar stuffs in another OSS project Scriban that is heavily relying on reflection, but it was too laborious to get it working.

Drop these into Tomlyn.props (and consider adding a net8.0) target to see the warnings - there aren't many, but they may be essential.

For .NET 8, I have been using the following (as described here)

<PropertyGroup>
    <IsAotCompatible>true</IsAotCompatible>
</PropertyGroup>

There's also another option - System.Text.Json already supports source generation and allows turning a JsonNode (tree) into a custom object. I'm unsure how exact the mapping between toml and json is, but converting the parsed toml tree to a jsonnode could be a workaround for some.

Yeah, I would probably prefer to avoid this.

@lilith
Copy link
Contributor Author

lilith commented Feb 2, 2024

Well, I don't think we want to tell downstream libs that it is AOT compatible until we've annotated which APIs are and aren't.

Yeah, I would probably prefer to avoid this.

Avoid source generation or System.Text.Json integration?

@xoofx
Copy link
Owner

xoofx commented Feb 2, 2024

Avoid source generation or System.Text.Json integration?

System.Text.Json

@xoofx
Copy link
Owner

xoofx commented Feb 2, 2024

Well, I don't think we want to tell downstream libs that it is AOT compatible until we've annotated which APIs are and aren't.

Yeah, it was just to suggest that this flag cover the 3 analyzers and we would use it in the end, but probably not during the transition if it takes more than one PR.

@lilith
Copy link
Contributor Author

lilith commented Feb 2, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR welcome User contribution/PR is welcome
Projects
None yet
Development

No branches or pull requests

2 participants