Skip to content

Conversation

drodriguez
Copy link
Contributor

Xcode seems to have some code in swiftc that knows how to diagnose incorrect usages of APIs annotated with @_semantics. There is around half a dozen different @_semantics annotation in SwiftUI. The changes here deal with only swiftui.requires_constant_range.

When the ForEach struct from SwiftUI is used with a Range (which conforms to RandomAccessCollection) the compiler seems to check for some extra details of the argument which cannot be expressed in the type system, one of them that it should be a compile-time "constant".

It seems that part of the code to do so is part of the open source swift.org toolchain, but some other pieces are not. This PR implements to the best of my knowledge what I think the Xcode toolchain might be doing as close as I can.

When one builds tooling on top of the open source toolchain one can find cases in which the tooling considers some code valid, while Xcode will consider it invalid, causing confusion.

I provide this implementation in the hope that the actual Xcode implementation can be open sourced, because even if SwiftUI itself is not open source, it would be valuable that the @_semantics annotations produce the same output in the open source swift.org and the Xcode toolchains.

Xcode seems to have some code in `swiftc` that knows how to diagnose
incorrect usages of APIs annotated with `@_semantics`. There is around
half a dozen different `@_semantics` annotation in `SwiftUI`. The
changes here deal with only `swiftui.requires_constant_range`.

When the `ForEach` `struct` from `SwiftUI` is used with a `Range` (which
conforms to `RandomAccessCollection`) the compiler seems to check for
some extra details of the argument which cannot be expressed in the type
system, one of them that it should be a compile-time "constant".

It seems that part of the code to do so is part of the open source
swift.org toolchain, but some other pieces are not. This PR implements
to the best of my knowledge what I think the Xcode toolchain might be
doing as close as I can.

When one builds tooling on top of the open source toolchain one can find
cases in which the tooling considers some code valid, while Xcode will
consider it invalid, causing confusion.

I provide this implementation in the hope that the actual Xcode
implementation can be open sourced, because even if SwiftUI itself is not open
source, it would be valuable that the `@_semantics` annotations produce
the same output in the open source swift.org and the Xcode toolchains.
@drodriguez
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@drodriguez
Copy link
Contributor Author

@swift-ci please test

@drodriguez
Copy link
Contributor Author

@swift-ci please test macOS platform

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.

1 participant