Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move newScope out of AST nodes to dsymbolsem.d #16880

Merged
merged 26 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c01f76b
extract newScope to dsymbolsem
dchidindu5 Sep 12, 2024
b2300c0
Extract newScope functions to dsymbolsem
dchidindu5 Sep 19, 2024
83ba750
Batch 3 errors encountered
dchidindu5 Sep 20, 2024
8ed06f1
Merge branch 'dlang:master' into practice1
dchidindu5 Sep 20, 2024
36489c9
Extract newScope and turn to visitor
dchidindu5 Sep 22, 2024
b9eab55
Merge branch 'dlang:master' into practice1
dchidindu5 Sep 22, 2024
21de527
Extract newScope and turn into a visitor
dchidindu5 Sep 24, 2024
311414f
Merge branch 'dlang:master' into practice1
dchidindu5 Sep 24, 2024
cd797ca
C
dchidindu5 Sep 25, 2024
b1c7e9c
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Sep 27, 2024
fd7f928
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Sep 30, 2024
e9c9c7e
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Oct 1, 2024
d65d3f7
Merge branch 'dlang:master' into practice1
dchidindu5 Oct 1, 2024
74a7aaf
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Oct 1, 2024
4e90a5d
Merge branch 'practice1' of https://github.com/dchidindu5/dmd into pr…
dchidindu5 Oct 1, 2024
1f4b10d
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Oct 2, 2024
f6d9314
Move newScope out of AST nodes to dsymbolsem.d
dchidindu5 Oct 3, 2024
78c9e42
Fix segfault when compiling druntime
RazvanN7 Oct 3, 2024
063ccba
Merge branch 'master' into practice1
thewilsonator Oct 3, 2024
02757c9
Remove newScope from attrib.h
dchidindu5 Oct 4, 2024
f5e9fc9
Merge branch 'dlang:master' into practice1
dchidindu5 Oct 4, 2024
15bab03
Merge branch 'practice1' of https://github.com/dchidindu5/dmd into pr…
dchidindu5 Oct 4, 2024
f788b09
Remove whitespace
dchidindu5 Oct 4, 2024
e0f76cd
make newScope extern(D)
dchidindu5 Oct 5, 2024
9ec7a80
Remove newScope from frontend.h
dchidindu5 Oct 5, 2024
4b0e00b
Fix newScope in frontend.h
dchidindu5 Oct 5, 2024
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
115 changes: 0 additions & 115 deletions compiler/src/dmd/attrib.d
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ extern (C++) abstract class AttribDeclaration : Dsymbol
return sc2;
}

/****************************************
* A hook point to supply scope for members.
* addMember, setScope, importAll, semantic, semantic2 and semantic3 will use this.
*/
Scope* newScope(Scope* sc)
{
return sc;
}

override void addComment(const(char)* comment)
{
Expand Down Expand Up @@ -201,28 +193,6 @@ extern (C++) class StorageClassDeclaration : AttribDeclaration
return new StorageClassDeclaration(stc, Dsymbol.arraySyntaxCopy(decl));
}

override Scope* newScope(Scope* sc)
{
StorageClass scstc = sc.stc;
/* These sets of storage classes are mutually exclusive,
* so choose the innermost or most recent one.
*/
if (stc & (STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest))
scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.extern_ | STC.manifest);
if (stc & (STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared))
scstc &= ~(STC.auto_ | STC.scope_ | STC.static_ | STC.manifest | STC.gshared);
if (stc & (STC.const_ | STC.immutable_ | STC.manifest))
scstc &= ~(STC.const_ | STC.immutable_ | STC.manifest);
if (stc & (STC.gshared | STC.shared_))
scstc &= ~(STC.gshared | STC.shared_);
if (stc & (STC.safe | STC.trusted | STC.system))
scstc &= ~(STC.safe | STC.trusted | STC.system);
scstc |= stc;
//printf("scstc = x%llx\n", scstc);
return createNewScope(sc, scstc, sc.linkage, sc.cppmangle,
sc.visibility, sc.explicitVisibility, sc.aligndecl, sc.inlining);
}

