cps icon indicating copy to clipboard operation
cps copied to clipboard

Handle inner procs

Open zevv opened this issue 4 years ago • 2 comments

import cps    
import strutils
                                                             
type              
  C = Continuation
                  
  CallBack = proc(): C
          
proc bar(cb: CallBack) {.cps:C.} =                                                      
  echo "bar"
                      
proc thing() {.cps:C.} =
  echo "thing"
                                                                          
proc foo() {.cps:C.} =         
  proc gen(): CallBack =
    result = proc(): C =
      whelp thing()     
  bar gen()        
           
foo()
$ nim r /tmp/t.nim 
Hint: used config file '/home/ico/external/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/ico/external/Nim/config/config.nims' [Conf]
..............................................................................
/home/ico/sandbox/prjs/cps/cps/environment.nim(390, 16) Warning: pending https://github.com/nim-lang/Nim/issues/17851 [User]
..
/home/ico/sandbox/prjs/cps/cps/transform.nim(1138, 12) Warning: compiler bug workaround, see: https://github.com/nim-lang/Nim/issues/18349 [User]
..
/home/ico/sandbox/prjs/cps/cps/exprs.nim(176, 13) template/generic instantiation of `filterExpr` from here
/home/ico/sandbox/prjs/cps/cps/exprs.nim(107, 14) Warning: compiler workaround here, see: https://github.com/nim-lang/Nim/issues/18351 [User]
/home/ico/sandbox/prjs/cps/cps/exprs.nim(176, 13) template/generic instantiation of `filterExpr` from here
/home/ico/sandbox/prjs/cps/cps/exprs.nim(118, 14) Warning: compiler workaround here, see: https://github.com/nim-lang/Nim/issues/18351 [User]
/home/ico/sandbox/prjs/cps/cps/exprs.nim(323, 12) Warning: compiler workaround here, see: https://github.com/nim-lang/Nim/issues/18352 [User]
/home/ico/sandbox/prjs/cps/cps.nim(12, 12) Warning: cps supports --gc:arc or --gc:orc only; see https://github.com/nim-lang/Nim/issues/18099 [User]
/home/ico/sandbox/prjs/cps/cps.nim(17, 12) Warning: cps supports --panics:on only;  see https://github.com/disruptek/cps/issues/110 [User]
/home/ico/sandbox/prjs/cps/cps.nim(69, 16) Warning: compiler bug workaround, see: https://github.com/nim-lang/Nim/issues/18349 [User]
.........
/tmp/t.nim(16, 14) template/generic instantiation of `cps` from here
/tmp/t.nim(17, 3) Error: incorrect result proc symbol

zevv avatar Jul 25 '21 17:07 zevv

Seems to be a compiler bug.

/home/adavidoff/git/Nim/compiler/semstmts.nim(1636) maybeAddResult
/home/adavidoff/git/Nim/compiler/semstmts.nim(1490) addResult
/home/adavidoff/git/Nim/lib/system/fatal.nim(53) sysFatal
Error: unhandled exception: 'sym' is not accessible using discriminant 'kind' of type 'TNode' [FieldDefect]

Maybe we simply need to strip the pesky result symbol from all internal procdefs as a workaround pass?

/cc @alaviss

disruptek avatar Aug 08 '21 23:08 disruptek

Stripping the result symbol didn't help, FWIW.

disruptek avatar Sep 11 '21 21:09 disruptek

Works as of 21775374ed1980b30dfd251c4c391080d652b627.

disruptek avatar Nov 30 '22 22:11 disruptek