remove the need for the .procvar annotation
This commit is contained in:
parent
e8cfa14354
commit
08f5087d2c
4 changed files with 37 additions and 30 deletions
|
|
@ -514,8 +514,17 @@ proc propagateEffects(tracked: PEffects, n: PNode, s: PSym) =
|
||||||
markSideEffect(tracked, s)
|
markSideEffect(tracked, s)
|
||||||
mergeLockLevels(tracked, n, s.getLockLevel)
|
mergeLockLevels(tracked, n, s.getLockLevel)
|
||||||
|
|
||||||
|
proc procVarcheck(n: PNode) =
|
||||||
|
if n.kind in nkSymChoices:
|
||||||
|
for x in n: procVarCheck(x)
|
||||||
|
elif n.kind == nkSym and n.sym.magic != mNone:
|
||||||
|
localError(n.info, errXCannotBePassedToProcVar, n.sym.name.s)
|
||||||
|
|
||||||
proc notNilCheck(tracked: PEffects, n: PNode, paramType: PType) =
|
proc notNilCheck(tracked: PEffects, n: PNode, paramType: PType) =
|
||||||
let n = n.skipConv
|
let n = n.skipConv
|
||||||
|
procVarcheck skipConvAndClosure(n)
|
||||||
|
#elif n.kind in nkSymChoices:
|
||||||
|
# echo "came here"
|
||||||
if paramType != nil and tfNotNil in paramType.flags and
|
if paramType != nil and tfNotNil in paramType.flags and
|
||||||
n.typ != nil and tfNotNil notin n.typ.flags:
|
n.typ != nil and tfNotNil notin n.typ.flags:
|
||||||
if n.kind == nkAddr:
|
if n.kind == nkAddr:
|
||||||
|
|
|
||||||
|
|
@ -71,27 +71,29 @@ proc toCover(t: PType): BiggestInt =
|
||||||
else:
|
else:
|
||||||
result = lengthOrd(skipTypes(t, abstractVar-{tyTypeDesc}))
|
result = lengthOrd(skipTypes(t, abstractVar-{tyTypeDesc}))
|
||||||
|
|
||||||
proc performProcvarCheck(c: PContext, info: TLineInfo, s: PSym) =
|
when false:
|
||||||
## Checks that the given symbol is a proper procedure variable, meaning
|
proc performProcvarCheck(c: PContext, info: TLineInfo, s: PSym) =
|
||||||
## that it
|
## Checks that the given symbol is a proper procedure variable, meaning
|
||||||
var smoduleId = getModule(s).id
|
## that it
|
||||||
if sfProcvar notin s.flags and s.typ.callConv == ccDefault and
|
var smoduleId = getModule(s).id
|
||||||
smoduleId != c.module.id:
|
if sfProcvar notin s.flags and s.typ.callConv == ccDefault and
|
||||||
block outer:
|
smoduleId != c.module.id:
|
||||||
for module in c.friendModules:
|
block outer:
|
||||||
if smoduleId == module.id:
|
for module in c.friendModules:
|
||||||
break outer
|
if smoduleId == module.id:
|
||||||
localError(info, errXCannotBePassedToProcVar, s.name.s)
|
break outer
|
||||||
|
localError(info, errXCannotBePassedToProcVar, s.name.s)
|
||||||
|
|
||||||
proc semProcvarCheck(c: PContext, n: PNode) =
|
template semProcvarCheck(c: PContext, n: PNode) =
|
||||||
var n = n.skipConv
|
when false:
|
||||||
if n.kind in nkSymChoices:
|
var n = n.skipConv
|
||||||
for x in n:
|
if n.kind in nkSymChoices:
|
||||||
if x.sym.kind in {skProc, skMethod, skConverter, skIterator}:
|
for x in n:
|
||||||
performProcvarCheck(c, n.info, x.sym)
|
if x.sym.kind in {skProc, skMethod, skConverter, skIterator}:
|
||||||
elif n.kind == nkSym and n.sym.kind in {skProc, skMethod, skConverter,
|
performProcvarCheck(c, n.info, x.sym)
|
||||||
skIterator}:
|
elif n.kind == nkSym and n.sym.kind in {skProc, skMethod, skConverter,
|
||||||
performProcvarCheck(c, n.info, n.sym)
|
skIterator}:
|
||||||
|
performProcvarCheck(c, n.info, n.sym)
|
||||||
|
|
||||||
proc semProc(c: PContext, n: PNode): PNode
|
proc semProc(c: PContext, n: PNode): PNode
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1003,16 +1003,6 @@ Nim supports these `calling conventions`:idx:\:
|
||||||
|
|
||||||
Most calling conventions exist only for the Windows 32-bit platform.
|
Most calling conventions exist only for the Windows 32-bit platform.
|
||||||
|
|
||||||
Assigning/passing a procedure to a procedural variable is only allowed if one
|
|
||||||
of the following conditions hold:
|
|
||||||
1) The procedure that is accessed resides in the current module.
|
|
||||||
2) The procedure is marked with the ``procvar`` pragma (see `procvar pragma <#pragmas-procvar-pragma>`_).
|
|
||||||
3) The procedure has a calling convention that differs from ``nimcall``.
|
|
||||||
4) The procedure is anonymous.
|
|
||||||
|
|
||||||
The rules' purpose is to prevent the case that extending a non-``procvar``
|
|
||||||
procedure with default parameters breaks client code.
|
|
||||||
|
|
||||||
The default calling convention is ``nimcall``, unless it is an inner proc (a
|
The default calling convention is ``nimcall``, unless it is an inner proc (a
|
||||||
proc inside of a proc). For an inner proc an analysis is performed whether it
|
proc inside of a proc). For an inner proc an analysis is performed whether it
|
||||||
accesses its environment. If it does so, it has the calling convention
|
accesses its environment. If it does so, it has the calling convention
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,12 @@ found `here <http://nim-lang.org/docs/manual.html#pragmas-used-pragma>`_.
|
||||||
This is particularly useful for DSLs that help in tree construction.
|
This is particularly useful for DSLs that help in tree construction.
|
||||||
|
|
||||||
|
|
||||||
|
Language changes
|
||||||
|
----------------
|
||||||
|
|
||||||
|
- The ``.procvar`` annotation is not required anymore. That doesn't mean you
|
||||||
|
can pass ``system.$`` to ``map`` just yet though.
|
||||||
|
|
||||||
|
|
||||||
Bugfixes
|
Bugfixes
|
||||||
--------
|
--------
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue