Conversation
|
Thanks for your pull request and interest in making D better, @marler8997! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#10536" |
1b509c3 to
4f27caa
Compare
src/build.d
Outdated
| Takes a lambda and returns a memoized function to build a dependecy object. | ||
| */ | ||
| alias makeDep(alias Func) = memoize!(function() { | ||
| alias makeDep(alias Func, T...) = memoize!(function(T args) { |
There was a problem hiding this comment.
I've tried some solutions to avoid explicit types separated from the identifiers but ran into different issues:
- Explicit function:
undefined identifier R|T
| alias makeDep(alias Func, T...) = memoize!(function(T args) { | |
| alias makeDep(R function(DepBuilder*, DependencyRef, T) Func, R, T...) = memoize!(function(T args) { |
Rejected because it contains forward-references within the template parameter list
(This seems like an artificially restriction as e.g. template methods allow forward references to the return type but maybe I am underestimating the entailing implementation difficulties)
- Extracting parameter types using traits:
| alias makeDep(alias Func, T...) = memoize!(function(T args) { | |
| alias makeDep(alias Func) = memoize!(function(Parameters!Func[2..$] args) { |
Fails as it can't resolve the parameter types (probably caused by the cyclic dependency between Func and this lambda. Could a resolution fur such a scenario be realized in DMD with reasonable effort?)
- ?
There was a problem hiding this comment.
I came up with something that seems to work...
There was a problem hiding this comment.
Nice. It would be beneficial to conflate the builder and the dependency as this requires all parameter types to be spelled out.
Or at least have alias DependencyBuilder = MethodInitializer!DependencyRef*
There was a problem hiding this comment.
meh, I'm fine with MethodInitializer!DependencyRef*. It's a bit verbose but that doesn't bother me as it will only be used once.
There was a problem hiding this comment.
... as it will only be used once
Currently, but we can keep the full type anyway
There was a problem hiding this comment.
Using DependencyBuilder adds a level of indirection. Now you have to look up what a DependencyBuilder is and then see that it's a MethodInitializer and then look up what that is. This can be worth it to save extra characters, but since it's only being used in one place, I don't see any benefit to it.
ec64fc1 to
6082657
Compare
| } | ||
|
|
||
| /** Initializes an object using a chain of method calls */ | ||
| struct MethodInitializer(T) |
There was a problem hiding this comment.
Why is this a template now?
There was a problem hiding this comment.
Makes it more general, could be added to phobos. I try to structure the code in a way that general code could be factored out into a library.
PetarKirov
left a comment
There was a problem hiding this comment.
Nice work! I have some suggestions/questions:
|
|
||
| alias makeDepImpl(alias Func, T...) = memoize!(function(T args) { | ||
| auto builder = MethodInitializer!DependencyRef(new DependencyRef()); | ||
| Func(&builder, builder.obj, args); |
There was a problem hiding this comment.
| Func(&builder, builder.obj, args); | |
| Func(builder, builder.obj, args); |
There was a problem hiding this comment.
Good suggestion. Will include in the next PR.
| */ | ||
| alias dmdExe = memoize!(function(string targetSuffix, string[] extraFlags...) | ||
| { | ||
| alias dmdExe = makeDepWithArgs!((MethodInitializer!DependencyRef* builder, DependencyRef dep, string targetSuffix, string[] extraFlags) { |
There was a problem hiding this comment.
| alias dmdExe = makeDepWithArgs!((MethodInitializer!DependencyRef* builder, DependencyRef dep, string targetSuffix, string[] extraFlags) { | |
| alias dmdExe = makeDepWithArgs!((MethodInitializer!DependencyRef builder, DependencyRef dep, string targetSuffix, string[] extraFlags) { |
| "-of" ~ target, | ||
| "-of" ~ dep.target, | ||
| "-vtls", | ||
| "-J"~env["G"], |
There was a problem hiding this comment.
As far as I can see, in order to use the output of versionFile target, we need to add the "-J"~env["G"] string import. Am I missing something?
There was a problem hiding this comment.
Its part of flags["DFLAGS"], see
https://github.com/marler8997/dmd/blob/6082657531b5fa5da5e91c78d8b4a88afcfe403d/src/build.d#L798
There was a problem hiding this comment.
Thanks, indeed I missed that part.
condense
build.da bit more using the new initialization technique