Skip to content

refactor serialization and state management #3696

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

Merged
merged 4 commits into from
Aug 31, 2021

Conversation

tomerd
Copy link
Contributor

@tomerd tomerd commented Aug 28, 2021

motivation: stronger seperation between state managment format and data model, allowing evolution of storeage format

changes:

  • refactor PinsStore, RepositoryManager, and WorkspaceState to model their state storage seperately from the data model
  • use Codable instead of JSONMappable/JSONSerializable/SimplePersistence
  • adjust call-sites and tests where necessary

@tomerd tomerd force-pushed the refactor/serialization branch 2 times, most recently from 47fe878 to f284806 Compare August 28, 2021 08:10
@tomerd
Copy link
Contributor Author

tomerd commented Aug 28, 2021

@swift-ci please smoke test

@tomerd tomerd force-pushed the refactor/serialization branch 3 times, most recently from 3ea2e7d to 3f0a2b0 Compare August 28, 2021 18:43
@tomerd
Copy link
Contributor Author

tomerd commented Aug 28, 2021

@swift-ci please smoke test

@tomerd
Copy link
Contributor Author

tomerd commented Aug 28, 2021

11:48:44 Test Suite 'Selected tests' started at 2021-08-28 13:46:58.332
11:48:44 Test Suite 'APIDiffTests' started at 2021-08-28 13:46:58.335
11:48:44 Test Case 'APIDiffTests.testCheckVendedModulesOnly' started at 2021-08-28 13:46:58.335
11:48:44 
/home/buildnode/jenkins/workspace/swift-package-manager-self-hosted-Linux-smoke-test/branch-main/swiftpm/Tests/CommandsTests/APIDiffTests.swift:144: error: APIDiffTests.testCheckVendedModulesOnly : XCTAssertTrue failed - 
11:48:44 Test Case 'APIDiffTests.testCheckVendedModulesOnly' failed (17.161 seconds)
11:48:44 Test Suite 'APIDiffTests' failed at 2021-08-28 13:47:15.495
11:48:44 	 Executed 1 test, with 1 failure (0 unexpected) in 17.161 (17.161) seconds
11:48:44 Test Suite 'Selected tests' failed at 2021-08-28 13:47:15.495
11:48:44 	 Executed 1 test, with 1 failure (0 unexpected) in 17.161 (17.161) seconds
11:48:44 
11:48:44 Test Suite 'Selected tests' started at 2021-08-28 13:46:58.324
11:48:44 Test Suite 'APIDiffTests' started at 2021-08-28 13:46:58.326
11:48:44 Test Case 'APIDiffTests.testFilters' started at 2021-08-28 13:46:58.328
11:48:44 /home/buildnode/jenkins/workspace/swift-package-manager-self-hosted-Linux-smoke-test/branch-main/swiftpm/Tests/CommandsTests/APIDiffTests.swift:182: error: APIDiffTests.testFilters : XCTAssertTrue failed - 
11:48:44 Test Case 'APIDiffTests.testFilters' failed (22.164 seconds)
11:48:44 Test Suite 'APIDiffTests' failed at 2021-08-28 13:47:20.492
11:48:44 	 Executed 1 test, with 1 failure (0 unexpected) in 22.164 (22.164) seconds
11:48:44 Test Suite 'Selected tests' failed at 2021-08-28 13:47:20.492
11:48:44 	 Executed 1 test, with 1 failure (0 unexpected) in 22.164 (22.164) seconds

APIDiffTests seem to be failing on Linux on this PR and others - maybe the underlying API diff tool on Linux is broken / changed? does it even make sense for SwiftPM tests to test the APIDiff functionality given its only an integration shim (which we need to move to plugin!). @neonichu @abertelrud @elsh?

@tomerd tomerd added the ready Author believes the PR is ready to be merged & any feedback has been addressed label Aug 28, 2021
@tomerd tomerd self-assigned this Aug 30, 2021
tomerd added 3 commits August 30, 2021 19:53
motivation: stronger seperation between state managment format and data model, allowing evolution of storeage format

changes:
* refactor PinsStore, RepositoryManager, and WorkspaceState to model their state storage seperately from the data model
* use Codable instead of JSONMappable/JSONSerializable/SimplePersistence
* adjust call-sites and tests where necessary
@tomerd tomerd force-pushed the refactor/serialization branch from 3f0a2b0 to c0b9d80 Compare August 31, 2021 03:07
@tomerd
Copy link
Contributor Author

tomerd commented Aug 31, 2021

@swift-ci please smoke test

@tomerd
Copy link
Contributor Author

tomerd commented Aug 31, 2021

@swift-ci please smoke test

Comment on lines +108 to +109
private let encoder = JSONEncoder.makeWithDefaults()
private let decoder = JSONDecoder.makeWithDefaults()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any particular advantage to keeping these around? (e.g. performance) Is there any concern about unintentional leaking of state from one encode/decode to the next?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

memory and performance. I dont think they hold any state.

// FIXME: We should emit a warning here using the diagnostic engine.
TSCBasic.stderrStream.write("\(error)\n")
TSCBasic.stderrStream.write("warning: unable to restore workspace state: \(error)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is existing code, so doesn't need to be changed in this PR, but should a future PR change this to use a Diagnostics collector since I assume this could be emitted from an IDE as well (as it's part of libSwiftPM)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issue is that Workspace does not have a DiagnosticsEngine to use in this case. I was planning to address this in one of the next refactoring PRs, focused on making Diagnostics more globally available

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yah, we have at least one more such case that we can clean up once we make diagnostics more broadly available.

Copy link
Contributor

@abertelrud abertelrud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great cleanup!

@tomerd tomerd merged commit 6f8a435 into swiftlang:main Aug 31, 2021
fileprivate struct DestinationInfo: Codable {
let target: String?
let sdk: AbsolutePath?
let binDir: AbsolutePath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed that this small change from this much larger pull changes the format for destination JSON files, rather than what's documented here and here.

@tomerd, should I update the docs and example for the new format or should we stick with the old format? I'll submit a pull for either way you want to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@buttaface great catch, would appreciate such help

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, I think we can also consider the reverse it the old name is more correct - ie we could also rename / change the decoding to accept the old name, as the rename was more cleanup code wise

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iow the goal here was not to change the format / names, but an internal cleanup of the decoding to use Codable, the name change was an oversight, so happy to change back to the name if preferable

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

def this is missing a test tho :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I will change it back and add a test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Submitted two fixes in #3793, will submit the test later.

finagolfin added a commit to finagolfin/swift-package-manager that referenced this pull request Oct 6, 2021
Motivation: The larger refactoring changed the destination JSON format and
introduced a bug in passing flags.

Changes: Use a CodingKeys enum to go back to the old format and correct the flag
error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready Author believes the PR is ready to be merged & any feedback has been addressed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants