Skip to content

Commit

Permalink
Remove dead debug/version level logic (#20802)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored Jan 30, 2025
1 parent 06d0cfe commit a05ac96
Show file tree
Hide file tree
Showing 14 changed files with 52 additions and 165 deletions.
21 changes: 7 additions & 14 deletions compiler/src/dmd/astbase.d
Original file line number Diff line number Diff line change
Expand Up @@ -451,16 +451,13 @@ struct ASTBase

extern (C++) final class DebugSymbol : Dsymbol
{
uint level;

extern (D) this(const ref Loc loc, Identifier ident)
{
super(ident);
this.loc = loc;
}
extern (D) this(const ref Loc loc, uint level)
extern (D) this(const ref Loc loc)
{
this.level = level;
this.loc = loc;
}

Expand All @@ -472,16 +469,13 @@ struct ASTBase

extern (C++) final class VersionSymbol : Dsymbol
{
uint level;

extern (D) this(const ref Loc loc, Identifier ident)
{
super(ident);
this.loc = loc;
}
extern (D) this(const ref Loc loc, uint level)
extern (D) this(const ref Loc loc)
{
this.level = level;
this.loc = loc;
}

Expand Down Expand Up @@ -6542,11 +6536,10 @@ struct ASTBase

extern (C++) class DVCondition : Condition
{
uint level;
Identifier ident;
Module mod;

final extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident)
final extern (D) this(const ref Loc loc, Module mod, Identifier ident)
{
super(loc);
this.mod = mod;
Expand All @@ -6561,9 +6554,9 @@ struct ASTBase

extern (C++) final class DebugCondition : DVCondition
{
extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident)
extern (D) this(const ref Loc loc, Module mod, Identifier ident)
{
super(loc, mod, level, ident);
super(loc, mod, ident);
}

override void accept(Visitor v)
Expand All @@ -6574,9 +6567,9 @@ struct ASTBase

extern (C++) final class VersionCondition : DVCondition
{
extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident)
extern (D) this(const ref Loc loc, Module mod, Identifier ident)
{
super(loc, mod, level, ident);
super(loc, mod, ident);
}

override void accept(Visitor v)
Expand Down
23 changes: 7 additions & 16 deletions compiler/src/dmd/cond.d
Original file line number Diff line number Diff line change
Expand Up @@ -493,15 +493,13 @@ extern (C++) final class StaticForeach : RootObject
*/
extern (C++) class DVCondition : Condition
{
uint level;
Identifier ident;
Module mod;

extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident) @safe
extern (D) this(const ref Loc loc, Module mod, Identifier ident) @safe
{
super(loc);
this.mod = mod;
this.level = level;
this.ident = ident;
}

Expand Down Expand Up @@ -556,15 +554,13 @@ extern (C++) final class DebugCondition : DVCondition
*
* Params:
* mod = Module this node belongs to
* level = Minimum global level this condition needs to pass.
* Only used if `ident` is `null`.
* ident = Identifier required for this condition to pass.
* If `null`, this conditiion will use an integer level.
* loc = Location in the source file
*/
extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident) @safe
extern (D) this(const ref Loc loc, Module mod, Identifier ident) @safe
{
super(loc, mod, level, ident);
super(loc, mod, ident);
}

override int include(Scope* sc)
Expand Down Expand Up @@ -592,8 +588,9 @@ extern (C++) final class DebugCondition : DVCondition
mod.debugidsNot.push(ident);
}
}
else if (level <= global.params.debuglevel || level <= mod.debuglevel)
else if (global.params.debugEnabled)
inc = Include.yes;

if (!definedInModule)
printDepsConditional(sc, this, "depsDebug ");
return (inc == Include.yes);
Expand Down Expand Up @@ -837,15 +834,13 @@ extern (C++) final class VersionCondition : DVCondition
*
* Params:
* mod = Module this node belongs to
* level = Minimum global level this condition needs to pass.
* Only used if `ident` is `null`.
* ident = Identifier required for this condition to pass.
* If `null`, this conditiion will use an integer level.
* loc = Location in the source file
*/
extern (D) this(const ref Loc loc, Module mod, uint level, Identifier ident) @safe
extern (D) this(const ref Loc loc, Module mod, Identifier ident) @safe
{
super(loc, mod, level, ident);
super(loc, mod, ident);
}

override int include(Scope* sc)
Expand Down Expand Up @@ -875,8 +870,6 @@ extern (C++) final class VersionCondition : DVCondition
mod.versionidsNot.push(ident);
}
}
else if (level <= global.params.versionlevel || level <= mod.versionlevel)
inc = Include.yes;
if (!definedInModule &&
(!ident || (!isReserved(ident.toString()) && ident != Id._unittest && ident != Id._assert)))
{
Expand Down Expand Up @@ -1010,7 +1003,5 @@ private void printDepsConditional(Scope* sc, DVCondition condition, const(char)[
ob.writestring(") : ");
if (condition.ident)
ob.writestring(condition.ident.toString());
else
ob.print(condition.level);
ob.writeByte('\n');
}
1 change: 0 additions & 1 deletion compiler/src/dmd/cond.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ class StaticForeach final : public RootObject
class DVCondition : public Condition
{
public:
unsigned level;
Identifier *ident;
Module *mod;

Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dmd/dmodule.d
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,9 @@ extern (C++) final class Module : Package

Modules aimports; // all imported modules

uint debuglevel; // debug level
Identifiers* debugids; // debug identifiers
Identifiers* debugidsNot; // forward referenced debug identifiers

uint versionlevel; // version level
Identifiers* versionids; // version identifiers
Identifiers* versionidsNot; // forward referenced version identifiers

Expand Down
61 changes: 18 additions & 43 deletions compiler/src/dmd/dsymbolsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4352,34 +4352,21 @@ private extern(C++) class AddMemberVisitor : Visitor
Module m = sds.isModule();
// Do not add the member to the symbol table,
// just make sure subsequent debug declarations work.
if (ds.ident)
if (!m)
{
if (!m)
{
.error(ds.loc, "%s `%s` declaration must be at module level", ds.kind, ds.toPrettyChars);
ds.errors = true;
}
else
{
if (m.debugidsNot && findCondition(*m.debugidsNot, ds.ident))
{
.error(ds.loc, "%s `%s` defined after use", ds.kind, ds.toPrettyChars);
ds.errors = true;
}
if (!m.debugids)
m.debugids = new Identifiers();
m.debugids.push(ds.ident);
}
.error(ds.loc, "%s `%s` declaration must be at module level", ds.kind, ds.toPrettyChars);
ds.errors = true;
}
else
{
if (!m)
if (m.debugidsNot && findCondition(*m.debugidsNot, ds.ident))
{
.error(ds.loc, "%s `%s` level declaration must be at module level", ds.kind, ds.toPrettyChars);
.error(ds.loc, "%s `%s` defined after use", ds.kind, ds.toPrettyChars);
ds.errors = true;
}
else
m.debuglevel = ds.level;
if (!m.debugids)
m.debugids = new Identifiers();
m.debugids.push(ds.ident);
}
}

Expand All @@ -4389,36 +4376,24 @@ private extern(C++) class AddMemberVisitor : Visitor
Module m = sds.isModule();
// Do not add the member to the symbol table,
// just make sure subsequent debug declarations work.
if (vs.ident)
VersionCondition.checkReserved(vs.loc, vs.ident.toString());
if (!m)
{
VersionCondition.checkReserved(vs.loc, vs.ident.toString());
if (!m)
{
.error(vs.loc, "%s `%s` declaration must be at module level", vs.kind, vs.toPrettyChars);
vs.errors = true;
}
else
{
if (m.versionidsNot && findCondition(*m.versionidsNot, vs.ident))
{
.error(vs.loc, "%s `%s` defined after use", vs.kind, vs.toPrettyChars);
vs.errors = true;
}
if (!m.versionids)
m.versionids = new Identifiers();
m.versionids.push(vs.ident);
}
.error(vs.loc, "%s `%s` declaration must be at module level", vs.kind, vs.toPrettyChars);
vs.errors = true;
}
else
{
if (!m)
if (m.versionidsNot && findCondition(*m.versionidsNot, vs.ident))
{
.error(vs.loc, "%s `%s` level declaration must be at module level", vs.kind, vs.toPrettyChars);
.error(vs.loc, "%s `%s` defined after use", vs.kind, vs.toPrettyChars);
vs.errors = true;
}
else
m.versionlevel = vs.level;
if (!m.versionids)
m.versionids = new Identifiers();
m.versionids.push(vs.ident);
}

}

override void visit(Nspace ns)
Expand Down
33 changes: 3 additions & 30 deletions compiler/src/dmd/dversion.d
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,27 @@ import dmd.visitor;
/***********************************************************
* DebugSymbol's happen for statements like:
* debug = identifier;
* debug = integer;
*/
extern (C++) final class DebugSymbol : Dsymbol
{
uint level;

extern (D) this(const ref Loc loc, Identifier ident) @safe
{
super(loc, ident);
}

extern (D) this(const ref Loc loc, uint level) @safe
extern (D) this(const ref Loc loc) @safe
{
super(loc, null);
this.level = level;
}

override DebugSymbol syntaxCopy(Dsymbol s)
{
assert(!s);
auto ds = new DebugSymbol(loc, ident);
ds.comment = comment;
ds.level = level;
return ds;
}

override const(char)* toChars() const nothrow
{
if (ident)
return ident.toChars();
OutBuffer buf;
buf.print(level);
return buf.extractChars();
}

override const(char)* kind() const nothrow
{
return "debug";
Expand All @@ -83,41 +69,28 @@ extern (C++) final class DebugSymbol : Dsymbol
/***********************************************************
* VersionSymbol's happen for statements like:
* version = identifier;
* version = integer;
*/
extern (C++) final class VersionSymbol : Dsymbol
{
uint level;

extern (D) this(const ref Loc loc, Identifier ident) @safe
{
super(loc, ident);
}

extern (D) this(const ref Loc loc, uint level) @safe
extern (D) this(const ref Loc loc) @safe
{
super(loc, null);
this.level = level;
}

override VersionSymbol syntaxCopy(Dsymbol s)
{
assert(!s);
auto ds = ident ? new VersionSymbol(loc, ident)
: new VersionSymbol(loc, level);
auto ds = new VersionSymbol(loc, ident);
ds.comment = comment;
return ds;
}

override const(char)* toChars() const nothrow
{
if (ident)
return ident.toChars();
OutBuffer buf;
buf.print(level);
return buf.extractChars();
}

override const(char)* kind() const nothrow
{
return "version";
Expand Down
Loading

0 comments on commit a05ac96

Please sign in to comment.