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>
This commit is contained in:
Juan M Gómez
2023-05-21 03:44:43 +01:00
committed by GitHub
parent 44f059c75e
commit 5606702e6d
3 changed files with 9 additions and 4 deletions

View File

@@ -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]

View File

@@ -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:

View File

@@ -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)