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

template/macro pragmas don't work in templates (eg: byaddr, since etc) #15920

Closed
Clonkk opened this issue Nov 11, 2020 · 2 comments · Fixed by #19406
Closed

template/macro pragmas don't work in templates (eg: byaddr, since etc) #15920

Clonkk opened this issue Nov 11, 2020 · 2 comments · Fixed by #19406

Comments

@Clonkk
Copy link
Contributor

Clonkk commented Nov 11, 2020

Using byaddrin a template does not compile while the same code inside a block works.

Example

import std/decls

template test(x: string)=
  var y {.byaddr.} = x
  echo y
 
var xx = "123"
test(xx)

Current Output

 template/generic instantiation of `test` from here
 Error: invalid pragma: byaddr

Expected Output

123

$ nim -v

Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2020-11-11
Copyright (c) 2006-2020 by Andreas Rumpf

git hash: bbe49a14ae827b6474d692042406716a3b3dd71f
active boot switches: -d:release

[EDIT]

@ringabout
Copy link
Member

There are some problems with using user-defined pragmas in templates

template pro(a: untyped) =
  discard

template test() =
  var y {.pro.} = 10

test()

They are both related to resolveOverloads.

@timotheecour
Copy link
Member

I've been tracking this + related issues, this isn't specific to byaddr but is more general:

template foo(lhs, typ, expr) =
  let lhs = expr
proc fun1()=
  let a {.foo.} = 1
template fun2()=
  let a {.foo.} = 1
fun1() # ok
fun2() # BUG: Error: invalid pragma: foo
template bar(a, body: untyped) {.dirty, used.} = discard
proc fun1() {.bar: 1.} = discard # ok
template fun2() {.bar: 1.} = discard # error: Error: cannot attach a custom pragma to 'fun2'

when false: # ditto with these
  template bar2(body: untyped) {.dirty, used.} = discard
  template bar3(body: untyped) = discard
  template fun2() {.bar2.} = discard
  template fun3() {.bar3.} = discard
template fun(body: untyped): untyped = echo "ok1"
{.pragma: callfun, fun.}
proc bar1() {.fun.} = echo "ok2" # ok
proc bar2() {.callfun.} = echo "ok2" # Error: invalid pragma: fun

related WIP PR's

@timotheecour timotheecour changed the title Using byaddr in template fails to compile template/macro pragmas don't work in templates (eg: byaddr, since etc) Nov 13, 2020
@timotheecour timotheecour removed their assignment Jun 8, 2021
Araq pushed a commit that referenced this issue Aug 11, 2021
…n `foo` is overloaded) (#13869)

* fix: `var a{.foo.} = expr` inside templates
* add test
* improve tdecls test
* improve tests
* add failing test
* PRTEMP
* fixup
metagn added a commit to metagn/Nim that referenced this issue Jan 17, 2022
fix nim-lang#15920, close nim-lang#18212, close nim-lang#14781, close nim-lang#6696,
close nim-lang/RFCs#220

Variable macro pragmas have been changed to
only take a unary section node.
They can now also be applied in sections with multiple variables,
as well as `const` sections. They also accept arguments.

Templates now support macro pragmas, mirroring other routine types.

Type and variable macro pragmas have been made experimental.
Symbols without parentheses instatiating nullary macros or templates
has also been documented in the experimental manual.

A check for a redefinition error based on the left hand side of variable
definitions when using variable macro pragmas was disabled.
This nerfs `byaddr` specifically, however this has been documented as
a consequence of the experimental features `byaddr` uses.

Given how simple these changes are I'm worried if I'm missing something.
Araq pushed a commit that referenced this issue Jan 20, 2022
* New/better macro pragmas, make some experimental

fix #15920, close #18212, close #14781, close #6696,
close nim-lang/RFCs#220

Variable macro pragmas have been changed to
only take a unary section node.
They can now also be applied in sections with multiple variables,
as well as `const` sections. They also accept arguments.

Templates now support macro pragmas, mirroring other routine types.

Type and variable macro pragmas have been made experimental.
Symbols without parentheses instatiating nullary macros or templates
has also been documented in the experimental manual.

A check for a redefinition error based on the left hand side of variable
definitions when using variable macro pragmas was disabled.
This nerfs `byaddr` specifically, however this has been documented as
a consequence of the experimental features `byaddr` uses.

Given how simple these changes are I'm worried if I'm missing something.

* accomodate compiler boot

* allow weird pragmas

* add test for #10994

* remove some control flow, try remove some logic
PMunch pushed a commit to PMunch/Nim that referenced this issue Mar 28, 2022
…cept when `foo` is overloaded) (nim-lang#13869)

* fix: `var a{.foo.} = expr` inside templates
* add test
* improve tdecls test
* improve tests
* add failing test
* PRTEMP
* fixup
PMunch pushed a commit to PMunch/Nim that referenced this issue Mar 28, 2022
* New/better macro pragmas, make some experimental

fix nim-lang#15920, close nim-lang#18212, close nim-lang#14781, close nim-lang#6696,
close nim-lang/RFCs#220

Variable macro pragmas have been changed to
only take a unary section node.
They can now also be applied in sections with multiple variables,
as well as `const` sections. They also accept arguments.

Templates now support macro pragmas, mirroring other routine types.

Type and variable macro pragmas have been made experimental.
Symbols without parentheses instatiating nullary macros or templates
has also been documented in the experimental manual.

A check for a redefinition error based on the left hand side of variable
definitions when using variable macro pragmas was disabled.
This nerfs `byaddr` specifically, however this has been documented as
a consequence of the experimental features `byaddr` uses.

Given how simple these changes are I'm worried if I'm missing something.

* accomodate compiler boot

* allow weird pragmas

* add test for nim-lang#10994

* remove some control flow, try remove some logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants