Skip to content

Sema: Optimize ConstraintSystem::is{Decl,Conformance}Unavailable #35132

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 1 commit into from
Dec 17, 2020

Conversation

slavapestov
Copy link
Contributor

Let's avoid creating an ExportContext, which computes a bunch of
irrelevant stuff. Also, delay the expensive call to
overApproximateAvailabilityAtLocation() unless we know the
declaration is conditionally unavailable.

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

This is almost exactly checkDeclarationAvailability besides availability reason computation at the end and isAwaysAvailable bit (does it make sense to add it there?). Should we just add a new method checkDeclarationAvailability which doesn't require ExprContext and returns a bool?

// of the versions on which the declaration is available. If this
// containment cannot be guaranteed, we say the reference is
// not available.
if (runningOSOverApprox.isContainedIn(safeRangeUnderApprox))
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: return !runningOSOverApprox.isContainedIn(safeRangeUnderApprox);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, heh. Fixed

@slavapestov
Copy link
Contributor Author

@xedin It takes a ConstraintLocator too (notice how obtaining the source location is delayed as much as possible). Nothing else in TypeCheckAvailability.cpp deals with locators or other constraint system stuff. Are you sure it makes sense to put it there instead?

Let's avoid creating an ExportContext, which computes a bunch of
irrelevant stuff. Also, delay the expensive call to
overApproximateAvailabilityAtLocation() unless we know the
declaration is conditionally unavailable.
@slavapestov slavapestov force-pushed the optimize-is-unavailable branch from 968b242 to 486562a Compare December 17, 2020 02:34
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@xedin
Copy link
Contributor

xedin commented Dec 17, 2020

@slavapestov Getting SourceLoc from ASTNode is not an expensive operation, new method can just accept ASTNode as an argument. The main concern for me is that we'd have almost exactly the same logic in two different places.

@slavapestov slavapestov merged commit 2c5abd8 into swiftlang:main Dec 17, 2020
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