Skip to content

Conversation

@jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Nov 21, 2025

I was trying to figure out the right way to get specifics to be added to the work.

Technically, we could keep the pending_specific list; this is taking a different approach of inserting inside the work stack, which will do extra work moving entries, although typically that should be expected to be small. One challenge of pending_specifics is that if we would need to shift them to work after both Done (for immediate processing) and Retry (for processing after the current instruction is later revisited and done). That feels kind of awkward as additional tracking to do. Also, the common case is probably that there's either 0 or 1 specifics being added, so an additional vector may be significant overhead. That's why I leaned more in this direction of just inserting them in the vector of work.

@jonmeow jonmeow requested a review from a team as a code owner November 21, 2025 00:19
@jonmeow jonmeow requested review from chandlerc and removed request for a team November 21, 2025 00:19
Copy link
Contributor

@chandlerc chandlerc left a comment

Choose a reason for hiding this comment

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

Nice! The rationale makes lots of sense to me, suggested maybe even capturing some of that in code comments so its more visible.


auto ImportRefResolver::PushSpecific(SemIR::SpecificId import_id,
SemIR::SpecificId local_id) -> void {
// Insert before the current instruction.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe add to this comment some of the nuance from the commit message around inserting into the middle of the work stack and why it should be fine?

Mostly thinking it could be helpful if this function shows up in a profile at some point because something weird changed, or if someone worries about the insert here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On the function declaration, I have:

  // Pushes a specific onto the work stack. This will only process when the
  // current instruction is done, and does not count towards `HasNewWork`. We
  // add specifics this way because some instructions (e.g. `FacetTypeInfo`) can
  // add multiple specifics.

Are there other details you're looking for? Typically I wouldn't expect discarded alternatives to be part of the implementation description -- if somebody wanted to try the other approach and it performed better, wouldn't that be fine?

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking some of the content in the commit message... maybe something along the lines of:

Note that this will do extra work moving existing entries on the work stack, but that is expected to be OK because the common cases are 0 or 1 specifics being added. If this ends up showing up in profiles, potentially due to vector growth, it may be worth revisiting.

Still, optional, change looks good either way.


auto ImportRefResolver::PushSpecific(SemIR::SpecificId import_id,
SemIR::SpecificId local_id) -> void {
// Insert before the current instruction.
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking some of the content in the commit message... maybe something along the lines of:

Note that this will do extra work moving existing entries on the work stack, but that is expected to be OK because the common cases are 0 or 1 specifics being added. If this ends up showing up in profiles, potentially due to vector growth, it may be worth revisiting.

Still, optional, change looks good either way.

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