Skip to content

Conversation

@mingxwa
Copy link
Member

@mingxwa mingxwa commented Apr 7, 2025

Changes

  • In proxy_invoke, pass the reference of proxy instead of the reference of proxy::ptr_ to the indirect function pointer. With this change, the assembly generated from caller side could be further optimized.

For example, for the code presented in section 5.1.3, P3086R3:

PRO_DEF_MEM_DISPATCH(MemDraw, Draw);
struct FDrawable : facade_builder
    ::add_convention<MemDraw, void() const>
    ::build {};

p->Draw();  // p is a value of proxy<FDrawable>

Here is a comparison table of the generated assembly before and after this change:

Compiler Before After
x86-64 (AMD64) Clang 19.1.0 mov rax, qword ptr [rdi]
add rdi, 8
jmp qword ptr [rax + 16]
mov rax, qword ptr [rdi]
jmp qword ptr [rax + 16]
ARM64 Clang 19.1.0 ldr x8, [x0], #8
ldr x1, [x8, #16]
br x1
ldr x8, [x0]
ldr x1, [x8, #16]
br x1
RISC-V RV64 Clang 19.1.0 ld a1, 0(a0)
ld a5, 16(a1)
addi a0, a0, 8
jr a5
ld a1, 0(a0)
ld a5, 16(a1)
jr a5
  • The fallback of a weak dispatch is no longer nullptr, but proxy or proxy_indirect_accessor. This allows invoking other proxy functions from within a dispatch, similar to a default method in C# or Java.
  • Removed PRO_DEF_WEAK_DISPATCH (deprecated since 3.2.0).
  • Updated the implementation of the built-in dispatch types accordingly.
  • Updated unit tests accordingly.

Spec will be updated separately

@mingxwa mingxwa requested review from guominrui and tian-lt April 7, 2025 11:09
Copy link
Collaborator

@tian-lt tian-lt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mingxwa mingxwa merged commit 1c68a57 into microsoft:main Apr 8, 2025
8 checks passed
@mingxwa mingxwa deleted the user/mingxwa/improve-proxy-invocation branch April 8, 2025 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants