Skip to content

Comments

Condense build#10536

Merged
RazvanN7 merged 1 commit intodlang:masterfrom
marler8997:condenseBuild
Nov 6, 2019
Merged

Condense build#10536
RazvanN7 merged 1 commit intodlang:masterfrom
marler8997:condenseBuild

Conversation

@marler8997
Copy link
Contributor

condense build.d a bit more using the new initialization technique

@dlang-bot
Copy link
Contributor

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 verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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 references

Your 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 locally

If 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"

@marler8997 marler8997 force-pushed the condenseBuild branch 3 times, most recently from 1b509c3 to 4f27caa Compare November 5, 2019 06:52
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) {
Copy link
Contributor

@MoonlightSentinel MoonlightSentinel Nov 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried some solutions to avoid explicit types separated from the identifiers but ran into different issues:

  1. Explicit function: undefined identifier R|T
Suggested change
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)

  1. Extracting parameter types using traits:
Suggested change
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?)

  1. ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came up with something that seems to work...

Copy link
Contributor

@MoonlightSentinel MoonlightSentinel Nov 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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*

Copy link
Contributor Author

@marler8997 marler8997 Nov 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

... as it will only be used once
Currently, but we can keep the full type anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

@marler8997 marler8997 force-pushed the condenseBuild branch 3 times, most recently from ec64fc1 to 6082657 Compare November 5, 2019 16:52
}

/** Initializes an object using a chain of method calls */
struct MethodInitializer(T)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this a template now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

@RazvanN7 RazvanN7 merged commit 99e6ac8 into dlang:master Nov 6, 2019
Copy link
Member

@PetarKirov PetarKirov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Func(&builder, builder.obj, args);
Func(builder, builder.obj, args);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, indeed I missed that part.

@marler8997 marler8997 deleted the condenseBuild branch November 6, 2019 16:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants