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

Add support for single file analysis #1691

Closed
wants to merge 2 commits into from

Conversation

tlakollo
Copy link
Contributor

This change allows the linker to produce warnings using the ReflectionMethodBodyScanner when the flag --single-file-analysis is used. On this first PR is only allowed to print single file warnings only if trimming is also enabled. Future PR should pursue the end goal of enabling linker analysis without trimming, so we could print single file warnings even when the app is not going to be trimmed

-Add flag for single file analysis in the linker
-Add single file dangerous patterns to the ReflectionMethodBodyScanner list
-Add test for single file dangerous patterns

Tlakollo added 2 commits December 11, 2020 16:11
-Add test for single file dangerous patterns
@tlakollo tlakollo self-assigned this Dec 12, 2020
// CodeBase ()
//
case IntrinsicId.Assembly_CodeBase when _context.SingleFileAnalysis == true:
_context.LogWarning ($"'{calledMethodDefinition.GetDisplayName ()}' always returns an empty string for assemblies embedded in a single-file app. If the path to the app directory is needed, consider calling 'System.AppContext.BaseDirectory'.", 3000, callingMethodDefinition);
Copy link
Contributor

@mateoatr mateoatr Dec 12, 2020

Choose a reason for hiding this comment

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

This actually throws, not return an empty string. I think we should add new warnings for this and other APIs (other than Assembly.Location and Assembly.GetFiles).

Copy link
Contributor

@mateoatr mateoatr Dec 12, 2020

Choose a reason for hiding this comment

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

And now that we have these warnings being produced by the linker, we should probably add them to the docs and close #1498.

@@ -106,6 +107,11 @@ public class LinkContext : IDisposable
set { _keepTypeForwarderOnlyAssemblies = value; }
}

public bool SingleFileAnalysis {
Copy link
Contributor

@mateoatr mateoatr Dec 12, 2020

Choose a reason for hiding this comment

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

nit: similar methods in LinkContext tend to be named IsSomething, maybe name this IsSingleFile?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, why expand the getter/settter.

public bool SingleFileAnalysis { get; set; }

namespace Mono.Linker.Tests.Cases.SingleFileAnalysis
{
[SetupLinkerArgument ("--single-file-analysis", "true")]
public class WarnOnSingleFileDangerousPatterns
Copy link
Contributor

Choose a reason for hiding this comment

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

If we move this tests here, can we remove them from ILLink.RoslynAnalyzer.Tests and call them in the analyzer with RunTest? Similar to what we already have for RequiresCapability tests.

@@ -246,6 +246,11 @@ enum IntrinsicId
AppDomain_CreateInstanceFrom,
AppDomain_CreateInstanceFromAndUnwrap,
Assembly_CreateInstance,
Assembly_Location,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we also add AssemblyName_CodeBase, AssemblyName_EscapedCodeBase, Module_Name, and Module_FullyQualifiedName?

@MichalStrehovsky
Copy link
Member

What's the value prop for introducing intrinsics for this vs just marking these as SingleFileUnsupported in CoreLib (dotnet/runtime#45705) and have linker understand that attribute?

I think the latter will leave us with less code to maintain and I tend to prefer that.

Copy link
Contributor

@marek-safar marek-safar left a comment

Choose a reason for hiding this comment

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

I think this is a wrong approach for several reasons

  • it forces the linker to be always used for single-file analysis
  • it hardcodes implementation which could change or evolve
  • it ignores runtime pack variations
  • it sets the wrong precedent for all other framework APIs that have a similar problem

@tlakollo
Copy link
Contributor Author

tlakollo commented Jan 9, 2021

Closing in favor of #1722

@tlakollo tlakollo closed this Jan 9, 2021
@tlakollo tlakollo deleted the SingleFileAnalysis branch February 19, 2021 02:14
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.

4 participants