-
Notifications
You must be signed in to change notification settings - Fork 128
Add a library mode for type hierarchy marking #2114
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
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
dae7e9c
Fix special handling of EventSource
LakshanF 2bd56eb
special case EventSource handling to library mode
LakshanF 648c3b1
test fixes
LakshanF 0bdf221
Update src/linker/Linker/LinkContext.cs
LakshanF 16aef59
FB
LakshanF 785d6dd
FB
LakshanF File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
test/Mono.Linker.Tests.Cases/BCLFeatures/ETW/CustomLibraryEventSource.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System; | ||
using System.Diagnostics.Tracing; | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
|
||
namespace Mono.Linker.Tests.Cases.BCLFeatures.ETW | ||
{ | ||
[SetupLinkerArgument ("-a", "test.exe", "library")] | ||
[KeptMember (".ctor()")] | ||
public class CustomLibraryEventSource | ||
{ | ||
public static void Main () | ||
{ | ||
// Reference to a derived EventSource but does not trigger Object.GetType() | ||
var b = CustomEventSourceInLibraryMode.Log.IsEnabled (); | ||
} | ||
} | ||
|
||
[Kept] | ||
[KeptBaseType (typeof (EventSource))] | ||
[KeptAttributeAttribute (typeof (EventSourceAttribute))] | ||
[KeptMember (".ctor()")] | ||
[KeptMember (".cctor()")] | ||
|
||
[EventSource (Name = "MyLibraryCompany")] | ||
class CustomEventSourceInLibraryMode : EventSource | ||
{ | ||
// In library mode, we special case nested types | ||
[Kept] | ||
public class Keywords | ||
{ | ||
[Kept] | ||
public const EventKeywords Page = (EventKeywords) 1; | ||
|
||
public int Unused; | ||
} | ||
|
||
[Kept] | ||
public class Tasks | ||
{ | ||
[Kept] | ||
public const EventTask Page = (EventTask) 1; | ||
|
||
public int Unused; | ||
} | ||
|
||
class NotMatching | ||
{ | ||
} | ||
|
||
[Kept] | ||
public static CustomEventSourceInLibraryMode Log = new CustomEventSourceInLibraryMode (); | ||
|
||
int private_member; | ||
|
||
void PrivateMethod () { } | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
158 changes: 158 additions & 0 deletions
158
test/Mono.Linker.Tests.Cases/Reflection/ObjectGetTypeLibraryMode.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Text; | ||
using Mono.Linker.Tests.Cases.Expectations.Assertions; | ||
using Mono.Linker.Tests.Cases.Expectations.Helpers; | ||
using Mono.Linker.Tests.Cases.Expectations.Metadata; | ||
|
||
namespace Mono.Linker.Tests.Cases.Reflection | ||
{ | ||
[SetupLinkerArgument ("-a", "test.exe", "library")] | ||
[ExpectedNoWarnings] | ||
[KeptMember (".ctor()")] | ||
public class ObjectGetTypeLibraryMode | ||
{ | ||
public static void Main () | ||
{ | ||
BasicAnnotationWithNoDerivedClasses.Test (); | ||
BasicNoAnnotationWithNoDerivedClasses.Test (); | ||
} | ||
|
||
[Kept] | ||
class BasicAnnotationWithNoDerivedClasses | ||
{ | ||
[Kept] | ||
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] | ||
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] | ||
public interface IBasicAnnotatedInterface | ||
{ | ||
} | ||
|
||
[Kept] | ||
[KeptMember (".ctor()")] | ||
[KeptInterface (typeof (IBasicAnnotatedInterface))] | ||
class ClassImplementingAnnotatedInterface : IBasicAnnotatedInterface | ||
{ | ||
[Kept] | ||
public void UsedMethod () { } | ||
[Kept] // The type is not sealed, so trimmer will apply the annotation from the interface | ||
public void UnusedMethod () { } | ||
} | ||
|
||
[Kept] | ||
static void TestInterface () | ||
{ | ||
var classImplementingInterface = new ClassImplementingAnnotatedInterface (); | ||
} | ||
|
||
[Kept] | ||
[KeptMember (".ctor()")] | ||
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] | ||
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] | ||
class BasicAnnotatedClass | ||
{ | ||
[Kept] | ||
public void UsedMethod () { } | ||
[Kept] // The type is not sealed, so trimmer will apply the annotation from the interface | ||
public void UnusedMethod () { } | ||
} | ||
|
||
[Kept] | ||
static void TestClass () | ||
{ | ||
var instance = new BasicAnnotatedClass (); | ||
} | ||
|
||
[Kept] | ||
[KeptMember (".ctor()")] | ||
[KeptAttributeAttribute (typeof (DynamicallyAccessedMembersAttribute))] | ||
[DynamicallyAccessedMembers (DynamicallyAccessedMemberTypes.PublicMethods)] | ||
struct BasicAnnotatedStruct | ||
{ | ||
[Kept] | ||
public void UsedMethod () { } | ||
[Kept] | ||
public void UnusedMethod () { } | ||
} | ||
|
||
[Kept] | ||
static void TestStruct () | ||
{ | ||
var instance = new BasicAnnotatedStruct (); | ||
} | ||
|
||
[Kept] | ||
public static void Test () | ||
{ | ||
TestInterface (); | ||
TestClass (); | ||
TestStruct (); | ||
} | ||
} | ||
|
||
[Kept] | ||
class BasicNoAnnotationWithNoDerivedClasses | ||
{ | ||
[Kept] | ||
public interface IBasicNoAnnotatedInterface | ||
{ | ||
} | ||
|
||
[Kept] | ||
[KeptMember (".ctor()")] | ||
[KeptInterface (typeof (IBasicNoAnnotatedInterface))] | ||
class ClassImplementingNoAnnotatedInterface : IBasicNoAnnotatedInterface | ||
{ | ||
public void UsedMethod () { } | ||
public void UnusedMethod () { } | ||
} | ||
|
||
[Kept] | ||
static void TestInterface () | ||
{ | ||
var classImplementingInterface = new ClassImplementingNoAnnotatedInterface (); | ||
} | ||
|
||
[Kept] | ||
[KeptMember (".ctor()")] | ||
class BasicNoAnnotatedClass | ||
{ | ||
public void UsedMethod () { } | ||
public void UnusedMethod () { } | ||
} | ||
|
||
[Kept] | ||
static void TestClass () | ||
{ | ||
var instance = new BasicNoAnnotatedClass (); | ||
} | ||
|
||
[Kept] | ||
[KeptMember (".ctor()")] | ||
struct BasicNoAnnotatedStruct | ||
{ | ||
public void UsedMethod () { } | ||
public void UnusedMethod () { } | ||
} | ||
|
||
[Kept] | ||
static void TestStruct () | ||
{ | ||
var instance = new BasicNoAnnotatedStruct (); | ||
} | ||
|
||
[Kept] | ||
public static void Test () | ||
{ | ||
TestInterface (); | ||
TestClass (); | ||
TestStruct (); | ||
} | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.