Skip to content

[expression.d] restrict import of dmd.globals - #23467

Merged
thewilsonator merged 1 commit into
dlang:masterfrom
thewilsonator:exp-global
Jul 27, 2026
Merged

[expression.d] restrict import of dmd.globals#23467
thewilsonator merged 1 commit into
dlang:masterfrom
thewilsonator:exp-global

Conversation

@thewilsonator

Copy link
Copy Markdown
Contributor

No description provided.

@rikkimax

Copy link
Copy Markdown
Contributor

This whole get method looks off, similar to #23466

Why do these get methods even exist? They store nothing useful.

It should be using the existing OOP pattern, with an instance global that is allocated statically.

To handle @safe:

class Foo {
    static Foo instance() @trusted {
        __gshared Foo foo = new Foo;
        return foo;
    }
}

Or just (should work):

class Foo {
    static Foo instance = new Foo;
}

@rainers

rainers commented Jul 27, 2026

Copy link
Copy Markdown
Member

Why do these get methods even exist? They store nothing useful.

Using a pre-allocated instance can be slightly more efficient for the compiler, but when using dmd as a library for Visual D it must not lose the original expression/statement in case of error, so that it can still be iterated over and (partial) information can still be provided to the user.

So the get method is patched to save the original expression within a new ErrorExp, see https://github.com/rainers/dmd/blob/dmdserver/compiler/src/dmd/expression.d#L830. Having this in one place makes it a lot easier than having to change it everywhere the singleton is accessed.

@thewilsonator

Copy link
Copy Markdown
Contributor Author

So the get method is patched to save the original expression within a new ErrorExp, see https://github.com/rainers/dmd/blob/dmdserver/compiler/src/dmd/expression.d#L830. Having this in one place makes it a lot easier than having to change it everywhere the singleton is accessed.

Please upstream this!

@thewilsonator
thewilsonator merged commit 0bea0b7 into dlang:master Jul 27, 2026
42 checks passed
@thewilsonator
thewilsonator deleted the exp-global branch July 28, 2026 23:43
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.

3 participants