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

Add a framework for typed InstIds. #4454

Closed
wants to merge 2 commits into from

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Oct 29, 2024

I'm switching Temporary::storage_id to a TemporaryStorageInstId as an example of this. Other than that, I'm not sure whether there are obvious low hanging fruit to change -- I figured starting to add the capability would be helpful towards use in future code.

Note, if you don't think this is more broadly helpful, I can abort this, but I think this is something you'd brought up so just trying to provide it while feeling a little blocked elsewhere.

Copy link
Contributor

@zygoloid zygoloid left a comment

Choose a reason for hiding this comment

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

I think this could be useful. Do you know how much this affects compile times? (It looks like it shouldn't be much to me.)

Comment on lines +127 to +129
// Subtyped InstId variants.
#define CARBON_SEM_IR_INST_KIND(Name) Name##InstId,
#include "toolchain/sem_ir/inst_kind.def"
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm concerned by this part: right now we have a few places where we're uniformly processing InstId operands of instructions by looking at the IdKind, and after this change those places will no longer visit the storage_id field on Temporary (example, example). Maybe we could map all the typed InstId kinds to IdKind::For<InstId>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PS: I was concerned that collapsing to IdKind::For<InstId> would affect the ability of NodeStack (and possibly others) to propagate a TypedInstId. This is what led the discussion below, where there's maybe not actually enough value, closing the PR.

@jonmeow
Copy link
Contributor Author

jonmeow commented Oct 31, 2024

I think this could be useful. Do you know how much this affects compile times? (It looks like it shouldn't be much to me.)

Right now it doesn't affect much. Maybe I'm a little biased due to typed node IDs and extract.cpp performance, but I think the biggest risk for compile performance is if it sees broad use in typed insts. Whereas right now that's not an issue, the number of kinds they deal with right now is small. If these start seeing broad use in signatures, I would expect that the things dealing with typed inst reflection will slow down (due to less reuse), and overall we could see a significant slowdown in compile times. However, it's possibly premature to make assumptions in that direction.

@jonmeow
Copy link
Contributor Author

jonmeow commented Oct 31, 2024

Per discussion, closing this PR. We went through current uses of As and GetAs, and it didn't look like there were enough spots where a TypedInstId could simplify things. We may look into specialized StructTypeField storage, but that wouldn't have been helped here unless we had typed InstBlockId fetching too.

@jonmeow jonmeow closed this Oct 31, 2024
@jonmeow jonmeow deleted the typed-inst-id branch October 31, 2024 17:52
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.

2 participants