This is an archive of the discontinued LLVM Phabricator instance.

[clang] Add support for attribute 'swift_async_error'
ClosedPublic

Authored by erik.pilkington on Feb 5 2021, 1:22 PM.

Details

Summary

This attribute specifies how an error is represented for a swift async method. rdar://71941280

Diff Detail

Event Timeline

erik.pilkington created this revision.Feb 5 2021, 1:22 PM
erik.pilkington requested review of this revision.Feb 5 2021, 1:22 PM
aaron.ballman added inline comments.Feb 8 2021, 6:19 AM
clang/lib/Sema/SemaDeclAttr.cpp
5867

You can elide this return.

5977

Should there be a diagnostic to combine swift_error and swift_async_error on the same function? Similarly, should there be a diagnostic when adding swift_async_error to a function that isn't (eventually) marked swift_async?

erik.pilkington marked 2 inline comments as done.

Get rid of a useless return.

clang/lib/Sema/SemaDeclAttr.cpp
5977

My understanding is that swift_error and swift_async_error don't conflict with each other. swift_error describes how the non-async swift function handles errors, whereas swift_async_error describes how the swift async function handles errors. Since both swift functions are generated, I think it can make sense to have both attributes on one ObjC function.

I think it can make sense to have swift_async_error without swift_async, since the swift importer infers some functions are async without the swift_async attribute using heuristics based on parameter names. I guess we could mimic those heuristics here to diagnose when swift_async_error doesn't make sense alone, but ISTM that it makes more sense to do that check in the swift importer.

aaron.ballman accepted this revision.Feb 8 2021, 10:15 AM

LGTM modulo some testing requests. Thanks!

clang/lib/Sema/SemaDeclAttr.cpp
5977

Thanks for the information!

I think it can make sense to have both attributes on one ObjC function.

Fine by me then! Can you add a test case with a comment showing that this is explicitly expected to be okay?

I think it can make sense to have swift_async_error without swift_async

Also fine by me then! I don't think we need to go to great effort here to diagnose that (the swift importer can gain extra logic if that's useful). I think this is also worth a test case with a comment.

(In both cases, I'm thinking mostly about code archeology projects in the future to answer "did they think of" kind of questions.)

This revision is now accepted and ready to land.Feb 8 2021, 10:15 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 10 2021, 10:23 AM