Skip to content

Remove nullable return from ConstructorInvoker.Invoke() #89448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ public static ConstructorInvoker Create(ConstructorInfo constructor)
return new ConstructorInvoker(runtimeConstructor);
}

public object? Invoke()
public object Invoke()
{
return _methodBaseInvoker.CreateInstanceWithFewArgs(new Span<object?>());
}

public object? Invoke(object? arg1)
public object Invoke(object? arg1)
{
return _methodBaseInvoker.CreateInstanceWithFewArgs(new Span<object?>(ref arg1));
}

public object? Invoke(object? arg1, object? arg2)
public object Invoke(object? arg1, object? arg2)
{
StackAllocatedArguments argStorage = default;
argStorage._args.Set(0, arg1);
argStorage._args.Set(1, arg2);
return _methodBaseInvoker.CreateInstanceWithFewArgs(argStorage._args.AsSpan(2));
}

public object? Invoke(object? arg1, object? arg2, object? arg3)
public object Invoke(object? arg1, object? arg2, object? arg3)
{
StackAllocatedArguments argStorage = default;
argStorage._args.Set(0, arg1);
Expand All @@ -55,7 +55,7 @@ public static ConstructorInvoker Create(ConstructorInfo constructor)
return _methodBaseInvoker.CreateInstanceWithFewArgs(argStorage._args.AsSpan(3));
}

public object? Invoke(object? arg1, object? arg2, object? arg3, object? arg4)
public object Invoke(object? arg1, object? arg2, object? arg3, object? arg4)
{
StackAllocatedArguments argStorage = default;
argStorage._args.Set(0, arg1);
Expand All @@ -65,7 +65,7 @@ public static ConstructorInvoker Create(ConstructorInfo constructor)
return _methodBaseInvoker.CreateInstanceWithFewArgs(argStorage._args.AsSpan(4));
}

