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

bpo-17611. Move unwinding of stack for "pseudo exceptions" from interpreter to compiler. #5071

Closed
wants to merge 12 commits into from

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Jan 1, 2018

See bpo-17611 for detailed discussion.
This PR:

  • Handles stack unwinding in the compiler rather than the interpreter, getting rid of "pseudo exceptions".
  • Deletes a number of overly complicated bytecodes, either eliminating them entirely or replacing them with simpler alternatives.
  • Removes one field from PyTryBlock reducing the size of a frame by 80 bytes.

This PR is not yet ready for merging as it does not include a misc.news entry, updates to Docs/library/dis.rst and the dis module tests fail.
If it is agreed that this is to be merged, then I will fill in the missing parts.

There are also a couple of further improvements that I would like to make, but have intentionally omitted. I intend to add them in separate PRs:

  • Replace LOAD_ADDR with LOAD_CONST in the peephole optimiser.
  • Fix stack size computation.

https://bugs.python.org/issue17611

@markshannon markshannon force-pushed the unwind-stack-in-compiler branch from bb69075 to 400d574 Compare January 2, 2018 14:08
@pitrou
Copy link
Member

pitrou commented Jan 2, 2018

It looks like the build core dumped on Travis-CI. There's also a build issue on AppVeyor (perhaps related to ..\Objects\frameobject.c(10): fatal error C1083: Cannot open include file: 'Python/wordcode_helpers.h': No such file or directory [C:\projects\cpython\PCbuild\pythoncore.vcxproj]).

@nascheme
Copy link
Member

nascheme commented Jan 2, 2018

The build error can be fixed by moving wordcode_helpers.h into Include. Then change "Python/wordcode_helpers.h" in frameobject.c to "wordcode_helpers.h". The current code doesn't compile if your build directory is not in the top-level source directory.

The following code causes a weird error in traceback.py:

def f1():                                                                   
    try:                                                                    
        raise RuntimeError                                                  
    finally:                                                                
        return 1                                                            
f1()                                                                        
                                                                            
def f2():                                                                   
    try:                                                                    
        raise Exception                                                     
    except:                                                                 
        try:                                                                
            x = 1                                                           
        finally:                                                            
            return 1                                                        
f2()                                                                        
                                                                            
try:                                                                        
    assert 0, 'assert #2'                                                   
except:                                                                     
    import traceback, sys                                                   
    print(sys.exc_info())                                                   
    traceback.print_exc()   

@brettcannon brettcannon removed the request for review from a team January 2, 2018 20:22
@markshannon
Copy link
Member Author

Closing in favour of #5006 and #5112

@markshannon markshannon closed this Jan 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants