dmd icon indicating copy to clipboard operation
dmd copied to clipboard

add dmd/hostcompiler.d

Open WalterBright opened this issue 6 months ago • 10 comments

This is to encapsulate host compiler differences. The logic is spread across several files, and should be encapsulated into one file.

This is not about the host operating system, the target operating system, or the target machine. It's only about the host compiler.

Putting abstracting this into one file makes the rest of the compiler more generic, and makes things easier to maintain.

This PR is just a first step towards implementing this.

Every effort should be made to minimize the number of imports this file does.

WalterBright avatar Jun 05 '25 05:06 WalterBright

Thanks for your pull request, @WalterBright!

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 run digger -- build "master + dmd#21431"

dlang-bot avatar Jun 05 '25 05:06 dlang-bot

There's already a compiler module for this.

ibuclaw avatar Jun 05 '25 07:06 ibuclaw

@ibuclaw I didn't know about that module. But I don't see any version statements in it.

WalterBright avatar Jun 05 '25 08:06 WalterBright

When I added it, I envisioned that each compiler would have its own version of it, rather than have it as a shared/common module between us.

For example, gdc implements dmd.compiler in C++. The D module is just the declarations.

https://github.com/gcc-mirror/gcc/blob/master/gcc/d/dmd/compiler.d

ibuclaw avatar Jun 05 '25 11:06 ibuclaw

Ready to merge

WalterBright avatar Jun 08 '25 15:06 WalterBright

What about putting these in the dmd.compiler module?

I don't see the need for version statements, as gdc/ldc can just provide their own implementations locally.

ibuclaw avatar Jun 08 '25 21:06 ibuclaw

I don't see any common purpose with the code that's in dmd.compiler. I don't understand what the code in it does.

Anyhow, there are several ways to do this, such as using interfaces, versions, pointers to functions, etc. Which one is best, I don't know at the moment. What I do know is the compiler is more tractable without version statements scattered through it. I'm open to a future scheme for this, but for the moment this PR will abstract a significant pile of versions out of the common compiler code into a separate module, which is a significant improvement.

WalterBright avatar Jun 08 '25 22:06 WalterBright

ping @ibuclaw

WalterBright avatar Jun 09 '25 01:06 WalterBright

I suspect gdc opturls will still be broken by this, but as these are all enums, it can be fixed again by using ctfe concatenation of the string format instead of runtime %s.

ibuclaw avatar Jun 12 '25 02:06 ibuclaw

OK, but this introduced module will be deleted after merge as everything here will just be folded into the dmd.compiler module.

Will leave it to @kinke to sign off the remaining ldc bits.

ibuclaw avatar Jun 12 '25 02:06 ibuclaw

Why aren't we moving forward with this?

WalterBright avatar Jun 28 '25 05:06 WalterBright

It looks like the extensive refactoring has completely scrambled and trashed this PR. I'll have to write a new one.

WalterBright avatar Aug 25 '25 08:08 WalterBright