Skip to content

Commit 9528f94

Browse files
[dstruct.d] remove semantic imports (#21680)
1 parent 6f674ae commit 9528f94

23 files changed

Lines changed: 225 additions & 221 deletions

compiler/src/dmd/access.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import dmd.dmodule;
2020
import dmd.dscope;
2121
import dmd.dstruct;
2222
import dmd.dsymbol;
23+
import dmd.dsymbolsem : toAlias;
2324
import dmd.errors;
2425
import dmd.expression;
2526
import dmd.funcsem : overloadApply;

compiler/src/dmd/canthrow.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import dmd.astenums;
2020
import dmd.blockexit : BE, checkThrow;
2121
import dmd.declaration;
2222
import dmd.dsymbol;
23-
import dmd.dsymbolsem : include;
23+
import dmd.dsymbolsem : include, toAlias;
2424
import dmd.errorsink;
2525
import dmd.expression;
2626
import dmd.expressionsem : errorSupplementalInferredAttr;

compiler/src/dmd/cxxfrontend.d

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,17 @@ void getLocalClasses(Module mod, ref ClassDeclarations aclasses)
206206
return dmd.dsymbolsem.getLocalClasses(mod, aclasses);
207207
}
208208

209+
Dsymbol toAlias(Dsymbol s)
210+
{
211+
import dmd.dsymbolsem;
212+
return dmd.dsymbolsem.toAlias(s);
213+
}
214+
215+
Dsymbol toAlias2(Dsymbol s)
216+
{
217+
import dmd.dsymbolsem;
218+
return dmd.dsymbolsem.toAlias2(s);
219+
}
209220
/***********************************************************
210221
* dtemplate.d
211222
*/

compiler/src/dmd/declaration.d

Lines changed: 3 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import dmd.delegatize;
2222
import dmd.dscope;
2323
import dmd.dstruct;
2424
import dmd.dsymbol;
25-
import dmd.dsymbolsem : dsymbolSemantic, aliasSemantic;
25+
import dmd.dsymbolsem : toAlias;
2626
import dmd.dtemplate;
2727
import dmd.errors;
2828
import dmd.expression;
@@ -40,7 +40,7 @@ import dmd.rootobject;
4040
import dmd.root.filename;
4141
import dmd.target;
4242
import dmd.tokens;
43-
import dmd.typesem : toDsymbol, typeSemantic, size;
43+
import dmd.typesem : typeSemantic, size;
4444
import dmd.visitor;
4545

4646
version (IN_GCC) {}
@@ -356,21 +356,6 @@ extern (C++) final class TupleDeclaration : Declaration
356356
return tupletype;
357357
}
358358

