-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
new syntax for lvalue references: var b {.byaddr.} = expr
#13508
Conversation
Pretty good. However, either use an AST to AST transformation inside semexprs only without the helper public symbols in system.nim, or let's fix pragmas for variables so that is can be done entirely as a template/macro. |
@timotheecour Can you please also document this in the manual in the Pragmas section: https://nim-lang.github.io/Nim/manual#pragmas ? Thanks. |
Aren't references a feature that is left out in Nim for reasons? |
1b5def3
to
eaccc04
Compare
eaccc04
to
81d8c2f
Compare
@Araq PTAL
done compiler now lowers there are othe applications for this new compiler feature besides the current
|
@Araq friendly ping (I'll rebase to fix |
…e, expr) * new pragmas.byaddr defined in pure library code exploiting this lowering
1ec0f41
to
8336443
Compare
TLDR
var b {.byaddr.} = expr
, eg:auto& b = expr;
byaddr x = expr
#13342 which can be closed if this is mergedbyRef: myref=x[1].foo[2]
#11824 which can be closed if this is mergedbyRef: myref=x[1].foo[2]
#11824 for rationale, examples etccompared to #13342 and #11824
(some of these are comparisons to only #13342 or only #11824 or both)
Error: redefinition
error #8275in particular giving a redefinition error with [superseded] ref syntax for lvalue expressions:
byRef: myref=x[1].foo[2]
#11824 approach would've been trickier to do correctly (we should only check in current scope)var b {.byaddr.}: int = s[0]
var
for now; so it's easier to extend, egvar b {.byunsafeaddr.}: int = s[0]
if neededbyaddr x = expr
#13342 (comment)I can change to
view
which is short and explicit, but I'd rather do the change just once, after this is greenlightedexample
future PR's
byaddr
must have a single element, support for more than 1 could be added in future (will be backward compatible of course)let b {.byaddr.} = expr
if needednote
this should replace at least some use cases for
shallowCopy
and{.shallow.}