Skip to content

Fix rebuild round trip in unit tests#51877

Merged
jaredpar merged 5 commits intodotnet:mainfrom
jaredpar:roundtrip
Mar 18, 2021
Merged

Fix rebuild round trip in unit tests#51877
jaredpar merged 5 commits intodotnet:mainfrom
jaredpar:roundtrip

Conversation

@jaredpar
Copy link
Member

This changes the rebuild unit tests to fully round trip the
Compilation they are building and verify the output byte for byte
matches the input.

Issue #51873 discovered working on the change

Note: this PR builds off of the changes in #51852 so make sure to review the last commit only here.

@jaredpar jaredpar added Area-Compilers Feature - Rebuild Compiler ability to verify provenance of code via rebuild operations labels Mar 15, 2021
@jaredpar jaredpar requested a review from RikkiGibson March 15, 2021 03:07
@jaredpar jaredpar requested review from a team as code owners March 15, 2021 03:07
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldn't need to pass a logger [](start = 17, length = 31)

Could we implement a simple ILogger that drops all log statements and use that here if logger == null?

Copy link
Member Author

Choose a reason for hiding this comment

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

We could but the goal is to just delete this field from the type entirely. I came close to making that change in this PR but decided to hold back and save it for another.

This changes the rebuild unit tests to fully round trip the
`Compilation` they are building and verify the output byte for byte
matches the input.

Issue dotnet#51873 discovered working on the change
The parse options weren't correctly being hooked up to the
`CompilationOptions` and that was breaking round tripping

closes dotnet#51873
@RikkiGibson RikkiGibson self-assigned this Mar 16, 2021
cancellationToken);
}

public static unsafe EmitResult Emit(
Copy link
Member

@RikkiGibson RikkiGibson Mar 16, 2021

Choose a reason for hiding this comment

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

Should we make this overload 'internal' or perhaps even 'private'?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure.

bool Debug,
string DebugPath);

internal record ResolvedSource(
Copy link
Member

Choose a reason for hiding this comment

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

I think I'm getting a little lost in the usage of these records:

  • ResolvedSource
  • SourceFileInfo
  • SyntaxTreeInfo

Could you please clarify why it's necessary to have all 3?

Copy link
Member Author

Choose a reason for hiding this comment

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

At the BuildConstructor level there is a need to essentially to pass down a tuple of (string FilePath, SourceText Text) to the language specific routine so that it can generate a SyntaxTree.

Before my change ResolvedSource served that purpose because we were only driving this operation from the BuildValidator tool. The ResolvedSource type is used for resolving source locations on disk, it contains the information necessary for creating SyntaxTree in BuildConstructor and hence it was used.

From the library / unit test layer though the ResolvedSource type contains a lot of unnecessary information for generating SyntaxTree. The caller needs to think about items like embedding, hashes, etc ... None of which is actually necessary to generate the SyntaxTree. I toyed for a bit with a pattern of having a method called CreateSyntaxTree(string filePath, SourceText sourceText) on BuildConstructor but that didn't feel right at this time. May be right later though when we get further into the abstractions.

Hence I decided to simplify and introduce SyntaxTreeInfo for the moment. I think it makes it clearer what the actual dependencies are for this layer.

As for why we need ResolvedSource and SourceFileInfo it's because one specifies what to retrieve and the other what was retrieved. It's possible we could get to a point where we don't need one of them but at the moment there didn't seem to be a clear way.

@jaredpar
Copy link
Member Author

@RikkiGibson, @cston any other feedback I need to take care of here?

@jaredpar jaredpar merged commit 77920cd into dotnet:main Mar 18, 2021
@ghost ghost added this to the Next milestone Mar 18, 2021
@jaredpar jaredpar deleted the roundtrip branch March 18, 2021 16:46
@allisonchou allisonchou modified the milestones: Next, 16.10.P2 Mar 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Feature - Rebuild Compiler ability to verify provenance of code via rebuild operations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants