Linker.Steps\MarkStep.cs (155)
240 public AnnotationStore Annotations => Context.Annotations;
241 public MarkingHelpers MarkingHelpers => Context.MarkingHelpers;
242 public Tracer Tracer => Context.Tracer;
243 public EmbeddedXmlInfo EmbeddedXmlInfo => Context.EmbeddedXmlInfo;
260 Context.Pipeline.InitializeMarkHandlers (Context, MarkContext);
271 var coreLib = Context.TryResolve (PlatformAssemblies.CoreLib);
275 var xmlInfo = EmbeddedXmlInfo.ProcessAttributes (coreLib, Context);
282 Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes (provider, annotations);
285 Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add (ca, origin);
409 bool scanReferences = IsFullyPreservedAction (Context.TrimAction) || IsFullyPreservedAction (Context.DefaultAction);
414 foreach (var (assemblyName, action) in Context.Actions) {
418 var assembly = Context.GetLoadedAssembly (assemblyName);
436 var assembliesToCheck = scanReferences ? Context.GetReferencedAssemblies ().ToArray () : Context.GetAssemblies ();
527 Context.LogMessage ($"Removing typecheck of '{type.FullName}' inside '{item.Body.Method.GetDisplayName ()}' method.");
555 bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled (CodeOptimizations.UnusedInterfaces, type);
580 foreach (var assembly in Context.GetReferencedAssemblies ().ToArray ()) {
631 MarkType (type, new DependencyInfo (DependencyKind.DynamicInterfaceCastableImplementation, iface.InterfaceType), new MessageOrigin (Context.TryResolve (iface.InterfaceType)));
696 if (!Context.IsOptimizationEnabled (CodeOptimizations.OverrideRemoval, overrideInformation.Override))
720 if (Context.IsOptimizationEnabled (CodeOptimizations.OverrideRemoval, overrideInformation.Override) && Annotations.IsInstantiated (overrideInformation.Override.DeclaringType)) {
724 Debug.Assert (!Context.IsOptimizationEnabled (CodeOptimizations.OverrideRemoval, overrideInformation.Override) || overrideInformation.Base.IsAbstract);
752 TypeDefinition? resolvedInterface = Context.Resolve (intf.InterfaceType);
771 var resolved = Context.TryResolve (iface.InterfaceType);
800 TypeDefinition? type = Context.Resolve (marshaler.ManagedType);
812 bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;
823 var resolvedAttributeType = Context.Resolve (ca.AttributeType);
881 if (Context.CanApplyOptimization (CodeOptimizations.RemoveDynamicDependencyAttribute, member.DeclaringType.Module.Assembly)) {
896 assembly = Context.TryResolve (dynamicDependency.AssemblyName);
898 Context.LogWarning (ScopeStack.CurrentScope.Origin, DiagnosticId.UnresolvedAssemblyInDynamicDependencyAttribute, dynamicDependency.AssemblyName);
908 type = DocumentationSignatureParser.GetTypeByDocumentationSignature (assembly, typeName, Context);
910 Context.LogWarning (ScopeStack.CurrentScope.Origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeName);
916 type = Context.TryResolve (typeReference);
918 Context.LogWarning (ScopeStack.CurrentScope.Origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeReference.GetDisplayName ());
922 type = Context.TryResolve (context.DeclaringType);
924 Context.LogWarning (context, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, context.DeclaringType.GetDisplayName ());
931 members = DocumentationSignatureParser.GetMembersByDocumentationSignature (type, memberSignature, Context, acceptName: true);
933 Context.LogWarning (ScopeStack.CurrentScope.Origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberSignature, type.GetDisplayName ());
938 members = type.GetDynamicallyAccessedMembers (Context, memberTypes);
940 Context.LogWarning (ScopeStack.CurrentScope.Origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberTypes.ToString (), type.GetDisplayName ());
981 Context.LogWarning (context, DiagnosticId.DeprecatedPreserveDependencyAttribute);
983 if (!DynamicDependency.ShouldProcess (Context, ca))
989 assembly = Context.TryResolve (assemblyName);
991 Context.LogWarning (context, DiagnosticId.CouldNotResolveDependencyAssembly, assemblyName);
1001 td = Context.TryResolve (assemblyDef, typeName);
1004 Context.LogWarning (context, DiagnosticId.CouldNotResolveDependencyType, typeName);
1041 Context.LogWarning (context, DiagnosticId.CouldNotResolveDependencyMember, member ?? "", td.GetDisplayName ());
1108 TypeDefinition? type = Context.Resolve (constructor_type);
1122 if (Context.KeepUsedAttributeTypesOnly) {
1140 TypeDefinition? type = Context.Resolve (attr_type);
1153 if (type.IsBeforeFieldInit && Context.IsOptimizationEnabled (CodeOptimizations.BeforeFieldInit, type))
1214 TypeDefinition? type = Context.Resolve (security_type);
1244 var scanner = new AttributeDataFlow (Context, this, ScopeStack.CurrentScope.Origin);
1257 type = Context.TryResolve (type.BaseType);
1281 var scanner = new AttributeDataFlow (Context, this, ScopeStack.CurrentScope.Origin);
1294 type = Context.TryResolve (type.BaseType);
1308 type = Context.TryResolve (type.BaseType);
1322 var resolvedConstructor = Context.TryResolve (ca.Constructor);
1324 var scanner = new AttributeDataFlow (Context, this, ScopeStack.CurrentScope.Origin);
1377 EmbeddedXmlInfo.ProcessDescriptors (assembly, Context);
1383 if (Context.StripSecurity)
1384 RemoveSecurity.ProcessAssembly (assembly, Context);
1386 MarkExportedTypesTarget.ProcessAssembly (assembly, Context);
1391 !Context.TryGetCustomData ("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
1507 var resolved = Context.Resolve (customAttribute.Constructor);
1561 var resolved = Context.Resolve (customAttribute.Constructor);
1596 FieldDefinition? field = Context.Resolve (reference);
1642 ReportRequiresUnreferencedCode (method.GetDisplayName (), requiresUnreferencedCode!, new DiagnosticContext (origin, diagnosticsEnabled: true, Context));
1653 Context.LogWarning (origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName ());
1668 Context.LogWarning (origin, DiagnosticId.CompilerGeneratedMemberAccessedViaReflection, method.GetDisplayName ());
1702 Context.LogWarning (origin, id, type.GetDisplayName (),
1711 Context.LogWarning (origin, id, type.GetDisplayName (), ((MemberReference) member).GetDisplayName ());
1722 Context.LogWarning (origin, id, type.GetDisplayName (), method.GetDisplayName ());
1728 Context.LogWarning (origin, id, type.GetDisplayName (), field.GetDisplayName ());
1773 typeWithFields = Context.TryResolve (typeWithFields.BaseType);
1838 ReportRequiresUnreferencedCode (field.GetDisplayName (), requiresUnreferencedCodeAttribute!, new DiagnosticContext (origin, diagnosticsEnabled: true, Context));
1849 Context.LogWarning (origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName ());
1859 Context.LogWarning (origin, DiagnosticId.CompilerGeneratedMemberAccessedViaReflection, field.GetDisplayName ());
1869 AssemblyDefinition? assembly = Context.Resolve (scope);
1890 if (Context.GetTargetRuntimeVersion () > TargetRuntimeVersion.NET5)
1918 if (Context.Resolve (method) is MethodDefinition methodDefinition) {
1983 TypeDefinition? type = Context.Resolve (reference);
2010 Context.LogWarning (ScopeStack.CurrentScope.Origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName ());
2042 if (Context.TryResolve (type.BaseType) is TypeDefinition baseType &&
2050 Context.LogWarning (currentOrigin, DiagnosticId.RequiresUnreferencedCodeOnBaseClass, type.GetDisplayName (), type.BaseType.GetDisplayName (), arg1, arg2);
2065 if ((!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion () < TargetRuntimeVersion.NET6) && BCL.EventTracingForWindows.IsEventSourceImplementation (type, Context)) {
2164 return Context.TryResolve ((TypeReference) property.Argument.Value);
2170 AssemblyDefinition? assembly = Context.TryResolve (assemblyQualifiedTypeName.AssemblyName.Name);
2171 return assembly == null ? null : Context.TryResolve (assembly, targetTypeName);
2174 return Context.TryResolve (asm, targetTypeName);
2188 var resolvedAttributeType = Context.Resolve (attrType);
2207 case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing" && (!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion () < TargetRuntimeVersion.NET6):
2245 if (Context.KeepMembersForDebugger) {
2315 if (Context.TryResolve (type.BaseType) is not TypeDefinition baseType)
2325 if (Context.KeepMembersForDebugger) {
2341 if (Context.TryResolve (proxyTypeReference) is TypeDefinition proxyType) {
2438 if (!Context.IsOptimizationEnabled (CodeOptimizations.UnusedInterfaces, type))
2441 if (Context.Resolve (ifaceType) is not TypeDefinition resolvedInterfaceType)
2449 if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
2634 var tdef = Context.Resolve (iface_type);
2644 } while ((type = Context.TryResolve (type.BaseType)) != null);
2655 var body = Context.GetMethodIL (method);
2700 Debug.Assert (Context.GetTargetRuntimeVersion () < TargetRuntimeVersion.NET6 || !Context.DisableEventSourceSpecialHandling);
2777 var scanner = new GenericArgumentDataFlow (Context, this, ScopeStack.CurrentScope.Origin);
2794 return Context.TryResolve (method.ElementMethod);
2797 return Context.TryResolve (type.ElementType);
2820 Context.LogWarning (type, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName ());
2824 Context.LogWarning (type, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName ());
2943 foreach (var ins in Context.GetMethodIL (body).Instructions) {
2986 if (reference.Name == ".ctor" && Context.TryResolve (arrayType) is TypeDefinition typeDefinition) {
3000 MethodDefinition? method = Context.Resolve (reference);
3056 return CheckRequiresReflectionMethodBodyScanner (Context.GetMethodIL (method));
3197 Context.LogWarning (ScopeStack.CurrentScope.Origin, DiagnosticId.RequiresUnreferencedCodeOnStaticConstructor, method.GetDisplayName ());
3219 var assembly = Context.Resolve (method.DeclaringType.Scope);
3227 Context.Resolve (@base) is MethodDefinition baseDefinition
3349 if (Context.Resolve (ov) is not MethodDefinition resolvedOverride)
3354 var resolvedInterfaceType = Context.Resolve (ifaceImpl.InterfaceType);
3374 var baseType = Context.Resolve (method.DeclaringType.BaseType);
3390 if (Context.MarkedKnownMembers.NotSupportedExceptionCtorString != null)
3393 var nse = BCL.FindPredefinedType (WellKnownType.System_NotSupportedException, Context);
3400 Context.MarkedKnownMembers.NotSupportedExceptionCtorString = nseCtor ??
3403 var objectType = BCL.FindPredefinedType (WellKnownType.System_Object, Context);
3410 Context.MarkedKnownMembers.ObjectCtor = objectCtor ??
3416 if (Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor != null)
3419 var disablePrivateReflection = BCL.FindPredefinedType (WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, Context);
3427 Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor = ctor ??
3460 if (!string.IsNullOrEmpty (Context.PInvokesListFile)) {
3461 Context.PInvokes.Add (new PInvokeInfo (
3470 TypeDefinition? returnTypeDefinition = Context.TryResolve (method.ReturnType);
3492 TypeDefinition? paramTypeDefinition = Context.TryResolve (paramTypeReference);
3508 (new UnsafeAccessorMarker (Context, this)).ProcessUnsafeAccessorMethod (method);
3520 AssemblyDefinition? assembly = Context.Resolve (method.DeclaringType.Scope);
3577 var processedMethodBody = Context.GetMethodIL (body);
3579 if (Context.IsOptimizationEnabled (CodeOptimizations.UnreachableBodies, body.Method) && IsUnreachableBody (processedMethodBody)) {
3604 if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody (Context, methodIL.Method))
3615 if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite (Context, (MethodReference) instruction.Operand))
3633 while (Context.CompilerGeneratedState.TryGetOwningMethodForCompilerGeneratedMember (owningMethod, out var owner))
3653 ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody (Context, methodIL.Method);
3684 var implementations = new InterfacesOnStackScanner (Context).GetReferencedInterfaces (methodIL);
3700 => ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess (Context, (FieldReference) instruction.Operand),
3703 => ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess (Context, (FieldReference) instruction.Operand),
3732 ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite (Context, methodReference);
3751 if (Context.TryResolve (typeReference) is TypeDefinition type)
3765 if (Context.TryResolve (operand) is TypeDefinition typeDefinition) {
3773 if (!Context.CanApplyOptimization (CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
3776 TypeDefinition? type = Context.Resolve (operand);
3836 if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod (methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees)) {
3841 requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner (Context.GetMethodIL (nestedBody));
3846 requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner (Context.GetMethodIL (stateMachineBody));
3859 var scanner = new ReflectionMethodBodyScanner (Context, this, ScopeStack.CurrentScope.Origin);