digitalmars.D.internals - di files vs CTFE
- Jean-Louis Leroy (18/18) Aug 04 2017 Hi,
- Stefan Koch (3/7) Aug 04 2017 make the function return auto.
- Jean-Louis Leroy (2/12) Aug 04 2017 Thanks. This is, hmmm, surprising ;-)
- Stefan Koch (4/17) Aug 04 2017 for the auto return type to work the compiler needs to infer it.
- Jean-Louis Leroy (5/23) Aug 04 2017 I see...OTOH the compiler could resolve the return type when
- Stefan Koch (5/10) Aug 05 2017 No, the header-generation is done before sema.
- Jacob Carlborg (8/13) Aug 05 2017 I've used that workaround as well. If you still want to go with the
Hi, While working on my openmethods library, I came across a gap that may be worth filling. I have this kind of code: // in openmethods.d string registerMethods() { ... } // in code using the lib import openmethods; mixin(registerMethods); When I add -H, the interface file takes precedence over the source file, but the body of registerMethods() is removed. I easily found a workaround - make the function a template (see here https://github.com/jll63/openmethods.d/commit/6a7bf93932bebc53fca36 e2280c71a0cbbf3c3b) but it's a bit of a hack. I also had to remove a couple of ctors that was there only because of my ignorance at the time. I tried pragma(inline) but it doesn't preserve the body. Maybe it should, because you cannot inline without the source. Or maybe we need another pragma, I couldn't find a nice name but something along pragma(interface) or pragma(keepBody).
Aug 04 2017
On Friday, 4 August 2017 at 13:55:29 UTC, Jean-Louis Leroy wrote:Hi, While working on my openmethods library, I came across a gap that may be worth filling. [...]make the function return auto. Then you'll have the body.
Aug 04 2017
On Friday, 4 August 2017 at 16:33:06 UTC, Stefan Koch wrote:On Friday, 4 August 2017 at 13:55:29 UTC, Jean-Louis Leroy wrote:Thanks. This is, hmmm, surprising ;-)Hi, While working on my openmethods library, I came across a gap that may be worth filling. [...]make the function return auto. Then you'll have the body.
Aug 04 2017
On Saturday, 5 August 2017 at 00:45:51 UTC, Jean-Louis Leroy wrote:On Friday, 4 August 2017 at 16:33:06 UTC, Stefan Koch wrote:for the auto return type to work the compiler needs to infer it. in order to infer it you need the body ;)On Friday, 4 August 2017 at 13:55:29 UTC, Jean-Louis Leroy wrote:Thanks. This is, hmmm, surprising ;-)Hi, While working on my openmethods library, I came across a gap that may be worth filling. [...]make the function return auto. Then you'll have the body.
Aug 04 2017
On Saturday, 5 August 2017 at 01:05:41 UTC, Stefan Koch wrote:On Saturday, 5 August 2017 at 00:45:51 UTC, Jean-Louis Leroy wrote:I see...OTOH the compiler could resolve the return type when generating the .di file, then the body would not be needed anymore. I changed my registerMethods back from a template to an auto function but I feel that I am in undocumented territory here.On Friday, 4 August 2017 at 16:33:06 UTC, Stefan Koch wrote:for the auto return type to work the compiler needs to infer it. in order to infer it you need the body ;)On Friday, 4 August 2017 at 13:55:29 UTC, Jean-Louis Leroy wrote:Thanks. This is, hmmm, surprising ;-)Hi, While working on my openmethods library, I came across a gap that may be worth filling. [...]make the function return auto. Then you'll have the body.
Aug 04 2017
On Saturday, 5 August 2017 at 02:12:33 UTC, Jean-Louis Leroy wrote:I see...OTOH the compiler could resolve the return type when generating the .di file, then the body would not be needed anymore. I changed my registerMethods back from a template to an auto function but I feel that I am in undocumented territory here.No, the header-generation is done before sema. Therefore it cannot reslove anything. That is not going to change.
Aug 05 2017
On 2017-08-04 15:55, Jean-Louis Leroy wrote:When I add -H, the interface file takes precedence over the source file, but the body of registerMethods() is removed. I easily found a workaround - make the function a template (see here https://github.com/jll63/openmethods.d/commit/6a7bf93932bebc53fca368e2280c71a0cbbf3c3b) but it's a bit of a hack.I've used that workaround as well. If you still want to go with the template, I recommend making the template argument empty: string registerMethods()(string moduleName = __MODULE__) Otherwise you'll get a new template instantiation for each call to the function where the module is different. -- /Jacob Carlborg
Aug 05 2017