Fix a mutation-during-iteration bug in package object loading #11064
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
The
deferredOpenmechanism was added in the 2.13.x series to avoid prematurely loading apackage.classprior to finding that the current sources contain the source of this that package object. #9661This mechanism was refined to support a use case with
-Yimports(custom predef imports). (#10333)The original change to
packageObjectsappears to have have incorrectly put the "load whatever is is left indeferredOpenlogic inapply(per unit logic) rather thanrun(per-phase logic). I've moved it.We then need to take a defensive copy of the collection before iteration asn
openPackageModulecan trigger typechecking of package object template parents, which now mutatesdeferredOpen. The behaviour is undefined in this case.I've also switched the backing collection to a
j.u.LinkedHashSetwhich fails fast when if we mutate during iteration. The enclosed test fails before the final commit make it green. I figured that using aLinkedcollection would make the compilation order deterministic between runs which might help diagnose any remnant bugs in this area.