From 02a1a083ed41867514b3499a0b3a8addb4b01ed4 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 21 Dec 2023 11:15:44 +0800 Subject: [PATCH 1/4] update action versions (#23109) --- .github/workflows/ci_docs.yml | 4 ++-- .github/workflows/ci_publish.yml | 2 +- .github/workflows/stale.yml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci_docs.yml b/.github/workflows/ci_docs.yml index 32e8e050e4a00..2faa37ce0abba 100644 --- a/.github/workflows/ci_docs.yml +++ b/.github/workflows/ci_docs.yml @@ -45,7 +45,7 @@ jobs: - target: windows os: windows-2019 - target: osx - os: macos-11 + os: macos-12 name: ${{ matrix.target }} runs-on: ${{ matrix.os }} @@ -109,7 +109,7 @@ jobs: if: | github.event_name == 'push' && github.ref == 'refs/heads/devel' && matrix.target == 'linux' - uses: crazy-max/ghaction-github-pages@v3 + uses: crazy-max/ghaction-github-pages@v4 with: build_dir: doc/html env: diff --git a/.github/workflows/ci_publish.yml b/.github/workflows/ci_publish.yml index 58da92206dea5..decfe953ecc9e 100644 --- a/.github/workflows/ci_publish.yml +++ b/.github/workflows/ci_publish.yml @@ -71,7 +71,7 @@ jobs: run: nim c -r -d:release ci/action.nim - name: 'Comment' - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: script: | const fs = require('fs'); diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index d89a4888a1b7e..0c5a533e1d5d9 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -9,7 +9,7 @@ jobs: stale: runs-on: ubuntu-latest steps: - - uses: actions/stale@v8 + - uses: actions/stale@v9 with: days-before-pr-stale: 365 days-before-pr-close: 30 From 4321ce2635cc91a975580e8a74bff70cf5d8aadf Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 21 Dec 2023 14:58:17 +0800 Subject: [PATCH 2/4] fixes nimdoc warnings (#23110) --- doc/manual_experimental.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/manual_experimental.md b/doc/manual_experimental.md index 3b552ef8e571f..87381f6559654 100644 --- a/doc/manual_experimental.md +++ b/doc/manual_experimental.md @@ -2450,7 +2450,7 @@ main() Will produce: -```c++ +```cpp struct Test { Foo foo; From b15463948c6f78a546742fc5c521fa2f6e8f9312 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Thu, 21 Dec 2023 15:56:02 +0800 Subject: [PATCH 3/4] document `--experimental:vtables` (#23111) --- doc/manual_experimental.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/doc/manual_experimental.md b/doc/manual_experimental.md index 87381f6559654..fc5ff19599aeb 100644 --- a/doc/manual_experimental.md +++ b/doc/manual_experimental.md @@ -2520,3 +2520,38 @@ NimFunctor()(1) ``` Notice we use the overload of `()` to have the same semantics in Nim, but on the `importcpp` we import the functor as a function. This allows to easy interop with functions that accepts for example a `const` operator in its signature. + +VTable for methods +================== + +Methods now support implementations based on a VTable by using `--experimental:vtables`. Note that the option needs to enabled +globally. The virtual method table is stored in the type info of +an object, which is an array of function pointers. + +```nim +method foo(x: Base, ...) {.base.} +method foo(x: Derived, ...) {.base.} +``` + +It roughly generates a dispatcher like + +```nim +proc foo_dispatch(x: Base, ...) = + x.typeinfo.vtable[method_index](x, ...) # method_index is the index of the sorted order of a method +``` + +Methods are required to be in the same module where their type has been defined. + +```nim +# types.nim +type + Base* = ref object +``` + +```nim +import types + +method foo(x: Base) {.base.} = discard +``` + +It gives an error: method `foo` can be defined only in the same module with its type (Base). From df3c95d8af7bfd1e61e6b06eec21f57781dff9d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20M=20G=C3=B3mez?= Date: Fri, 22 Dec 2023 04:38:40 +0000 Subject: [PATCH 4/4] makes nimsuggest `con` work under v3 (#23113) Co-authored-by: Jake Leahy --- nimsuggest/nimsuggest.nim | 9 ++++++--- nimsuggest/tests/tv3_con.nim | 13 +++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 nimsuggest/tests/tv3_con.nim diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim index 03a6e32e19007..1d48bf653d9c0 100644 --- a/nimsuggest/nimsuggest.nim +++ b/nimsuggest/nimsuggest.nim @@ -984,10 +984,10 @@ proc executeNoHooksV3(cmd: IdeCmd, file: AbsoluteFile, dirtyfile: AbsoluteFile, graph.unmarkAllDirty() # these commands require partially compiled project - elif cmd in {ideSug, ideOutline, ideHighlight, ideDef, ideChkFile, ideType, ideDeclaration, ideExpand} and - (graph.needsCompilation(fileIndex) or cmd == ideSug): + elif cmd in {ideSug, ideCon, ideOutline, ideHighlight, ideDef, ideChkFile, ideType, ideDeclaration, ideExpand} and + (graph.needsCompilation(fileIndex) or cmd in {ideSug, ideCon}): # for ideSug use v2 implementation - if cmd == ideSug: + if cmd in {ideSug, ideCon}: conf.m.trackPos = newLineInfo(fileIndex, line, col) conf.m.trackPosAttached = false else: @@ -1033,6 +1033,9 @@ proc executeNoHooksV3(cmd: IdeCmd, file: AbsoluteFile, dirtyfile: AbsoluteFile, # ideSug performs partial build of the file, thus mark it dirty for the # future calls. graph.markDirtyIfNeeded(file.string, fileIndex) + of ideCon: + graph.markDirty fileIndex + graph.markClientsDirty fileIndex of ideOutline: let n = parseFile(fileIndex, graph.cache, graph.config) graph.iterateOutlineNodes(n, graph.fileSymbols(fileIndex).deduplicateSymInfoPair) diff --git a/nimsuggest/tests/tv3_con.nim b/nimsuggest/tests/tv3_con.nim new file mode 100644 index 0000000000000..4714c366ba765 --- /dev/null +++ b/nimsuggest/tests/tv3_con.nim @@ -0,0 +1,13 @@ +# tests v3 + +proc test(a: string, b:string) = discard +proc test(a: int) = discard + +test(#[!]# + +discard """ +$nimsuggest --v3 --tester $file +>con $1 +con;;skProc;;tv3_con.test;;proc (a: string, b: string);;$file;;3;;5;;"";;100 +con;;skProc;;tv3_con.test;;proc (a: int);;$file;;4;;5;;"";;100 +"""