359-
override Dsymbol toAlias2()
360-
{
361-
//printf("TupleDeclaration::toAlias2() '%s' objects = %s\n", toChars(), objects.toChars());
362-
for (size_t i = 0; i < objects.length; i++)
363-
{
364-
RootObject o = (*objects)[i];
365-
if (Dsymbol s = isDsymbol(o))
366-
{
367-
s = s.toAlias2();
368-
(*objects)[i] = s;
369-
}
370-
}
371-
return this;
372-
}
373-
374359
override bool needThis()
375360
{
376361
//printf("TupleDeclaration::needThis(%s)\n", toChars());
@@ -599,117 +584,7 @@ extern (C++) final class AliasDeclaration : Declaration
599584
{
600585
if (type)
601586
return type;
602-
return toAlias().getType();
603-
}
604-
605-
override Dsymbol toAlias()
606-
{
607-
static if (0)
608-
printf("[%s] AliasDeclaration::toAlias('%s', this = %p, aliassym: %s, kind: '%s', inuse = %d)\n",
609-
loc.toChars(), toChars(), this, aliassym ? aliassym.toChars() : "", aliassym ? aliassym.kind() : "", inuse);
610-
assert(this != aliassym);
611-
//static int count; if (++count == 10) *(char*)0=0;
612-
613-
Dsymbol err()
614-
{
615-
// Avoid breaking "recursive alias" state during errors gagged
616-
if (global.gag)
617-
return this;
618-
aliassym = new AliasDeclaration(loc, ident, Type.terror);
619-
type = Type.terror;
620-
return aliassym;
621-
}
622-
// Reading the AliasDeclaration
623-
if (!this.ignoreRead)
624-
this.wasRead = true; // can never assign to this AliasDeclaration again
625-
626-
if (inuse == 1 && type && _scope)
627-
{
628-
inuse = 2;
629-
const olderrors = global.errors;
630-
Dsymbol s = type.toDsymbol(_scope);
631-
//printf("[%s] type = %s, s = %p, this = %p\n", loc.toChars(), type.toChars(), s, this);
632-
if (global.errors != olderrors)
633-
return err();
634-
if (s)
635-
{
636-
s = s.toAlias();
637-
if (global.errors != olderrors)
638-
return err();
639-
aliassym = s;
640-
inuse = 0;
641-
}
642-
else
643-
{
644-
Type t = type.typeSemantic(loc, _scope);
645-
if (t.ty == Terror)
646-
return err();
647-
if (global.errors != olderrors)
648-
return err();
649-
//printf("t = %s\n", t.toChars());
650-
inuse = 0;
651-
}
652-
}
653-
if (inuse)
654-
{
655-
.error(loc, "%s `%s` recursive alias declaration", kind, toPrettyChars);
656-
return err();
657-
}
658-
659-
if (semanticRun >= PASS.semanticdone)
660-
{
661-
// semantic is already done.
662-
663-
// Do not see aliassym !is null, because of lambda aliases.
664-
665-
// Do not see type.deco !is null, even so "alias T = const int;` needs
666-
// semantic analysis to take the storage class `const` as type qualifier.
667-
}
668-
else
669-
{
670-
// stop AliasAssign tuple building
671-
if (aliassym)
672-
{
673-
if (auto td = aliassym.isTupleDeclaration())
674-
{
675-
if (td.building)
676-
{
677-
td.building = false;
678-
semanticRun = PASS.semanticdone;
679-
return td;
680-
}
681-
}
682-
}
683-
if (_import && _import._scope)
684-
{
685-
/* If this is an internal alias for selective/renamed import,
686-
* load the module first.
687-
*/
688-
_import.dsymbolSemantic(null);
689-
}
690-
if (_scope)
691-
{
692-
aliasSemantic(this, _scope);
693-
}
694-
}
695-
696-
inuse = 1;
697-
Dsymbol s = aliassym ? aliassym.toAlias() : this;
698-
inuse = 0;
699-
return s;
700-
}
701-
702-
override Dsymbol toAlias2()
703-
{
704-
if (inuse)
705-
{
706-
.error(loc, "%s `%s` recursive alias declaration", kind, toPrettyChars);
707-
return this;
708-
}
709-
inuse = 1;
710-
Dsymbol s = aliassym ? aliassym.toAlias2() : this;
711-
inuse = 0;
712-
return s;
587+
return toAlias(this).getType();
713588
}
714589

715590
override bool isOverloadable() const
@@ -1049,17 +924,6 @@ extern (C++) class VarDeclaration : Declaration
1049924
return edtor && !(storage_class & STC.nodtor);
1050925
}
1051926

