Skip to content

Introduce Maybe Capabilities #19500

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

Merged
merged 8 commits into from
Feb 2, 2024
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jan 21, 2024

Introduce maybe capabilities x? to handle the case where a capture set
appears invariantly in its surrounding type.

Maybe capabilities are similar to TypeBounds types, but
restricted to capture sets. For instance,

 Array[C^{x?}]

should be morally equivaelent to

 Array[_ >: C^{} <: C^{x}]

but it has fewer issues with type inference.

@odersky odersky changed the title Avoid forming intersections for dependent function types Introduce Maybe Capabilities Jan 23, 2024
* cannot be propagated between sets. If `a <: b` and `a` acquires `x?` then
* `x` is propagated to `b` as a conservative approximation.
*
* Maybe capabilities should only arise for caoture sets that appear in invariant

Choose a reason for hiding this comment

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

typo: "capture"

*
* Array[C^{x?}]
*
* should be morally equivaelent to

Choose a reason for hiding this comment

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

typo: "equivalent"

@odersky
Copy link
Contributor Author

odersky commented Jan 24, 2024

@dwijnand Mima rejects the changes, even though I did add the suggested problemFilter. Can you check, please?

@dwijnand
Copy link
Member

"in other version" implies (normally) forwards compat, so I think you might need to move the change to StdlibBootstrappedForward.

@odersky odersky force-pushed the add-maybe-caps branch 2 times, most recently from 947c64e to 6ee2aaa Compare January 25, 2024 13:23
@odersky
Copy link
Contributor Author

odersky commented Jan 25, 2024

@dwijnand I now added to either only to Forward or Forward and Backward, still with the same results. Can you try it out, or maybe @nicolasstucki knows something?

@odersky odersky force-pushed the add-maybe-caps branch 2 times, most recently from 474ac9e to 50597e7 Compare January 26, 2024 18:32
@odersky
Copy link
Contributor Author

odersky commented Jan 26, 2024

@dwijnand @nicolasstucki I could not make MimaFilters work. Maybe we simply cannot add any class during a point release, even though it is compiler-internal? I now avoid creating the class entirely and use a synthesized symbol instead. It's more complicated, though, so it would be good to know the answer to this question for the future:

Is there a way to add in a point release a file to the scala library that's supposed to be only used by the scala compiler?

@odersky odersky assigned Linyxus and unassigned dwijnand Jan 26, 2024
@dwijnand
Copy link
Member

I haven't been following what's been done for and around LTS. I think @nicolasstucki did it.

Avoid forming an intersection when selecting the apply method
of a dependent function type.
Introduce maybe capabilities x? to handle the case where a capture set
appears invariantly in its surrounding type.

Maybe capabilities are similar to TypeBounds types, but
restricted to capture sets. For instance,

     Array[C^{x?}]

should be morally equivaelent to

     Array[_ >: C^{} <: C^{x}]

but it has fewer issues with type inference.
Most hacks using `asInstanceOf` or `???` are no longer necessary.
It's used only during the capture checking phase, cannot appear in source
or Tasty. So it's best contained as a synthetic symbol created directly by
the compiler.
Detected manually, even though the test as a whole succeeded
Copy link
Contributor

@Linyxus Linyxus left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -422,9 +444,14 @@ object ReachCapabilityApply:
/** An extractor for `ref @annotation.internal.reachCapability`, which is used to express
Copy link
Contributor

Choose a reason for hiding this comment

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

The documentation is out-dated

@nicolasstucki
Copy link
Contributor

Is there a way to add in a point release a file to the scala library that's supposed to be only used by the scala compiler?

We do not have a way to encode that. We throw all those into runtime, which is not great. Maybe we should see if we can split the library into runtime and compile time.

@odersky
Copy link
Contributor Author

odersky commented Feb 1, 2024

There's also annotation.internal.

@odersky odersky merged commit 0011ea6 into scala:main Feb 2, 2024
@odersky odersky deleted the add-maybe-caps branch February 2, 2024 13:18
@Kordyjan Kordyjan added this to the 3.4.1 milestone Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants