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

cannot get pointer to nested generic proc due to "unspecified generic parameters" even though they are specified #18059

Closed
alaviss opened this issue May 22, 2021 · 1 comment · Fixed by #18140
Labels
CPS bugs/pulls related to the cps project Generics Severe

Comments

@alaviss
Copy link
Collaborator

alaviss commented May 22, 2021

This bug concerns future development of CPS regarding the transformation of generic procedures.

Example

type
  C = ref object of RootObj
    fn: ContProc
    ex: ref Exception
  
  ContProc = proc(c: C): C {.nimcall.}

proc noop(c: C): C = c

when false:
  # original proc
  proc foo[T](x: T) {.cps.} =
    noop()
    echo x

type
  Env[T] = ref object of C
    x: T

proc foo_cont[U](c: C): C =
  proc afterCall[V](c: C): C =
    echo Env[V](c).x

  c.fn = afterCall[U]
  return noop(c)
  
proc foo[T](x: T): C =
  return Env[T](fn: foo_cont[T], x: x)

proc tramp(c: sink C) =
  while c != nil and c.fn != nil:
    c = c.fn(c)

tramp foo(10)
tramp foo("string")

Current Output

in.nim(34, 10) template/generic instantiation of `foo` from here
in.nim(28, 29) template/generic instantiation of `foo_cont` from here
in.nim(24, 10) Error: 'afterCall' doesn't have a concrete type, due to unspecified generic parameters.

Expected Output

This should compile correctly.

In fact, if you move afterCall to outside foo_cont, this compiles and functions perfectly.

In CPS these nested procs will be moved out at the end of the transformation, however during IR passes we keep them there, and this bug would prevent immediate code like this from successfully sem.

Additional Information

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-05-01
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 13b57524d35a18df57bec2a7d6a2faa7ce712e9f
active boot switches: -d:release -d:nimUseLinenoise
@alaviss alaviss added Generics CPS bugs/pulls related to the cps project labels May 22, 2021
@alaviss
Copy link
Collaborator Author

alaviss commented May 22, 2021

This is blocking try-finally transforms in CPS.

@Araq Araq added the Severe label May 31, 2021
Araq added a commit that referenced this issue May 31, 2021
@Araq Araq closed this as completed in f10eef2 Jun 2, 2021
PMunch pushed a commit to PMunch/Nim that referenced this issue Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CPS bugs/pulls related to the cps project Generics Severe
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants