mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-29 09:24:36 +00:00
* .forbids pragma: defining illegal effects for proc types This patch intends to define the opposite of the .tags pragma: a way to define effects which are not allowed in a proc. * updated documentation and changelogs for the forbids pragma * renamed notTagEffects to forbiddenEffects * corrected issues of forbids pragma the forbids pragma didn't handle simple restrictions properly and it also had issues with subtyping * removed incorrect character from changelog * added test to cover the interaction of methods and the forbids pragma * covering the interaction of the tags and forbids pragmas * updated manual about the forbids pragma * removed useless statement * corrected the subtyping of proc types using the forbids pragma * updated manual for the forbids pragma * updated documentations for forbids pragma * updated nim docs * updated docs with rsttester.nim * regenerated documentation * updated rst docs * Update changelog.md Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> * updated changelog * corrected typo Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
53 lines
1.5 KiB
Nim
53 lines
1.5 KiB
Nim
discard """
|
|
action: compile
|
|
"""
|
|
|
|
import std/locks
|
|
|
|
type
|
|
Test2Effect* = object
|
|
Test2* = object
|
|
value2*: int
|
|
Test1Effect* = object
|
|
Test1* = object
|
|
value1*: int
|
|
Main* = object
|
|
test1Lock: Lock
|
|
test1: Test1
|
|
test2Lock: Lock
|
|
test2: Test2
|
|
|
|
proc `=copy`(obj1: var Test2, obj2: Test2) {.error.}
|
|
proc `=copy`(obj1: var Test1, obj2: Test1) {.error.}
|
|
proc `=copy`(obj1: var Main, obj2: Main) {.error.}
|
|
|
|
proc withTest1(main: var Main,
|
|
fn: proc(test1: var Test1) {.gcsafe, forbids: [Test1Effect].}) {.gcsafe, tags: [Test1Effect, RootEffect].} =
|
|
withLock(main.test1Lock):
|
|
fn(main.test1)
|
|
|
|
proc withTest2(main: var Main,
|
|
fn: proc(test1: var Test2) {.gcsafe, forbids: [Test2Effect].}) {.gcsafe, tags: [Test2Effect, RootEffect].} =
|
|
withLock(main.test2Lock):
|
|
fn(main.test2)
|
|
|
|
proc newMain(): Main =
|
|
var test1lock: Lock
|
|
initLock(test1Lock)
|
|
var test2lock: Lock
|
|
initLock(test2Lock)
|
|
var main = Main(test1Lock: move(test1Lock), test1: Test1(value1: 1),
|
|
test2Lock: move(test2Lock), test2: Test2(value2: 2))
|
|
main.withTest1(proc(test1: var Test1) = test1.value1 += 1)
|
|
main.withTest2(proc(test2: var Test2) = test2.value2 += 1)
|
|
move main
|
|
|
|
var main = newMain()
|
|
main.withTest1(proc(test1: var Test1) =
|
|
test1.value1 += 1
|
|
main.withTest2(proc(test2: var Test2) = test2.value2 += 1)
|
|
)
|
|
|
|
main.withTest1(proc(test1: var Test1) {.tags: [].} = echo $test1.value1)
|
|
main.withTest2(proc(test2: var Test2) {.tags: [].} = echo $test2.value2)
|