Skip to content

Conversation

@wilzbach
Copy link
Contributor

Lazy initialization seems to be the new game in town.
dmd.frontend wants to play with the big kids too!

@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.

*/
void initDMD()
{
import std.concurrency : initOnce;
Copy link
Member

Choose a reason for hiding this comment

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

We're not linking with Phobos - just druntime.

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 uses Phobos as it isn't part of the compiler.

@WalterBright
Copy link
Member

I'm afraid I don't see how this improves anything.

@wilzbach
Copy link
Contributor Author

The dmd.frontend is user-facing and this is one small step into making it easier for people to use as it reduces the number of things people can do wrong. initOnce is used very generously in Phobos and this file is very similar to Phobos - it's a user API after all.

@jacob-carlborg
Copy link
Contributor

What happens if initDMD is called more than once?

@rainers
Copy link
Member

rainers commented Jan 27, 2018

What happens if initDMD is called more than once?

Reinitialization is not so easy due to "inaccessible" globals: here's what I had to do in my experiments for Visual D some time ago:

https://github.com/rainers/visuald/blob/dmdserver/vdc/dmdserver.d#L1009
https://github.com/rainers/visuald/blob/dmdserver/vdc/dmdserver.d#L667

Expression._init();
Objc._init();
builtin_init();
static shared bool initialized;
Copy link
Member

Choose a reason for hiding this comment

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

The front end is not thread safe, no need to pretend it here.

@jacob-carlborg
Copy link
Contributor

Reinitialization is not so easy due to "inaccessible" globals: here's what I had to do in my experiments for Visual D some time ago.

I was thinking if something bad can happen if initDMD is called more than once.

import dmd.arraytypes : Strings;
import std.string : toStringz;

initDMD;
Copy link
Member

Choose a reason for hiding this comment

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

Please let's not introduce a new style for calling functions - append the ().

@WalterBright
Copy link
Member

This just seems like over-engineering. Just use:

__gshared bool initialized;
assert(!initialized);
initialized = true;

Done - no import, no delegate, no dependencies, no "what does this do", etc.

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