Skip to content
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

Fix visibility check at definition for aspects #19442

Closed
wants to merge 1 commit into from

Conversation

fmeum
Copy link
Collaborator

@fmeum fmeum commented Sep 7, 2023

With --incompatible_visibility_private_attributes_at_definition, the visibility of aspects (and aspects on aspects) into their implicit dependencies is now checked relative to the aspect's, not the rule's definition.

This requires ensuring the precedence of aspect on aspect attributes over those of the underlying aspect in DependencyResolutionHelper, which was hinted at by a comment but not realized.

@fmeum fmeum force-pushed the aspect-check-at-definition branch 2 times, most recently from 0e2def4 to c7289ce Compare September 7, 2023 14:25
@fmeum
Copy link
Collaborator Author

fmeum commented Sep 7, 2023

@mai93 @comius was right in #19141 (comment), the aspect case of --incompatible_visibility_private_attributes_at_definition wasn't implemented correctly.

I think that visibility for an implicit attribute of an aspect should be checked relative to that aspect's definition. I have implemented this in this PR and added test cases.

The new tests uncovered the interesting edge case of which attribute wins if two aspects define attributes with the same name. In the spirit of @mai93's commit 93ad589, I would argue that the outer aspect should see its own attribute or it might risk being broken by being applied to an aspect with an attribute of an incompatible type. aspectWithExtraAttributeDependsOnNotApplicable_usesAttributeFromDependentAspect codifies the opposite behavior though.

Is flipping that behavior around something we could do? If not, could we do that for implicit attributes only? Picking up an implicit attribute from a lower aspect instead of the own one seems just wrong.

@fmeum fmeum marked this pull request as ready for review September 7, 2023 14:31
@fmeum fmeum requested a review from a team as a code owner September 7, 2023 14:31
@fmeum fmeum requested review from katre, a team and sdtwigg and removed request for a team and katre September 7, 2023 14:31
@fmeum fmeum assigned comius and mai93 Sep 7, 2023
@github-actions github-actions bot added awaiting-review PR is awaiting review from an assigned reviewer team-Configurability Issues for Configurability team labels Sep 7, 2023
@fmeum fmeum unassigned comius and mai93 Sep 7, 2023
@fmeum fmeum requested review from comius and mai93 and removed request for sdtwigg September 7, 2023 14:32
@mai93
Copy link
Contributor

mai93 commented Sep 7, 2023

Thanks @fmeum! I also think the main aspect should get its dependencies from its own attributes not from its underlying aspects. I need to run internal tests for this part to verify that there is nothing depending on the old behaviour that needs to be updated first.

@fmeum
Copy link
Collaborator Author

fmeum commented Sep 8, 2023

@mai93 Thanks for the feedback. I will separate out the change to aspect ordering.

I identified another place in which this ordering would probably need to be changed, but it doesn't seem to be covered by tests: #19449
In a previous version of that test PR, I replaced putIfAbsent with put, but all tests passed (except one that seemed unrelated). Do you happen to have an idea why this doesn't have an effect on the existing aspect order tests?

@fmeum fmeum force-pushed the aspect-check-at-definition branch 2 times, most recently from 4f9f0c6 to f5f0838 Compare September 10, 2023 09:23
@fmeum
Copy link
Collaborator Author

fmeum commented Sep 10, 2023

@mai93 I extracted the aspect-on-aspect fixes into #19449 and stacked the visibility fixes onto that PR.

@fmeum
Copy link
Collaborator Author

fmeum commented Sep 13, 2023

@mai93 I set the test blocked on #19449 to ignored as you suggested in #19449 (comment).

if (!RuleContext.isVisible(implicitDefinition, prerequisite.getConfiguredTarget())) {
handleVisibilityConflict(context, prerequisite, implicitDefinition);
}
}
}

private static boolean forStarlarkRuleOrAspect(RuleContext.Builder context) {
Aspect currentAspect = context.getMainAspect();
if (currentAspect != null && currentAspect.getAspectClass() instanceof StarlarkAspectClass) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I missed this in the first review but if the aspect is native, this needs to return False and not fallback to the rule type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good catch, fixed. Also renamed the local variable to mainAspect.

@fmeum fmeum force-pushed the aspect-check-at-definition branch 2 times, most recently from e3d7e1a to 81ee3b3 Compare September 15, 2023 06:22
@fmeum fmeum requested a review from mai93 September 15, 2023 06:22
@mai93 mai93 added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels Sep 15, 2023
// Only verify visibility of implicit dependencies of the current aspect. Implicit
// dependencies of other aspects as well as the rule itself are checked when they are
// evaluated.
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Readability: The return here breaks the encapsulation of the else block. You can't add any code after the block and assume it's correct.

Possible solution is to invert if (!mainAspect.getDefinition().getAttributes().containsKey(attrName)) {
and move the block if (!RuleContext.isVisible... inside after setting implicitDefinition.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wasn't entirely sure what you meant with "move the block ... inside". I left it outside without duplicating it, please let me know what you think.

@comius comius added awaiting-user-response Awaiting a response from the author and removed awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally labels Sep 19, 2023
With `--incompatible_visibility_private_attributes_at_definition`,
the visibility of aspects (and aspects on aspects) into their implicit
dependencies is now checked relative to the aspect's, not the rule's
definition.
@comius comius added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-user-response Awaiting a response from the author labels Sep 20, 2023
@comius
Copy link
Contributor

comius commented Sep 20, 2023

This is ready for reimport. @iancha1992

@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label Sep 21, 2023
@fmeum fmeum deleted the aspect-check-at-definition branch September 22, 2023 06:23
mai93 pushed a commit that referenced this pull request Dec 12, 2023
With `--incompatible_visibility_private_attributes_at_definition`, the visibility of aspects (and aspects on aspects) into their implicit dependencies is now checked relative to the aspect's, not the rule's definition.

This requires ensuring the precedence of aspect on aspect attributes over those of the underlying aspect in `DependencyResolutionHelper`, which was hinted at by a comment but not realized.

Closes #19442.

PiperOrigin-RevId: 567333681
Change-Id: I167c45fea8535e0f35c0298ca1cb9f845c9fe2d2
(cherry picked from commit 7a537ca)
mai93 pushed a commit that referenced this pull request Dec 12, 2023
With `--incompatible_visibility_private_attributes_at_definition`, the visibility of aspects (and aspects on aspects) into their implicit dependencies is now checked relative to the aspect's, not the rule's definition.

This requires ensuring the precedence of aspect on aspect attributes over those of the underlying aspect in `DependencyResolutionHelper`, which was hinted at by a comment but not realized.

Closes #19442.

PiperOrigin-RevId: 567333681
Change-Id: I167c45fea8535e0f35c0298ca1cb9f845c9fe2d2
(cherry picked from commit 7a537ca)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-Configurability Issues for Configurability team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants