An Issue I Wish To Raise Awareness On

Arek via Digitalmars-d digitalmars-d at puremagic.com
Mon Aug 14 11:59:17 PDT 2017


On Monday, 14 August 2017 at 16:49:22 UTC, Atila Neves wrote:
> On Saturday, 12 August 2017 at 19:34:35 UTC, Arek wrote:
>> On Friday, 21 July 2017 at 08:53:44 UTC, Atila Neves wrote:
... /cut/...
>
> It's a template postblit constructor - it'd get instantiated 
> differently depending on the type of the implicit `this` 
> parameter and would be able to fix things up taking into 
> account whether or not `this` was shared (or immutable).
>
> Atila

I've tested this code on dmd 2.075.0 and it doesn't behave like 
postblit.

It's not executed in these statements:
     auto nonSharedCopy = nonShared;
     auto sharedCopy = shared_;

To get it executed, you have to change the statements into
     auto nonSharedCopy = A(nonShared);
     auto sharedCopy = A(shared_);

this(this T)(this) is compiled into

0000000000000000 <shared(ref shared(b.A) 
function(immutable(char)[])) b.A.__ctor>:
    0:	55                   	push   %rbp
    1:	48 8b ec             	mov    %rsp,%rbp
    4:	48 89 f8             	mov    %rdi,%rax
    7:	5d                   	pop    %rbp
    8:	c3                   	retq
    9:	00 00                	add    %al,(%rax)
	...
what is exacly the same as the constructor:

0000000000000000 <ref b.A b.A.__ctor(immutable(char)[])>:
    0:	55                   	push   %rbp
    1:	48 8b ec             	mov    %rsp,%rbp
    4:	48 89 f8             	mov    %rdi,%rax
    7:	5d                   	pop    %rbp
    8:	c3                   	retq
    9:	00 00                	add    %al,(%rax)
	...

The real postblit looks like this:
Disassembly of section .text.void b.A.__postblit():

0000000000000000 <void b.A.__postblit()>:
    0:	55                   	push   %rbp
    1:	48 8b ec             	mov    %rsp,%rbp
    4:	48 83 ec 10          	sub    $0x10,%rsp
    8:	48 89 7d f8          	mov    %rdi,-0x8(%rbp)
    c:	b8 73 00 00 00       	mov    $0x73,%eax
   11:	b9 0a 00 00 00       	mov    $0xa,%ecx
   16:	99                   	cltd
   17:	f7 f9                	idiv   %ecx
   19:	48 83 7d f8 00       	cmpq   $0x0,-0x8(%rbp)
   1e:	75 2e                	jne    4e <void b.A.__postblit()+0x4e>
   20:	49 89 c8             	mov    %rcx,%r8
   23:	48 8d 0d 00 00 00 00 	lea    0x0(%rip),%rcx        # 2a 
<void b.A.__postblit()+0x2a>
   2a:	b8 03 00 00 00       	mov    $0x3,%eax
   2f:	48 89 c2             	mov    %rax,%rdx
   32:	48 89 55 f0          	mov    %rdx,-0x10(%rbp)
   36:	48 8d 15 00 00 00 00 	lea    0x0(%rip),%rdx        # 3d 
<void b.A.__postblit()+0x3d>
   3d:	bf 09 00 00 00       	mov    $0x9,%edi
   42:	48 89 d6             	mov    %rdx,%rsi
   45:	48 8b 55 f0          	mov    -0x10(%rbp),%rdx
   49:	e8 00 00 00 00       	callq  4e <void b.A.__postblit()+0x4e>
   4e:	c9                   	leaveq
   4f:	c3                   	retq

So, in my opinion, your example compiles (but doesn't work) 
because it doesn't have the user defined postblit.

It's a pity, because it's looked promising.

Arek


More information about the Digitalmars-d mailing list