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

Dynamic function replacement #20333

Merged

Commits on Nov 6, 2018

  1. Allow dynamic without @objc in -swift-version 5

    Dynamic functions will allow replacement of their implementation at
    runtime.
    aschwaighofer committed Nov 6, 2018
    Copy the full SHA
    c158106 View commit details
    Browse the repository at this point in the history
  2. Add [dynamically_replacable] to SILFunctions

    'dynamic' functions are marked as [dynamically_replaceable].
    aschwaighofer committed Nov 6, 2018
    Copy the full SHA
    5f4e183 View commit details
    Browse the repository at this point in the history
  3. IRGen: Add implementation for dynamically replaceable functions

    A dynamically replaceable function calls through a global variable that
    holds the function pointer.
    
    struct ChainEntry {
       void *(funPtr)();
       struct ChainEntry *next;
    }
    
    ChainEntry dynamicallyReplaceableVar;
    
    void dynamicallyReplaceableFunction() {
      dynamicallyReplaceableVar.funPtr()
    }
    
    dynamic replacements will be chainable so the global variable also
    functions as the root entry in the chain of replacements.
    
    A dynamic replacement functions can call the previous implementation by
    going through its chain entry.
    
    ChainEntry chainEntryOf_dynamic_replacement_for_foo;
    
    void dynamic_replacement_for_foo() {
       // call the previous (original) implementation.
       chainEntryOf_dynamic_replacement_for_foo.funPtr();
    }
    aschwaighofer committed Nov 6, 2018
    Copy the full SHA
    ebbe3ae View commit details
    Browse the repository at this point in the history
  4. Add new SIL instruction for calling dynamically_replaceable funtions

      %0 = dynamic_function_ref @dynamically_replaceable_function
      apply %0()
      Calls a [dynamically_replaceable] function.
    
      %0 = prev_dynamic_function_ref @dynamic_replacement_function
      apply %0
      Calls the previous implementation that dynamic_replacement_function
      replaced.
    aschwaighofer committed Nov 6, 2018
    Copy the full SHA
    7e32c68 View commit details
    Browse the repository at this point in the history
  5. Copy the full SHA
    52c1903 View commit details
    Browse the repository at this point in the history
  6. Parser/Sema/SILGen changes for @_dynamicReplacement(for:)

    Dynamic replacements are currently written in extensions as
    
    extension ExtendedType {
      @_dynamicReplacement(for: replacedFun())
      func replacement() { }
    }
    
    The runtime implementation allows an implementation in the future where
    dynamic replacements are gather in a scope and can be dynamically
    enabled and disabled.
    
    For example:
    
    dynamic_extension_scope CollectionOfReplacements {
      extension ExtentedType {
        func replacedFun() {}
      }
    
      extension ExtentedType2 {
        func replacedFun() {}
      }
    }
    
    CollectionOfReplacements.enable()
    CollectionOfReplacements.disable()
    aschwaighofer committed Nov 6, 2018
    Copy the full SHA
    b102c7f View commit details
    Browse the repository at this point in the history
  7. Copy the full SHA
    152e8db View commit details
    Browse the repository at this point in the history
  8. Cleanups

    aschwaighofer committed Nov 6, 2018
    Copy the full SHA
    89e1969 View commit details
    Browse the repository at this point in the history
  9. Copy the full SHA
    f1b53eb View commit details
    Browse the repository at this point in the history
  10. Copy the full SHA
    c77da02 View commit details
    Browse the repository at this point in the history
  11. Copy the full SHA
    cf2eb21 View commit details
    Browse the repository at this point in the history

Commits on Nov 7, 2018

  1. Adjust test for 32bit

    aschwaighofer committed Nov 7, 2018
    Copy the full SHA
    fff1333 View commit details
    Browse the repository at this point in the history