Skip to content

Comments

Don't generate ModuleInfo if it's not declared in druntime#7395

Merged
dlang-bot merged 1 commit intodlang:masterfrom
JinShil:nomoduleinfo2
Dec 5, 2017
Merged

Don't generate ModuleInfo if it's not declared in druntime#7395
dlang-bot merged 1 commit intodlang:masterfrom
JinShil:nomoduleinfo2

Conversation

@JinShil
Copy link
Contributor

@JinShil JinShil commented Dec 4, 2017

In response to http://forum.dlang.org/post/onn8vi$tgs$1@digitalmars.com and http://forum.dlang.org/post/p0280p$29t$1@digitalmars.com

Rationale

The compiler shouldn't require ModuleInfo to exist if the platform doesn't support it or the program author wishes to provide an alternate druntime implementation that doesn't support it.

Platform support is provided by druntime. ModuleInfo is declared in object.d. Therefore, the compiler can see, at compile-time, whether or not the platform engineer has provided support for ModuleInfo and generate object code accordingly. (i.e. Design by Introspection)

There are also use cases where, although the platform could support ModuleInfo, the program author may choose to provide an alternate implementation of druntime features just for their program. That alternate implementation may not support ModuleInfo.

The current compiler implementation will emit errors if ModuleInfo is not declared. It is an unnecessary restriction to require the author to workaround this constraint when they don't wish to support ModuleInfo.

Current workarounds are to define a stub ModuleInfo and have it discarded through LTO, --gc-sections, or a custom linker script.

Benefits

  • Eliminate the need for hackish workarounds due to arbitrary constraints imposed by the compiler
  • Reduce friction for platform engineers wishing to incrementally port D to new platforms
  • A step in the right direction for using D in a more pay-as-you-go fashion.
  • Broaden D's relevance in new, interesting, and niche use cases currently dominated by minimal runtime languages such as Rust and C.

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @JinShil!

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.

@JinShil JinShil added the Review:WIP Work In Progress - not ready for review or pulling label Dec 4, 2017
@JinShil JinShil changed the title Don't generate ModuleInfo if its not declared in druntime Don't generate ModuleInfo if it's not declared in druntime Dec 4, 2017
@JinShil JinShil added Review:Easy Review and removed Review:WIP Work In Progress - not ready for review or pulling labels Dec 4, 2017
Copy link
Member

@WalterBright WalterBright left a comment

Choose a reason for hiding this comment

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

Something of this significance needs a changelog entry.

@WalterBright
Copy link
Member

In fact, much of what you wrote in the explanation above is ideal for the changelog entry.

@JinShil
Copy link
Contributor Author

JinShil commented Dec 5, 2017

Something of this significance needs a changelog entry.

Changelog entry added.

@WalterBright
Copy link
Member

It's a good idea. Wish I'd thought of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants