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

Configurable Generic Constraints for Swift #95

Merged
merged 7 commits into from
May 10, 2023

Conversation

snowsignal
Copy link
Contributor

@snowsignal snowsignal commented Apr 11, 2023

Resolves #86.

Default type constraints can now be specified for Swift within the config, using default_generic_constraints = [...] under [swift]. Constraint strings within the list can include multiple constraints, such as Sendable & Identifiable.

Copy link
Collaborator

@CerulanLumina CerulanLumina left a comment

Choose a reason for hiding this comment

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

Looks good so far, needs further tests as mentioned.

Copy link
Collaborator

@kevinbhayes kevinbhayes left a comment

Choose a reason for hiding this comment

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

The default typeshare.toml specification worked, but if I didn't specify it there, and tried to apply it to a single type, it did nothing. For example:

#[typeshare(swift(generic_decorators = "Sendable & Codable"))]
#[derive(Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct MyMenuEntry<A> {

generated:

public struct MyMenuEntry<A: Codable>: Codable, Sendable

@snowsignal
Copy link
Contributor Author

@kevinbhayes I've been trying to fix this - it looks like parenthesized parameters like swift(...) were being ignored by the Swift codegen code, and this issue runs deeper than I expected.

@kevinbhayes
Copy link
Collaborator

@kevinbhayes I've been trying to fix this - it looks like parenthesized parameters like swift(...) were being ignored by the Swift codegen code, and this issue runs deeper than I expected.

If you want to break that part off into a separate issue, that's ok with me. I think we'll be using the toml definitions anyway.

@snowsignal
Copy link
Contributor Author

@kevinbhayes Okay, I'll split this PR.

@snowsignal snowsignal changed the title Configurable Generic Decorators for Swift Configurable Generic Constraints for Swift May 10, 2023
Copy link
Collaborator

@kevinbhayes kevinbhayes left a comment

Choose a reason for hiding this comment

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

Tested by adding Sendable to default_generic_constraints = ["Sendable"] and it produced MyStruct<A: Codable & Sendable>: Codable so all is good!

@snowsignal snowsignal merged commit fcc0619 into main May 10, 2023
6 checks passed
@snowsignal snowsignal deleted the jane/swift/type-constraints branch May 10, 2023 19:48
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.

Support specifying swift Generic Type Constraints
3 participants