Linker.Steps\MarkStep.cs (156)
237public AnnotationStore Annotations => Context.Annotations;
238public MarkingHelpers MarkingHelpers => Context.MarkingHelpers;
239public Tracer Tracer => Context.Tracer;
240public EmbeddedXmlInfo EmbeddedXmlInfo => Context.EmbeddedXmlInfo;
256Context.Pipeline.InitializeMarkHandlers(Context, MarkContext);
260if (Context.TypeMapEntryAssembly is not null)
262var assemblyName = AssemblyNameReference.Parse(Context.TypeMapEntryAssembly);
263startingAssembly = Context.TryResolve(assemblyName);
268_typeMapHandler.Initialize(Context, this, startingAssembly);
278var coreLib = Context.TryResolve(PlatformAssemblies.CoreLib);
282var xmlInfo = EmbeddedXmlInfo.ProcessAttributes(coreLib, Context);
289Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes(provider, annotations);
292Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add(ca, origin);
402bool scanReferences = IsFullyPreservedAction(Context.TrimAction) || IsFullyPreservedAction(Context.DefaultAction);
408foreach (var (assemblyName, action) in Context.Actions)
413var assembly = Context.GetLoadedAssembly(assemblyName);
432var assembliesToCheck = scanReferences ? Context.GetReferencedAssemblies().ToArray() : Context.GetAssemblies();
524Context.LogMessage($"Removing typecheck of '{type.FullName}' inside '{item.Body.Method.GetDisplayName()}' method.");
571bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type);
597foreach (var assembly in Context.GetReferencedAssemblies().ToArray())
655MarkType(type, new DependencyInfo(DependencyKind.DynamicInterfaceCastableImplementation, iface.InterfaceType), new MessageOrigin(Context.TryResolve(iface.InterfaceType)));
727if (!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override))
751if (Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) && Annotations.IsInstantiated(overrideInformation.Override.DeclaringType))
758Debug.Assert(!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) || overrideInformation.Base.IsAbstract);
784=> IsInterfaceImplementationMarkedRecursively(type, interfaceType, Context);
830TypeDefinition? type = Context.Resolve(marshaler.ManagedType);
844bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;
857var resolvedAttributeType = Context.Resolve(ca.AttributeType);
918if (Context.CanApplyOptimization(CodeOptimizations.RemoveDynamicDependencyAttribute, member.DeclaringType.Module.Assembly))
937assembly = Context.TryResolve(dynamicDependency.AssemblyName);
940Context.LogWarning(origin, DiagnosticId.UnresolvedAssemblyInDynamicDependencyAttribute, dynamicDependency.AssemblyName);
953type = DocumentationSignatureParser.GetTypeByDocumentationSignature(assembly, typeName, Context);
956Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeName);
964type = Context.TryResolve(typeReference);
967Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeReference.GetDisplayName());
973type = Context.TryResolve(context.DeclaringType);
976Context.LogWarning(context, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, context.DeclaringType.GetDisplayName());
984members = DocumentationSignatureParser.GetMembersByDocumentationSignature(type, memberSignature, Context, acceptName: true);
987Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberSignature, type.GetDisplayName());
994members = type.GetDynamicallyAccessedMembers(Context, memberTypes);
997Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberTypes.ToString(), type.GetDisplayName());
1040Context.LogWarning(context, DiagnosticId.DeprecatedPreserveDependencyAttribute);
1042if (!DynamicDependency.ShouldProcess(Context, ca))
1049assembly = Context.TryResolve(assemblyName);
1052Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyAssembly, assemblyName);
1065td = Context.TryResolve(assemblyDef, typeName);
1069Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyType, typeName);
1114Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyMember, member ?? "", td.GetDisplayName());
1189TypeDefinition? type = Context.Resolve(constructor_type);
1204if (Context.KeepUsedAttributeTypesOnly)
1224TypeDefinition? type = Context.Resolve(attr_type);
1237if (type.IsBeforeFieldInit && Context.IsOptimizationEnabled(CodeOptimizations.BeforeFieldInit, type))
1300TypeDefinition? type = Context.Resolve(security_type);
1332var scanner = new AttributeDataFlow(Context, this, origin);
1346type = Context.TryResolve(type.BaseType);
1371var scanner = new AttributeDataFlow(Context, this, origin);
1385type = Context.TryResolve(type.BaseType);
1400type = Context.TryResolve(type.BaseType);
1414var resolvedConstructor = Context.TryResolve(ca.Constructor);
1417var scanner = new AttributeDataFlow(Context, this, origin);
1473EmbeddedXmlInfo.ProcessDescriptors(assembly, Context);
1479if (Context.StripSecurity)
1480RemoveSecurity.ProcessAssembly(assembly, Context);
1482MarkExportedTypesTarget.ProcessAssembly(assembly, Context);
1488!Context.TryGetCustomData("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
1618var resolved = Context.Resolve(customAttribute.Constructor);
1678var resolved = Context.Resolve(customAttribute.Constructor);
1714FieldDefinition? field = Context.Resolve(reference);
1774ReportRequiresUnreferencedCode(method.GetDisplayName(), requiresUnreferencedCode!, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1787Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName());
1824Context.LogWarning(origin, id, type.GetDisplayName(),
1834Context.LogWarning(origin, id, type.GetDisplayName(), ((MemberReference)member).GetDisplayName());
1884typeWithFields = Context.TryResolve(typeWithFields.BaseType);
1924ReportRequiresUnreferencedCode(field.GetDisplayName(), requiresUnreferencedCodeAttribute, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1935Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName());
1946AssemblyDefinition? assembly = Context.Resolve(scope);
1970if (Context.GetTargetRuntimeVersion() > TargetRuntimeVersion.NET5)
2005if (Context.Resolve(method) is MethodDefinition methodDefinition)
2013GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, methodDefinition.ReturnType);
2017GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, parameter.ParameterType);
2039if (Context.Resolve(field) is FieldDefinition fieldDefinition)
2044GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in fieldOrigin, this, Context, fieldDefinition.FieldType);
2124TypeDefinition? type = Context.Resolve(reference);
2156Context.LogWarning(origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName());
2195if ((!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6) && BCL.EventTracingForWindows.IsEventSourceImplementation(type, Context))
2307return Context.TryResolve((TypeReference)property.Argument.Value);
2312return Context.TryResolve(asm, targetTypeName);
2327var resolvedAttributeType = Context.Resolve(attrType);
2348case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing" && (!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6):
2389if (Context.KeepMembersForDebugger)
2467if (Context.TryResolve(type.BaseType) is not TypeDefinition baseType)
2477if (Context.KeepMembersForDebugger)
2497if (Context.TryResolve(proxyTypeReference) is TypeDefinition proxyType)
2597if (!Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type))
2600if (Context.Resolve(ifaceType) is not TypeDefinition resolvedInterfaceType)
2608if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
2801var tdef = Context.Resolve(iface_type);
2812} while ((type = Context.TryResolve(type.BaseType)) != null);
2823var body = Context.GetMethodIL(method);
2873Debug.Assert(Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6 || !Context.DisableEventSourceSpecialHandling);
2950return Context.TryResolve(method.ElementMethod);
2953return Context.TryResolve(type.ElementType);
2978Context.LogWarning(type, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName());
2982Context.LogWarning(type, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName());
3101foreach (var ins in Context.GetMethodIL(body).Instructions)
3147if (reference.Name == ".ctor" && Context.TryResolve(arrayType) is TypeDefinition typeDefinition)
3163MethodDefinition? method = Context.Resolve(reference);
3237return CheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(method));
3373Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnStaticConstructor, method.GetDisplayName());
3375Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnEntryPoint, method.GetDisplayName());
3399var assembly = Context.Resolve(method.DeclaringType.Scope);
3408Context.Resolve(@base) is MethodDefinition baseDefinition
3546if (Context.Resolve(ov) is not MethodDefinition resolvedOverride)
3557if (TypeReferenceEqualityComparer.AreEqual(iface.InterfaceType, interfaceToBeImplemented, Context))
3573var baseType = Context.Resolve(method.DeclaringType.BaseType);
3589if (Context.MarkedKnownMembers.NotSupportedExceptionCtorString != null)
3592var nse = BCL.FindPredefinedType(WellKnownType.System_NotSupportedException, Context);
3599Context.MarkedKnownMembers.NotSupportedExceptionCtorString = nseCtor ??
3602var objectType = BCL.FindPredefinedType(WellKnownType.System_Object, Context);
3609Context.MarkedKnownMembers.ObjectCtor = objectCtor ??
3615if (Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor != null)
3618var disablePrivateReflection = BCL.FindPredefinedType(WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, Context);
3626Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor = ctor ??
3661if (!string.IsNullOrEmpty(Context.PInvokesListFile))
3663Context.PInvokes.Add(new PInvokeInfo(
3672TypeDefinition? returnTypeDefinition = Context.TryResolve(method.ReturnType);
3699TypeDefinition? paramTypeDefinition = Context.TryResolve(paramTypeReference);
3718(new UnsafeAccessorMarker(Context, this)).ProcessUnsafeAccessorMethod(method);
3731AssemblyDefinition? assembly = Context.Resolve(method.DeclaringType.Scope);
3789var processedMethodBody = Context.GetMethodIL(body);
3791if (Context.IsOptimizationEnabled(CodeOptimizations.UnreachableBodies, body.Method) && IsUnreachableBody(processedMethodBody))
3817if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method))
3830if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, (MethodReference)instruction.Operand))
3852if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference))
3872while (Context.CompilerGeneratedState.TryGetOwningMethodForCompilerGeneratedMember(owningMethod, out var owner))
3892ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method);
3923var implementations = new InterfacesOnStackScanner(Context).GetReferencedInterfaces(methodIL);
3942=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (FieldReference)instruction.Operand),
3955=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (TypeReference)instruction.Operand),
3988ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4017ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4035if (Context.TryResolve(operand) is TypeDefinition typeDefinition)
4044if (!Context.CanApplyOptimization(CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
4047TypeDefinition? type = Context.Resolve(operand);
4084GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in origin, this, Context, iface.InterfaceType);
4110if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod(methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees))
4120requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(nestedBody), nestedOrigin);
4129requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(stateMachineBody), stateMachineOrigin);
4142var scanner = new ReflectionMethodBodyScanner(Context, this, origin);