Extract portable/managed code from Array for sharing with Mono and CoreCLR#3201
Extract portable/managed code from Array for sharing with Mono and CoreCLR#3201MichalStrehovsky merged 2 commits intodotnet:masterfrom
Conversation
477dc78 to
1884826
Compare
|
In keeping with our filenaming conventions (https://github.com/dotnet/corert/blob/master/src/System.Private.CoreLib/shared/README.md), please rename... Array.Portable.cs => Array.cs Thanks! |
|
Array.Initialize() is not functioning on CoreRt and is inherently unportable. It should stay in the non-portable partition. |
| // Project N port note: On the desktop, this api is a nop unless the array element type is a value type with | ||
| // an explicit nullary constructor. Such a type cannot be expressed in C# so Project N does not support this. | ||
| // The ILC toolchain fails the build if it encounters such a type. | ||
| return; |
There was a problem hiding this comment.
This won't be sharable once CoreRT implements the right semantics.
There was a problem hiding this comment.
Moved to CoreRT version
| int endIndex = startIndex + count; | ||
|
|
||
| // See comment above Array.GetComparerForReferenceTypesOnly for details | ||
| EqualityComparer<T> comparer = GetComparerForReferenceTypesOnly<T>(); |
There was a problem hiding this comment.
Places that call GetComparerForReferenceTypesOnly rely on deep compiler magic that is not even portable between our two CoreRT compilers right now.
There was a problem hiding this comment.
Moved to CoreRT version
There was a problem hiding this comment.
There are still places in Array.cs left that call into this.
| Array.CopyImplReferenceArrayToValueTypeArray(objItems, index, items, index, length, reliable: false); | ||
| } | ||
| #else | ||
| Object[] objKeys = keys as Object[]; |
There was a problem hiding this comment.
This is going to break us on the TFS side because Project N (the AOT compiler for Universal Windows Apps) doesn't define CORERT.
There was a problem hiding this comment.
That something we should fix.
- CORERT - defined in both TFS side and GitHub side
- PROJECTN - defined in TFS only
For now, any ifdefs need to be #if CORERT || PROJECTN.
There was a problem hiding this comment.
Or even better - move anything with ifdefs to the non-portable part.
There was a problem hiding this comment.
Moved to CoreRT part
| { | ||
| if (_index < 0) throw new InvalidOperationException(SR.InvalidOperation_EnumNotStarted); | ||
| if (_index >= _endIndex) throw new InvalidOperationException(SR.InvalidOperation_EnumEnded); | ||
| return _array.GetValueWithFlattenedIndex_NoErrorCheck(_index); |
There was a problem hiding this comment.
ArrayEnumerator differs from CoreCLR at this place (we avoid a bunch of checks this way), but it makes the enumerator rather non-portable (see my pending change to it in #3192).
There was a problem hiding this comment.
This should not matter as GetValueWithFlattenedIndex_NoErrorCheck is in implementation specific part
There was a problem hiding this comment.
Yeah, but as the name suggest, it doesn't do error checking, which means it doesn't check if the element type is an unmanaged pointer. If I get my #3192 signed off before you do your pull request, it won't be portable...
There was a problem hiding this comment.
There was a problem hiding this comment.
CoreRT limitation ?
You can't call get_Current on the enumerator of e.g. int*[]. I would think Mono blocks this too (CLR does). Pointer types cannot be boxed.
There was a problem hiding this comment.
moved it to CoreRT part
|
You should probably compare each method with the CoreCLR version before putting in in the shared part. Even if the code compiles and runs, you may lose optimizations that CoreRT wasn't able to take advantage of (in particular, around the sorting and searching apis where CoreRT was hobbled by the inability to create generic instantiations on the fly with assurance of success.) There's also the "throw" vs. ThrowHelper issue (another optimization thing on CoreCLR.) |
|
@atsushikan files renamed I'll leave it to CoreCLR folks to decide what to do with ThrowHelper optimization |
We should deal with that separately from this PR - once we actually move it to the shared partition. |
|
I can't comment on the diff because this is unchanged, but private static bool StructOnlyEquals<T>(T left, T right)Is the same kind of deep compiler magic as It also seems like we don't need |
2c6262c to
90fe366
Compare
|
If you make your change a rename Array.cs -> Array.CoreRT.cs followed by starting a new Array.cs from scratch, it should merge clean with the pull request I just merged. The interesting parts (and majority of the code) is in Array.CoreRT.cs so that's where I would want to see uninterrupted history anyway. |
99f5538 to
efdb06e
Compare
666ebb7 to
241f8bd
Compare
|
@MichalStrehovsky Done. Although I could move the new common bits to shared and avoid the rename altogether |
|
@marek-safar The I'm not sure if it's worth having I don't know what the policy is for moves to /shared/ (do we need to follow more cleanup rules?). I'm not opposed to it, but I've been detached from those efforts. @jkotas? Other than that, looks good! Thanks! |
The best way to do it is to do similar refactoring in both CoreCLR and CoreRT, so that the file being moved is same or pretty close in both. Then move the file to shared in one repo, wait for the automatic PR to get generated in the other repo and amend it with a commit to delete the unshared copy of the file in other repo. I do not think it makes sense to move Array.cs to shared as part of this PR. |
…oreCLR Includes few missing GetLowerBound calls from CoreCLR version
|
@MichalStrehovsky moved both to CoreRT version |
|
@dotnet-bot test OSX Release |
Includes few missing GetLowerBound calls from CoreCLR version