Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1441: init MODULE$ in <clinit> #9181

Merged
merged 35 commits into from
Aug 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
506ef7c
Fix #1441: init $MODULE in <clinit>
liufengyun Jun 12, 2020
6b28347
Remove old init code in constructor
liufengyun Jun 14, 2020
7426c78
Handle class field uniformly
liufengyun Jun 14, 2020
967375d
Fix flags of MODULE field
liufengyun Jun 14, 2020
b07b47c
Remove legacy code
liufengyun Jun 14, 2020
7e232e7
Add jvm-9 as target
liufengyun Jun 14, 2020
4cd9626
Avoid Ycheck errors
liufengyun Jun 14, 2020
a2d9003
Pass -Ycheck
liufengyun Jun 14, 2020
3adfcea
Handle undesugared ident
liufengyun Jun 15, 2020
04d0dc9
Performance tweak
liufengyun Jun 15, 2020
7ad5beb
Handle existing <clinit> in template
liufengyun Jun 15, 2020
3e6fb43
Handle super calls properly
liufengyun Jun 15, 2020
fff0162
Use backend magic to handle super calls
liufengyun Jul 10, 2020
93e1c9e
Fix usage of ctx
liufengyun Jul 15, 2020
0cc4dfa
Generate super accessors for inner classes
liufengyun Jul 15, 2020
1fbd26f
Fix #9341: add test
liufengyun Jul 15, 2020
80e6f94
Add test
liufengyun Jul 15, 2020
1f18857
Add test case t10290
liufengyun Jul 15, 2020
a79c835
Generate super accessor for traits
liufengyun Jul 15, 2020
b9502e3
Special case Array.scala compilation
liufengyun Jul 15, 2020
90d00ec
Handle super calls in blocks
liufengyun Jul 15, 2020
d002c78
Remove unsupported options
liufengyun Jul 21, 2020
b1a5234
Add comment as doc
liufengyun Jul 21, 2020
d2419fc
Fix usage of context
liufengyun Jul 21, 2020
b05ce6c
Update compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
liufengyun Jul 21, 2020
5acfdbb
Check that qual of Super is always This
liufengyun Jul 21, 2020
7e3c61b
The qual of This could be Ident
liufengyun Jul 21, 2020
867e56e
Port scala.js changes
liufengyun Jul 21, 2020
ef11f9b
Change default target to jvm-9 in test
liufengyun Aug 3, 2020
38a5aec
Try use JDK 11 as default
liufengyun Aug 3, 2020
479fd13
Set module class fields to static except bitmap fields
liufengyun Aug 3, 2020
eaedbca
Make <static> flag order-independent at backend
liufengyun Aug 4, 2020
51783fe
Use semantic names for bitmaps
liufengyun Aug 4, 2020
ab59eee
Don't use Java 11 for community projects
liufengyun Aug 4, 2020
745d53c
Address reviews
liufengyun Aug 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
container: lampepfl/dotty:2020-04-24

steps:
- name: Set JDK 11 as default
run: echo "::add-path::/usr/lib/jvm/java-11-openjdk-amd64/bin"

- name: Checkout cleanup script
uses: actions/checkout@v2

Expand Down Expand Up @@ -55,6 +58,9 @@ jobs:
container: lampepfl/dotty:2020-04-24

steps:
- name: Set JDK 11 as default
run: echo "::add-path::/usr/lib/jvm/java-11-openjdk-amd64/bin"

- name: Checkout cleanup script
uses: actions/checkout@v2

Expand Down Expand Up @@ -174,7 +180,7 @@ jobs:
- name: Test
run: ./project/scripts/sbt sbt-dotty/scripted