1052-
override final Dsymbol toAlias()
1053-
{
1054-
//printf("VarDeclaration::toAlias('%s', this = %p, aliassym = %p)\n", toChars(), this, aliassym);
1055-
if ((!type || !type.deco) && _scope)
1056-
dsymbolSemantic(this, _scope);
1057-
1058-
assert(this != aliasTuple);
1059-
Dsymbol s = aliasTuple ? aliasTuple.toAlias() : this;
1060-
return s;
1061-
}
1062-
1063927
override void accept(Visitor v)
1064928
{
1065929
v.visit(this);

compiler/src/dmd/declaration.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ class TupleDeclaration final : public Declaration
184184
TupleDeclaration *syntaxCopy(Dsymbol *) override;
185185
const char *kind() const override;
186186
Type *getType() override;
187-
Dsymbol *toAlias2() override;
188187
bool needThis() override;
189188

190189
void accept(Visitor *v) override { v->visit(this); }
@@ -204,8 +203,6 @@ class AliasDeclaration final : public Declaration
204203
bool overloadInsert(Dsymbol *s) override;
205204
const char *kind() const override;
206205
Type *getType() override;
207-
Dsymbol *toAlias() override;
208-
Dsymbol *toAlias2() override;
209206
bool isOverloadable() const override;
210207

211208
void accept(Visitor *v) override { v->visit(this); }
@@ -223,7 +220,6 @@ class OverDeclaration final : public Declaration
223220
bool equals(const RootObject * const o) const override;
224221
bool overloadInsert(Dsymbol *s) override;
225222

226-
Dsymbol *toAlias() override;
227223
Dsymbol *isUnique();
228224
bool isOverloadable() const override;
229225

@@ -301,7 +297,6 @@ class VarDeclaration : public Declaration
301297
bool isOverlappedWith(VarDeclaration *v);
302298
bool canTakeAddressOf();
303299
bool needsScopeDtor();
304-
Dsymbol *toAlias() override final;
305300
// Eliminate need for dynamic_cast
306301
void accept(Visitor *v) override { v->visit(this); }
307302
};

compiler/src/dmd/dimport.d

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,6 @@ extern (C++) final class Import : Dsymbol
141141
scopesym.addAccessiblePackage(mod, visibility); // d
142142
}
143143

144-
override Dsymbol toAlias()
145-
{
146-
if (aliasId)
147-
return mod;
148-
return this;
149-
}
150-
151144
override bool overloadInsert(Dsymbol s)
152145
{
153146
/* Allow multiple imports with the same package base, but disallow

compiler/src/dmd/dsymbol.d

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import dmd.dmodule;
3030
import dmd.dversion;
3131
import dmd.dscope;
3232
import dmd.dstruct;
33+
import dmd.dsymbolsem : toAlias;
3334
import dmd.dtemplate;
3435
import dmd.errors;
3536
import dmd.expression;
@@ -731,24 +732,6 @@ extern (C++) class Dsymbol : ASTNode
731732
return "symbol";
732733
}
733734

734-
/*********************************
735-
* If this symbol is really an alias for another,
736-
* return that other.
737-
* If needed, semantic() is invoked due to resolve forward reference.
738-
*/
739-
Dsymbol toAlias()
740-
{
741-
return this;
742-
}
743-
744-
/*********************************
745-
* Resolve recursive tuple expansion in eponymous template.
746-
*/
747-
Dsymbol toAlias2()
748-
{
749-
return toAlias();
750-
}
751-
752735
bool overloadInsert(Dsymbol s)
753736
{
754737
//printf("Dsymbol::overloadInsert('%s')\n", s.toChars());

compiler/src/dmd/dsymbol.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ namespace dmd
101101
void dsymbolSemantic(Dsymbol *dsym, Scope *sc);
102102
void semantic2(Dsymbol *dsym, Scope *sc);
103103
void semantic3(Dsymbol *dsym, Scope* sc);
104+
Dsymbol *toAlias(Dsymbol* s);
105+
Dsymbol *toAlias2(Dsymbol* s);
104106
// in iasm.d
105107
void asmSemantic(CAsmDeclaration *ad, Scope *sc);
106108
// in iasmgcc.d
@@ -223,8 +225,6 @@ class Dsymbol : public ASTNode
223225
virtual Identifier *getIdent();
224226
virtual const char *toPrettyChars(bool QualifyTypes = false);
225227
virtual const char *kind() const;
226-
virtual Dsymbol *toAlias(); // resolve real symbol
227-
virtual Dsymbol *toAlias2();
228228
virtual bool overloadInsert(Dsymbol *s);
229229
virtual uinteger_t size(Loc loc);
230230
virtual bool isforwardRef();

0 commit comments

Comments
 (0)