Skip to content

Conversation

@jackkoenig
Copy link
Contributor

This is mostly used when constructing PseudoModules when looking up Instances within other Instances or Definitions. Previously, we would construct the PseudoModule then manually set the _parent field. The problem with this is that _parent is used during construction of the object and defaults to Builder.currentModule. Instead, we properly set the Builder state to hold the desired _parent and then construct the PseudoModule.

This also cleaned up tech debt in Module.do_pseudo_apply which duplicated logic from the standard Module.apply path in a way that had already gotten out of sync and likely would result in other very subtle bugs.

Fixes #5011

Contributor Checklist

  • Did you add Scaladoc to every public function/method?
  • Did you add at least one test demonstrating the PR?
  • Did you delete any extraneous printlns/debugging code?
  • Did you specify the type of improvement?
  • Did you add appropriate documentation in docs/src?
  • Did you request a desired merge strategy?
  • Did you add text to be included in the Release Notes for this change?

Type of Improvement

  • Bugfix

Desired Merge Strategy

  • Squash

Release Notes

This fixes subtle bugs where accessing children of an Instance (whether directly or by using Select APIs) could change the result of future Select to be incorrect. For example, a call to Select.unsafe.allCurrentInstancesIn could cause Select.unsafe.currentInstancesIn to also incorrectly include grandchildren and all other transitive children.

Reviewer Checklist (only modified by reviewer)

  • Did you add the appropriate labels? (Select the most appropriate one based on the "Type of Improvement")
  • Did you mark the proper milestone (Bug fix: 3.6.x, 5.x, or 6.x depending on impact, API modification or big change: 7.0)?
  • Did you review?
  • Did you check whether all relevant Contributor checkboxes have been checked?
  • Did you do one of the following when ready to merge:
    • Squash: You/ the contributor Enable auto-merge (squash) and clean up the commit message.
    • Merge: Ensure that contributor has cleaned up their commit history, then merge with Create a merge commit.

@jackkoenig jackkoenig added the Bugfix Fixes a bug, will be included in release notes label Sep 2, 2025
@jackkoenig jackkoenig force-pushed the jackkoenig/fix-instance-lookup-parent branch from 7e62798 to 5300793 Compare September 2, 2025 23:04
Copy link
Contributor

@mikeurbach mikeurbach left a comment

Choose a reason for hiding this comment

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

Nice, looks like a good solution to me. I hadn't seen Builder.State APIs yet but that looks great, glad to see it used here to simplify do_pseudo_apply.

@jackkoenig
Copy link
Contributor Author

Schuyler used it to replace the similar logic in Module.evaluate here:

val module = Builder.State.guard(Builder.State.default) {
in #4641, but I think we must've just missed that it could also apply here which should also help prevent other bugs when the Builder state changes in the future.

@jackkoenig jackkoenig enabled auto-merge (squash) September 2, 2025 23:17
@jackkoenig jackkoenig disabled auto-merge September 2, 2025 23:36
This is mostly used when constructing PseudoModules when looking up
Instances within other Instances or Definitions. Previously, we would
construct the PseudoModule then manually set the _parent field. The
problem with this is that _parent is used during construction of the
object and defaults to Builder.currentModule. Instead, we properly set
the Builder state to hold the desired _parent and then construct the
PseudoModule.

This also cleaned up tech debt in Module.do_pseudo_apply which
duplicated logic from the standard Module.apply path in a way that had
already gotten out of sync and likely would result in other very subtle
bugs.
@jackkoenig jackkoenig force-pushed the jackkoenig/fix-instance-lookup-parent branch from 5300793 to 11a9956 Compare September 3, 2025 02:16
@jackkoenig jackkoenig enabled auto-merge (squash) September 3, 2025 02:17
@jackkoenig jackkoenig merged commit 887e709 into main Sep 3, 2025
15 checks passed
@jackkoenig jackkoenig deleted the jackkoenig/fix-instance-lookup-parent branch September 3, 2025 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bugfix Fixes a bug, will be included in release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Select API's allCurrentInstancesIn affect later currentInstancesIn

3 participants