From 04f46ff87d3eb6803e2f07dea5f28ff1f88d8afd Mon Sep 17 00:00:00 2001 From: Walter Bright Date: Tue, 1 Aug 2023 02:48:34 -0700 Subject: [PATCH] remove some dyncast calls (#15488) --- compiler/src/dmd/declaration.d | 2 +- compiler/src/dmd/dinterpret.d | 2 +- compiler/src/dmd/dscope.d | 2 +- compiler/src/dmd/dsymbol.d | 4 ++-- compiler/src/dmd/func.d | 4 ++-- compiler/src/dmd/nogc.d | 6 ++++-- compiler/src/dmd/typesem.d | 10 ++++------ 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/compiler/src/dmd/declaration.d b/compiler/src/dmd/declaration.d index 9db57ce0d9..6cfb53dd1c 100644 --- a/compiler/src/dmd/declaration.d +++ b/compiler/src/dmd/declaration.d @@ -626,7 +626,7 @@ extern (C++) final class TupleDeclaration : Declaration for (size_t i = 0; i < objects.length; i++) { RootObject o = (*objects)[i]; - if (o.dyncast() != DYNCAST.type) + if (!o.isType()) { //printf("\tnot[%d], %p, %d\n", i, o, o.dyncast()); return null; diff --git a/compiler/src/dmd/dinterpret.d b/compiler/src/dmd/dinterpret.d index 228245db57..59483511f6 100644 --- a/compiler/src/dmd/dinterpret.d +++ b/compiler/src/dmd/dinterpret.d @@ -7706,7 +7706,7 @@ private void removeHookTraceImpl(ref CallExp ce, ref FuncDeclaration fd) // Get the Hook from the second template parameter TemplateInstance templateInstance = fd.parent.isTemplateInstance; RootObject hook = (*templateInstance.tiargs)[1]; - assert(hook.dyncast() == DYNCAST.dsymbol, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!"); + assert(hook.isDsymbol(), "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!"); fd = (cast(Dsymbol)hook).isFuncDeclaration; // Remove the first three trace parameters diff --git a/compiler/src/dmd/dscope.d b/compiler/src/dmd/dscope.d index dc4986282b..c2c0628f5e 100644 --- a/compiler/src/dmd/dscope.d +++ b/compiler/src/dmd/dscope.d @@ -168,7 +168,7 @@ extern (C++) struct Scope sc.minst = _module; sc.scopesym = new ScopeDsymbol(); sc.scopesym.symtab = new DsymbolTable(); - sc.eSink = eSink; + sc.eSink = eSink; // Add top level package as member of this global scope Dsymbol m = _module; while (m.parent) diff --git a/compiler/src/dmd/dsymbol.d b/compiler/src/dmd/dsymbol.d index 8ebdc03710..0fa4dbcfa5 100644 --- a/compiler/src/dmd/dsymbol.d +++ b/compiler/src/dmd/dsymbol.d @@ -353,9 +353,9 @@ extern (C++) class Dsymbol : ASTNode { if (this == o) return true; - if (o.dyncast() != DYNCAST.dsymbol) + const s = o.isDsymbol(); + if (!s) return false; - auto s = cast(Dsymbol)o; // Overload sets don't have an ident // Function-local declarations may have identical names // if they are declared in different scopes diff --git a/compiler/src/dmd/func.d b/compiler/src/dmd/func.d index d58b11e602..c963a470a3 100644 --- a/compiler/src/dmd/func.d +++ b/compiler/src/dmd/func.d @@ -4708,9 +4708,9 @@ void errorSupplementalInferredAttr(FuncDeclaration fd, int maxDepth, bool deprec s.arg0 ? s.arg0.toChars() : "", s.arg1 ? s.arg1.toChars() : "", s.arg2 ? s.arg2.toChars() : ""); } } - else if (s.arg0.dyncast() == DYNCAST.dsymbol) + else if (auto sa = s.arg0.isDsymbol()) { - if (FuncDeclaration fd2 = (cast(Dsymbol) s.arg0).isFuncDeclaration()) + if (FuncDeclaration fd2 = sa.isFuncDeclaration()) { if (maxDepth > 0) { diff --git a/compiler/src/dmd/nogc.d b/compiler/src/dmd/nogc.d index 18cf3180a3..01a6832a97 100644 --- a/compiler/src/dmd/nogc.d +++ b/compiler/src/dmd/nogc.d @@ -19,6 +19,7 @@ import dmd.aggregate; import dmd.astenums; import dmd.declaration; import dmd.dscope; +import dmd.dtemplate : isDsymbol; import dmd.errors; import dmd.expression; import dmd.func; @@ -263,6 +264,7 @@ private FuncDeclaration stripHookTraceImpl(FuncDeclaration fd) // Get the Hook from the second template parameter auto templateInstance = fd.parent.isTemplateInstance; RootObject hook = (*templateInstance.tiargs)[1]; - assert(hook.dyncast() == DYNCAST.dsymbol, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!"); - return (cast(Dsymbol)hook).isFuncDeclaration; + Dsymbol s = hook.isDsymbol(); + assert(s, "Expected _d_HookTraceImpl's second template parameter to be an alias to the hook!"); + return s.isFuncDeclaration; } diff --git a/compiler/src/dmd/typesem.d b/compiler/src/dmd/typesem.d index a044a4fd7e..a80aa80a89 100644 --- a/compiler/src/dmd/typesem.d +++ b/compiler/src/dmd/typesem.d @@ -530,12 +530,10 @@ extern(C++) Type typeSemantic(Type type, const ref Loc loc, Scope* sc) } RootObject o = (*tup.objects)[cast(size_t)d]; - if (o.dyncast() != DYNCAST.type) - { - .error(loc, "`%s` is not a type", mtype.toChars()); - return error(); - } - return (cast(Type)o).addMod(mtype.mod); + if (auto tt = o.isType()) + return tt.addMod(mtype.mod); + .error(loc, "`%s` is not a type", mtype.toChars()); + return error(); } if (t && t.ty == Terror)