This is an automated email from the ASF dual-hosted git repository.
sergeykamov pushed a commit to branch NLPCRAFT-500
in repository https://gitbox.apache.org/repos/asf/incubator-nlpcraft.git
The following commit(s) were added to refs/heads/NLPCRAFT-500 by this push:
new c65837a5 WIP.
c65837a5 is described below
commit c65837a5c37924316f0e83f4867ef604a67ac379
Author: Sergey Kamov <[email protected]>
AuthorDate: Wed Aug 24 22:49:27 2022 +0300
WIP.
---
.../nlpcraft/internal/impl/NCModelScanner.scala | 39 ++++++++++++----------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
index f957c198..db57764a 100644
---
a/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
+++
b/nlpcraft/src/main/scala/org/apache/nlpcraft/internal/impl/NCModelScanner.scala
@@ -414,6 +414,19 @@ object NCModelScanner extends LazyLogging:
var compiler = new NCIDLCompiler(mdl.getConfig)
+ def callNoCache[T](f: () => T): T =
+ val cp = compiler.clone()
+ try f()
+ finally compiler = cp
+
+ def callNoCacheOnError[T](f: () => T): T =
+ val cp = compiler.clone()
+ try
+ f()
+ catch case e: Throwable =>
+ compiler = cp
+ throw e
+
val cfg = mdl.getConfig
lazy val z = s"mdlId=${cfg.getId}"
val intentsMtds = mutable.HashMap.empty[Method, IntentHolder]
@@ -443,13 +456,8 @@ object NCModelScanner extends LazyLogging:
// 1. First pass.
for (ann <- anns)
- val copy = compiler.clone()
- try
- addIntents(ann)
- catch
- case _: NCException =>
- compiler = copy
- errAnns += ann
+ try callNoCacheOnError(() => addIntents(ann))
+ catch case _: NCException => errAnns += ann
// 2. Second pass.
for (ann <- errAnns) addIntents(ann)
@@ -480,16 +488,13 @@ object NCModelScanner extends LazyLogging:
// // Collects intents for each method.
for (mtd <- methods)
- val copy = compiler.clone()
-
- try
- for (
- ann <- mtd.getAnnotationsByType(CLS_INTENT);
- intent <- compiler.compile(ann.value, method2Str(mtd))
- )
- addDecl(intent)
- addIntent(intent, mtd, obj)
- finally compiler = copy
+ callNoCache(
+ () =>
+ for (ann <- mtd.getAnnotationsByType(CLS_INTENT);
intent <- compiler.compile(ann.value, method2Str(mtd)))
+ addDecl(intent)
+ addIntent(intent, mtd, obj)
+ )
+
scan(mdl)
// Second phase. For model and all its references scans each method
and finds intents references (NCIntentRef)