Git Product home page Git Product logo

Comments (1)

kateinoigakukun avatar kateinoigakukun commented on July 16, 2024 2

Progress report

I developed a WebAssembly debugger kateinoigakukun/wasminspect. If you are interested in fixing test cases, this tool is very useful to investigate.

As far as I investigated, CapturePropagation pass in SILOptimizer omits partial_apply which is emitted for thunk function call.

For example,

sil @main : $@convention(c) (Builtin.Int32, Builtin.RawPointer) -> Builtin.Int32 {
bb0(%c : $Builtin.Int32, %v : $Builtin.RawPointer):
  // function_ref createInstance()
  %1 = function_ref @$s5Katei14createInstanceAA1SVSgyF : $@convention(thin) () -> Optional<S> // user: %3
  // function_ref thunk for @escaping @convention(thin) () -> (@unowned S?)
  %2 = function_ref @$s5Katei1SVSgIetd_ADIegd_TR : $@convention(thin) (@convention(thin) () -> Optional<S>) -> Optional<S> // user: %3
  %3 = partial_apply [callee_guaranteed] [on_stack] %2(%1) : $@convention(thin) (@convention(thin) () -> Optional<S>) -> Optional<S> // users: %5, %9
}

this SIL is optimized to be that.

sil @main : $@convention(c) (Builtin.Int32, Builtin.RawPointer) -> Builtin.Int32 {
bb0(%c : $Builtin.Int32, %v : $Builtin.RawPointer):
  // function_ref specialized thunk for @callee_guaranteed () -> (@unowned S?)
  %1 = function_ref @$s5Katei1SVSgIgd_ADIegr_TR69$s5Katei1SVSgIetd_ADIegd_TR33$s5Katei14createInstanceAA1SVSgyFTf3pf_nTf3npf_n : $@convention(thin) @noescape () -> @out Optional<S> // user: %2
  %2 = thin_to_thick_function %3 : $@convention(thin) @noescape () -> @out Optional<S> to $@noescape @callee_guaranteed () -> @out Optional<S>
}


// specialized thunk for @callee_guaranteed () -> (@unowned S?)
sil shared [transparent] [reabstraction_thunk] @$s5Katei1SVSgIgd_ADIegr_TR69$s5Katei1SVSgIetd_ADIegd_TR33$s5Katei14createInstanceAA1SVSgyFTf3pf_nTf3npf_n : $@convention(thin) @noescape () -> @out Optional<S> {
// %0                                             // user: %5
bb0(%0 : $*Optional<S>):
  // function_ref createInstance()
  %1 =  function_ref @$s5Katei14createInstanceAA1SVSgyF : $@convention(thin) () -> Optional<S> // user: %3
  %2 = apply %1() : $@convention(method) () -> S // user: %3
  %3 = enum $Optional<S>, #Optional.some!enumelt.1, %2 : $S // user: %4
  store %3 to %0 : $*Optional<S>                  // id: %4
  %5 = tuple ()                                   // user: %6
  return %5 : $()                                 // id: %6
} // end sil function '$s5Katei1SVSgIgd_ADIegr_TR69$s5Katei1SVSgIetd_ADIegd_TR33$s5Katei14createInstanceAA1SVSgyFTf3pf_nTf3npf_n'

This means thin_to_thick_function should emit LLVM IR level thunk function through IRGen module.

If -Onone is set, most of stdlib test cases are passed 😜

from swift.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.