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

ConfigurationBinder source generator should not generate source for types without members #94142

Open
ericstj opened this issue Oct 28, 2023 · 2 comments
Assignees
Labels
area-Extensions-Configuration enhancement Product code improvement that does NOT require public API changes/additions source-generator Indicates an issue with a source generator feature
Milestone

Comments

@ericstj
Copy link
Member

ericstj commented Oct 28, 2023

If a type contains no members for binding we shouldn't generator source for that. This includes the case where the only members it generates are references to itself.

Consider the following types:

public abstract class MySingleton
{
    public static MySingleton Instance {get; set;}
}
public abstract class MyNode
{
  public MyNode Next { get; set; }
}
public class MyClass
{
   // all members below are excluded
  public int[,] Matrix { get; set; }
  public Func<string, int> ParseMethod { get; set; }
}

All have no bindable members and result in useless code gen today. It's harmless - but we should try to identify these types of things through heuristics to reduce the size of the codegen. We should inform the behavior for non-abstract instance types from the runtime binder to determine if they'll be initialized or not in these cases -- I don't think they would.

@dotnet-issue-labeler dotnet-issue-labeler bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Oct 28, 2023
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Oct 28, 2023
@vcsjones vcsjones added area-Extensions-Configuration source-generator Indicates an issue with a source generator feature and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Oct 28, 2023
@ghost
Copy link

ghost commented Oct 28, 2023

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

Issue Details

If a type contains no members for binding we shouldn't generator source for that. This includes the case where the only members it generates are references to itself.

Consider the following types:

public abstract class MySingleton
{
    public static MySingleton Instance {get; set;}
}
public abstract class MyNode
{
  public MyNode Next { get; set; }
}
public class MyClass
{
   // all members below are excluded
  public int[,] Matrix { get; set; }
  public Func<string, int> ParseMethod { get; set; }
}

All have no bindable members and result in useless code gen today. It's harmless - but we should try to identify these types of things through heuristics to reduce the size of the codegen. We should inform the behavior for non-abstract instance types from the runtime binder to determine if they'll be initialized or not in these cases -- I don't think they would.

Author: ericstj
Assignees: -
Labels:

untriaged, area-Extensions-Configuration, source-generator

Milestone: -

@eiriktsarpalis eiriktsarpalis added this to the 9.0.0 milestone Nov 1, 2023
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Nov 1, 2023
@eiriktsarpalis eiriktsarpalis added enhancement Product code improvement that does NOT require public API changes/additions untriaged New issue has not been triaged by the area owner and removed untriaged New issue has not been triaged by the area owner labels Nov 1, 2023
@tarekgh
Copy link
Member

tarekgh commented Nov 8, 2023

The PR #94438 should address the third case

public class MyClass
{
   // all members below are excluded
  public int[,] Matrix { get; set; }
  public Func<string, int> ParseMethod { get; set; }
}

@tarekgh tarekgh modified the milestones: 9.0.0, 10.0.0 Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Extensions-Configuration enhancement Product code improvement that does NOT require public API changes/additions source-generator Indicates an issue with a source generator feature
Projects
None yet
Development

No branches or pull requests

4 participants