Skip to content

Commit f39a06b

Browse files
committed
add __traits(isReturnOnStack, func)
1 parent cb44110 commit f39a06b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

spec/traits.dd

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ $(GNAME TraitsKeyword):
4242
$(GLINK isRef)
4343
$(GLINK isOut)
4444
$(GLINK isLazy)
45+
$(GLINK isReturnOnStack)
4546
$(GLINK hasMember)
4647
$(GLINK identifier)
4748
$(GLINK getAliasThis)
@@ -399,6 +400,39 @@ static assert(!__traits(isTemplate,foo!int()));
399400
static assert(!__traits(isTemplate,"string"));
400401
---
401402

403+
$(H2 $(GNAME isReturnOnStack))
404+
405+
$(P
406+
Takes one argument which must either be a function symbol, function literal,
407+
a delegate, or a function pointer.
408+
It returns a `bool` which is `true` if the return value of the function is
409+
returned on the stack via a pointer to it passed as a hidden extra
410+
parameter to the function.
411+
)
412+
413+
---
414+
struct S { int[20] a; }
415+
int test1();
416+
S test2();
417+
418+
static assert(__traits(isReturnOnStack, test1) == false);
419+
static assert(__traits(isReturnOnStack, test2) == true);
420+
---
421+
422+
$(IMPLEMENTATION_DEFINED
423+
This is determined by the function ABI calling convention in use,
424+
which is often complex.
425+
)
426+
427+
$(BEST_PRACTICE This has applications in:
428+
$(OL
429+
$(LI Returning values in registers is often faster, so this can be used as
430+
a check on a hot function to ensure it is using the fastest method.)
431+
$(LI When using inline assembly to correctly call a function.)
432+
$(LI Testing that the compiler does this correctly is normally hackish and awkward,
433+
this enables efficient, direct, and simple testing.)
434+
))
435+
402436
$(H2 $(GNAME hasMember))
403437

404438
$(P The first argument is a type that has members, or

0 commit comments

Comments
 (0)