question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Proposal: simplified arguments passing and first-class support of in parameters

See original GitHub issue

Hi Lucas!

I’m using InlineIL widely in my project .NEXT. Your add-in helping me a lot to write performance-critical code. However, I feel some inconvenience with it. The first one is an absence of support in-modifiers. Let’s take a look at this code:

 public static void Bitcast<T, TResult>(in T input, out TResult output)
            where T : unmanaged
            where TResult : unmanaged
        {
            const string slowPath = "slow";
            Ldarg(nameof(output));
            Sizeof(typeof(T));
            Sizeof(typeof(TResult));
            Blt_Un(slowPath);
            //copy from input into output as-is
            Ldarg(nameof(input));
            Ldobj(typeof(TResult));
            Stobj(typeof(TResult));
            Ret();

            MarkLabel(slowPath);
            Dup();
            Initobj(typeof(TResult));
            Ldarg(nameof(input));
            Ldobj(typeof(T));
            Stobj(typeof(T));
            Ret();
            throw Unreachable();    //output must be defined within scope
        }

I have to use Ldarg(nameof(input)) and Ldarg(nameof(output)) because there is no overloads with out and in parameters. This cause unwanted warnings from Roslyn about unused parameters.

The second issue is a method call. It’s verbose. I like Push helper that allows to push result of parameterless method or property on the evaluation stack. However, this approach is not working for call sites when arguments are not locals or parameters. In this case I have to use Call with call site descriptor object. I would like to propose T Arg<T>() and ref T RefArg<T>() helper which allow to load argument from the evaluation stack:

Ldc_I4(10);
Ldc_I4(2);
Push(Math.Max(Arg<int>(), Arg<int>());
return Return<int>();

//equivalent to
ldc.i4 10
ldc.i4 2
call Math.Max(int, int)
ret

Additionally, it would be great if InlineIL will be able to recognize params correctly:

Ldstr("Hello, {0}!");
Ldstr("Albert Wesker");
Push(Console.WriteLine(Arg<string>(), Arg<string>()); //automatically creates object[] array in resulted IL code
Ret();

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:27 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
saknocommented, Apr 10, 2020

Yes, sure. I need to inspect crash dump before this. It takes some time.

Also, you was right about configuration. I fixed everything and found the explanation why optimized build demonstrates worse result. It was because of my unawareness about how to correctly write benchmarks. If benchmark checks something that has return value then benchmark method should have return type as well.

1reaction
saknocommented, Apr 7, 2020

dotnet crashed with SIGABRT Unfortunately disassembler is not working, at least as easy as on Windows 😢

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposal: Support function parameter type constraints ...
Proposal. Part A: Introduce any T as a type constructor wildcard. Pattern matching at compile-time amounts to constrained comptime polymorphism ...
Read more >
Pass arguments back and forth between two classes
I have two classes (which are frames full of tkinter widgets - not relevant to the problem). The first class allows for user...
Read more >
Proposal: Register-based Go calling convention
Since its initial release, Go has used a stack-based calling convention based on the Plan 9 ABI, in which arguments and result values...
Read more >
Parameter overrides as a first class section in samconfig.toml
Practical example: I have a SAM stack that has an AWS::SecretsManager::secret , and so I need to pass a private RSA key in...
Read more >
Do not fear first class functions
Because WithCities takes an argument, we cannot simply pass WithCities to NewTerrain , its signature does not match.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found