Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
829bb94
Marshal.SizeOf/OffsetOf of structs with fixed-size buffers
filipnavara Nov 9, 2026
0500a34
A Type local that is exactly typeof(T) stands for T in per-type lower…
filipnavara Nov 10, 2026
d8f86a6
[DynamicallyAccessedMembers] on properties and fields keeps the membe…
filipnavara Nov 10, 2026
89fe75a
Uri: relative references and implicit file paths with spaces
filipnavara Nov 10, 2026
b3811fe
Renumber sample 1304 to 1340 (upstream has its own 1304 now)
filipnavara Nov 10, 2026
4906a4e
Renumber sample 1306 to 1342 (upstream has its own 1306 now)
filipnavara Nov 10, 2026
2b02244
Renumber sample 1307 to 1343 (upstream has its own 1307 now)
filipnavara Nov 10, 2026
584359e
Renumber sample 1308 to 1344 (upstream has its own 1308 now)
filipnavara Nov 10, 2026
2251718
P/Invoke delegate parameters
filipnavara Nov 10, 2026
7f9ce9a
P/Invoke SafeHandle parameters
filipnavara Nov 10, 2026
1e505f1
Create preserialized resources stored as bytes: formats 2 and 4
jonathanperis Nov 25, 2026
4247a59
Wrap a stream resource's constructor exception as .NET does
jonathanperis Nov 25, 2026
a53fac7
Keep the inner exception whatever its parameter is called
jonathanperis Nov 25, 2026
5daf93a
Give Activator's missing-constructor error .NET's inner exception
jonathanperis Nov 25, 2026
a0be6a5
Merge remote-tracking branch 'origin/main' into feat/preserialized-by…
jonathanperis Nov 25, 2026
ab1e967
Nest 'Member not found.' in a stream resource's error only as .NET does
jonathanperis Nov 25, 2026
ee143c4
Compile System.IO.Pipes from the framework's IL on Linux and macOS
jonathanperis Nov 25, 2026
0f36a2d
Format a framework struct without a ToString override as its type name
jonathanperis Nov 25, 2026
c55d75d
Read and write through a property override that has only one accessor
jonathanperis Nov 25, 2026
b261b46
Merge remote-tracking branch 'origin/main' into feat/pipes-from-il
jonathanperis Nov 25, 2026
0a3854d
Use the inherited accessor in compound assignments too
jonathanperis Nov 25, 2026
841dc98
Index interface-table entries and class descendants for dispatch lowe…
jonathanperis Nov 25, 2026
a285d35
Merge remote-tracking branch 'origin/main' into perf/dispatch-indexes
jonathanperis Nov 25, 2026
553cd2a
Merge remote-tracking branch 'origin/main' into feat/pipes-from-il
jonathanperis Nov 26, 2026
8a34c99
Merge remote-tracking branch 'origin/main' into perf/dispatch-indexes
jonathanperis Nov 26, 2026
6928521
Merge remote-tracking branch 'origin/main' into feat/preserialized-by…
jonathanperis Nov 26, 2026
80b21f9
Merge remote-tracking branch 'origin/main' into feat/pipes-from-il
jonathanperis Nov 26, 2026
d8278bd
Merge remote-tracking branch 'origin/main' into feat/preserialized-by…
jonathanperis Nov 26, 2026
8f7dc68
Merge remote-tracking branch 'origin/main' into perf/dispatch-indexes
jonathanperis Nov 26, 2026
34a2f6e
Merge remote-tracking branch 'origin/main' into feat/pipes-from-il
jonathanperis Nov 26, 2026
f94fb52
Merge remote-tracking branch 'origin/main' into feat/preserialized-by…
jonathanperis Nov 26, 2026
83e7cca
Merge remote-tracking branch 'origin/main' into perf/dispatch-indexes
jonathanperis Nov 26, 2026
6c9fd2b
Merge remote-tracking branch 'origin/main' into feat/pipes-from-il
jonathanperis Nov 26, 2026
3985f49
Give macOS getpwuid_r a struct passwd of its full size
jonathanperis Nov 26, 2026
c931f03
Merge remote-tracking branch 'origin/main' into perf/dispatch-indexes
jonathanperis Nov 27, 2026
7366376
Merge remote-tracking branch 'origin/main' into feat/pipes-from-il
jonathanperis Nov 27, 2026
be0887b
Merge remote-tracking branch 'origin/main' into feat/preserialized-by…
jonathanperis Nov 27, 2026
ff3d9a7
Merge remote-tracking branch 'origin/main' into perf/dispatch-indexes
jonathanperis Nov 27, 2026
4dcb023
Merge remote-tracking branch 'origin/main' into feat/pipes-from-il
jonathanperis Nov 27, 2026
090c9d5
Merge remote-tracking branch 'origin/main' into feat/preserialized-by…
jonathanperis Nov 27, 2026
85c60a9
Merge remote-tracking branch 'origin/main' into pr-291
jonathanperis Nov 27, 2026
740c8a0
Merge remote-tracking branch 'origin/main' into pr-279
jonathanperis Nov 27, 2026
348a4e6
Merge remote-tracking branch 'origin/main' into pr-284
jonathanperis Nov 27, 2026
3b0a258
Merge remote-tracking branch 'origin/main' into pr-297
jonathanperis Nov 27, 2026
b1a3eb4
Merge remote-tracking branch 'origin/main' into pr-298
jonathanperis Nov 27, 2026
1087f50
Merge remote-tracking branch 'origin/main' into pr-283
jonathanperis Nov 27, 2026
2be9b73
Merge branch 'feat/preserialized-bytes-stream' into pr-291
jonathanperis Nov 27, 2026
605cbff
Merge branch 'pr-291' into pr-279
jonathanperis Nov 27, 2026
96db974
Merge branch 'pr-279' into pr-284
jonathanperis Nov 27, 2026
c3a0953
Merge branch 'pr-284' into pr-297
jonathanperis Nov 27, 2026
1ba8676
Merge branch 'perf/dispatch-indexes' into feat/pipes-from-il
jonathanperis Nov 27, 2026
234d011
Merge P/Invoke delegate parameters (#297) under SafeHandle parameters
jonathanperis Nov 27, 2026
962d290
Merge branch 'feat/pipes-from-il' into feat/preserialized-bytes-stream
jonathanperis Nov 27, 2026
bc9be68
Merge branch 'feat/preserialized-bytes-stream' into pr-291
jonathanperis Nov 27, 2026
7dbd2bc
Merge branch 'pr-291' into pr-279
jonathanperis Nov 27, 2026
ab99772
Merge branch 'pr-279' into pr-284
jonathanperis Nov 27, 2026
48211e7
Merge branch 'pr-284' into pr-297
jonathanperis Nov 27, 2026
9e2db3c
Merge branch 'pr-297' into pr-298
jonathanperis Nov 27, 2026
a1d1980
Merge branch 'pr-298' into pr-283
jonathanperis Nov 27, 2026
da0d90f
Keep backslashes in relative URIs; such references are not well formed
jonathanperis Nov 27, 2026
b9a398e
Merge branch 'pr-291' into pr-279
jonathanperis Nov 27, 2026
4e7a5c1
Merge branch 'pr-279' into pr-284
jonathanperis Nov 27, 2026
ee42a0f
Merge branch 'pr-284' into pr-297
jonathanperis Nov 27, 2026
3859740
Merge branch 'pr-297' into pr-298
jonathanperis Nov 27, 2026
cafa14c
Merge branch 'pr-298' into pr-283
jonathanperis Nov 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Csharpc/CodeGen/BclValueTypes.Reflection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ BclHandler frameworkTypeAttributes(string method, string frameworkMethod) => (g,
// isn't constructed. .NET's argument checks are corelib C# (ReflectionRuntime.GetUninitializedObject).
t["System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject(System.Type)"] = (g, _, _, a, at) =>
{
if (at is Microsoft.CodeAnalysis.Operations.IInvocationOperation { Arguments: [var argument] } && FunctionCodeGen.TypeOfOperand(argument.Value) is { } created)
if (at is Microsoft.CodeAnalysis.Operations.IInvocationOperation { Arguments: [var argument] } && g.ExactTypeOf(argument.Value) is { } created)
g.NoteConstructedType(created is INamedTypeSymbol { OriginalDefinition.SpecialType: SpecialType.System_Nullable_T, TypeArguments: [var underlying] } ? underlying : created);
return g.CallCoreLib("ReflectionRuntime", "GetUninitializedObject", a[0]);
};
Expand Down
27 changes: 26 additions & 1 deletion src/Csharpc/CodeGen/FunctionCodeGen.Calls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ private LLVMValueRef EmitPropertyGet(IPropertyReferenceOperation p)
return EmitInterfaceCall(property.GetMethod!, p.Instance!, p.Arguments, [], null);
if (_m.IsUserType(property.ContainingType))
{
var getter = property.GetMethod ?? throw CompileError.Unsupported($"reading set-only property '{property.Name}'", p);
var getter = GetterOf(property) ?? throw CompileError.Unsupported($"reading set-only property '{property.Name}'", p);
var self = property.IsStatic ? default : Receiver(p.Instance!, getter);
return CallAccessor(p, getter, self, []);
}
Expand Down Expand Up @@ -1124,6 +1124,12 @@ private LLVMValueRef EmitPropertySet(IPropertyReferenceOperation p, Func<LLVMVal
: property.ContainingType.IsValueType ? AddressOrSpill(p.Instance!) : EmitValue(p.Instance!);
var v = Coerce(value(), valueType, property.Type);

// An override with only a getter: the write calls the nearest overridden property's setter, virtually, as C# binds it.
if (property.SetMethod is null && property.IsOverride && SetterOf(property) is { } inherited)
{
CallAccessor(p, inherited, self, [v]);
return v;
}
if (property.SetMethod is null)
{
// Get-only auto-property assigned in a constructor: write the backing field directly.
Expand Down Expand Up @@ -1697,6 +1703,25 @@ private static string NotCompiledHint(ITypeSymbol type) =>
type.ContainingAssembly is { } asm && Frontend.FrameworkIl.NotCompiledFromIl.TryGetValue(asm.Name, out var why)
? $" ({asm.Name} is not compiled from IL: {why})" : "";

/// <summary>
/// The getter a read of <paramref name="property"/> calls: its own, or, for an override that only overrides the setter
/// (AnonymousPipeClientStream.ReadMode), the nearest overridden property's, called virtually as C# binds it.
/// </summary>
internal static IMethodSymbol? GetterOf(IPropertySymbol property)
{
for (var p = property; p is not null; p = p.OverriddenProperty)
if (p.GetMethod is { } getter) return getter;
return null;
}

/// <summary>The setter a write of <paramref name="property"/> calls: its own, or the nearest overridden property's.</summary>
internal static IMethodSymbol? SetterOf(IPropertySymbol property)
{
for (var p = property; p is not null; p = p.OverriddenProperty)
if (p.SetMethod is { } setter) return setter;
return null;
}

/// <summary>
/// `Dispose()` on the stack enumerator of a foreach over an array, also through implicit conversions (the finally's
/// `((IDisposable)e).Dispose()` when the array is cast in the foreach header, #516): it does nothing. Shared with the finally
Expand Down
8 changes: 6 additions & 2 deletions src/Csharpc/CodeGen/FunctionCodeGen.CoreLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,15 @@ private LLVMValueRef CallAccessorDirect(IMethodSymbol accessor, LLVMValueRef[] a

private LLVMValueRef GetCapturedProperty(PropertyCapture pc)
{
var getter = pc.Property.GetMethod ?? throw CompileError.Unsupported($"reading set-only property '{pc.Property.Name}'", pc.Property);
var getter = GetterOf(pc.Property) ?? throw CompileError.Unsupported($"reading set-only property '{pc.Property.Name}'", pc.Property);
return CallAccessorDirect(getter, CapturedAccessorArgs(pc, getter, []));
}

private LLVMValueRef SetCapturedProperty(PropertyCapture pc, LLVMValueRef value)
{
if (pc.Property.SetMethod is not { } setter)
// A getter-only override writes through the nearest overridden property's setter (as SetProperty does).
var setter = pc.Property.SetMethod ?? (pc.Property.IsOverride ? SetterOf(pc.Property) : null);
if (setter is null)
{
// Get-only auto-property assigned in a constructor: write its backing field.
var field = BackingField(pc.Property);
Expand Down Expand Up @@ -170,6 +172,8 @@ private LLVMValueRef EmitCoreIntrinsic(IMethodSymbol target, IInvocationOperatio
"TryFaultAsyncTask" => CallRuntime("csrt_task_try_fault_async", L.I1, [L.Ptr, L.Ptr], args[0], args[1]),
"CompareStringsWith" => CallRuntime("csrt_string_compare_with", L.I32, [L.Ptr, L.Ptr, L.I32], args[0], args[1], args[2]),
"ResourceObjectHook" => ProgramHook("ResourceObject", target, args),
"ResourceObjectFromBytesHook" => ProgramHook("ResourceObjectFromBytes", target, args),
"ResourceObjectFromStreamHook" => ProgramHook("ResourceObjectFromStream", target, args),
"HasConverterResources" => _m.HasConverterResources() ? L.True : L.False,
"HasNonStringResources" => _m.HasNonStringResources() ? L.True : L.False,
"NestedTypeTable" => _b.Call(_m.NestedTypesFunction().Type, _m.NestedTypesFunction().Fn, [args[0], args[1]]),
Expand Down
2 changes: 1 addition & 1 deletion src/Csharpc/CodeGen/FunctionCodeGen.Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public sealed partial class FunctionCodeGen
// The Type overloads (Enum.GetValues(typeof(Color))): with a typeof operand they are the
// generic ones in disguise; the leading Type argument is dropped.
if (target.Parameters.FirstOrDefault()?.Type is not { Name: "Type", ContainingNamespace.Name: "System" }) return null;
if (TypeOfOperand(args[0].Value) is not { } typeOperand || S(typeOperand) is not INamedTypeSymbol { TypeKind: TypeKind.Enum } named)
if (ExactTypeOf(args[0].Value) is not { } typeOperand || S(typeOperand) is not INamedTypeSymbol { TypeKind: TypeKind.Enum } named)
{
// Configuration.Binder and similar pass a run-time Type into Enum.Parse/IsDefined:
// lower to a corelib helper (NotSupportedException until a full run-time enum table exists)
Expand Down
13 changes: 11 additions & 2 deletions src/Csharpc/CodeGen/FunctionCodeGen.Exceptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,21 @@ private void EmitExceptionConstructor(IMethodSymbol constructor, LLVMValueRef ex
}
var value = EmitValue(argument.Value);
var uriFormat = Mangler.MetadataName(constructor.ContainingType) == "System.UriFormatException";
// The inner exception is the parameter typed System.Exception, whatever its name: "innerException" in most of the
// framework, "inner" in MissingMemberException, MissingMethodException, RegexMatchTimeoutException and others, "e" in
// UriFormatException and the SqlTypes exceptions. Matching only one name dropped the others' inner exception silently.
if (argument.Parameter?.Type is INamedTypeSymbol { Name: "Exception", ContainingNamespace: { Name: "System", ContainingNamespace.IsGlobalNamespace: true } })
{
inner = value;
continue;
}
switch (argument.Parameter?.Name)
{
case "message": message = value; break;
case "textString" when uriFormat: message = value; break; // UriFormatException(string textString, Exception e)
case "e" when uriFormat: inner = value; break;
case "innerException": inner = value; break;
case "fullTypeName" when Mangler.MetadataName(constructor.ContainingType) == "System.TypeInitializationException":
message = CallCoreLib("ExceptionData", "TypeInitializerMessage", value); // its message names the type
break;
case "paramName" or "parameterName": paramName = value; break; // parameterName: DuplicateWaitObjectException
case "fileName": paramName = value; break; // FileNotFoundException.FileName (csrt keeps it in param_name)
case "directoryPath": paramName = value; break; // DirectoryNotFoundException.DirectoryPath (.NET 11), likewise
Expand Down
26 changes: 21 additions & 5 deletions src/Csharpc/CodeGen/FunctionCodeGen.Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,21 @@ private LLVMValueRef FieldAddress(IFieldReferenceOperation f)
private LLVMValueRef EmitSimpleAssignment(ISimpleAssignmentOperation a)
{
if (a.IsRef) return EmitRefAssignment(a);
if (a.Target is IPropertyReferenceOperation { Property.RefKind: RefKind.None } p) return EmitPropertySet(p, () => EmitValue(a.Value), TypeOf(a.Value));
if (a.Target is IPropertyReferenceOperation { Property.RefKind: RefKind.None } p)
{
// An assignment is the setter's call: an annotated value parameter (or property) keeps the assigned typeof's members.
if (p.Property.SetMethod is { } setter && KnownTypeofValues(a.Value) is { Count: > 0 } assigned)
foreach (var known in assigned)
_m.NoteDynamicallyAccessedArguments(S(setter), i => i == setter.Parameters.Length - 1 ? S(known) : null);
return EmitPropertySet(p, () => EmitValue(a.Value), TypeOf(a.Value));
}
if (a.Target is IFlowCaptureReferenceOperation r && _cfg!.PropertyCaptures.TryGetValue(r.Id, out var pc))
return SetCapturedProperty(pc, Coerce(EmitValue(a.Value), TypeOf(a.Value), pc.Property.Type));
// `[DynamicallyAccessedMembers(K)] Type field = typeof(X)` (an initializer or an assignment): X keeps its members of
// kinds K, as the IL front-end's NoteDynamicallyAccessedField does.
if (a.Target is IFieldReferenceOperation { Field: var annotatedField } && IsSystemType(annotatedField.Type)
&& ModuleCodeGen.DamKindsOf(annotatedField.OriginalDefinition.GetAttributes()) is var fieldKinds and not 0)
foreach (var known in KnownTypeofValues(a.Value)) _m.MarkDynamicallyAccessed(S(known), fieldKinds);

var targetType = TypeOf(a.Target)!;
var address = StoreAddress(a.Target, out var covariant); // C#: target sub-expressions are evaluated first
Expand Down Expand Up @@ -273,17 +285,21 @@ private LLVMValueRef ReadModifyWrite(IOperation target, Func<LLVMValueRef, (LLVM
{
// Evaluate the receiver once, then call get + set on it.
var property = S(p.Property);
var self = property.IsStatic ? default : Receiver(p.Instance!, property.GetMethod!);
// An override with one accessor reads or writes through the nearest overridden property's other one (virtually).
var getter = GetterOf(property) ?? throw CompileError.Unsupported($"reading set-only property '{property.Name}'", p);
var setter = property.SetMethod ?? (property.IsOverride ? SetterOf(property) : null)
?? throw CompileError.Unsupported("compound assignment to a get-only property", p);
var self = property.IsStatic ? default : Receiver(p.Instance!, getter);
// Indexer arguments are evaluated once, then shared by the get and set calls (c[i++] += v).
var savedArgs = _argumentCache;
if (!p.Arguments.IsEmpty)
{
_argumentCache = new Dictionary<IArgumentOperation, LLVMValueRef>(ReferenceEqualityComparer.Instance);
foreach (var argument in p.Arguments) _argumentCache[argument] = EmitArgument(argument, property.GetMethod!);
foreach (var argument in p.Arguments) _argumentCache[argument] = EmitArgument(argument, getter);
}
var old = CallAccessor(p, property.GetMethod!, self, []);
var old = CallAccessor(p, getter, self, []);
var (newValue, result) = modify(old);
CallAccessor(p, property.SetMethod ?? throw CompileError.Unsupported("compound assignment to a get-only property", p), self, [newValue]);
CallAccessor(p, setter, self, [newValue]);
_argumentCache = savedArgs;
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Csharpc/CodeGen/FunctionCodeGen.IlInstructions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ private IlValueOperation IlOperand(IlEntry e, ITypeSymbol type, bool lvalue = fa
return new IlValueOperation(il.Syntax, type, () => IlTyped(e, type), nonNull: e.NonNull || e.IsThis)
{
Constant = e.Constant is null ? default : TypedConstant(e.Constant, type),
TypeOfOperand = e is { Kind: IlKind.Ref, Symbol: ITypeSymbol known } ? known : null,
TypeOfOperand = e is { Kind: IlKind.Ref, Symbol: ITypeSymbol known } ? known : e is { Kind: IlKind.Ref, FromLocal: { } local } ? IlExactTypeofLocal(local) : null,
BoxedFrom = e is { Kind: IlKind.Ref, Unboxed: { Type: { } boxedType } boxed } && !boxed.Value.IsNull ? IlOperand(boxed, boxedType) : null,
IsNullLiteral = e is { Kind: IlKind.Ref, Type: null } && !e.Value.IsNull && Native.LLVMIsNull(e.Value) != 0,
EntryType = e.Type,
Expand Down
27 changes: 23 additions & 4 deletions src/Csharpc/CodeGen/FunctionCodeGen.MarshalLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ private sealed class NativeLayout(ITypeSymbol type, NativeKind kind)
public int BoolSize { get; set; } = 4;
public List<NativeField> Fields { get; } = [];
public bool IsClass { get; set; }
/// <summary>A fixed-size buffer anywhere in the layout: sizes and offsets are known, element conversion is not modelled.</summary>
public bool HasFixedBuffer { get; set; }
}

/// <summary>What the marshaller would refuse (an ArgumentException at run time) versus what csharpc can't do yet.</summary>
Expand Down Expand Up @@ -106,7 +108,11 @@ private NativeLayout NativeLayoutOfType(ITypeSymbol type, bool sizeOf)
if (type is not INamedTypeSymbol { TypeKind: TypeKind.Struct or TypeKind.Class } structure)
throw notMarshalable;
if (!_m.IsUserType(structure)) throw new NativeLayoutException(false, $"Marshal layout of library type '{name}'");
return BuildNativeLayout(structure, notMarshalable);
var layout = BuildNativeLayout(structure, notMarshalable);
// .NET's marshaller converts only a fixed-size buffer's first element (the generated struct's one field) and
// zeroes the rest: SizeOf/OffsetOf are exact, copying such a struct is left unsupported rather than approximated.
if (!sizeOf && layout.HasFixedBuffer) throw new NativeLayoutException(false, $"marshalling the contents of a fixed-size buffer in '{name}'");
return layout;
}

/// <summary>A field or element of a primitive, native-int, enum, bool, char or opaque (decimal, Guid) type; null for anything else.</summary>
Expand Down Expand Up @@ -159,14 +165,27 @@ private NativeLayout BuildNativeLayout(INamedTypeSymbol type, NativeLayoutExcept
var align = 1;
foreach (var field in type.GetMembers().OfType<IFieldSymbol>().Where(f => !f.IsStatic && !f.IsConst))
{
if (field.IsFixedSizeBuffer) throw new NativeLayoutException(false, $"Marshal layout of fixed-size buffer '{field.Name}'");
var fieldType = S(field.Type);
var leaf = NativeScalarLayout(fieldType, field, charSet, notMarshalable);
NativeLayout? leaf;
if (field.IsFixedSizeBuffer)
{
// The compiler's <name>e__FixedBuffer struct: one element field (marshalled with the container's CharSet)
// and StructLayout.Size = FixedSize elements of managed size, so it is at least that large and aligned as its element.
var element = fieldType is IPointerTypeSymbol { PointedAtType: var pointed } ? S(pointed)
: throw new NativeLayoutException(false, $"Marshal layout of fixed-size buffer '{field.Name}'");
var elementLeaf = NativeScalarLayout(element, null, charSet, notMarshalable)
?? throw new NativeLayoutException(false, $"Marshal layout of fixed-size buffer '{field.Name}' of '{element}'");
var managedBytes = field.FixedSize * (int)T.Target.SizeOf(T.Storage(element));
leaf = new NativeLayout(fieldType, NativeKind.Opaque) { Size = Math.Max(elementLeaf.Size, managedBytes), Align = elementLeaf.Align };
layout.HasFixedBuffer = true;
}
else leaf = NativeScalarLayout(fieldType, field, charSet, notMarshalable);
if (leaf is null)
{
if (fieldType is not INamedTypeSymbol { TypeKind: TypeKind.Struct } nestedType || !_m.IsUserType(nestedType) )
throw new NativeLayoutException(false, $"Marshal layout of field '{field.Name}' of type '{fieldType}'");
leaf = BuildNativeLayout(nestedType, notMarshalable);
layout.HasFixedBuffer |= leaf.HasFixedBuffer;
}
var fieldAlign = pack == 0 ? leaf.Align : Math.Min(leaf.Align, pack);
long offset;
Expand Down Expand Up @@ -221,7 +240,7 @@ private NativeLayout BuildNativeLayout(INamedTypeSymbol type, NativeLayoutExcept
/// <summary>The type an argument of type Type (typeof(X)) or object (the structure) stands for, when it is known statically.</summary>
private ITypeSymbol? MarshalTypeOf(IOperation argument, bool structure)
{
if (!structure) return TypeOfOperand(argument) is { } typeOf ? S(typeOf) : null;
if (!structure) return ExactTypeOf(argument) is { } typeOf ? S(typeOf) : null;
var value = argument;
while (value is IConversionOperation { Operand: var operand } conversion && !conversion.Conversion.IsUserDefined && !conversion.Conversion.IsNumeric && !conversion.Conversion.IsNullable)
value = operand;
Expand Down
5 changes: 5 additions & 0 deletions src/Csharpc/CodeGen/FunctionCodeGen.Structs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,11 @@ internal LLVMValueRef FormatValue(LLVMValueRef value, ITypeSymbol type, IOperati
return ConcatStrings(ConcatStrings(prefix, count), _m.StringLiteral("]"));
}
}
// A library struct that does not override ToString formats as ValueType.ToString(): its full name, known here for a
// non-generic one (System.IO.Pipes interpolates a CancellationToken into a message).
if (type is INamedTypeSymbol { TypeKind: TypeKind.Struct, IsGenericType: false } plain
&& !plain.GetMembers("ToString").OfType<IMethodSymbol>().Any(m => m.IsOverride && m.Parameters.IsEmpty))
return _m.StringLiteral(Mangler.MetadataName(plain)); // (Outer+Inner, as Type.FullName)
throw CompileError.Unsupported($"formatting '{type}'", at);
}
}
Loading
Loading