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
[SR-9876] Adding Data and FlattenSequence of Data is Trimmed #3544
Comments
Is this macOS or Linux? The only difference between those two snapshots on macOS was apple/swift#21929 which is very unlikely to be related. |
cc @phausler |
@belkadan This is macOS 10.14.4 Beta (18E184e) |
If whoever takes this wants to test my exact case that triggers this - it's while running unit tests for NIORedis The offending code is found in RESPEncoder.swift L34 Just switching between the two toolchains shows the change in output with case .array(let array):
let encodedArray = array.map(encode).joined()
return "*\(array.count)\r\n".convertedToData() + encodedArray |
swift-DEVELOPMENT-SNAPSHOT-2019-02-03-a-osx works from what I can tell.. ```swift func encodeString(_ source: String) -> Data { let raw = ["Hello", "World"].map(encodeString).joined() let prefix = "*2\r\n".convertedToData() let result = prefix + raw |
swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-06-a-osx also works |
Update the code for the line return "$\(data.count)\r\n".utf8 + data + "\r\n".utf8 so that it's return "$\(data.count)\r\n".convertedToData() + data + "\r\n".convertedToData() The original script I wrote was a mistake on my part. |
that also works on those compilers for me on both builds. |
This video shows me reproducing on macOS 10.14.4 Beta |
from what I can tell there is no correlation to the host OS of Darwin platforms as long as the toolchain is the same variant. `String(bytes: raw, encoding: .utf8)` does bridge out to objc still. |
I was able to run a 5.0.3 redis server and ran all the RESPEncoder/Decoder tests against the 5.0 2/6 development snapshot. {{ |
Please run the `BasicCommandsTests` suite, as they have real-use encoding of commands and communication with Redis. |
I am still unable to reproduce the failure: however here is an alternative code-path: var data = "*(array.count)\r\n".convertedToData() that seems a bit clearer to me and does not rely on FlattenSequence being DataProtocol (which I am not sure how that conformance is happening) |
Updating to use that process (dropping intermediate usage of FlattenSequence) does resolve the bug. However, it still concerns me that essentially the first byte of the last element of the FlattenSequence<[Data]> is getting dropped somehow when doing Data() + encodedArray |
Also updating the code to be let encodedArray = array.map(encode).reduce(into: Data(), { $0.append($1) }
return "*\(array.count)\r\n".convertedToData() + encodedArray works as well. It seems the issue is when converting FlattenSequence<[Data]> to Data with either Data() + or even Data(encodedArray) |
Comment by tanner0101 (JIRA) I'm seeing this issue as well with the following code running in Swift 5 compiler as Swift 4 mode. Changing from `joined` to `reduce` fixes serialization:
I'm using Xcode Version 10.2 beta 3 (10P99q) with 10.2 toolchain selected. |
Comment by tanner0101 (JIRA) This should be reproducible by the following:
|
As of Swift 5's official release - I have not been able to reproduce this. |
Attachment: Download
Additional Detail from JIRA
md5: 1ce37ef1fca9c9fdfb1ed62d2e206bd2
Issue Description:
Using 5.0-DEVELOPMENT-SNAPSHOT-2019-01-16-a the following code works:
See attached Swift file that reproduces the bug.
Using 5.0-DEVELOPMENT-SNAPSHOT-2019-1-17-a it no longer works.
The text was updated successfully, but these errors were encountered: