qsharp-runtime icon indicating copy to clipboard operation
qsharp-runtime copied to clipboard

Functions in Microsoft.Quantum.Bitwise should be marked as inline and implemented via operators

Open swernli opened this issue 4 years ago • 5 comments

The functions in Microsoft.Quantum.Bitwise are currently body intrinsic meaning they rely on an external implementation. However, Q# supports the bitwise operators as part of the language now, so these should be marked with the inline attribute and implemented via those operators.

See https://github.com/microsoft/qsharp-runtime/blob/main/src/Simulation/QSharpFoundation/Bitwise/Bitwise.qs#L21 for example.

swernli avatar Feb 01 '21 18:02 swernli

Do you mean an @Inline() attribute in Q#? I don't think Q# has one of those.

bamarsha avatar Feb 01 '21 19:02 bamarsha

Ah, I might be getting ahead of myself then. Maybe we can leave the desire to inline them as a comment in the new implementations?

swernli avatar Feb 01 '21 20:02 swernli

I think the most common scenario for the operator functions is to use with HOFs, in which case I'm not sure that inlining would be possible - you would need some function value to pass to something expecting a function type.

bamarsha avatar Feb 01 '21 20:02 bamarsha

@swernli @samarsha The QIR emission makes use of an Inline attribute in addition to the TargetIntrinsic attribute. We need to add both of these to the runtime in any case, so we should attach the inline attribute where it makes sense (right now the compiler has no heurtistics for determining when to inline automatically; it inlines only if the attribute is present).

bettinaheim avatar Feb 02 '21 05:02 bettinaheim

I believe this was resolved by #497. @bettinaheim should we keep this issue open to track adding the Inline attribute to bitwise functions, or is it worth closing this and opening a separate issue to add Inline attributes more broadly across the runtime?

swernli avatar Jun 01 '21 18:06 swernli