private void ProcessAssemblyDirective(IRootingServiceProvider rootProvider, XElement assemblyElement) { var assemblyNameAttribute = assemblyElement.Attribute("Name"); if (assemblyNameAttribute == null) throw new Exception(); ModuleDesc assembly = _context.ResolveAssembly(new AssemblyName(assemblyNameAttribute.Value)); var dynamicDegreeAttribute = assemblyElement.Attribute("Dynamic"); if (dynamicDegreeAttribute != null) { if (dynamicDegreeAttribute.Value != "Required All") throw new NotSupportedException(); // Reuse LibraryRootProvider to root everything new LibraryRootProvider((EcmaModule)assembly).AddCompilationRoots(rootProvider); } foreach (var element in assemblyElement.Elements()) { switch (element.Name.LocalName) { case "Type": ProcessTypeDirective(rootProvider, assembly, element); break; default: throw new NotSupportedException(); } } }
private void RootMethods(TypeDesc type, string reason, IRootingServiceProvider rootProvider) { foreach (MethodDesc method in type.GetMethods()) { // Skip methods with no IL and uninstantiated generic methods if (method.IsIntrinsic || method.IsAbstract || method.HasInstantiation) continue; if (method.IsInternalCall) continue; try { CheckCanGenerateMethod(method); rootProvider.AddCompilationRoot(method, reason); } catch (TypeSystemException) { // TODO: fail compilation if a switch was passed // Individual methods can fail to load types referenced in their signatures. // Skip them in library mode since they're not going to be callable. continue; // TODO: Log as a warning } } }
private void AddReflectionInitializationCode(IRootingServiceProvider rootProvider) { // System.Private.Reflection.Execution needs to establish a communication channel with System.Private.CoreLib // at process startup. This is done through an eager constructor that calls into CoreLib and passes it // a callback object. // // Since CoreLib cannot reference anything, the type and it's eager constructor won't be added to the compilation // unless we explictly add it. var refExec = _typeSystemContext.GetModuleForSimpleName("System.Private.Reflection.Execution", false); if (refExec != null) { var exec = refExec.GetKnownType("Internal.Reflection.Execution", "ReflectionExecution"); if (ContainsType(exec)) { rootProvider.AddCompilationRoot(exec.GetStaticConstructor(), "Reflection execution"); } } else { // If we can't find Reflection.Execution, we better be compiling a nonstandard thing (managed // portion of the runtime maybe?). Debug.Assert(_typeSystemContext.GetModuleForSimpleName("System.Private.CoreLib", false) == null); } }
public void AddCompilationRoots(IRootingServiceProvider rootProvider) { foreach (TypeDesc type in _module.GetAllTypes()) { // Skip delegates (since their Invoke methods have no IL) if (type.IsDelegate) continue; try { rootProvider.AddCompilationRoot(type, "Library module type"); } catch (TypeSystemException) { // TODO: fail compilation if a switch was passed // Swallow type load exceptions while rooting continue; // TODO: Log as a warning } // If this is not a generic definition, root all methods if (!type.HasInstantiation) RootMethods(type, "Library module method", rootProvider); } }
private void AddWellKnownTypes(IRootingServiceProvider rootProvider) { var stringType = _typeSystemContext.GetWellKnownType(WellKnownType.String); if (ContainsType(stringType)) { rootProvider.AddCompilationRoot(stringType, "String type is always generated"); } }
private void AddCompilationRootsForMultifileLibrary(EcmaModule module, IRootingServiceProvider rootProvider) { foreach (TypeDesc type in module.GetAllTypes()) { // Skip delegates (since their Invoke methods have no IL) and uninstantiated generic types if (type.IsDelegate || type.ContainsGenericVariables) continue; rootProvider.AddCompilationRoot(type, "Library module type"); RootMethods(type, "Library module method", rootProvider); } }
public override void AddCompilationRoots(IRootingServiceProvider rootProvider) { base.AddCompilationRoots(rootProvider); if (BuildingLibrary) { foreach (var module in InputModules) { AddCompilationRootsForMultifileLibrary(module, rootProvider); } } }
public virtual void AddCompilationRoots(IRootingServiceProvider rootProvider) { foreach (var inputFile in _typeSystemContext.InputFilePaths) { var module = _typeSystemContext.GetModuleFromPath(inputFile.Value); if (module.PEReader.PEHeaders.IsExe) AddMainMethodCompilationRoot(module, rootProvider); AddCompilationRootsForExports(module, rootProvider); } AddWellKnownTypes(rootProvider); AddReflectionInitializationCode(rootProvider); }
public void AddCompilationRoots(IRootingServiceProvider rootProvider) { RootWellKnownType(WellKnownType.Void, rootProvider); RootWellKnownType(WellKnownType.Boolean, rootProvider); RootWellKnownType(WellKnownType.Char, rootProvider); RootWellKnownType(WellKnownType.SByte, rootProvider); RootWellKnownType(WellKnownType.Byte, rootProvider); RootWellKnownType(WellKnownType.Int16, rootProvider); RootWellKnownType(WellKnownType.UInt16, rootProvider); RootWellKnownType(WellKnownType.Int32, rootProvider); RootWellKnownType(WellKnownType.UInt32, rootProvider); RootWellKnownType(WellKnownType.Int64, rootProvider); RootWellKnownType(WellKnownType.UInt64, rootProvider); RootWellKnownType(WellKnownType.IntPtr, rootProvider); RootWellKnownType(WellKnownType.UIntPtr, rootProvider); RootWellKnownType(WellKnownType.Single, rootProvider); RootWellKnownType(WellKnownType.Double, rootProvider); }
public void AddCompilationRoots(IRootingServiceProvider rootProvider) { var libraryOrApplication = _documentRoot.Elements().Single(); if (libraryOrApplication.Name.LocalName != "Library" && libraryOrApplication.Name.LocalName != "Application") throw new Exception(); if (libraryOrApplication.Attributes().Any()) throw new NotSupportedException(); foreach (var element in libraryOrApplication.Elements()) { switch (element.Name.LocalName) { case "Assembly": ProcessAssemblyDirective(rootProvider, element); break; default: throw new NotSupportedException(); } } }
public void AddCompilationRoots(IRootingServiceProvider rootProvider) { foreach (var type in _module.GetAllTypes()) { foreach (var method in type.GetMethods()) { EcmaMethod ecmaMethod = (EcmaMethod)method; if (ecmaMethod.IsRuntimeExport) { string runtimeExportName = ecmaMethod.GetRuntimeExportName(); if (runtimeExportName != null) rootProvider.AddCompilationRoot(method, "Runtime export", runtimeExportName); } if (ecmaMethod.IsNativeCallable) { string nativeCallableExportName = ecmaMethod.GetNativeCallableExportName(); if (nativeCallableExportName != null) rootProvider.AddCompilationRoot(method, "Native callable", nativeCallableExportName); } } } }
private void RootMethods(TypeDesc type, string reason, IRootingServiceProvider rootProvider) { foreach (MethodDesc method in type.GetMethods()) { // Skip methods with no IL and uninstantiated generic methods if (method.IsIntrinsic || method.IsAbstract || method.ContainsGenericVariables) continue; if (method.IsInternalCall) continue; rootProvider.AddCompilationRoot(method, reason); } }
public void AddCompilationRoots(IRootingServiceProvider rootProvider) { foreach (var methodProfileInfo in _profileData.GetAllMethodProfileData()) { if (!methodProfileInfo.Flags.HasFlag(MethodProfilingDataFlags.ExcludeHotMethodCode) && !methodProfileInfo.Flags.HasFlag(MethodProfilingDataFlags.ExcludeColdMethodCode)) { try { MethodDesc method = methodProfileInfo.Method; // Validate that this method is fully instantiated if (method.OwningType.IsGenericDefinition || method.OwningType.ContainsSignatureVariables()) { continue; } bool containsSignatureVariables = false; foreach (TypeDesc t in method.Instantiation) { if (t.IsGenericDefinition) { containsSignatureVariables = true; break; } if (t.ContainsSignatureVariables()) { containsSignatureVariables = true; break; } } if (containsSignatureVariables) { continue; } CheckCanGenerateMethod(method); rootProvider.AddCompilationRoot(method, "Profile triggered method"); } catch (TypeSystemException) { // Individual methods can fail to load types referenced in their signatures. // Skip them in library mode since they're not going to be callable. continue; } } } if (!_profileData.PartialNGen) { foreach (TypeDesc type in _module.GetAllTypes()) { try { rootProvider.AddCompilationRoot(type, "Library module type"); } catch (TypeSystemException) { // Swallow type load exceptions while rooting continue; } // If this is not a generic definition, root all methods if (!type.HasInstantiation) { RootMethods(type, "Library module method", rootProvider); } } } }
void ICompilationRootProvider.AddCompilationRoots(IRootingServiceProvider rootProvider) { // MetadataManagers can override this to provide metadata compilation roots that need to be added to the graph ahead of time. // (E.g. reflection roots computed by IL analyzers, or non-compilation-based roots) }
private void AddMainMethodCompilationRoot(EcmaModule module, IRootingServiceProvider rootProvider) { if (StartupCodeMain != null) throw new Exception("Multiple entrypoint modules"); MethodDesc mainMethod = module.EntryPoint; if (mainMethod == null) throw new Exception("No managed entrypoint defined for executable module"); var owningType = module.GetGlobalModuleType(); StartupCodeMain = new StartupCodeMainMethod(owningType, mainMethod); rootProvider.AddCompilationRoot(StartupCodeMain, "Startup Code Main Method", "__managed__Main"); }
private void ProcessTypeDirective(IRootingServiceProvider rootProvider, ModuleDesc containingModule, XElement typeElement) { var typeNameAttribute = typeElement.Attribute("Name"); if (typeNameAttribute == null) throw new Exception(); var dynamicDegreeAttribute = typeElement.Attribute("Dynamic"); if (dynamicDegreeAttribute != null) { if (dynamicDegreeAttribute.Value != "Required All") throw new NotSupportedException(); } string typeName = typeNameAttribute.Value; TypeDesc type = containingModule.GetTypeByCustomAttributeTypeName(typeName); rootProvider.AddCompilationRoot(type, "RD.XML root"); if (type.IsDefType) { foreach (var method in type.GetMethods()) { if (method.IsAbstract || method.HasInstantiation) continue; rootProvider.AddCompilationRoot(method, "RD.XML root"); } } }
public override void AddCompilationRoots(IRootingServiceProvider rootProvider) { base.AddCompilationRoots(rootProvider); AddCompilationRootsForExports((EcmaModule)_typeSystemContext.SystemModule, rootProvider); }
public override void AddCompilationRoots(IRootingServiceProvider rootProvider) { rootProvider.AddCompilationRoot(_method, "Single method mode"); }
public void AddCompilationRoots(IRootingServiceProvider rootProvider) { rootProvider.AddCompilationRoot(_method, "Single method root"); }
private void RootWellKnownType(WellKnownType wellKnownType, IRootingServiceProvider rootProvider) { var type = _context.GetWellKnownType(wellKnownType); rootProvider.AddCompilationRoot(type, "Enables CPP codegen"); }