-
-
Notifications
You must be signed in to change notification settings - Fork 714
dmd.expression: Utilize padding between Expression and derived AST nodes to store bitfields #23604
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
Draft
ibuclaw
wants to merge
1
commit into
dlang:master
Choose a base branch
from
ibuclaw:expression_scratchpad
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -135,6 +135,11 @@ extern (C++) abstract class Expression : ASTNode | |
| import dmd.common.bitfields; | ||
| mixin(generateBitFields!(BitFields, ubyte)); | ||
|
|
||
| // This is the remaining padding between Expression and all of its derived | ||
| // classes, it is used as a space to hold per-expression bitfields, flags, | ||
| // or a value of these derived AST nodes to save on space. | ||
| private ushort astNodeBitFields; | ||
|
|
||
| extern (D) this(Loc loc, EXP op) scope @safe | ||
| { | ||
| //printf("Expression::Expression(op = %d) this = %p\n", op, this); | ||
|
|
@@ -1441,10 +1446,10 @@ extern (C++) final class StructLiteralExp : Expression | |
| bool useStaticInit; /// if this is true, use the StructDeclaration's init symbol | ||
| bool isOriginal = false; /// used when moving instances to indicate `this is this.origin` | ||
| OwnedBy ownedByCtfe = OwnedBy.code; | ||
| StageFlags stageflags; | ||
| } | ||
| import dmd.common.bitfields; | ||
| mixin(generateBitFields!(BitFields, ubyte)); | ||
| StageFlags stageflags; | ||
| mixin(generateBitFields!(BitFields, ushort, "astNodeBitFields")); | ||
|
|
||
| StructDeclaration sd; /// which aggregate this is for | ||
| Expressions* elements; /// parallels sd.fields[] with null entries for fields to skip | ||
|
|
@@ -1508,6 +1513,19 @@ extern (C++) final class StructLiteralExp : Expression | |
| return exp; | ||
| } | ||
|
|
||
| /** Mark `stageflags` with the bit `flag` | ||
| * Params: | ||
| * flag = StageFlag to set | ||
| * Returns: | ||
| * The previous value of `stageflags` | ||
| */ | ||
| extern (D) StageFlags setStageFlag(StageFlags flag) | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moving the |
||
| { | ||
| const old = stageflags; | ||
| stageflags = StageFlags(old | flag); | ||
| return old; | ||
| } | ||
|
|
||
| override void accept(Visitor v) | ||
| { | ||
| v.visit(this); | ||
|
|
@@ -2730,7 +2748,7 @@ extern (C++) final class SliceExp : UnaExp | |
| bool arrayop; // an array operation, rather than a slice | ||
| } | ||
| import dmd.common.bitfields : generateBitFields; | ||
| mixin(generateBitFields!(BitFields, ubyte)); | ||
| mixin(generateBitFields!(BitFields, ushort, "astNodeBitFields")); | ||
|
|
||
| /************************************************************/ | ||
| extern (D) this(Loc loc, Expression e1, IntervalExp ie) @safe | ||
|
|
||
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
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
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
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
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
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
Oops, something went wrong.
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.
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.
I made bitFields an ushort instead in #23519, but that causes a padding byte before it. Your versions allows accessing all 21 remaining bits and is probably simpler most of the time. "Appending" to an existing bitfield might be needed with mutliple derivation steps, but I don't remember actually requiring that.
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.
I think you can get around that with the
bitOffparameter.It's a bit awkward, and I guess none of this is actually unit-tested. :-)
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.
That's what the appendBitfields mixin in my PR does, but also evaluates the offset automatically from the base class.