Skip to content

Commit 1aaec74

Browse files
committed
[WIP] Fixes towards integrating with Checker framework
Better treatment of params in nullification policy: if a param is specified as non-null, that only applies to the outermost level. Also, let's try a different approach to getting the descriptors from the java methods/fields. Instead of trying to re-generate the descriptor from the type, let's try to grab it from the class file (not done yet).
1 parent 21312f1 commit 1aaec74

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

compiler/src/dotty/tools/dotc/core/JavaNull.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ object JavaNull {
2929
FieldP(_.name == nme.TYPE_),
3030
// The `toString` method.
3131
MethodP(_.name == nme.toString_, Seq.empty, nnRes = true),
32-
// stdLibP(sym, tp),
3332
// Constructors: params are nullified, but the result type isn't.
3433
paramsOnlyP(_.isConstructor),
34+
// stdLibP(sym, tp)
3535
// )
3636
) ++ Seq(
3737
// Methods in `java.lang.String`.
@@ -49,7 +49,7 @@ object JavaNull {
4949
// Methods in `java.lang.Class`
5050
paramsOnlyP(_.name == nme.newInstance),
5151
paramsOnlyP(_.name == nme.asSubclass),
52-
paramsOnlyP(_.name == jnme.ForName),
52+
paramsOnlyP(_.name == jnme.ForName)
5353
).map(WithinSym(_, defn.ClassClass))
5454

5555
val (fromWhitelistTp, handled) = whitelist.foldLeft((tp, false)) {
@@ -70,7 +70,7 @@ object JavaNull {
7070
private case class ClassStats(name: String, fields: Seq[FieldStats], methods: Seq[MethodStats]) {
7171
private def find(sym: Symbol, tp: Type, nameToDesc: Seq[(String, String)])(implicit ctx: Context): Option[Int] = {
7272
val name = sym.name.show
73-
val descOpt = GenericSignatures.javaDescriptor(sym, tp)
73+
val descOpt: Option[String] = None
7474
descOpt match {
7575
case Some(desc) =>
7676
nameToDesc.indexOf((name, desc)) match {
@@ -156,9 +156,11 @@ object JavaNull {
156156
case (paramInfo, index) =>
157157
// TODO(abeln): the sequence lookup can be optimized, because the indices
158158
// in it appear in increasing order.
159-
if (nnParams.contains(index)) paramInfo else nullifyType(paramInfo)
159+
val nullTpe = nullifyType(paramInfo)
160+
if (nnParams.contains(index)) nullTpe.stripNull else nullTpe
160161
}
161-
val resTpe = if (nnRes) mtp.resType else nullifyType(mtp.resType)
162+
val nullRes = nullifyType(mtp.resType)
163+
val resTpe = if (nnRes) nullRes.stripNull else nullRes
162164
derivedLambdaType(mtp)(paramTpes, resTpe)
163165
}
164166
}

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,11 @@ object GenericSignatures {
3232
def javaSig(sym0: Symbol, info: Type)(implicit ctx: Context): Option[String] = {
3333
// Avoid generating a signature for local symbols.
3434
if (sym0.isLocal) None
35-
else javaSig0(sym0, info, descriptor = false)(ctx.withPhase(ctx.erasurePhase))
36-
}
37-
38-
def javaDescriptor(sym0: Symbol, info: Type)(implicit ctx: Context): Option[String] = {
39-
// Avoid generating a signature for local symbols.
40-
if (sym0.isLocal) None
41-
else {
42-
ctx.atPhase(ctx.erasurePhase) { implicit ctx =>
43-
javaSig0(sym0, info, descriptor = true)
44-
}
45-
}
35+
else javaSig0(sym0, info)(ctx.withPhase(ctx.erasurePhase))
4636
}
4737

4838
@noinline
49-
private final def javaSig0(sym0: Symbol, info: Type, descriptor: Boolean)(implicit ctx: Context): Option[String] = {
39+
private final def javaSig0(sym0: Symbol, info: Type)(implicit ctx: Context): Option[String] = {
5040
val builder = new StringBuilder(64)
5141
val isTraitSignature = sym0.enclosingClass.is(Trait)
5242

@@ -302,7 +292,7 @@ object GenericSignatures {
302292
}
303293
}
304294
val throwsArgs = sym0.annotations flatMap ThrownException.unapply
305-
if (descriptor || needsJavaSig(info, throwsArgs)) {
295+
if (needsJavaSig(info, throwsArgs)) {
306296
try {
307297
jsig(info, toplevel = true)
308298
throwsArgs.foreach { t =>

0 commit comments

Comments
 (0)