Linker.Steps\MarkStep.cs (158)
240public AnnotationStore Annotations => Context.Annotations;
241public MarkingHelpers MarkingHelpers => Context.MarkingHelpers;
242public Tracer Tracer => Context.Tracer;
243public EmbeddedXmlInfo EmbeddedXmlInfo => Context.EmbeddedXmlInfo;
259Context.Pipeline.InitializeMarkHandlers(Context, MarkContext);
263if (Context.TypeMapEntryAssembly is not null)
265var assemblyName = LinkContext.TryParseAssemblyName(Context.TypeMapEntryAssembly);
266startingAssembly = assemblyName is null ? null : Context.TryResolve(assemblyName);
271_typeMapHandler.Initialize(Context, this, startingAssembly);
281var coreLib = Context.TryResolve(PlatformAssemblies.CoreLib);
285var xmlInfo = EmbeddedXmlInfo.ProcessAttributes(coreLib, Context);
292Context.CustomAttributes.PrimaryAttributeInfo.AddCustomAttributes(provider, annotations);
295Context.CustomAttributes.PrimaryAttributeInfo.CustomAttributesOrigins.Add(ca, origin);
405bool scanReferences = IsFullyPreservedAction(Context.TrimAction) || IsFullyPreservedAction(Context.DefaultAction);
411foreach (var (assemblyName, action) in Context.Actions)
416var assembly = Context.GetLoadedAssembly(assemblyName);
435var assembliesToCheck = scanReferences ? Context.GetReferencedAssemblies().ToArray() : Context.GetAssemblies();
545Context.LogMessage($"Removing typecheck of '{type.FullName}' inside '{item.Body.Method.GetDisplayName()}' method.");
592bool unusedInterfacesOptimizationEnabled = Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type);
618foreach (var assembly in Context.GetReferencedAssemblies().ToArray())
676MarkType(type, new DependencyInfo(DependencyKind.DynamicInterfaceCastableImplementation, iface.InterfaceType), new MessageOrigin(Context.TryResolve(iface.InterfaceType)));
748if (!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override))
772if (Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) && Annotations.IsInstantiated(overrideInformation.Override.DeclaringType))
779Debug.Assert(!Context.IsOptimizationEnabled(CodeOptimizations.OverrideRemoval, overrideInformation.Override) || overrideInformation.Base.IsAbstract);
805=> IsInterfaceImplementationMarkedRecursively(type, interfaceType, Context);
851TypeDefinition? type = Context.Resolve(marshaler.ManagedType);
865bool markOnUse = Context.KeepUsedAttributeTypesOnly && providerInLinkedAssembly;
878var resolvedAttributeType = Context.Resolve(ca.AttributeType);
939if (Context.CanApplyOptimization(CodeOptimizations.RemoveDynamicDependencyAttribute, member.DeclaringType.Module.Assembly))
958assembly = Context.TryResolve(dynamicDependency.AssemblyName);
961Context.LogWarning(origin, DiagnosticId.UnresolvedAssemblyInDynamicDependencyAttribute, dynamicDependency.AssemblyName);
974type = DocumentationSignatureParser.GetTypeByDocumentationSignature(assembly, typeName, Context);
977Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeName);
985type = Context.TryResolve(typeReference);
988Context.LogWarning(origin, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, typeReference.GetDisplayName());
994type = Context.TryResolve(context.DeclaringType);
997Context.LogWarning(context, DiagnosticId.UnresolvedTypeInDynamicDependencyAttribute, context.DeclaringType.GetDisplayName());
1005members = DocumentationSignatureParser.GetMembersByDocumentationSignature(type, memberSignature, Context, acceptName: true);
1008Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberSignature, type.GetDisplayName());
1015members = type.GetDynamicallyAccessedMembers(Context, memberTypes);
1018Context.LogWarning(origin, DiagnosticId.NoMembersResolvedForMemberSignatureOrType, memberTypes.ToString(), type.GetDisplayName());
1061Context.LogWarning(context, DiagnosticId.DeprecatedPreserveDependencyAttribute);
1063if (!DynamicDependency.ShouldProcess(Context, ca))
1070assembly = Context.TryResolve(assemblyName);
1073Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyAssembly, assemblyName);
1086td = Context.TryResolve(assemblyDef, typeName);
1090Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyType, typeName);
1135Context.LogWarning(context, DiagnosticId.CouldNotResolveDependencyMember, member ?? "", td.GetDisplayName());
1210if (GenericArgumentDataFlow.RequiresGenericArgumentDataFlow(Context.Annotations.FlowAnnotations, constructor_type))
1211GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in origin, this, Context, constructor_type);
1213TypeDefinition? type = Context.Resolve(constructor_type);
1228if (Context.KeepUsedAttributeTypesOnly)
1248TypeDefinition? type = Context.Resolve(attr_type);
1261if (type.IsBeforeFieldInit && Context.IsOptimizationEnabled(CodeOptimizations.BeforeFieldInit, type))
1324TypeDefinition? type = Context.Resolve(security_type);
1356var scanner = new AttributeDataFlow(Context, this, origin);
1370type = Context.TryResolve(type.BaseType);
1395var scanner = new AttributeDataFlow(Context, this, origin);
1409type = Context.TryResolve(type.BaseType);
1424type = Context.TryResolve(type.BaseType);
1438var resolvedConstructor = Context.TryResolve(ca.Constructor);
1441var scanner = new AttributeDataFlow(Context, this, origin);
1500EmbeddedXmlInfo.ProcessDescriptors(assembly, Context);
1506if (Context.StripSecurity)
1507RemoveSecurity.ProcessAssembly(assembly, Context);
1509MarkExportedTypesTarget.ProcessAssembly(assembly, Context);
1515!Context.TryGetCustomData("DisableMarkingOfCopyAssemblies", out string? disableMarkingOfCopyAssembliesValue) ||
1645var resolved = Context.Resolve(customAttribute.Constructor);
1705var resolved = Context.Resolve(customAttribute.Constructor);
1741FieldDefinition? field = Context.Resolve(reference);
1804ReportRequiresUnreferencedCode(method.GetDisplayName(), requiresUnreferencedCode!, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1817Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersMethodAccessedViaReflection, method.GetDisplayName());
1854Context.LogWarning(origin, id, type.GetDisplayName(),
1864Context.LogWarning(origin, id, type.GetDisplayName(), ((MemberReference)member).GetDisplayName());
1914typeWithFields = Context.TryResolve(typeWithFields.BaseType);
1957ReportRequiresUnreferencedCode(field.GetDisplayName(), requiresUnreferencedCodeAttribute, new DiagnosticContext(origin, diagnosticsEnabled: true, Context));
1968Context.LogWarning(origin, DiagnosticId.DynamicallyAccessedMembersFieldAccessedViaReflection, field.GetDisplayName());
1979AssemblyDefinition? assembly = Context.Resolve(scope);
2003if (Context.GetTargetRuntimeVersion() > TargetRuntimeVersion.NET5)
2034if (Context.TryResolve(type.BaseType) is TypeDefinition baseType && !Annotations.IsRelevantToVariantCasting(baseType))
2041if (Context.Resolve(method) is MethodDefinition methodDefinition)
2066GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, method.ReturnType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
2070GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in methodOrigin, this, Context, parameter.ParameterType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
2097if (Context.Resolve(field) is FieldDefinition fieldDefinition)
2121GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in fieldOrigin, this, Context, field.FieldType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
2206TypeDefinition? type = Context.Resolve(reference);
2238Context.LogWarning(origin, DiagnosticId.AttributeIsReferencedButTrimmerRemoveAllInstances, type.GetDisplayName());
2277if ((!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6) && BCL.EventTracingForWindows.IsEventSourceImplementation(type, Context))
2389return Context.TryResolve((TypeReference)property.Argument.Value);
2394return Context.TryResolve(asm, targetTypeName);
2409var resolvedAttributeType = Context.Resolve(attrType);
2430case "EventDataAttribute" when attrType.Namespace == "System.Diagnostics.Tracing" && (!Context.DisableEventSourceSpecialHandling || Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6):
2471if (Context.KeepMembersForDebugger)
2549if (Context.TryResolve(type.BaseType) is not TypeDefinition baseType)
2559if (Context.KeepMembersForDebugger)
2579if (Context.TryResolve(proxyTypeReference) is TypeDefinition proxyType)
2679if (!Context.IsOptimizationEnabled(CodeOptimizations.UnusedInterfaces, type))
2682if (Context.Resolve(ifaceType) is not TypeDefinition resolvedInterfaceType)
2690if (Context.KeepComInterfaces && (resolvedInterfaceType.IsImport || resolvedInterfaceType.IsWindowsRuntime))
2883var tdef = Context.Resolve(iface_type);
2894} while ((type = Context.TryResolve(type.BaseType)) != null);
2905var body = Context.GetMethodIL(method);
2955Debug.Assert(Context.GetTargetRuntimeVersion() < TargetRuntimeVersion.NET6 || !Context.DisableEventSourceSpecialHandling);
3032return Context.TryResolve(method.ElementMethod);
3035return Context.TryResolve(type.ElementType);
3060Context.LogWarning(type, DiagnosticId.TypeHasNoFieldsToPreserve, type.GetDisplayName());
3064Context.LogWarning(type, DiagnosticId.TypeHasNoMethodsToPreserve, type.GetDisplayName());
3183foreach (var ins in Context.GetMethodIL(body).Instructions)
3229if (reference.Name == ".ctor" && Context.TryResolve(arrayType) is TypeDefinition typeDefinition)
3245MethodDefinition? method = Context.Resolve(reference);
3308return CheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(method));
3444Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnStaticConstructor, method.GetDisplayName());
3446Context.LogWarning(methodOrigin, DiagnosticId.RequiresUnreferencedCodeOnEntryPoint, method.GetDisplayName());
3470var assembly = Context.Resolve(method.DeclaringType.Scope);
3479Context.Resolve(@base) is MethodDefinition baseDefinition
3617if (Context.Resolve(ov) is not MethodDefinition resolvedOverride)
3628if (TypeReferenceEqualityComparer.AreEqual(iface.InterfaceType, interfaceToBeImplemented, Context))
3644var baseType = Context.Resolve(method.DeclaringType.BaseType);
3660if (Context.MarkedKnownMembers.NotSupportedExceptionCtorString != null)
3663var nse = BCL.FindPredefinedType(WellKnownType.System_NotSupportedException, Context);
3670Context.MarkedKnownMembers.NotSupportedExceptionCtorString = nseCtor ??
3673var objectType = BCL.FindPredefinedType(WellKnownType.System_Object, Context);
3680Context.MarkedKnownMembers.ObjectCtor = objectCtor ??
3686if (Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor != null)
3689var disablePrivateReflection = BCL.FindPredefinedType(WellKnownType.System_Runtime_CompilerServices_DisablePrivateReflectionAttribute, Context);
3697Context.MarkedKnownMembers.DisablePrivateReflectionAttributeCtor = ctor ??
3732if (!string.IsNullOrEmpty(Context.PInvokesListFile))
3734Context.PInvokes.Add(new PInvokeInfo(
3743TypeDefinition? returnTypeDefinition = Context.TryResolve(method.ReturnType);
3770TypeDefinition? paramTypeDefinition = Context.TryResolve(paramTypeReference);
3789(new UnsafeAccessorMarker(Context, this)).ProcessUnsafeAccessorMethod(method);
3802AssemblyDefinition? assembly = Context.Resolve(method.DeclaringType.Scope);
3860var processedMethodBody = Context.GetMethodIL(body);
3862if (Context.IsOptimizationEnabled(CodeOptimizations.UnreachableBodies, body.Method) && IsUnreachableBody(processedMethodBody))
3888if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method))
3901if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, (MethodReference)instruction.Operand))
3923if (ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference))
3963ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForMethodBody(Context, methodIL.Method);
3994var implementations = new InterfacesOnStackScanner(Context).GetReferencedInterfaces(methodIL);
4013=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (FieldReference)instruction.Operand),
4026=> ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForAccess(Context, (TypeReference)instruction.Operand),
4059ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4088ReflectionMethodBodyScanner.RequiresReflectionMethodBodyScannerForCallSite(Context, methodReference);
4106if (Context.TryResolve(operand) is TypeDefinition typeDefinition)
4115if (!Context.CanApplyOptimization(CodeOptimizations.UnusedTypeChecks, method.DeclaringType.Module.Assembly))
4118TypeDefinition? type = Context.Resolve(operand);
4161GenericArgumentDataFlow.ProcessGenericArgumentDataFlow(in origin, this, Context, iface.InterfaceType, suppressTrimAnalysisWarnings: suppressTrimAnalysisWarnings);
4187if (Context.CompilerGeneratedState.TryGetCompilerGeneratedCalleesForUserMethod(methodIL.Method, out List<IMemberDefinition>? compilerGeneratedCallees))
4197requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(nestedBody), nestedOrigin);
4206requiresReflectionMethodBodyScanner |= MarkAndCheckRequiresReflectionMethodBodyScanner(Context.GetMethodIL(stateMachineBody), stateMachineOrigin);
4219var scanner = new ReflectionMethodBodyScanner(Context, this, origin);