Improve field layout of Declaration

This commit is contained in:
Dennis Korpel 2025-02-11 21:30:55 +01:00 committed by The Dlang Bot
parent efd10b140c
commit ff28aa1195
9 changed files with 48 additions and 44 deletions

View file

@ -2006,7 +2006,7 @@ final class CParser(AST) : Parser!AST
//printf("AliasDeclaration %s %s\n", id.toChars(), dt.toChars());
auto ad = new AST.AliasDeclaration(token.loc, id, dt);
if (id == idt)
ad.adFlags |= ad.hidden; // do not print when generating .di files
ad.hidden = true; // do not print when generating .di files
s = ad;
}
@ -2088,8 +2088,7 @@ final class CParser(AST) : Parser!AST
{
auto str = asmName.peekString();
p.mangleOverride = str;
// p.adFlags |= AST.VarDeclaration.nounderscore;
p.adFlags |= 4; // cannot get above line to compile on Ubuntu
p.noUnderscore = true;
}
}
s = applySpecifier(s, specifier);

View file

@ -87,19 +87,23 @@ extern (C++) abstract class Declaration : Dsymbol
Type type;
Type originalType; // before semantic analysis
StorageClass storage_class = STC.undefined_;
Visibility visibility;
LINK _linkage = LINK.default_; // may be `LINK.system`; use `resolvedLinkage()` to resolve it
short inuse; // used to detect cycles
ubyte adFlags; // control re-assignment of AliasDeclaration (put here for packing reasons)
enum wasRead = 1; // set if AliasDeclaration was read
enum ignoreRead = 2; // ignore any reads of AliasDeclaration
enum nounderscore = 4; // don't prepend _ to mangled name
enum hidden = 8; // don't print this in .di files
enum nrvo = 0x10; /// forward to fd.nrvo_var when generating code
// overridden symbol with pragma(mangle, "...")
const(char)[] mangleOverride;
Visibility visibility;
short inuse; // used to detect cycles
private extern (D) static struct BitFields
{
LINK _linkage = LINK.default_; // may be `LINK.system`; use `resolvedLinkage()` to resolve it
bool wasRead; // set if AliasDeclaration was read
bool ignoreRead; // ignore any reads of AliasDeclaration
bool noUnderscore; // don't prepend _ to mangled name
bool hidden; // don't print this in .di files
bool nrvo; /// forward to fd.nrvo_var when generating code
}
import dmd.common.bitfields;
mixin(generateBitFields!(BitFields, ubyte));
final extern (D) this(Identifier ident) @safe
{
@ -628,8 +632,8 @@ extern (C++) final class AliasDeclaration : Declaration
return aliassym;
}
// Reading the AliasDeclaration
if (!(adFlags & ignoreRead))
adFlags |= wasRead; // can never assign to this AliasDeclaration again
if (!this.ignoreRead)
this.wasRead = true; // can never assign to this AliasDeclaration again
if (inuse == 1 && type && _scope)
{

View file

@ -121,11 +121,10 @@ public:
Type *type;
Type *originalType; // before semantic analysis
StorageClass storage_class;
Visibility visibility;
LINK _linkage; // may be `LINK::system`; use `resolvedLinkage()` to resolve it
short inuse; // used to detect cycles
uint8_t adFlags;
DString mangleOverride; // overridden symbol with pragma(mangle, "...")
Visibility visibility;
short inuse; // used to detect cycles
uint8_t bitFields;
const char *kind() const override;
uinteger_t size(Loc loc) override final;

View file

@ -5500,7 +5500,7 @@ private void aliasAssignSemantic(AliasAssign ds, Scope* sc)
if (!aliassym)
return errorRet();
if (aliassym.adFlags & Declaration.wasRead)
if (aliassym.wasRead)
{
if (!aliassym.errors)
error(ds.loc, "%s was read, so cannot reassign", aliassym.toChars());
@ -5508,7 +5508,7 @@ private void aliasAssignSemantic(AliasAssign ds, Scope* sc)
return errorRet();
}
aliassym.adFlags |= Declaration.ignoreRead; // temporarilly allow reads of aliassym
aliassym.ignoreRead = true; // temporarilly allow reads of aliassym
const storage_class = sc.stc & (STC.deprecated_ | STC.ref_ | STC.nothrow_ | STC.nogc | STC.pure_ | STC.shared_ | STC.disable);
@ -5632,8 +5632,7 @@ private void aliasAssignSemantic(AliasAssign ds, Scope* sc)
aliassym.aliassym = null;
}
aliassym.adFlags &= ~Declaration.ignoreRead;
aliassym.ignoreRead = false;
if (aliassym.type && aliassym.type.ty == Terror ||
global.gag && errors != global.errors)

