-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Conversation
@dotnet-bot test eta please |
tag @dotnet/roslyn-compiler @dotnet/roslyn-interactive |
406e5c9
to
247b4a8
Compare
@tmat updated with a test and explicitly redirecting I had to provide another test corlib since none of the existing ones satisfied a shape like the Xamarin mobile profile corlibs:
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:
|
@dotnet-bot test eta please |
247b4a8
to
9764f6f
Compare
@tmat updated with VB patch and test, and while they both compile just fine I'm shooting in the dark:
I do not have a Windows machine readily available with a build environment 😄 |
@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. |
9764f6f
to
37882f8
Compare
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
👍 |
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? |
The failure is not likely related to this change |
@dotnet-bot retest prtest/win/dbg/unit32 please |
test this please |
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: |
FYI: #11279 |
@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. |
f2a44b3
to
3a0434d
Compare
We currently run only a small subset of tests on Mac :( |
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. |
@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. |
3a0434d
to
ffc52fa
Compare
@tmat @davkean @AlekseyTs updated again, VB and C# tests passing locally |
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.
ffc52fa
to
9b206e6
Compare
@dotnet-bot test eta please |
@tmat Can you look at the recent commits? |
👍 |
test windows_vsi_p2_open_prtest please |
LGTM. |
Yep, let's do it. |
Merging to master and porting to stabilization. |
* 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.
* 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.
@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. |
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.