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

Remove more private reflection from compiler #32257

Merged
merged 8 commits into from
Jan 16, 2019

Conversation

jaredpar
Copy link
Member

@jaredpar jaredpar commented Jan 8, 2019

This change continues the removal of private reflection code from the compiler code base and instead relying on mulit-targeting to have detect the runtime. This also necessarily cleans up a number of our #if checks in the code base.

Follow up to #31763

Use multi-target instead of reflection
This removes the remaining private reflection code from the compiler and
replaces it with multi-targeting approaches.
@jaredpar jaredpar requested review from a team as code owners January 8, 2019 23:24
@jaredpar
Copy link
Member Author

jaredpar commented Jan 8, 2019

CC @dotnet/roslyn-compiler for review

@jcouv jcouv added this to the 16.0.P3 milestone Jan 11, 2019
var expectedCompilerPath = Path.Combine(clientDir, ServerNameCoreClr);
expectedPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet";
processArguments = $@"""{expectedCompilerPath}"" ""-pipename:{pipeName}""";
var serverPathWithoutExetnsion = Path.Combine(clientDir, "VBCSCompiler");
Copy link
Member

@jcouv jcouv Jan 11, 2019

Choose a reason for hiding this comment

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

serverPathWithoutExetnsion [](start = 16, length = 26)

typo: Extension #Resolved

@@ -55,7 +56,7 @@ public enum TargetFramework

public static class TargetFrameworkUtil
{
public static MetadataReference StandardCSharpReference => CoreClrShim.IsRunningOnCoreClr ? NetStandard20.MicrosoftCSharpRef : TestBase.CSharpDesktopRef;
Copy link
Member

@jcouv jcouv Jan 11, 2019

Choose a reason for hiding this comment

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

CoreClrShim.IsRunningOnCoreClr [](start = 67, length = 30)

It looks like you're replacing all uses of CoreClrShim.IsRunningOnCoreClr. Can that API be removed then? #WontFix

Copy link
Member Author

@jaredpar jaredpar Jan 11, 2019

Choose a reason for hiding this comment

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

No. Scripting still uses it and pulling it out from there is a lot of work. It's on my list but wanted it to be a separate change as it's likely a bit of refactoring. #WontFix

_culture = new Lazy<CultureInfo>(() => new CultureInfo(culture, useUserOverride: false));
_uiCulture = new Lazy<CultureInfo>(() => new CultureInfo(uiCulture, useUserOverride: false));
#elif NETCOREAPP2_1
_culture = new Lazy<CultureInfo>(() => new CultureInfo(culture));
Copy link
Member

@jcouv jcouv Jan 11, 2019

Choose a reason for hiding this comment

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

)); [](start = 74, length = 3)

We used to have a distinction of useUserOverride: being true or false. Did something change that allows us to no longer care? #ByDesign

Copy link
Member Author

@jaredpar jaredpar Jan 11, 2019

Choose a reason for hiding this comment

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

The original code here preferred the useUserOverride: false approach. But when we went to netcoreapp1.1 originally that overload wasn't present and we were forced to pick a different one. Now with netcoreapp2.1 the overload is back and we can go with our original preferred approach. #ByDesign

/// This gets information about invoking a tool on the current runtime. This will attempt to
/// execute a tool as an EXE when on desktop and using dotnet when on CoreClr.
/// </summary>
internal static (string ProcessFilePath, string CommandLineArguments, string ToolFilePath) GetProcessInfo(string toolFilePathWithoutExtension, string commandLineArguments)
Copy link
Member

@jcouv jcouv Jan 11, 2019

Choose a reason for hiding this comment

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

ProcessFilePath [](start = 32, length = 15)

nit: tuple names should be lower-cased (parallel with parameter names) #Resolved

Debug.Assert(!toolFilePathWithoutExtension.EndsWith(".dll") && !toolFilePathWithoutExtension.EndsWith(".exe"));

var toolFilePath = $"{toolFilePathWithoutExtension}.{ToolExtension}";
if (IsDotnetHost(out string pathToDotNet))
Copy link
Member

@jcouv jcouv Jan 11, 2019

Choose a reason for hiding this comment

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

nit: Dotnet vs. DotNet. This line has both conventions #Resolved

Copy link
Member Author

@jaredpar jaredpar Jan 11, 2019

Choose a reason for hiding this comment

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

I've confirmed that Dotnet is preferred. Will use that. #Resolved

/// Get the path to the dotnet executable. In the case the host did not provide this information
/// in the environment this will return simply "dotnet".
/// </summary>
internal static string GetDotnetPathOrDefault()
Copy link
Member

@jcouv jcouv Jan 11, 2019

Choose a reason for hiding this comment

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

internal [](start = 8, length = 8)

private? #Resolved

/// Get the path to the dotnet executable. This will throw in the case it is not properly setup
/// by the environment.
/// </summary>
internal static string GetDotnetPath()
Copy link
Member

@jcouv jcouv Jan 11, 2019

Choose a reason for hiding this comment

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

internal [](start = 8, length = 8)

private?
Same comment for IsDotnetHost and DotnetHostPathEnvironmentName above

Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM Thanks (iteration 6)

@jcouv jcouv self-assigned this Jan 11, 2019
@jaredpar
Copy link
Member Author

@roslyn-compiler could I get one more review here?

After more searching it is clear that DotNet is preferred in API
signatures over Dotnet. Easy to see when you look at the reference
source

https://referencesource.microsoft.com/#q=dotnet
<Compile Include="..\..\Shared\NamedPipeUtil.cs" />
<Compile Include="..\..\Shared\BuildClient.cs">
<Link>BuildClient.cs</Link>
Copy link
Contributor

Choose a reason for hiding this comment

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

This is documented in https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-items?view=vs-2017 as follows:
Link | Optional string. The notational path to be displayed when the file is physically located outside the influence of the project file.

Does this mean this only affects the build logs, not the behavior?

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 unsure if it affects the build logs or not but it does affect the UI in Visual Studio. You can use this field to change how the file is displayed, and in what folder, in the VS solution explore.

@jaredpar jaredpar merged commit 9e012fe into dotnet:master Jan 16, 2019
@jaredpar jaredpar deleted the fix-reflection branch January 16, 2019 19:31
jaredpar added a commit to jaredpar/roslyn that referenced this pull request Feb 18, 2019
The name for the named pipe used between MSBuild and VBCSCompiler is
generated from a combination of values including the current user name,
specifically `%USERNAME%`. It is possible for this value to have spaces
in it and hence the argument must be quoted when passing it to the
command line of VBCSCompiler instances.

Regression initially introduced: dotnet#32257
jaredpar added a commit to jaredpar/roslyn that referenced this pull request Feb 18, 2019
The name for the named pipe used between MSBuild and VBCSCompiler is
generated from a combination of values including the current user name,
specifically `%USERNAME%`. It is possible for this value to have spaces
in it and hence the argument must be quoted when passing it to the
command line of VBCSCompiler instances.

Regression initially introduced: dotnet#32257
xoofx pushed a commit to stark-lang/stark-roslyn that referenced this pull request Apr 16, 2019
Remove more private reflection from compiler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants