Skip to content

Conversation

@sbomer
Copy link
Member

@sbomer sbomer commented Aug 12, 2023

When we started building with preview 7 in
5549f72, NullableAttribute in these testcases started to use the attribute definition from the framework, instead of generating it into the code. This broke the --used-attrs-only optimization because skip assemblies (the default for the framework in these testcases) are treated as if all types in them are kept, for the purposes of the --used-attrs-only optimization. (The optimization removes attribute instances unless the attribute type is preserved for some other reason).

It's not clear what the intended behavior of --used-attrs-only is for skip assemblies, and the discussion in
dotnet/linker#952 indicates that it's considered experimental, so this fixes the failures by using the link action. This represents a more realistic scenario since skip is mainly used in testing to avoid linking the framework in every testcase.

An alternative fix is to change

bool providerInLinkedAssembly = Annotations.GetAction (CustomAttributeSource.GetAssemblyFromCustomAttributeProvider (provider)) == AssemblyAction.Link;
bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;

to also set markOnUse for skip assemblies, but I think such a change would require more discussion of what skip is supposed to mean.

Fixes #90431

When we started building with preview 7 in
5549f72, NullableAttribute in
these testcases started to use the attribute definition from the
framework, instead of generating it into the code. This broke the
`--used-attrs-only` optimization because `skip` assemblies (the
default for the framework in these testcases) are treated as if
all types in them are kept, for the purposes of the
`--used-attrs-only` optimization. (The optimization removes
attribute instances unless the attribute type is preserved for
some other reason).

It's not clear what the intended behavior of `--used-attrs-only`
is for `skip` assemblies, and the discussion in
dotnet/linker#952 indicates that it's
considered experimental, so this fixes the failures by using the
`link` action. This represents a more realistic scenario since
`skip` is mainly used in testing to avoid linking the framework
in every testcase.
@sbomer sbomer requested a review from vitek-karas August 12, 2023 01:11
@sbomer sbomer requested a review from marek-safar as a code owner August 12, 2023 01:11
@ghost ghost added area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework labels Aug 12, 2023
@ghost ghost assigned sbomer Aug 12, 2023
@ghost
Copy link

ghost commented Aug 12, 2023

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas
See info in area-owners.md if you want to be subscribed.

Issue Details

When we started building with preview 7 in
5549f72, NullableAttribute in these testcases started to use the attribute definition from the framework, instead of generating it into the code. This broke the --used-attrs-only optimization because skip assemblies (the default for the framework in these testcases) are treated as if all types in them are kept, for the purposes of the --used-attrs-only optimization. (The optimization removes attribute instances unless the attribute type is preserved for some other reason).

It's not clear what the intended behavior of --used-attrs-only is for skip assemblies, and the discussion in
dotnet/linker#952 indicates that it's considered experimental, so this fixes the failures by using the link action. This represents a more realistic scenario since skip is mainly used in testing to avoid linking the framework in every testcase.

An alternative fix is to change

bool providerInLinkedAssembly = Annotations.GetAction (CustomAttributeSource.GetAssemblyFromCustomAttributeProvider (provider)) == AssemblyAction.Link;
bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;

to also set markOnUse for skip assemblies, but I think such a change would require more discussion of what skip is supposed to mean.

Fixes #90431

Author: sbomer
Assignees: -
Labels:

area-Tools-ILLink

Milestone: -

Copy link
Member

@vitek-karas vitek-karas left a comment

Choose a reason for hiding this comment

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

I agree with basically everything in the PR description - so the change looks good. Thanks!

@carlossanlop
Copy link
Contributor

This is hitting the RC1 branch. I'll backport it.

@carlossanlop
Copy link
Contributor

/backport to release/8.0-rc1

@github-actions
Copy link
Contributor

Started backporting to release/8.0-rc1: https://github.com/dotnet/runtime/actions/runs/5882378435

@carlossanlop
Copy link
Contributor

I'm not entirely sure if it's the exact same failure, but it looks very similar. @sbomer can you confirm it's the same we're seeing here? #90665

@sbomer
Copy link
Member Author

sbomer commented Aug 16, 2023

Yup, this is the same failure. Backporting should fix it.

@ghost ghost locked as resolved and limited conversation to collaborators Sep 16, 2023
@sbomer sbomer deleted the fixNullableTest branch November 3, 2023 18:39
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-Tools-ILLink .NET linker development as well as trimming analyzers linkable-framework Issues associated with delivering a linker friendly framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attributes.OnlyKeepUsed.NullableOnConstraints failing in dotnet-linker-tests

3 participants