Skip to content

[mono] Issues with handling nested generic structures during generic sharing #89613

@vargaz

Description

@vargaz

Description

Currently, the mono generic sharing code has issues with nested structures.

Example:

static void Write<T>(ref byte b, T value) => Unsafe.WriteUnaligned<T>(ref b, value);

If we try to aot an instance like Write<AStruct<string>>, the generic sharing code will aot Write<T_STRUCT>,
there T_STRUCT is a synthetic generic parameter constrained to AStruct<T_REF> where T_REF is a similar parameter constrained to reference types.

Problems can arise if the JIT replaces T_STRUCT with AStruct<T_REF> during JITing, which is done for example by mini_get_underlying_type (). The generic sharing runtime code will expand T_STRUCT to AStruct<string>, but it will not do the same for AStruct<T_REF> leading to problems.
The current workaround is to disable generic sharing, i.e. by setting cfg->prefer_instances.

Re: #89417

Reproduction Steps

.

Expected behavior

.

Actual behavior

.

Regression?

No.

Known Workarounds

.

Configuration

dotnet/runtime master

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions