Skip to content

[5.10] Cherry-pick multiple PRs to release/5.10 #2346

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 12 commits into from
Nov 29, 2023

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Nov 9, 2023

@ahoppen ahoppen changed the base branch from main to release/5.10 November 9, 2023 22:28
@ahoppen ahoppen changed the title [5.10] Cherry-pick multiple PRs to release/5.10 [5.10] Cherry-pick multiple PRs to release/5.10 🚥 #2339 Nov 9, 2023
@ahoppen
Copy link
Member Author

ahoppen commented Nov 13, 2023

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge November 13, 2023 22:32
@ahoppen ahoppen disabled auto-merge November 13, 2023 22:32
ahoppen and others added 12 commits November 13, 2023 14:33
…ansion` method

When adding a new type that conforms to `MemberMacro`, no `expansion` function is required to be implemented. It’s necessary to do it this way because:

- `expansion(of:providingMembersOf:in:)` needs to exist as a protocol requirement to keep Swift 5.9 macros that implement this method compiling
- `expansion(of:providingMembersOf:in:)` needs to be defaulted so that macros implementing `expansion(of:providingMembersOf:conformingTo:in:)` don’t need to also provide an implementation for the legacy version that doesn’t have `conformingTo:`
- `expansion(of:providingMembersOf:conformingTo:in:)` obviously needs to exist since it’s the new dedicated entry point
- `expansion(of:providingMembersOf:conformingTo:in:)` needs to have a default implementation that calls `expansion(of:providingMembersOf:in:)` so that 5.9 macros continue to work
- We can’t mark `expansion(of:providingMembersOf:in:)` as deprecated because it’s called by the default implementation of `expansion(of:providingMembersOf:conformingTo:in:)` and we want to keep swift-syntax building without warnings.

At the moment, we provide default implementations for both `expansion` functions that call each other, which causes an infinite recursion, that makes it non-obvious to see what’s going wrong.

With this change, the default implementation of the legacy `expansion(of:providingMembersOf:in:)` method throws an error saying that you need to implement either of the two expansion methods. That way you get the following behavior:
- If you don’t implement either expansion function, the error gets thrown
- If a macro implements the legacy `expansion(of:providingMembersOf:in:)` function, then it overrides the throwing version and the macro works.
- If a macro implements the new `expansion(of:providingMembersOf:conformingTo:in:)` method, then the compiler calls into that method directly and the legacy `expansion(of:providingMembersOf:in:)` never gets invoked by the compiler.

The only possible issue I can think of is if a library is calling `expansion(of:providingMembersOf:in:)` but the macro only implements `expansion(of:providingMembersOf:conformingTo:in:)`. In this case an error would get thrown where it currently isn’t. But since I don’t see any reason why anyone would be calling `expansion(of:providingMembersOf:in:)` directly, I think this is fine.
# Conflicts:
#	Package.swift
Updates LabeledExprSyntax convenience initializer to include a trailing
space trivia after the colon if an argument label is specified. This
ensures the rendered description is 'arg: value' instead of 'arg:value'.
When a user is getting the interpolation `os_log` failure message but actually supports parsing invalid source code, offer them an alternative parses the source code without checking for errors.
Otherwise consumers of SwiftSyntax may encounter warnings when compiling
with `-strict-concurrency=complete`.

For example:

```swift
extension DeclModifierListSyntax {
    var fileprivateModifierIndex: DeclModifierListSyntax.Index? {
        firstIndex(where: { $0.name.tokenKind == .keyword(.fileprivate) })
    }

    var fileprivateModifier: DeclModifierSyntax? {
        fileprivateModifierIndex.flatMap { self[$0] }
    }

    func replacing(fileprivateModifierIndex: DeclModifierListSyntax.Index) -> DeclModifierListSyntax {
        let fileprivateModifier = self[fileprivateModifierIndex]
        return with(
            \.[fileprivateModifierIndex],
            fileprivateModifier.with(
                \.name,
                .keyword(
                    .private,
                    leadingTrivia: fileprivateModifier.leadingTrivia,
                    trailingTrivia: fileprivateModifier.trailingTrivia
                )
            )
        )
    }
}
```

Produces the following warning:

> cannot form key path that captures non-sendable type
> 'DeclModifierListSyntax.Index' (aka 'SyntaxChildrenIndex')
commit 4cd9756
Author: Ruslan Alikhamov <[email protected]>
Date:   Mon Oct 23 22:17:28 2023 +0400

    applied swift-format

commit dc59e96
Author: Ruslan Alikhamov <[email protected]>
Date:   Mon Oct 23 22:02:35 2023 +0400

    removed redundant variable

commit ff95302
Author: Ruslan Alikhamov <[email protected]>
Date:   Mon Oct 23 22:00:23 2023 +0400

    refactored optimization in isValidIdentifierContinuationCodePoint

commit 5b94ec9
Author: Ruslan Alikhamov <[email protected]>
Date:   Mon Oct 23 21:51:48 2023 +0400

    fixed a typo; renamed variables

commit 7e1f23d
Author: Ruslan Alikhamov <[email protected]>
Date:   Mon Oct 23 21:38:08 2023 +0400

    renamed variables in slice(of:)

commit 3b9c1f8
Author: Ruslan Alikhamov <[email protected]>
Date:   Sat Oct 21 19:45:34 2023 +0400

    removed redundant newline

commit 83ad08c
Author: Ruslan Alikhamov <[email protected]>
Date:   Sat Oct 21 19:02:13 2023 +0400

    optimized isSlice(of other: SyntaxText) -> Bool

commit f5d0a3a
Author: Ruslan Alikhamov <[email protected]>
Date:   Sat Oct 21 19:02:03 2023 +0400

    optimized isValidIdentifierContinuationCodePoint
@ahoppen ahoppen force-pushed the ahoppen/5.10/cherry-picks branch from db08e67 to 58a574e Compare November 13, 2023 22:33
@ahoppen
Copy link
Member Author

ahoppen commented Nov 13, 2023

@swift-ci Please test

@ahoppen ahoppen enabled auto-merge November 13, 2023 22:33
@ahoppen
Copy link
Member Author

ahoppen commented Nov 13, 2023

@swift-ci Please test Windows

@ahoppen ahoppen changed the title [5.10] Cherry-pick multiple PRs to release/5.10 🚥 #2339 [5.10] Cherry-pick multiple PRs to release/5.10 Nov 13, 2023
@ahoppen
Copy link
Member Author

ahoppen commented Nov 17, 2023

swiftlang/swift#69963

@swift-ci Please test

@ahoppen
Copy link
Member Author

ahoppen commented Nov 18, 2023

swiftlang/swift#69963

@swift-ci Please test Windows

2 similar comments
@ahoppen
Copy link
Member Author

ahoppen commented Nov 23, 2023

swiftlang/swift#69963

@swift-ci Please test Windows

@kimdv
Copy link
Contributor

kimdv commented Nov 24, 2023

swiftlang/swift#69963

@swift-ci Please test Windows

@ahoppen
Copy link
Member Author

ahoppen commented Nov 28, 2023

@swift-ci Please test Windows

@ahoppen ahoppen merged commit e0c65b2 into swiftlang:release/5.10 Nov 29, 2023
@ahoppen ahoppen deleted the ahoppen/5.10/cherry-picks branch November 29, 2023 02:53
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.

8 participants