From 5a60f2cfcbd05f83591b977cfe71124742e13789 Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 29 Jan 2026 11:40:57 +0100 Subject: [PATCH 1/7] Added utility functions for logical -> physical conversion --- src/analysis/typepal/TModel.rsc | 69 +++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/analysis/typepal/TModel.rsc b/src/analysis/typepal/TModel.rsc index fa84df9..41cc623 100644 --- a/src/analysis/typepal/TModel.rsc +++ b/src/analysis/typepal/TModel.rsc @@ -117,6 +117,75 @@ data TModel ( TypePalConfig config = tconfig() ) = tmodel(); +@synopsis{Convert logical locations in a TModel to physical locations} +// This function can be written with a single (expensive) visit +// For efficiency reasons, this version avoids visits as much as possible +TModel convertTModel2PhysicalLocs(TModel tm){ + if(tm.usesPhysicalLocs) return tm; + + locMap = tm.logical2physical; + defines = {}; + definitions = (); + for(d: <- tm.defines){ + defi = visit(defInfo){ case loc l => locMap[l] when l in locMap }; + d1 = d[scope=(scope in locMap ? locMap[scope] : scope)] + [defined=(defined in locMap ? locMap[defined] : defined)] + [defInfo=defi]; + defines += d1; + definitions[d1.defined] = d1; + } + tm.defines = defines; + tm.definitions = definitions; + + tm.scopes = ( (outer in locMap ? locMap[outer] : outer) : (inner in locMap ? locMap[inner] : inner) + | loc outer <- tm.scopes, loc inner := tm.scopes[outer] + ); + tm.paths = { <(from in locMap ? locMap[from] : from), + pathRole, + (to in locMap ? locMap[to] : to)> + | <- tm.paths + }; + + tm.referPaths = visit(tm.referPaths){ case loc l => locMap[l] when l in locMap }; + tm.uses = visit(tm.uses){ case loc l => locMap[l] when l in locMap }; + tm.definesMap = visit(tm.definesMap){ case loc l => locMap[l] when l in locMap }; + tm.moduleLocs = ( key : (l in locMap ? locMap[l] : l) + | key <- tm.moduleLocs, l := tm.moduleLocs[key] + ); + facts = tm.facts; + tm.facts = ((l in locMap ? locMap[l] : l) + : ( (overloadedAType(rel[loc, IdRole, AType] overloads) := atype) + ? overloadedAType({ <(l in locMap ? locMap[l] : l), idr, at> | <- overloads }) + : atype) + | l <- facts, atype := facts[l] + ); + //tm.facts = visit(tm.facts){ case loc l => locMap[l] ? l }; + tm.specializedFacts = + ((l in locMap ? locMap[l] : l) + : ( (overloadedAType(rel[loc, IdRole, AType] overloads) := atype) + ? overloadedAType({ <(l in locMap ? locMap[l] : l), idr, at> | <- overloads }) + : atype) + | l <- tm.specializedFacts, atype := tm.specializedFacts[l] + ); + //tm.specializedFacts = visit(tm.specializedFacts){ case loc l => locMap[l] ? l }; + tm.useDef = { < (f in locMap ? locMap[f] : f), + (t in locMap ? locMap[t] : t) > + | <- tm.useDef }; + // Exlude messages from conversion: otherwise users would see logical locations + //tm.messages = visit(tm.messages){ case loc l => locMap[l] ? l }; + tm.store = visit(tm.store){ case loc l => locMap[l] when l in locMap}; + tm.config = visit(tm.config){ case loc l => locMap[l] when l in locMap}; + + tm.usesPhysicalLocs = true; + return tm; +} + +@synopsis{Convert the logical locations in an arbitrary value to physical locations} +value convert2PhysicalLocs(value v, TModel tm){ + locMap = tm.logical2physical; + return visit(v) { case loc l => locMap[l] when l in locMap}; +} + void printTModel(TModel tm){ println("TModel("); println(" defines = {"); From e4314cf6af8ebb14c8f6a010d48a88280d17fe92 Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 29 Jan 2026 12:38:45 +0100 Subject: [PATCH 2/7] Fixed incorrect import --- src/analysis/typepal/AType.rsc | 2 +- src/analysis/typepal/TModel.rsc | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/analysis/typepal/AType.rsc b/src/analysis/typepal/AType.rsc index f492193..77cb095 100644 --- a/src/analysis/typepal/AType.rsc +++ b/src/analysis/typepal/AType.rsc @@ -19,7 +19,7 @@ module analysis::typepal::AType import List; extend analysis::typepal::GetLoc; -extend analysis::typepal::TModel; +import analysis::typepal::TModel; data AType = tvar(loc tname) // type variable, used for type inference diff --git a/src/analysis/typepal/TModel.rsc b/src/analysis/typepal/TModel.rsc index 41cc623..bbdef2f 100644 --- a/src/analysis/typepal/TModel.rsc +++ b/src/analysis/typepal/TModel.rsc @@ -22,6 +22,7 @@ import Node; import IO; import analysis::typepal::Version; +import analysis::typepal::AType; data AType; From 1cf3c443dc3aa12e8c5fe8ef9f0c650eac72829e Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 29 Jan 2026 12:55:56 +0100 Subject: [PATCH 3/7] Removed aobsolete file --- src/analysis/typepal/Inspect.rsc | 31 ------------------------------- 1 file changed, 31 deletions(-) delete mode 100644 src/analysis/typepal/Inspect.rsc diff --git a/src/analysis/typepal/Inspect.rsc b/src/analysis/typepal/Inspect.rsc deleted file mode 100644 index 1e4f762..0000000 --- a/src/analysis/typepal/Inspect.rsc +++ /dev/null @@ -1,31 +0,0 @@ -@license{ -Copyright (c) 2017, Paul Klint -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -} -module analysis::typepal::Inspect - -import analysis::typepal::Collector; -import String; -import IO; -import ValueIO; - -void show(loc tmodelLoc, str _key){ - - if(!endsWith(tmodelLoc.path, ".tpl")){ - println("Can only show files with `tpl` extension"); - return; - } - tm = readBinaryValueFile(#TModel, tmodelLoc); - for(/Tree t := tm) iprintln(t); - //for(d <- tm.defines, d.id == key){ - // iprintln(d, lineLimit=10000); - //} -} \ No newline at end of file From 647d5b9ccabde30935a5e146a006d4ee01aa19e2 Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 29 Jan 2026 13:24:56 +0100 Subject: [PATCH 4/7] Removed variants of isContainedIn --- src/analysis/typepal/Collector.rsc | 7 ------- src/analysis/typepal/StringSimilarity.rsc | 5 ----- src/analysis/typepal/TModel.rsc | 9 +++++++++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/analysis/typepal/Collector.rsc b/src/analysis/typepal/Collector.rsc index ba7d534..7966b9b 100644 --- a/src/analysis/typepal/Collector.rsc +++ b/src/analysis/typepal/Collector.rsc @@ -32,13 +32,6 @@ import analysis::typepal::Messenger; extend analysis::typepal::ConfigurableScopeGraph; extend analysis::typepal::ICollector; -// TODO: remove these temporary copies of isContainedIn and isBefore -// (needed to break deployment cycle). They should reside in Location.rsc -private bool isContainedIn(loc inner, loc outer, map[loc,loc] m) - = isContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); -bool isBefore(loc inner, loc outer, map[loc,loc] m) - = isBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - // Extract (nested) tree locations and type variables from a list of dependencies list[loc] dependenciesAslocList(list[value] dependencies){ return diff --git a/src/analysis/typepal/StringSimilarity.rsc b/src/analysis/typepal/StringSimilarity.rsc index 1283a4e..05c6541 100644 --- a/src/analysis/typepal/StringSimilarity.rsc +++ b/src/analysis/typepal/StringSimilarity.rsc @@ -67,11 +67,6 @@ list[str] similarWords(str w, set[str] vocabulary, int maxDistance) = sort({ | str v <- vocabulary, d := lev(w, v), d <= maxDistance }, bool (WordSim x, WordSim y){ return x.sim < y.sim;}).word; -// TODO: remove this temporary copy of isContainedIn (needed to break deployment cycle) -// should reside in Location.rsc -private bool isContainedIn(loc inner, loc outer, map[loc,loc] m) - = isContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); - @synopsis{Find in TModel tm, names similar to Use u. Max edit distance comes from TypePal Configuration.} list[str] similarNames(Use u, TModel tm){ w = getOrgId(u); diff --git a/src/analysis/typepal/TModel.rsc b/src/analysis/typepal/TModel.rsc index bbdef2f..75bb7ab 100644 --- a/src/analysis/typepal/TModel.rsc +++ b/src/analysis/typepal/TModel.rsc @@ -17,6 +17,7 @@ module analysis::typepal::TModel It can be extended to suit the needs of a specific type checker. */ import String; +import Location; import Message; import Node; import IO; @@ -187,6 +188,14 @@ value convert2PhysicalLocs(value v, TModel tm){ return visit(v) { case loc l => locMap[l] when l in locMap}; } +// Generalized versions of isContainedIn and isBefore that take +// a logical -> physical mapping into account. +bool isContainedIn(loc inner, loc outer, map[loc,loc] m) + = isContainedIn(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + +bool isBefore(loc inner, loc outer, map[loc,loc] m) + = isBefore(inner in m ? m[inner] : inner, outer in m ? m[outer] : outer); + void printTModel(TModel tm){ println("TModel("); println(" defines = {"); From 08b9b17f9e281b68cf6b8700ea43c4c521dd9434 Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 29 Jan 2026 13:25:54 +0100 Subject: [PATCH 5/7] Updated to rascal 0.41.3-RC4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bdf05d0..0a3cf67 100644 --- a/pom.xml +++ b/pom.xml @@ -183,7 +183,7 @@ org.rascalmpl rascal - 0.41.2 + 0.41.3-RC4 provided From 76c47016edaae1e85356caaf762776051838ca0c Mon Sep 17 00:00:00 2001 From: paulklint Date: Thu, 29 Jan 2026 15:12:50 +0100 Subject: [PATCH 6/7] Set to rascal 0.41.3-RC1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0a3cf67..4f9de29 100644 --- a/pom.xml +++ b/pom.xml @@ -183,7 +183,7 @@ org.rascalmpl rascal - 0.41.3-RC4 + 0.41.3-RC1 provided From c00fabcc88b205d6a1930c30db3105e7fc353d37 Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 30 Jan 2026 15:34:45 +0100 Subject: [PATCH 7/7] Switched to rascal 0.41.3-RC4 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4f9de29..0a3cf67 100644 --- a/pom.xml +++ b/pom.xml @@ -183,7 +183,7 @@ org.rascalmpl rascal - 0.41.3-RC1 + 0.41.3-RC4 provided