diff --git a/modules/dists/DSIUtil.chpl b/modules/dists/DSIUtil.chpl index 2feca42d3801..d50c6d6acfdd 100644 --- a/modules/dists/DSIUtil.chpl +++ b/modules/dists/DSIUtil.chpl @@ -301,7 +301,7 @@ proc densify(subs, wholes, userErrors = true) return result; } -proc densify(s: range(?,bounds=?B), w: range(?IT,?), userErrors=true +proc densify(s: range(?,bounds=?), w: range(?IT,?), userErrors=true ) : densiResult(s, w) { _densiEnsureBounded(s); @@ -425,7 +425,7 @@ proc unDensify(denses, wholes, userErrors = true) return result; } -proc unDensify(dense: range(?dIT,bounds=?B), whole: range(?IT,?) +proc unDensify(dense: range(?dIT,bounds=?), whole: range(?IT,?) ) : densiResult(dense, whole) { _undensEnsureBounded(dense); diff --git a/test/chplcheck/UnusedTypeQuery.chpl b/test/chplcheck/UnusedTypeQuery.chpl new file mode 100644 index 000000000000..6d2b06e982d7 --- /dev/null +++ b/test/chplcheck/UnusedTypeQuery.chpl @@ -0,0 +1,10 @@ +module UnusedTypeQuery { + + proc foo(ref a: ?t) { + a = 1; + } + proc bar(ref arr: [?d] ?elt) where elt == int{ + arr[1] = 1; + } + +} diff --git a/test/chplcheck/UnusedTypeQuery.good b/test/chplcheck/UnusedTypeQuery.good new file mode 100644 index 000000000000..5647d9bb3d36 --- /dev/null +++ b/test/chplcheck/UnusedTypeQuery.good @@ -0,0 +1,2 @@ +UnusedTypeQuery.chpl:3: node violates rule UnusedTypeQuery +UnusedTypeQuery.chpl:6: node violates rule UnusedTypeQuery diff --git a/test/chplcheck/activerules.good b/test/chplcheck/activerules.good index f2075f252650..5646f7be158f 100644 --- a/test/chplcheck/activerules.good +++ b/test/chplcheck/activerules.good @@ -18,3 +18,4 @@ Active rules: UnusedLoopIndex Warn for unused index variables in loops. UnusedTaskIntent Warn for unused task intents in functions. UnusedTupleUnpack Warn for unused tuple unpacking, such as '(_, _)'. + UnusedTypeQuery Warn for unused type queries in functions. diff --git a/test/chplcheck/allrules.good b/test/chplcheck/allrules.good index 3640f8173209..421c6c169acf 100644 --- a/test/chplcheck/allrules.good +++ b/test/chplcheck/allrules.good @@ -21,4 +21,5 @@ Available rules (default rules marked with *): * UnusedLoopIndex Warn for unused index variables in loops. * UnusedTaskIntent Warn for unused task intents in functions. * UnusedTupleUnpack Warn for unused tuple unpacking, such as '(_, _)'. + * UnusedTypeQuery Warn for unused type queries in functions. UseExplicitModules Warn for code that relies on auto-inserted implicit modules. diff --git a/tools/chplcheck/src/rules.py b/tools/chplcheck/src/rules.py index a9893af8a3de..05cccac07bda 100644 --- a/tools/chplcheck/src/rules.py +++ b/tools/chplcheck/src/rules.py @@ -697,6 +697,29 @@ def RemoveTaskIntent(context: Context, result: AdvancedRuleResult): pass return [fixit] if fixit else [] + @driver.advanced_rule + def UnusedTypeQuery(context: Context, root: AstNode): + """ + Warn for unused type queries in functions. + """ + if isinstance(root, Comment): + return + + typequeries = dict() + uses = set() + + for tq, _ in chapel.each_matching(root, TypeQuery): + + typequeries[tq.unique_id()] = tq + + for use, _ in chapel.each_matching(root, Identifier): + refersto = use.to_node() + if refersto: + uses.add(refersto.unique_id()) + + for unused in typequeries.keys() - uses: + yield AdvancedRuleResult(typequeries[unused]) + @driver.advanced_rule def UnusedLoopIndex(context: Context, root: AstNode): """