Skip to content
New issue

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

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

Already on GitHub? # to your account

Move common entity fields to a 'base' struct. #4161

Merged
merged 4 commits into from
Jul 24, 2024

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Jul 24, 2024

I'd considered moving DeclParams uses over, but when handling qualified names, there's a parse node instead of an instruction. I did try to unify a couple other uses though, including adding MergeDefinition. I expect interface will use a little more once it's more completely implemented, but maybe I'm wrong about that.

@jonmeow jonmeow requested a review from zygoloid July 24, 2024 18:39
@jonmeow
Copy link
Contributor Author

jonmeow commented Jul 24, 2024

Per discussion, restructured from a base field to instead use multiple inheritance.

Comment on lines +38 to +40
auto PrintBaseFields(llvm::raw_ostream& out) const -> void {
out << "name: " << name_id << ", parent_scope: " << parent_scope_id;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems a bit weird to mention the "Base" in the name here. Maybe we could just call this PrintFields, shadow it in the derived class when necessary, and have Printable<T> call PrintFields if it exists:

struct EntityWithParamsBase {
  auto PrintFields(llvm::raw_ostream& out) const -> void { ... }
  // ...
}

struct Function : EntityWithParamsBase, FunctionFields, Printable<Function> {
  auto PrintFields(llvm::raw_ostream& out) const -> void {
    EntityWithParamsBase::PrintFields(out);
    out << ...function fields...
  }
};

But I'm happy to leave that to later given that this is already a large PR.

@zygoloid zygoloid added this pull request to the merge queue Jul 24, 2024
Merged via the queue into carbon-language:trunk with commit bf89652 Jul 24, 2024
7 checks passed
@jonmeow jonmeow deleted the entity-base branch July 25, 2024 16:38
brymer-meneses pushed a commit to brymer-meneses/carbon-lang that referenced this pull request Aug 15, 2024
I'd considered moving DeclParams uses over, but when handling qualified
names, there's a parse node instead of an instruction. I did try to
unify a couple other uses though, including adding MergeDefinition. I
expect `interface` will use a little more once it's more completely
implemented, but maybe I'm wrong about that.
# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants