Skip to content

Fix FixedPointConversion validation test #21912

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

Closed
wants to merge 2 commits into from
Closed

Fix FixedPointConversion validation test #21912

wants to merge 2 commits into from

Conversation

gwynne
Copy link
Contributor

@gwynne gwynne commented Jan 16, 2019

The FixedPointConversion validation test appears to have been completely hosted for quite some time. The following changes are made to restore it to (hopefully) intended operation:

  • Use lit.cfg's %target-ptrsize substitution instead of nesting gyb templates; this is faster, cleaner, and provides correct line-directive output.
  • Floating-point/integer comparisons in Python were using string/int comparison, which has undefined behavior in Python 2 and is flat-out illegal in 3; this prevented a large number of tests from being generated at all. Replaced with proper numeric comparisons.
  • Work around an edge case where the inability of Python to represent Int64.min exactly in floating-point due to insufficient precision resulted in the gyb logic choosing the wrong test logic, causing a spurious test failure.
  • Fix an inverted assertion in the tests where .init(exactly:) returns non-nil but was being checked for nil.
  • Respect the "round-towards-zero then check range" behavior of the truncating .init(_:) initializers; prevents incorrect test failures at the extreme ranges of large integer types.

- Use lit.cfg's %target-ptrsize instead of nested gyb template; faster, cleaner, and provides correct line-directive output.
- Fp/integer comparisons were using Python string/int comparison, undefined in Python 2 and illegal in 3, preventing large number of tests from being generated at all. Replace with actual numeric comparisons.
- Work around edge case where inability of Python to represent `Int64.min` exactly in fp (insufficient precision) caused incorrect test failure.
- Fix inverted assertion in tests for `.init(exactly:)` returning non-nil.
- Respect "round-towards-zero then check range" behavior of truncating `.init(_:)` initializers, prevents incorrect failures at extreme ranges of int types.
@gwynne gwynne requested a review from gottesmm January 16, 2019 10:25
@gwynne
Copy link
Contributor Author

gwynne commented Jan 16, 2019

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 00e374e

@gottesmm
Copy link
Contributor

@gwynne I think that @stephentyrone should take a look at this as well. Once he is cool with the changes, I am happy to look at the python part.

@gwynne
Copy link
Contributor Author

gwynne commented Jan 18, 2019

I'm working on clearing up the failure on Linux; I solved the same issue for Int64.min but it seems UInt64.max exhibits it on Linux only for some reason...

@gwynne
Copy link
Contributor Author

gwynne commented Jan 22, 2019

@swift-ci please test

@gwynne
Copy link
Contributor Author

gwynne commented Jan 22, 2019

@stephentyrone Would very much appreciate your eyes on this one; the one test failure I'm getting on Linux only pops up in the Release version of the test, works as expected in Debug:

[ RUN      ] FloatingPointToFixedPointConversionTruncations.Float80ToUInt64Conversion/dest=18446744073709551615
stdout>>> check failed at /home/gwynne/swift/swift/validation-test/stdlib/Inputs/FixedPointConversion.swift.gyb, line 130
stdout>>> expected: 18446744073709551615.0 (of type Swift.Float80)
stdout>>> actual: 18446743523953737728.0 (of type Swift.Float80)
[     FAIL ] FloatingPointToFixedPointConversionTruncations.Float80ToUInt64Conversion/dest=18446744073709551615
[ RUN      ] FloatingPointToFixedPointConversionTruncations.Float80ToUIntConversion/dest=18446744073709551615
stdout>>> check failed at /home/gwynne/swift/swift/validation-test/stdlib/Inputs/FixedPointConversion.swift.gyb, line 130
stdout>>> expected: 18446744073709551615.0 (of type Swift.Float80)
stdout>>> actual: 18446743523953737728.0 (of type Swift.Float80)
[     FAIL ] FloatingPointToFixedPointConversionTruncations.Float80ToUIntConversion/dest=18446744073709551615

There must be a reason the Float80 -> Uint[64] conversion is losing precision only in optimizing mode on Linux, but I don't know what it is 😕

@gwynne
Copy link
Contributor Author

gwynne commented Jan 22, 2019

I'm running the individual test in question via:

~/swift/swift$ ../llvm/utils/lit/lit.py -a ../build/Ninja-RelWithDebInfoAssert/swift-linux-x86_64/validation-test-linux-x86_64/ --filter='stdlib/FixedPointConversion_Release.*'

@stephentyrone
Copy link
Contributor

@gwynne Can you post the assembly generated by a swift source file containing the following compiled with your swift build and -O?

public func foo(_ x: Float80) -> UInt { return UInt(x) }

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 00e374e

@gwynne
Copy link
Contributor Author

gwynne commented Jan 23, 2019

@stephentyrone
Copy link
Contributor

@gwynne Thanks. I've been swamped the past few days, but I'll take a look this weekend.

@gwynne
Copy link
Contributor Author

gwynne commented Feb 12, 2019

@stephentyrone Ping 😅

@drodriguez
Copy link
Contributor

@gwynne: I didn’t see this fix before, and I ended up fixing part of what you fix here in #23220. It mostly deals with the floating to integer conversions. It would be good to merge both solutions. I think your solution is missing some pieces like using Decimal to not loose precision in the Python side, and doing the right tests against the float to integer bounds (which are different than the integer bounds for unsigned types).

Tell me how you want to coordinate on this.

@gwynne
Copy link
Contributor Author

gwynne commented Mar 13, 2019

@drodriguez I would suggest you integrate this PR into yours (to me the most critical change is getting rid of the unnecessary gyb nesting! 🙂) and go from there; you definitely know better how to handle the precision issues than I do.

@stephentyrone
Copy link
Contributor

@gwynne @drodriguez Ping me once you two decide how to handle the overlapping PRs and I'll review and merge them.

@CodaFi
Copy link
Contributor

CodaFi commented Nov 22, 2019

Looks like we took #23220. Closing this out. Thanks y'all!

@CodaFi CodaFi closed this Nov 22, 2019
@gwynne gwynne deleted the gwynne/fix-FixedPointConversion-tests branch April 9, 2023 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants