swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.37k stars 10.34k forks source link

[Compile Time Constant Extraction] Extract listed Availability Attributes for buildLimitedAvailability in Result Builders #76731

Open venkatesh5789 opened 2 days ago

venkatesh5789 commented 2 days ago

This takes a #available usage in a result builder and adds the availability information to the swiftconstvalues files.

An example usage is the following:

public struct MyFooProviderInferred: FooProvider {
    public static var foos: [Foo] {

        if #available(iOS 18.0, macOS 15.0, watchOS 11.0, tvOS 18.0, visionOS 2.0, *) {
            Foo(name: "Blah 1")
        } else {
            Foo(name: "Other Blah")
        }
    }
}

This adds the following to the existing swiftconstvalues file:

            "availabilityAttributes": [
              {
                "platform": "iOS",
                "minVersion": "18.0"
              },
              {
                "platform": "macOS",
                "minVersion": "15.0"
              },
              {
                "platform": "watchOS",
                "minVersion": "11.0"
              },
              {
                "platform": "tvOS",
                "minVersion": "18.0"
              },
              {
                "platform": "visionOS",
                "minVersion": "2.0"
              }
            ],