From 522def7c1f52783d05b752cf38bc4fcf28121664 Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Sat, 23 Nov 2024 00:07:30 +0100 Subject: [PATCH 1/4] Improve matching of ignored items --- loki/batch/configure.py | 12 ++++++------ loki/batch/item.py | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/loki/batch/configure.py b/loki/batch/configure.py index ed8186b21..d46c440ba 100644 --- a/loki/batch/configure.py +++ b/loki/batch/configure.py @@ -5,7 +5,7 @@ # granted to it by virtue of its status as an intergovernmental organisation # nor does it submit to any jurisdiction. -from fnmatch import fnmatch +import fnmatch from itertools import accumulate from pathlib import Path import re @@ -183,10 +183,10 @@ def match_item_keys(item_name, keys, use_pattern_matching=False, match_item_pare } # Match against keys - keys = as_tuple(keys) + keys = tuple(key.lower() for key in as_tuple(keys)) if use_pattern_matching: - return tuple(key for key in keys or () if any(fnmatch(name, key.lower()) for name in item_names)) - return tuple(key for key in keys or () if key.lower() in item_names) + return tuple(key for key in keys if fnmatch.filter(item_names, key)) + return tuple(key for key in keys if key in item_names) def create_item_config(self, name): """ @@ -233,7 +233,7 @@ def create_frontend_args(self, path, default_args): frontend_args = default_args.copy() for key, args in (self.frontend_args or {}).items(): pattern = key.lower() if key[0] == '/' else f'*{key}'.lower() - if fnmatch(path, pattern): + if fnmatch.fnmatch(path, pattern): frontend_args.update(args) return frontend_args return frontend_args @@ -242,7 +242,7 @@ def is_disabled(self, name): """ Check if the item with the given :data:`name` is marked as `disabled` """ - return len(self.match_item_keys(name, self.disable, use_pattern_matching=True, match_item_parents=True)) > 0 + return bool(self.match_item_keys(name, self.disable, use_pattern_matching=True, match_item_parents=True)) class TransformationConfig: diff --git a/loki/batch/item.py b/loki/batch/item.py index 3ce14b39b..db4284e01 100644 --- a/loki/batch/item.py +++ b/loki/batch/item.py @@ -1489,7 +1489,7 @@ def _is_ignored(name, config, ignore): ``True`` if matched successfully via :data:`config` or :data:`ignore` list, otherwise ``False`` """ - return ( - (config and config.is_disabled(name)) or - (ignore and SchedulerConfig.match_item_keys(name, ignore, use_pattern_matching=True)) + keys = as_tuple(config.disable if config else ()) + as_tuple(ignore) + return keys and SchedulerConfig.match_item_keys( + name, keys, use_pattern_matching=True, match_item_parents=True ) From ca59ca58e9d808970c251c1df2753dcb6e0d6a0c Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Sat, 23 Nov 2024 00:15:24 +0100 Subject: [PATCH 2/4] Avoid redundant matching of disabled items --- loki/batch/item.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/loki/batch/item.py b/loki/batch/item.py index db4284e01..454aaa279 100644 --- a/loki/batch/item.py +++ b/loki/batch/item.py @@ -1118,8 +1118,6 @@ def get_or_create_item(self, item_cls, item_name, scope_name, config=None): :any:`Item` or None The item object or `None` if disabled or impossible to create """ - if config and config.is_disabled(item_name): - return None if item_name in self.item_cache: return self.item_cache[item_name] From 5f0449567d6095f44ccdd1ce1ea0ea7c8ba6bb4c Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Sat, 23 Nov 2024 02:02:09 +0100 Subject: [PATCH 3/4] ModuleItem: Do not search for variable definitions to improve Graph creation performance --- loki/batch/item.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/loki/batch/item.py b/loki/batch/item.py index 454aaa279..4130d9721 100644 --- a/loki/batch/item.py +++ b/loki/batch/item.py @@ -623,10 +623,7 @@ def definitions(self): global variables. """ self.concretize_definitions() - definitions = tuple( - d for d in self.ir.definitions - if not isinstance(d, (MetaSymbol, TypedSymbol)) or isinstance(d, ProcedureSymbol) - ) + definitions = self.ir.subroutines + as_tuple(FindNodes((TypeDef, Interface)).visit(self.ir.spec)) return definitions @property From aacccfc641336da62401cc21a3854ea2cc74d172 Mon Sep 17 00:00:00 2001 From: Balthasar Reuter Date: Tue, 10 Dec 2024 17:38:59 +0100 Subject: [PATCH 4/4] Fix test because new logic avoids some redundant definition items --- loki/batch/tests/test_batch.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/loki/batch/tests/test_batch.py b/loki/batch/tests/test_batch.py index 7abf47d90..2a44c468f 100644 --- a/loki/batch/tests/test_batch.py +++ b/loki/batch/tests/test_batch.py @@ -347,7 +347,7 @@ def test_module_item4(testdir): # Make sure interfaces are correctly identified as definitions item = get_item(ModuleItem, proj/'some_module.F90', 'some_module', RegexParserClass.ProgramUnitClass) definitions = item.definitions - assert len(definitions) == 8 + assert len(definitions) == 6 assert len(item.ir.interfaces) == 1 assert item.ir.interfaces[0] in definitions @@ -355,7 +355,7 @@ def test_module_item4(testdir): item_factory.item_cache[item.name] = item items = item.create_definition_items(item_factory=item_factory) - assert len(items) == 10 + assert len(items) == 8 assert len(set(items)) == 6 assert 'some_module#add_args' in item_factory.item_cache assert isinstance(item_factory.item_cache['some_module#add_args'], InterfaceItem)