From 6aafa1d741650f593b7716e4f64fab0de3e8d7d1 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Wed, 29 Jul 2026 10:29:00 +0200 Subject: [PATCH 1/3] Add conversion function for field `definesMap` of `TModel` to make its usage in `bindWide` more efficient --- .../typepal/ConfigurableScopeGraph.rsc | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/analysis/typepal/ConfigurableScopeGraph.rsc b/src/analysis/typepal/ConfigurableScopeGraph.rsc index d6df65c..7ad6d8b 100644 --- a/src/analysis/typepal/ConfigurableScopeGraph.rsc +++ b/src/analysis/typepal/ConfigurableScopeGraph.rsc @@ -404,11 +404,30 @@ ScopeGraph newScopeGraph(TModel tm, TypePalConfig config){ /* parents) and definitions that can be reached in a single step via semantic links */ /************************************************************************************/ + // Convert `tm.definesMap` to a more efficient representation for the kind + // of lookups that are performed in `bindWide`. The idea is to convert only + // once, and enjoy a return on investment each time when a lookup is + // performed in it (instead of also needing a `domainR` call each time). + map[loc, map[str, map[IdRole, set[loc]]]] convertDefinesMap() { + // Conversion function for the outer map + map[loc, map[str, map[IdRole, set[loc]]]] convert(map[loc, map[str, rel[IdRole, loc]]] scope2id2pairs) { + return (scope: convert(scope2id2pairs[scope]) | loc scope <- scope2id2pairs); + } + // Conversion function for the inner maps + map[str, map[IdRole, set[loc]]] convert(map[str, rel[IdRole, loc]] id2pairs) { + return (id: Relation::index(id2pairs[id]) | str id <- id2pairs); + } + return convert(tm.definesMap); + } + + // Convert only once + map[loc, map[str, map[IdRole, set[loc]]]] scope2id2role2defs = convertDefinesMap(); + //@memo // Retrieve all bindings for use in given syntactic scope private set[loc] bindWide(loc scope, str id, set[IdRole] idRoles){ - idsInScope = (scope in tm.definesMap) ? tm.definesMap[scope] : (); - foundDefs = id in idsInScope ? domainR(idsInScope[id], idRoles)<1> : {}; + map[IdRole, set[loc]] role2defs = (scope2id2role2defs[scope] ? ())[id] ? (); + foundDefs = {*(role2defs[role] ? {}) | IdRole role <- idRoles}; // dbg("bindWide: , =\> "); return foundDefs; } From 0f42f397e7eae136a7378d40f56237599ed45462 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Fri, 14 Aug 2026 10:40:53 +0200 Subject: [PATCH 2/3] Improve comment --- src/analysis/typepal/ConfigurableScopeGraph.rsc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/analysis/typepal/ConfigurableScopeGraph.rsc b/src/analysis/typepal/ConfigurableScopeGraph.rsc index 7ad6d8b..ff0f8be 100644 --- a/src/analysis/typepal/ConfigurableScopeGraph.rsc +++ b/src/analysis/typepal/ConfigurableScopeGraph.rsc @@ -420,7 +420,8 @@ ScopeGraph newScopeGraph(TModel tm, TypePalConfig config){ return convert(tm.definesMap); } - // Convert only once + // Convert only once. (Note: this variable is local to `newScopeGraph`, so + // always associated with the same TModel.) map[loc, map[str, map[IdRole, set[loc]]]] scope2id2role2defs = convertDefinesMap(); //@memo From ea58ab5928510092083647f839833634047a6342 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Fri, 14 Aug 2026 10:41:23 +0200 Subject: [PATCH 3/3] Rename auxiliary functions --- src/analysis/typepal/ConfigurableScopeGraph.rsc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/analysis/typepal/ConfigurableScopeGraph.rsc b/src/analysis/typepal/ConfigurableScopeGraph.rsc index ff0f8be..2bf9e5e 100644 --- a/src/analysis/typepal/ConfigurableScopeGraph.rsc +++ b/src/analysis/typepal/ConfigurableScopeGraph.rsc @@ -410,14 +410,14 @@ ScopeGraph newScopeGraph(TModel tm, TypePalConfig config){ // performed in it (instead of also needing a `domainR` call each time). map[loc, map[str, map[IdRole, set[loc]]]] convertDefinesMap() { // Conversion function for the outer map - map[loc, map[str, map[IdRole, set[loc]]]] convert(map[loc, map[str, rel[IdRole, loc]]] scope2id2pairs) { - return (scope: convert(scope2id2pairs[scope]) | loc scope <- scope2id2pairs); + map[loc, map[str, map[IdRole, set[loc]]]] convertOuter(map[loc, map[str, rel[IdRole, loc]]] scope2id2pairs) { + return (scope: convertInner(scope2id2pairs[scope]) | loc scope <- scope2id2pairs); } // Conversion function for the inner maps - map[str, map[IdRole, set[loc]]] convert(map[str, rel[IdRole, loc]] id2pairs) { + map[str, map[IdRole, set[loc]]] convertInner(map[str, rel[IdRole, loc]] id2pairs) { return (id: Relation::index(id2pairs[id]) | str id <- id2pairs); } - return convert(tm.definesMap); + return convertOuter(tm.definesMap); } // Convert only once. (Note: this variable is local to `newScopeGraph`, so