Skip to content
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

Backport "Context Bounds for Polymorphic Functions" to 3.6 #21972

Merged
merged 19 commits into from
Nov 19, 2024
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
59e29d8
Implement basic version of desugaring context bounds for poly functions
KacperFKorban Sep 24, 2024
d97ddd6
Handle named context bounds in poly function context bound desugaring
KacperFKorban Sep 24, 2024
34827b1
Correctly-ish desugar poly function context bounds in function types
KacperFKorban Sep 24, 2024
c8399ea
Fix pickling issue
KacperFKorban Sep 24, 2024
76455c0
Hide context bounds expansion for poly functions under modularity fea…
KacperFKorban Sep 24, 2024
7da2270
Small cleanup
KacperFKorban Sep 25, 2024
a2c6c4b
Add more test cases
KacperFKorban Sep 25, 2024
930d420
Change the implementation of context bound expansion for poly functio…
KacperFKorban Oct 2, 2024
019c6cf
Add support for some type aliases, when expanding context bounds for …
KacperFKorban Oct 3, 2024
eae738e
Make the expandion of context bounds for poly types slightly more ele…
KacperFKorban Oct 4, 2024
a679f11
Add more aliases tests for context bounds with poly functions
KacperFKorban Oct 8, 2024
341f643
Bring back the restriction for requiring value parameters in poly fun…
KacperFKorban Oct 14, 2024
8178cf4
Cleanup dead code
KacperFKorban Oct 18, 2024
38b7785
Reuse addEvidenceParams logic, but no aliases
KacperFKorban Nov 14, 2024
682691c
Cleanup context bounds for poly functions implementation, make the im…
KacperFKorban Nov 14, 2024
96e07b2
More cleanup of poly context bound desugaring
KacperFKorban Nov 14, 2024
44577f6
Short circuit adding evidence params to poly functions, when there ar…
KacperFKorban Nov 14, 2024
1de5b3e
Add a run test for poly context bounds; cleanup typer changes
KacperFKorban Nov 15, 2024
386d83d
Cleanup context bounds for poly functions implementation after review
KacperFKorban Nov 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Handle named context bounds in poly function context bound desugaring
[Cherry-picked 8dc68c3]
KacperFKorban authored and WojciechMazur committed Nov 18, 2024

Unverified

The email in this signature doesn’t match the committer email.
commit d97ddd6657b96df9861cb69222f8c4a6d382fc32
8 changes: 6 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
@@ -1230,15 +1230,19 @@ object desugar {
case td @ TypeDef(name, cb @ ContextBounds(bounds, ctxBounds)) =>
TypeDef(name, ContextBounds(bounds, List.empty))
}
var idx = -1
var idx = 0
val collecedContextBounds = tparams.collect {
case td @ TypeDef(name, cb @ ContextBounds(bounds, ctxBounds)) if ctxBounds.nonEmpty =>
// TOOD(kπ) Should we handle non empty normal bounds here?
name -> ctxBounds
}.flatMap { case (name, ctxBounds) =>
ctxBounds.map { ctxBound =>
idx = idx + 1
makeSyntheticParameter(idx, ctxBound).withAddedFlags(Given)
ctxBound match
case ContextBoundTypeTree(_, _, ownName) =>
ValDef(ownName, ctxBound, EmptyTree).withFlags(TermParam | Given)
case _ =>
makeSyntheticParameter(idx, ctxBound).withAddedFlags(Given)
}
}
val contextFunctionResult =
6 changes: 4 additions & 2 deletions tests/pos/contextbounds-for-poly-functions.scala
Original file line number Diff line number Diff line change
@@ -7,9 +7,11 @@ trait Ord[X]:

val less1 = [X: Ord] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0

val less2 = [X: Ord as ord] => (x: X, y: X) => ord.compare(x, y) < 0

// type Comparer = [X: Ord] => (x: X, y: X) => Boolean
// val less2: Comparer = [X: Ord as ord] => (x: X, y: X) => ord.compare(x, y) < 0
// val less3: Comparer = [X: Ord as ord] => (x: X, y: X) => ord.compare(x, y) < 0

// type Cmp[X] = (x: X, y: X) => Boolean
// type Comparer2 = [X: Ord] => Cmp[X]
// val less3: Comparer2 = [X: Ord] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0
// val less4: Comparer2 = [X: Ord] => (x: X, y: X) => summon[Ord[X]].compare(x, y) < 0