* 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.
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.
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.
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.
* [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
* 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
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)
- 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
- 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
- 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
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>
* [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
* 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
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.