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

Some slicing syntaxes fails inside generics #62

Open
edubart opened this issue Sep 23, 2017 · 3 comments
Open

Some slicing syntaxes fails inside generics #62

edubart opened this issue Sep 23, 2017 · 3 comments

Comments

@edubart
Copy link
Contributor

edubart commented Sep 23, 2017

import arraymancer

proc test[T](t: Tensor[T]) =
  discard t[^1..0|-1] # fails
  discard t[0..1] # fails
  discard t[0..^1] # fails
  discard t[0..1|1] # works
  discard t[_] # works
  discard t[0] # works

zeros([2], int).test()
@mratsim
Copy link
Owner

mratsim commented Sep 23, 2017

It seems like for generics, macros are called before symbol resolution (but after identifier resolution).

This means that instead of giving me the proper symbol, Nim returns all the procs that are possible match:

Example for t[0..1]

------------------
Original tree
Arglist
  Infix
    OpenSymChoice
      Sym ".."
      Sym ".."
      Sym ".."
      Sym ".."
    Prefix
      OpenSymChoice
        Sym "^"
        Sym "^"
        Sym "^"
        Sym "^"
        Sym "^"
      IntLit 1
      Ident !"t"
    IntLit 1

Concretly that means that I have to redo my macros and have a specific test suite for generic procs.

@mratsim
Copy link
Owner

mratsim commented Jan 22, 2018

Something to try from PMunch:

https://github.com/zah/grip-lang/blob/master/compiler/patterns.nim#L69

proc inSymChoice(sc, x: PNode): bool =
  if sc.kind == nkClosedSymChoice:
    for i in 0.. <sc.len:
      if sc.sons[i].sym == x.sym: return true
  elif sc.kind == nkOpenSymChoice:
    # same name suffices for open sym choices!
    result = sc.sons[0].sym.name.id == x.sym.name.id

@mratsim
Copy link
Owner

mratsim commented May 10, 2018

Nim standard library is also struggling with macro/templates + Generics: nim-lang/Nim#7632 (strformat) and nim-lang/Nim#5053 ({.this: self.} pragma)

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