Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/dmd/mtype.d
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,10 @@ extern (C++) abstract class Type : ASTNode
* we bank on the idea that usually only one of variants exist.
* It will also speed up code because these are rarely referenced and
* so need not be in the cache.
*
* NOTE: The cache stores the naked type at the "identity" position.
* For example, a "shared const T" type will have its naked "T" type
* in the field "scto". See also: dmd.typesem.nakedOf(Type).
*/
Type cto; // MODFlags.const_
Type ito; // MODFlags.immutable_
Expand Down
48 changes: 27 additions & 21 deletions compiler/src/dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -464,57 +464,62 @@ void check(Type _this)
* For our new type '_this', which is type-constructed from t,
* fill in the cto, ito, sto, scto, wto shortcuts.
*/
void fixTo(Type _this, Type t)
private void fixTo(Type _this, Type t)
{
Type mto = null; // the naked type of `t`
if (_this.mod || t.mod)
{
_this.getMcache();
t.getMcache();
}
// If fixing this: immutable(T*) by t: immutable(T)*,
// cache t to this.xto won't break transitivity.
Type mto = null;
Type tn = _this.nextOf();
if (!tn || _this.ty != Tsarray && tn.mod == t.nextOf().mod)
{
switch (t.mod)
{
case 0:
mto = t;
mto = t; // t is naked
break;

case MODFlags.const_:
_this.getMcache();
mto = t.mcache.cto; // cto is naked
_this.mcache.cto = t;
break;

case MODFlags.wild:
_this.getMcache();
mto = t.mcache.wto; // wto is naked
_this.mcache.wto = t;
break;

case MODFlags.wildconst:
_this.getMcache();
mto = t.mcache.wcto; // wcto is naked
_this.mcache.wcto = t;
break;

case MODFlags.shared_:
_this.getMcache();
mto = t.mcache.sto; // sto is naked
_this.mcache.sto = t;
break;

case MODFlags.shared_ | MODFlags.const_:
_this.getMcache();
mto = t.mcache.scto; // scto is naked
_this.mcache.scto = t;
break;

case MODFlags.shared_ | MODFlags.wild:
_this.getMcache();
mto = t.mcache.swto; // swto is naked
_this.mcache.swto = t;
break;

case MODFlags.shared_ | MODFlags.wildconst:
_this.getMcache();
mto = t.mcache.swcto; // swcto is naked
_this.mcache.swcto = t;
break;

case MODFlags.immutable_:
_this.getMcache();
mto = t.mcache.ito; // ito is naked
_this.mcache.ito = t;
break;

Expand All @@ -524,11 +529,6 @@ void fixTo(Type _this, Type t)
}
assert(_this.mod != t.mod);

if (_this.mod)
{
_this.getMcache();
t.getMcache();
}
switch (_this.mod)
{
case 0:
Expand Down Expand Up @@ -8529,6 +8529,15 @@ Type immutableOf(Type type)

/********************************
* Make type mutable.
* 0 => 0
* const => 0
* immutable => 0
* shared => shared
* shared const => shared
* wild => 0
* wild const => 0
* shared wild => shared
* shared wild const => shared
*/
Type mutableOf(Type type)
{
Expand All @@ -8545,15 +8554,12 @@ Type mutableOf(Type type)
type.getMcache();
if (type.isShared())
{
if (type.isWild())
t = type.mcache.swcto; // shared wild const -> shared
else
t = type.mcache.sto; // shared const => shared
t = type.mcache.sto; // shared (wild) const => shared
Copy link
Copy Markdown
Member Author

@ibuclaw ibuclaw Apr 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found bug. The swcto back reference of a shared-wild-const type is "naked", not "shared".

It has never been used to hold the reference to the "shared" type, that is in sto instead.

}
else
{
if (type.isWild())
t = type.mcache.wcto; // wild const -> naked
t = type.mcache.wcto; // wild const => naked
else
t = type.mcache.cto; // const => naked
}
Expand Down
Loading