Open vkuncak opened 1 year ago
Probably some bug in type encoding (which triggers because the type arguments aren't bijective in Commutative[A] extends Forall[(A,A)]
). What does the crash say?
Not TypeEncoding
this time! It is the dispatching process in MethodLifting
(and unrelated to @law
).
If we were to remove PlusCommutative
, we get for the abstract apply
, after MethodLifting
:
def apply[T](thiss: Forall[T], x: T): Boolean = if (thiss.isInstanceOf[Commutative[_ >: Nothing <: Any]]) {
apply[_ >: Nothing <: Any](@DropVCs thiss.asInstanceOf[Commutative[_ >: Nothing <: Any]], {
assume(x.isInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)])
@DropVCs x.asInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)]
})
} else {
apply[T](@DropVCs thiss.asInstanceOf[ForallExt[T]], x)
}
but this fails the well-formedness check.
So the "problem" is really due to type arguments not being bijective.
If this is working as intended, the FragmentChecker
should at least reject these definitions.
Otherwise, we could imagine having a phase that could (somehow) encode/unveil existential types but this seems to be an unsoundness spring. But we could then support GADTs :)
Hmm, why does this fail the well-formedness check?
Due to a typing error, here is the message I get:
Ensuring well-formedness after phase MethodLifting...
i1397a.scala:5:9: Type error: if (thiss$6.isInstanceOf[CommutativeExt$0[_ >: Nothing <: Any]]) {
holdsFor$2[_ >: Nothing <: Any](@DropVCs thiss$6.asInstanceOf[CommutativeExt$0[_ >: Nothing <: Any]], {
assume(x$100.isInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)])
@DropVCs x$100.asInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)]
})
} else {
holdsFor$3[T$60](@DropVCs thiss$6.asInstanceOf[ForallExt$0[T$60]], x$100)
}, expected Boolean,
found <untyped>
Typing explanation:
if (thiss$6.isInstanceOf[CommutativeExt$0[_ >: Nothing <: Any]]) {
holdsFor$2[_ >: Nothing <: Any](@DropVCs thiss$6.asInstanceOf[CommutativeExt$0[_ >: Nothing <: Any]], {
assume(x$100.isInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)])
@DropVCs x$100.asInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)]
})
} else {
holdsFor$3[T$60](@DropVCs thiss$6.asInstanceOf[ForallExt$0[T$60]], x$100)
} is of type <untyped>
thiss$6.isInstanceOf[CommutativeExt$0[_ >: Nothing <: Any]] is of type Boolean
thiss$6 is of type Forall$0[T$60]
holdsFor$2[_ >: Nothing <: Any](@DropVCs thiss$6.asInstanceOf[CommutativeExt$0[_ >: Nothing <: Any]], {
assume(x$100.isInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)])
@DropVCs x$100.asInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)]
}) is of type <untyped>
@DropVCs thiss$6.asInstanceOf[CommutativeExt$0[_ >: Nothing <: Any]] is of type CommutativeExt$0[_ >: Nothing <: Any]
thiss$6.asInstanceOf[CommutativeExt$0[_ >: Nothing <: Any]] is of type CommutativeExt$0[_ >: Nothing <: Any]
thiss$6 is of type Forall$0[T$60]
assume(x$100.isInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)])
@DropVCs x$100.asInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)] is of type (_ >: Nothing <: Any, _ >: Nothing <: Any)
x$100.isInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)] is of type Boolean
x$100 is of type T$60
@DropVCs x$100.asInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)] is of type (_ >: Nothing <: Any, _ >: Nothing <: Any)
x$100.asInstanceOf[(_ >: Nothing <: Any, _ >: Nothing <: Any)] is of type (_ >: Nothing <: Any, _ >: Nothing <: Any)
x$100 is of type T$60 because holdsFor was instantiated with A$112:=_ >: Nothing <: Any with type (CommutativeExt$0[A$112],(A$112, A$112)) => Boolean
holdsFor$3[T$60](@DropVCs thiss$6.asInstanceOf[ForallExt$0[T$60]], x$100) is of type Boolean
@DropVCs thiss$6.asInstanceOf[ForallExt$0[T$60]] is of type ForallExt$0[T$60]
thiss$6.asInstanceOf[ForallExt$0[T$60]] is of type ForallExt$0[T$60]
thiss$6 is of type Forall$0[T$60]
x$100 is of type T$60 because holdsFor was instantiated with T$63:=T$60 with type (ForallExt$0[T$63],T$63) => Boolean
trait Forall[T] {
^^^^^^^^^^^...
Well-formedness check failed after phase MethodLifting
Hmm, so holdsFor
is the broken method in that snippet. Do you also have a failing well-formedness check for apply
?
We would need to see the definition of holdsFor
generated for Commutative
by the law phase to understand why the function invocation isn't being typed correctly.
The same crash occurs without @law
. For the same snippet (modulo val PlusCommutative
replaced with trait PlusCommutative
for less clutter, and with @law
removed), before MethodLifting
, we have:
i.e. everything is alright.
After MethodLifting
(with the definition of PlusCommutative
commented in order to avoid the crash occurring while transforming), we have:
so apply
would also fail the well-formedness check if it was checked first.
Are things really "broken"? To me, it seems that everything works as expected, but that such inheritance should be instead rejected?
I must be missing something.
In the above trees, I would expect the definitions of apply
and holdsFor
dispatchers to correctly type-check, no?
In the branch where the type-checking fails, we're just invoking apply
/ holdsFor
with the type parameter instantiated to _ >: Nothing <: Any
. All the arguments seem to be cast to the right type.
Oh, I thought that _ >: Nothing <: Any
means "for some T >: Nothing <: Any
" therefore we would not necessarily have the same T
every time we mention such wildcard?
No these aren't really existentials but rather "erased" types with bounds. The idea is that we can lose a bit of precision at the type level since the semantics are precisely encoded. This might lead to spurious counter-examples when invoking abstract methods but we're still far from running into this kind of problem :)
Anyway, I believe the dispatch functions should be well-formed so we have a problem in our "simple" type checking implementation.
I see! I'll dig into the implementation and check to see what's causing the issue.
Any updates, @mario-bucev ?
I will resume when I'm done with the current task :)
I'd love if we could do this:
but we get an internal crash.
On the other hand:
@law
leads to no crash (and no vcs, as expected)