-
Notifications
You must be signed in to change notification settings - Fork 42
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
Support Polymorphic Tags (Take 2) #239
Conversation
Yes, this approach seems to be lot better than the previous one. Though I won't say that your previous idea was totally wrong. And anyway, seems like you got a good exposure to the internals, which is a very good thing :) |
Any thoughts on how I can create a Union/OrType constructor for LightTypeTag, similar to mkRefined? // TODO: This ain't right
case orType: OrType =>
val ltts0: List[Expr[LightTypeTag]] = flattenOr(orType).map(tt => mkLtt(tt))
val ltts: Expr[List[LightTypeTag]] = Expr.ofList(ltts0)
orType.asType match {
case '[a] =>
val struct = '{ Inspect.inspect[a] }
'{ Tag.refinedTag(classOf[Any], $ltts, $struct, Map.empty)}
} |
I think you may need to add a method alike to |
You would need to construct a
Also you won't need to do argument application ( |
Something alike to this: def asUnion(args: LightTypeTag*): LightTypeTag = {
def mergedBasesDB = LightTypeTag.mergeIDBs(basesdb, args.iterator.map(_.basesdb))
def mergedInheritanceDb = LightTypeTag.mergeIDBs(idb, args.iterator.map(_.idb))
LightTypeTag(LightTypeTagRef.UnionReference(args.map(_.ref match {
case reference: AbstractReference =>
reference match {
case Lambda(input, output) => ???
case reference: AppliedReference =>
reference
}
}).toSet), mergedBasesDB, mergedInheritanceDb)
} |
And yes, in case you meet a lambda there, probably you can't do anything sane with it, you just have to throw a useful exception. |
Woo! That seemed to work :) |
Though, in testing: object Testing extends App {
trait Animal
trait Mammal extends Animal
def nestedTag[A: Tag, B: Tag] = TagMacro.tag[A | B]
val animalStringTag = nestedTag[Animal, String]
val mammalStringTag = nestedTag[Mammal, String]
implicitly[(Mammal | String) <:< (Animal | String)] // compiles! :)
println(mammalStringTag.tag <:< animalStringTag.tag) // returns false :(
} Is |
Ah, doing it with a strong type also returns false: object Testing extends App {
println(Tag[Mammal | String].tag <:< Tag[Animal | String].tag)
} So, at least I didn't break anything :D |
So far, this seems to fix all of our open ZIO issues with dotty (testing against a snapshot). Is there anything else you think I should add to this to polish/clean/test? Can also extend it further in the future once (inevitably) more issues arise. Glad I sort of understand some of what's happening now (though not the DB/subtyping/pickling parts yet) 😄 |
Yes, from what I can remember |
Nope, looks good. I'm happy to merge it as is, though it would be very nice if you may track the union subtyping problem, anyway you are somewhere around already :) |
Some sub typing works. If I change it to: val animalStringTag = nestedTag[Any, String]
val mammalStringTag = nestedTag[Mammal, String]
implicitly[(Mammal | String) <:< (Animal | String)]
println(mammalStringTag.tag <:< animalStringTag.tag) // true
println(Tag[Mammal | String].tag <:< Tag[Any | String].tag) // true |
I'll check what tests exist currently and see if I can come up with anything :) Thanks for all the help! That was fun. |
Use |
I think these tests should be copied here if possible. There's also a large test suite for TagMacro Scala 2 in A large portion of them may now pass or at least compile, whenever a test now compiles but doesn't pass, you can flip it to a progression test. ^ Actually |
case (s: UnionReference, t: UnionReference) =>
// yeah, this shit is quadratic
s.refs.exists {
c =>
t.refs.exists { // <-- this was t.refs.forall
p =>
ctx.isChild(c, p)
}
}
Wait... no no. That makes everything return true. But I'll explore. Using debug, things look correct: ⚙️ HI: {Testing$::Mammal | String}
⚡️bases:
- String ->
* CharSequence
* Serializable
* Comparable[=String]
* Object
- Comparable[=String] ->
* Matchable
* Any
* Object
- Testing$::Mammal ->
* Object
* Testing$::Animal
- Matchable ->
* Any
- Serializable ->
* Any
- Testing$::Animal ->
* Object
- Object ->
* Matchable
* Any
- CharSequence ->
* Object
⚡️inheritance:
- Testing$::Mammal ->
* Matchable
* Any
* Object
* Testing$::Animal
- String ->
* Any
* Matchable
* Serializable
* Comparable
* Object
* CharSequence
⚙️ end HI |
This is it! 🥳 case (s: UnionReference, t: UnionReference) =>
// yeah, this shit is quadratic
s.refs.forall { // <- was exists
c =>
t.refs.exists { // <- was forall
p =>
ctx.isChild(c, p)
}
} |
I'll add my tests from ZIO and these other union tests (I don't think it was tested before—as far as I could see) 🤗 |
Yes, that's seems to be correct. Sorry, my bad. Probably I just copied the logic from intersection but didn't change it properly and didn't add any tests. |
Please throw a meaningful exception there, as in other cases |
.map(_.ref match { | ||
case reference: AbstractReference => | ||
reference match { | ||
case Lambda(input, output) => ??? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to throw something readable here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yeah, did that. Copying tests from the Scala 2 tag tests to Shared (that I can) now, then I'll push :)
Addressed @pshirshov's comment, added a spec, and moved some passing tests to the shared spec (as @neko-kai suggested). I think that's all for now. Though I'm sure I'll be back :) |
5a9fb0b
to
aac6ded
Compare
aac6ded
to
40fd50f
Compare
Great job, thanks! |
Thank you both! |
@neko-kai @pshirshov Would it be possible to get another version bump (at your leisure of course)? 😄🙏 |
Here is a work in progress, if I correctly understood @neko-kai's suggestions in #238, then I think this is much closer to what is actually needed. A lot more remains to be done, but I'm going to push what I have so far, just in case you (@neko-kai & @pshirshov) have any thoughts. Thanks for all the feedback :)