override final bool oneMember(out Dsymbol ps, Identifier ident)
{
bool t = Dsymbol.oneMembers(decl, ps, ident);
Expand Down Expand Up @@ -285,25 +255,6 @@ extern (C++) final class DeprecatedDeclaration : StorageClassDeclaration
return new DeprecatedDeclaration(msg.syntaxCopy(), Dsymbol.arraySyntaxCopy(decl));
}

/**
* Provides a new scope with `STC.deprecated_` and `Scope.depdecl` set
*
* Calls `StorageClassDeclaration.newScope` (as it must be called or copied
* in any function overriding `newScope`), then set the `Scope`'s depdecl.
*
* Returns:
* Always a new scope, to use for this `DeprecatedDeclaration`'s members.
*/
override Scope* newScope(Scope* sc)
{
auto scx = super.newScope(sc);
// The enclosing scope is deprecated as well
if (scx == sc)
scx = sc.push();
scx.depdecl = this;
return scx;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down Expand Up @@ -338,11 +289,6 @@ extern (C++) final class LinkDeclaration : AttribDeclaration
return new LinkDeclaration(loc, linkage, Dsymbol.arraySyntaxCopy(decl));
}

override Scope* newScope(Scope* sc)
{
return createNewScope(sc, sc.stc, this.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility,
sc.aligndecl, sc.inlining);
}

override const(char)* toChars() const
{
Expand Down Expand Up @@ -385,12 +331,6 @@ extern (C++) final class CPPMangleDeclaration : AttribDeclaration
return new CPPMangleDeclaration(loc, cppmangle, Dsymbol.arraySyntaxCopy(decl));
}

override Scope* newScope(Scope* sc)
{
return createNewScope(sc, sc.stc, LINK.cpp, cppmangle, sc.visibility, sc.explicitVisibility,
sc.aligndecl, sc.inlining);
}

override const(char)* toChars() const
{
return toString().ptr;
Expand Down Expand Up @@ -461,18 +401,6 @@ extern (C++) final class CPPNamespaceDeclaration : AttribDeclaration
this.loc, this.ident, this.exp, Dsymbol.arraySyntaxCopy(this.decl), this.cppnamespace);
}

/**
* Returns:
* A copy of the parent scope, with `this` as `namespace` and C++ linkage
*/
override Scope* newScope(Scope* sc)
{
auto scx = sc.copy();
scx.linkage = LINK.cpp;
scx.namespace = this;
return scx;
}

override const(char)* toChars() const
{
return toString().ptr;
Expand Down Expand Up @@ -544,13 +472,6 @@ extern (C++) final class VisibilityDeclaration : AttribDeclaration
return new VisibilityDeclaration(this.loc, visibility, Dsymbol.arraySyntaxCopy(decl));
}

override Scope* newScope(Scope* sc)
{
if (pkg_identifiers)
dsymbolSemantic(this, sc);
return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, this.visibility, 1, sc.aligndecl, sc.inlining);
}

override const(char)* kind() const
{
return "visibility attribute";
Expand Down Expand Up @@ -620,11 +541,6 @@ extern (C++) final class AlignDeclaration : AttribDeclaration
Dsymbol.arraySyntaxCopy(decl));
}

override Scope* newScope(Scope* sc)
{
return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, this, sc.inlining);
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down Expand Up @@ -693,17 +609,6 @@ extern (C++) final class PragmaDeclaration : AttribDeclaration
return new PragmaDeclaration(loc, ident, Expression.arraySyntaxCopy(args), Dsymbol.arraySyntaxCopy(decl));
}

