Skip to content

[Sema] Require explicit availability on public modules and customizable diagnostics level #61105

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

Merged
merged 5 commits into from
Sep 15, 2022

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Sep 14, 2022

Extend the require explicit availability logic with two new features:

  • Enable the require explicit availability warnings by default for public modules. Public modules are usually inferred automatically and identified with -library-level api. rdar://99929744

  • Intro the flag -require-explicit-availability=<error,warn,ignore> to define a custom diagnostic level. The default is still a warning, and the diagnostic can be promoted to an error or ignored.

@xymus xymus requested a review from tshortli September 14, 2022 19:03
@xymus
Copy link
Contributor Author

xymus commented Sep 14, 2022

@swift-ci Please smoke test

@tshortli
Copy link
Contributor

tshortli commented Sep 14, 2022

Should we check the effect of this on the stdlib build? I expect that we will want to potentially preemptively add the "ignore" flag there since there are so many existing APIs without availability because they have always been available.

@xymus xymus force-pushed the default-require-explicit-avail branch from d4c60ef to 0ebf98c Compare September 14, 2022 22:47
@xymus xymus force-pushed the default-require-explicit-avail branch from 0ebf98c to a4f85e1 Compare September 14, 2022 23:55
@xymus xymus force-pushed the default-require-explicit-avail branch from a4f85e1 to 4bec9d5 Compare September 15, 2022 00:01
HelpText<"Require explicit availability on public declarations">;
HelpText<"Warn on public declarations without an availability attribute">;

def require_explicit_availability_EQ : Joined<["-"], "require-explicit-availability=">,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you think it would make sense to name this -require-explicit-api-availability= to help distinguish if we want to also add a similar -require-explicit-spi-availability= flag in the future?

I suppose an alternative design could be to add a -require-explicit-availability-for-spi-groups= flag that takes SPI group names that should be diagnosed at the same level as API, rather than having it be all or nothing for SPI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was considering renaming the flag to -require-availability, just to make it shorter even if a bit less descriptive.

Interesting idea for SPI, in most cases SPI doesn't require any availability so I don't think we'd need the "all SPI" version, but for specific SPI groups it could be useful and a good practice to apply. Users would have to learn to mark their features as SPI first before upgrading them to API instead of the other way around though.

@xymus
Copy link
Contributor Author

xymus commented Sep 15, 2022

Good catch @tshortli, I didn't realize the stdlib was marked -library-level api. I added the flag to ignore the diagnostics there as suggested. It showed a lot of warnings for expected code, the stdlib doesn't fit in the pattern of the typical API library-level module.

@swift-ci Please smoke test

@xymus
Copy link
Contributor Author

xymus commented Sep 15, 2022

@swift-ci Please smoke test

1 similar comment
@xymus
Copy link
Contributor Author

xymus commented Sep 15, 2022

@swift-ci Please smoke test

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.

2 participants