cps icon indicating copy to clipboard operation
cps copied to clipboard

Unable to overload voodoo/magic by continuation types

Open shayanhabibi opened this issue 4 years ago • 3 comments

import cps
type
  C = ref object of Continuation
  O = ref object of C
  P = ref object of C

proc sayYourName(c: C): string {.cpsVoodoo.} = return "I am C"
proc sayYourName(c: O): string {.cpsVoodoo.} = return "I am O"
proc sayYourName(c: P): string {.cpsVoodoo.} = return "I am P"

Either as magic or voodoo this considers them all to be redefinitions. If I change parameter field names this still occurs.

Even if the objects ref different continuations I hit the same wall

type
  C = ref object of Continuation
  Z = ref object of Continuation
proc sayYourName(c: C): string {.cpsVoodoo.} = return "I am C"
proc sayYourName(c: Z): string {.cpsVoodoo.} = return "I am Z"

Changing parameter names does not help, leorize has offered knowledge into the origin of the matter.

WORK AROUND: His suggestion was to split the calls into separate modules. Doing so I was able to overload the calls and successfully make dynamic dispatch calls with continuations

See https://github.com/shayanhabibi/cpslearning/blob/main/dynamicdispatch/main.nim

shayanhabibi avatar Sep 14 '21 07:09 shayanhabibi

The main limitation for this is that we have to produce a version of magic/voodoo without the continuation parameter so that it can be matched by sigmatch before {.cps.} kicks in.

I can only think of two ways out:

  • Figure out how to create these continuation-less wrappers in a shadow scope then inject them into cps body in an untyped pass (see this union PR which have something like that)
  • Get cps in the compiler and we can use its scoping system.

This issue is low priority for now.

alaviss avatar Sep 14 '21 07:09 alaviss

#258 was reverted

alaviss avatar Nov 10 '21 21:11 alaviss

Future fixes to this bug needs to be aware of #259.

alaviss avatar Nov 10 '21 21:11 alaviss