Commit Graph
113703 Commits
Author SHA1 Message Date
David Wrighton c1cd92075c Convert CreateSpan test to IL 2021-11-01 16:51:56 -07:00
David Wrighton 4421a82954 Fix CreateSpan in R2R code generation 2021-11-01 16:45:15 -07:00
Vladimir Sadov 1bca35bdd5 [hackathon] ValueArray - a compliment type to the Span, which owns its data without indirections. (#60519)
* ValueArray<T> that has its field repeated 64 times

* Update ValueArray API, add range checks.

* less hacky ValueArray detection

* Use MD array to encode Length

* Tweak ValueArray so that range checks could be inlined/omitted by JIT

* comments

* Make the Element0 field private

* Make API more similar to Span.

* add a proper test

* Add a field test

* bug fixes

* Value semantics should consider all elements.

* Hide `GetPinnableReference` per convention, since it is for use in `fixed` statements.

* Add a test for use with pointers/fixed

* A few test fixes to match the changes.

* Disable ValueArray tests on mono until implemented.
2021-10-21 09:51:59 -07:00
Aleksey Kliger (λgeek) 04213c5280 Merge pull request #60489 from lambdageek/hack-mono-byref-byref-clean
[hack] Mono byref of byref support
2021-10-18 10:14:02 -04:00
Stephen Toub 9ce5ad3587 Experiment with Roslyn optimization for ROS<T> in assembly data section (#60327)
Rolls it out to most static readonly T[] fields initialized to only const values.  This will tank perf until Roslyn optimizes these.
2021-10-17 20:46:35 -04:00
David Wrighton 2a07030e0c Most static initialization data fields are of a structure type, but it is legal for them to be of a primitive type. Fix the CreateSpan intrinsic to handle that case (#60525) 2021-10-17 14:28:51 -07:00
David Wrighton 5e6dafe03a Fix issue where no xunit based tests can run (#60522) 2021-10-17 14:03:42 -07:00
David Wrighton 758750cb0f Fix CreateSpan build failure (#60510) 2021-10-16 18:30:36 -07:00
Aaron Robinson 4b28fe9e86 [hackathon] Implement CreateSpan<T> intrinsic. (#60498)
* Implement CreateSpan<T> intrinsic.
2021-10-15 17:35:26 -07:00
Aleksey Kliger 946cd23dc3 [metadata] Implement type inflation for byref of byref 2021-10-15 15:54:35 -04:00
Aleksey Kliger 3a99d34051 [mono] If a generic struct is instantiated with byref or byreflike, make it byreflike
Match CoreCLR behavior
2021-10-15 15:54:35 -04:00
Aleksey Kliger 9ac5e87b89 Add FIXME to make generic valuetypes byreflike if instantiated with byref or byreflike 2021-10-15 15:54:34 -04:00
Aleksey Kliger 0897e26fcf [metadata] add FIXME and a byref case to type inflation 2021-10-15 15:54:34 -04:00
Aleksey Kliger 684899aee4 [metadata] Allow generics of typedbyref and of IsByRefLike
Only `void` is bad now
2021-10-15 15:54:34 -04:00
Aleksey Kliger cef5ad1755 [reflection] Implement RuntimeTyhpe.MakeByRefType icall for byref of byref 2021-10-15 15:54:34 -04:00
Aleksey Kliger fe4546f335 make mono_type_get_object_checked work with byref of byref 2021-10-15 15:54:34 -04:00
Aleksey Kliger fcc7da3749 Add MONO_TYPE_REF cases in a few places
most importantly in formmating utils, type equivalence and hashing
2021-10-15 15:54:34 -04:00
Aleksey Kliger 2fef584074 Add mono_class_is_byref 2021-10-15 15:54:34 -04:00
Aleksey Kliger 9442ff41d0 fix infinite loop in mono_class_from_mono_type2 on byref of byref 2021-10-15 15:54:34 -04:00
Aleksey Kliger 8d53c142eb [reflection] Allow MakeByRefType to work on byrefs 2021-10-15 15:54:34 -04:00
Aleksey Kliger f2d3fd8f5b [metadata] parse byref of byref
There are some problems here with custom modifier placement.  We don't track
the order of byref and modopt/modreq, so all the custom modifiers collapse on
the innermost type.
2021-10-15 15:53:09 -04:00
Aaron RobinsonandDavid Wrighton 45e5a74c00 Add non-intrinsic implementation for CreateSpan<T>. (#60451)
* Add non-intrinsic implementation for CreateSpan<T>.

* Validate RVA field for Span<T>

Co-authored-by: David Wrighton <[email protected]>
2021-10-15 10:59:31 -07:00
Aleksey Kliger c4c347723e [metadata] Add mono_class_create_byref to create managed pointer types
We would like for "byref"/"&"/"managed pointer" to be just a normal MonoClass
like unmanaged pointers ("*") are.

One complication is that MonoType is not well-suited to representing multiple
levels of byref.

The solution is to make things more complicated.

Previously `MONO_TYPE_BYREF` was not used in MonoType:type.  Now it is allowed.
But we don't use it for int& or MyClass&. Those are still represented as the
underlying type (MONO_TYPE_I4, MONO_TYPE_CLASS, etc) with the MonoType:byref__
bit set.

We only use `MONO_TYPE_BYREF` for multiple levels of byref.  So int&& is:
  MonoType int_ref = {0};
  int_ref.type = MONO_TYPE_I4;
  int_ref.byref__ = TRUE;

  MonoType int_ref_ref = {0};
  int_ref_ref.type = MONO_TYPE_REF;
  int_ref_ref.byref__ = TRUE;
  int_ref_ref.data.type = &int_ref;

Now int_ref_ref represents int&&.

Once we have byref of byref, we can call `mono_class_from_mono_type_internal`
on it.  Unfortunately for historical reasons, that function can take a
`MonoType` with the `byref__` bit set and (silently) strip off the bit and
return the MonoClass for the underlying non-ref type.

So to preserve that behavior, we implement `mono_class_from_mono_type_internal`
in terms of `mono_class_from_mono_type2` which has a flag to say if we should
strip off the extra byref-ness.

In the cases where we want it to return a `MonoClass` for an actual byref
type (either by stripping off one layer of byref from `int&&` (etc) or if we
call it and explicitly ask it not to strip off a byref layer) it returns a
`MonoClassPointer` instance (tracked in a separate byref_cache in the mono
image or in a memory manager like the unmanaged pointers) for the byref type.

At this point we don't have any way to parse `int&&` from metadata; so this
code is all dead, but it should at least not crash existing tests.
2021-10-15 11:31:26 -04:00
Aleksey Kliger c72e51fea2 [jit] Remove unneeded call to m_class_get_this_arg
type_check_context_used for  this_arg will be the same as for byval_arg
2021-10-15 11:31:25 -04:00
Aleksey Kliger 70fb11abd5 Change m_class_get_this_arg->mono_class_get_byref_type when it creates byrefs
In cases where it's evident the intent is to create a byref type around a known
type, use mono_class_get_byref_type instead of the this_arg getter.

No functional change, but sets the stage.
2021-10-15 11:31:25 -04:00
Aleksey Kliger bb78c7a944 rename MonoClass:this_arg to _this_arg 2021-10-15 11:31:25 -04:00
Aleksey Kliger (λgeek) 6c83297d9a [metadata] Replace uses of MonoType:byref by a getter (#60313)
* [metadata] Replace uses of MonoType:byref by a getter

Call `mono_type_is_byref_internal` instead of accessing the byref bit directly.

No functional change. (I hope).

This is in preparation for exploring alternative representations of ref types.

* Change mono_type_is_byref_internal to take a const argument

* Missed a couple byref reads

* rename mono_type_is_byref_internal -> m_type_is_byref [NFC]

* more missed byrefs

* revert unintended change
2021-10-15 11:30:41 -04:00
Fan Yang d0093330cd [Mono] Add check for field->type->byref (#60420)
* Add check for field->type->byref

* Add a test

* Fix error message
2021-10-14 20:21:45 -04:00
Rikki Gibson 668e2e2af4 Merge pull request #60421 from RikkiGibson/fix-toolexe
Use more reliable toolexe path
2021-10-14 14:00:13 -07:00
Rikki Gibson a479e15469 Use more reliable toolexe path 2021-10-14 12:06:39 -07:00
Aleksey Kliger (λgeek) bc9f795a64 fix Release builds of CoreCLR (#60404) 2021-10-14 09:11:42 -07:00
David Wrighton 2ccb89a374 Make all delegates support fully general generics (In support of Action/Func of everything) (#60377) 2021-10-13 17:37:06 -07:00
David Wrighton 1a5180e6ca Constraint generic work (#60320)
* Current state of generic constraint work

* Add a new Type.IsAssignableTo<Tfrom, TTo> intrinsic and implement a ConvertUnconstrainedCallsToThrowVerificationExceptionAttribute which allows a method call to a static generic method to either succeed (if the method type parameters succeed the constraint check) or fail (with a VerificationException) if the constraints are not satisfied. This is the runtime portion of an MVP for implementing the constraint specialization work that I proposed

* Fix code review comments

* Implement C# test, and fix up some naming
2021-10-13 15:58:32 -07:00
David Wrighton d83009aacd Fix ref field loading, when metadata type is actually ref type. Also fix test to return 100. (#60356) 2021-10-13 13:09:36 -07:00
Fan Yang 208e0213c7 Add test for struct with ref field (#60352) 2021-10-13 10:46:53 -07:00
Aleksey Kliger (λgeek) b0dce44152 Add script to run local Roslyn build on non-Windows (#60304)
tested on macOS. Shoudl work on Linux, too.

Build roslyn with
```
./build.sh --restore --build -c Release
```
then build the runtime with
```
./build.sh clr.native+mono+libs -c Release
```
(or your preferred subsets)
2021-10-12 14:26:57 -04:00
David Wrighton 697c9884cd Merge pull request #60303 from davidwrighton/checkin_work_to_hackathon_tree
Checkin the work for coreclr around stackalloc, ref fields and arbitrary generics to hackathon tree
2021-10-12 10:25:36 -07:00
David Wrighton f7cf9a8569 Generics over pointers, byrefs, and function pointers
- Enable generics over just about anything but System.Void
- Adds an attribute to indicate which generic arguments support that
- Adds an attribute for an escape hatch to allow functions which are generic over anything to just throw if the method is actually used on a non-traditional instantiation (This is expected to be needed for various Span<T> methods. It may be useful elsewhere
- Various instructions normally used with generics are not supported
  - unbox
  - unbox.any
  - ldelema
  - ldelem
  - stelem
  - box
  - castclass
  - isinst
  - newarr
- No testing has been done for pointer/functionpointer generics. They may work.

Add support for ref fields
- Turns out to be needed for generics over byrefs, and it was easy to write such tests compared to writing direct ref field tests
- Required support for byrefs of byrefs in order to support ldflda, ldobj, and stobj

Add support for TypedReference fields
- Again, only tested via the generics pathway

Add support for ByRefs of ByRefs
- Since we can have generics of refs, these turn out to appear, and it looks like functionally are pretty simple to implement
  - The only significant difficulty encountered in implementation was in the verification type system in the JIT
  - There is likely a bug tail here. The generation of full names of byref byref types is implemented, but it looks like there are more fixes to be had (parsing, etc).
  - Added but not tested is support for mkrefany and refanyval for ref types
2021-10-12 10:20:13 -07:00
David Wrighton 808ffeded8 Remove comments in Span<T> contstructor as they are no longer needed. 2021-10-12 10:20:12 -07:00
David Wrighton d613b0284d Improve fancy stackalloc to return Span<T> instead of just ByRef
- Test adjusted to handle new case
- Fix usage of various clone routines in importer
- jit intrinsic creates Span<T> ... probably not in ideal fashion as generated code looks terrible
- Reduce size of stackallocated region in test case as it had too much stack requirement to actually be stackallocated and was triggering a StackOverflowException as the new logic let it go down the real stack alloc path
2021-10-12 10:20:11 -07:00
David Wrighton 92240de30f Hackathon Quality implementation of StackAlloc
- Known limitations
  - Currently requires nothing to be on the stack to utilize the localloc pathway
  - Testting is super minimal. actual localloc usage, and finally behavior not done
  - Naming is terrible
  - Intrinsic returns void* not a proper Span<T>
- General structure is to setup a try/finally in the method if it uses the StackAlloc intrinsic, and report any GC regions as appropriate
2021-10-12 10:20:10 -07:00
David Wrighton 1da165a45e Use local version of Roslyn to build (#60302) 2021-10-12 10:14:15 -07:00
Layomi Akinrinade 784687f1af Prevent runtime prop metadata retrieval when [JsonIgnore] is used (#60024)
* Prevent runtime prop metadata retrieval when [JsonIgnore] is used

* Address feedback

* Re-add ctor param default handling tests

* Remove new concurrent dictionary for generic method holders
2021-10-12 12:02:36 -04:00
dotnet-maestro[bot]anddotnet-maestro[bot] 31c38ef019 Update dependencies from https://github.com/dotnet/linker build 20211011.1 (#60289)
Microsoft.NET.ILLink.Tasks
 From Version 7.0.100-1.21504.4 -> To Version 7.0.100-1.21511.1

Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
2021-10-12 17:28:55 +02:00
Thays Grazia d6c3ad1382 [wasm] Fixing compilation on windows using debug mode. (#60260)
* Fixing compilation on windows using debug mode.

* Fixing as suggested by @radekdoulik

* fix release compilation
2021-10-12 16:13:17 +02:00
Vlad Brezae 383a479a0b [mono][interp] Fix short branches (#58806)
* [interp] Fix short branches

In interp, long branches have 4 byte signed offset while short branches have a 2 byte signed offset. Ideally we would want to always emit short branches if possible due to improved performance. The problem is that we emit a short or long branch early in the codegen process, there is no way to know whether a branch is long or short at that time and no further computations were done later to determine whether the branch is really long or short.  Before this commit we arbitrarily decided that all branches in methods with IL size of less than 25000 are short and, in some cases, completely ignored that long branches actually happen in practice.

This commit makes it such that we always emit long opcodes at the beginning of the codegen process, also serving as a simplification since optimizations operating on IR code don't need to care about both short and long versions of branches. Later on, we will end up converting all these long branches to short branches when emitting the final method code. We achieve this by doing a quick preliminary code iteration and computing conservative native offsets (assuming all branches are long). Since the final code will be equal in size or smaller, we have the guarantee that if a branch is short between the conservative offsets, it will surely be short also in the final code. With this approach we guarantee correctness and we can fail to shorten only a negligible amount of branches.

Since the super instruction pass generates some branching instructions that are supported only for the short version, we need to run a computation of conservative offsets beforehand.

* Re-enable test suite
2021-10-12 11:15:54 +03:00
Bruce Forstall df42364f8f Add C# multi-dimension array versions of the Benchstones tests (#60192)
* Add C# multi-dimension array versions of the Benchstones tests

The Benchstones tests using multi-dimension arrays currently are
implemented using C# "jagged" arrays. Add versions of the tests
that use true C# multi-dimensional arrays. The code is exactly
the same, except for the array creation and indexing.

This will allow us to compare code generated for each, as well as
to verify functionality. I intend to add versions of these to the
microbenchmarks in the https://github.com/dotnet/performance repo as well.

* Fix MDPuzzle build
2021-10-11 23:15:51 -07:00
Elinor Fung debe671db1 Take write lock in PEImage::LoadFlat/LoadImage (#60277) 2021-10-11 19:43:48 -07:00
Alexander Köplinger 4b8445190e Fix runtime-staging trigger and one bug (#60257)
We were triggering the runtime-staging jobs for all branches rather than just PRs and the scheduled runs on main.
Fix it to only run for pushes on release branches, like runtime.yml.

I also noticed a small bug where we had `interpreter: true` in the "iOS/tvOS devices - Full AOT + AggressiveTrimming" job, that was probably a copy/paste mistake.
2021-10-12 00:56:23 +02:00
Bruce Forstall c028f39d6c Build using build.cmd/sh, not bootstrap.cmd/sh (#60264) 2021-10-11 15:12:58 -07:00