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

Added InterleaveFields source generator. #982

Merged
merged 10 commits into from
Jan 19, 2024

Conversation

MoFtZ
Copy link
Collaborator

@MoFtZ MoFtZ commented Apr 8, 2023

This PR adds support for generating a structure of arrays from a struct.

When the [GeneratedStructutreOfArrays] attribute is added to a partial struct, the source generator will populate the field members.

// Example:
public struct MyPoint
{
    public int X;
    public int Y;
}

[GeneratedStructureOfArrays(typeof(MyPoint), 4)]
partial struct MyPoint4
{ }

// Will generate:
unsafe partial struct MyPoint4
{
    public fixed int X[4];
    public fixed int Y[4];
}

The source generator is also able to expand inner structures as necessary.

// Example:
public struct MyPoint
{
    public int X;
    public int Y;
    public InnerStruct Z;
}

public unsafe struct InnerStruct
{
    public fixed int A[4];
    public fixed int B[2];
}

[GeneratedStructureOfArrays(typeof(MyPoint), 4)]
partial struct MyPoint4
{ }

// Will generate:
unsafe partial struct MyPoint4
{
    public fixed int X[4];
    public fixed int Y[4];
    public fixed int Z_A[16];
    public fixed int Z_B[8];
}

@MoFtZ MoFtZ force-pushed the feature/analyzers branch 17 times, most recently from d85e823 to 10bc2c0 Compare April 9, 2023 04:18
@m4rs-mt m4rs-mt added the feature A new feature (or feature request) label Apr 12, 2023
@m4rs-mt m4rs-mt added this to the v1.5 milestone Apr 12, 2023
@MoFtZ MoFtZ marked this pull request as draft April 26, 2023 11:39
@MoFtZ
Copy link
Collaborator Author

MoFtZ commented Apr 26, 2023

Converted to draft, until we can decide on a better name for the marker attribute.

@Yey007
Copy link
Contributor

Yey007 commented May 12, 2023

@MoFtZ Did we come to a conclusion on this? Are we going with GeneratedInterleavingStruct as you had suggested a couple of meetings ago? Or perhaps Interleaved or InterleavedStructure?

@MoFtZ
Copy link
Collaborator Author

MoFtZ commented May 12, 2023

InterleaveFields is the current candidate. But I haven't had the time to refactor the PR yet.

@MoFtZ MoFtZ changed the title Added StructureOfArrays source generator. Added InterleaveFields source generator. Jan 8, 2024
@MoFtZ MoFtZ marked this pull request as ready for review January 8, 2024 10:26
@MoFtZ MoFtZ force-pushed the feature/analyzers branch from 78d0144 to c94f33a Compare January 10, 2024 23:08
@m4rs-mt m4rs-mt merged commit c87b037 into m4rs-mt:master Jan 19, 2024
50 checks passed
@MoFtZ MoFtZ deleted the feature/analyzers branch January 19, 2024 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature (or feature request)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants