www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - refactoring issues

reply "Ivan Kazmenko" <gassa mail.ru> writes:
Hi,

I was just refactoring a project to compile under 2.067.

The fixes themselves were trivial: just adding "import 
std.traits;" to some files.  Apparently its pieces were publicly 
imported by another module in 2.066.  So, it's the right fix 
anyway.

Understanding what happened, however, took more time than fixing. 
  Surely, the compiler couldn't just say "hey, I know, you forgot 
to import std.traits!", and threw some distant consequences at me 
instead.  Essentially, there were two complications:

1. In a complex template constraint, if some identifier 
disappears out of scope, the whole constraint silently fails, and 
the whole template instantiation fails with a rather generic 
error message.

2. When the compiler could not find a suitable overload of a 
function, if there are template and non-template overloads, it 
lists only non-template overloads.

My question therefore is: can the process be improved somehow to 
address the above issues?  For the former problem, is there a 
tool which jumps out and tells you use Phobos without importing 
things properly, or suggests a Phobos import by the name of the 
stuff.  For the latter one, I wonder if this is the intended 
behavior.

Ivan Kazmenko.
Mar 17 2015
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Tuesday, 17 March 2015 at 15:11:02 UTC, Ivan Kazmenko wrote:
 For the former problem, is there a tool which jumps out and 
 tells you use Phobos without importing things properly, or 
 suggests a Phobos import by the name of the stuff.
I did make something simple for myself, but it doesn't work in the more complicated cases you mentioned (contracts failing because of missing imports). http://dump.thecybershadow.net/e91be687ebaeb0171d830025adf82848/autofix.gif I could post the code but the editor integration part is pretty specific to my editor.
Mar 19 2015
parent reply "Ivan Kazmenko" <gassa mail.ru> writes:
On Thursday, 19 March 2015 at 10:21:09 UTC, Vladimir Panteleev 
wrote:
 On Tuesday, 17 March 2015 at 15:11:02 UTC, Ivan Kazmenko wrote:
 For the former problem, is there a tool which jumps out and 
 tells you use Phobos without importing things properly, or 
 suggests a Phobos import by the name of the stuff.
I did make something simple for myself, but it doesn't work in the more complicated cases you mentioned (contracts failing because of missing imports). http://dump.thecybershadow.net/e91be687ebaeb0171d830025adf82848/autofix.gif I could post the code but the editor integration part is pretty specific to my editor.
Hey, I also happen to use Far Manager and its internal editor, at least for simple projects. Is that dcheck triggering a Far plugin? I have a bit of experience with Far recording macros, but didn't try to write a plugin.
Mar 19 2015
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Thursday, 19 March 2015 at 14:32:53 UTC, Ivan Kazmenko wrote:
 Hey, I also happen to use Far Manager and its internal editor, 
 at least for simple projects.  Is that dcheck triggering a Far 
 plugin?  I have a bit of experience with Far recording macros, 
 but didn't try to write a plugin.
It's all a bit of a mess... A FAR Lua macro[1] runs dcheck, which is just a batch file that runs DMD piped through colorout[2], which in turn parses the compiler output and records the results to a temporary file, that's read by a second program that parses and caches the .json files generated as part of my D build process and then generates editing instructions read back by the Lua macro. [1]http://dump.thecybershadow.net/5c0afb5c0f4306b1368dd8528c838133/F9.lua [2]http://blog.thecybershadow.net/2013/07/27/colorize-your-compilers-output/
Mar 19 2015
parent reply "Ivan Kazmenko" <gassa mail.ru> writes:
On Thursday, 19 March 2015 at 16:06:31 UTC, Vladimir Panteleev 
wrote:
 On Thursday, 19 March 2015 at 14:32:53 UTC, Ivan Kazmenko wrote:
 Hey, I also happen to use Far Manager and its internal editor, 
 at least for simple projects.  Is that dcheck triggering a Far 
 plugin?  I have a bit of experience with Far recording macros, 
 but didn't try to write a plugin.
