From f4a660d1b216d2af161f08e5a6d95ae396db1fe7 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 29 Nov 2023 13:50:50 +0000 Subject: [PATCH] implement `experimental:vtableMethods` --- changelog.md | 2 +- compiler/cgen.nim | 2 +- compiler/cgmeth.nim | 2 +- compiler/condsyms.nim | 2 ++ compiler/nim.cfg | 5 ++++- compiler/options.nim | 3 ++- compiler/sem.nim | 2 +- lib/system.nim | 2 +- lib/system/arc.nim | 7 +++---- tests/config.nims | 3 +-- tests/generics/tobjecttyperel.nim | 2 +- tests/method/tgeneric_methods.nim | 2 +- tests/method/tmethods_old.nim | 2 +- 13 files changed, 20 insertions(+), 16 deletions(-) diff --git a/changelog.md b/changelog.md index fb70a9a6b088d..bbed88b3ff2ad 100644 --- a/changelog.md +++ b/changelog.md @@ -5,7 +5,7 @@ - `-d:nimStrictDelete` becomes the default. An index error is produced when the index passed to `system.delete` was out of bounds. Use `-d:nimAuditDelete` to mimic the old behavior for backwards compatibility. - The default user-agent in `std/httpclient` has been changed to `Nim-httpclient/` instead of `Nim httpclient/` which was incorrect according to the HTTP spec. -- Methods now support implementations based on vtable by using `-d:nimPreviewVtables`. methods are confined in the same module where the type has been defined. +- Methods now support implementations based on vtable by using `--experimental:vtableMethods`. methods are confined in the same module where the type has been defined. - With `-d:nimPreviewNonVarDestructor`, non-var destructors become the default. ## Standard library additions and changes diff --git a/compiler/cgen.nim b/compiler/cgen.nim index e159c41c9d9b8..d3b56961126b0 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -2234,7 +2234,7 @@ proc finalCodegenActions*(graph: ModuleGraph; m: BModule; n: PNode) = incl m.flags, objHasKidsValid if optMultiMethods in m.g.config.globalOptions or m.g.config.selectedGC notin {gcArc, gcOrc, gcAtomicArc} or - not m.g.config.isDefined("nimPreviewVtables"): + vtableMethods notin m.g.config.features: generateIfMethodDispatchers(graph, m.idgen) diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index 3bbe7b3f4a0d4..6f4b62ff69145 100644 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -157,7 +157,7 @@ proc fixupDispatcher(meth, disp: PSym; conf: ConfigRef) = proc methodDef*(g: ModuleGraph; idgen: IdGenerator; s: PSym) = var witness: PSym = nil - if s.typ[1].owner.getModule != s.getModule and g.config.isDefined("nimPreviewVtables"): + if s.typ[1].owner.getModule != s.getModule and vtableMethods in g.config.features and not g.config.isDefined("nimInternalNonVtablesTesting"): localError(g.config, s.info, errGenerated, "method `" & s.name.s & "` can be defined only in the same module with its type (" & s.typ[1].typeToString() & ")") for i in 0..