override Scope* newScope(Scope* sc)
{
if (ident == Id.Pinline)
{
// We keep track of this pragma inside scopes,
// then it's evaluated on demand in function semantic
return createNewScope(sc, sc.stc, sc.linkage, sc.cppmangle, sc.visibility, sc.explicitVisibility, sc.aligndecl, this);
}
return sc;
}

override const(char)* kind() const
{
return "pragma";
Expand Down Expand Up @@ -1004,13 +909,6 @@ extern(C++) final class ForwardingAttribDeclaration : AttribDeclaration
sym.symtab = new DsymbolTable();
}

/**************************************
* Use the ForwardingScopeDsymbol as the parent symbol for members.
*/
override Scope* newScope(Scope* sc)
{
return sc.push(sym);
}

override inout(ForwardingAttribDeclaration) isForwardingAttribDeclaration() inout
{
Expand Down Expand Up @@ -1087,18 +985,6 @@ extern (C++) final class UserAttributeDeclaration : AttribDeclaration
return new UserAttributeDeclaration(Expression.arraySyntaxCopy(this.atts), Dsymbol.arraySyntaxCopy(decl));
}

override Scope* newScope(Scope* sc)
{
Scope* sc2 = sc;
if (atts && atts.length)
{
// create new one for changes
sc2 = sc.copy();
sc2.userAttribDecl = this;
}
return sc2;
}

extern (D) static Expressions* concat(Expressions* udas1, Expressions* udas2)
{
Expressions* udas;
Expand Down Expand Up @@ -1178,7 +1064,6 @@ int foreachUdaNoSemantic(Dsymbol sym, int delegate(Expression) dg)
return 0;
}


/**
* Returns: true if the given expression is an enum from `core.attribute` named `id`
*/
Expand Down
11 changes: 0 additions & 11 deletions compiler/src/dmd/attrib.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class AttribDeclaration : public Dsymbol
Dsymbols *decl; // array of Dsymbol's

virtual Dsymbols *include(Scope *sc);
virtual Scope *newScope(Scope *sc);
void addComment(const utf8_t *comment) override;
const char *kind() const override;
bool oneMember(Dsymbol *&ps, Identifier *ident) override;
Expand All @@ -48,7 +47,6 @@ class StorageClassDeclaration : public AttribDeclaration
StorageClass stc;

StorageClassDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;
bool oneMember(Dsymbol *&ps, Identifier *ident) override final;
StorageClassDeclaration *isStorageClassDeclaration() override { return this; }

Expand All @@ -62,7 +60,6 @@ class DeprecatedDeclaration final : public StorageClassDeclaration
const char *msgstr;

DeprecatedDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;
void accept(Visitor *v) override { v->visit(this); }
};

Expand All @@ -73,7 +70,6 @@ class LinkDeclaration final : public AttribDeclaration

static LinkDeclaration *create(const Loc &loc, LINK p, Dsymbols *decl);
LinkDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;
const char *toChars() const override;
void accept(Visitor *v) override { v->visit(this); }
};
Expand All @@ -84,7 +80,6 @@ class CPPMangleDeclaration final : public AttribDeclaration
CPPMANGLE cppmangle;

CPPMangleDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;
const char *toChars() const override;
void accept(Visitor *v) override { v->visit(this); }
};
Expand All @@ -95,7 +90,6 @@ class CPPNamespaceDeclaration final : public AttribDeclaration
Expression *exp;

CPPNamespaceDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;
const char *toChars() const override;
void accept(Visitor *v) override { v->visit(this); }
};
Expand All @@ -107,7 +101,6 @@ class VisibilityDeclaration final : public AttribDeclaration
DArray<Identifier*> pkg_identifiers;

VisibilityDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;
const char *kind() const override;
const char *toPrettyChars(bool unused) override;
VisibilityDeclaration *isVisibilityDeclaration() override { return this; }
Expand All @@ -121,7 +114,6 @@ class AlignDeclaration final : public AttribDeclaration
structalign_t salign;

AlignDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;
void accept(Visitor *v) override { v->visit(this); }
};

Expand All @@ -146,7 +138,6 @@ class PragmaDeclaration final : public AttribDeclaration
Expressions *args; // array of Expression's

PragmaDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;
const char *kind() const override;
void accept(Visitor *v) override { v->visit(this); }
};
Expand Down Expand Up @@ -200,7 +191,6 @@ class ForwardingAttribDeclaration final : public AttribDeclaration
public:
ForwardingScopeDsymbol *sym;

Scope *newScope(Scope *sc) override;
ForwardingAttribDeclaration *isForwardingAttribDeclaration() override { return this; }
void accept(Visitor *v) override { v->visit(this); }
};
Expand Down Expand Up @@ -230,7 +220,6 @@ class UserAttributeDeclaration final : public AttribDeclaration
Expressions *atts;

UserAttributeDeclaration *syntaxCopy(Dsymbol *s) override;
Scope *newScope(Scope *sc) override;
const char *kind() const override;
void accept(Visitor *v) override { v->visit(this); }
};
1 change: 1 addition & 0 deletions compiler/src/dmd/dsymbol.h
Original file line number Diff line number Diff line change
Expand Up @@ -448,4 +448,5 @@ namespace dmd
Dsymbol *search(Dsymbol *d, const Loc &loc, Identifier *ident, SearchOptFlags flags = (SearchOptFlags)SearchOpt::localsOnly);
void setScope(Dsymbol *d, Scope *sc);
void importAll(Dsymbol *d, Scope *sc);
Scope* newScope(Dsymbol *d, Scope *sc);
Copy link
Contributor

Choose a reason for hiding this comment

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

...in which case remove this from this header

Copy link
Contributor

Choose a reason for hiding this comment

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

