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

Address Cyclic Unit references in Parser.h #3358

Open
InsertCreativityHere opened this issue Jan 14, 2025 · 0 comments
Open

Address Cyclic Unit references in Parser.h #3358

InsertCreativityHere opened this issue Jan 14, 2025 · 0 comments

Comments

@InsertCreativityHere
Copy link
Member

In the Slice compiler, the base type for all Slice types & definitions is SyntaxTreeBase. SyntaxTreeBase itself inherits from the true base class: GrammarBase. This represents other grammatical objects that aren't types or definitions (metadata, parts of definitions that haven't been fully parsed yet, and tokens for holding string-literals, integer-literals, etc.)

One of the types which inherits from SyntaxTreeBase is Unit (which represents a compilation unit, a.k.a. 1 Slice file).
But, this inheritance is useless and causes problems for us because SyntaxTreeBase holds a UnitPtr _unit;, a cyclic reference.

More importantly though is that this API is useless, and doesn't make sense for Unit to implement:

virtual void destroy();                   // Only sets `_unit = nullptr;`
UnitPtr unit() const;                     // Useless on `Unit`, it already has access to itself.
DefinitionContextPtr definitionContext() const;     // Always `nullptr` for `Unit`
virtual void visit(ParserVisitor* visitor);         // Only useful function.

We should consider either moving these useless functions down the inheritance tree, or move Unit up the tree, so that it isn't implementing these useless functions.


If that isn't possible without great effort, we should at least fix the cyclic reference issue as suggested by @pepone:
#3292 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant