LDC asm for int128
I want to translate this c code into d (build with ldc), so I can use -flto and inline with other code. uint64_t _wymum(uint64_t A, uint64_t B){ __uint128_t r = A ; r *= B; return (r>>64)^r; } Do i need ASM or is there a easy way to implement it ?
Re: ref auto getRange() return scope move struct ?
On Friday, 16 August 2019 at 16:22:27 UTC, Jonathan M Davis wrote: [...] Thanks very much again, very helpful explain. I use pass by ref scope instead "return TreeRange.__ctor();" to workround this issue.
Re: ref auto getRange() return scope move struct ?
On Friday, 16 August 2019 at 13:51:49 UTC, Jonathan M Davis wrote: It is not possible to prevent moving in D as things currently stand. DIP 1014 will need to be implemented to either hook into moves or to prevent them. However, once DIP 1014 has been implemented, I would expect the result to be that what you're trying to do here simply wouldn't work if you disallowed moving, since DIP 1014 doesn't affect when the compiler does a move. It just allows you to hook into when a move takes place so that you can do stuff like adjust pointers, and presumably, if you @disable the function that hooks into the move, moving will then be disabled (though IIRC, that's not explicitly called out in DIP 1014; it's just what would naturally fall out from how @disable works). - Jonathan M Davis Thanks for the very helpful explain, I will try find some work around to fix this. One more question: If the struct has "@disable this() ;@disable this(this) ;", and the instance is stored into other struct member or local|global vars, it will never moved again?
Re: ref auto getRange() return scope move struct ?
On Friday, 16 August 2019 at 12:23:01 UTC, Newbie2019 wrote: I has this simple function has some memory bugs: --- struct TreeRange { @disable this() ; @disable this(this) ; } struct Tree { ref auto getRange() return scope { return TreeRange!T(_root); } } Tree tree; auto range = tree.getRange(); -- when I trace the issue, I find the address for TreeRange is moved. it TreeRange.__ctor the address is 0x7ffeefbfd168, but "auto range = tree.getRange();" address is 0x7ffeefbfd420 How to prevent this struct move in this case ? With dip1014 I can fix the internal pointer(but I guess It will need maybe 1 years late to implement). Right now I just want forbit the move action, is it doable ?
ref auto getRange() return scope move struct ?
I has this simple function has some memory bugs: --- struct TreeRange { @disable this() ; @disable this(this) ; } struct Tree { ref auto getRange() return scope { return TreeRange!T(_root); } } Tree tree; auto range = tree.getRange(); -- when I trace the issue, I find the address for TreeRange is moved. it TreeRange.__ctor the address is 0x7ffeefbfd168, but "auto range = tree.getRange();" address is 0x7ffeefbfd420 How to prevent this struct move in this case ?
Re: how to get the struct member as delegate type ?
On Tuesday, 30 July 2019 at 10:08:55 UTC, Newbie2019 wrote: foreach(int name_index, name; __traits(allMembers, S) ) static if( isDelegateMember!(S, name, Type) ) { enum Rules = getUDAs!( __traits(getMember, S, name) , Rule); // handle the member is match this rules. } And one more question, how to get the Function address or delegate address of a struct member on compile time ? struct S { void onMatch(){} } __gshared auto onMatch = (&(S.init)).funcptr ; // this not work
Re: how to get the struct member as delegate type ?
On Tuesday, 30 July 2019 at 10:06:21 UTC, Newbie2019 wrote: template isDelegateMember(S, string name, D) if(is(S == struct) && __traits(hasMember, S, name) && is( D == delegate ) ) { alias Fn= typeof( __traits(getMember, S.init, name) ); static assert( isFunction!Fn ); pragma(msg, D); pragma(msg, typeof(D.init.funcptr)); pragma(msg, Fn ); pragma(msg, __traits(isSame, Fn, typeof(D.init.funcptr)) ); enum isDelegateMember = is( Fn == typeof(D.init.funcptr) ) ; } foreach(int name_index, name; __traits(allMembers, S) ) static if( isDelegateMember!(S, name, Type) ) { enum Rules = getUDAs!( __traits(getMember, S, name) , Rule); // handle the member is match this rules. }
how to get the struct member as delegate type ?
I need to check on struct members is match a delegate type. for example; alias Type = scope void delegate(int) @nogc ; struct S { void onMatch1(int) scope @nogc { } void onNotMatch2(int) scope { } void onNotMatch2(int, int) scope @nogc { } Type not_match3; } please notify not_match3 member is should return false, I try this template but not work: template isDelegateMember(S, string name, D) if(is(S == struct) && __traits(hasMember, S, name) && is( D == delegate ) ) { alias Fn= typeof( __traits(getMember, S.init, name) ); static assert( isFunction!Fn ); pragma(msg, D); pragma(msg, typeof(D.init.funcptr)); pragma(msg, Fn ); pragma(msg, __traits(isSame, Fn, typeof(D.init.funcptr)) ); enum isDelegateMember = is( Fn == typeof(D.init.funcptr) ) ; }
Re: struct is not copyable because it is annotated with @disable bugs ?
On Saturday, 27 July 2019 at 17:13:45 UTC, Adam D. Ruppe wrote: If you change that to just plain `return NodeList(a, b);`, while keeping the first line, it will compile too. The reason here is when you return and construct together, it constructs it in-place. But if you put it in a local variable first, it needs to copy it to the return value. Removing the first line just lets the compiler optimize out the local variable, reducing it to the in-place one again. But explicitly returning and constructing together works in either case. Thanks your for the very quick and good explain. I thinks the DMD should report a more helpful error about this.
struct is not copyable because it is annotated with @disable bugs ?
I think this is a bug. If I return a struct more than one times, will throw this error. If I return once, every thing is ok. https://run.dlang.io/is/T4kWKM ref auto getList() return scope { if( i ) return NodeList(null); // remove this line will fix this error A* a; B* b; auto list = NodeList(a, b); return list; }
Re: Is there a way to bypass the file and line into D assert function ?
On Monday, 22 July 2019 at 09:54:13 UTC, Jacob Carlborg wrote: On 2019-07-19 22:16, Max Haughton wrote: Isn't assert a template (file and line) rather than a plain function call? No. It's a keyword, it's built-in to the compiler. It get extra benefits compared to a regular functions: the asserts will be removed in release builds. Thanks for explain.
Re: Is this a new bug ?
On Saturday, 20 July 2019 at 14:19:08 UTC, Adam D. Ruppe wrote: Like the other person said, try/catch turns throws to nothrow. The `debug` keyword disables pure checks. Those make this easy without any mixin or wrappers/casts at all. But even if you did want to do the mixin route, look at how Phobos does this. http://dpldocs.info/experimental-docs/std.traits.SetFunctionAttributes.1.html the example of that function shows adding pure to a function pointer. (and btw I think the phobos function itself works with -betterC as well, you might be able to simply call it). Thanks your all for explain, now i get a better understand how pure & debug & nothrow to work together.
Re: Is this a new bug ?
On Saturday, 20 July 2019 at 09:01:21 UTC, Newbie2019 wrote: I want to cast std.stdio : writefln into pure function pointer, so I can call it from debug pure function. is there a way to work around the pure check for call writefln ? nothrow check, not pure.
Re: Is this a new bug ?
On Saturday, 20 July 2019 at 06:43:03 UTC, user1234 wrote: use `__traits(identifier)` instead of `.stringof`, see https://dlang.org/spec/traits.html#identifier. as explained this is not a new bug, not even a bug according to me. I want to cast std.stdio : writefln into pure function pointer, so I can call it from debug pure function. is there a way to work around the pure check for call writefln ?
Re: Is this a new bug ?
On Saturday, 20 July 2019 at 04:18:15 UTC, Adam D. Ruppe wrote: show me what you're doing now and I'll see which case it is. Most the time I see these, the code is significantly simplified and bugs fixed by removing the usages of these strings.. I want to do this in betterC: template asPure(string P, alias Fn) if (isFunctionPointer!(typeof(&Fn))) { enum N = __traits(identifier, Fn); enum string asPure = "private alias " ~ N ~ "_P = " ~ typeof(&Fn).stringof ~ " pure;\n" ~ "__gshared immutable " ~ N ~ "_P " ~ P ~"= cast(" ~ N ~ "_P) &" ~ N ~ " ;" ; }
Re: Is this a new bug ?
On Saturday, 20 July 2019 at 03:58:36 UTC, Adam D. Ruppe wrote: You should never actually need that! What is your use case? In most cases I see people doing .stringof, the correct solution is to simply... not. Use the local name directly. If you do need the name - and the only cases for this ought to be declaring a new item for public consumption or for interfacing with users - the correct way to get an identifier is `__traits(identifier, T)`... but again, more often than not, you do NOT need this and it is wrong to try! .stringof should almost never be used except for debugging, and string concatenation in string mixings is actually only necessary for new declaration names. OK: mixin("int " ~ name ~ " = T;"); Wrong: mixin("int " ~ name ~ " = " ~ T.stringof ~ ";"); Thanks very much, __traits(identifier, Fn) is what I need. I may not fully understand why I can done it without identifier.stringof, I also need this string mixin for code and debug. so I just go with __traits(identifier, Fn) right now.
Is this a new bug ?
template Test(alias T){ pragma(msg, T.stringof); enum Test = T.stringof; } string t1; void t2(){} void t3(string s){} extern(C) void main(){ enum x1 = Test!(t1); // ok enum x2 = Test!(t2); // expect t2, but get t2() enum x3 = Test!(t3); //Error: function test2.t3(string s) is not callable using argument types () } I want get the function name "t2", "t3" for string mixin, how do I do this in D ?
Is there a way to bypass the file and line into D assert function ?
for example: void ASSERT(string fmt, string file = __FILE_FULL_PATH__, size_t line = __LINE__, T...) (bool c, scope T a) @nogc { assert(c, string, file, line); } but i get this error: error.d(39): Error: found file when expecting ) error.d(39): Error: found ) when expecting ; following statement error.d(39): Deprecation: use { } for an empty statement, not ; I want d to print the error message with some format information, and show the right file and line for the original location. Is it doable ?
can not find the error: Error: TypeInfo cannot be used with -betterC
when build my project with -betterC, it throw this error: Error: TypeInfo cannot be used with -betterC There is no location information about it, how can I find what code cause this ?
Re: Error: @nogc function run cannot call non-@nogc destructor TcpServer.~this
On Wednesday, 17 July 2019 at 12:16:54 UTC, Adam D. Ruppe wrote: It is also possible a member of the struct has a destructor that is triggering it. Thanks, I check all member and one of them is not @nogc nothrow. add @nogc nothrow to member fix it.
Error: @nogc function run cannot call non-@nogc destructor TcpServer.~this
this is very hard to made a minimal example, and the projects only build with ldc. There is a struct TcpServer has no destructor, and all method is @nogc nothrow. but some how when I use it on function run @nogc nothrow, ldc report : @nogc function run cannot call non-@nogc destructor TcpServer.~this this problem only exists for this TcpServer struct, all other struct without ~this() is ok. And the code run fun before we add copyConstructor, but this one has no copyConstructor.
Re: static variable A cannot be read at compile time
On Wednesday, 12 June 2019 at 13:53:09 UTC, H. S. Teoh wrote: On Wed, Jun 12, 2019 at 01:12:58PM +, Newbie2019 via Digitalmars-d-learn wrote: Read: https://wiki.dlang.org/User:Quickfur/Compile-time_vs._compile-time T Thanks for the tips. I move the static array into local var then it work. Still the last error message make no sense here.
static variable A cannot be read at compile time
https://run.dlang.io/is/s4cfiv onlineapp.d(23): Error: static variable A cannot be read at compile time onlineapp.d(23): Error: cannot implicitly convert expression 1 of type int to int* I see no reason the code should not work, and the second error message make no sense. please suggestion how should I made this code to work.