www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - pragma(mangle, "name") suggestion !

reply Calvin P <changlon gmail.com> writes:
I intend use pragma(mangle, "name")   to avoid compiler generate 
extra long symbol name. but it not work nicely.


1:) it can not use with for function define inside a method.     
throw:  Error: unrecognized pragma(mangle)

I think if https://issues.dlang.org/show_bug.cgi?id=17638 get 
fixed will solve this problem.


2:) it can not use the enum value pass into the template.  for 
example:

===========
  pragma(mangle,  name ~ "_myAction")
void myAction(string name, ubyte[][] fields)(){


}
===========

I need this because the ubyte[][] fields is very big array,  the 
symbol length is like more than 2000. The  backtrace debug 
information is unable to reading even after demangle.


This kind change require DIPs?
Mar 18
next sibling parent reply Calvin P <changlon gmail.com> writes:
On Thursday, 19 March 2020 at 04:59:14 UTC, Calvin P wrote:
 ===========
  pragma(mangle,  name ~ "_myAction")
 void myAction(string name, ubyte[][] fields)(){


 }
 ===========
If allow pragma(mangle) defined inside function will fix this problem. just like pragma(inline); ======== void myAction(string name, ubyte[][] fields)(){ pragma(mangle, name ~ "_myAction"); pragma(inline, true); } ======
Mar 18
parent reply Mathias Lang <pro.mathias.lang gmail.com> writes:
On Thursday, 19 March 2020 at 05:05:37 UTC, Calvin P wrote:
 On Thursday, 19 March 2020 at 04:59:14 UTC, Calvin P wrote:
 ===========
  pragma(mangle,  name ~ "_myAction")
 void myAction(string name, ubyte[][] fields)(){


 }
 ===========
If allow pragma(mangle) defined inside function will fix this problem. just like pragma(inline); ======== void myAction(string name, ubyte[][] fields)(){ pragma(mangle, name ~ "_myAction"); pragma(inline, true); } ======
Or just use: template myAction(string name) { pragma(mangle, name ~ "_myAction") void myAction(ubyte[][] fields) () { ] } Although if you need to use such trick, I would recommend you to reorganize your code. Do you have a link to the code ?
Mar 18
parent Calvin P <changlon gmail.com> writes:
On Thursday, 19 March 2020 at 05:34:10 UTC, Mathias Lang wrote:
 Or just use:
 template myAction(string name)
 {
     pragma(mangle, name ~ "_myAction")
     void myAction(ubyte[][] fields) ()
     {
     ]
 }


 Although if you need to use such trick, I would recommend you 
 to reorganize your code.
 Do you have a link to the code ?
Thanks for the very kind tips. I can not provide link to code right now. Why I need this is because there is at lease 3 level embed function to provide ctfe && runtime Joint processing. each step depend last steps ctfe result and runtime results. It is doable to move them out( pass all the middle generate enum result and runtime result into global template), but with this the code will being hard to reading. for example: ========= auto getMyRactor(alias App)(Config config){ enum APP_RULES = getUDERules!(App); void myAction(ubyte[][] fields) (){ static if( APP_RULES.a && !APP_RULES.b ) { } else { } } config.handle = &myAction; App app; app.setConfig(config); return app; } ========= the point is there is 3 level function need to been passed as function address, and they depend on the uplevel enum const and runtime arguments. I will think about it to try if I can reorganize it to better shape.
Mar 18
prev sibling next sibling parent reply Tim <tim.dlang t-online.de> writes:
On Thursday, 19 March 2020 at 04:59:14 UTC, Calvin P wrote:
 ===========
  pragma(mangle,  name ~ "_myAction")
 void myAction(string name, ubyte[][] fields)(){


 }
 ===========
Another option is to pass a symbol instead of the data itself: struct FieldsWrapper { immutable ubyte[][] fields = [[1, 2, 3, 4]]; } void myAction(string name, T)(){ enum fields = T.fields; } void main() { myAction!("test", FieldsWrapper)(); } Now the mangled name of myAction contains only the struct name and not the complete data.
Mar 19
parent reply Calvin P <changlon gmail.com> writes:
On Thursday, 19 March 2020 at 16:38:22 UTC, Tim wrote:
 Another option is to pass a symbol instead of the data itself:

 struct FieldsWrapper
 {
     immutable ubyte[][] fields = [[1, 2, 3, 4]];
 }
 void myAction(string name, T)(){
     enum fields = T.fields;
 }
 void main()
 {
     myAction!("test", FieldsWrapper)();
 }

 Now the mangled name of myAction contains only the struct name 
 and not the complete data.
Thanks for the tips. with this methed I get a lot Error: variable name cannot be read at compile time but the name is enum and I am able to use them as const pass to template. and the new struct self has a very long symbol name. On Thursday, 19 March 2020 at 17:04:13 UTC, Johan wrote:
 You can use LDC's --hash-threshold for this (hashes symbol 
 names larger than a certain threshold.

 -Johan
Thanks for reply. I reduce the symbol name to easy debug process, I guess with hashes symbol will not help here.
Mar 21
parent Johan <j j.nl> writes:
On Saturday, 21 March 2020 at 14:00:51 UTC, Calvin P wrote:
 
 On Thursday, 19 March 2020 at 17:04:13 UTC, Johan wrote:
 You can use LDC's --hash-threshold for this (hashes symbol 
 names larger than a certain threshold.

 -Johan
Thanks for reply. I reduce the symbol name to easy debug process, I guess with hashes symbol will not help here.
The last part of the symbol is not hashed. See https://github.com/ldc-developers/ldc/pull/1445
Mar 21
prev sibling parent Johan <j j.nl> writes:
On Thursday, 19 March 2020 at 04:59:14 UTC, Calvin P wrote:
 I intend use pragma(mangle, "name")   to avoid compiler 
 generate extra long symbol name. but it not work nicely.
...
 I need this because the ubyte[][] fields is very big array,  
 the symbol length is like more than 2000. The  backtrace debug 
 information is unable to reading even after demangle.
You can use LDC's --hash-threshold for this (hashes symbol names larger than a certain threshold. -Johan
Mar 19