-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
typRel
and sumGeneric
adjustments
#23137
Conversation
These examples do not actually translate to bugs in the current version of the compiler! This is just to demonstrate the output of the relevant functions. Ptr and Reftype A[T] = ref object
proc p(M: ref object): bool = false
proc p(M: A): bool = true
var s = new(A[int])
discard p(s) OK:
not OK:
Arraytype IntArray[N: static[int]] = array[N, int]
proc p(a: IntArray): bool= true
proc p[T;N](a: array[N,T]): bool= false
var s: IntArray[5]
discard s.p() not OK:
OK:
Same idea as above Need to devalue
|
f | a | output |
---|---|---|
tyProc(proc (): int{.closure.}) | tyProc(proc (): T{.closure.}) | isInferred |
tyGenericParam(T) | tyInt(int) | isGeneric |
f | a | output |
---|---|---|
tyProc(proc (): T{.closure.}) | tyProc(proc (): int{.closure.}) | isGeneric |
tyGenericParam(T) | tyInt(int) | isGeneric |
Both of these are okay, but one of them ultimately returns isInferred
and the other isGeneric
. In this situation the generic match should be preferred to the inferred one. Adjustment in checkGeneric
Obscured base class
type
X = ref object
Z[T] = X
proc p[H](x:Z[H]):bool = false
proc p(x: ref object): bool = true
echo p(new(Z[int]))
not OK:
f | a | output |
---|---|---|
tyRef(ref object) | tyGenericInvocation(Z[p.H]) | isNone |
OK:
f | a | output |
---|---|---|
tyGenericInvocation(Z[p.H]) | tyRef(ref object) | isNone |
tyGenericBody(Z) | tyRef(ref object) | isNone |
tyRef(Z) | tyRef(ref object) | isNone |
tyObject(X:ObjectType) | tyBuiltInTypeClass(object) | isNone |
Changing in getObjectType
:
of tyGenericInvocation:
result = getObjectType(f.baseClass)
Edit: I should also mention #22143 for organizational purposes, since that is the PR that lead to finding these
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
Filling in some more logic in `typeRel` that I came across when poking the compiler in another PR. Some of the cases where `typeRel` returns an "incorrect" result are actually common, but `sumGeneric` ends up breaking the tie correctly. There isn't anything wrong with that necessarily, but I assume that it's preferred these functions behave just as well in isolation as they do when integrated. I will be following up this description with specific examples. (cherry picked from commit ccc7c45)
Filling in some more logic in
typeRel
that I came across when poking the compiler in another PR. Some of the cases wheretypeRel
returns an "incorrect" result are actually common, butsumGeneric
ends up breaking the tie correctly. There isn't anything wrong with that necessarily, but I assume that it's preferred these functions behave just as well in isolation as they do when integrated.I will be following up this description with specific examples.