Skip to content

[NCGenerics] fold InverseType into PCT #70278

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 8, 2023

Conversation

kavon
Copy link
Member

@kavon kavon commented Dec 6, 2023

We already need to track the inverses separate from the members in a
ProtocolCompositionType, since inverses aren't real types. Thus, the
only purpose being served by InverseType is to be eliminated by
RequirementLowering when it appears in a conformance requirement.

Instead, we introduce separate type InverseRequirement just to keep
track of which inverses we encounter to facilitate cancelling-out
defaults and ensuring that the inverses are respected after running
the RequirementMachine.

@kavon
Copy link
Member Author

kavon commented Dec 6, 2023

@swift-ci please smoke test

@kavon
Copy link
Member Author

kavon commented Dec 7, 2023

@swift-ci please smoke test macOS platform

@ahoppen ahoppen removed their request for review December 7, 2023 16:55
@kavon kavon force-pushed the refactor-InverseType branch from 949a7d7 to d4842f2 Compare December 8, 2023 00:40
@kavon
Copy link
Member Author

kavon commented Dec 8, 2023

@swift-ci please smoke test linux platform


// At this point, we have a conformance constraint with an inverse.
auto subject = req.getFirstType()->getCanonicalType();
// WARNING: possible quadratic behavior, but should be OK in practice.
Copy link
Contributor

Choose a reason for hiding this comment

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

This could check getDepth()

SmallVector<Type, 4> localGPs;
if (genericParamList)
for (auto *gtpd : genericParamList->getParams())
localGPs.push_back(gtpd->getDeclaredInterfaceType());
Copy link
Contributor

Choose a reason for hiding this comment

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

localGPs could be replaced with a depth check

@@ -447,8 +447,12 @@ RequirementSignatureRequest::evaluate(Evaluator &evaluator,
}
}

// FIXME: We don't have the inverses from desugaring available here!
Copy link
Contributor

Choose a reason for hiding this comment

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

StructuralRequirementsRequest could return a second list of inverses as part of the request result

diag::noncopyable_generic_but_copyable,
proto->getSelfInterfaceType(),
getProtocolName(KnownProtocolKind::Copyable));
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't this diagnosed in diagnoseRequirementErrors() along with the other cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's because the StructuralRequirementsRequest isn't carrying the InverseRequirements up to RequirementSignatureRequest. I'll try your suggestion and see if that makes this bit of code redundant.

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried it and got a verification failure in the requirement machine. Will have to dig into it later.

@kavon kavon force-pushed the refactor-InverseType branch from d4842f2 to 23533f7 Compare December 8, 2023 03:34
@kavon
Copy link
Member Author

kavon commented Dec 8, 2023

@swift-ci please test

@kavon kavon enabled auto-merge December 8, 2023 06:10
We already need to track the inverses separate from the members in a
ProtocolCompositionType, since inverses aren't real types. Thus, the
only purpose being served by InverseType is to be eliminated by
RequirementLowering when it appears in a conformance requirement.

Instead, we introduce separate type InverseRequirement just to keep
track of which inverses we encounter to facilitate cancelling-out
defaults and ensuring that the inverses are respected after running
the RequirementMachine.
@kavon kavon force-pushed the refactor-InverseType branch from 23533f7 to 63b3e76 Compare December 8, 2023 06:14
@kavon
Copy link
Member Author

kavon commented Dec 8, 2023

@swift-ci please test

@kavon kavon merged commit 338d426 into swiftlang:main Dec 8, 2023
@kavon kavon deleted the refactor-InverseType branch December 8, 2023 17:52
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