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

getImpl on type symbol hides implementation #10702

krux02 opened this issue Feb 17, 2019 · 1 comment


None yet
1 participant
Copy link

commented Feb 17, 2019

This is a regression, my normalizeType procedure relies on the old behavior.

To translate Nim type to glsl type I have a normalize type macro in fancygl. The type normalization dosn't work anymore. Now the ast has a node of type nnkType that I cannot do anything with from what the macros API provides. Before this, it was a call that contains more symbols.


This code is a stripped version of the original version. The vector type is normaly imported from nim_glm.

import macros

  VectorElementType = SomeNumber | bool
  Vec*[N : static[int], T: VectorElementType] = object
    arr*: array[N, T]

  Vec4*[T: VectorElementType] = Vec[4,T]
  Vec3*[T: VectorElementType] = Vec[3,T]
  Vec2*[T: VectorElementType] = Vec[2,T]

template vecGen(U:untyped,V:typed):typed=
  ## ``U`` suffix
  ## ``V`` valType
    `Vec2 U`* {.inject.} = Vec2[V]
    `Vec3 U`* {.inject.} = Vec3[V]
    `Vec4 U`* {.inject.} = Vec4[V]

vecGen(f, float32)

macro foobar(arg: typed): untyped =
  let typ = arg.getTypeInst
  echo typ.getImpl.lispRepr
  echo typ.getImpl.repr

  assert typ.getImpl[^1].kind == nnkCall

var x: Vec2f


Current Output

output of 6c8dee418072dbf047e6b21ab083547683656702

(TypeDef (PragmaExpr (Sym "Vec2f") (Pragma (Ident "inject"))) (Empty) (Type))
Vec2f {.inject.} = [type node]

Expected Output

output of 26255c72f Fix getCustomPragmaVal on `var` fields

(TypeDef (PragmaExpr (Sym "Vec2f") (Pragma (Ident "inject"))) (Empty) (Call (OpenSymChoice (Sym "[]") (Sym "[]") (Sym "[]") (Sym "[]") (Sym "[]") (Sym "[]") (Sym "[]") (Sym "[]") (Sym "[]") (Sym "[]") (Sym "[]") (Sym "[]") (Sym "[]")) (Sym "Vec2") (Sym "float32")))
Vec2f {.inject.} = Vec2[float32]

Additional Information

git bisect results

6c8dee418072dbf047e6b21ab083547683656702 is the first bad commit
commit 6c8dee418072dbf047e6b21ab083547683656702
Author: LemonBoy <>
Date:   Wed Feb 6 11:35:44 2019 +0100

    Avoid evaluating macros twice in type sections (#10550)
    Fixes #10548

:040000 040000 1c774b93d890cf541a1e3571454ef4d5c3f0f2ac d49ee8a769d64a194cab24eac5562fc8d6e19ab5 M	compiler
:040000 040000 e353c12caa1710bbbc4a101d34fd6cf224190875 645d87f9827074a64a02a294c0036e25c4048f95 M	tests

The bisect commend is koch temp <filename of example>.


This comment has been minimized.

Copy link
Contributor Author

commented Feb 17, 2019

@LemonBoy I would like to have your thoughts on it, since you worked on the PR that cause the breaking change. Do you think there is an alternative solution for #10548 or for my type normalization?

The type normalization is supposed to strip all Alias information and normalize to a generic type like Vec[4, float32], so that from this representation onwards it is possable to descide if the type is a builtin type of glsl, or if that type needs to be generated.

Araq added a commit that referenced this issue Feb 18, 2019

@Araq Araq closed this in 2deb1e3 Feb 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.