-
-
Notifications
You must be signed in to change notification settings - Fork 655
fix issues #10442: no or incomplete RTInfo #2480
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
Closed
Closed
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
ee09667
do not assume zero-init of structs, calculate lazily if necessary
rainers f79c4c2
fix issue 10442: predict type info references in glue layer
rainers fc5c098
TypeInfo generation always needs semantic3 to evaluate RTInfo
rainers 9819a55
white space fixes
rainers 68847e6
do not write type info for broken definitions
rainers 393427c
cannot skip RTInfo generation for deprecated structs, they might stil…
rainers 9c55f54
fix rebase
rainers 41878b4
add test case for issue 10442
rainers 5e7e84b
use enum for zeroInit
rainers c3280e8
make some symbols private, add ddoc comments
rainers 7f14169
fix rebase
rainers 56aefa3
no error if RTInfo not defined
rainers 2216410
RTInfo generation must not be omitted for deprecated aggregates
rainers 3fff582
fix semantic not run on TypeInfo when added to module that has alread…
rainers 391ca7c
cannot avoid running semantic on struct declaration if template RTInf…
rainers 353957d
adapt test to new RTInfo, skip semanticTypeInfo with -betterC, ensure…
rainers 2f87481
don't generate TypeInfo data for forward declared struct
rainers cd76c8d
remove unnecessary call to verifyTypeInfo
rainers 1a42547
static foreach: no need to convert static array, can be used directly…
rainers 0340cf1
use semanticTypeInfo instead of direct call to genTypeInfo
rainers 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
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 |
---|---|---|
|
@@ -70,6 +70,9 @@ | |
*/ | ||
extern (C++) void semanticTypeInfo(Scope* sc, Type t) | ||
{ | ||
if (!global.params.useTypeInfo || !Type.dtypeinfo) | ||
return; // not expected to be used with -betterC | ||
|
||
if (sc) | ||
{ | ||
if (sc.intypeof) | ||
|
@@ -128,7 +131,7 @@ | |
*/ | ||
if (!sd.members) | ||
return; // opaque struct | ||
if (!sd.xeq && !sd.xcmp && !sd.postblit && !sd.dtor && !sd.xhash && !search_toString(sd)) | ||
if (!Type.rtinfo && !sd.xeq && !sd.xcmp && !sd.postblit && !sd.dtor && !sd.xhash && !search_toString(sd)) | ||
return; // none of TypeInfo-specific members | ||
|
||
// If the struct is in a non-root module, run semantic3 to get | ||
|
@@ -166,7 +169,7 @@ | |
/* Note structural similarity of this Type walker to that in isSpeculativeType() | ||
*/ | ||
|
||
Type tb = t.toBasetype(); | ||
Type tb = t.toBasetype().mutableOf().unSharedOf(); // remove modifiers | ||
switch (tb.ty) | ||
{ | ||
case Tvector: visitVector(tb.isTypeVector()); break; | ||
|
@@ -194,12 +197,19 @@ | |
fwd, // POD not yet computed | ||
} | ||
|
||
private enum ZeroInit : byte | ||
{ | ||
unknown = -1, // not computed yet | ||
no = 0, // struct is not all zeroes | ||
yes = 1, // struct is all zeroes | ||
}; | ||
|
||
/*********************************************************** | ||
* All `struct` declarations are an instance of this. | ||
*/ | ||
extern (C++) class StructDeclaration : AggregateDeclaration | ||
{ | ||
bool zeroInit; // !=0 if initialize with 0 fill | ||
ZeroInit zeroInit; // if struct is initialized to all zeroes | ||
bool hasIdentityAssign; // true if has identity opAssign | ||
bool hasBlitAssign; // true if opAssign is a blit | ||
bool hasIdentityEquals; // true if has identity opEquals | ||
|
@@ -228,7 +238,7 @@ | |
extern (D) this(const ref Loc loc, Identifier id, bool inObject) | ||
{ | ||
super(loc, id); | ||
zeroInit = false; // assume false until we do semantic processing | ||
zeroInit = ZeroInit.unknown; | ||
ispod = StructPOD.fwd; | ||
// For forward references | ||
type = new TypeStruct(this); | ||
|
@@ -386,36 +396,8 @@ | |
return; | ||
} | ||
|
||
// Determine if struct is all zeros or not | ||
zeroInit = true; | ||
foreach (vd; fields) | ||
{ | ||
if (vd._init) | ||
{ | ||
if (vd._init.isVoidInitializer()) | ||
/* Treat as 0 for the purposes of putting the initializer | ||
* in the BSS segment, or doing a mass set to 0 | ||
*/ | ||
continue; | ||
|
||
// Zero size fields are zero initialized | ||
if (vd.type.size(vd.loc) == 0) | ||
continue; | ||
|
||
// Examine init to see if it is all 0s. | ||
auto exp = vd.getConstInitializer(); | ||
if (!exp || !_isZeroInit(exp)) | ||
{ | ||
zeroInit = false; | ||
break; | ||
} | ||
} | ||
else if (!vd.type.isZeroInit(loc)) | ||
{ | ||
zeroInit = false; | ||
break; | ||
} | ||
} | ||
if (zeroInit == ZeroInit.unknown) | ||
zeroInit = calcZeroInit(); | ||
|
||
argTypes = target.toArgTypes(type); | ||
} | ||
|
@@ -585,6 +567,52 @@ | |
return (ispod == StructPOD.yes); | ||
} | ||
|
||
/*************************************** | ||
* Lazily determine whether a struct init value is a chunk of zeroes | ||
* | ||
* Returns: | ||
* true if struct is all zeroes | ||
*/ | ||
final bool isZeroInit() | ||
MoonlightSentinel marked this conversation as resolved.
Show resolved
Hide resolved
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. Why add this function alongside |
||
{ | ||
if (zeroInit == ZeroInit.unknown) | ||
if (semanticRun < PASS.semanticdone && _scope) | ||
dsymbolSemantic(this, null); | ||
if (zeroInit == ZeroInit.unknown) | ||
zeroInit = calcZeroInit(); | ||
return zeroInit == ZeroInit.yes; | ||
} | ||
|
||
private final ZeroInit calcZeroInit() | ||
{ | ||
// Determine if struct is all zeros or not | ||
foreach (vd; fields) | ||
{ | ||
if (vd._init) | ||
{ | ||
if (vd._init.isVoidInitializer()) | ||
/* Treat as 0 for the purposes of putting the initializer | ||
* in the BSS segment, or doing a mass set to 0 | ||
*/ | ||
continue; | ||
|
||
// Zero size fields are zero initialized | ||
if (vd.type.size(vd.loc) == 0) | ||
continue; | ||
|
||
// Examine init to see if it is all 0s. | ||
auto exp = vd.getConstInitializer(); | ||
if (!exp || !_isZeroInit(exp)) | ||
return ZeroInit.no; | ||
} | ||
else if (!vd.type.isZeroInit(loc)) | ||
{ | ||
return ZeroInit.no; | ||
} | ||
} | ||
return ZeroInit.yes; | ||
} | ||
|
||
override final inout(StructDeclaration) isStructDeclaration() inout | ||
{ | ||
return this; | ||
|
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.
enum class
can now be used