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

Compilation: use System.Object from target corlib #8507

Merged
merged 3 commits into from
Jun 2, 2016

Conversation

abock
Copy link
Contributor

@abock abock commented Feb 9, 2016

When creating a script compilation without an explicit return type, System.Object was being resolved via reflection from the host.

This resulted in an implicit dependency of a script compilation on the host corlib, even if a different corlib was specified as a reference for the compilation (e.g. Xamarin.iOS).

Fix this by using System.Object as defined in the corlib resolved for the compilation.

This fixes #8506.

@davkean davkean added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Feb 10, 2016
@davkean
Copy link
Member

davkean commented Feb 10, 2016

@dotnet-bot test eta please
@dotnet-bot test vsi please

@davkean
Copy link
Member

davkean commented Feb 10, 2016

tag @dotnet/roslyn-compiler @dotnet/roslyn-interactive

@ManishJayaswal ManishJayaswal added this to the 1.3 milestone Feb 10, 2016
@abock abock force-pushed the system-object-from-comp-corlib branch from 406e5c9 to 247b4a8 Compare February 10, 2016 06:20
@abock
Copy link
Contributor Author

abock commented Feb 10, 2016

@tmat updated with a test and explicitly redirecting typeof(object).

I had to provide another test corlib since none of the existing ones satisfied a shape like the Xamarin mobile profile corlibs:

  • assembly version cannot be 4.0.0.0 (Xamarin mobile corlibs are 2.0.5.0)
  • must provide Task.GetAwaiter(), Task<T> {}, and TaskAwaiter.GetResult() stubs to support the script host

I will update this PR again with the VB side later.

Without the fix, the test fails as it did for me realistically as when cross compiling for Xamarin.iOS:

Microsoft.CodeAnalysis.CSharp.UnitTests.CompilationAPITests.CrossCorlibSystemObjectReturnType_Script [FAIL]

