Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

split off main.d from mars.d #15472

Merged
merged 1 commit into from
Aug 1, 2023
Merged

split off main.d from mars.d #15472

merged 1 commit into from
Aug 1, 2023

Conversation

WalterBright
Copy link
Member

Obviously, the only time dmd will need a main is if a standalone console program is being generated. For dmd-as-library, an LSP plugin, or a DLL, no main is required. So I thought I'd split off main and put it in its own file, main.d, along with the code versioned as "not NoMain". This should be straightforward.

Knotty problems:

  1. main.d winds up importing every other module
  2. the not NoMain code calls other functions that are not NoMain (!) but are not called by other not NoMain code not no how not no way

@RazvanN7 I could use your advice on your vision for dmd-as-library, and maybe we can extirpate the naughtiness with this code, so this PR is not for nought.

@WalterBright WalterBright added the Refactoring No semantic changes to code label Jul 29, 2023
@dlang-bot
Copy link
Contributor

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#15472"

@maxhaton
Copy link
Member

There is already an entrypoint for DMD as a library in frontend.d, have you looked at it?

@RazvanN7
Copy link
Contributor

@maxhaton Yes, there is an entry point for dmd as a lib, however, mars.d currently contains (or used to contain) some functions that need to be used for config purposes in dmd as a lib. In the past, we used to just move these functions to other files that are included in dmd-as-a-lib, because mars.d is currently excluded the packaging of the library.

@WalterBright I approve this addition, however, why not go fully in this direction? What I mean is that we can keep all of the functions that main.d calls in mars.d and mars.d could be included in the dmd-as-a-lib package. You never know what the library might need to use, so if you want to be on the safe side just leave everything up for grabs.

main.d winds up importing every other module

That's fine. It's the main function after all. dmd-as-a-lib does not include this file. And that's what mars.d did anyway.

the not NoMain code calls other functions that are not NoMain (!) but are not called by other not NoMain code not no how not no way

I cannot parse this sentence, too many negations. But I think the simplest way to move forward is to just keep everything, except for the main function, in mars.d and just have main.d include it. The purpose of this is to make mars.d importable, so why not just go down that path?

@WalterBright
Copy link
Member Author

I cannot parse this sentence, too many negations

That's the point, NoMain is confusing. A better version would be Main.

I only moved the functions over to main.d that were not NoMain functions. There should be a clear separation between code only needed for main() and code needed for any build of the compiler.

@RazvanN7
Copy link
Contributor

RazvanN7 commented Aug 1, 2023

I only moved the functions over to main.d that were not NoMain functions. There should be a clear separation between code only needed for main() and code needed for any build of the compiler.

But dmd as a library might use that code even if the not NoMain code uses it.

Copy link
Member

@Geod24 Geod24 left a comment

Choose a reason for hiding this comment

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

Great!

@Geod24 Geod24 merged commit c187d64 into dlang:master Aug 1, 2023
40 checks passed
@WalterBright WalterBright deleted the main branch August 1, 2023 20:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Refactoring No semantic changes to code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants