Skip to content

Commit 9299f05

Browse files
authored
Simplify pattern matching of CallArgument (#11943)
* Do not use CallArgument in extractor pattern match * Use new instead of apply
1 parent 9cd355c commit 9299f05

File tree

11 files changed

+76
-41
lines changed

11 files changed

+76
-41
lines changed

engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/AliasAnalysis.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -653,13 +653,13 @@ case object AliasAnalysis extends IRPass {
653653
args: List[CallArgument],
654654
builder: GraphBuilder
655655
): List[CallArgument] = {
656-
args.map { case arg @ CallArgument.Specified(_, expr, _, _, _) =>
657-
val currentScope = expr match {
656+
args.map { case arg: CallArgument.Specified =>
657+
val currentScope = arg.value match {
658658
case _: Literal => builder
659659
case _ => builder.addChild()
660660
}
661661
arg
662-
.copy(value = analyseExpression(expr, currentScope))
662+
.copy(value = analyseExpression(arg.value, currentScope))
663663
.updateMetadata(
664664
new MetadataPair(
665665
this,

engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/AutomaticParallelism.scala

+17-6
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,18 @@ object AutomaticParallelism extends IRPass {
322322
val refWrite = Application.Prefix(
323323
Name.Special(Name.Special.WriteRef, null),
324324
List(
325-
CallArgument
326-
.Specified(None, refVars(bind.name).duplicate(), true, null),
327-
CallArgument.Specified(None, bind.name.duplicate(), true, null)
325+
new CallArgument.Specified(
326+
None,
327+
refVars(bind.name).duplicate(),
328+
true,
329+
null
330+
),
331+
new CallArgument.Specified(
332+
None,
333+
bind.name.duplicate(),
334+
true,
335+
null
336+
)
328337
),
329338
false,
330339
null
@@ -335,7 +344,7 @@ object AutomaticParallelism extends IRPass {
335344
val spawn = Application.Prefix(
336345
Name.Special(Name.Special.RunThread, null),
337346
List(
338-
CallArgument.Specified(
347+
new CallArgument.Specified(
339348
None,
340349
Expression.Block(blockBody.init, blockBody.last, null),
341350
true,
@@ -355,7 +364,9 @@ object AutomaticParallelism extends IRPass {
355364
val threadJoins = threadSpawns.map { bind =>
356365
Application.Prefix(
357366
Name.Special(Name.Special.JoinThread, null),
358-
List(CallArgument.Specified(None, bind.name.duplicate(), true, null)),
367+
List(
368+
new CallArgument.Specified(None, bind.name.duplicate(), true, null)
369+
),
359370
false,
360371
null
361372
)
@@ -367,7 +378,7 @@ object AutomaticParallelism extends IRPass {
367378
name.duplicate(),
368379
Application.Prefix(
369380
Name.Special(Name.Special.ReadRef, null),
370-
List(CallArgument.Specified(None, ref.duplicate(), true, null)),
381+
List(new CallArgument.Specified(None, ref.duplicate(), true, null)),
371382
false,
372383
null
373384
),

engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/DataflowAnalysis.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -745,20 +745,20 @@ case object DataflowAnalysis extends IRPass {
745745
info: DependencyInfo
746746
): CallArgument = {
747747
argument match {
748-
case spec @ CallArgument.Specified(name, value, _, _, _) =>
748+
case spec: CallArgument.Specified =>
749749
val specDep = asStatic(spec)
750-
val valueDep = asStatic(value)
750+
val valueDep = asStatic(spec.value)
751751
info.dependents.updateAt(valueDep, Set(specDep))
752752
info.dependencies.updateAt(specDep, Set(valueDep))
753-
name.foreach(name => {
753+
spec.name.foreach(name => {
754754
val nameDep = asStatic(name)
755755
info.dependents.updateAt(nameDep, Set(specDep))
756756
info.dependencies.updateAt(specDep, Set(nameDep))
757757
})
758758

759759
spec
760760
.copy(
761-
value = analyseExpression(value, info)
761+
value = analyseExpression(spec.value, info)
762762
)
763763
.updateMetadata(new MetadataPair(this, info))
764764
}

engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/analyse/FramePointerAnalysis.scala

+6-7
Original file line numberDiff line numberDiff line change
@@ -242,13 +242,12 @@ case object FramePointerAnalysis extends IRPass {
242242
arguments: List[CallArgument],
243243
graph: Graph
244244
): Unit = {
245-
arguments.foreach {
246-
case arg @ CallArgument.Specified(name, value, _, _, _) =>
247-
maybeAttachFramePointer(arg, graph)
248-
name.foreach(maybeAttachFramePointer(_, graph))
249-
processExpression(value, graph, false)
250-
maybAttachFrameVariableNames(value)
251-
maybAttachFrameVariableNames(arg)
245+
arguments.foreach { case arg: CallArgument.Specified =>
246+
maybeAttachFramePointer(arg, graph)
247+
arg.name.foreach(maybeAttachFramePointer(_, graph))
248+
processExpression(arg.value, graph, false)
249+
maybAttachFrameVariableNames(arg.value)
250+
maybAttachFrameVariableNames(arg)
252251
}
253252
}
254253

engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/desugar/LambdaShorthandToLambdaMini.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ class LambdaShorthandToLambdaMini(
3434
parent match {
3535
case Application.Prefix(fn, args, _, _, _) =>
3636
val hasBlankArg = args.exists {
37-
case CallArgument.Specified(_, _: Name.Blank, _, _, _) => true
38-
case _ => false
37+
case arg: CallArgument.Specified
38+
if arg.value.isInstanceOf[Name.Blank] =>
39+
true
40+
case _ => false
3941
}
4042
val hasBlankFn = fn.isInstanceOf[Name.Blank]
4143
hasBlankArg || hasBlankFn

engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/GlobalNames.scala

+7-2
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ case object GlobalNames extends IRPass {
224224
val app = Application.Prefix(
225225
fun,
226226
List(
227-
CallArgument.Specified(
227+
new CallArgument.Specified(
228228
None,
229229
self,
230230
true,
@@ -352,7 +352,12 @@ case object GlobalNames extends IRPass {
352352
)
353353
)
354354
val selfArg =
355-
CallArgument.Specified(None, self, true, identifiedLocation = null)
355+
new CallArgument.Specified(
356+
None,
357+
self,
358+
true,
359+
identifiedLocation = null
360+
)
356361
processedFun.passData.remove(this) // Necessary for IrToTruffle
357362
app.copy(function = processedFun, arguments = selfArg :: processedArgs)
358363
case _ =>

engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/analyse/GatherDiagnosticsTest.scala

+6-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ class GatherDiagnosticsTest extends CompilerTest {
2626
val plusApp = Application.Prefix(
2727
plusOp,
2828
List(
29-
CallArgument.Specified(None, error1, false, identifiedLocation = null)
29+
new CallArgument.Specified(
30+
None,
31+
error1,
32+
false,
33+
identifiedLocation = null
34+
)
3035
),
3136
hasDefaultsSuspended = false,
3237
identifiedLocation = null

engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/OperatorToFunctionTest.scala

+18-8
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ class OperatorToFunctionTest extends MiniPassTest {
6565
val loc = new IdentifiedLocation(new Location(1, 33))
6666

6767
val leftArg =
68-
CallArgument.Specified(None, left, false, left.identifiedLocation())
68+
new CallArgument.Specified(None, left, false, left.identifiedLocation())
6969
val rightArg =
70-
CallArgument.Specified(None, right, false, right.identifiedLocation())
70+
new CallArgument.Specified(None, right, false, right.identifiedLocation())
7171

7272
val binOp =
7373
Operator.Binary(leftArg, name, rightArg, loc)
@@ -86,19 +86,19 @@ class OperatorToFunctionTest extends MiniPassTest {
8686
Name.Literal("=:=", isMethod = true, null)
8787
val left = Empty(null)
8888
val right = Empty(null)
89-
val rightArg = CallArgument.Specified(None, Empty(null), false, null)
89+
val rightArg = new CallArgument.Specified(None, Empty(null), false, null)
9090

9191
val (operator, operatorFn) = genOprAndFn(opName, left, right)
9292

93-
val oprArg = CallArgument.Specified(None, operator, false, null)
94-
val oprFnArg = CallArgument.Specified(None, operatorFn, false, null)
93+
val oprArg = new CallArgument.Specified(None, operator, false, null)
94+
val oprFnArg = new CallArgument.Specified(None, operatorFn, false, null)
9595

9696
"Operators" should {
9797
val opName =
9898
Name.Literal("=:=", isMethod = true, identifiedLocation = null)
9999
val left = Empty(identifiedLocation = null)
100100
val right = Empty(identifiedLocation = null)
101-
val rightArg = CallArgument.Specified(
101+
val rightArg = new CallArgument.Specified(
102102
None,
103103
Empty(identifiedLocation = null),
104104
false,
@@ -108,9 +108,19 @@ class OperatorToFunctionTest extends MiniPassTest {
108108
val (operator, operatorFn) = genOprAndFn(opName, left, right)
109109

110110
val oprArg =
111-
CallArgument.Specified(None, operator, false, identifiedLocation = null)
111+
new CallArgument.Specified(
112+
None,
113+
operator,
114+
false,
115+
identifiedLocation = null
116+
)
112117
val oprFnArg =
113-
CallArgument.Specified(None, operatorFn, false, identifiedLocation = null)
118+
new CallArgument.Specified(
119+
None,
120+
operatorFn,
121+
false,
122+
identifiedLocation = null
123+
)
114124

115125
"be translated to functions" in {
116126
OperatorToFunctionTestPass.runExpression(

engine/runtime-integration-tests/src/test/scala/org/enso/compiler/test/pass/desugar/SectionsToBinOpMegaPass.scala

+6-6
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ case object SectionsToBinOpMegaPass extends IRPass {
105105
case sectionLeft @ Section.Left(arg, op, loc, passData) =>
106106
val rightArgName = freshNameSupply.newName()
107107
val rightCallArg =
108-
CallArgument.Specified(
108+
new CallArgument.Specified(
109109
None,
110110
rightArgName,
111111
true,
@@ -122,7 +122,7 @@ case object SectionsToBinOpMegaPass extends IRPass {
122122
if (arg.value.isInstanceOf[Name.Blank]) {
123123
val leftArgName = freshNameSupply.newName()
124124
val leftCallArg =
125-
CallArgument.Specified(
125+
new CallArgument.Specified(
126126
None,
127127
leftArgName,
128128
true,
@@ -171,7 +171,7 @@ case object SectionsToBinOpMegaPass extends IRPass {
171171
case sectionSides @ Section.Sides(op, loc, passData) =>
172172
val leftArgName = freshNameSupply.newName()
173173
val leftCallArg =
174-
CallArgument.Specified(
174+
new CallArgument.Specified(
175175
None,
176176
leftArgName,
177177
true,
@@ -187,7 +187,7 @@ case object SectionsToBinOpMegaPass extends IRPass {
187187

188188
val rightArgName = freshNameSupply.newName()
189189
val rightCallArg =
190-
CallArgument.Specified(
190+
new CallArgument.Specified(
191191
None,
192192
rightArgName,
193193
true,
@@ -244,7 +244,7 @@ case object SectionsToBinOpMegaPass extends IRPass {
244244
case sectionRight @ Section.Right(op, arg, loc, passData) =>
245245
val leftArgName = freshNameSupply.newName()
246246
val leftCallArg =
247-
CallArgument.Specified(
247+
new CallArgument.Specified(
248248
None,
249249
leftArgName,
250250
true,
@@ -263,7 +263,7 @@ case object SectionsToBinOpMegaPass extends IRPass {
263263
// Note [Blanks in Sections]
264264
val rightArgName = freshNameSupply.newName()
265265
val rightCallArg =
266-
CallArgument.Specified(
266+
new CallArgument.Specified(
267267
None,
268268
rightArgName,
269269
true,

engine/runtime-parser/src/main/scala/org/enso/compiler/core/ir/CallArgument.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ object CallArgument {
8383
|| diagnostics != this.diagnostics
8484
|| id != this.id
8585
) {
86-
val res = Specified(name, value, isSynthetic, location.orNull, passData)
86+
val res =
87+
new Specified(name, value, isSynthetic, location.orNull, passData)
8788
res.diagnostics = diagnostics
8889
res.id = id
8990
res

engine/runtime/src/main/scala/org/enso/interpreter/runtime/IrToTruffle.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -2468,7 +2468,9 @@ class IrToTruffle(
24682468
subjectToInstrumentation: Boolean
24692469
): callable.argument.CallArgument =
24702470
arg match {
2471-
case CallArgument.Specified(name, value, _, _, _) =>
2471+
case specifiedArg: CallArgument.Specified =>
2472+
val name = specifiedArg.name
2473+
val value = specifiedArg.value
24722474
val scopeInfo = childScopeInfo("call argument", arg)
24732475

24742476
def valueHasSomeTypeCheck() =

0 commit comments

Comments
 (0)