From f727e7fb36b67a90d89e65b6a9bce5196109d9f9 Mon Sep 17 00:00:00 2001 From: 0-v-0 Date: Sun, 14 Jul 2024 13:14:16 +0800 Subject: [PATCH] refactor nested reference checking (#16693) --- compiler/src/dmd/attrib.d | 3 +-- compiler/src/dmd/clone.d | 3 +-- compiler/src/dmd/cppmangle.d | 3 +-- compiler/src/dmd/dclass.d | 3 +-- compiler/src/dmd/declaration.d | 3 +-- compiler/src/dmd/dscope.d | 3 +-- compiler/src/dmd/dsymbol.d | 6 ++---- compiler/src/dmd/func.d | 9 +++------ compiler/src/dmd/funcsem.d | 3 +-- compiler/src/dmd/inline.d | 6 ++---- compiler/src/dmd/toobj.d | 3 +-- druntime/benchmark/gcbench/vdparser.extra/vdc/ast/stmt.d | 3 +-- druntime/src/core/internal/gc/impl/conservative/gc.d | 7 +++---- 13 files changed, 19 insertions(+), 36 deletions(-) diff --git a/compiler/src/dmd/attrib.d b/compiler/src/dmd/attrib.d index 1c8eb57726..fc13a4c5ef 100644 --- a/compiler/src/dmd/attrib.d +++ b/compiler/src/dmd/attrib.d @@ -237,8 +237,7 @@ extern (C++) class StorageClassDeclaration : AttribDeclaration * before the semantic analysis of 'to', so that template overloading based on the * 'this' pointer can be successful. */ - FuncDeclaration fd = ps.isFuncDeclaration(); - if (fd) + if (FuncDeclaration fd = ps.isFuncDeclaration()) { /* Use storage_class2 instead of storage_class otherwise when we do .di generation * we'll wind up with 'const const' rather than 'const'. diff --git a/compiler/src/dmd/clone.d b/compiler/src/dmd/clone.d index 17b33d839d..a14d84c1f9 100644 --- a/compiler/src/dmd/clone.d +++ b/compiler/src/dmd/clone.d @@ -99,8 +99,7 @@ StorageClass mergeFuncAttrs(StorageClass s1, const FuncDeclaration f) pure */ FuncDeclaration hasIdentityOpAssign(AggregateDeclaration ad, Scope* sc) { - Dsymbol assign = search_function(ad, Id.assign); - if (assign) + if (Dsymbol assign = search_function(ad, Id.assign)) { /* check identity opAssign exists */ diff --git a/compiler/src/dmd/cppmangle.d b/compiler/src/dmd/cppmangle.d index 79be1e5454..2991545faa 100644 --- a/compiler/src/dmd/cppmangle.d +++ b/compiler/src/dmd/cppmangle.d @@ -826,8 +826,7 @@ private final class CppMangleVisitor : Visitor return buf.writestring("St"); auto si = getInstance(s); - Dsymbol p = getQualifier(si); - if (p) + if (Dsymbol p = getQualifier(si)) { if (isStd(p)) { diff --git a/compiler/src/dmd/dclass.d b/compiler/src/dmd/dclass.d index 2199d5d1a7..74074d7078 100644 --- a/compiler/src/dmd/dclass.d +++ b/compiler/src/dmd/dclass.d @@ -490,8 +490,7 @@ extern (C++) class ClassDeclaration : AggregateDeclaration return null; if (cdb.ident.equals(ident)) return cdb; - auto result = cdb.searchBase(ident); - if (result) + if (auto result = cdb.searchBase(ident)) return result; } return null; diff --git a/compiler/src/dmd/declaration.d b/compiler/src/dmd/declaration.d index 9119ecb8bb..2048d20099 100644 --- a/compiler/src/dmd/declaration.d +++ b/compiler/src/dmd/declaration.d @@ -1238,8 +1238,7 @@ extern (C++) class VarDeclaration : Declaration */ for (auto s = cast(Dsymbol)this; s; s = s.parent) { - auto ad = (cast(inout)s).isMember(); - if (ad) + if (auto ad = (cast(inout)s).isMember()) return ad; if (!s.parent || !s.parent.isTemplateMixin()) break; diff --git a/compiler/src/dmd/dscope.d b/compiler/src/dmd/dscope.d index 4719529554..6d2e3bf9d1 100644 --- a/compiler/src/dmd/dscope.d +++ b/compiler/src/dmd/dscope.d @@ -495,8 +495,7 @@ extern (C++) struct Scope if (global.params.fixAliasThis) { Expression exp = new ThisExp(loc); - Dsymbol aliasSym = checkAliasThis(sc.scopesym.isAggregateDeclaration(), ident, flags, &exp); - if (aliasSym) + if (Dsymbol aliasSym = checkAliasThis(sc.scopesym.isAggregateDeclaration(), ident, flags, &exp)) { //printf("found aliassym: %s\n", aliasSym.toChars()); pscopesym = new ExpressionDsymbol(exp); diff --git a/compiler/src/dmd/dsymbol.d b/compiler/src/dmd/dsymbol.d index 90b2d9fda6..bbb4cc3141 100644 --- a/compiler/src/dmd/dsymbol.d +++ b/compiler/src/dmd/dsymbol.d @@ -396,8 +396,7 @@ extern (C++) class Dsymbol : ASTNode while (s) { //printf("\ts = %s '%s'\n", s.kind(), s.toPrettyChars()); - Module m = s.isModule(); - if (m) + if (Module m = s.isModule()) return m; s = s.parent; } @@ -428,8 +427,7 @@ extern (C++) class Dsymbol : ASTNode while (s) { //printf("\ts = %s '%s'\n", s.kind(), s.toPrettyChars()); - Module m = s.isModule(); - if (m) + if (Module m = s.isModule()) return m; TemplateInstance ti = s.isTemplateInstance(); if (ti && ti.enclosing) diff --git a/compiler/src/dmd/func.d b/compiler/src/dmd/func.d index 4f2b08cc8c..e8928f31d7 100644 --- a/compiler/src/dmd/func.d +++ b/compiler/src/dmd/func.d @@ -431,8 +431,7 @@ extern (C++) class FuncDeclaration : Declaration { //printf("FuncDeclaration::overloadInsert(s = %s) this = %s\n", s.toChars(), toChars()); assert(s != this); - AliasDeclaration ad = s.isAliasDeclaration(); - if (ad) + if (AliasDeclaration ad = s.isAliasDeclaration()) { if (overnext) return overnext.overloadInsert(ad); @@ -501,8 +500,7 @@ extern (C++) class FuncDeclaration : Declaration while (f && f.overnext) { //printf("f.overnext = %p %s\n", f.overnext, f.overnext.toChars()); - TemplateDeclaration td = f.overnext.isTemplateDeclaration(); - if (td) + if (TemplateDeclaration td = f.overnext.isTemplateDeclaration()) return td; f = f.overnext.isFuncDeclaration(); } @@ -1731,8 +1729,7 @@ extern (C++) final class FuncLiteralDeclaration : FuncDeclaration { if (parent) { - TemplateInstance ti = parent.isTemplateInstance(); - if (ti) + if (TemplateInstance ti = parent.isTemplateInstance()) return ti.tempdecl.toPrettyChars(QualifyTypes); } return Dsymbol.toPrettyChars(QualifyTypes); diff --git a/compiler/src/dmd/funcsem.d b/compiler/src/dmd/funcsem.d index 594e481e46..1da7eac4a7 100644 --- a/compiler/src/dmd/funcsem.d +++ b/compiler/src/dmd/funcsem.d @@ -1047,8 +1047,7 @@ Ldone: } // If it's a member template - ClassDeclaration cd = ti.tempdecl.isClassMember(); - if (cd) + if (ClassDeclaration cd = ti.tempdecl.isClassMember()) { .error(funcdecl.loc, "%s `%s` cannot use template to add virtual function to class `%s`", funcdecl.kind, funcdecl.toPrettyChars, cd.toChars()); } diff --git a/compiler/src/dmd/inline.d b/compiler/src/dmd/inline.d index a95ded38f2..9e1e0de1f8 100644 --- a/compiler/src/dmd/inline.d +++ b/compiler/src/dmd/inline.d @@ -1239,11 +1239,9 @@ public: void scanVar(Dsymbol s) { //printf("scanVar(%s %s)\n", s.kind(), s.toPrettyChars()); - VarDeclaration vd = s.isVarDeclaration(); - if (vd) + if (VarDeclaration vd = s.isVarDeclaration()) { - TupleDeclaration td = vd.toAlias().isTupleDeclaration(); - if (td) + if (TupleDeclaration td = vd.toAlias().isTupleDeclaration()) { td.foreachVar((s) { diff --git a/compiler/src/dmd/toobj.d b/compiler/src/dmd/toobj.d index 4046ccea11..598ad1c8c3 100644 --- a/compiler/src/dmd/toobj.d +++ b/compiler/src/dmd/toobj.d @@ -1197,8 +1197,7 @@ private size_t emitVtbl(ref DtBuilder dtb, BaseClass *b, ref FuncDeclarations bv foreach (j; jstart .. id_vtbl_dim) { - FuncDeclaration fd = bvtbl[j]; - if (fd) + if (FuncDeclaration fd = bvtbl[j]) { auto offset2 = b.offset; if (fd.interfaceVirtual) diff --git a/druntime/benchmark/gcbench/vdparser.extra/vdc/ast/stmt.d b/druntime/benchmark/gcbench/vdparser.extra/vdc/ast/stmt.d index c2e0947906..9d46795751 100644 --- a/druntime/benchmark/gcbench/vdparser.extra/vdc/ast/stmt.d +++ b/druntime/benchmark/gcbench/vdparser.extra/vdc/ast/stmt.d @@ -38,8 +38,7 @@ class Statement : Node { foreach(m; members) { - Value v = m.interpret(sc); - if(v) + if (Value v = m.interpret(sc)) return v; } return null; diff --git a/druntime/src/core/internal/gc/impl/conservative/gc.d b/druntime/src/core/internal/gc/impl/conservative/gc.d index b1b270799a..d21b541a90 100644 --- a/druntime/src/core/internal/gc/impl/conservative/gc.d +++ b/druntime/src/core/internal/gc/impl/conservative/gc.d @@ -1609,7 +1609,7 @@ struct Gcx void Invariant() const { } debug(INVARIANT) - invariant() + invariant { if (initialized) { @@ -3171,8 +3171,7 @@ Lmark: { // first, we find the Pool this block is in, then check to see if the // mark bit is clear. - auto pool = findPool(addr); - if (pool) + if (auto pool = findPool(addr)) { auto offset = cast(size_t)(addr - pool.baseAddr); auto pn = offset / PAGESIZE; @@ -3924,7 +3923,7 @@ struct Pool void Invariant() const {} debug(INVARIANT) - invariant() + invariant { if (baseAddr) {