-
-
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
fix operators containing percent for VM usage #13536
Conversation
Somehow there is a breaking test. This is what breaks, but it also breaks on devel. But it would mean that the development branch is broken. import times
echo parse("1", "YYYY", utc()) |
just copy the one I wrote here: https://github.com/nim-lang/Nim/pull/13532/files#diff-750bc0bcbc3193d1a2854eed2d5ec5d1 |
@timotheecour Thanks for the help, but that test isn't suitable. I am circumventing to fix semfold for |
tests/concepts/t3330.nim
Outdated
@@ -17,17 +17,17 @@ proc add[T](x: var seq[T]; y: openArray[T]) | |||
first type mismatch at position: 1 | |||
required type for x: var seq[T] | |||
but expression 'k' is of type: Alias | |||
proc add(result: var string; x: float) | |||
proc add(x: var string; y: cstring) |
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.
no action needed here but I see this kind of thing break a lot (where ordering is changed), may be good to start sorting sigmatch errors in compiler by some reliable criterion (simplest would be raw string sort) to avoid having to edit tests
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.
yea it is annoying. But I don't know what the cause it. Is it that I changed some definitions that symbols get a different order when iterating them? Or is it because I introduce a bug into +%
so that hash values are calculated differently? Or did I fix +%
and hash values are calculated differently? I don't know. I am worried because I don't understand 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.
not sure about the other points raised but I'm tracking this specific issue here #13538
lib/system/comparisons.nim
Outdated
|
||
template `>=%`*(x, y: untyped): untyped = y <=% x | ||
proc `>=%`*(x, y: int): bool {.inline.} = |
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.
- instead of introducing all those overloads (previous code had a single template for
>=%
) use this:
template `>=%`*[T](x, y: T): untyped = y <=% x
- ditto with
>%
from reading your diff, seems like performance impact should only be for VM, not RT, can you confirm?
ditto with mLtU64 etc
|
This is the test that you can execute to verify that here is a problem to fix. proc testUnsignedOps() =
let a: int8 = -128
let b: int8 = 127
echo toHex(cast[uint16](b +% 1))
echo toHex(cast[uint16](b -% -1))
echo toHex(cast[uint16](b *% 2))
echo toHex(cast[uint16](a /% 4))
echo toHex(cast[uint16](a %% 7))
testUnsignedOps()
static:
testUnsignedOps() |
Test failure is unrelated. |
mInt64ToStr: ["cstrToNimstr", "cstrToNimstr"], | ||
mFloatToStr: ["cstrToNimstr", "cstrToNimstr"], | ||
mCStrToStr: ["cstrToNimstr", "cstrToNimstr"], | ||
mStrToStr: ["", ""]] |
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 had to remove the mMeU64
and mLtU64
. Since I was already at it. I converted the comments of the array into proper named array members.
e9f1913
to
1b5a28f
Compare
I'd be happier with templates instead of inline procs as inline procs are currently not inlined in debug builds. Also you seem to mix refactorings with bugfixes which makes everything harder and slower to review. |
then maybe that should be fixed instead ? IMO {.inline.} procs should inline in debug builds (ie without -d:release), but we could have an option |
I can do it if you say that is how it should be done.
I only mix in those refactoring that are structurally integrated with the bugfixes. The other refactorings are part of my other already merged PR here: #13551 But please don't expect me to like this splitting of the contribution. I only do it to do you a favor. But for me it means that the amount of time that I have to deal the slow CI the review process is doubled. And then when when one of the PRs is merged I usually get merge conflics as the bug fixes and refactorings can't be separated perfectly. So I have to deal with the CI yet another time. |
it results in much less overhead on side of contributor than splitting in PR's. |
Agreed, let's hope __always_inline (or whatever it is called) is portable enough... |
=> let's discuss this in nim-lang/RFCs#198
that's not what I'm seeing, see nim-lang/RFCs#198: cgen generates however:
|
Short explanation, in the VM signed numbers are stored with an extended sign. Unsigned numbers do not have a sign and therefore no sign extension. Applying unsigned operations on numbers with with sign extensions will have different results than without those extensions. Also unsigned ops do not apply sign extension afterwards, even though signed numbers require the sign extension. The casting operations introduced in this PR will do the sign extension removal and reintroduction for the VM accordingly. For runtime behavior, casting is a noop and should not affect performance.
fixes #13513