-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
DI Generation Improvements. #945
Conversation
|
@LightBender time to rebase and see what happens with the tester failures! |
|
By stripping all the function bodies out, then functions in .di files lose the ability to be inlined. I disagree with this change. I am also not seeing much point in pretty-printing .di files. If someone wants to build a D source code formatting filter, that would be the place for it. Then, the .di file could be piped through that. Otherwise, we'll be building a pretty-printer twice. |
|
You realize that without this change D is pretty much useless for commercial library development as ALL function implementations are included in the DI file. It would be like writing your entire library in a header file. It doesn't matter if you're an OSS guy, but legal teams at commercial shops everywhere are going to scream bloody murder... Don't expect any commercial libraries to be built for D without this. |
|
On 11/10/2012 7:28 PM, LightBender wrote:
Just the ones that look like they are inlineable. Functions that have loops in
These days, an increasing amount of the code is winding up as templates anyway,
And, if someone is building a commercial library and considers themselves |
|
I discussed this with Walter. There are a few reasonable views on this:
Regarding the exchange: (a) please let's not overstate the case; (b) using C++ as a baseline is inadequate; (c) "if someone is building a commercial library and considers themselves blocked by this, please contact me" is rather provincial and non-scalable - it would behoove us to never talk or think that way. |
|
@andralex So, you know, there's that. Adding that attribute would kill two birds with one stone. |
|
Again, I'm favoring using the current language over adding new features. |
|
How about this: If the switch -inline is used for the .di generation, then the bodies are included. Otherwise, not. |
|
Like |
|
@andralex: Dislike. ;) In my opinion, there is no good reason from a user's perspective why I think this makes it clear that the switches have nothing to do with each other. There is nothing wrong in adding an additional command line flag for the .di generator ( |
|
I think it's very fit to have -inline mean keep inlined function bodies when generating .di files. Yes, it is a different meaning, but it's right on the spot. I don't see why people should remember a different flag when it comes about the same concept, just applied to .di generation. |
|
How is »do function inlining« related to »keep function bodies«? How are two meanings for the same flag easier to remember than two well-named ones? If you knew nothing about D, would |
|
|
@andralex: Regarding the previous question, I think it is a proven fact that being able to override the compiler's inline heuristics is a useful feature in certain, rare cases. One of these is certainly real-time graphics/game engines, where you often can't afford a function call to be inserted for math code, even in debug mode. For example, Manu/@TurkeyMan has asked several times for something like this on the newsgroup. Note that this has nothing to do with the C++ However, contrary to @alexrp, I don't think this should have anything to do with the problem discussed here, other than the fact that the .di generator could keep function bodies which are marked |
|
I'm totally with Walter on 1-3, he essentially spelled it for me. @klickverbot you're making a good point about forcing inline but let's leave that to a future diff. @LightBender could you please do the honors of implementing the decision depending on -inline? Thanks all! |
|
@WalterBright: What do you mean by ».di generation is done separately from code generation«? If you mean on a compiler level, then obviously yes, I think I'm somewhat familiar with that. If you mean that it is done separately as in not in the same compiler invocation in which code is generated, then that's not always the case. Apparently quite a few people use -H along with compilation (I discovered that when investigating an LDC bug), which actually makes sense when building/installing open source packages (and for whatever reason you assume that it is beneficial to install .di files, which is questionable). The fundamental problem I have with the idea is that I still think there is no good reason to conflate the two concepts. You probably wouldn't expect |
|
@klickverbot, you're right, Manu's feature request is distinct from this one. "alwaysinline" is not the negation of "neverinline". |
... and CTFE. |
And this is rather a big deal. |
|
Hm, regarding CTFE, wouldn't .di generation simply not be used at all in that case? Also, please note that while I still don't see why merging the additional flag into |
Issue 9150 - Mismatching static array length should be detected in foreach
…r function bodies.
…ementations with -inline specified. Added unittests for DMD for the -inline switch.
|
I have added the -inline switch support, new unittests for DMD covering the new -inline switch, and cleaned up some dead code that was used in earlier iterations of this pull request. This is now ready to merge. I want to give a shout-out to @AndrejMitrovic for helping me out with the Unittests. |
| @@ -1545,10 +1545,18 @@ void OutBuffer::prependstring(const char *string) | |||
| void OutBuffer::writenl() | |||
| { | |||
| #if _WIN32 | |||
| #if M_UNICODE | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no reason to support M_UNICODE. None of the rest of the code does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, i'll remove it. I think that was a hold-over from when I copied kenji's old pretty printing pull because I didn't write that.
| if (fbody && | ||
| (!hgs->hdrgen || hgs->tpltMember || canInline(1,1,1)) | ||
| ) | ||
| if (fbody && (!hgs->hdrgen || global.params.useInline || hgs->autoMember || hgs->tpltMember)) | ||
| { buf->writenl(); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In here:
- save values of autoMember and tpltMember
- set autoMember and tpltMember to 0
- execute code in { }
- restore autoMember and tpltMember to their saved values
| int saveauto = hgs->autoMember; | ||
| hgs->tpltMember = 0; | ||
| hgs->autoMember = 0; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@WalterBright Is this what you had in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, that works
|
Due to some irretrievable merge conflicts in the last rebase I have had to close this pull and start again. See pull: #1487 for the new pull request. |
As discussed in the original PR that added the feature (dlang#945), DMD currently triggers two entirely unrelated features with the -inline switch. Since LDC does not really have an equivalent to that switch in the first place, but users still want to control the emission of function bodies, we need to be control it separately. For DMD, global.params.hdrStripPlainFunctions is always set to !global.params.useInline in the driver to match the current behavior.
As discussed in the original PR that added the feature (dlang#945), DMD currently triggers two entirely unrelated features with the -inline switch. Since LDC does not really have an equivalent to that switch in the first place, but users still want to control the emission of function bodies, we need to be able to control it separately. For DMD, global.params.hdrStripPlainFunctions is always set to !global.params.useInline in the driver to match the current behavior.
This pull request improves the follow DI generation rules:
All functions stripped of their implementations except for template functions and auto return functions.
Improved indenting.
Requires: dlang/druntime#218
Supersedes: #538
Fix issue: http://d.puremagic.com/issues/show_bug.cgi?id=1427
Fix issue: http://d.puremagic.com/issues/show_bug.cgi?id=5461