Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/dmd/frontend.d
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ import std.traits : isNarrowString;
version (Windows) private enum sep = ";", exe = ".exe";
version (Posix) private enum sep = ":", exe = "";

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

@jacob-carlborg jacob-carlborg Jan 28, 2018

Choose a reason for hiding this comment

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

I'm not sure I like this. The original reason why it's necessary to call initDMD is that I said no to using a module constructor. What I said back then was that there might be a use case/possible to use multiple instances of the compiler in the future. I'm not sure if that's worth striving for.

An alternative would be to wrap everything in a class that needs to be instantiated, Frontend or Compiler.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we should strive for making the compiler as reusable as a simple object with constructor and destructor, so +1 for having a Compiler class/struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure whether that makes sense as long as the compiler still uses globals - it would create a false abstraction.
On the other hand, we need to start somewhere and we could already store state like the import paths...

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure whether that makes sense as long as the compiler still uses globals - it would create a false abstraction.

True. But changing the API (if needed in the future) is usually quite difficult. Another idea is to use a singleton. The user basically gets access to an instance but can not create new instances. Later we can lift that restriction and I don't think that would break the API.

Copy link
Member

Choose a reason for hiding this comment

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

I am quite aware that we're pretty far from having a reusable Compiler RAII object. I'm just saying that we should strive to change the architecture.


/*
Initializes the global variables of the DMD compiler.
This needs to be done $(I before) calling any function.
Expand Down
1 change: 0 additions & 1 deletion test/dub_package/frontend.d
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ void main()
import dmd.frontend;
import std.algorithm : each;

initDMD;
findImportPaths.each!addImport;

auto m = parseModule("test.d", q{
Expand Down
1 change: 0 additions & 1 deletion test/dub_package/frontend_file.d
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ void main()
import std.file : remove, tempDir, fwrite = write;
import std.path : buildPath;

initDMD;
findImportPaths.each!addImport;

auto fileName = tempDir.buildPath("d_frontend_test.d");
Expand Down