Skip to content
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

Add a managed static registrar. Fixes #17324. #18268

Merged
merged 68 commits into from
May 19, 2023
Merged

Commits on May 11, 2023

  1. Configuration menu
    Copy the full SHA
    527cba2 View commit details
    Browse the repository at this point in the history
  2. [dotnet-linker] Reduce a bit of code duplication.

    There are no functional changes here, just code simplification.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    7c7637e View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    9e11297 View commit details
    Browse the repository at this point in the history
  4. [dotnet-linker] Unify exception handling to go through the LinkerConf…

    …iguration.Report method.
    
    Since LinkerConfiguration.Report uses the trimmer's API to report warnings and errors.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    eb01507 View commit details
    Browse the repository at this point in the history
  5. [dotnet-linker] Add a way for ConfigurationAwareStep subclasses to re…

    …turn exceptions.
    
    Without having to throw them.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    4351674 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    3ac9b8f View commit details
    Browse the repository at this point in the history
  7. [static registrar] Refactor code to make it easier to reuse code late…

    …r on.
    
    There are no functional changes here, just refactoring to make code easier to re-use.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    872af5d View commit details
    Browse the repository at this point in the history
  8. [static registrar] Refactor code to make it easier to reuse code late…

    …r on.
    
    There are no functional changes here, just refactoring to make code easier to re-use.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    e66f82d View commit details
    Browse the repository at this point in the history
  9. [static registrar] Refactor code to make it easier to reuse code late…

    …r on.
    
    There are no functional changes here, just refactoring to make code easier to re-use.
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    a1410ac View commit details
    Browse the repository at this point in the history
  10. [tools] Add a ManagedStatic registrar mode.

    This new mode is still considered a 'Static' registrar mode, it's just a variation of it.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    cfb248e View commit details
    Browse the repository at this point in the history
  11. [dotnet] Add an 'IsManagedStaticRegistrar' feature to the linker.

    This way we can ask the linker to inline the Runtime.IsManagedStaticRegistrar property, and remove any dead code paths.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    34264cd View commit details
    Browse the repository at this point in the history
  12. [dotnet-linker] Add the scaffolding for a ManagedRegistrarStep and a …

    …ManagedRegistrarLookupTablesStep.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    bf639a9 View commit details
    Browse the repository at this point in the history
  13. [dotnet-linker] Don't do anything in ManagedRegistrarStep unless the …

    …current registrar mode is 'ManagedStatic'.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    57d40d9 View commit details
    Browse the repository at this point in the history
  14. [dotnet-linker] Rearrange registration and generation in the static r…

    …egistrar
    
    The managed static registrar will add code to the processed assemblies, which means
    it must run before the trimmer sweeps unused code.
    
    This means we have to split the current registrar logic in two:
    
    1. First we process all the assemblies.
    2. Then we write out the results.
    
    When not using the managed static registrar, these two steps happens right after
    oneanother (like they do now), while when using the managed static registrar, the
    processing is done before the trimmer sweeps (where we'll also generate all the new
    IL code), and then the generated native code will be done at the end of the build
    process (like for the old-school static registrar).
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    e39c6fb View commit details
    Browse the repository at this point in the history
  15. [registrar] Make some API from the registrar public so that the manag…

    …ed static registrar step can access them.
    
    There are no functional changes here, just refactoring to make code easier to re-use.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    a1e0e30 View commit details
    Browse the repository at this point in the history
  16. [src] Fix comparison between signed and unsigned int.

    Comparing -1 to 0xFFFFFFFF doesn't get the right result otherwise.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    43b88af View commit details
    Browse the repository at this point in the history
  17. [static registrar] Add support for generating block syntax in Objecti…

    …ve-C method signatures.
    
    This is required when generating a cast of a function pointer to an Objective-C method
    signature (which the managed static registrar does).
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    8f1fb22 View commit details
    Browse the repository at this point in the history
  18. [static registrar] Move token reference creation a little bit later.

    It's not needed until later anyway.
    
    This way we can add code for the managed static registrar (which does not need the
    token reference, in fact creating a token reference for a method won't be possible
    with the managed static registra) in the correct location in the code.
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    70a39a7 View commit details
    Browse the repository at this point in the history
  19. [tools] Move code to compute block signatures to the static registrar.

    This makes it easier to use this code from the managed static registrar.
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    53d7bc5 View commit details
    Browse the repository at this point in the history
  20. [registrar] Add an HasCustomAttribute overload that returns the found…

    … attribute (if any)
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    dc56054 View commit details
    Browse the repository at this point in the history
  21. [dotnet-linker] Add extension methods for making IL emission easier w…

    …ith Cecil.
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    47eddc5 View commit details
    Browse the repository at this point in the history
  22. [dotnet-linker] Add a helper class for keeping track of methods and t…

    …ypes when emitting IL code with Cecil.
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    2a40824 View commit details
    Browse the repository at this point in the history
  23. [registrar] Refactor code to determine if a method is a property acce…

    …ssor to make it easier to reuse.
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    72c654e View commit details
    Browse the repository at this point in the history
  24. [dotnet-linker] Remove trimmed API from the registered types before g…

    …enerating native code when using the managed static registrar.
    
    When using the managed static registrar, we register types with the static registrar
    before the linker does its work, so we need to follow-up after the linker has figured
    out what will be trimmed away to remove any such types from the list of registered types.
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    4ab321d View commit details
    Browse the repository at this point in the history
  25. [static registrar] Refactor code to make it easier to reuse code late…

    …r on.
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    4bd045e View commit details
    Browse the repository at this point in the history
  26. [src] Refactor Class.ResolveToken to take the assembly as a parameter.

    This is to make the Class.ResolveToken usable from the managed static registrar.
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    cbfc591 View commit details
    Browse the repository at this point in the history
  27. [runtime] Add an API to look up the native symbol for an [UnmanagedCa…

    …llersOnly] method.
    
    Add an API to look up the native symbol for an [UnmanagedCallersOnly] method from native code.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    fb6ed7b View commit details
    Browse the repository at this point in the history
  28. [tools] Add a managed static registrar. Fixes xamarin#17324.

    This adds a managed static registrar, which is a variation of the static registrar
    that takes advantage of a few new features in C# and the runtime, as well as avoiding
    metadata tokens, which NativeAOT doesn't support.
    
    This registrar will generate most of the trampoline/interop code as managed code
    using Cecil, and the Objective-C part is as small as possible.
    
    Fixes xamarin#17324.
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    382ebae View commit details
    Browse the repository at this point in the history
  29. [static registrar] Implement support for calling the generated Unmana…

    …gedCallersOnly method from the managed static registrar
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    9bcc96e View commit details
    Browse the repository at this point in the history
  30. [src] Add helper methods for the managed static registrar

    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    b8ccbad View commit details
    Browse the repository at this point in the history
  31. [registrar] We might link the [Protocol] attribute away, so store it …

    …for later reference by the static registrar
    Git History Editor authored and rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    8f55662 View commit details
    Browse the repository at this point in the history
  32. [src] Track selector and method better to provide more helpful error …

    …messages.
    
    This commit introduces a few new GetNSObject/GetINativeObject overloads that will
    be used by the managed static registrar.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    ed4eb42 View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    a2f5e16 View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    1deba2c View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    eb62964 View commit details
    Browse the repository at this point in the history
  36. [monotouch-test] Use MidiThruConnectionEndpoint instead of MidiCIDevi…

    …ceIdentification in exported methods.
    
    MidiCIDeviceIdentification isn't blittable ((yet)[1]), so exporting it makes
    the AOT compiler complain. Use a different (but blittable) type instead in the
    test.
    
    [1]: xamarin@03f0a35
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    4f5fa5e View commit details
    Browse the repository at this point in the history
  37. [tests] Adjust to cope with slightly different errors reported when u…

    …sing the managed static registrar.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    17b2d37 View commit details
    Browse the repository at this point in the history
  38. [linker] Don't optimize calls to BlockLiteral.SetupBlock in BlockLite…

    …ral.CreateBlockForDelegate.
    rolfbjarne committed May 11, 2023
    Configuration menu
    Copy the full SHA
    00a8228 View commit details
    Browse the repository at this point in the history

