Skip to content
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

Cancel unnecessary instance method call #1204

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
18 changes: 18 additions & 0 deletions src/Neo.Compiler.CSharp/MethodConvert/Helpers/CallHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ private void CallInstanceMethod(SemanticModel model, IMethodSymbol symbol, bool

var (convert, methodCallingConvention) = GetMethodConvertAndCallingConvention(model, symbol);

if (NeedInstanceConstructor(symbol) && convert != null && convert.Instructions.Count >= 2)
{
Instruction initslot = convert.Instructions[0];
Instruction ret = convert.Instructions[1];
if (initslot.OpCode == OpCode.INITSLOT && initslot.Operand?[0] == 0 && initslot.Operand[1] == 1
&& ret.OpCode == OpCode.RET)
return; // Do not call meaningless contructors
}

HandleConstructorDuplication(instanceOnStack, methodCallingConvention, symbol);

PrepareArgumentsForMethod(model, symbol, arguments, methodCallingConvention);
Expand All @@ -98,6 +107,15 @@ private void CallMethodWithInstanceExpression(SemanticModel model, IMethodSymbol

var (convert, methodCallingConvention) = GetMethodConvertAndCallingConvention(model, symbol, instanceExpression);

if (NeedInstanceConstructor(symbol) && convert != null && convert.Instructions.Count >= 2)
{
Instruction initslot = convert.Instructions[0];
Instruction ret = convert.Instructions[1];
if (initslot.OpCode == OpCode.INITSLOT && initslot.Operand?[0] == 0 && initslot.Operand[1] == 1
&& ret.OpCode == OpCode.RET)
return; // Do not call meaningless contructors
}

HandleInstanceExpression(model, symbol, instanceExpression, methodCallingConvention, beforeArguments: true);

PrepareArgumentsForMethod(model, symbol, arguments, methodCallingConvention);
Expand Down
Loading