It's all a bit of a mess... A FAR Lua macro[1] runs dcheck, which is just a batch file that runs DMD piped through colorout[2], which in turn parses the compiler output and records the results to a temporary file, that's read by a second program that parses and caches the .json files generated as part of my D build process and then generates editing instructions read back by the Lua macro. [1]http://dump.thecybershadow.net/5c0afb5c0f4306b1368dd8528c838133/F9.lua [2]http://blog.thecybershadow.net/2013/07/27/colorize-your-compilers-output/
Thanks. I was able to reproduce the workflow you showed in the gif to the part where an error pop-up (e.g. "no property iota for type int") is followed by suggesting the appropriate fix. Do I need another tool for that? Colorout does not seem to suggest fixes. Also, what about this?
2. When the compiler could not find a suitable overload of a 
function, if there are template and non-template overloads, it 
lists only non-template overloads.
Since no one replied by rationalizing that it works as intended, perhaps I should file an issue about it? Ivan Kazmenko.
Mar 20 2015
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Friday, 20 March 2015 at 18:05:07 UTC, Ivan Kazmenko wrote:
 Thanks.  I was able to reproduce the workflow you showed in the 
 gif to the part where an error pop-up (e.g. "no property iota 
 for type int") is followed by suggesting the appropriate fix.  
 Do I need another tool for that?  Colorout does not seem to 
 suggest fixes.
OK, here it is: https://github.com/CyberShadow/AutoFix It has some hardcoded paths though.
Mar 20 2015
parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Friday, 20 March 2015 at 18:36:19 UTC, Vladimir Panteleev 
wrote:
 On Friday, 20 March 2015 at 18:05:07 UTC, Ivan Kazmenko wrote:
 Thanks.  I was able to reproduce the workflow you showed in 
 the gif to the part where an error pop-up (e.g. "no property 
 iota for type int") is followed by suggesting the appropriate 
 fix.  Do I need another tool for that?  Colorout does not seem 
 to suggest fixes.
OK, here it is: https://github.com/CyberShadow/AutoFix It has some hardcoded paths though.
It's used like this: C:\Path\To\colorout\colorout ^ --json C:\Temp\colorout.json ^ --trigger id=C:\Path\To\AutoFix\autofix.exe ^ C:\Path\To\colorout\d.col ^ dmd, rdmd etc...
Mar 20 2015
parent "Ivan Kazmenko" <gassa mail.ru> writes:
On Friday, 20 March 2015 at 18:37:57 UTC, Vladimir Panteleev 
wrote:
 On Friday, 20 March 2015 at 18:36:19 UTC, Vladimir Panteleev 
 wrote:
 On Friday, 20 March 2015 at 18:05:07 UTC, Ivan Kazmenko wrote:
 Thanks.  I was able to reproduce the workflow you showed in 
 the gif to the part where an error pop-up (e.g. "no property 
 iota for type int") is followed by suggesting the appropriate 
 fix.  Do I need another tool for that?  Colorout does not 
 seem to suggest fixes.
OK, here it is: https://github.com/CyberShadow/AutoFix It has some hardcoded paths though.
It's used like this: C:\Path\To\colorout\colorout ^ --json C:\Temp\colorout.json ^ --trigger id=C:\Path\To\AutoFix\autofix.exe ^ C:\Path\To\colorout\d.col ^ dmd, rdmd etc...
Yay, I finally got it working! Thank you, it feels nice. Theoretically, AutoFix can be extended to handle cases similar to mine, though the details may be cumbersome. The template constraint is reported by the compiler, so the identifier to be imported is right there in the error message. One may just tokenize the string and loop over the identifiers... But that will perhaps generate too much noise in suggestions. The biggest thing to learn for me however was that I can use JSON files of Phobos and druntime, which in turn can be generated by building them. Ivan Kazmenko.
Mar 22 2015