Skip to content

Commit

Permalink
Devirtualize Dsymbol.isXXX functions (#20925)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Feb 27, 2025
1 parent 5fc1141 commit 216837b
Show file tree
Hide file tree
Showing 33 changed files with 582 additions and 617 deletions.
5 changes: 0 additions & 5 deletions compiler/src/dmd/aggregate.d
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,6 @@ extern (C++) abstract class AggregateDeclaration : ScopeDsymbol
// Back end
void* sinit; /// initializer symbol

override final inout(AggregateDeclaration) isAggregateDeclaration() inout
{
return this;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down
5 changes: 0 additions & 5 deletions compiler/src/dmd/aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class AggregateDeclaration : public ScopeDsymbol
// Back end
void *sinit;

AggregateDeclaration *isAggregateDeclaration() override final { return this; }
void accept(Visitor *v) override { v->visit(this); }
};

Expand Down Expand Up @@ -191,7 +190,6 @@ class StructDeclaration : public AggregateDeclaration
bool requestTypeInfo() const;
bool requestTypeInfo(bool v);

StructDeclaration *isStructDeclaration() override final { return this; }
void accept(Visitor *v) override { v->visit(this); }

unsigned numArgTypes() const;
Expand All @@ -205,7 +203,6 @@ class UnionDeclaration final : public StructDeclaration
UnionDeclaration *syntaxCopy(Dsymbol *s) override;
const char *kind() const override;

UnionDeclaration *isUnionDeclaration() override { return this; }
void accept(Visitor *v) override { v->visit(this); }
};

Expand Down Expand Up @@ -305,7 +302,6 @@ class ClassDeclaration : public AggregateDeclaration
Dsymbol *vtblsym;
Dsymbol *vtblSymbol();

ClassDeclaration *isClassDeclaration() override final { return (ClassDeclaration *)this; }
void accept(Visitor *v) override { v->visit(this); }
};

Expand All @@ -320,6 +316,5 @@ class InterfaceDeclaration final : public ClassDeclaration
bool isCPPinterface() const override;
bool isCOMinterface() const override;

InterfaceDeclaration *isInterfaceDeclaration() override { return this; }
void accept(Visitor *v) override { v->visit(this); }
};
2 changes: 1 addition & 1 deletion compiler/src/dmd/aliasthis.d
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern (C++) final class AliasThis : Dsymbol

extern (D) this(Loc loc, Identifier ident) @safe
{
super(loc, null); // it's anonymous (no identifier)
super(DSYM.aliasThis, loc, null); // it's anonymous (no identifier)
this.ident = ident;
}

Expand Down
63 changes: 23 additions & 40 deletions compiler/src/dmd/attrib.d
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,19 @@ extern (C++) abstract class AttribDeclaration : Dsymbol

extern (D) this(Dsymbols* decl) @safe
{
super(DSYM.attribDeclaration);
this.decl = decl;
}

extern (D) this(Loc loc, Dsymbols* decl) @safe
{
super(loc, null);
super(DSYM.attribDeclaration, loc, null);
this.decl = decl;
}

extern (D) this(Loc loc, Identifier ident, Dsymbols* decl) @safe
{
super(loc, ident);
super(DSYM.attribDeclaration, loc, ident);
this.decl = decl;
}

Expand Down Expand Up @@ -126,11 +127,6 @@ extern (C++) abstract class AttribDeclaration : Dsymbol
objc.addSymbols(this, classes, categories);
}

override inout(AttribDeclaration) isAttribDeclaration() inout pure @safe
{
return this;
}

override void accept(Visitor v)
{
v.visit(this);
Expand All @@ -150,12 +146,14 @@ extern (C++) class StorageClassDeclaration : AttribDeclaration
{
super(decl);
this.stc = stc;
this.dsym = DSYM.storageClassDeclaration;
}

extern (D) this(Loc loc, StorageClass stc, Dsymbols* decl) @safe
{
super(loc, decl);
this.stc = stc;
this.dsym = DSYM.storageClassDeclaration;
}

override StorageClassDeclaration syntaxCopy(Dsymbol s)
Expand All @@ -164,11 +162,6 @@ extern (C++) class StorageClassDeclaration : AttribDeclaration
return new StorageClassDeclaration(stc, Dsymbol.arraySyntaxCopy(decl));
}

override inout(StorageClassDeclaration) isStorageClassDeclaration() inout
{
return this;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down Expand Up @@ -221,6 +214,7 @@ extern (C++) final class LinkDeclaration : AttribDeclaration
super(loc, null, decl);
//printf("LinkDeclaration(linkage = %d, decl = %p)\n", linkage, decl);
this.linkage = linkage;
this.dsym = DSYM.linkDeclaration;
}

static LinkDeclaration create(Loc loc, LINK p, Dsymbols* decl) @safe
Expand Down Expand Up @@ -257,6 +251,7 @@ extern (C++) final class CPPMangleDeclaration : AttribDeclaration
super(loc, null, decl);
//printf("CPPMangleDeclaration(cppmangle = %d, decl = %p)\n", cppmangle, decl);
this.cppmangle = cppmangle;
this.dsym = DSYM.cppMangleDeclaration;
}

