Skip to content

Commit

Permalink
for RuntimeTypeValue make it dependent on SupportsFrozenRuntimeTypeIn…
Browse files Browse the repository at this point in the history
…stances (#96654)
  • Loading branch information
yowl authored Jan 9, 2024
1 parent 17cc102 commit 4276583
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ private Status TryScanMethod(MethodIL methodIL, Value[] parameters, Stack<Method
Value value = stack.PopIntoLocation(field.FieldType);
if (value is IInternalModelingOnlyValue)
return Status.Fail(methodIL.OwningMethod, opcode, "Value with no external representation");
if (value is { TargetSupportsWritingFieldData: false })
return Status.Fail(methodIL.OwningMethod, opcode, "Value cannot be written to target as it does not support writing field data and hence FrozenRuntimeTypeNode");
_fieldValues[field] = value;
}
}
Expand Down Expand Up @@ -2217,6 +2219,8 @@ private static T ThrowInvalidProgram<T>()
public virtual float AsSingle() => ThrowInvalidProgram<float>();
public virtual double AsDouble() => ThrowInvalidProgram<double>();
public virtual Value Clone() => ThrowInvalidProgram<Value>();

public virtual bool TargetSupportsWritingFieldData => true;
}

private abstract class BaseValueTypeValue : Value
Expand Down Expand Up @@ -2399,8 +2403,14 @@ public RuntimeTypeValue(TypeDesc type)

public override bool GetRawData(NodeFactory factory, out object data)
{
data = factory.SerializedMaximallyConstructableRuntimeTypeObject(TypeRepresented);
return true;
if (TargetSupportsWritingFieldData)
{
data = factory.SerializedMaximallyConstructableRuntimeTypeObject(TypeRepresented);
return true;
}

data = null;
return false;
}
public override ReferenceTypeValue ToForeignInstance(int baseInstructionCounter, TypePreinit preinitContext)
{
Expand All @@ -2414,6 +2424,8 @@ public override void WriteFieldData(ref ObjectDataBuilder builder, NodeFactory f
{
builder.EmitPointerReloc(factory.SerializedMaximallyConstructableRuntimeTypeObject(TypeRepresented));
}

public override bool TargetSupportsWritingFieldData => EETypeNode.SupportsFrozenRuntimeTypeInstances(Type.Context.Target);
}

private sealed class ReadOnlySpanValue : BaseValueTypeValue, IInternalModelingOnlyValue
Expand Down

0 comments on commit 4276583

Please sign in to comment.