test_java11:
test_java8:
runs-on: self-hosted
container: lampepfl/dotty:2020-04-24
if: (
Expand All @@ -184,6 +190,9 @@ jobs:
github.event_name == 'schedule'

steps:
- name: Set JDK 8 as default
run: echo "::add-path::/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin"

- name: Checkout cleanup script
uses: actions/checkout@v2

Expand Down Expand Up @@ -215,14 +224,12 @@ jobs:
restore-keys: ${{ runner.os }}-general-

- name: Test
run: |
export PATH="/usr/lib/jvm/java-11-openjdk-amd64/bin:$PATH"
./project/scripts/sbt ";compile ;test"
run: ./project/scripts/sbt ";compile ;test"

publish_nightly:
runs-on: self-hosted
container: lampepfl/dotty:2020-04-24
needs: [test, test_bootstrapped, community_build, test_sbt, test_java11]
needs: [test, test_bootstrapped, community_build, test_sbt, test_java8]
if: github.event_name == 'schedule'
env:
NIGHTLYBUILD: yes
Expand Down Expand Up @@ -323,7 +330,7 @@ jobs:
publish_release:
runs-on: self-hosted
container: lampepfl/dotty:2020-04-24
needs: [test, test_bootstrapped, community_build, test_sbt, test_java11]
needs: [test, test_bootstrapped, community_build, test_sbt, test_java8]
if: github.event_name == 'push' &&
startsWith(github.event.ref, 'refs/tags/') &&
!startsWith(github.event.ref, 'refs/tags/sbt-dotty-')
Expand Down Expand Up @@ -475,7 +482,7 @@ jobs:
publish_sbt_release:
runs-on: self-hosted
container: lampepfl/dotty:2020-04-24
needs: [test, test_bootstrapped, community_build, test_sbt, test_java11]
needs: [test, test_bootstrapped, community_build, test_sbt, test_java8]
if: github.event_name == 'push' &&
startsWith(github.event.ref, 'refs/tags/sbt-dotty-')

Expand Down
33 changes: 11 additions & 22 deletions compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,13 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
}
else {
mnode.visitVarInsn(asm.Opcodes.ALOAD, 0)
generatedType =
if (tree.symbol == defn.ArrayClass) ObjectReference
else classBTypeFromSymbol(claszSymbol)
// When compiling Array.scala, the constructor invokes `Array.this.super.<init>`. The expectedType
// is `[Object` (computed by typeToBType, the type of This(Array) is `Array[T]`). If we would set
// the generatedType to `Array` below, the call to adapt at the end would fail. The situation is
// similar for primitives (`I` vs `Int`).
if (tree.symbol != defn.ArrayClass && !tree.symbol.isPrimitiveValueClass) {
generatedType = classBTypeFromSymbol(claszSymbol)
}
}

case DesugaredSelect(Ident(nme.EMPTY_PACKAGE), module) =>
Expand Down Expand Up @@ -710,33 +714,18 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
if (t.symbol ne defn.Object_synchronized) genTypeApply(t)
else genSynchronized(app, expectedType)

case Apply(fun @ DesugaredSelect(Super(_, _), _), args) =>
def initModule(): Unit = {
// we initialize the MODULE$ field immediately after the super ctor
if (!isModuleInitialized &&
jMethodName == INSTANCE_CONSTRUCTOR_NAME &&
fun.symbol.javaSimpleName == INSTANCE_CONSTRUCTOR_NAME &&
claszSymbol.isStaticModuleClass) {
isModuleInitialized = true
mnode.visitVarInsn(asm.Opcodes.ALOAD, 0)
mnode.visitFieldInsn(
asm.Opcodes.PUTSTATIC,
thisName,
str.MODULE_INSTANCE_FIELD,
"L" + thisName + ";"
)
}
}
case Apply(fun @ DesugaredSelect(Super(superQual, _), _), args) =>
// 'super' call: Note: since constructors are supposed to
// return an instance of what they construct, we have to take
// special care. On JVM they are 'void', and Scala forbids (syntactically)
// to call super constructors explicitly and/or use their 'returned' value.
// therefore, we can ignore this fact, and generate code that leaves nothing
// on the stack (contrary to what the type in the AST says).
mnode.visitVarInsn(asm.Opcodes.ALOAD, 0)

// scala/bug#10290: qual can be `this.$outer()` (not just `this`), so we call genLoad (not just ALOAD_0)
genLoad(superQual)
liufengyun marked this conversation as resolved.
Show resolved Hide resolved
genLoadArguments(args, paramTKs(app))
generatedType = genCallMethod(fun.symbol, InvokeStyle.Super, app.span)
initModule()

// 'new' constructor call: Note: since constructors are
// thought to return an instance of what they construct,
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/backend/jvm/BCodeIdiomatic.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ trait BCodeIdiomatic {
case "jvm-1.6" => asm.Opcodes.V1_6
case "jvm-1.7" => asm.Opcodes.V1_7
case "jvm-1.8" => asm.Opcodes.V1_8
case "jvm-9" => asm.Opcodes.V9
liufengyun marked this conversation as resolved.
Show resolved Hide resolved
}

lazy val majorVersion: Int = (classfileVersion & 0xFF)
Expand Down
Loading