Skip to content

Rebuild extern aliases#52321

Merged
jaredpar merged 3 commits intodotnet:mainfrom
jaredpar:alias
Apr 6, 2021
Merged

Rebuild extern aliases#52321
jaredpar merged 3 commits intodotnet:mainfrom
jaredpar:alias

Conversation

@jaredpar
Copy link
Member

The portable PDB writing code was not properly encoding external
aliases. They were being ignored since they aren't included in the
CommonReferenceManager as the code expected. Convertd to a more direct
way of grabbing the PEReader value and properly encoded the modules

The portable PDB writing code was not properly encoding external
aliases. They were being ignored since they aren't included in the
`CommonReferenceManager` as the code expected. Convertd to a more direct
way of grabbing the `PEReader` value and properly encoded the modules
@jaredpar jaredpar added Area-Compilers Feature - Rebuild Compiler ability to verify provenance of code via rebuild operations labels Mar 31, 2021
@jaredpar jaredpar requested a review from a team as a code owner March 31, 2021 23:27
@jaredpar
Copy link
Member Author

@dotnet/roslyn-compiler PTAL

Add(Permutate(new CommandInfo("hw.cs /target:exe /debug:embedded", "test.exe", null)));
Add(Permutate(new CommandInfo("lib1.cs /target:library /debug:embedded", "test.dll", null)));
Add(Permutate(new CommandInfo("lib2.cs /target:library /r:SystemRuntime=System.Runtime.dll /debug:embedded", "test.dll", null)));
Add(Permutate(new CommandInfo("lib3.cs /target:library /r:SystemRuntime1=System.Runtime.dll /r:SystemRuntime2=System.Runtime.dll /debug:embedded", "test.dll", null)));
Copy link
Contributor

Choose a reason for hiding this comment

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

/r:SystemRuntime2=System.Runtime.dll [](start = 104, length = 36)

Would it make sense to reference two different versions of System.Runtime.dll, so it's clear that references in the rebuilt binary are to the expected versions?

Copy link
Member Author

Choose a reason for hiding this comment

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

The case I'm interested in testing here is when it refers to the same DLL

return metadataReference.Properties.Aliases.Length == 1
? metadataReference.Properties.Aliases[0]
: null;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing with metadataReference.Properties.Aliases.SingleOrDefault().

@jaredpar jaredpar requested a review from a team as a code owner April 1, 2021 18:35
imageSize,
name,
mvid,
alias == "global" ? null : alias,
Copy link
Member

Choose a reason for hiding this comment

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

does this constant live anywhere in the compiler that we can reference from here?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I could find and I couldn't find a place that made sense as a place to define so that it would be usable across all the layers of the compiler.

public readonly FileInfo FileInfo;
public readonly Guid Mvid;
public readonly ImmutableArray<string> ExternAliases;
public readonly string? ExternAlias;
Copy link
Member

Choose a reason for hiding this comment

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

why did we delay splitting the alias names?

Copy link
Member Author

Choose a reason for hiding this comment

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

My guess is that the original implementation attempted to represent extern aliases in the same way that MSBuild does. Essentially there is one reference with a collection of aliases. In reality though the compiler ends up representing it more as a 1-1 mapping by the time you get to the command line. This change better reflects the compiler representation and is more suited to reubild scenarios.

properties: new MetadataReferenceProperties(
kind: MetadataImageKind.Assembly,
aliases: reference.ExternAliases,
aliases: reference.ExternAlias is null ? ImmutableArray<string>.Empty : ImmutableArray.Create(reference.ExternAlias),
Copy link
Member

Choose a reason for hiding this comment

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

Isn't the property ExternAlias of type string, meaning this expression will create an array of a single alias even if multiple comma-separated aliases are present?

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 code will maintain the pattern of a 1:1 relationship between extern alias and the reference. That is how the compiler actually represents extern aliases internally. The fact that the property back on MetadataReference has a collection of aliases is a red herring. It may be useful in API driven scenarios (have not checked) but in the command line scenario it is always a 1:1 relationship.

It is a very confusing detail and the majority of my time in this change was understanding this relationship.

@jaredpar jaredpar merged commit 262dbad into dotnet:main Apr 6, 2021
@ghost ghost added this to the Next milestone Apr 6, 2021
@jaredpar jaredpar deleted the alias branch April 6, 2021 04:16
@dibarbet dibarbet modified the milestones: Next, 16.10.P3 Apr 26, 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