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

How are all the polyfill source files generated? #88

Closed
0xced opened this issue Nov 8, 2023 · 4 comments
Closed

How are all the polyfill source files generated? #88

0xced opened this issue Nov 8, 2023 · 4 comments
Labels
question Further information is requested

Comments

@0xced
Copy link
Contributor

0xced commented Nov 8, 2023

Looking inside src/PolySharp.SourceGenerators/EmbeddedResources all polyfill source files are marked as // <auto-generated/> but I could not figure out how exactly those files are generated. I was expecting to find a tool inside this repository that was responsible for automatically generating those files, but could not find one! I even tried looking at the commit history to find clues but it did not help.

@Sergio0694 Could you please shed some light?

Some context: I wanted to contribute a polyfill for UnreachableException (issue #60) and I had to copy/paste the code from https://github.com/dotnet/runtime/blob/main/src/libraries/System.Private.CoreLib/src/System/Diagnostics/UnreachableException.cs It felt very much cheating to not use automatic code generation like all other polyfills.

0xced added a commit to 0xced/PolySharp that referenced this issue Nov 8, 2023
The System.Diagnostics.UnreachableException.cs file was not actually auto-generated (see Sergio0694#88).
0xced added a commit to 0xced/PolySharp that referenced this issue Nov 8, 2023
The System.Diagnostics.UnreachableException.cs file was not actually auto-generated (see Sergio0694#88).

Fixes Sergio0694#60
@Sergio0694
Copy link
Owner

Hey there! The polyfills are generated by an incremental generator bundled in the package 🙂
It's this one:

[Generator(LanguageNames.CSharp)]
public sealed partial class PolyfillsGenerator : IIncrementalGenerator

@Sergio0694 Sergio0694 added the question Further information is requested label Nov 8, 2023
@0xced
Copy link
Contributor Author

0xced commented Nov 8, 2023

OK, I think my question was not clear enough. Let's try to rephrase it: where do files inside the src/PolySharp.SourceGenerators/EmbeddedResources directory come from when they are checked into the repository? For example, the System.Diagnostics.CodeAnalysis.NotNullWhenAttribute.cs file that was added in commit f337dca starts with // <auto-generated/>. So I assumed it was generated by some tool, wasn't it? Was it generated by the PolyfillsGenerator incremental generator? From what I understand this source generator is reading those files from the embedded resources, not generating those files.

Were the 3 first lines manually added despite the first line implying the opposite?

// <auto-generated/>
#pragma warning disable
#nullable enable annotations

I hope my question makes sense now.

@Sergio0694
Copy link
Owner

Oooh gotcha, sorry. Yeah those were just manually added to those files 😄
Those files are not autogenerated in this repo, they're more like templates.

@0xced
Copy link
Contributor Author

0xced commented Nov 8, 2023

OK, got it. I was totally fooled by the // <auto-generated/> comment. I was expecting something like what Simon Cropp does in its NullabilityInfoContext polyfill, i.e. syncing from the dotnet/runtime repository and applying some fixes on top of it: https://github.com/SimonCropp/NullabilityInfo/blob/1e49e8d7f3bb6a2146ea0ca606ab803ac3ceb6ac/src/Nullability.Source.Tests/Sync.cs#L12-L40

0xced added a commit to 0xced/PolySharp that referenced this issue Nov 22, 2024
The System.Diagnostics.UnreachableException.cs file was not actually auto-generated (see Sergio0694#88).

Fixes Sergio0694#60
0xced added a commit to 0xced/PolySharp that referenced this issue Nov 22, 2024
The System.Diagnostics.UnreachableException.cs file was not actually auto-generated (see Sergio0694#88).

Fixes Sergio0694#60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants