diff options
author | Juan M Gómez <info@jmgomez.me> | 2023-05-21 03:44:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-21 04:44:43 +0200 |
commit | 5606702e6d9aa583141c975f45534d0f55d9acc9 (patch) | |
tree | dc80722ef4d63b9c18d0947d2f020f4b48aa20a9 | |
parent | 44f059c75ee6db2278c671e3da18eb9af390b937 (diff) | |
download | Nim-5606702e6d9aa583141c975f45534d0f55d9acc9.tar.gz |
implements: "Allow bycopy to work in params #21874" (#21877)
* implements: "Allow bycopy to work in params #21874" * Update compiler/pragmas.nim --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
-rw-r--r-- | compiler/ast.nim | 3 | ||||
-rw-r--r-- | compiler/ccgutils.nim | 4 | ||||
-rw-r--r-- | compiler/pragmas.nim | 6 |
3 files changed, 9 insertions, 4 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 7e92cd140..da9b3898e 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -231,7 +231,7 @@ type TNodeKinds* = set[TNodeKind] type - TSymFlag* = enum # 50 flags! + TSymFlag* = enum # 51 flags! sfUsed, # read access of sym (for warnings) or simply used sfExported, # symbol is exported from module sfFromGeneric, # symbol is instantiation of a generic; this is needed @@ -313,6 +313,7 @@ type # This is disallowed but can cause the typechecking to go into # an infinite loop, this flag is used as a sentinel to stop it. sfVirtual # proc is a C++ virtual function + sfByCopy # param is marked as pass bycopy TSymFlags* = set[TSymFlag] diff --git a/compiler/ccgutils.nim b/compiler/ccgutils.nim index d9aa58c67..ea4f3fe18 100644 --- a/compiler/ccgutils.nim +++ b/compiler/ccgutils.nim @@ -122,8 +122,10 @@ proc ccgIntroducedPtr*(conf: ConfigRef; s: PSym, retType: PType): bool = var pt = skipTypes(s.typ, typedescInst) assert skResult != s.kind + #note precedence: params override types if optByRef in s.options: return true - if tfByRef in pt.flags: return true + elif sfByCopy in s.flags: return false + elif tfByRef in pt.flags: return true elif tfByCopy in pt.flags: return false case pt.kind of tyObject: diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index bc375b1bc..11305db2a 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -84,7 +84,7 @@ const wGensym, wInject, wIntDefine, wStrDefine, wBoolDefine, wDefine, wCompilerProc, wCore} - paramPragmas* = {wNoalias, wInject, wGensym, wByRef} + paramPragmas* = {wNoalias, wInject, wGensym, wByRef, wByCopy} letPragmas* = varPragmas procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNoSideEffect, wThread, wRaises, wEffectsOf, wLocks, wTags, wForbids, wGcSafe, @@ -1204,7 +1204,9 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, incl(sym.typ.flags, tfByRef) of wByCopy: noVal(c, it) - if sym.kind != skType or sym.typ == nil: invalidPragma(c, it) + if sym.kind == skParam: + incl(sym.flags, sfByCopy) + elif sym.kind != skType or sym.typ == nil: invalidPragma(c, it) else: incl(sym.typ.flags, tfByCopy) of wPartial: noVal(c, it) |