www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - BetterC is so much bugs, is Walter really use it in DMD?

reply test <test gmail.com> writes:
==================
import core.stdc.stdio;

version(D_BetterC) {
	extern(C) void main() {
		start;
	}
} else {
	void main(){
		start;
	}
}

struct Node {
	 disable this();
	 disable this(this);
	int _count = 0;
	
	this(int i){
		_count =i ;
	}
	
	void add(){
		_count++;
	}
	
	void dec(){
		_count--;
	}
}

struct Proxy {
	
	Node* p ;
	this(Node* n){
		assert(n);
		p = n ;
		p.add;
	}
	
	~this() {
		printf("~this(%x, p=%x)\n", &this, p) ;
		drop ;
	}
	
	void opAssign(ref Proxy other){
		printf("opAssign(ref this=%x, %x), other=%x, %x\n", &this, p, 
&other, other.p) ;
		drop ;
		assert(other.p);
		p	= other.p ;
		p.add ;
	}
	this(this) {
		printf("this(this)\n") ;
		if( p ) p.add ;
	}
	void opAssign(Proxy other){
		printf("opAssign(this=%x, %x), other=%x, %x\n", &this, p, 
&other, other.p) ;
		drop;
		if( other.p ) {
			p	= other.p ;
			p.add ;
		}
	}
	
	void drop(){
		if( p ) {
			p.dec;
		}
		p	= null ;
	}
}

__gshared Node n = Node(0) ;
__gshared ThreadS s ;
Proxy proxy;

void start(){
	run(null);
}

void run(void* data) {
	printf(" ========> run.enter\n") ;
	proxy = runFiber(&n);
	printf(" ========> run.exit\n") ;
}

ref auto runFiber(Node* p){
	auto fiber	= ThreadS.getThisS.getFiber(p);
	return fiber ;
}

struct ThreadS {
	static auto getThisS(){
		return &s;
	}
	ref auto getFiber(Node* p) {
		return fromPointer(p) ;
	}
}

ref auto fromPointer(Node* p) {
	return  Proxy(p) ;
}

version(D_BetterC) extern(C) {
	__gshared int _d_eh_personality(int, int, size_t, void*, void*) 
{ return 0;};
	__gshared void _d_eh_resume_unwind(void*) { return ;};
}
=================================




with -BetterC
  ========> run.enter
~this(c7da5060, p=3e40030)
opAssign(this=b40574b0, 0), other=c7da5030, 0
~this(c7da5030, p=0)
  ========> run.exit


without -BetterC
  ========> run.enter
opAssign(this=ffd1ab60, 0), other=885b32f0, 8f8da960
~this(885b32f0, p=8f8da960)
  ========> run.exit



Take me 16 hours to find this bug,  Is your people really use it 
to build compiler ?


Really is a good way to waste time to use this.
Oct 25 2018
next sibling parent reply rikki cattermole <rikki cattermole.co.nz> writes:
On 26/10/2018 1:47 AM, test wrote:

snip

 Take me 16 hours to find this bug,  Is your people really use it to 
 build compiler ?
 
 
 Really is a good way to waste time to use this.
I just compared the assembly, there isn't anything terribly different for Proxy.__dtor being called. So I would say that you have found some corner case bug. Please try to minimize it + report it to bugzilla (issues.dlang.org).
Oct 25 2018
parent reply test <test gmail.com> writes:
On Thursday, 25 October 2018 at 13:00:51 UTC, rikki cattermole 
wrote:
 I just compared the assembly, there isn't anything terribly 
 different for Proxy.__dtor being called. So I would say that 
 you have found some corner case bug.

 Please try to minimize it + report it to bugzilla 
 (issues.dlang.org).
============== import core.stdc.stdio; version(D_BetterC) { extern(C) void main() { start; } } else { void main(){ start; } } struct Proxy { this(bool i){} ~this() { printf("~this(%x)\n", &this) ; } void opAssign(Proxy other){ printf("opAssign(this=%x), other=%x\n", &this, &other) ; } } Proxy proxy; void start(){ proxy = getProxy(); } ref auto getProxy(){ auto proxy = Proxy(1); return proxy ; } version(D_BetterC) extern(C) { __gshared int _d_eh_personality(int, int, size_t, void*, void*) { return 0;}; __gshared void _d_eh_resume_unwind(void*) { return ;}; } ==================== still can not register, please help me to report.
Oct 25 2018
parent reply rikki cattermole <rikki cattermole.co.nz> writes:
After minimizing it myself (at the end), I think that you're running 
into https://issues.dlang.org/show_bug.cgi?id=18457

struct Node {}
struct Proxy {
     ~this() {
     	count++;
     }

	Node* n;
}

ref auto something(Node* p){
     auto value = Proxy(p);
     return value;
}

__gshared int count;

extern(C) void main() {
     Node n;
     something(&n);
     assert(count == 1);
}
Oct 25 2018
next sibling parent SrMordred <patric.dexheimer gmail.com> writes:
On Thursday, 25 October 2018 at 13:28:22 UTC, rikki cattermole 
wrote:
 After minimizing it myself (at the end), I think that you're 
 running into https://issues.dlang.org/show_bug.cgi?id=18457

 struct Node {}
 struct Proxy {
     ~this() {
     	count++;
     }

 	Node* n;
 }

 ref auto something(Node* p){
     auto value = Proxy(p);
     return value;
 }

 __gshared int count;

 extern(C) void main() {
     Node n;
     something(&n);
     assert(count == 1);
 }
