Skip to content

Commit d35c399

Browse files
committed
[stable] Revert "Fix dlang#22754 - Move Object.__monitor to druntime (dlang#22766)"
This reverts commit b660a8d.
1 parent 12c1081 commit d35c399

21 files changed

Lines changed: 30 additions & 125 deletions

File tree

changelog/dmd.monitor-field.dd

Lines changed: 0 additions & 10 deletions
This file was deleted.

compiler/src/dmd/dclass.d

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -333,17 +333,11 @@ extern (C++) class ClassDeclaration : AggregateDeclaration
333333
}
334334

335335
/**************
336-
* Returns: true if there's a __monitor field, i.e. the druntime `Object` class declares it
336+
* Returns: true if there's a __monitor field
337337
*/
338338
final bool hasMonitor()
339339
{
340-
if (classKind != ClassKind.d)
341-
return false;
342-
// Check if Object in druntime actually declares a __monitor field.
343-
// Custom druntimes can omit it by not declaring it in Object.
344-
if (!object || !object.symtab)
345-
return true; // conservative: Object not yet loaded, assume monitor present
346-
return object.symtab.lookup(Id.__monitor) !is null;
340+
return classKind == ClassKind.d;
347341
}
348342

349343
/****************************************

compiler/src/dmd/dinterpret.d

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,11 +2867,8 @@ public:
28672867
size_t totalFieldCount = 0;
28682868
for (ClassDeclaration c = cd; c; c = c.baseClass)
28692869
totalFieldCount += c.fields.length;
2870-
2871-
totalFieldCount -= cd.hasMonitor(); // skip __monitor field
2872-
28732870
auto elems = new Expressions(totalFieldCount);
2874-
ptrdiff_t fieldsSoFar = totalFieldCount;
2871+
size_t fieldsSoFar = totalFieldCount;
28752872
for (ClassDeclaration c = cd; c; c = c.baseClass)
28762873
{
28772874
fieldsSoFar -= c.fields.length;
@@ -2883,9 +2880,6 @@ public:
28832880
result = CTFEExp.cantexp;
28842881
return;
28852882
}
2886-
if (fieldsSoFar + ptrdiff_t(i) < 0) // field -1 = __monitor which we skip
2887-
break;
2888-
28892883
Expression m;
28902884
if (v._init)
28912885
{

compiler/src/dmd/dsymbolsem.d

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9978,6 +9978,8 @@ private extern(C++) class FinalizeSizeVisitor : Visitor
99789978
{
99799979
outerCd.alignsize = target.ptrsize;
99809980
outerCd.structsize = target.ptrsize; // allow room for __vptr
9981+
if (outerCd.hasMonitor())
9982+
outerCd.structsize += target.ptrsize; // allow room for __monitor
99819983
}
99829984

99839985
//printf("finalizeSize() %s, sizeok = %d\n", toChars(), sizeok);

compiler/src/dmd/dtoh.d

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,9 +1065,6 @@ public:
10651065

10661066
if (adparent)
10671067
{
1068-
if (vd.ident && vd.ident == Id.__monitor)
1069-
return;
1070-
10711068
writeProtection(vd.visibility.kind);
10721069
typeToBuffer(type, vd, true);
10731070
buf.writestringln(";");

compiler/src/dmd/expressionsem.d

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9983,11 +9983,7 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
99839983
if (t1.ty == Tpointer)
99849984
t1 = t1.nextOf();
99859985

9986-
// __monitor is always void* regardless of shared - strip shared from the mod
9987-
auto t1mod = t1.mod;
9988-
if (exp.var.ident == Id.__monitor)
9989-
t1mod &= ~MODFlags.shared_;
9990-
exp.type = exp.type.addMod(t1mod);
9986+
exp.type = exp.type.addMod(t1.mod);
99919987

99929988
// https://issues.dlang.org/show_bug.cgi?id=23109
99939989
// Run semantic on the DotVarExp type

compiler/src/dmd/glue/todt.d

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import dmd.dsymbol;
3737
import dmd.dtemplate;
3838
import dmd.errors;
3939
import dmd.expression;
40-
import dmd.id;
4140
import dmd.expressionsem : toBool, toInteger;
4241
import dmd.func;
4342
import dmd.globals;
@@ -782,11 +781,6 @@ private void membersToDt(AggregateDeclaration ad, ref DtBuilder dtb,
782781
size_t index = 0;
783782
for (ClassDeclaration c = cdb.baseClass; c; c = c.baseClass)
784783
index += c.fields.length;
785-
// CTFE elements exclude __monitor (emitted separately).
786-
// Subtract it from the index, but only when Object is actually
787-
// in the base hierarchy (index > 0 means cdb is not itself Object).
788-
if (index > 0)
789-
index -= cdb.hasMonitor();
790784
membersToDt(cdb, dtb, elements, index, concreteType, null);
791785
offset = cdb.structsize;
792786
}
@@ -851,12 +845,9 @@ private void membersToDt(AggregateDeclaration ad, ref DtBuilder dtb,
851845
offset = 0;
852846
// `offset` now is where the fields start
853847

854-
// __monitor is emitted separately (not from CTFE elements), so exclude it from the count.
855-
// This applies to Object itself (the root class with no base class), not to interfaces.
856-
const size_t monitorExcluded = (cd && !cd.isInterfaceDeclaration() && !cd.baseClass && cd.hasMonitor()) ? 1 : 0;
857848
assert(!elements ||
858849
firstFieldIndex <= elements.length &&
859-
firstFieldIndex + ad.fields.length - monitorExcluded <= elements.length);
850+
firstFieldIndex + ad.fields.length <= elements.length);
860851

861852
uint bitByteOffset = 0; // byte offset of bit field
862853
uint bitOffset = 0; // starting bit number
@@ -909,10 +900,6 @@ private void membersToDt(AggregateDeclaration ad, ref DtBuilder dtb,
909900

910901
foreach (i, field; ad.fields)
911902
{
912-
// __monitor is emitted separately (not from CTFE elements), skip it here
913-
if (field.ident == Id.__monitor)
914-
continue;
915-
916903
// skip if no element for this field
917904
if (elements && !(*elements)[firstFieldIndex + i])
918905
continue;
@@ -1179,9 +1166,6 @@ void ClassReferenceExp_toInstanceDt(ClassReferenceExp ce, ref DtBuilder dtb)
11791166
size_t firstFieldIndex = 0;
11801167
for (ClassDeclaration c = cd.baseClass; c; c = c.baseClass)
11811168
firstFieldIndex += c.fields.length;
1182-
// CTFE elements exclude __monitor (it is emitted separately by membersToDt),
1183-
// so adjust the index to match the elements array layout.
1184-
firstFieldIndex -= cd.hasMonitor();
11851169
membersToDt(cd, dtb, ce.value.elements, firstFieldIndex, cd, null);
11861170
}
11871171

compiler/src/dmd/glue/toobj.d

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,8 +1253,7 @@ private void ClassInfoToDt(ref DtBuilder dtb, ClassDeclaration cd, Symbol* sinit
12531253
}
12541254

12551255
// m_init[]
1256-
// Class instances always have at least a vtable pointer
1257-
assert(cd.structsize >= target.ptrsize || (cd.classKind == ClassKind.cpp && cd.structsize >= 4));
1256+
assert(cd.structsize >= 8 || (cd.classKind == ClassKind.cpp && cd.structsize >= 4));
12581257
dtb.size(cd.structsize); // size
12591258
dtb.xoff(sinit, 0, TYnptr); // initializer
12601259

@@ -1329,8 +1328,6 @@ Louter:
13291328
foreach (vd; pc.fields)
13301329
{
13311330
//printf("vd = %s %s\n", vd.kind(), vd.toChars());
1332-
if (vd.ident == Id.__monitor)
1333-
continue; // __monitor is not GC-managed
13341331
if (vd.hasPointers())
13351332
{
13361333
flags &= ~ClassFlags.noPointers; // not no-how, not no-way

compiler/src/dmd/statementsem.d

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3129,12 +3129,6 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
31293129
ss.exp = new CastExp(ss.loc, ss.exp, t);
31303130
ss.exp = ss.exp.expressionSemantic(sc);
31313131
}
3132-
if (!cd.hasMonitor())
3133-
{
3134-
error(ss.loc, "cannot `synchronize` on a `%s` because `object.Object` has no `__monitor` field",
3135-
cd.toChars());
3136-
return setError();
3137-
}
31383132
version (all)
31393133
{
31403134
/* Rewrite as:

compiler/src/dmd/traits.d

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,6 @@ ulong getTypePointerBitmap(Loc loc, Type t, ref Array!(ulong) data, ErrorSink eS
267267
visitTopLevelClass(t.sym.baseClass.type.isTypeClass());
268268
foreach (v; t.sym.fields)
269269
{
270-
if (v.ident == Id.__monitor)
271-
continue; // __monitor is not GC-managed
272270
offset = classoff + v.offset;
273271
visit(v.type);
274272
}
@@ -1788,7 +1786,6 @@ Expression semanticTraits(TraitsExp e, Scope* sc)
17881786
// Skip over internal members in __traits(allMembers)
17891787
if ((sm.isCtorDeclaration() && sm.ident != Id.ctor) ||
17901788
(sm.isDtorDeclaration() && sm.ident != Id.dtor) ||
1791-
(sm.ident == Id.__monitor) ||
17921789
(sm.isPostBlitDeclaration() && sm.ident != Id.postblit) ||
17931790
sm.isInvariantDeclaration() ||
17941791
sm.isUnitTestDeclaration())

0 commit comments

Comments
 (0)