View file

@ -642,7 +642,7 @@ elem* toElem(Expression e, ref IRState irs)
if (se.var.toParent2())
fd = se.var.toParent2().isFuncDeclaration();
const bool nrvo = fd && (fd.isNRVO() && fd.nrvo_var == se.var || se.var.adFlags & Declaration.nrvo && fd.shidden);
const bool nrvo = fd && (fd.isNRVO() && fd.nrvo_var == se.var || se.var.nrvo && fd.shidden);
if (nrvo)
s = fd.shidden;

View file

@ -853,7 +853,7 @@ extern (D) Expression doCopyOrMove(Scope* sc, Expression e, Type t, bool nrvo, b
*/
VarDeclaration vd = new VarDeclaration(e.loc, e.type, Identifier.generateId("__copyrvalue"), null);
if (nrvo)
vd.adFlags |= Declaration.nrvo;
vd.nrvo = true;
vd.storage_class |= STC.nodtor;
vd.dsymbolSemantic(sc);
Expression de = new DeclarationExp(e.loc, vd);
@ -903,7 +903,7 @@ private Expression callCpCtor(Scope* sc, Expression e, Type destinationType, boo
*/
VarDeclaration tmp = copyToTemp(STC.rvalue, "__copytmp", e);
if (nrvo)
tmp.adFlags |= Declaration.nrvo;
tmp.nrvo = true;
if (sd.hasCopyCtor && destinationType)
{
// https://issues.dlang.org/show_bug.cgi?id=22619

View file

@ -6662,21 +6662,24 @@ public:
Type* type;
Type* originalType;
StorageClass storage_class;
Visibility visibility;
LINK _linkage;
int16_t inuse;
uint8_t adFlags;
enum : int32_t { wasRead = 1 };
enum : int32_t { ignoreRead = 2 };
enum : int32_t { nounderscore = 4 };
enum : int32_t { hidden = 8 };
enum : int32_t { nrvo = 16 };
_d_dynamicArray< const char > mangleOverride;
Visibility visibility;
int16_t inuse;
LINK _linkage() const;
LINK _linkage(LINK v);
bool wasRead() const;
bool wasRead(bool v);
bool ignoreRead() const;
bool ignoreRead(bool v);
bool noUnderscore() const;
bool noUnderscore(bool v);
bool hidden() const;
bool hidden(bool v);
bool nrvo() const;
bool nrvo(bool v);
private:
uint8_t bitFields;
public:
const char* kind() const override;
uinteger_t size(Loc loc) final override;
bool isStatic() const;

View file

@ -1724,7 +1724,7 @@ void toCBuffer(Dsymbol s, ref OutBuffer buf, ref HdrGenState hgs)
{
if (d.storage_class & STC.local)
return;
if (d.adFlags & d.hidden)
if (d.hidden)
return;
buf.writestring("alias ");
if (d.aliassym)

View file

@ -163,7 +163,7 @@ Symbol* toSymbol(Dsymbol s)
s.Sflags |= SFLartifical;
if (isNRVO)
s.Sflags |= SFLnodebug;
if (vd.adFlags & Declaration.nounderscore)
if (vd.noUnderscore)
s.Sflags |= SFLnounderscore;
TYPE* t;
@ -441,7 +441,7 @@ Symbol* toSymbol(Dsymbol s)
break;
case LINK.c:
if (fd.adFlags & Declaration.nounderscore)
if (fd.noUnderscore)
s.Sflags |= SFLnounderscore;
goto case;
case LINK.objc: