Skip to content

Commit d0ac06e

Browse files
authored
Remove top-level SymExprs from the AST (chapel-lang#26321)
They aren't used for anything, so deleting them is reasonable. This fixes chapel-lang#25885. The crux of that issue is that we incorrectly identify the `R` type as "unused", since it's generic but not used for any sub-classes and is never instantiated. I first attempted to fix the problem by adjusting `isUnusedClass` to respect `SymExprs` still in the tree that still point to the class. However, subsequent code __deletes all generic type declarations, because by that point we expect all occurrences to be concrete__: ```Chapel new genericType(...); // replaced with a call to concreteType.init var x: genericType = ...; // replaced with `var x: concreteType` // the following: proc foo(type arg) {} foo(genericType) // is replaced with: proc foo() {} foo(); ``` Deleting all generic types seems like a reasonable approach to me; the standalone variables are a weird exception, in which the type is neither instantiated nor removed. Moreover, since they don't modify or even really access the variable, these standalone `SymExprs` can be safely removed. This PR does just that. Reviewed by @jabraham17 -- thanks! ## Testing - [x] paratest
2 parents a5ea505 + 05c6e26 commit d0ac06e

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

compiler/resolution/cleanups.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,14 @@ static void removeUnusedFunctions() {
124124
}
125125
}
126126

127+
static void removeTopLevelSymExprs() {
128+
for_alive_in_Vec(SymExpr, se, gSymExprs) {
129+
if (se->getStmtExpr() == se) {
130+
se->remove();
131+
}
132+
}
133+
}
134+
127135
static CallExpr* replaceRuntimeTypeGetField(CallExpr* call) {
128136
SymExpr* rt = toSymExpr(call->get(1));
129137

@@ -1038,6 +1046,8 @@ void pruneResolvedTree() {
10381046

10391047
removeUnusedFunctions();
10401048

1049+
removeTopLevelSymExprs();
1050+
10411051
if (fRemoveUnreachableBlocks) {
10421052
deadBlockElimination();
10431053
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
record R { var arg; }
2+
R;

test/types/records/generic/generic-type-standalone-mention.good

Whitespace-only changes.

0 commit comments

Comments
 (0)