Skip to content

[SPI] Requestify, inherit SPI groups and better diagnostics #30215

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 11 commits into from
Mar 5, 2020

Conversation

xymus
Copy link
Contributor

@xymus xymus commented Mar 4, 2020

Improve SPI support on four main points:

  • SPI related diagnostics should now correctly report SPIs as being @_spi instead of internal.
  • Requestify the service gathering SPI group names applied on a declaration.
  • A declaration inherits the SPI groups from its parent contexts unless it has its own @_spi.
  • Extend SPI tests to cover more use cases.

@xymus
Copy link
Contributor Author

xymus commented Mar 4, 2020

@swift-ci please smoke test

Copy link
Contributor

@hamishknight hamishknight left a comment

Choose a reason for hiding this comment

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

Nice!

@xymus xymus force-pushed the spi-isnt-internal branch from 8a86e42 to 2bbebcb Compare March 5, 2020 00:48
@xymus
Copy link
Contributor Author

xymus commented Mar 5, 2020

@swift-ci please smoke test

}

llvm::Expected<llvm::ArrayRef<Identifier>>
SPIGroupsRequest::evaluate(Evaluator &evaluator, const Decl *decl) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

There could be a cycle in this request. Could we diagnose that explicitly?

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'll have to look into this... Do you see a direct cycle that could be created here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not currently. My concern is when we add more recursive calls of getSPIGroups() in this function, we may end up with unexpected cycles. The request template should allow us to diagnose cycle by overriding void diagnoseCycle(DiagnosticEngine &diags)

@@ -127,9 +127,10 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
if (D->getDeclContext()->isLocalContext())
return false;

// Public declarations are OK.
// Public non-SPI declarations are OK.
Copy link
Contributor

@nkcsgexi nkcsgexi Mar 5, 2020

Choose a reason for hiding this comment

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

Do we diagnose @SPI decl inside a non-resilient type marked of @frozen? it should be disallowed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should be diagnosed. There's a test in local_spi_decls.swift but it could be extended to cover more edge cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I should be more specific here. Say when we have a frozen struct with three fields and the second field is marked as SPI. This means in the API world, the third field will be referenced as the second field in runtime even the user thinks they are referencing the third field by name. This could lead to unintended runtime behavior. I wonder whether this pattern is diagnosed in local_spi_decls.swift.

@xymus xymus merged commit 34353b8 into swiftlang:master Mar 5, 2020
@xymus xymus deleted the spi-isnt-internal branch October 31, 2022 21:02
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.

3 participants