Move hard-coded logic to generate C main out of the compiler and into druntime#10351
Merged
dlang-bot merged 1 commit intodlang:masterfrom Aug 26, 2019
JinShil:entry
Merged
Move hard-coded logic to generate C main out of the compiler and into druntime#10351dlang-bot merged 1 commit intodlang:masterfrom JinShil:entry
dlang-bot merged 1 commit intodlang:masterfrom
JinShil:entry
Conversation
JinShil
commented
Aug 26, 2019
| } | ||
|
|
||
| // Only mixin `_d_cmain` if it is defined | ||
| if (cmainTemplateExists()) |
Contributor
Author
There was a problem hiding this comment.
I suppose I could put this logic back into compiler.genCmain if that would be less disruptive.
Contributor
|
Thanks for your pull request and interest in making D better, @JinShil! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour 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 locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#10351" |
thewilsonator
approved these changes
Aug 26, 2019
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR will not pass any tests until dlang/druntime#2759 is merged.This PR is futher work towards making the D language and its runtime more pay-as-you-go and extensible to other emerging platforms and use cases. It is very similar to the work already done in these PRs...
ModuleInfoThrowableis not declared #7786 forThrowableTypeInfo... and congruent with the current efforts to convert D runtime hooks to templates.
This PR moves the hard-coded logic for entry point generation (e.g. C main and the logic necessary to initialize druntime and call D main) out of the compiler and into to druntime. Doing so removes some of the complexity in the compiler, and instead, leverages D's unique language features to achieve the same result.
With this PR, the C main to D main code path can be completely customized for any platform, compiler, compiler invocation (e.g. betterC), or other use case without requiring any changes to the compiler. And, because it is template-based, it does not require linking in druntime.
If a user's custom runtime does not include the
_d_cmaintemplate definition, no C main to D main logic will be generated. This is especially useful for some bare metal programming where a user may wish to provide their own startup code without having to adopt workarounds such as renaming theirmainfunction or implementing druntime stubs.How it works:
_d_cmainwhich will typically exist in druntime (assuming the accompanying druntime PR is merged)._d_cmaintemplate is defined, the compiler simply appends amixin _d_cmain!();statement to the module effectively injecting C main and the logic necessary to initialize druntime and call D main._d_cmaintemplate is not defined, no code is injected, and the user is free to implement their own startup logic however they preferI believe this implementation will provide much more flexibility for everyone, while accomodating for emerging use cases, without the need for workarounds or compromise.
If necessary, the
_d_cmaintemplate could even be modified to take compile-time arguments from the compiler front-end to further extend its capabilities.This PR is an alternative to #10181.
cc @kinke @ibuclaw @jpf91 This changes the interface in
compiler.h, hopefully for the better. It removes thegenCmainfunction and theentrypointmodule, delegating that logic instead to the runtime.