- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 33.3k
gh-98831: rewrite MAKE_FUNCTION and BUILD_SLICE in the instruction definition DSL #101529
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
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -2972,36 +2972,39 @@ dummy_func( | |
| CHECK_EVAL_BREAKER(); | ||
| } | ||
|  | ||
| // error: MAKE_FUNCTION has irregular stack effect | ||
| inst(MAKE_FUNCTION) { | ||
| PyObject *codeobj = POP(); | ||
| PyFunctionObject *func = (PyFunctionObject *) | ||
| inst(MAKE_FUNCTION, (defaults if (oparg & 0x01), | ||
| kwdefaults if (oparg & 0x02), | ||
| annotations if (oparg & 0x04), | ||
| closure if (oparg & 0x08), | ||
| codeobj -- func)) { | ||
|  | ||
| PyFunctionObject *func_obj = (PyFunctionObject *) | ||
| PyFunction_New(codeobj, GLOBALS()); | ||
|  | ||
| Py_DECREF(codeobj); | ||
| if (func == NULL) { | ||
| if (func_obj == NULL) { | ||
| goto error; | ||
| } | ||
|  | ||
| if (oparg & 0x08) { | ||
| assert(PyTuple_CheckExact(TOP())); | ||
| func->func_closure = POP(); | ||
| assert(PyTuple_CheckExact(closure)); | ||
| func_obj->func_closure = closure; | ||
| } | ||
| if (oparg & 0x04) { | ||
| assert(PyTuple_CheckExact(TOP())); | ||
| func->func_annotations = POP(); | ||
| assert(PyTuple_CheckExact(annotations)); | ||
| func_obj->func_annotations = annotations; | ||
| } | ||
| if (oparg & 0x02) { | ||
| assert(PyDict_CheckExact(TOP())); | ||
| func->func_kwdefaults = POP(); | ||
| assert(PyDict_CheckExact(kwdefaults)); | ||
| func_obj->func_kwdefaults = kwdefaults; | ||
| } | ||
| if (oparg & 0x01) { | ||
| assert(PyTuple_CheckExact(TOP())); | ||
| func->func_defaults = POP(); | ||
| assert(PyTuple_CheckExact(defaults)); | ||
| func_obj->func_defaults = defaults; | ||
| } | ||
|  | ||
| func->func_version = ((PyCodeObject *)codeobj)->co_version; | ||
| PUSH((PyObject *)func); | ||
| func_obj->func_version = ((PyCodeObject *)codeobj)->co_version; | ||
| func = (PyObject *)func_obj; | ||
| } | ||
|  | ||
| inst(RETURN_GENERATOR, (--)) { | ||
|  | @@ -3027,22 +3030,12 @@ dummy_func( | |
| goto resume_frame; | ||
| } | ||
|  | ||
| // error: BUILD_SLICE has irregular stack effect | ||
| inst(BUILD_SLICE) { | ||
| PyObject *start, *stop, *step, *slice; | ||
| if (oparg == 3) | ||
| step = POP(); | ||
| else | ||
| step = NULL; | ||
| stop = POP(); | ||
| start = TOP(); | ||
| inst(BUILD_SLICE, (start, stop, step if (oparg == 3) -- slice)) { | ||
| slice = PySlice_New(start, stop, step); | ||
| Py_DECREF(start); | ||
| Py_DECREF(stop); | ||
| Py_XDECREF(step); | ||
| 
      Comment on lines
    
      3035
     to 
      3037
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, we should augment  | ||
| SET_TOP(slice); | ||
| if (slice == NULL) | ||
| goto error; | ||
| ERROR_IF(slice == NULL, error); | ||
| } | ||
|  | ||
| // error: FORMAT_VALUE has irregular stack effect | ||
|  | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
      
      Oops, something went wrong.
      
    
  
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Too bad we can't write
func: PyFunctionObject *yet -- I've gotta add that to the grammar, it would add the casts and save the ugly extrafunc_objvariable.