This is an archive of the discontinued LLVM Phabricator instance.

Add documentation for @available
ClosedPublic

Authored by thakis on Jul 13 2017, 1:06 PM.

Details

Summary

Based on https://devstreaming-cdn.apple.com/videos/wwdc/2017/411a7o9phe4uekm/411/411_whats_new_in_llvm.pdf

(I couldn't find a way to play the corresponding video on linux, so I didn't look at that.)

Diff Detail

Event Timeline

thakis created this revision.Jul 13 2017, 1:06 PM
erik.pilkington edited edge metadata.
erik.pilkington added a subscriber: arphaman.

This looks great, thanks for working on this! LGTM, but @arphaman might have some thoughts.

docs/LanguageExtensions.rst
1290

did you mean to remove this?

1309

Don't forget the '*', ie @available(macos 10.12, *)!

thakis updated this revision to Diff 106513.Jul 13 2017, 1:35 PM
thakis marked an inline comment as done.

comments

docs/LanguageExtensions.rst
1290

I meant to move it above the "protocol-qualifier mangling of parameters" section; I think that's where it belongs. Did that.

1309

Done, thanks. What does the * do, by the way? :-)

docs/LanguageExtensions.rst
1309

Its supposed to make explicit that if the platform isn't listed in the @available, the true branch is taken and diagnostics are emitted in the then stmt using the deployment target version. The idea is that if a new platform is introduced, it would use existing APIs and it would be unfortunate if it broke everything.

Now that I think about it, this should probably be mentioned, as its probably the most counter-intuitive part of this feature. Maybe something like: "If the platform your running on isn't listed in the @available, then the the true branch of the if is taken and warnings are emitted against the current deployment target."? It might also be nice if you added another OS to this example, like @available(macOS 10.12, iOS 10, *)?

thakis updated this revision to Diff 106528.Jul 13 2017, 1:58 PM
thakis marked an inline comment as done.

Document *, add example with multiple platforms

arphaman edited edge metadata.Jul 14 2017, 12:53 AM

Thanks for doing this! I have some comments:

docs/LanguageExtensions.rst
1277

possible to use

1278

Nit: older versions of macOS or iOS

1281

...in the OS that's newer than the target OS (as determined by the minimum deployment version), ..

1286

NIT: run fine on newer systems, but crash on older systems.

1291

I would reword this sentence like this:
When a method that's introduced in the OS newer than the target OS is called, a -Wunguarded-availability warning is emitted if that call is not guarded:

1303

Nit: and to avoid the crash on macOS 10.11

1342

Nit: in C and C++ code

1347

We don't want to encourage usage of undocumented/private APIs before they are officially made public for a number of reasons. Can you please remove or rewrite this paragraph (ideally removing/replacing the specific example)?

thakis marked 7 inline comments as done.Jul 14 2017, 9:16 AM

Thanks, all done, much better!

docs/LanguageExtensions.rst
1347

I removed it from this patch, but this is something that's necessary every now and then. If there's no guidance on this, chances are people will come up with worse hacks :-) So I think having some documentation on this is a good thing. Once this is in, I'll send out a follow-up and we can iterate on this paragraph there (or decide to omit it and let each project decide on what to do here.)

thakis updated this revision to Diff 106650.Jul 14 2017, 9:17 AM
thakis marked an inline comment as done.

arphaman comments

sdy added a subscriber: sdy.Jul 14 2017, 9:21 AM
sdy added inline comments.
docs/LanguageExtensions.rst
1274

I think "Objective-C" is redundant, this is already in the ObjC section and most of the other headers don't start with "Objective-C".

1274

@available should probably be wrapped in backticks.

1278

I thought this flag was --mmacosx-version-min?
Nit: I would remove the comma after "versions".

1317

I would say "The * is required and means…"

1331

attributes ➔ attribute

1333

Maybe something like "…which will suppress the warning and require that calls to my_fun() are checked."

thakis updated this revision to Diff 106652.Jul 14 2017, 9:26 AM
thakis marked 3 inline comments as done.

sdy comments

Mostly done, thanks!

docs/LanguageExtensions.rst
1274

The one below and the two above start with "Objective-C".

1278

Nicos-MacBook-Pro:llvm-build thakis$ bin/clang -mmacosx-version-min=10.11 -c test.mm
Nicos-MacBook-Pro:llvm-build thakis$ bin/clang --mmacosx-version-min=10.11 -c test.mm
clang-3.5: error: unsupported option '--mmacosx-version-min=10.11'

Removed comma.

I went ahead and landed this in r308044, given that I addressed the nits and removed the possibly contentious bits. Happy to address remaining nits in a follow-up.

sdy added inline comments.Jul 14 2017, 11:46 AM
docs/LanguageExtensions.rst
1278

Sorry, I added an extra dash in the comment. I meant that the CL says mmacosx-version-info, not min.

thakis marked an inline comment as done.Jul 14 2017, 11:53 AM
thakis added inline comments.
docs/LanguageExtensions.rst
1278
arphaman added inline comments.Jul 17 2017, 2:56 AM
docs/LanguageExtensions.rst
1347

Ok, sure.

thakis accepted this revision.Aug 2 2022, 9:35 AM
thakis marked an inline comment as done.

landed long ago in 11cafc82b72a80fb9a7266bbda7fc7a0cc1b51a0 / 564004ae78c61a9292a15f8ed0500016b93ea74e

This revision is now accepted and ready to land.Aug 2 2022, 9:35 AM
Herald added a project: Restricted Project. · View Herald Transcript
thakis closed this revision.Aug 2 2022, 9:36 AM