From 55456edcc52653e42d7f534a5412147b01b68c29 Mon Sep 17 00:00:00 2001 From: paulklint Date: Tue, 27 Aug 2024 12:46:55 +0200 Subject: [PATCH] Improved addUse to only add "inner" definitions --- src/analysis/typepal/Solver.rsc | 76 ++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 34 deletions(-) diff --git a/src/analysis/typepal/Solver.rsc b/src/analysis/typepal/Solver.rsc index fcd74e7..be0036d 100644 --- a/src/analysis/typepal/Solver.rsc +++ b/src/analysis/typepal/Solver.rsc @@ -675,7 +675,9 @@ Solver newSolver(map[str,Tree] namedTrees, TModel tm){ void addUse(set[loc] defs, Use u){ for(loc def <- defs){ if(definedBy[u.occ]?){ // TODO is this isContainedIn safe to use? - definedBy[u.occ] = { isContainedIn(def, d) ? def : d | loc d <- definedBy[u.occ] }; + if(!any(loc d <- definedBy[u.occ], isContainedIn(d, def))){ + definedBy[u.occ] += {def}; + } } else { definedBy[u.occ] = {def}; } @@ -817,6 +819,9 @@ Solver newSolver(map[str,Tree] namedTrees, TModel tm){ Define solver_getDefine(loc l) = definitions[l]; + rel[loc,loc] solver_getUseDef() + = { *{ | loc d <- definedBy[u]} | loc u <- definedBy }; + // ---- resolvePath ------------------------------------------------------- bool resolvePaths(){ @@ -1589,12 +1594,12 @@ Solver newSolver(map[str,Tree] namedTrees, TModel tm){ } } - tm.calculators = calculators; - tm.requirements = requirements; + tm.calculators = calculators; + tm.requirements = requirements; - tm.facts = facts; - // prune the definedBy relation using specialized facts - for(loc u <- specializedFacts){ + tm.facts = facts; + // prune the definedBy relation using specialized facts + for(loc u <- specializedFacts){ orgtp = facts[u]; spectp = specializedFacts[u]; if(definedBy[u]? && overloadedAType(org_overloads) := orgtp){ @@ -1606,39 +1611,41 @@ Solver newSolver(map[str,Tree] namedTrees, TModel tm){ } } - tm.specializedFacts = specializedFacts; - tm.useDef = { *{ | loc d <- definedBy[u]} | loc u <- definedBy }; + tm.specializedFacts = specializedFacts; + + //println("definedBy;"); iprintln(definedBy); + tm.useDef = { *{ | loc d <- definedBy[u]} | loc u <- definedBy }; - ldefines = for(tup: <- tm.defines){ - if(defInfo has tree){ + ldefines = for(tup: <- tm.defines){ + if(defInfo has tree){ + try { + dt = defType(tm.facts[getLoc(defInfo.tree)]); + tup.defInfo = setKeywordParameters(dt, getKeywordParameters(defInfo)); + } catch NoSuchKey(_): { + continue; + } + } else { try { - dt = defType(tm.facts[getLoc(defInfo.tree)]); - tup.defInfo = setKeywordParameters(dt, getKeywordParameters(defInfo)); - } catch NoSuchKey(_): { - continue; - } - } else { - try { - dt = defType(tm.facts[defined]); - tup.defInfo = setKeywordParameters(dt, getKeywordParameters(defInfo)); - } catch NoSuchKey(_): { - continue; - } - } - append tup; - }; - tm.defines = toSet(ldefines); + dt = defType(tm.facts[defined]); + tup.defInfo = setKeywordParameters(dt, getKeywordParameters(defInfo)); + } catch NoSuchKey(_): { + continue; + } + } + append tup; + }; + tm.defines = toSet(ldefines); - for(Define def <- tm.defines){ - if(def.defined notin def2uses && def.defined notin doubleDefs && reportUnused(def.defined, tm)){ - messages += warning("Unused ``", def.defined); - } - } + for(Define def <- tm.defines){ + if(def.defined notin def2uses && def.defined notin doubleDefs && reportUnused(def.defined, tm)){ + messages += warning("Unused ``", def.defined); + } + } - tm.messages = sortMostPrecise(toList(toSet(messages))); + tm.messages = sortMostPrecise(toList(toSet(messages))); - checkAllTypesAvailable(tm); - return tm; + checkAllTypesAvailable(tm); + return tm; } // The actual code of newSolver @@ -1682,6 +1689,7 @@ Solver newSolver(map[str,Tree] namedTrees, TModel tm){ solver_getDefinitions, solver_getAllDefines, solver_getDefine, + solver_getUseDef, /* Nested Info */ solver_push, solver_pop,