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

Simplify interface for getting an instruction from a type. #3455

Merged

Conversation

zygoloid
Copy link
Contributor

@zygoloid zygoloid commented Dec 5, 2023

No description provided.

@@ -238,6 +239,30 @@ class File : public Printable<File> {
}
}

// Returns the instruction used to define the specified type.
auto GetType(TypeId type_id) const -> Inst {
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like it should be GetTypeInst, since GetType would really be types().Get. Similar thoughts on below.

Maybe these could be moved onto insts(), where you could do insts().GetType more naturally? Could that have a reference to types() without creating problems?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Last time I looked at this, referencing one ValueStore from another was problematic due to File being copyable (and actually copied in practice). But... after the recent changes for imports, we might not be copying Files any more, so maybe this is easier now.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I think the ValueStores already aren't copyable.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's also the BumpPtrAllocator

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved onto types() , rather than insts(). I think this makes the call sites read a bit better, but I could go either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Works for me too.

@@ -226,7 +226,8 @@ class File : public Printable<File> {
complete_types_.push_back(object_type_id);
}

auto GetTypeAllowBuiltinTypes(TypeId type_id) const -> InstId {
// Returns the ID of the instruction used to define the specified type.
auto GetTypeInstId(TypeId type_id) const -> InstId {
Copy link
Contributor

Choose a reason for hiding this comment

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

As long as you're touching this, maybe types().GetInstId?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jonmeow
Copy link
Contributor

jonmeow commented Dec 5, 2023

Note, I'm okay with this as-is if you want to merge, but I do lean towards moving things off File.

@zygoloid zygoloid requested a review from jonmeow December 8, 2023 01:58
toolchain/sem_ir/value_stores.h Outdated Show resolved Hide resolved
@zygoloid zygoloid added this pull request to the merge queue Dec 8, 2023
Merged via the queue into carbon-language:trunk with commit cef7eb5 Dec 8, 2023
6 checks passed
@zygoloid zygoloid deleted the toolchain-always-allow-builtin-types branch December 8, 2023 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants