www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Mixin templates vs interface files

reply Jean-Louis Leroy <jl leroy.nyc> writes:
Consider:

// app.d

import std.stdio;
import tracemodule;

mixin traceModule;

void main()
{
   writeln("main");
}

// tracemodule.d

module tracemodule;

import std.stdio;

mixin template traceModule(string moduleName = __MODULE__)
{
   import std.stdio;

   static this()
   {
     writeln("init " ~ moduleName);
   }

   static ~this()
   {
     writeln("deinit " ~ moduleName);
   }
}

When I compile like this:

$ rm -f *.o *.di
$ dmd -c tracemodule.d
$ dmd -c app.d
$ dmd app.o tracemodule.o -of=app

...and run 'app' I get the expected output:

$ ./app
init app
main
deinit app

Now if I throw -H in, things get weird:

$ rm -f *.o *.di
$ dmd -c -H tracemodule.d
$ dmd -c app.d
$ dmd app.o tracemodule.o -of=app
$ ./app
init app
main

Indeed when I look at the content of the interface file, I see:

// D import file generated from 'tracemodule.d'
module tracemodule;
import std.stdio;
template traceModule(string moduleName = __MODULE__)
{
	import std.stdio;
	static this()
	{
		writeln("init " ~ moduleName);
	}
}

'static this()' is there, but no 'static ~this()'.

What's happening here?
Aug 06
parent reply Jean-Louis Leroy <jl leroy.nyc> writes:
On Sunday, 6 August 2017 at 13:24:23 UTC, Jean-Louis Leroy wrote:
 Consider:

 // app.d

 [...]
I see no reason why this() is kept and ~this() not. Should I report this as a bug?
Aug 07
parent Jean-Louis Leroy <jl leroy.nyc> writes:
On Tuesday, 8 August 2017 at 01:04:30 UTC, Jean-Louis Leroy wrote:
 On Sunday, 6 August 2017 at 13:24:23 UTC, Jean-Louis Leroy 
 wrote:
 Consider:

 // app.d

 [...]
I see no reason why this() is kept and ~this() not. Should I report this as a bug?
It seems to be happening here: https://github.com/dlang/dmd/blob/master/src/ddmd/hdrgen.d#L1982 Maybe if (hgs.hdrgen) return; should read: if (hgs.hdrgen && !hgs.tpltMember) return; When I make that change I get my static ~this in the .di file. Beyond that, I don't see the reason why visit(StaticDtorDeclaration d) is not a copy-paste of visit(StaticCtorDeclaration d) with one tilde added. PR?
Aug 07