override CPPMangleDeclaration syntaxCopy(Dsymbol s)
Expand Down Expand Up @@ -302,18 +297,21 @@ extern (C++) final class CPPNamespaceDeclaration : AttribDeclaration
extern (D) this(Loc loc, Identifier ident, Dsymbols* decl) @safe
{
super(loc, ident, decl);
this.dsym = DSYM.cppNamespaceDeclaration;
}

extern (D) this(Loc loc, Expression exp, Dsymbols* decl) @safe
{
super(loc, null, decl);
this.dsym = DSYM.cppNamespaceDeclaration;
this.exp = exp;
}

extern (D) this(Loc loc, Identifier ident, Expression exp, Dsymbols* decl,
CPPNamespaceDeclaration parent) @safe
{
super(loc, ident, decl);
this.dsym = DSYM.cppNamespaceDeclaration;
this.exp = exp;
this.cppnamespace = parent;
}
Expand All @@ -329,8 +327,6 @@ extern (C++) final class CPPNamespaceDeclaration : AttribDeclaration
{
v.visit(this);
}

override inout(CPPNamespaceDeclaration) isCPPNamespaceDeclaration() inout { return this; }
}

/***********************************************************
Expand All @@ -353,6 +349,7 @@ extern (C++) final class VisibilityDeclaration : AttribDeclaration
extern (D) this(Loc loc, Visibility visibility, Dsymbols* decl) @safe
{
super(loc, null, decl);
this.dsym = DSYM.visibilityDeclaration;
this.visibility = visibility;
//printf("decl = %p\n", decl);
}
Expand All @@ -366,6 +363,7 @@ extern (C++) final class VisibilityDeclaration : AttribDeclaration
extern (D) this(Loc loc, Identifier[] pkg_identifiers, Dsymbols* decl)
{
super(loc, null, decl);
this.dsym = DSYM.visibilityDeclaration;
this.visibility.kind = Visibility.Kind.package_;
this.pkg_identifiers = pkg_identifiers;
if (pkg_identifiers.length > 0)
Expand Down Expand Up @@ -399,11 +397,6 @@ extern (C++) final class VisibilityDeclaration : AttribDeclaration
return buf.extractChars();
}

override inout(VisibilityDeclaration) isVisibilityDeclaration() inout
{
return this;
}

override void accept(Visitor v)
{
v.visit(this);
Expand All @@ -428,6 +421,7 @@ extern (C++) final class AlignDeclaration : AttribDeclaration
extern (D) this(Loc loc, Expression exp, Dsymbols* decl)
{
super(loc, null, decl);
this.dsym = DSYM.alignDeclaration;
if (exp)
{
exps = new Expressions();
Expand All @@ -438,12 +432,14 @@ extern (C++) final class AlignDeclaration : AttribDeclaration
extern (D) this(Loc loc, Expressions* exps, Dsymbols* decl) @safe
{
super(loc, null, decl);
this.dsym = DSYM.alignDeclaration;
this.exps = exps;
}

extern (D) this(Loc loc, structalign_t salign, Dsymbols* decl) @safe
{
super(loc, null, decl);
this.dsym = DSYM.alignDeclaration;
this.salign = salign;
}

Expand Down Expand Up @@ -475,6 +471,7 @@ extern (C++) final class AnonDeclaration : AttribDeclaration
extern (D) this(Loc loc, bool isunion, Dsymbols* decl) @safe
{
super(loc, null, decl);
this.dsym = DSYM.anonDeclaration;
this.isunion = isunion;
}

Expand All @@ -489,11 +486,6 @@ extern (C++) final class AnonDeclaration : AttribDeclaration
return (isunion ? "anonymous union" : "anonymous struct");
}

override inout(AnonDeclaration) isAnonDeclaration() inout
{
return this;
}

override void accept(Visitor v)
{
v.visit(this);
Expand All @@ -513,6 +505,7 @@ extern (C++) final class PragmaDeclaration : AttribDeclaration
extern (D) this(Loc loc, Identifier ident, Expressions* args, Dsymbols* decl) @safe
{
super(loc, ident, decl);
this.dsym = DSYM.pragmaDeclaration;
this.args = args;
}

Expand Down Expand Up @@ -548,6 +541,7 @@ extern (C++) class ConditionalDeclaration : AttribDeclaration
extern (D) this(Loc loc, Condition condition, Dsymbols* decl, Dsymbols* elsedecl) @safe
{
super(loc, null, decl);
this.dsym = DSYM.conditionalDeclaration;
//printf("ConditionalDeclaration::ConditionalDeclaration()\n");
this.condition = condition;
this.elsedecl = elsedecl;
Expand Down Expand Up @@ -579,6 +573,7 @@ extern (C++) final class StaticIfDeclaration : ConditionalDeclaration
extern (D) this(Loc loc, Condition condition, Dsymbols* decl, Dsymbols* elsedecl) @safe
{
super(loc, condition, decl, elsedecl);
this.dsym = DSYM.staticIfDeclaration;
//printf("StaticIfDeclaration::StaticIfDeclaration()\n");
}

Expand All @@ -593,11 +588,6 @@ extern (C++) final class StaticIfDeclaration : ConditionalDeclaration
return "static if";
}

override inout(StaticIfDeclaration) isStaticIfDeclaration() inout pure @safe
{
return this;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down Expand Up @@ -628,6 +618,7 @@ extern (C++) final class StaticForeachDeclaration : AttribDeclaration
extern (D) this(StaticForeach sfe, Dsymbols* decl) @safe
{
super(sfe.loc, null, decl);
this.dsym = DSYM.staticForeachDeclaration;
this.sfe = sfe;
}

Expand Down Expand Up @@ -683,16 +674,11 @@ extern(C++) final class ForwardingAttribDeclaration : AttribDeclaration
this(Dsymbols* decl) @safe
{
super(decl);
this.dsym = DSYM.forwardingAttribDeclaration;
sym = new ForwardingScopeDsymbol();
sym.symtab = new DsymbolTable();
}


override inout(ForwardingAttribDeclaration) isForwardingAttribDeclaration() inout
{
return this;
}

override void accept(Visitor v)
{
v.visit(this);
Expand All @@ -715,6 +701,7 @@ extern (C++) final class MixinDeclaration : AttribDeclaration
{
super(loc, null, null);
//printf("MixinDeclaration(loc = %d)\n", loc.linnum);
this.dsym = DSYM.mixinDeclaration;
this.exps = exps;
}

Expand All @@ -729,11 +716,6 @@ extern (C++) final class MixinDeclaration : AttribDeclaration
return "mixin";
}

override inout(MixinDeclaration) isMixinDeclaration() inout
{
return this;
}

override void accept(Visitor v)
{
v.visit(this);
Expand All @@ -752,6 +734,7 @@ extern (C++) final class UserAttributeDeclaration : AttribDeclaration
extern (D) this(Expressions* atts, Dsymbols* decl) @safe
{
super(decl);
this.dsym = DSYM.userAttributeDeclaration;
this.atts = atts;
}

Expand Down
6 changes: 0 additions & 6 deletions compiler/src/dmd/attrib.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class AttribDeclaration : public Dsymbol
const char *kind() const override;
bool hasPointers() override final;
bool hasStaticCtorOrDtor() override final;
AttribDeclaration *isAttribDeclaration() override { return this; }

void accept(Visitor *v) override { v->visit(this); }
};
Expand All @@ -42,7 +41,6 @@ class StorageClassDeclaration : public AttribDeclaration
StorageClass stc;

StorageClassDeclaration *syntaxCopy(Dsymbol *s) override;
StorageClassDeclaration *isStorageClassDeclaration() override { return this; }

void accept(Visitor *v) override { v->visit(this); }
};
Expand Down Expand Up @@ -94,7 +92,6 @@ class VisibilityDeclaration final : public AttribDeclaration
VisibilityDeclaration *syntaxCopy(Dsymbol *s) override;
const char *kind() const override;
const char *toPrettyChars(bool unused) override;
VisibilityDeclaration *isVisibilityDeclaration() override { return this; }
void accept(Visitor *v) override { v->visit(this); }
};

Expand All @@ -119,7 +116,6 @@ class AnonDeclaration final : public AttribDeclaration

AnonDeclaration *syntaxCopy(Dsymbol *s) override;
const char *kind() const override;
AnonDeclaration *isAnonDeclaration() override { return this; }
void accept(Visitor *v) override { v->visit(this); }
};

Expand Down Expand Up @@ -151,7 +147,6 @@ class StaticIfDeclaration final : public ConditionalDeclaration
d_bool onStack;

StaticIfDeclaration *syntaxCopy(Dsymbol *s) override;
StaticIfDeclaration *isStaticIfDeclaration() override { return this; }
const char *kind() const override;
void accept(Visitor *v) override { v->visit(this); }
};
Expand All @@ -175,7 +170,6 @@ class ForwardingAttribDeclaration final : public AttribDeclaration
public:
ForwardingScopeDsymbol *sym;

ForwardingAttribDeclaration *isForwardingAttribDeclaration() override { return this; }
void accept(Visitor *v) override { v->visit(this); }
};

Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dmd/cond.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class DebugCondition final : public DVCondition
static void addGlobalIdent(const char *ident);

int include(Scope *sc) override;
DebugCondition *isDebugCondition() override { return this; }
void accept(Visitor *v) override { v->visit(this); }
};

Expand All @@ -82,7 +81,6 @@ class VersionCondition final : public DVCondition
static void addPredefinedGlobalIdent(const char *ident);

int include(Scope *sc) override;
VersionCondition *isVersionCondition() override { return this; }
void accept(Visitor *v) override { v->visit(this); }
};

Expand Down
Loading

0 comments on commit 216837b

Please sign in to comment.