Skip to content

Commit

Permalink
Draft: Tentative fix for missing struct TypeInfo symbols
Browse files Browse the repository at this point in the history
Reverting dlang#14844, which caused such missing TypeInfos, *and* making
sure the special TypeInfo members are fully analyzed and ready for
codegen (otherwise hitting an assertion).
  • Loading branch information
kinke committed Nov 27, 2023
1 parent 41f3577 commit 1e96faf
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 30 deletions.
12 changes: 1 addition & 11 deletions compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -6919,17 +6919,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
// Handle this in the glue layer
e = new TypeidExp(exp.loc, ta);

bool genObjCode = true;

// https://issues.dlang.org/show_bug.cgi?id=23650
// We generate object code for typeinfo, required
// by typeid, only if in non-speculative context
if (sc.flags & SCOPE.compile)
{
genObjCode = false;
}

e.type = getTypeInfoType(exp.loc, ta, sc, genObjCode);
e.type = getTypeInfoType(exp.loc, ta, sc);
semanticTypeInfo(sc, ta);

if (ea)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -8208,7 +8208,7 @@ extern bool tpsemantic(TemplateParameter* tp, Scope* sc, Array<TemplateParameter

extern bool genTypeInfo(Expression* e, const Loc& loc, Type* torig, Scope* sc);

extern Type* getTypeInfoType(const Loc& loc, Type* t, Scope* sc, bool genObjCode = true);
extern Type* getTypeInfoType(const Loc& loc, Type* t, Scope* sc);

extern bool isSpeculativeType(Type* t);

Expand Down
7 changes: 7 additions & 0 deletions compiler/src/dmd/todt.d
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,13 @@ private extern (C++) class TypeInfoDtVisitor : Visitor
/* ti.toObjFile() won't get called. So, store these
* member functions into object file in here.
*/

if (sd.semanticRun < PASS.semantic3done)
{
import dmd.semantic3 : semanticTypeInfoMembers;
semanticTypeInfoMembers(sd);
}

if (sd.xeq && sd.xeq != StructDeclaration.xerreq)
toObjFile(sd.xeq, global.params.multiobj);
if (sd.xcmp && sd.xcmp != StructDeclaration.xerrcmp)
Expand Down
5 changes: 2 additions & 3 deletions compiler/src/dmd/typinf.d
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,13 @@ extern (C++) bool genTypeInfo(Expression e, const ref Loc loc, Type torig, Scope
* loc = the location for reporting line nunbers in errors
* t = the type to get the type of the `TypeInfo` object for
* sc = the scope
* genObjCode = if true, object code will be generated for the obtained TypeInfo
* Returns:
* The type of the `TypeInfo` object associated with `t`
*/
extern (C++) Type getTypeInfoType(const ref Loc loc, Type t, Scope* sc, bool genObjCode = true)
extern (C++) Type getTypeInfoType(const ref Loc loc, Type t, Scope* sc)
{
assert(t.ty != Terror);
if (genTypeInfo(null, loc, t, sc) && genObjCode)
if (genTypeInfo(null, loc, t, sc))
{
// Find module that will go all the way to an object file
Module m = sc._module.importedFrom;
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dmd/typinf.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FuncDeclaration;
class ScopeDsymbol;

bool genTypeInfo(Expression *e, const Loc &loc, Type *torig, Scope *sc);
Type *getTypeInfoType(const Loc &loc, Type *t, Scope *sc, bool genObjCode = true);
Type *getTypeInfoType(const Loc &loc, Type *t, Scope *sc);
bool isSpeculativeType(Type *t);
bool builtinTypeInfo(Type *t);
FuncDeclaration *findGetMembers(ScopeDsymbol *dsym);
2 changes: 1 addition & 1 deletion compiler/src/tests/cxxfrontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,7 @@ void test_typinf(Expression *e, const Loc &loc, Type *t, Scope *sc)
{
// Link tests
genTypeInfo(e, loc, t, sc);
getTypeInfoType(loc, t, sc, false);
getTypeInfoType(loc, t, sc);
isSpeculativeType(t);
builtinTypeInfo(t);
}
Expand Down
13 changes: 0 additions & 13 deletions compiler/test/runnable/test23650.d

This file was deleted.

0 comments on commit 1e96faf

Please sign in to comment.