Conversation
|
did you benchmark the compiletime of this, against bitfields ? |
09c7374 to
5f02580
Compare
|
The new one was compiling a bit slower because I was using std.format to generate code. I've since replaced it with string appending, like the original one uses and now performance is basically the same. Here's the benchmark. import std.stdio, std.conv, std.bitmanip;
void main()
{
mixin(function()
{
string code;
foreach(i; 0..300)
{
version(Original)
{
code ~=
`static struct Bitfield`~ i.to!string ~ `
{
mixin(bitfields!(
uint, "x", 2,
int, "y", 3,
uint, "z", 2,
bool, "flag", 1));
}`;
}
version(New)
{
code ~=
`static struct Bitfield`~ i.to!string ~ `
{
mixin bitfields2!(
uint, "x", 2,
int, "y", 3,
uint, "z", 2,
bool, "flag", 1);
}`;
}
}
return code;
}());
} |
|
@UplinkCoder EDIT: Nevermind, my edit actually caused some of the code not to be generated, fixed it and now performance is still very similar to the original. |
66043a9 to
50c9566
Compare
|
yeah |
6acabd4 to
06523d4
Compare
Codecov Report
@@ Coverage Diff @@
## master #5490 +/- ##
==========================================
- Coverage 88.45% 88.42% -0.03%
==========================================
Files 120 120
Lines 78371 78523 +152
==========================================
+ Hits 69320 69436 +116
- Misses 9051 9087 +36
Continue to review full report at Codecov.
|
237f854 to
efed84d
Compare
| private string bitfieldsCodeGenerator() | ||
| { | ||
| string store; | ||
| size_t storageSize = 0; |
There was a problem hiding this comment.
Stop creating AST nodes for something that's done automatically (i.e default initialization).
|
|
||
| string mixinCode = "private " ~ storageType ~ " " ~ store ~ ";\n"; | ||
|
|
||
| size_t bitOffset = 0; |
|
Thanks for your pull request and interest in making D better, @marler8997! 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. |
|
On Thu, Jun 22, 2017 at 06:05:04PM -0700, Basile Burg wrote:
Stop creating AST nodes for something that's done automatically (i.e default initialization).
why?
|
|
Seems there is a problem with circleci.sh...is this a known error? If it's been fixed can someone retrigger the build? |
Yes.
You need to rebase to master.. |
|
@marler8997 can you please show a simple example "this would not work (or would be awful) with |
struct Foo
{
mixin(bitfields!(
Flag!"foo", "foo", 1, // Error: std.typecons.Flag(string name) is used as a type
void, null, 7));
}struct Foo
{
mixin bitfields2!(
Flag!"foo", "foo", 1,
void, null, 7);
} |
|
I should also mention that I created another PR to fix the specific use case I just gave as an example, but it is brittle and can't work in general, hence, why this PR was created which does work in the general case. |
| $(LREF BitArray) | ||
| $(LREF bitfields) | ||
| $(LREF bitfields2) | ||
| $(LREF bitfields2Code) |
There was a problem hiding this comment.
I am not sure that exposing a debug function is a good idea. As a user I would expect a standard library function to work ...
There was a problem hiding this comment.
The purpose of having it isn't to allow a developer to "debug" the implementation but to see/understand the code being generated. Maybe that's not a good enough reason though?
There was a problem hiding this comment.
I see in my description that I explicitly said the purpose of this function was to "debug" the code :) Woops!
|
I don't want to start a bikeshedding discussion, but |
|
Cleaning up old PRs that aren't going anywhere |
Based on discussion with @adamdruppe (http://forum.dlang.org/thread/ibwazxrngcsrfolgbefs@forum.dlang.org)
Added a new version of
bitfieldscalledbitfields2. The reason for creatingbitfields2instead of enhancingbitfieldsis because the design requires it to be a mixin template instead of a normal template. This change is crucial to howbitfields2works, but means that any application using it must omit the extra set of parenthesis thatbitfieldsrequires, i.e.The main advantage of
bitfields2is that it is able to reference the field types by alias, whereas the current implementation converts each field type alias to a string and then mixes in the type name. I've included a small program to demonstrate the differences in each technique and where the weakness lies in the current technique.P.S. I've also added the
bitfields2Codetemplate so that an application can see/grok the generated bitfield code if needed, i.e.