Skip to content

Commit 198b1e0

Browse files
committed
Revert "Revert "Upgrade to ASM 7.0""
This reverts commit 5a74718 which itself reverted 0abd076. Since scala#5936 is not fixed yet, we need to turn off one test in semanticdb which uses parens in a class name.
1 parent 2d9b3d1 commit 198b1e0

File tree

10 files changed

+145
-23
lines changed

10 files changed

+145
-23
lines changed

compiler/src/dotty/tools/backend/jvm/AsmUtils.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package backend
33
package jvm
44

5-
import scala.tools.asm.tree.{AbstractInsnNode, ClassNode, MethodNode}
5+
import scala.tools.asm.tree.{AbstractInsnNode}
66
import java.io.PrintWriter
77
import scala.tools.asm.util.{TraceClassVisitor, TraceMethodVisitor, Textifier}
88
import scala.tools.asm.ClassReader
@@ -31,7 +31,7 @@ object AsmUtils {
3131
final val traceSerializedClassEnabled = false
3232
final val traceSerializedClassPattern = ""
3333

34-
def traceMethod(mnode: MethodNode): Unit = {
34+
def traceMethod(mnode: MethodNode1): Unit = {
3535
println(s"Bytecode for method ${mnode.name}")
3636
val p = new Textifier
3737
val tracer = new TraceMethodVisitor(p)
@@ -41,7 +41,7 @@ object AsmUtils {
4141
w.flush()
4242
}
4343

44-
def traceClass(cnode: ClassNode): Unit = {
44+
def traceClass(cnode: ClassNode1): Unit = {
4545
println(s"Bytecode for class ${cnode.name}")
4646
val w = new PrintWriter(System.out)
4747
cnode.accept(new TraceClassVisitor(w))
@@ -50,8 +50,8 @@ object AsmUtils {
5050

5151
def traceClass(bytes: Array[Byte]): Unit = traceClass(readClass(bytes))
5252

53-
def readClass(bytes: Array[Byte]): ClassNode = {
54-
val node = new ClassNode()
53+
def readClass(bytes: Array[Byte]): ClassNode1 = {
54+
val node = new ClassNode1()
5555
new ClassReader(bytes).accept(node, 0)
5656
node
5757
}

compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package backend
33
package jvm
44

55
import scala.tools.asm
6+
import scala.tools.asm.ClassWriter
67
import scala.collection.mutable
78
import dotty.tools.io.AbstractFile
89

@@ -111,6 +112,20 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
111112
}
112113
}
113114

115+
/*
116+
* can-multi-thread
117+
*/
118+
def createJAttribute(name: String, b: Array[Byte], offset: Int, len: Int): asm.Attribute = {
119+
new asm.Attribute(name) {
120+
override def write(classWriter: ClassWriter, code: Array[Byte],
121+
codeLength: Int, maxStack: Int, maxLocals: Int): asm.ByteVector = {
122+
val byteVector = new asm.ByteVector(len)
123+
byteVector.putByteArray(b, offset, len)
124+
byteVector
125+
}
126+
}
127+
}
128+
114129
/*
115130
* Custom attribute (JVMS 4.7.1) "ScalaSig" used as marker only
116131
* i.e., the pickle is contained in a custom annotation, see:
@@ -136,15 +151,6 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
136151
vp
137152
}
138153

139-
/*
140-
* can-multi-thread
141-
*/
142-
def createJAttribute(name: String, b: Array[Byte], offset: Int, len: Int): asm.Attribute = {
143-
val dest = new Array[Byte](len)
144-
System.arraycopy(b, offset, dest, 0, len)
145-
new asm.CustomAttr(name, dest)
146-
}
147-
148154
/*
149155
* can-multi-thread
150156
*/

compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
5353
final val MaximumJvmParameters = 254
5454

5555
// current class
56-
var cnode: asm.tree.ClassNode = null
56+
var cnode: ClassNode1 = null
5757
var thisName: String = null // the internal name of the class being emitted
5858

5959
var claszSymbol: Symbol = null
@@ -88,7 +88,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
8888
isCZStaticModule = claszSymbol.isStaticModuleClass
8989
thisName = internalName(claszSymbol)
9090

91-
cnode = new asm.tree.ClassNode()
91+
cnode = new ClassNode1()
9292

9393
initJClass(cnode)
9494

@@ -248,7 +248,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
248248
} // end of method addClassFields()
249249

250250
// current method
251-
var mnode: asm.tree.MethodNode = null
251+
var mnode: MethodNode1 = null
252252
var jMethodName: String = null
253253
var isMethSymStaticCtor = false
254254
var returnType: BType = null
@@ -526,7 +526,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
526526
mdesc,
527527
jgensig,
528528
mkArrayS(thrownExceptions)
529-
).asInstanceOf[asm.tree.MethodNode]
529+
).asInstanceOf[MethodNode1]
530530

531531
// TODO param names: (m.params map (p => javaName(p.sym)))
532532

compiler/src/dotty/tools/backend/jvm/BytecodeWriters.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ trait BytecodeWriters {
8282
private def emitAsmp(jclassBytes: Array[Byte], asmpFile: dotty.tools.io.File): Unit = {
8383
val pw = asmpFile.printWriter()
8484
try {
85-
val cnode = new asm.tree.ClassNode()
85+
val cnode = new ClassNode1()
8686
val cr = new asm.ClassReader(jclassBytes)
8787
cr.accept(cnode, 0)
8888
val trace = new scala.tools.asm.util.TraceClassVisitor(new java.io.PrintWriter(new java.io.StringWriter()))
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package dotty.tools.backend.jvm;
14+
15+
import scala.tools.asm.MethodVisitor;
16+
import scala.tools.asm.Opcodes;
17+
import scala.tools.asm.tree.ClassNode;
18+
import scala.tools.asm.tree.MethodNode;
19+
20+
/**
21+
* A subclass of {@link ClassNode} to customize the representation of
22+
* label nodes with {@link LabelNode1}.
23+
*/
24+
public class ClassNode1 extends ClassNode {
25+
public ClassNode1() {
26+
this(Opcodes.ASM6);
27+
}
28+
29+
public ClassNode1(int api) {
30+
super(api);
31+
}
32+
33+
@Override
34+
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
35+
MethodNode method = new MethodNode1(access, name, descriptor, signature, exceptions);
36+
methods.add(method);
37+
return method;
38+
}
39+
}

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import dotty.tools.dotc.core.Phases.Phase
77

88
import scala.collection.mutable
99
import scala.collection.JavaConverters._
10-
import scala.tools.asm.CustomAttr
1110
import dotty.tools.dotc.transform.SymUtils._
1211
import dotty.tools.dotc.interfaces
1312
import dotty.tools.dotc.util.SourceFile
@@ -241,7 +240,7 @@ class GenBCodePipeline(val int: DottyBackendInterface)(implicit val ctx: Context
241240
getFileForClassfile(outF, store.name, ".hasTasty")
242241
binary
243242
}
244-
val dataAttr = new CustomAttr(nme.TASTYATTR.mangledString, tasty)
243+
val dataAttr = createJAttribute(nme.TASTYATTR.mangledString, tasty, 0, tasty.length)
245244
store.visitAttribute(dataAttr)
246245
}
247246

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package dotty.tools.backend.jvm;
14+
15+
import scala.tools.asm.Label;
16+
import scala.tools.asm.tree.ClassNode;
17+
import scala.tools.asm.tree.LabelNode;
18+
19+
/**
20+
* A subclass of {@link LabelNode} to add user-definable flags.
21+
*/
22+
public class LabelNode1 extends LabelNode {
23+
public LabelNode1() {
24+
}
25+
26+
public LabelNode1(Label label) {
27+
super(label);
28+
}
29+
30+
public int flags;
31+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Scala (https://www.scala-lang.org)
3+
*
4+
* Copyright EPFL and Lightbend, Inc.
5+
*
6+
* Licensed under Apache License 2.0
7+
* (http://www.apache.org/licenses/LICENSE-2.0).
8+
*
9+
* See the NOTICE file distributed with this work for
10+
* additional information regarding copyright ownership.
11+
*/
12+
13+
package dotty.tools.backend.jvm;
14+
15+
import scala.tools.asm.Label;
16+
import scala.tools.asm.Opcodes;
17+
import scala.tools.asm.tree.LabelNode;
18+
import scala.tools.asm.tree.MethodNode;
19+
/**
20+
* A subclass of {@link MethodNode} to customize the representation of
21+
* label nodes with {@link LabelNode1}.
22+
*/
23+
public class MethodNode1 extends MethodNode {
24+
public MethodNode1(int api, int access, String name, String descriptor, String signature, String[] exceptions) {
25+
super(api, access, name, descriptor, signature, exceptions);
26+
}
27+
28+
public MethodNode1(int access, String name, String descriptor, String signature, String[] exceptions) {
29+
this(Opcodes.ASM6, access, name, descriptor, signature, exceptions);
30+
}
31+
32+
public MethodNode1(int api) {
33+
super(api);
34+
}
35+
36+
public MethodNode1() {
37+
this(Opcodes.ASM6);
38+
}
39+
40+
@Override
41+
protected LabelNode getLabelNode(Label label) {
42+
if (!(label.info instanceof LabelNode)) {
43+
label.info = new LabelNode1(label);
44+
}
45+
return (LabelNode) label.info;
46+
}
47+
}

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ object Build {
482482

483483
// get libraries onboard
484484
libraryDependencies ++= Seq(
485-
"org.scala-lang.modules" % "scala-asm" % "6.0.0-scala-1", // used by the backend
485+
"org.scala-lang.modules" % "scala-asm" % "7.0.0-scala-1", // used by the backend
486486
Dependencies.`compiler-interface`,
487487
"org.jline" % "jline-reader" % "3.9.0", // used by the REPL
488488
"org.jline" % "jline-terminal" % "3.9.0",

0 commit comments

Comments
 (0)