Commits on May 12, 2023

  1. Update docs/managed-static-registrar.md

    Co-authored-by: Haritha Mohan <harithamohan@microsoft.com>
    rolfbjarne and haritha-mohan committed May 12, 2023
    Configuration menu
    Copy the full SHA
    dd64974 View commit details
    Browse the repository at this point in the history
  2. Update docs/managed-static-registrar.md

    Co-authored-by: Haritha Mohan <harithamohan@microsoft.com>
    rolfbjarne and haritha-mohan committed May 12, 2023
    Configuration menu
    Copy the full SHA
    5693250 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    b4ea025 View commit details
    Browse the repository at this point in the history
  4. [dotnet-linker] Don't prefix the exported entry point from an Unmanag…

    …edCallersOnly method with an underscore in .NET 8+.
    rolfbjarne committed May 12, 2023
    Configuration menu
    Copy the full SHA
    3da0809 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    f32c9e1 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    dd2252f View commit details
    Browse the repository at this point in the history

Commits on May 15, 2023

  1. Apply suggestions from code review

    Co-authored-by: Alexander Köplinger <alex.koeplinger@outlook.com>
    Co-authored-by: Ivan Povazan <55002338+ivanpovazan@users.noreply.github.com>
    3 people committed May 15, 2023
    Configuration menu
    Copy the full SHA
    3a8b988 View commit details
    Browse the repository at this point in the history
  2. Update runtime/xamarin/runtime.h

    Co-authored-by: Ivan Povazan <55002338+ivanpovazan@users.noreply.github.com>
    rolfbjarne and ivanpovazan committed May 15, 2023
    Configuration menu
    Copy the full SHA
    7a5fca4 View commit details
    Browse the repository at this point in the history
  3. Mark type forwarders when saving assemblies

    Otherwise the linker will remove them.
    
    Co-authored-by: Filip Navara <filip.navara@gmail.com>
    rolfbjarne and filipnavara committed May 15, 2023
    Configuration menu
    Copy the full SHA
    a04a1d4 View commit details
    Browse the repository at this point in the history
  4. [dotnet-linker] Improve code in AppBundleRewriter according to review.

    Add a few more helper methods to get method references, that simplifies calling code.
    rolfbjarne committed May 15, 2023
    Configuration menu
    Copy the full SHA
    6d33409 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    065da5f View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    587058f View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    4053da7 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    e4830a8 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    fd67384 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    2828d7f View commit details
    Browse the repository at this point in the history
  11. [dotnet-linker] Always use 'IntPtr' as the type of for the first argu…

    …ment in UnmanagedCallersOnly methods in the managed static registrar.
    
    This fixes invalid IL in a few cases.
    rolfbjarne committed May 15, 2023
    Configuration menu
    Copy the full SHA
    25ad7b2 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    429b8e3 View commit details
    Browse the repository at this point in the history
  13. [runtime] Change NSObject.AllocateNSObject<T> to not take the flags p…

    …arameter.
    
    It's only called from one place, and the flags are constant, so just hardcode
    the value in the method instead of taking it as an input. This simplifies the
    generated managed static registrar code a little bit.
    rolfbjarne committed May 15, 2023
    Configuration menu
    Copy the full SHA
    50ba357 View commit details
    Browse the repository at this point in the history
  14. Auto-format source code

    GitHub Actions Autoformatter committed May 15, 2023
    Configuration menu
    Copy the full SHA
    a248260 View commit details
    Browse the repository at this point in the history

Commits on May 18, 2023

  1. [dotnet-linker] Make sure local variables are initialized before use …

    …in generated method bodies.
    rolfbjarne committed May 18, 2023
    Configuration menu
    Copy the full SHA
    643015e View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    799095e View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    a7371cf View commit details
    Browse the repository at this point in the history
  4. [dotnet-linker] Fix detecting when we must call the object-based Runt…

    …ime.GetNSObject
    
    We can't call the generic Runtime.GetNSObject<T> method when we don't know the final
    type of the returned object, which happens for open types. However, we must always
    call the generic Runtime.GetNSObject<T> when we know the final type, so that we have
    the correct object type on the evaluation stack.
    
    Fix this by properly detecting open types and only calling Runtime.GetNSObject in
    that case.
    Git History Editor authored and rolfbjarne committed May 18, 2023
    Configuration menu
    Copy the full SHA
    469fdb5 View commit details
    Browse the repository at this point in the history
  5. [dotnet-linker] Keep better track of when we're calling MethodBase.In…

    …voke.
    
    Keep better track of whether we're calling MethodBase.Invoke to call the target method,
    which allows us to detect certain error scenarios (and show a corresponding error).
    Git History Editor authored and rolfbjarne committed May 18, 2023
    Configuration menu
    Copy the full SHA
    ed7b4b6 View commit details
    Browse the repository at this point in the history
  6. [dotnet-linker] Keep track of when we called MethodBase.Invoke and an…

    … 'object' reference is left on the stack.
    
    Keep track of when we called MethodBase.Invoke and an 'object' reference is left
    on the stack, so that we can cast to the appropiate type later on when we know how
    the value is converted to the corresponding native type.
    
    This fixes a few cases of the managed static registrar creating unverifiable IL.
    Git History Editor authored and rolfbjarne committed May 18, 2023
    Configuration menu
    Copy the full SHA
    aa75c70 View commit details
    Browse the repository at this point in the history
  7. [dotnet-linker] Add a missing cast to make generated code more verifi…

    …able
    Git History Editor authored and rolfbjarne committed May 18, 2023
    Configuration menu
    Copy the full SHA
    d540050 View commit details
    Browse the repository at this point in the history
  8. [dotnet-linker] Simplify generated code for constructors of generic t…

    …ypes.
    
    We can't create an instance of a generic type in the UnmanagedCallersOnly trampoline,
    so simplify the code to not even try, and instead just throw the final exception.
    rolfbjarne committed May 18, 2023
    Configuration menu
    Copy the full SHA
    666ec96 View commit details
    Browse the repository at this point in the history
  9. Auto-format source code

    GitHub Actions Autoformatter committed May 18, 2023
    Configuration menu
    Copy the full SHA
    03488a2 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    65590ba View commit details
    Browse the repository at this point in the history