zinc icon indicating copy to clipboard operation
zinc copied to clipboard

Inheritance of a field with a return type A causes A to be necessary in scalac analysis

Open stuhood opened this issue 9 years ago • 7 comments

When a scala class extends a trait with a concrete field with a particular return type, the classfile for that return type is occasionally (always?) required for compilation to succeed. But these inherited methods are not always tracked in zinc's scala analysis.

stuhood avatar Jul 13 '16 19:07 stuhood

Can you provide a testcase?

smarter avatar Jul 13 '16 19:07 smarter

Hello @stuhood, I confirm that if the field on the trait is used anywhere in the program, its classfile is necessary (I've been working on the stub errors proposal that Twitter submitted to the Advisory Board). I'll have a look at this soon, it would be great if you could provide a test case to get me going faster.

jvican avatar Feb 03 '17 11:02 jvican

@stuhood I definitely need a little bit more of background to move on this front. What's "particular return type"? What do you mean by "inherited methods are not always tracked"?

Can you provide a test case? With it, I'll be able to fix this issue soon. Otherwise this fix won't make in on time for the beta I'm preparing.

jvican avatar Feb 19 '17 20:02 jvican

I created a repro repo/branch here: https://github.com/stuhood/pants-repros/tree/stuhood/sbt-zinc-150 ... it has strict_deps enabled, so only directly declared dependencies will be present on the classpath.

Running ./pants compile :: will report an "unused dep" warning after compiling c that indicates that it didn't need a on the classpath. But removing a from c's classpath causes c to fail to compile.

Inspecting the analysis for c at: .pants.d/compile/zinc/current/src.scala.com.example.c.c/current/src.scala.com.example.c.c.analysis indicates that c has no references to a.

It does, on the other hand, have an inheritance reference to b. If zinc is properly walking inheritance relationships to invalidate subclasses, then this might not be a bug... just a failure of pants to do the same thing.

stuhood avatar Feb 23 '17 19:02 stuhood

Thank you @stuhood, I wish i would get these kind of minimisations every day. I'll try to see what's happening in the Zinc side and how to fix it.

Regarding your repo, I was not able to reproduce the "unused dep" warning after compiling c when running ./pants compile ::. I don't get any warning. This is the output I get:

jvican in /data/rw/code/scala/pants-repros                            [10:13:37] 
> $ ./pants compile ::                                                 [±master]

10:14:55 00:00 [main]
               (To run a reporting server: ./pants server)
10:14:55 00:00   [setup]
10:14:55 00:00     [parse]
               Executing tasks in goals: bootstrap -> imports -> unpack-jars -> deferred-sources -> gen -> jvm-platform-validate -> resolve -> compile
10:14:55 00:00   [bootstrap]
10:14:55 00:00     [substitute-aliased-targets]
10:14:55 00:00     [jar-dependency-management]
10:14:55 00:00     [bootstrap-jvm-tools]
10:14:55 00:00     [provide-tools-jar]
10:14:55 00:00   [imports]
10:14:55 00:00     [ivy-imports]
10:14:55 00:00   [unpack-jars]
10:14:55 00:00     [unpack-jars]
10:14:55 00:00   [deferred-sources]
10:14:55 00:00     [deferred-sources]
10:14:55 00:00   [gen]
10:14:55 00:00     [antlr-java]
10:14:55 00:00     [antlr-py]
10:14:55 00:00     [jaxb]
10:14:55 00:00     [protoc]
10:14:55 00:00     [ragel]
10:14:55 00:00     [thrift-java]
10:14:55 00:00     [thrift-py]
10:14:55 00:00     [wire]
10:14:55 00:00   [jvm-platform-validate]
10:14:55 00:00     [jvm-platform-validate]
10:14:55 00:00   [resolve]
10:14:55 00:00     [ivy]
10:14:55 00:00   [compile]
10:14:55 00:00     [compile-jvm-prep-command]
10:14:55 00:00       [jvm_prep_command]
10:14:55 00:00     [scalafmt]
10:14:55 00:00     [compile-prep-command]
10:14:55 00:00     [compile]
10:14:55 00:00     [zinc]
10:14:55 00:00     [jvm-dep-check]
10:14:55 00:00   [complete]
               SUCCESS

I suppose this is somehow related to the option strict_deps not being correctly handled?

Also, when I try to inspect the analysis file, .pants.d/compile does not exist. I'm not familiar with pants, is there something special I have to do?

jvican avatar Feb 24 '17 09:02 jvican

You're running on master: need to use the branch I linked to.

On Feb 24, 2017 1:23 AM, "Jorge" [email protected] wrote:

Thank you @stuhood https://github.com/stuhood, I wish i would get these kind of minimisations every day. I'll try to see what's happening in the Zinc side and how to fix it.

Regarding your repo, I was not able to reproduce the "unused dep" warning after compiling c when running ./pants compile ::. I don't get any warning. This is the output I get:

jvican in /data/rw/code/scala/pants-repros [10:13:37]

$ ./pants compile :: [±master]

10:14:55 00:00 [main] (To run a reporting server: ./pants server) 10:14:55 00:00 [setup] 10:14:55 00:00 [parse] Executing tasks in goals: bootstrap -> imports -> unpack-jars -> deferred-sources -> gen -> jvm-platform-validate -> resolve -> compile 10:14:55 00:00 [bootstrap] 10:14:55 00:00 [substitute-aliased-targets] 10:14:55 00:00 [jar-dependency-management] 10:14:55 00:00 [bootstrap-jvm-tools] 10:14:55 00:00 [provide-tools-jar] 10:14:55 00:00 [imports] 10:14:55 00:00 [ivy-imports] 10:14:55 00:00 [unpack-jars] 10:14:55 00:00 [unpack-jars] 10:14:55 00:00 [deferred-sources] 10:14:55 00:00 [deferred-sources] 10:14:55 00:00 [gen] 10:14:55 00:00 [antlr-java] 10:14:55 00:00 [antlr-py] 10:14:55 00:00 [jaxb] 10:14:55 00:00 [protoc] 10:14:55 00:00 [ragel] 10:14:55 00:00 [thrift-java] 10:14:55 00:00 [thrift-py] 10:14:55 00:00 [wire] 10:14:55 00:00 [jvm-platform-validate] 10:14:55 00:00 [jvm-platform-validate] 10:14:55 00:00 [resolve] 10:14:55 00:00 [ivy] 10:14:55 00:00 [compile] 10:14:55 00:00 [compile-jvm-prep-command] 10:14:55 00:00 [jvm_prep_command] 10:14:55 00:00 [scalafmt] 10:14:55 00:00 [compile-prep-command] 10:14:55 00:00 [compile] 10:14:55 00:00 [zinc] 10:14:55 00:00 [jvm-dep-check] 10:14:55 00:00 [complete] SUCCESS

I suppose this is somehow related to the option strict_deps not being correctly handled?

Also, when I try to inspect the analysis file, .pants.d/compile does not exist. I'm not familiar with pants, is there something special I have to do?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/sbt/zinc/issues/150#issuecomment-282244448, or mute the thread https://github.com/notifications/unsubscribe-auth/AAC2lKyxcoyHy6b_zc4lzGPw87R5uv2Fks5rfqGBgaJpZM4JLxMv .

stuhood avatar Feb 24 '17 16:02 stuhood

Right, I was able to reproduce. Will keep you posted on this one.

jvican avatar Feb 24 '17 17:02 jvican