Expected:
Actual:
// error CS0400: The type or namespace name 'System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' could not be found in the global namespace (are you missing an assembly reference?)
Diagnostic(ErrorCode.ERR_GlobalSingleTypeNameNotFound).WithArguments("System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089").WithLocation(1, 1)
Diff:
++>     Diagnostic(ErrorCode.ERR_GlobalSingleTypeNameNotFound).WithArguments("System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089").WithLocation(1, 1)
Expected: True
Actual:   False
Stack Trace:
<filename unknown>(0,0): at Microsoft.CodeAnalysis.DiagnosticExtensions.Verify (IEnumerable`1 actual, Microsoft.CodeAnalysis.Test.Utilities.DiagnosticDescription[] expected, Boolean errorCodeOnly)
<filename unknown>(0,0): at Microsoft.CodeAnalysis.DiagnosticExtensions.Verify (IEnumerable`1 actual, Microsoft.CodeAnalysis.Test.Utilities.DiagnosticDescription[] expected)
<filename unknown>(0,0): at Microsoft.CodeAnalysis.DiagnosticExtensions.Verify (ImmutableArray`1 actual, Microsoft.CodeAnalysis.Test.Utilities.DiagnosticDescription[] expected)
<filename unknown>(0,0): at Microsoft.CodeAnalysis.DiagnosticExtensions.VerifyDiagnostics[TCompilation] (Microsoft.CodeAnalysis.TCompilation c, Microsoft.CodeAnalysis.Test.Utilities.DiagnosticDescription[] expected)
<filename unknown>(0,0): at Microsoft.CodeAnalysis.CSharp.UnitTests.CompilationAPITests.CrossCorlibSystemObjectReturnType_Script ()
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
<filename unknown>(0,0): at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture)

@davkean
Copy link
Member

davkean commented Feb 10, 2016

@dotnet-bot test eta please
@dotnet-bot test vsi please

@abock abock force-pushed the system-object-from-comp-corlib branch from 247b4a8 to 9764f6f Compare February 10, 2016 07:05
@abock
Copy link
Contributor Author

abock commented Feb 10, 2016

@tmat updated with VB patch and test, and while they both compile just fine I'm shooting in the dark:

  • this is the first VB I've ever written
  • the VB tests do not seem to run at all (even if I fiddle with build/scripts/tests.sh) on Mac. Seems every test fails

I do not have a Windows machine readily available with a build environment 😄

@abock
Copy link
Contributor Author

abock commented Feb 10, 2016

@tmat also FYI, if you comment on the PR diff itself (Files changed tab) instead of individual commits (Commits tab) then comments will stick around in the PR when pushing a rebased patch.

@abock abock force-pushed the system-object-from-comp-corlib branch from 9764f6f to 37882f8 Compare February 10, 2016 23:03
@abock
Copy link
Contributor Author

abock commented Feb 10, 2016

rebased to fix merge conflict with master

// corlib's System.Object. This allows cross compiling scripts to build on one
// corlib and run on another.
// cf. https://github.com/dotnet/roslyn/issues/8506
resultType = submissionReturnType == typeof(object)
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels to me that compilation.GetTypeByReflectionType should locate proper symbol without a need to special case System.Object. Otherwise, why other special types not special cased (System.Int32, for example)? Perhaps submissionReturnType is set to the wrong Type instance, perhaps that is what should be fixed?

Copy link
Member

Choose a reason for hiding this comment

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

This is the right approach. We only handle system.object here because typeof(object) is filled in by default if the host doesn't specify the type. If the host specifies a rutnime type explicitly it has to match the corresponding type in referenced metadata exactly.

Copy link
Contributor

Choose a reason for hiding this comment

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

It sounds like we would want the code to fail if host specified typeof(object) explicitly, but with this change the code would succeed. I would suggest to change the line

var submissionReturnType = compilation.SubmissionReturnType ?? typeof(object);

to not overwrite null with typeof(object) and base the current logic on whether submissionReturnType is null instead.

Copy link
Member

Choose a reason for hiding this comment

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

@AlekseyTs brings up a good point. We can change ScriptCompilationInfo like so:

public Type ReturnType => ReturnTypeOpt ?? typeof(object);
internal Type ReturnTypeOpt { get; }

internal ScriptCompilationInfo(Type returnType, Type globalsType)
{
      ReturnTypeOpt = returnType;
      GlobalsType = globalsType;
}

and then in CalculateReturnType we can replace the first line with

var submissionReturnTypeOpt = compilation.ScriptCompilationInfo.ReturnTypeOpt;

and avoid equality check with typeof(object).

Note that ScriptCompilationInfo should always be non-null here, since the method is only used for compiling submissions.

@tmat
Copy link
Member

tmat commented Feb 11, 2016

👍

@davkean
Copy link
Member

davkean commented Feb 11, 2016

Both unit64/unit32 timed out here, with a deadlock in Roslyn.Compilers.CSharp.Symbol.UnitTests.dll. Unfortunately, we don't have dumps as our infrastructure isn't setup to catch them.

These look like real failures. Do you have a Windows machine to repro this locally?

@tmat
Copy link
Member

tmat commented Feb 11, 2016

The failure is not likely related to this change

@tmat
Copy link
Member

tmat commented Feb 12, 2016

@dotnet-bot retest prtest/win/dbg/unit32 please
// Previous failure: http://dotnet-ci.cloudapp.net/job/roslyn_prtest_win_dbg_unit32/3644/
// Retest reason:

@tmat
Copy link
Member

tmat commented Feb 12, 2016

test this please

@tmat tmat closed this Feb 12, 2016
@tmat tmat reopened this Feb 12, 2016
@abock
Copy link
Contributor Author

abock commented Feb 16, 2016

Just an FYI, I haven't been able to get back to this until now. I'll come back to this PR to encapsulate the rest of the feedback sometime this week.

I have set up a Windows build environment and was able to test the patch as-is just fine. No local failures. Subsequently, I opened a new PR to fix the test runner invocation:

#8744

@tmat
Copy link
Member

tmat commented May 12, 2016

FYI: #11279

@abock
Copy link
Contributor Author

abock commented May 12, 2016

@tmat cool, thanks, I'll fix that. I was not able to see the failure locally (Mac) and on CI there was nothing obvious - just timing out.

@abock abock force-pushed the system-object-from-comp-corlib branch from f2a44b3 to 3a0434d Compare May 12, 2016 23:24
@tmat
Copy link
Member

tmat commented May 12, 2016

We currently run only a small subset of tests on Mac :(

@abock
Copy link
Contributor Author

abock commented May 13, 2016

Okay, now the failures are legitimate and sensible, but look like the result of taking a previous comment's change suggestion into account. I'll get back to a Windows machine tomorrow to take a look.

@jasonmalinowski
Copy link
Member

@tmat: failed assertions should be throwing exceptions instead of popping dialogs. This thread is long and windy and not quite sure what I can look at to see what you're seeing.

@tmat
Copy link
Member

tmat commented May 13, 2016

@abock abock force-pushed the system-object-from-comp-corlib branch from 3a0434d to ffc52fa Compare June 1, 2016 01:13
@abock
Copy link
Contributor Author

abock commented Jun 1, 2016

@tmat @davkean @AlekseyTs updated again, VB and C# tests passing locally

abock added 2 commits May 31, 2016 21:35
This combines the async features of minasync with mincorlib to produce
a minimum unversioned corlib with async stubs.
When creating a script compilation without an explicit return type,
System.Object was being resolved via reflection from the host.

This resulted in an implicit dependency of a script compilation on the
host corlib, even if a different corlib was specified as a reference
for the compilation (e.g. Xamarin.iOS).

Fix this by using System.Object as defined in the corlib resovled
for the compilation.
@abock abock force-pushed the system-object-from-comp-corlib branch from ffc52fa to 9b206e6 Compare June 1, 2016 01:35
@davkean
Copy link
Member

davkean commented Jun 1, 2016

@dotnet-bot test eta please
@dotnet-bot test vsi please

@davkean
Copy link
Member

davkean commented Jun 1, 2016

@tmat Can you look at the recent commits?

@tmat
Copy link
Member

tmat commented Jun 1, 2016

👍

@tmat
Copy link
Member

tmat commented Jun 1, 2016

test windows_vsi_p2_open_prtest please

@AlekseyTs
Copy link
Contributor

LGTM.
@ManishJayaswal If we want this change to go to Update 3, we need to get Ask mode approval and retarget this change to stabilization.

@MattGertz
Copy link
Contributor

Yep, let's do it.

@tmat
Copy link
Member

tmat commented Jun 2, 2016

Merging to master and porting to stabilization.

@tmat tmat merged commit c073826 into dotnet:master Jun 2, 2016
tmat pushed a commit to tmat/roslyn that referenced this pull request Jun 2, 2016
* Tests: fix minasync Task<T> to derive from Task

* Tests: provide MinAsyncCorlibRef

This combines the async features of minasync with mincorlib to produce
a minimum unversioned corlib with async stubs.

* Compilation: use System.Object from target corlib

When creating a script compilation without an explicit return type,
System.Object was being resolved via reflection from the host.

This resulted in an implicit dependency of a script compilation on the
host corlib, even if a different corlib was specified as a reference
for the compilation (e.g. Xamarin.iOS).

Fix this by using System.Object as defined in the corlib resovled
for the compilation.
tmat added a commit that referenced this pull request Jun 2, 2016
* Tests: fix minasync Task<T> to derive from Task

* Tests: provide MinAsyncCorlibRef

This combines the async features of minasync with mincorlib to produce
a minimum unversioned corlib with async stubs.

* Compilation: use System.Object from target corlib

When creating a script compilation without an explicit return type,
System.Object was being resolved via reflection from the host.

This resulted in an implicit dependency of a script compilation on the
host corlib, even if a different corlib was specified as a reference
for the compilation (e.g. Xamarin.iOS).

Fix this by using System.Object as defined in the corlib resovled
for the compilation.
@davkean
Copy link
Member

davkean commented Jun 2, 2016

@abock Know that this was a long effort, but thanks a lot for the contribution! Hope this means you can move to public bits, instead of privately built bits.

@abock
Copy link
Contributor Author

abock commented Jun 2, 2016

@davkean thanks! We will definitely now be able to take builds directly from upstream with this patch now landed.

Thanks @tmat as well!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved to merge Area-Compilers cla-already-signed Community The pull request was submitted by a contributor who is not a Microsoft employee.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Script compilations not specifying a return type take an implicit dependency on the host corlib
9 participants