Skip to content

[Syntax] Workaround for 'cannot bypass resilience' warnings #3020

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 1 commit into from
Mar 19, 2025

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Mar 17, 2025

RawSyntaxArena and SyntaxDataaArena have properties with types from _SwiftSyntaxCShims which is @_implementationOnly when compiling with -enable-library-evolution.

But for -allow-non-resilient-access for the package cross module optimizations, they caused warnings in 6.1+ compilers:

warning: cannot bypass resilience due to member deserialization failure while attempting to access member 'mutex' of 'SyntaxDataArena' in module 'SwiftSyntax' from module 'SwiftSyntax'
warning: cannot bypass resilience due to member deserialization failure while attempting to access member 'hasParent' of 'RawSyntaxArena' in module 'SwiftSyntax' from module 'SwiftSyntax'

and non-resilient-access are disabled for these types.

To workaround that, use UnsafeRawPointer for those stored properties and use casting methods to access the actual types. Note the using computed properties were not enough to silience the warnings.

private let mutex: PlatformMutex
///
/// - Note: `UnsafeMutableRawPointer` + casting accessor is a workaround to silence the warning 'cannot bypass resilience'.
private let _mutex: UnsafeMutableRawPointer!
Copy link
Member

Choose a reason for hiding this comment

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

Why does this nave to be an IUO? Shouldn’t we be able to make this a UnsafeMutableRawPointer?

Copy link
Member Author

@rintaro rintaro Mar 17, 2025

Choose a reason for hiding this comment

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

We have platforms where it is actually nil (i.e !SWIFTSYNTAX_HAS_THREAD). I used IUO because the PlatformMutex.opaque type is UnsafeMutableRawPointer! (by default by ClangImporter)

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I see. Should we just make it a proper optional in that case?

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, I don't see any drawbacks for using optional. Done

@rintaro
Copy link
Member Author

rintaro commented Mar 17, 2025

@swift-ci Please test

`RawSyntaxArena` and `SyntaxDataaArena` have properties with types from
`_SwiftSyntaxCShims` which is `@_implementationOnly` when compiling with
'-enable-library-evolution`.

But for `-allow-non-resilient-access` for the package cross module
optimizations, they causes warnings:

```
warning: cannot bypass resilience due to member deserialization failure while attempting to access member 'mutex' of 'SyntaxDataArena' in module 'SwiftSyntax' from module 'SwiftSyntax'
warning: cannot bypass resilience due to member deserialization failure while attempting to access member 'hasParent' of 'RawSyntaxArena' in module 'SwiftSyntax' from module 'SwiftSyntax'
```

and non-resilient-access are disabled for these types.

To workaround that, use `UnsafeRawPointer` for those stored properties
and use casting methods to access the actual types.
Note the using computed properties were not enough to silience the
warnings.
@rintaro rintaro force-pushed the arena-non-resilient-access branch from 40b82e4 to 31182de Compare March 18, 2025 18:10
@rintaro
Copy link
Member Author

rintaro commented Mar 18, 2025

@swift-ci Please test

@rintaro
Copy link
Member Author

rintaro commented Mar 18, 2025

@swift-ci Please test Linux

@rintaro rintaro enabled auto-merge March 18, 2025 23:04
@rintaro
Copy link
Member Author

rintaro commented Mar 18, 2025

@swift-ci Please test Windows

@rintaro
Copy link
Member Author

rintaro commented Mar 19, 2025

@swift-ci Please test Linux

@rintaro
Copy link
Member Author

rintaro commented Mar 19, 2025

swiftlang/swift-package-manager#8386
@swift-ci Please test Linux

@rintaro rintaro merged commit d9fabf7 into swiftlang:main Mar 19, 2025
24 checks passed
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.

2 participants