Adjustments to the capability trilogy#23428
Merged
Linyxus merged 8 commits intoscala:mainfrom Jun 27, 2025
Merged
Conversation
Contributor
Author
|
To be merged after #23427. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves the conversion of capabilities by turning invariant cap occurrences into Freshes and converting fresh caps of def methods with only type parameters into result caps. Key changes include:
- Converting invariants to Fresh ownership in capToFresh.
- Adapting toResultInResults to also cover def methods with type parameters.
- Refactoring internal utilities to use deep boxing (boxDeeply) and adjusting variance handling in capability mapping.
Reviewed Changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/pos-custom-args/captures/singleton-subtyping.scala | Updates to capability conversion and singleton subtyping tests. |
| tests/neg-custom-args/captures/i16725.scala | Adjusted inline error comments for wrapped IO usage. |
| compiler/src/dotty/tools/dotc/cc/Setup.scala | Replaced usages of box with boxDeeply and refined defaultApply behavior. |
| compiler/src/dotty/tools/dotc/cc/Capability.scala | Refined the variance check in capability mapping from <= to <. |
| ... | Other files show updates to test expectations and diagnostic messages. |
Comments suppressed due to low confidence (3)
tests/neg-custom-args/captures/i16725.scala:10
- The inline error comment on this line is now misleading since the expected behavior has changed; please update or remove the comment to reflect the current expected behavior.
wrapper.value: io =>
compiler/src/dotty/tools/dotc/cc/Capability.scala:696
- The change from 'if variance <= 0' to 'if variance < 0' refines the handling of invariant positions; please verify that this update aligns with the intended capability variance semantics.
if variance < 0 then t
compiler/src/dotty/tools/dotc/cc/Setup.scala:228
- Replacing 'box' with 'boxDeeply' improves the safety of nested capture conversions; double-check that this change preserves the intended behavior across all application sites.
tp.derivedAppliedType(tycon, args.mapConserve(_.boxDeeply))
odersky
requested changes
Jun 27, 2025
bracevac
approved these changes
Jun 27, 2025
It was unsound, but fixed now on main.
odersky
approved these changes
Jun 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #23421.
This PR includes the following two changes:
capToFresh, turncaps in invariant occurrences also toFreshes. Previously, in the follow code:The
capis kept intact since it is invariant. Now, it gets converted into aFreshowned byxs.2. In
toResultInResults, convert fresh caps ofdef-method with only type parameters into result caps, just like parameterless defs. Specifically, for the following code:The
^will be turned into a result cap, just like what happens for a parameterless def:The
^is a result cap that gets instantiated to a new fresh at each application ofmkRef. Doing the same thing foremptyis the arguably more desirable behavior.