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

[decompiler] Get rid of FormStack peek and fix virtual method calls #488

Merged
merged 2 commits into from
May 15, 2021

Conversation

water111
Copy link
Collaborator

I was expecting this to be much harder, so I'm a little suspicious that this isn't going to work 100% of the time.

@coveralls
Copy link

coveralls commented May 15, 2021

Pull Request Test Coverage Report for Build 845297566

  • 25 of 25 (100.0%) changed or added relevant lines in 2 files are covered.
  • 6 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.01%) to 69.178%

Files with Coverage Reduction New Missed Lines %
decompiler/IR2/FormExpressionAnalysis.cpp 6 80.56%
Totals Coverage Status
Change from base Build 845084620: -0.01%
Covered Lines: 34425
Relevant Lines: 49763

💛 - Coveralls

@water111
Copy link
Collaborator Author

Yeah this didn't work. The issue would be if the method call is falsely "split".

(defmacro set-vector! (vec x y z w)
  `(begin
     (set! (-> vec x) ,x)
     (set! (-> vec y) ,y)
     (set! (-> vec z) ,z)
     (set! (-> vec w) ,w)
   )
  )

;; method call with a macro used to generate an argument
(some-method obj (set-vector! (new 'stack 'vector) 1. 2. 3. 4.))

(let ((x (method-of-object obj some-method))
      (vec (new 'stack 'vector)))
  (set! (-> vec x) 1.)
  (set! (-> vec y) 2.)
  (set! (-> vec z) 3.)
  (set! (-> vec w) 4.)
  (x vec) ;; missing obj
  )

I really don't like the peek system. It seems like it would be better to ditch it and treat a method call as normal use of variables. Then, if it makes a mess with multiply accessing an object for the vtable and the this argument, we can clean that up manually in a later pass (or part of let pass). When it was first implemented, there was no let detection, which would make the clean up much harder. Now I think this is the better approach, and would let us delete all the "peek" junk.

@water111
Copy link
Collaborator Author

Will close #255

This finally ditches the awful peek system and weird special casing for virtual methods. The new strategy is to treat a virtual method just like any other method, but when popping the object, we allow it to be used twice. This wasn't possible in the original framework because we didn't have SSA based use/def counts.

I originally tried to fix this up at the let stage, but that didn't work when the method call was embedded in another expression - the temp var for the this blocked other unrelated variables from propagating properly.

@water111 water111 changed the title [decompiler] fix method peek issues, but it was too easy [decompiler] Get rid of FormStack peek and fix virtual method calls May 15, 2021
@water111 water111 merged commit d73501c into master May 15, 2021
@water111 water111 deleted the w/fix-method-peek branch May 15, 2021 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants