Skip to content

Commit

Permalink
Fix Bugzilla 24599 - Wrongly elided TypeInfo emission (dlang#15868)
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 for the real-world project).
  • Loading branch information
kinke authored and thewilsonator committed Oct 7, 2024
1 parent d661273 commit ec75b67
Show file tree
Hide file tree
Showing 8 changed files with 37 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 @@ -7194,17 +7194,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
// Handle this in the glue layer
Expression 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.traitsCompiles)
{
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 @@ -7596,7 +7596,7 @@ struct Target final

extern Target target;

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

class SemanticTimeTransitiveVisitor : public SemanticTimePermissiveVisitor
{
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 @@ -1441,6 +1441,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 @@ -100,14 +100,13 @@ bool genTypeInfo(Expression e, const ref Loc loc, Type torig, Scope* sc)
* 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 @@ -22,4 +22,4 @@ namespace dmd
bool isSpeculativeType(Type *t);
bool builtinTypeInfo(Type *t);
}
Type *getTypeInfoType(const Loc &loc, Type *t, Scope *sc, bool genObjCode = true);
Type *getTypeInfoType(const Loc &loc, Type *t, Scope *sc);
2 changes: 1 addition & 1 deletion compiler/src/tests/cxxfrontend.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1865,7 +1865,7 @@ void template_h(TemplateParameter *tp, Scope *sc, TemplateParameters *tps,
void typinf_h(Expression *e, const Loc &loc, Type *t, Scope *sc)
{
dmd::genTypeInfo(e, loc, t, sc);
::getTypeInfoType(loc, t, sc, false);
::getTypeInfoType(loc, t, sc);
dmd::isSpeculativeType(t);
dmd::builtinTypeInfo(t);
}
13 changes: 0 additions & 13 deletions compiler/test/runnable/test23650.d

This file was deleted.

24 changes: 24 additions & 0 deletions compiler/test/runnable/test24599.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module mod;

struct Variable
{
size_t toHash() const { return 0; }
}

enum hasInoutConstruction(T) = __traits(compiles, { struct S { T a; } });

struct Algebraic(T)
{
static if (hasInoutConstruction!T)
{
}
}

Algebraic!Variable foo();

struct S
{
Variable[] symbols;
}

void main() {}

0 comments on commit ec75b67

Please sign in to comment.