public object? Invoke(Span<object?> arguments)
public object Invoke(Span<object?> arguments)
{

return _methodBaseInvoker.CreateInstance(arguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ private ConstructorInvoker(RuntimeConstructorInfo constructor, RuntimeType[] arg
Initialize(argumentTypes, out _strategy, out _invokerArgFlags, out _needsByRefStrategy);
}

public object? Invoke() => Invoke(null, null, null, null);
public object? Invoke(object? arg1) => Invoke(arg1, null, null, null);
public object? Invoke(object? arg1, object? arg2) => Invoke(arg1, arg2, null, null);
public object? Invoke(object? arg1, object? arg2, object? arg3) => Invoke(arg1, arg2, arg3, null);
public object? Invoke(object? arg1, object? arg2, object? arg3, object? arg4)
public object Invoke() => Invoke(null, null, null, null);
public object Invoke(object? arg1) => Invoke(arg1, null, null, null);
public object Invoke(object? arg1, object? arg2) => Invoke(arg1, arg2, null, null);
public object Invoke(object? arg1, object? arg2, object? arg3) => Invoke(arg1, arg2, arg3, null);
public object Invoke(object? arg1, object? arg2, object? arg3, object? arg4)
{
if ((_invocationFlags & (InvocationFlags.NoInvoke | InvocationFlags.ContainsStackPointers)) != 0)
{
Expand Down Expand Up @@ -82,22 +82,22 @@ private ConstructorInvoker(RuntimeConstructorInfo constructor, RuntimeType[] arg
// Check fast path first.
if (_invokeFunc_Obj4Args is not null)
{
return _invokeFunc_Obj4Args(obj: null, arg1, arg2, arg3, arg4);
return _invokeFunc_Obj4Args(obj: null, arg1, arg2, arg3, arg4)!;
}

if ((_strategy & InvokerStrategy.StrategyDetermined_Obj4Args) == 0)
{
DetermineStrategy_Obj4Args(ref _strategy, ref _invokeFunc_Obj4Args, _method, _needsByRefStrategy, backwardsCompat: false);
if (_invokeFunc_Obj4Args is not null)
{
return _invokeFunc_Obj4Args(obj: null, arg1, arg2, arg3, arg4);
return _invokeFunc_Obj4Args(obj: null, arg1, arg2, arg3, arg4)!;
}
}

return InvokeDirectByRef(arg1, arg2, arg3, arg4);
}

public object? Invoke(Span<object?> arguments)
public object Invoke(Span<object?> arguments)
{
if (!_needsByRefStrategy)
{
Expand Down Expand Up @@ -137,7 +137,7 @@ private ConstructorInvoker(RuntimeConstructorInfo constructor, RuntimeType[] arg
return InvokeWithFewArgs(arguments);
}

internal object? InvokeWithFewArgs(Span<object?> arguments)
internal object InvokeWithFewArgs(Span<object?> arguments)
{
Debug.Assert(_argCount <= MaxStackAllocArgCount);

Expand All @@ -155,7 +155,7 @@ private ConstructorInvoker(RuntimeConstructorInfo constructor, RuntimeType[] arg
// Check fast path first.
if (_invokeFunc_ObjSpanArgs is not null)
{
return _invokeFunc_ObjSpanArgs(obj : null, copyOfArgs);
return _invokeFunc_ObjSpanArgs(obj : null, copyOfArgs)!;
// No need to call CopyBack here since there are no ref values.
}

Expand All @@ -164,22 +164,22 @@ private ConstructorInvoker(RuntimeConstructorInfo constructor, RuntimeType[] arg
DetermineStrategy_ObjSpanArgs(ref _strategy, ref _invokeFunc_ObjSpanArgs, _method, _needsByRefStrategy, backwardsCompat: false);
if (_invokeFunc_ObjSpanArgs is not null)
{
return _invokeFunc_ObjSpanArgs(obj: null, copyOfArgs);
return _invokeFunc_ObjSpanArgs(obj: null, copyOfArgs)!;
}
}

object? ret = InvokeDirectByRefWithFewArgs(copyOfArgs);
object ret = InvokeDirectByRefWithFewArgs(copyOfArgs);
CopyBack(arguments, copyOfArgs, shouldCopyBack);
return ret;
}

internal object? InvokeDirectByRef(object? arg1 = null, object? arg2 = null, object? arg3 = null, object? arg4 = null)
internal object InvokeDirectByRef(object? arg1 = null, object? arg2 = null, object? arg3 = null, object? arg4 = null)
{
StackAllocatedArguments stackStorage = new(arg1, arg2, arg3, arg4);
return InvokeDirectByRefWithFewArgs(stackStorage._args.AsSpan(_argCount));
}

internal unsafe object? InvokeDirectByRefWithFewArgs(Span<object?> copyOfArgs)
internal unsafe object InvokeDirectByRefWithFewArgs(Span<object?> copyOfArgs)
{
if ((_strategy & InvokerStrategy.StrategyDetermined_RefArgs) == 0)
{
Expand All @@ -200,14 +200,14 @@ private ConstructorInvoker(RuntimeConstructorInfo constructor, RuntimeType[] arg
ByReference.Create(ref copyOfArgs[i]);
}

return _invokeFunc_RefArgs!(obj: null, pByRefFixedStorage);
return _invokeFunc_RefArgs!(obj: null, pByRefFixedStorage)!;
}

internal unsafe object? InvokeWithManyArgs(Span<object?> arguments)
internal unsafe object InvokeWithManyArgs(Span<object?> arguments)
{
Span<object?> copyOfArgs;
GCFrameRegistration regArgStorage;
object? ret;
object ret;

if ((_strategy & InvokerStrategy.StrategyDetermined_ObjSpanArgs) == 0)
{
Expand All @@ -232,7 +232,7 @@ private ConstructorInvoker(RuntimeConstructorInfo constructor, RuntimeType[] arg
copyOfArgs[i] = arg;
}

ret = _invokeFunc_ObjSpanArgs(obj: null, copyOfArgs);
ret = _invokeFunc_ObjSpanArgs(obj: null, copyOfArgs)!;
// No need to call CopyBack here since there are no ref values.
}
finally
Expand Down Expand Up @@ -274,7 +274,7 @@ private ConstructorInvoker(RuntimeConstructorInfo constructor, RuntimeType[] arg
ByReference.Create(ref Unsafe.AsRef<object>(pStorage + i));
}

ret = _invokeFunc_RefArgs!(obj: null, pByRefStorage);
ret = _invokeFunc_RefArgs!(obj: null, pByRefStorage)!;
CopyBack(arguments, copyOfArgs, shouldCopyBack);
}
finally
Expand Down
12 changes: 6 additions & 6 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11315,12 +11315,12 @@ protected ConstructorInfo() { }
public sealed partial class ConstructorInvoker
{
internal ConstructorInvoker() { }
public object? Invoke(System.Span<object?> arguments) { throw null; }
public object? Invoke() { throw null; }
public object? Invoke(object? arg1) { throw null; }
public object? Invoke(object? arg1, object? arg2) { throw null; }
public object? Invoke(object? arg1, object? arg2, object? arg3) { throw null; }
public object? Invoke(object? arg1, object? arg2, object? arg3, object? arg4) { throw null; }
public object Invoke(System.Span<object?> arguments) { throw null; }
public object Invoke() { throw null; }
public object Invoke(object? arg1) { throw null; }
public object Invoke(object? arg1, object? arg2) { throw null; }
public object Invoke(object? arg1, object? arg2, object? arg3) { throw null; }
public object Invoke(object? arg1, object? arg2, object? arg3, object? arg4) { throw null; }
public static System.Reflection.ConstructorInvoker Create(System.Reflection.ConstructorInfo constructor) { throw null; }
}
public partial class CustomAttributeData
Expand Down