-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Inferring tracked #21628
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
Inferring tracked #21628
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2ec3d68
A PoC for infering tracked with one working case
KacperFKorban 4115578
Check for parameter references in type bounds when infering tracked
KacperFKorban 9d2a245
Try potential fixes for some of the cyclic referenc errors
KacperFKorban 50d8d88
Add non-infering completers for infering tracked
KacperFKorban 07c62f2
Some condition reorder fixes related to infering tracked
KacperFKorban 0499af6
Fix some pickling errors •ᴗ•
KacperFKorban 4e6a6f4
Enable modularity by default to test infering tracked
KacperFKorban df1048f
Separate features related to tracked into a separate sub-feature
KacperFKorban 2e68fb9
Enable tracked by default to test infering tracked
KacperFKorban fca3a65
Disable tracked by default, mark accessors as tracked, when infering …
KacperFKorban abc41f6
Revert "Separate features related to tracked into a separate sub-feat…
KacperFKorban 5c08c56
Refactor checking for symbol references in signatures, when infering …
KacperFKorban 161f697
Also check type members, when infering tracked
KacperFKorban 5e295b3
Cleanup infer-tracked
KacperFKorban 0e453a1
Add a section about tracked inference to the modularity doc
KacperFKorban c027987
Add some test cases with current limitations
KacperFKorban 9231b69
Infer tracked for explicit type class witnesses
KacperFKorban 7442d5a
Don't add tracked to PrivateLocal witnesses
KacperFKorban 90d60cf
tracked inference review changes
KacperFKorban 4b6a9ad
Merge remote-tracking branch 'origin/main' into infer-tracked
KacperFKorban a96c9c5
tracked inference review changes cd.
KacperFKorban File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import scala.language.experimental.modularity | ||
|
||
trait T: | ||
type Self | ||
type X | ||
def foo: Self | ||
|
||
class D[C](using wd: C is T) | ||
class E(using we: Int is T) | ||
|
||
def Test = | ||
given w: Int is T: | ||
def foo: Int = 42 | ||
type X = Long | ||
val d = D(using w) | ||
summon[d.wd.X =:= Long] // error | ||
val e = E(using w) | ||
summon[e.we.X =:= Long] // error |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import scala.language.experimental.modularity | ||
import scala.language.future | ||
|
||
trait Ordering { | ||
type T | ||
def compare(t1:T, t2: T): Int | ||
} | ||
|
||
class SetFunctor(val ord: Ordering) { | ||
type Set = List[ord.T] | ||
def empty: Set = Nil | ||
|
||
implicit class helper(s: Set) { | ||
def add(x: ord.T): Set = x :: remove(x) | ||
def remove(x: ord.T): Set = s.filter(e => ord.compare(x, e) != 0) | ||
def member(x: ord.T): Boolean = s.exists(e => ord.compare(x, e) == 0) | ||
} | ||
} | ||
|
||
object Test { | ||
val orderInt = new Ordering { | ||
type T = Int | ||
def compare(t1: T, t2: T): Int = t1 - t2 | ||
} | ||
|
||
val IntSet = new SetFunctor(orderInt) | ||
import IntSet.* | ||
|
||
def main(args: Array[String]) = { | ||
val set = IntSet.empty.add(6).add(8).add(23) | ||
assert(!set.member(7)) | ||
assert(set.member(8)) | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import scala.language.experimental.modularity | ||
|
||
trait T: | ||
type Self | ||
type X | ||
def foo: Self | ||
|
||
class D[C](using val wd: C is T) | ||
class E(using val we: Int is T) | ||
|
||
def Test = | ||
given w: Int is T: | ||
def foo: Int = 42 | ||
type X = Long | ||
val d = D(using w) | ||
summon[d.wd.X =:= Long] | ||
val e = E(using w) | ||
summon[e.we.X =:= Long] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import scala.language.experimental.modularity | ||
import scala.language.future | ||
|
||
trait WithValue { type Value = Int } | ||
|
||
case class Year(value: Int) extends WithValue { | ||
val x: Value = 2 | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import scala.language.experimental.modularity | ||
import scala.language.future | ||
|
||
import collection.mutable | ||
|
||
/// A parser combinator. | ||
trait Combinator[T]: | ||
|
||
/// The context from which elements are being parsed, typically a stream of tokens. | ||
type Context | ||
/// The element being parsed. | ||
type Element | ||
|
||
extension (self: T) | ||
/// Parses and returns an element from `context`. | ||
def parse(context: Context): Option[Element] | ||
end Combinator | ||
|
||
final case class Apply[C, E](action: C => Option[E]) | ||
final case class Combine[A, B](first: A, second: B) | ||
|
||
object test: | ||
|
||
class apply[C, E] extends Combinator[Apply[C, E]]: | ||
type Context = C | ||
type Element = E | ||
extension(self: Apply[C, E]) | ||
def parse(context: C): Option[E] = self.action(context) | ||
|
||
def apply[C, E]: apply[C, E] = new apply[C, E] | ||
|
||
class combine[A, B]( | ||
val f: Combinator[A], | ||
val s: Combinator[B] { type Context = f.Context} | ||
) extends Combinator[Combine[A, B]]: | ||
type Context = f.Context | ||
type Element = (f.Element, s.Element) | ||
extension(self: Combine[A, B]) | ||
def parse(context: Context): Option[Element] = ??? | ||
|
||
def combine[A, B]( | ||
_f: Combinator[A], | ||
_s: Combinator[B] { type Context = _f.Context} | ||
) = new combine[A, B](_f, _s) | ||
// cast is needed since the type of new combine[A, B](_f, _s) | ||
// drops the required refinement. | ||
|
||
extension [A] (buf: mutable.ListBuffer[A]) def popFirst() = | ||
if buf.isEmpty then None | ||
else try Some(buf.head) finally buf.remove(0) | ||
|
||
@main def hello: Unit = { | ||
val source = (0 to 10).toList | ||
val stream = source.to(mutable.ListBuffer) | ||
|
||
val n = Apply[mutable.ListBuffer[Int], Int](s => s.popFirst()) | ||
val m = Combine(n, n) | ||
|
||
val c = combine( | ||
apply[mutable.ListBuffer[Int], Int], | ||
apply[mutable.ListBuffer[Int], Int] | ||
) | ||
val r = c.parse(m)(stream) // was type mismatch, now OK | ||
val rc: Option[(Int, Int)] = r | ||
} |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.