if for some reason it needs to be, you will also need to update frontend.h with the same changes (look for a failure on the CircleCI tester)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Razvan said I only should remove newScope from attrib.h @thewilsonator

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but that doesn't mean you need add it here. You must do one of two things:

  • leave newScope extern(C++), leave this dsymbol.haddition here and add it tofrontend.h` (see the Circle CI failure)

  • make newScope extern(D) and remove this addition (and don't update frontend.h, because there is nothing that needs updating).

newScope is unused by LDC and from what I can tell is unused by GDC, so there is no need for it to be extern(C++).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it says "newly generated header file (/home/circleci/dmd/generated/linux/release/64/frontend.h) doesn't match with the reference header file (/home/circleci/dmd/compiler/src/dmd/frontend.h) and The file src/dmd/frontend.h seems to be out of sync. This is likely because changes were made which affect the C++ interface used by GDC and LDC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I got it now

Copy link
Contributor

@thewilsonator thewilsonator Oct 4, 2024

Choose a reason for hiding this comment

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

Yes, this is because newScope is extern(C++). See also the diff that is says you should apply:

diff --git a/home/circleci/dmd/compiler/src/dmd/frontend.h b/home/circleci/dmd/generated/linux/release/64/frontend.h
index 23d404ba6b..9e08f3cd0b 100644
--- a/home/circleci/dmd/compiler/src/dmd/frontend.h
+++ b/home/circleci/dmd/generated/linux/release/64/frontend.h
@@ -6214,7 +6214,6 @@ class AttribDeclaration : public Dsymbol
 public:
     Array<Dsymbol* >* decl;
     virtual Array<Dsymbol* >* include(Scope* sc);
-    virtual Scope* newScope(Scope* sc);
     void addComment(const char* comment) override;
     const char* kind() const override;
     bool oneMember(Dsymbol*& ps, Identifier* ident) override;
@@ -6231,7 +6230,6 @@ class StorageClassDeclaration : public AttribDeclaration
 public:
     StorageClass stc;
     StorageClassDeclaration* syntaxCopy(Dsymbol* s) override;
-    Scope* newScope(Scope* sc) override;
     bool oneMember(Dsymbol*& ps, Identifier* ident) final override;
     StorageClassDeclaration* isStorageClassDeclaration() override;
     void accept(Visitor* v) override;
@@ -6243,7 +6241,6 @@ public:
     Expression* msg;
     const char* msgstr;
     DeprecatedDeclaration* syntaxCopy(Dsymbol* s) override;
-    Scope* newScope(Scope* sc) override;
     void accept(Visitor* v) override;
 };
 
@@ -6253,7 +6250,6 @@ public:
     LINK linkage;
     static LinkDeclaration* create(const Loc& loc, LINK p, Array<Dsymbol* >* decl);
     LinkDeclaration* syntaxCopy(Dsymbol* s) override;
-    Scope* newScope(Scope* sc) override;
     const char* toChars() const override;
     void accept(Visitor* v) override;
 };
@@ -6263,7 +6259,6 @@ class CPPMangleDeclaration final : public AttribDeclaration
 public:
     CPPMANGLE cppmangle;
     CPPMangleDeclaration* syntaxCopy(Dsymbol* s) override;
-    Scope* newScope(Scope* sc) override;
     const char* toChars() const override;
     void accept(Visitor* v) override;
 };
@@ -6273,7 +6268,6 @@ class CPPNamespaceDeclaration final : public AttribDeclaration
 public:
     Expression* exp;
     CPPNamespaceDeclaration* syntaxCopy(Dsymbol* s) override;
-    Scope* newScope(Scope* sc) override;
     const char* toChars() const override;
     void accept(Visitor* v) override;
     CPPNamespaceDeclaration* isCPPNamespaceDeclaration() override;
@@ -6285,7 +6279,6 @@ public:
     Visibility visibility;
     _d_dynamicArray< Identifier* > pkg_identifiers;
     VisibilityDeclaration* syntaxCopy(Dsymbol* s) override;
-    Scope* newScope(Scope* sc) override;
     const char* kind() const override;
     const char* toPrettyChars(bool __param_0_) override;
     VisibilityDeclaration* isVisibilityDeclaration() override;
@@ -6298,7 +6291,6 @@ public:
     Array<Expression* >* exps;
     structalign_t salign;
     AlignDeclaration* syntaxCopy(Dsymbol* s) override;
-    Scope* newScope(Scope* sc) override;
     void accept(Visitor* v) override;
 };
 
@@ -6321,7 +6313,6 @@ class PragmaDeclaration final : public AttribDeclaration
 public:
     Array<Expression* >* args;
     PragmaDeclaration* syntaxCopy(Dsymbol* s) override;
-    Scope* newScope(Scope* sc) override;
     const char* kind() const override;
     void accept(Visitor* v) override;
 };
@@ -6374,7 +6365,6 @@ class ForwardingAttribDeclaration final : public AttribDeclaration
 public:
     ForwardingScopeDsymbol* sym;
     ForwardingAttribDeclaration(Array<Dsymbol* >* decl);
-    Scope* newScope(Scope* sc) override;
     ForwardingAttribDeclaration* isForwardingAttribDeclaration() override;
     void accept(Visitor* v) override;
 };
@@ -6396,7 +6386,6 @@ class UserAttributeDeclaration final : public AttribDeclaration
 public:
     Array<Expression* >* atts;
     UserAttributeDeclaration* syntaxCopy(Dsymbol* s) override;
-    Scope* newScope(Scope* sc) override;
     const char* kind() const override;
     void accept(Visitor* v) override;
 };
@@ -7407,6 +7396,8 @@ public:
     void visit(StaticForeachDeclaration* _) override;
 };
 
+extern Scope* newScope(Dsymbol* d, Scope* sc);
+
 class NrvoWalker final : public StatementRewriteWalker
 {
 public:

Note that you should leave out that last addition if you make newScope extern(D)

}
Loading
Loading