From b48c288762549f6a4166c5c17916c9199cc7d691 Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Sat, 12 Jul 2025 18:32:10 +0800 Subject: [PATCH] [dsymbol.d] remove dependance on glue layer --- compiler/src/dmd/dsymbol.d | 3 +- compiler/src/dmd/frontend.h | 4 +-- compiler/src/dmd/tocsym.d | 19 ++++++----- compiler/src/dmd/todt.d | 8 ++--- compiler/src/dmd/toir.d | 21 ++++++++---- compiler/src/dmd/toobj.d | 64 ++++++++++++++++++++----------------- 6 files changed, 67 insertions(+), 52 deletions(-) diff --git a/compiler/src/dmd/dsymbol.d b/compiler/src/dmd/dsymbol.d index 5eb395cef71f..7e6647bc6c1b 100644 --- a/compiler/src/dmd/dsymbol.d +++ b/compiler/src/dmd/dsymbol.d @@ -22,7 +22,6 @@ import dmd.arraytypes; import dmd.attrib; import dmd.astenums; import dmd.ast_node; -import dmd.gluelayer; import dmd.dclass; import dmd.declaration; import dmd.denum; @@ -334,7 +333,7 @@ extern (C++) class Dsymbol : ASTNode { Identifier ident; Dsymbol parent; - Symbol* csym; // symbol for code generator + void* csym; // symbol for code generator Scope* _scope; // !=null means context to use for semantic() private DsymbolAttributes* atts; /// attached attribute declarations const Loc loc; // where defined diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index 692fdc36f971..a178956000b5 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -39,7 +39,6 @@ struct _d_dynamicArray final class Visitor; class Identifier; -struct Symbol; struct Scope; struct DsymbolAttributes; class DeprecatedDeclaration; @@ -118,6 +117,7 @@ class ForeachStatement; class ForeachRangeStatement; struct OutBuffer; class TypeInfoClassDeclaration; +struct Symbol; class TypeTuple; class Initializer; struct IntRange; @@ -543,7 +543,7 @@ class Dsymbol : public ASTNode public: Identifier* ident; Dsymbol* parent; - Symbol* csym; + void* csym; Scope* _scope; private: DsymbolAttributes* atts; diff --git a/compiler/src/dmd/tocsym.d b/compiler/src/dmd/tocsym.d index ad753bbecdd5..b9f95f151ae6 100644 --- a/compiler/src/dmd/tocsym.d +++ b/compiler/src/dmd/tocsym.d @@ -368,7 +368,7 @@ Symbol* toSymbol(Dsymbol s) /* Use the C symbol for the previously generated function */ fd.csym = Csymtab.lookup(fd.ident).csym; - result = fd.csym; + result = cast(Symbol*)fd.csym; fd.skipCodegen = true; return; @@ -532,15 +532,18 @@ Symbol* toSymbol(Dsymbol s) } } - if (s.csym) - return s.csym; + if (auto csym = cast(Symbol*)s.csym) + return csym; scope ToSymbol v = new ToSymbol(); s.accept(v); s.csym = v.result; if (isDllImported(s)) - s.csym.Sisym = createImport(s.csym, s.loc); + { + auto csym = cast(Symbol*) s.csym; + csym.Sisym = createImport(csym, s.loc); + } return v.result; } @@ -606,7 +609,7 @@ Symbol* toImport(Dsymbol ds) { if (!ds.csym) toSymbol(ds); - return ds.csym.Sisym; + return (cast(Symbol*)(ds.csym)).Sisym; } /************************************* @@ -629,10 +632,10 @@ Symbol* toThunkSymbol(FuncDeclaration fd, int offset) char[nameLen] name = void; const len = snprintf(name.ptr,nameLen,"_THUNK%d",tmpnum++); - auto sthunk = symbol_name(name[0 .. len],SC.static_,fd.csym.Stype); + auto sthunk = symbol_name(name[0 .. len],SC.static_,(cast(Symbol*)(fd.csym)).Stype); sthunk.Sflags |= SFLnodebug | SFLartifical; sthunk.Sflags |= SFLimplem; - outthunk(sthunk, fd.csym, 0, TYnptr, -offset, -1, 0); + outthunk(sthunk, cast(Symbol*)fd.csym, 0, TYnptr, -offset, -1, 0); return sthunk; } @@ -675,7 +678,7 @@ Symbol* toVtblSymbol(ClassDeclaration cd, bool genCsymbol = true) auto vtbl = cd.vtblSymbol(); vtbl.csym = s; } - return cd.vtblsym.csym; + return cast(Symbol*)cd.vtblsym.csym; } /********************************** diff --git a/compiler/src/dmd/todt.d b/compiler/src/dmd/todt.d index f9a3520cfe0c..a4992ff36e1e 100644 --- a/compiler/src/dmd/todt.d +++ b/compiler/src/dmd/todt.d @@ -1265,7 +1265,7 @@ private extern (C++) class TypeInfoDtVisitor : Visitor const(char)* name = sd.toPrettyChars(); size_t namelen = strlen(name); dtb.size(namelen); - dtb.xoff(d.csym, Type.typeinfoenum.structsize); + dtb.xoff(cast(Symbol*)d.csym, Type.typeinfoenum.structsize); // void[] init; if (!sd.members || d.tinfo.isZeroInit(Loc.initial)) @@ -1385,7 +1385,7 @@ private extern (C++) class TypeInfoDtVisitor : Visitor assert(name); const namelen = strlen(name); dtb.size(namelen); - dtb.xoff(d.csym, Type.typeinfofunction.structsize); + dtb.xoff(cast(Symbol*)d.csym, Type.typeinfofunction.structsize); // Put out name[] immediately following TypeInfo_Function dtb.nbytes(name[0 .. namelen + 1]); @@ -1409,7 +1409,7 @@ private extern (C++) class TypeInfoDtVisitor : Visitor assert(name); const namelen = strlen(name); dtb.size(namelen); - dtb.xoff(d.csym, Type.typeinfodelegate.structsize); + dtb.xoff(cast(Symbol*)d.csym, Type.typeinfodelegate.structsize); // Put out name[] immediately following TypeInfo_Delegate dtb.nbytes(name[0 .. namelen + 1]); @@ -1485,7 +1485,7 @@ private extern (C++) class TypeInfoDtVisitor : Visitor const mangledName = tc.deco; const mangledNameLen = strlen(mangledName); dtb.size(mangledNameLen); - dtb.xoff(d.csym, Type.typeinfostruct.structsize); + dtb.xoff(cast(Symbol*)d.csym, Type.typeinfostruct.structsize); // void[] init; dtb.size(sd.structsize); // init.length diff --git a/compiler/src/dmd/toir.d b/compiler/src/dmd/toir.d index e1f22b06043d..2e3aa5de4e5b 100644 --- a/compiler/src/dmd/toir.d +++ b/compiler/src/dmd/toir.d @@ -322,8 +322,10 @@ elem* getEthis(Loc loc, ref IRState irs, Dsymbol fd, Dsymbol fdp = null, Dsymbol ethis = el_long(TYnptr, 0); ethis.Eoper = OPframeptr; - thisfd.csym.Sfunc.Fflags &= ~Finline; // inliner breaks with this because the offsets are off - // see runnable/ice10086b.d + auto csym = cast(Symbol*) thisfd.csym; + // inliner breaks with this because the offsets are off + // see runnable/ice10086b.d + csym.Sfunc.Fflags &= ~Finline; } else { @@ -681,8 +683,13 @@ TYPE* getParentClosureType(Symbol* sthis, FuncDeclaration fd) for (Dsymbol sym = fd.toParent2(); sym; sym = sym.toParent2()) { if (auto fn = sym.isFuncDeclaration()) - if (fn.csym && fn.csym.Sscope) - return fn.csym.Sscope.Stype; + { + if (auto csym = cast(Symbol*)fn.csym) + { + if (csym.Sscope) + return csym.Sscope.Stype; + } + } if (sym.isAggregateDeclaration()) break; } @@ -880,7 +887,7 @@ void buildClosure(FuncDeclaration fd, ref IRState irs) //printf("structsize = %d\n", cast(uint)structsize); Closstru.Ttag.Sstruct.Sstructsize = cast(uint)structsize; - fd.csym.Sscope = sclosure; + (cast(Symbol*)fd.csym).Sscope = sclosure; if (driverParams.symdebug) toDebugClosure(Closstru.Ttag); @@ -1112,7 +1119,7 @@ void buildAlignSection(FuncDeclaration fd, ref IRState irs) structsize += aggAlignment - stackAlign; Closstru.Ttag.Sstruct.Sstructsize = cast(uint)structsize; - fd.csym.Sscope = sclosure; + (cast(Symbol*)fd.csym).Sscope = sclosure; if (driverParams.symdebug) toDebugClosure(Closstru.Ttag); @@ -1180,7 +1187,7 @@ void buildCapture(FuncDeclaration fd) Symbol* scapture = symbol_name("__captureptr", SC.alias_, type_pointer(capturestru)); scapture.Sflags |= SFLtrue | SFLfree; //symbol_add(scapture); - fd.csym.Sscope = scapture; + (cast(Symbol*)fd.csym).Sscope = scapture; toDebugClosure(capturestru.Ttag); } diff --git a/compiler/src/dmd/toobj.d b/compiler/src/dmd/toobj.d index 9d01e12bf694..ce8f9660142c 100644 --- a/compiler/src/dmd/toobj.d +++ b/compiler/src/dmd/toobj.d @@ -95,8 +95,9 @@ void genModuleInfo(Module m) ////////////////////////////////////////////// - m.csym.Sclass = SC.global; - m.csym.Sfl = FL.data; + auto csym = cast(Symbol*)m.csym; + csym.Sclass = SC.global; + csym.Sfl = FL.data; auto dtb = DtBuilder(0); @@ -210,9 +211,9 @@ void genModuleInfo(Module m) } objc.generateModuleInfo(m); - m.csym.Sdt = dtb.finish(); - out_readonly(m.csym); - outdata(m.csym); + csym.Sdt = dtb.finish(); + out_readonly(csym); + outdata(csym); ////////////////////////////////////////////// @@ -420,7 +421,7 @@ void toObjFile(Dsymbol ds, bool multiobj) //printf("putting out %s.vtbl[]\n", toChars()); auto dtbv = DtBuilder(0); if (cd.vtblOffset()) - dtbv.xoff(cd.csym, 0, TYnptr); // first entry is ClassInfo reference + dtbv.xoff(cast(Symbol*)cd.csym, 0, TYnptr); // first entry is ClassInfo reference foreach (i; cd.vtblOffset() .. cd.vtbl.length) { FuncDeclaration fd = cd.vtbl[i].isFuncDeclaration(); @@ -441,13 +442,14 @@ void toObjFile(Dsymbol ds, bool multiobj) */ dtbv.size(0); } - cd.vtblsym.csym.Sdt = dtbv.finish(); - cd.vtblsym.csym.Sclass = scclass; - cd.vtblsym.csym.Sfl = FL.data; - out_readonly(cd.vtblsym.csym); - outdata(cd.vtblsym.csym); + auto csym = cast(Symbol*) cd.vtblsym.csym; + csym.Sdt = dtbv.finish(); + csym.Sclass = scclass; + csym.Sfl = FL.data; + out_readonly(csym); + outdata(csym); if (cd.isExport() || driverParams.exportVisibility == ExpVis.public_) - objmod.export_symbol(cd.vtblsym.csym, 0); + objmod.export_symbol(csym, 0); } override void visit(InterfaceDeclaration id) @@ -1227,18 +1229,19 @@ private void genClassInfoForClass(ClassDeclaration cd, Symbol* sinit) // Put out the ClassInfo, which will be the __ClassZ symbol in the object file SC scclass = SC.comdat; - cd.csym.Sclass = scclass; - cd.csym.Sfl = FL.data; + auto csym = cast(Symbol*) cd.csym; + csym.Sclass = scclass; + csym.Sfl = FL.data; auto dtb = DtBuilder(0); ClassInfoToDt(dtb, cd, sinit); - cd.csym.Sdt = dtb.finish(); + csym.Sdt = dtb.finish(); // ClassInfo cannot be const data, because we use the monitor on it - outdata(cd.csym); + outdata(csym); if (cd.isExport() || driverParams.exportVisibility == ExpVis.public_) - objmod.export_symbol(cd.csym, 0); + objmod.export_symbol(csym, 0); } private void ClassInfoToDt(ref DtBuilder dtb, ClassDeclaration cd, Symbol* sinit) @@ -1293,19 +1296,20 @@ private void ClassInfoToDt(ref DtBuilder dtb, ClassDeclaration cd, Symbol* sinit namelen = strlen(name); } dtb.size(namelen); - dt_t* pdtname = dtb.xoffpatch(cd.csym, 0, TYnptr); + auto csym = cast(Symbol*) cd.csym; + dt_t* pdtname = dtb.xoffpatch(csym, 0, TYnptr); // vtbl[] dtb.size(cd.vtbl.length); if (cd.vtbl.length) - dtb.xoff(cd.vtblsym.csym, 0, TYnptr); + dtb.xoff(cast(Symbol*)cd.vtblsym.csym, 0, TYnptr); else dtb.size(0); // interfaces[] dtb.size(cd.vtblInterfaces.length); if (cd.vtblInterfaces.length) - dtb.xoff(cd.csym, offset, TYnptr); // (*) + dtb.xoff(csym, offset, TYnptr); // (*) else dtb.size(0); @@ -1432,7 +1436,7 @@ Louter: // vtbl[] dtb.size(id.vtbl.length); - dtb.xoff(cd.csym, offset, TYnptr); + dtb.xoff(cast(Symbol*)cd.csym, offset, TYnptr); // offset dtb.size(b.offset); @@ -1483,18 +1487,19 @@ private void genClassInfoForInterface(InterfaceDeclaration id) SC scclass = SC.comdat; // Put out the ClassInfo - id.csym.Sclass = scclass; - id.csym.Sfl = FL.data; + auto csym = cast(Symbol*) id.csym; + csym.Sclass = scclass; + csym.Sfl = FL.data; auto dtb = DtBuilder(0); InterfaceInfoToDt(dtb, id); - id.csym.Sdt = dtb.finish(); - out_readonly(id.csym); - outdata(id.csym); + csym.Sdt = dtb.finish(); + out_readonly(csym); + outdata(csym); if (id.isExport() || driverParams.exportVisibility == ExpVis.public_) - objmod.export_symbol(id.csym, 0); + objmod.export_symbol(csym, 0); } private void InterfaceInfoToDt(ref DtBuilder dtb, InterfaceDeclaration id) @@ -1541,7 +1546,8 @@ private void InterfaceInfoToDt(ref DtBuilder dtb, InterfaceDeclaration id) const(char) *name = id.toPrettyChars(/*QualifyTypes=*/ true); size_t namelen = strlen(name); dtb.size(namelen); - dt_t* pdtname = dtb.xoffpatch(id.csym, 0, TYnptr); + auto csym = cast(Symbol*)id.csym; + dt_t* pdtname = dtb.xoffpatch(csym, 0, TYnptr); // vtbl[] dtb.size(0); @@ -1562,7 +1568,7 @@ private void InterfaceInfoToDt(ref DtBuilder dtb, InterfaceDeclaration id) fatal(); } } - dtb.xoff(id.csym, offset, TYnptr); // (*) + dtb.xoff(csym, offset, TYnptr); // (*) } else {