Repository: joernio/joern
Pull request #5468 (2025-05-05 15:56:44)

[swiftsrc2cpg] Refactor synthetic name generation
To be more in line with the other frontends.

max-leuthaeuser: I made this PR actually just for the  naming itself. The index is another story and should be generated with individual counters and method-local, totally agree with that. At least for c2cpg we have the exact same issue.

Patch:
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstCreator.scala b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstCreator.scala
index 9f54f2742..41a35a68d 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstCreator.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstCreator.scala
@@ -43,13 +43,12 @@ class AstCreator(val config: Config, val global: Global, val parserResult: Parse
 
   protected val scope = new VariableScopeManager()
 
-  protected val methodAstParentStack          = new Stack[NewNode]()
-  protected val typeRefIdStack                = new Stack[NewTypeRef]
-  protected val dynamicInstanceTypeStack      = new Stack[String]
-  protected val localAstParentStack           = new Stack[NewBlock]()
-  protected val functionNodeToNameAndFullName = mutable.HashMap.empty[SwiftNode, (String, String)]
-  protected val usedVariableNames             = mutable.HashMap.empty[String, Int]
-  protected val seenAliasTypes                = mutable.HashSet.empty[NewTypeDecl]
+  protected val methodAstParentStack     = new Stack[NewNode]()
+  protected val typeRefIdStack           = new Stack[NewTypeRef]
+  protected val dynamicInstanceTypeStack = new Stack[String]
+  protected val localAstParentStack      = new Stack[NewBlock]()
+  protected val scopeLocalUniqueNames    = mutable.HashMap.empty[String, Int]
+  protected val seenAliasTypes           = mutable.HashSet.empty[NewTypeDecl]
 
   protected lazy val definedSymbols: Map[String, String] = {
     config.defines.map {
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstCreatorHelper.scala b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstCreatorHelper.scala
index 894783129..2321c4573 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstCreatorHelper.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstCreatorHelper.scala
@@ -10,13 +10,10 @@ import io.joern.swiftsrc2cpg.parser.SwiftNodeSyntax.InitializerDeclSyntax
 import io.joern.swiftsrc2cpg.parser.SwiftNodeSyntax.SwiftNode
 import io.joern.x2cpg.Ast
 import io.joern.x2cpg.ValidationMode
-import io.joern.x2cpg.utils.IntervalKeyPool
 import io.shiftleft.codepropertygraph.generated.nodes.NewNode
 import io.shiftleft.codepropertygraph.generated.ControlStructureTypes
 import io.shiftleft.codepropertygraph.generated.PropertyNames
 
-import scala.collection.mutable
-
 object AstCreatorHelper {
 
   implicit class OptionSafeAst(val ast: Ast) extends AnyVal {
@@ -30,10 +27,6 @@ object AstCreatorHelper {
 
 trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: AstCreator =>
 
-  private val anonClassKeyPool = new IntervalKeyPool(first = 0, last = Long.MaxValue)
-
-  protected def nextAnonClassName(): String = s"<anon-class>${anonClassKeyPool.next}"
-
   protected def notHandledYet(node: SwiftNode): Ast = {
     val text =
       s"""Node type '${node.toString}' not handled yet!
@@ -98,22 +91,13 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
     global.usedTypes.putIfAbsent(typeFullName, true)
   }
 
-  protected def generateUnusedVariableName(
-    usedVariableNames: mutable.HashMap[String, Int],
-    variableName: String
-  ): String = {
-    val counter             = usedVariableNames.get(variableName).fold(0)(_ + 1)
-    val currentVariableName = s"${variableName}_$counter"
-    usedVariableNames.put(variableName, counter)
-    currentVariableName
-  }
-
-  private def calcMethodName(func: SwiftNode): String = func match {
-    case f: FunctionDeclSyntax      => code(f.name)
-    case a: AccessorDeclSyntax      => code(a.accessorSpecifier)
-    case d: DeinitializerDeclSyntax => code(d.deinitKeyword)
-    case i: InitializerDeclSyntax   => code(i.initKeyword)
-    case _                          => nextClosureName()
+  protected def scopeLocalUniqueName(targetName: String): String = {
+    val name = if (targetName.nonEmpty) { s"<$targetName>" }
+    else { "<anonymous>" }
+    val key = s"${scope.computeScopePath}:$name"
+    val idx = scopeLocalUniqueNames.getOrElseUpdate(key, 0)
+    scopeLocalUniqueNames.update(key, idx + 1)
+    s"$name$idx"
   }
 
   protected def calcTypeNameAndFullName(name: String): (String, String) = {
@@ -123,14 +107,18 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
   }
 
   protected def calcMethodNameAndFullName(func: SwiftNode): (String, String) = {
-    functionNodeToNameAndFullName.get(func) match {
-      case Some(nameAndFullName) => nameAndFullName
-      case None =>
-        val name           = calcMethodName(func)
-        val fullNamePrefix = s"${parserResult.filename}:${scope.computeScopePath}:"
-        val fullName       = s"$fullNamePrefix$name"
-        (name, fullName)
-    }
+    val name           = calcMethodName(func)
+    val fullNamePrefix = s"${parserResult.filename}:${scope.computeScopePath}:"
+    val fullName       = s"$fullNamePrefix$name"
+    (name, fullName)
+  }
+
+  private def calcMethodName(func: SwiftNode): String = func match {
+    case f: FunctionDeclSyntax      => code(f.name)
+    case a: AccessorDeclSyntax      => code(a.accessorSpecifier)
+    case d: DeinitializerDeclSyntax => code(d.deinitKeyword)
+    case i: InitializerDeclSyntax   => code(i.initKeyword)
+    case _                          => nextClosureName()
   }
 
 }
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForDeclSyntaxCreator.scala b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForDeclSyntaxCreator.scala
index a51503236..54115758e 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForDeclSyntaxCreator.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForDeclSyntaxCreator.scala
@@ -640,13 +640,8 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
     }
     registerType(returnType)
     val methodFullNameAndSignature = s"$methodFullName:$signature"
-    functionNodeToNameAndFullName(node) = (methodName, methodFullNameAndSignature)
-
-    val methodRefNode_ = if (!shouldCreateFunctionReference) {
-      None
-    } else {
-      Option(methodRefNode(node, methodName, methodFullNameAndSignature, methodFullNameAndSignature))
-    }
+    val methodRefNode_ = if (!shouldCreateFunctionReference) { None }
+    else { Option(methodRefNode(node, methodName, methodFullNameAndSignature, methodFullNameAndSignature)) }
 
     val callAst = if (shouldCreateAssignmentCall && shouldCreateFunctionReference) {
       val idNode  = identifierNode(node, methodName)
@@ -921,7 +916,7 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
         case valueBinding: ValueBindingPatternSyntax =>
           Seq(code(valueBinding.pattern))
         case _: WildcardPatternSyntax =>
-          Seq(generateUnusedVariableName(usedVariableNames, "wildcard"))
+          Seq(scopeLocalUniqueName("wildcard"))
       }
 
       names.map { name =>
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForExprSyntaxCreator.scala b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForExprSyntaxCreator.scala
index a9d9a0124..dfb063331 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForExprSyntaxCreator.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForExprSyntaxCreator.scala
@@ -103,7 +103,7 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
   }
 
   private def astForDiscardAssignmentExprSyntax(node: DiscardAssignmentExprSyntax): Ast = {
-    val name   = generateUnusedVariableName(usedVariableNames, "wildcard")
+    val name   = scopeLocalUniqueName("wildcard")
     val idNode = identifierNode(node, name)
     scope.addVariableReference(name, idNode, Defines.Any, EvaluationStrategies.BY_REFERENCE)
     Ast(idNode)
@@ -155,12 +155,6 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
       case _ => callExprCode
     }
     val callNode_ = callNode(callExpr, callCode, callName, DispatchTypes.DYNAMIC_DISPATCH)
-    // If the callee is a function itself, e.g. closure, then resolve this locally, if possible
-    if (callExpr.calledExpression.isInstanceOf[ClosureExprSyntax]) {
-      functionNodeToNameAndFullName.get(callExpr.calledExpression).foreach { case (name, fullName) =>
-        callNode_.name(name).methodFullName(fullName)
-      }
-    }
     callAst(callNode_, args, receiver = Option(receiverAst), base = Option(Ast(baseNode)))
   }
 
@@ -192,7 +186,7 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
               scope.addVariableReference(code(d), baseNode, Defines.Any, EvaluationStrategies.BY_REFERENCE)
               (receiverAst, baseNode, code(member))
             case Some(otherBase) =>
-              val tmpVarName  = generateUnusedVariableName(usedVariableNames, "_tmp")
+              val tmpVarName  = scopeLocalUniqueName("tmp")
               val baseTmpNode = identifierNode(otherBase, tmpVarName)
               scope.addVariableReference(tmpVarName, baseTmpNode, Defines.Any, EvaluationStrategies.BY_REFERENCE)
               val baseAst   = astForNodeWithFunctionReference(otherBase)
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForStmtSyntaxCreator.scala b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForStmtSyntaxCreator.scala
index e20904d14..87b1a418b 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForStmtSyntaxCreator.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForStmtSyntaxCreator.scala
@@ -129,7 +129,7 @@ trait AstForStmtSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
     val collectionName = code(collection)
 
     // _iterator assignment:
-    val iteratorName      = generateUnusedVariableName(usedVariableNames, "_iterator")
+    val iteratorName      = scopeLocalUniqueName("iterator")
     val iteratorLocalNode = localNode(node, iteratorName, iteratorName, Defines.Any).order(0)
     val iteratorNode      = identifierNode(node, iteratorName)
     diffGraph.addEdge(localAstParentStack.head, iteratorLocalNode, EdgeTypes.AST)
@@ -154,7 +154,7 @@ trait AstForStmtSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
     val iteratorAssignmentAst  = callAst(iteratorAssignmentNode, iteratorAssignmentArgs)
 
     // _result:
-    val resultName      = generateUnusedVariableName(usedVariableNames, "_result")
+    val resultName      = scopeLocalUniqueName("result")
     val resultLocalNode = localNode(node, resultName, resultName, Defines.Any).order(0)
     val resultNode      = identifierNode(node, resultName)
     diffGraph.addEdge(localAstParentStack.head, resultLocalNode, EdgeTypes.AST)
@@ -265,7 +265,7 @@ trait AstForStmtSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
     val collectionName = code(collection)
 
     // _iterator assignment:
-    val iteratorName      = generateUnusedVariableName(usedVariableNames, "_iterator")
+    val iteratorName      = scopeLocalUniqueName("iterator")
     val iteratorLocalNode = localNode(node, iteratorName, iteratorName, Defines.Any).order(0)
     val iteratorNode      = identifierNode(node, iteratorName)
     diffGraph.addEdge(localAstParentStack.head, iteratorLocalNode, EdgeTypes.AST)
@@ -290,7 +290,7 @@ trait AstForStmtSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
     val iteratorAssignmentAst  = callAst(iteratorAssignmentNode, iteratorAssignmentArgs)
 
     // _result:
-    val resultName      = generateUnusedVariableName(usedVariableNames, "_result")
+    val resultName      = scopeLocalUniqueName("result")
     val resultLocalNode = localNode(node, resultName, resultName, Defines.Any).order(0)
     val resultNode      = identifierNode(node, resultName)
     diffGraph.addEdge(localAstParentStack.head, resultLocalNode, EdgeTypes.AST)
@@ -393,7 +393,7 @@ trait AstForStmtSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
     val collectionName = code(collection)
 
     // _iterator assignment:
-    val iteratorName      = generateUnusedVariableName(usedVariableNames, "_iterator")
+    val iteratorName      = scopeLocalUniqueName("iterator")
     val iteratorLocalNode = localNode(node, iteratorName, iteratorName, Defines.Any).order(0)
     val iteratorNode      = identifierNode(node, iteratorName)
     diffGraph.addEdge(localAstParentStack.head, iteratorLocalNode, EdgeTypes.AST)
@@ -417,7 +417,7 @@ trait AstForStmtSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
     val iteratorAssignmentAst  = callAst(iteratorAssignmentNode, iteratorAssignmentArgs)
 
     // _result:
-    val resultName      = generateUnusedVariableName(usedVariableNames, "_result")
+    val resultName      = scopeLocalUniqueName("result")
     val resultLocalNode = localNode(node, resultName, resultName, Defines.Any).order(0)
     val resultNode      = identifierNode(node, resultName)
     diffGraph.addEdge(localAstParentStack.head, resultLocalNode, EdgeTypes.AST)
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForTypeSyntaxCreator.scala b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForTypeSyntaxCreator.scala
index c614ad4f4..2943d9c1c 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForTypeSyntaxCreator.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForTypeSyntaxCreator.scala
@@ -13,7 +13,7 @@ trait AstForTypeSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
   this: AstCreator =>
 
   private def typeDeclForTypeSyntax(node: TypeSyntax): NewTypeDecl = {
-    val name                     = nextAnonClassName()
+    val name                     = scopeLocalUniqueName("anon-class")
     val (typeName, typeFullName) = calcTypeNameAndFullName(name)
     registerType(typeFullName)
 


Test patch:
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/AsyncTests.scala b/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/AsyncTests.scala
index d4b1b9a2e..0125082a3 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/AsyncTests.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/AsyncTests.scala
@@ -108,9 +108,9 @@ class AsyncTests extends AstSwiftSrc2CpgSuite {
         "MyFuture()",
         "asyncGlobal1()",
         "await asyncGlobal1()",
+        "let <wildcard>0 = await asyncGlobal1()",
+        "let <wildcard>1 = myFuture.await()",
         "let myFuture = MyFuture()",
-        "let wildcard_0 = await asyncGlobal1()",
-        "let wildcard_1 = myFuture.await()",
         "myFuture.await",
         "myFuture.await()"
       )
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/DirectiveTests.scala b/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/DirectiveTests.scala
index f3195163b..d819a20cd 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/DirectiveTests.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/DirectiveTests.scala
@@ -75,9 +75,9 @@ class DirectiveTests extends AstSwiftSrc2CpgSuite {
         |.oneMore(x: 1)
         |""".stripMargin).withConfig(Config(Set("CONFIG1")))
       cpg.call.code.l shouldBe List(
-        "(_tmp_0 = foo.bar()).oneMore(x: 1)",
-        "(_tmp_0 = foo.bar()).oneMore",
-        "(_tmp_0 = foo.bar())",
+        "(<tmp>0 = foo.bar()).oneMore(x: 1)",
+        "(<tmp>0 = foo.bar()).oneMore",
+        "(<tmp>0 = foo.bar())",
         "foo.bar()",
         "foo.bar"
       )
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/ForeachTests.scala b/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/ForeachTests.scala
index 82baf8f53..c778bc8b9 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/ForeachTests.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/ForeachTests.scala
@@ -66,21 +66,21 @@ class ForeachTests extends AstSwiftSrc2CpgSuite {
   }
 
   private def checkForLoopWithIdentifier(node: Block, withWhere: Boolean = false): Unit = {
-    val List(localIterator) = node.astChildren.isLocal.nameExact("_iterator_0").l
-    localIterator.code shouldBe "_iterator_0"
+    val List(localIterator) = node.astChildren.isLocal.nameExact("<iterator>0").l
+    localIterator.code shouldBe "<iterator>0"
 
-    val List(localResult) = node.astChildren.isLocal.nameExact("_result_0").l
-    localResult.code shouldBe "_result_0"
+    val List(localResult) = node.astChildren.isLocal.nameExact("<result>0").l
+    localResult.code shouldBe "<result>0"
 
     val List(localI) = node.astChildren.isLocal.nameExact("elem").l
     localI.code shouldBe "elem"
 
     val List(iteratorAssignment) =
-      node.astChildren.isCall.codeExact("_iterator_0 = <operator>.iterator(elements)").l
+      node.astChildren.isCall.codeExact("<iterator>0 = <operator>.iterator(elements)").l
     iteratorAssignment.name shouldBe Operators.assignment
 
     val List(iteratorAssignmentLhs) = iteratorAssignment.astChildren.isIdentifier.l
-    iteratorAssignmentLhs.name shouldBe "_iterator_0"
+    iteratorAssignmentLhs.name shouldBe "<iterator>0"
     iteratorAssignmentLhs.order shouldBe 1
     iteratorAssignmentLhs.argumentIndex shouldBe 1
 
@@ -96,8 +96,8 @@ class ForeachTests extends AstSwiftSrc2CpgSuite {
     objectKeysCallArg.name shouldBe "elements"
     objectKeysCallArg.order shouldBe 1
 
-    val List(varResult) = node.astChildren.isIdentifier.nameExact("_result_0").l
-    varResult.code shouldBe "_result_0"
+    val List(varResult) = node.astChildren.isIdentifier.nameExact("<result>0").l
+    varResult.code shouldBe "<result>0"
 
     val List(varI) = node.astChildren.isIdentifier.nameExact("elem").l
     varI.code shouldBe "elem"
@@ -105,24 +105,24 @@ class ForeachTests extends AstSwiftSrc2CpgSuite {
     val List(loop) = node.astChildren.isControlStructure.l
     loop.controlStructureType shouldBe ControlStructureTypes.WHILE
 
-    val List(loopTestCall) = loop.astChildren.isCall.codeExact("!(_result_0 = _iterator_0.next()).done").l
+    val List(loopTestCall) = loop.astChildren.isCall.codeExact("!(<result>0 = <iterator>0.next()).done").l
     loopTestCall.name shouldBe Operators.not
     loopTestCall.order shouldBe 1
 
-    val List(doneMaCall) = loopTestCall.astChildren.isCall.codeExact("(_result_0 = _iterator_0.next()).done").l
+    val List(doneMaCall) = loopTestCall.astChildren.isCall.codeExact("(<result>0 = <iterator>0.next()).done").l
     doneMaCall.name shouldBe Operators.fieldAccess
 
-    val List(doneMaBase) = doneMaCall.astChildren.isCall.codeExact("(_result_0 = _iterator_0.next())").l
+    val List(doneMaBase) = doneMaCall.astChildren.isCall.codeExact("(<result>0 = <iterator>0.next())").l
     doneMaBase.name shouldBe Operators.assignment
     doneMaBase.order shouldBe 1
     doneMaBase.argumentIndex shouldBe 1
 
     val List(doneMaBaseLhs) = doneMaBase.astChildren.isIdentifier.order(1).l
-    doneMaBaseLhs.name shouldBe "_result_0"
+    doneMaBaseLhs.name shouldBe "<result>0"
     doneMaBaseLhs.argumentIndex shouldBe 1
 
     val List(doneMaBaseRhs) = doneMaBase.astChildren.isCall.order(2).l
-    doneMaBaseRhs.code shouldBe "_iterator_0.next()"
+    doneMaBaseRhs.code shouldBe "<iterator>0.next()"
     doneMaBaseRhs.argumentIndex shouldBe 2
 
     val List(doneMember) = doneMaCall.astChildren.isFieldIdentifier.canonicalNameExact("done").l
@@ -132,7 +132,7 @@ class ForeachTests extends AstSwiftSrc2CpgSuite {
     val List(whileLoopBlock) = loop.astChildren.isBlock.l
     whileLoopBlock.order shouldBe 2
 
-    val List(loopVarAssignmentCall) = whileLoopBlock.astChildren.isCall.codeExact("elem = _result_0.value").l
+    val List(loopVarAssignmentCall) = whileLoopBlock.astChildren.isCall.codeExact("elem = <result>0.value").l
     loopVarAssignmentCall.name shouldBe Operators.assignment
     loopVarAssignmentCall.order shouldBe 1
 
@@ -150,11 +150,11 @@ class ForeachTests extends AstSwiftSrc2CpgSuite {
   }
 
   private def checkForLoopWithTuple(node: Block): Unit = {
-    val List(localIterator) = node.astChildren.isLocal.nameExact("_iterator_0").l
-    localIterator.code shouldBe "_iterator_0"
+    val List(localIterator) = node.astChildren.isLocal.nameExact("<iterator>0").l
+    localIterator.code shouldBe "<iterator>0"
 
-    val List(localResult) = node.astChildren.isLocal.nameExact("_result_0").l
-    localResult.code shouldBe "_result_0"
+    val List(localResult) = node.astChildren.isLocal.nameExact("<result>0").l
+    localResult.code shouldBe "<result>0"
 
     val List(localA) = node.astChildren.isLocal.nameExact("a").l
     localA.code shouldBe "a"
@@ -164,11 +164,11 @@ class ForeachTests extends AstSwiftSrc2CpgSuite {
     localC.code shouldBe "c"
 
     val List(iteratorAssignment) =
-      node.astChildren.isCall.codeExact("_iterator_0 = <operator>.iterator(elements)").l
+      node.astChildren.isCall.codeExact("<iterator>0 = <operator>.iterator(elements)").l
     iteratorAssignment.name shouldBe Operators.assignment
 
     val List(iteratorAssignmentLhs) = iteratorAssignment.astChildren.isIdentifier.l
-    iteratorAssignmentLhs.name shouldBe "_iterator_0"
+    iteratorAssignmentLhs.name shouldBe "<iterator>0"
     iteratorAssignmentLhs.order shouldBe 1
     iteratorAssignmentLhs.argumentIndex shouldBe 1
 
@@ -184,8 +184,8 @@ class ForeachTests extends AstSwiftSrc2CpgSuite {
     objectKeysCallArg.name shouldBe "elements"
     objectKeysCallArg.order shouldBe 1
 
-    val List(varResult) = node.astChildren.isIdentifier.nameExact("_result_0").l
-    varResult.code shouldBe "_result_0"
+    val List(varResult) = node.astChildren.isIdentifier.nameExact("<result>0").l
+    varResult.code shouldBe "<result>0"
 
     val List(varA) = node.astChildren.isIdentifier.nameExact("a").l
     varA.code shouldBe "a"
@@ -197,24 +197,24 @@ class ForeachTests extends AstSwiftSrc2CpgSuite {
     val List(loop) = node.astChildren.isControlStructure.l
     loop.controlStructureType shouldBe ControlStructureTypes.WHILE
 
-    val List(loopTestCall) = loop.astChildren.isCall.codeExact("!(_result_0 = _iterator_0.next()).done").l
+    val List(loopTestCall) = loop.astChildren.isCall.codeExact("!(<result>0 = <iterator>0.next()).done").l
     loopTestCall.name shouldBe Operators.not
     loopTestCall.order shouldBe 1
 
-    val List(doneMaCall) = loopTestCall.astChildren.isCall.codeExact("(_result_0 = _iterator_0.next()).done").l
+    val List(doneMaCall) = loopTestCall.astChildren.isCall.codeExact("(<result>0 = <iterator>0.next()).done").l
     doneMaCall.name shouldBe Operators.fieldAccess
 
-    val List(doneMaBase) = doneMaCall.astChildren.isCall.codeExact("(_result_0 = _iterator_0.next())").l
+    val List(doneMaBase) = doneMaCall.astChildren.isCall.codeExact("(<result>0 = <iterator>0.next())").l
     doneMaBase.name shouldBe Operators.assignment
     doneMaBase.order shouldBe 1
     doneMaBase.argumentIndex shouldBe 1
 
     val List(doneMaBaseLhs) = doneMaBase.astChildren.isIdentifier.order(1).l
-    doneMaBaseLhs.name shouldBe "_result_0"
+    doneMaBaseLhs.name shouldBe "<result>0"
     doneMaBaseLhs.argumentIndex shouldBe 1
 
     val List(doneMaBaseRhs) = doneMaBase.astChildren.isCall.order(2).l
-    doneMaBaseRhs.code shouldBe "_iterator_0.next()"
+    doneMaBaseRhs.code shouldBe "<iterator>0.next()"
     doneMaBaseRhs.argumentIndex shouldBe 2
 
     val List(doneMember) = doneMaCall.astChildren.isFieldIdentifier.canonicalNameExact("done").l
@@ -224,13 +224,13 @@ class ForeachTests extends AstSwiftSrc2CpgSuite {
     val List(whileLoopBlock) = loop.astChildren.isBlock.l
     whileLoopBlock.order shouldBe 2
 
-    val List(loopVarAssignmentCallA) = whileLoopBlock.astChildren.isCall.codeExact("a = _result_0.value._1").l
+    val List(loopVarAssignmentCallA) = whileLoopBlock.astChildren.isCall.codeExact("a = <result>0.value._1").l
     loopVarAssignmentCallA.name shouldBe Operators.assignment
     loopVarAssignmentCallA.order shouldBe 1
-    val List(loopVarAssignmentCallB) = whileLoopBlock.astChildren.isCall.codeExact("b = _result_0.value._2").l
+    val List(loopVarAssignmentCallB) = whileLoopBlock.astChildren.isCall.codeExact("b = <result>0.value._2").l
     loopVarAssignmentCallB.name shouldBe Operators.assignment
     loopVarAssignmentCallB.order shouldBe 2
-    val List(loopVarAssignmentCallC) = whileLoopBlock.astChildren.isCall.codeExact("c = _result_0.value._3").l
+    val List(loopVarAssignmentCallC) = whileLoopBlock.astChildren.isCall.codeExact("c = <result>0.value._3").l
     loopVarAssignmentCallC.name shouldBe Operators.assignment
     loopVarAssignmentCallC.order shouldBe 3
 
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/SuperTests.scala b/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/SuperTests.scala
index c3e538e43..9d4022238 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/SuperTests.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/SuperTests.scala
@@ -33,7 +33,7 @@ class SuperTests extends AstSwiftSrc2CpgSuite {
         |  }
         |}""".stripMargin)
       cpg.typeDecl.nameExact("D").method.isConstructor.block.astChildren.isCall.code.sorted.l shouldBe List(
-        "let wildcard_0: () -> D = self.init"
+        "let <wildcard>0: () -> D = self.init"
       )
     }
 
diff --git a/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/ToplevelLibraryTests.scala b/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/ToplevelLibraryTests.scala
index a70e3645c..05f3d2e3f 100644
--- a/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/ToplevelLibraryTests.scala
+++ b/joern-cli/frontends/swiftsrc2cpg/src/test/scala/io/joern/swiftsrc2cpg/passes/ast/ToplevelLibraryTests.scala
@@ -48,21 +48,21 @@ class ToplevelLibraryTests extends AstSwiftSrc2CpgSuite {
       val List(methodBlock) = method.astChildren.isBlock.l
       val List(loopBlock)   = methodBlock.astChildren.isBlock.l
 
-      val List(localIterator) = loopBlock.astChildren.isLocal.nameExact("_iterator_0").l
-      localIterator.code shouldBe "_iterator_0"
+      val List(localIterator) = loopBlock.astChildren.isLocal.nameExact("<iterator>0").l
+      localIterator.code shouldBe "<iterator>0"
 
-      val List(localResult) = loopBlock.astChildren.isLocal.nameExact("_result_0").l
-      localResult.code shouldBe "_result_0"
+      val List(localResult) = loopBlock.astChildren.isLocal.nameExact("<result>0").l
+      localResult.code shouldBe "<result>0"
 
       val List(localI) = loopBlock.astChildren.isLocal.nameExact("elem").l
       localI.code shouldBe "elem"
 
       val List(iteratorAssignment) =
-        loopBlock.astChildren.isCall.codeExact("_iterator_0 = <operator>.iterator(bar())").l
+        loopBlock.astChildren.isCall.codeExact("<iterator>0 = <operator>.iterator(bar())").l
       iteratorAssignment.name shouldBe Operators.assignment
 
       val List(iteratorAssignmentLhs) = iteratorAssignment.astChildren.isIdentifier.l
-      iteratorAssignmentLhs.name shouldBe "_iterator_0"
+      iteratorAssignmentLhs.name shouldBe "<iterator>0"
       iteratorAssignmentLhs.order shouldBe 1
       iteratorAssignmentLhs.argumentIndex shouldBe 1
 
@@ -79,8 +79,8 @@ class ToplevelLibraryTests extends AstSwiftSrc2CpgSuite {
       objectKeysCallArg.code shouldBe "bar()"
       objectKeysCallArg.order shouldBe 1
 
-      val List(varResult) = loopBlock.astChildren.isIdentifier.nameExact("_result_0").l
-      varResult.code shouldBe "_result_0"
+      val List(varResult) = loopBlock.astChildren.isIdentifier.nameExact("<result>0").l
+      varResult.code shouldBe "<result>0"
 
       val List(varI) = loopBlock.astChildren.isIdentifier.nameExact("elem").l
       varI.code shouldBe "elem"
@@ -88,24 +88,24 @@ class ToplevelLibraryTests extends AstSwiftSrc2CpgSuite {
       val List(loop) = loopBlock.astChildren.isControlStructure.l
       loop.controlStructureType shouldBe ControlStructureTypes.WHILE
 
-      val List(loopTestCall) = loop.astChildren.isCall.codeExact("!(_result_0 = _iterator_0.next()).done").l
+      val List(loopTestCall) = loop.astChildren.isCall.codeExact("!(<result>0 = <iterator>0.next()).done").l
       loopTestCall.name shouldBe Operators.not
       loopTestCall.order shouldBe 1
 
-      val List(doneMaCall) = loopTestCall.astChildren.isCall.codeExact("(_result_0 = _iterator_0.next()).done").l
+      val List(doneMaCall) = loopTestCall.astChildren.isCall.codeExact("(<result>0 = <iterator>0.next()).done").l
       doneMaCall.name shouldBe Operators.fieldAccess
 
-      val List(doneMaBase) = doneMaCall.astChildren.isCall.codeExact("(_result_0 = _iterator_0.next())").l
+      val List(doneMaBase) = doneMaCall.astChildren.isCall.codeExact("(<result>0 = <iterator>0.next())").l
       doneMaBase.name shouldBe Operators.assignment
       doneMaBase.order shouldBe 1
       doneMaBase.argumentIndex shouldBe 1
 
       val List(doneMaBaseLhs) = doneMaBase.astChildren.isIdentifier.order(1).l
-      doneMaBaseLhs.name shouldBe "_result_0"
+      doneMaBaseLhs.name shouldBe "<result>0"
       doneMaBaseLhs.argumentIndex shouldBe 1
 
       val List(doneMaBaseRhs) = doneMaBase.astChildren.isCall.order(2).l
-      doneMaBaseRhs.code shouldBe "_iterator_0.next()"
+      doneMaBaseRhs.code shouldBe "<iterator>0.next()"
       doneMaBaseRhs.argumentIndex shouldBe 2
 
       val List(doneMember) = doneMaCall.astChildren.isFieldIdentifier.canonicalNameExact("done").l
@@ -115,7 +115,7 @@ class ToplevelLibraryTests extends AstSwiftSrc2CpgSuite {
       val List(whileLoopBlock) = loop.astChildren.isBlock.l
       whileLoopBlock.order shouldBe 2
 
-      val List(loopVarAssignmentCall) = whileLoopBlock.astChildren.isCall.codeExact("elem = _result_0.value").l
+      val List(loopVarAssignmentCall) = whileLoopBlock.astChildren.isCall.codeExact("elem = <result>0.value").l
       loopVarAssignmentCall.name shouldBe Operators.assignment
       loopVarAssignmentCall.order shouldBe 1