I started to make some BetterC libs and fall on this same bug. It make it impossible to properly control resources lifetime if you return it from functions ;/
Oct 25 2018
prev sibling parent reply test <test gmail.com> writes:
On Thursday, 25 October 2018 at 13:28:22 UTC, rikki cattermole 
wrote:
 After minimizing it myself (at the end), I think that you're 
 running into https://issues.dlang.org/show_bug.cgi?id=18457
Thanks for share this. On Thursday, 25 October 2018 at 15:48:43 UTC, SrMordred wrote:
 I started to make some BetterC libs and fall on this same bug.
 It make it impossible to properly control resources lifetime if 
 you return it from functions ;/
Yes, is is make the refCount release not working, already 8 month passed, I am curious how many time take before it fixed. And there is more bugs I can not find or minimize in betterC since the codebase is huge. A bugs is still show after I remove all "debug{ ...}" code, I get it with "-betterC -debug"(not exists if I only pass -betterC). bin/../import/std/array.d(2957): Error: TypeInfo cannot be used with -betterC On Thursday, 25 October 2018 at 13:51:16 UTC, Adam D. Ruppe wrote:
 No, the compiler is built as ordinary D. betterC is just a toy 
 switch.

 But the bug there is that you used TLS without properly 
 initializing it. I am kinda of the opinion that betterC should 
 make this an error, or at least that -betterC should imply 
 -vtls, since it is so frequently a mistake.
As rikki cattermole said, this is not related to tls. and please don't make tls a error in betterC. since I use it in my product with betterC, with a tiny runtime(no typeinfo) it can working nice.
Oct 25 2018
parent reply Nicholas Wilson <iamthewilsonator hotmail.com> writes:
On Friday, 26 October 2018 at 01:50:01 UTC, test wrote:
 Yes, is is make the refCount release not working,  already 8 
 month passed, I am curious how many time take before it fixed.
Not long: https://github.com/dlang/dmd/pull/8872
Oct 26 2018
next sibling parent SrMordred <patric.dexheimer gmail.com> writes:
On Friday, 26 October 2018 at 10:12:14 UTC, Nicholas Wilson wrote:
 On Friday, 26 October 2018 at 01:50:01 UTC, test wrote:
 Yes, is is make the refCount release not working,  already 8 
 month passed, I am curious how many time take before it fixed.
Not long: https://github.com/dlang/dmd/pull/8872
Nice!
Oct 26 2018
prev sibling parent test <test gmail.com> writes:
On Friday, 26 October 2018 at 10:12:14 UTC, Nicholas Wilson wrote:
 On Friday, 26 October 2018 at 01:50:01 UTC, test wrote:
 Yes, is is make the refCount release not working,  already 8 
 month passed, I am curious how many time take before it fixed.
Not long: https://github.com/dlang/dmd/pull/8872
This is great.
Oct 26 2018
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Thursday, 25 October 2018 at 12:47:17 UTC, test wrote:
 Is your people really use it to build compiler ?
No, the compiler is built as ordinary D. betterC is just a toy switch. But the bug there is that you used TLS without properly initializing it. I am kinda of the opinion that betterC should make this an error, or at least that -betterC should imply -vtls, since it is so frequently a mistake.
Oct 25 2018
next sibling parent rikki cattermole <rikki cattermole.co.nz> writes:
On 26/10/2018 2:51 AM, Adam D. Ruppe wrote:
 On Thursday, 25 October 2018 at 12:47:17 UTC, test wrote:
 Is your people really use it to build compiler ?
No, the compiler is built as ordinary D. betterC is just a toy switch. But the bug there is that you used TLS without properly initializing it. I am kinda of the opinion that betterC should make this an error, or at least that -betterC should imply -vtls, since it is so frequently a mistake.
Its not TLS at fault. See my minimized code as an example. -betterC seems to be calling dtor when it shouldn't be (existing known bug).
Oct 25 2018
prev sibling next sibling parent 12345swordy <alexanderheistermann gmail.com> writes:
On Thursday, 25 October 2018 at 13:51:16 UTC, Adam D. Ruppe wrote:
 On Thursday, 25 October 2018 at 12:47:17 UTC, test wrote:
 Is your people really use it to build compiler ?
No, the compiler is built as ordinary D. betterC is just a toy switch. But the bug there is that you used TLS without properly initializing it. I am kinda of the opinion that betterC should make this an error, or at least that -betterC should imply -vtls, since it is so frequently a mistake.
Walter develop betterC for the conversion of the back end.
Oct 25 2018
prev sibling parent Jacob Carlborg <doob me.com> writes:
On 2018-10-25 15:51, Adam D. Ruppe wrote:

 But the bug there is that you used TLS without properly initializing it. 
The operating system is initializing TLS. -- /Jacob Carlborg
Oct 25 2018