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

Ensure we sync source-generator versions over properly when doing a cone-sync #73688

Merged
merged 8 commits into from
May 24, 2024

Conversation

CyrusNajmabadi
Copy link
Member

No description provided.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels May 24, 2024
}

return Checksum.Create(checksums);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a move.

AssetPathKind.SolutionSourceGeneratorExecutionVersionMap, newSolutionCompilationChecksums.SourceGeneratorExecutionVersionMap, cancellationToken).ConfigureAwait(false);

solution = solution.WithSourceGeneratorExecutionVersions(newVersions, cancellationToken);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this is something that was missing. but is also a stopgap. the right way to do things is to do teh initial bulk sync, then run the normal 'delta' sync algorithm to ensure that all checksums match. That's what #72860, but it has a problem i'm working with Jason on.


// For each project, we'll add one checksum for the project id and one for the version map.
using var _ = ArrayBuilder<Checksum>.GetInstance(2 * supportedCount, out var checksums);
public SourceGeneratorExecutionVersionMap GetFilteredSourceGenerationExecutionMap(ProjectCone? projectCone)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public SourceGeneratorExecutionVersionMap GetFilteredSourceGenerationExecutionMap(ProjectCone? projectCone)

Was this part of the change a functional fix, or something else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was very much part of the functional fix. When we're producing the checksum on the host side, we want to filter the map to what's in the cone. Then, on the oop side, we want to be able to ask for this filtered map portion. We then update that part of the OOP side with this filtered set.

checksums.Add(Checksum.Create(version, static (v, w) => v.WriteTo(w)));
}

return Checksum.Create(checksums);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checksum.Create(checksums);

a bit off topic: is the ReadOnlySpan overload of Checksum.Create more performant than the ImmutableArray/ArrayBuilder versions? If so, and not that it helps here, couldn't the ImmutableArray overload get the underlying array and use the equivalent of the readonlyspan implementation?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes. the IA version should defer to the ROS version.

That said, this is not an IA. This is an ArrayBuilder.

checksums.Add(Checksum.Create(@this.SourceGeneratorExecutionVersionMap[projectId], static (v, w) => v.WriteTo(w)));
builder.Remove(projectId);
}
else if (projectCone != null && !projectCone.Contains(projectId))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else if (projectCone != null && !projectCone.Contains(projectId))

a projectCone doesn't usually span multiple projects right? I'm just wondering whether it would be better to build this up by testing for inclusion rather than reduce this by testing for exclusion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a project-cone very often spans multiple projects. it represents a project and all the projects that project depends on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just wondering whether it would be better to build this up by testing for inclusion rather than reduce this by testing for exclusion.

that would work as well. I don't have strong feelings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a great explanation, thank you! Can you put a blurb in the code so I don't have that thought again?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review May 24, 2024 04:15
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner May 24, 2024 04:15
@CyrusNajmabadi
Copy link
Member Author

@ToddGrun @jasonmalinowski i def want to get this in today.

Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Comment on lines +130 to +131
Debug.Assert(projectCone.ProjectIds.Count == newVersions.Map.Count);
Debug.Assert(projectCone.ProjectIds.All(id => newVersions.Map.ContainsKey(id)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not have a SetEquals helper to call? This works but would be shorter/clearer.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def can clean that up in followup.

{
await solution.AppendAssetMapAsync(map, project1.Id, CancellationToken.None);
var project1Checksum = await solution.CompilationState.GetChecksumAsync(project1.Id, CancellationToken.None);
var project1SyncedSolution = await remoteWorkspace.GetTestAccessor().GetSolutionAsync(assetProvider, project1Checksum, updatePrimaryBranch: false, CancellationToken.None);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this need an extra assert?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The impl actually already asserts that the checksums are the same (and throws if not). (so this failed prior to this fix).

@CyrusNajmabadi CyrusNajmabadi merged commit 9f61479 into dotnet:main May 24, 2024
25 checks passed
@CyrusNajmabadi CyrusNajmabadi deleted the inProgress branch May 24, 2024 20:29
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone May 24, 2024
@Cosifne Cosifne modified the milestones: Next, 17.11 P2 May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants