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

recursive default call in type sections: invalid type in this context for proc #13048

Open
mratsim opened this issue Jan 5, 2020 · 2 comments

Comments

@mratsim
Copy link
Collaborator

mratsim commented Jan 5, 2020

The following doesn't compile

type
  Enqueueable* {.explain.} = concept x, type T
    x is ptr
    x.next is T

  Queue*[T: Enqueueable] = object
    count: int
    back: T
    front: typeof(default(T)[])

  Foo = ptr object
    next: Foo

  FooWrapper = ptr object
    next: FooWrapper
    foo: Foo
    bar: Bar

  Bar = ptr object
    queue: Queue[FooWrapper]

While I use concept here I think it's related to the nested default calls.

This builds up on the following issues:

@mratsim
Copy link
Collaborator Author

mratsim commented Jan 5, 2020

The following custom deref prevents the issue from happening:

macro deref*(T: typedesc): typedesc =
  echo T.getTypeInst.treerepr
  let instantiated = T.getTypeInst
  instantiated.expectkind(nnkBracketExpr)
  doAssert instantiated[0].eqIdent"typeDesc"

  let ptrT = instantiated[1]
  let ptrTImpl = instantiated[1].getImpl

  ptrTimpl.expectKind(nnkTypeDef)
  ptrTImpl[2].expectKind(nnkPtrTy)
  ptrTImpl[2][0].expectKind(nnkObjectTy)

  result = getType(ptrTImpl[2][0])

type
  Enqueueable* {.explain.} = concept x, type T
    x is ptr
    x.next is T

  Queue*[T: Enqueueable] = object
    count: int
    back: T
    front: deref(T)

  Foo = ptr object
    next: Foo

  FooWrapper = ptr object
    next: FooWrapper
    foo: Foo
    bar: Bar

  Bar = ptr object
    queue: Queue[FooWrapper]

var q: Queue[FooWrapper]
echo q

@mratsim
Copy link
Collaborator Author

mratsim commented Jan 5, 2020

But unfortunately, creating a pointer from the "deref"-ed type doesn't match the original

  type
    Task = ptr object
      prev, next: Task
      parent: Task
      fn: proc (param: pointer) {.nimcall.}
      # User data
      data: array[10, byte]

  var t = create(deref(Task))
  doAssert t is Task

mratsim added a commit to mratsim/weave that referenced this issue Jan 5, 2020
mratsim added a commit to mratsim/weave that referenced this issue Jan 7, 2020
* Stash pledges, blocked by nim-lang/Nim#13048

* Workaround nim-lang/Nim#13048

* Pass the pledges implementation tests

* Prepare for supporting mixed single and iteration pledges

* move pledge access counter to the impl. + Move file to channels subfolder

* add iteration pledges

* Sanity checks for loop pledges

* create fulfill public API

* Prepare parallel_tasks for supporting pledges

* Add dataflow graph parallelism 💥 🎆

* Add daflow support to parallel for loops

* Fix atomics + assert templates visibility on some platforms

* remove anti overwrite check (not true as compilers don't always zero-init)

* Please the template early symbol resolution god

* Nestable GEMM reaching 2.87TFlops for a speedup of 17.96 on 18 cores machines

* dependent loops

* Prepare for multiple pledge dependencies support

* Support joining dataflow graph

* bindSym + augment TaskDataSize

* Awaitable for loop now returns true if it was the last iteration to await

* Fix + test againt vendor BLAS, still one non-nestable barrier :/ (but consistently 17.5x speedup)

* typos

* Allow failure on C++
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants