-
-
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
Make typeRel
behave to spec
#22261
Make typeRel
behave to spec
#22261
Conversation
This is mostly concerning type
A[T] = object
C = object
|
CI fail is Mac os servers shitting out again I think Overview of changes:
In
There is a case in this PR that should probably be reviewed by someone with authority on the matter. Consider: type A[T] = object
proc d(x: A):bool= false
proc d(x: int | A[SomeInteger]):bool= true
echo d(A[5]()) Currently this will print I will continue to make pushes to this PR that attempt to implement the special case to preserve the current behavior, if it is not needed then the commit preceding this comment should be rolled back to. |
No, A is a generic, not an object. |
I wasn't saying It was not a good idea for me to post this without clarifying the syntax I chose to use |
Ok, but please add some tests that show what is now possible that wasn't before. |
I added to a test that highlights the only discrepancy. The behavior may be changed in the future. I think it is beyond the spec definitions, but that is a problem for another time. |
compiler/sigmatch.nim
Outdated
if a.kind == tyObject: | ||
if sameObjectTypes(f, a): | ||
result = isEqual | ||
let effectiveArgType = if a.kind == tyAlias: a else: getObjectTypeOrNil(a) |
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.
Why does tyAlias
remain a tyAlias
?! The rest of the logic does not consider tyAlias
and aliases to object types are allowed and common.
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.
I should have taken better notes, but I believe I tracked this down to an issue with bare type variables. You are right, this is not correct. I'll draft until I fix it.
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.
To follow up on this, the reason checking for tyAlias
was done here was to "keep concepts working" as I said in one of my comments that I forgot about. When a concept is evaluating matching, particularly with the var
modifier, it is assumed that on to typeRel
: f:tyObject
, aOrig: tyTypedesc
(typedesc[var Alias]
) should return isNone
. This means that in order for this functionality to work in the current version of Nim, the condition for tyAlias
never matching with tyObject
is acceptable (assuming there is no other legal way to get that type structure). Since this doesn't really make sense, as you pointed out, I switched the logic to try and explicitly detect concept modifier matching by checking for useTypeLoweringRuleInTypeClass
instead. This is essentially the same approach as before, in that it just falls back on previous behavior for this case but it may read easier this way.
compiler/sigmatch.nim
Outdated
skipOwned(a) | ||
if a.kind == f.kind: | ||
#skipOwned(a) | ||
let effectiveArgType = getObjectTypeOrNil(a) |
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.
Neither the newly added tests nor the specification nor logic suggest that the handling of ptr
and ref
need to care about getObjectTypeOrNil
.
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.
As stated in my comment there are "alignment issues" with ptr
and ref
, but that only applied to my other PR about generic type variables. It seems evident that this is not the correct way to handle that issue anyway, so I'll just take note of this and make it a point to implement it the correct way in that PR.
Thanks for your hard work on this PR! Hint: mm: orc; opt: speed; options: -d:release |
The goal of this PR is to make `typeRel` accurate to it's definition for generics: ``` # 3) When used with two type classes, it will check whether the types # matching the first type class (aOrig) are a strict subset of the types matching # the other (f). This allows us to compare the signatures of generic procs in # order to give preferrence to the most specific one: ``` I don't want this PR to break any code, and I want to preserve all of Nims current behaviors. I think that making this more accurate will help serve as ground work for the future. It may not be possible to not break anything but this is my attempt. So that it is understood, this code was part of another PR (#22143) but that problem statement only needed this change by extension. It's more organized to split two problems into two PRs and this issue, being non-breaking, should be a more immediate improvement. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de> (cherry picked from commit b2ca6be)
The goal of this PR is to make
typeRel
accurate to it's definition for generics:I don't want this PR to break any code, and I want to preserve all of Nims current behaviors. I think that making this more accurate will help serve as ground work for the future. It may not be possible to not break anything but this is my attempt.
So that it is understood, this code was part of another PR (#22143) but that problem statement only needed this change by extension. It's more organized to split two problems into two PRs and this issue, being non-breaking, should be a more immediate improvement.