Skip to content
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

Basics: extract darwinCacheDirectories from TSCUtility #6011

Merged
merged 1 commit into from Jan 4, 2023

Conversation

compnerd
Copy link
Collaborator

@compnerd compnerd commented Jan 2, 2023

This function is used solely in SPM and is the last portion of TSCUtility.Platform in use. Move the implementation into the single use site to allow us to deprecate the interface in swift-tools-support-core.

@compnerd
Copy link
Collaborator Author

compnerd commented Jan 2, 2023

@swift-ci please smoke test

compnerd added a commit to compnerd/swift-tools-support-core that referenced this pull request Jan 2, 2023
This marks the `Platform` type as deprecated.  The functionality has
been split up into swift-package-manager and sourcekit-lsp as
appropriate.  There remain no users of this at this point.

apple/sourcekit-lsp#686
apple/swift-package-manager#6011
Copy link
Member

@MaxDesiatov MaxDesiatov 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, thanks! 👍

@@ -55,6 +53,29 @@ public enum Sandbox {
// MARK: - macOS

#if os(macOS)
fileprivate let threadSafeDarwinCacheDirectories: ThreadSafeArrayStore<AbsolutePath> = {
Copy link
Member

Choose a reason for hiding this comment

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

the use of ThreadSafeArrayStore here was for caching and we loose the cache with this change. that may be okay, but then we dont need ThreadSafeArrayStore

@abertelrud wdyt about loosing the cache?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do retain the caching in some aspect - the value will be computed once and re-used rather than computed each time. The idea of replacing the ThreadSafeArrayStore<AbsolutePath> with [AbsolutePath] however still stands and would also simplify this further. I think that need to wait for @abertelrud to chime in on that.

Copy link
Contributor

@abertelrud abertelrud Jan 3, 2023

Choose a reason for hiding this comment

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

I do think it's a good idea to compute this only once (i.e. keep the cache). Based on @compnerd's comment I do see that the value gets computed only once, but it does get computed once for each Sandbox instance, so it's not cached as much as it was. It also seems that the change looses the thread safety aspect.

Couldn't it be implemented as a static, as it was before, where the contents of ThreadSafeArrayStore are what get cached? i.e. keep the property as static though no longer on an extension of TSCUtility.Platform.

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, are the initializers of Swift statics atomic already? If so, do we need ThreadSafeArrayStore at all here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@abertelrud - that is my understanding, that the initialisers are atomic, which is why I removed the locking in the first place. If that is not the case, we should restore that. As to the static bit, this is effectively so - the variable is a global variable, and thus does not need to be marked static.

Copy link
Contributor

Choose a reason for hiding this comment

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

A static property of the Sandbox type makes sense to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure that moving it into Sandbox makes it any more encapsulated, but does namespace it. I don't see the value, but I can move it nonetheless. I'll remove the now unnecessary use of ThreadSafeArrayStore.

Copy link
Contributor

@abertelrud abertelrud Jan 3, 2023

Choose a reason for hiding this comment

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

I have no strong opinion about whether it's a fileprivate global or a static inside Sandbox, so whatever @tomerd and you agree on is fine with me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually, that is even more odd - the value is used in a single free-standing function only. I'm leaving it currently as a global until @tomerd responds.

Copy link
Member

Choose a reason for hiding this comment

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

I prefer it inside Sandbox, but won't hold this back

Copy link
Member

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

we should address the usage of ThreadSafeArrayStore / loss of cache

This function is used solely in SPM and is the last portion of
`TSCUtility.Platform` in use.  Move the implementation into the single
use site to allow us to deprecate the interface in
swift-tools-support-core.
Copy link
Member

@tomerd tomerd left a comment

Choose a reason for hiding this comment

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

thanks

@tomerd
Copy link
Member

tomerd commented Jan 4, 2023

@swift-ci smoke test

@tomerd tomerd merged commit ff19f08 into apple:main Jan 4, 2023
@compnerd compnerd deleted the caches branch January 5, 2023 00:22
compnerd added a commit to apple/swift-tools-support-core that referenced this pull request Jan 30, 2023
This marks the `Platform` type as deprecated.  The functionality has
been split up into swift-package-manager and sourcekit-lsp as
appropriate.  There remain no users of this at this point.

apple/sourcekit-lsp#686
apple/swift-package-manager#6011
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.

None yet

4 participants