Compiler updating user code

Sergei Nosov sergei.nosov at gmail.com
Fri Mar 14 02:13:37 PDT 2014


On Friday, 14 March 2014 at 07:10:43 UTC, Rikki Cattermole wrote:
> On Friday, 14 March 2014 at 05:15:05 UTC, Manu wrote:
>> So it comes up fairly regularly that people suggest that the 
>> compiler
>> should have a mode where it may update user code automatically 
>> to assist
>> migration to new compiler versions.
>>
>> I'm personally against the idea, and Walter certainly doesn't 
>> like it, but
>> it occurred to me that a slight variation on this idea might 
>> be awesome.
>>
>> Imagine instead, an '-update' option which instead of 
>> modifying your code,
>> would output a .patch file containing suggested amendments 
>> wherever it
>> encountered deprecated code...
>> The user can then take this patch file, inspect it visually 
>> using their
>> favourite merge tool, and pick and choose the bits that they 
>> agree or
>> disagree with.
>>
>> I would say this approach takes a dubious feature and turns it 
>> into a
>> spectacular feature!
>>
>> Language changes are probably easy enough to handle, but what 
>> about cases
>> of 'deprecated' in the library?
>> It's conceivable that the deprecated keyword could take an 
>> optional
>> argument to a CTFE function which would receive the expression 
>> as a string,
>> and the function could transform and return an amended string 
>> which would
>> also be added to the output patch file. This way, the feature 
>> could
>> conceivably also offer upgrade advice for arbitrary library 
>> changes.
>>
>> Considering the advice in the context of a visual diff/merge 
>> window would
>> be awesome if you ask me.
>
> Sounds like a cool idea. But not as part of the compiler. Its 
> more of a use case for compiler as a library ;)

I believe the first candidate is `dub fix` - by analogy with `go 
fix`. I also believe this kind of tool would be great for 
handling language changes. However, it seems implementing and 
maintaining it is quite a lot of work.


More information about the Digitalmars-d mailing list