Skip to content

Move frontend utility functions from the DUB package to dmd.frontend#7485

Merged
dlang-bot merged 1 commit intodlang:masterfrom
wilzbach:frontend-code
Jan 25, 2018
Merged

Move frontend utility functions from the DUB package to dmd.frontend#7485
dlang-bot merged 1 commit intodlang:masterfrom
wilzbach:frontend-code

Conversation

@wilzbach
Copy link
Contributor

Following to #7425, this just move these bits to dmd.frontend. Of course, further work is needed to define the API, but I thought having an open PR is the best place to facilitate this discussion.

This is far from perfect, but I won't have time to work much on it until I chat with @RazvanN7.

Anyhow if you have already have an API idea/requirement and want to drop it or just want to subscribe to the discussion, this is the place to be ;-)

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @wilzbach!

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.

@dlang-bot dlang-bot added the Review:WIP Work In Progress - not ready for review or pulling label Dec 21, 2017
@jacob-carlborg
Copy link
Contributor

What's the idea here, just move common functionality from the test package or to come up new a proper API?

@wilzbach wilzbach changed the title [WIP] Move frontend utility functions from the DUB packag to dmd.frontend [WIP] Move frontend utility functions from the DUB package to dmd.frontend Dec 21, 2017
foreach (p; path)
{
import std.string : toStringz;
Strings* a = new Strings();
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 an array created for each path, why not added the path directly to res?

@wilzbach
Copy link
Contributor Author

What's the idea here, just move common functionality from the test package or to come up new a proper API?

Both, but (B) is definitely the goal. I just moved the bits from the test package over to bootstrap a discussion and avoid this topic sinking in the abyss.
Anyhow I assume that coming up with a proper API from scratch will be tricky and require a couple of iterations (and use cases). So in any case I will put a red reminder in the module header that warns the user about the API's instability. Maybe dmd.experimental.frontend would have been a better place for this module?

.array
.sort
.uniq
.map!buildNormalizedPath;
Copy link
Contributor

Choose a reason for hiding this comment

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

This whole expression doesn't look very nice. Perhaps split it up with some helper functions/aliases. It's not very clear of what the code is actually doing.

shared static this()
{
initDMD();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure if this is the best idea if we want to allow multiple instances of the compiler in the future.

import dmd.dinifile : findConfFile;
import dmd.errors : fatal;
import std.algorithm, std.range, std.regex;
import std.stdio : File, stderr;
Copy link
Contributor

Choose a reason for hiding this comment

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

There's an extra space after the comma.

import std.algorithm, std.range, std.regex;
import std.stdio : File, stderr;

auto dmdEnv = env.get("DMD", "dmd");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this function needs to be split into several layers building on top of each other. One where it's possible to give a direct path to the config and another which tries to infer it.

Params:
path = range of imports to add
*/
void addImports(T)(T path)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should have constraints.

Returns: the parsed module object
*/
// TODO: allow files?
auto parseModule(string fileName, string code)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think auto should be used here. It returns a simple class and not a template, so I don't think it's necessary.

Returns:
Pretty printed module as string.
*/
auto prettyPrint(Module m)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, write out the actual return type instead of auto.

@jacob-carlborg
Copy link
Contributor

So in any case I will put a red reminder in the module header that warns the user about the API's instability. Maybe dmd.experimental.frontend would have been a better place for this module?

I'm don't think that's necessary. I do think the version of the first releases should be 0.x.y, that allows breaking changes at any point according to semantic versioning.


if (global.path is null)
{
Strings* res = new Strings();
Copy link
Contributor

Choose a reason for hiding this comment

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

This variable doesn't seem to add any value.


return File(iniFile, "r")
.byLineCopy
// search for all -I imports in this file
Copy link
Contributor

Choose a reason for hiding this comment

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

I still prefer separate functions/lambdas instead of comments.

@ibuclaw
Copy link
Member

ibuclaw commented Jan 6, 2018

Shouldn't this module be named something like dmd.driver? It's pretty useless for other backends.

@wilzbach
Copy link
Contributor Author

wilzbach commented Jan 7, 2018

Shouldn't this module be named something like dmd.driver? It's pretty useless for other backends.

It's not intended to be used by any library. It's only intended to be used for the DMD as a library builds - most likely via DUB.

Regarding the name, see: #7425 (comment)
I also don't think the name is perfect, so happy to rename.

* the `CRuntime` used).
*/
private void addDefaultVersionIdentifiers()
void addDefaultVersionIdentifiers()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #7524 for a better approach

@wilzbach wilzbach changed the title [WIP] Move frontend utility functions from the DUB package to dmd.frontend Move frontend utility functions from the DUB package to dmd.frontend Jan 8, 2018
@wilzbach wilzbach removed the Review:WIP Work In Progress - not ready for review or pulling label Jan 8, 2018
@wilzbach wilzbach force-pushed the frontend-code branch 2 times, most recently from 1ff3d42 to 6794c43 Compare January 8, 2018 18:41
@wilzbach wilzbach requested a review from MartinNowak as a code owner January 8, 2018 18:41
Initializes the DMD compiler
import dmd.dmodule : Module;
import std.range.primitives : isInputRange, ElementType;
import std.traits : isNarrowString;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thought Phobos is DMD was a no-no ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file isn't used by dmd at all - only by the DMD as a library project.
Should we rename the file or move it to somwhere else, s.t. this gets clearer?

I don't see any reason not to use Phobos here, it allows to write the high-level wrappers and stops us from re-inventing the wheel and blowing up the code with inferior, probably buggy implementations of Phobos.

@wilzbach
Copy link
Contributor Author

BTW anything else blocking this PR except for the name of this module?
(it's already there and we can always rename if after this PR though)

Everything is still marked as unstable, so we can always improve/change this, but it should give us sth. to get started.

if ("DMD" in environment)
compilers = environment.get("DMD") ~ compilers;
auto paths = environment.get("PATH", "").splitter(sep);
auto res = compilers.map!(c => paths.map!(p => p.buildPath(c~exe))).joiner.filter!exists;
Copy link
Contributor

Choose a reason for hiding this comment

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

The indentation is wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@wilzbach
Copy link
Contributor Author

Closing & reopening for Semaphore to learn about this PR.

@wilzbach
Copy link
Contributor Author

Anything else blocking this?

@wilzbach
Copy link
Contributor Author

CC @RazvanN7 are you okay with this too?

@RazvanN7
Copy link
Contributor

LGTM

@dlang-bot dlang-bot merged commit 289b79e into dlang:master Jan 25, 2018
@wilzbach wilzbach deleted the frontend-code branch January 26, 2018 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants