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 #4616: Proper static dependency tracking for jl.Class #4623

Merged
merged 2 commits into from
Feb 4, 2022

Conversation

gzm0
Copy link
Contributor

@gzm0 gzm0 commented Jan 15, 2022

No description provided.

@gzm0
Copy link
Contributor Author

gzm0 commented Jan 15, 2022

Still needs tests. I need to think about how to do that.

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix looks good. ;)

@gzm0
Copy link
Contributor Author

gzm0 commented Jan 15, 2022

For reference: To test this properly, we need a codebase in which there is no unoptimized call to getClass. Otherwise, we'll hit the GetClass node in java.lang.Object and the problem vanishes.

@gzm0
Copy link
Contributor Author

gzm0 commented Jan 15, 2022

Hrm, this means we cannot even write a JUnit test: JUnit itself uses getClass extensively :-/

@gzm0
Copy link
Contributor Author

gzm0 commented Jan 15, 2022

Also, we must have the optimizer: Otherwise getClass is always reachable through the implementation of toString in java.lang.Object.

@gzm0
Copy link
Contributor Author

gzm0 commented Jan 16, 2022

I have built a fixture so we can test this. However, it is hit by: scala-js/scala-js-js-envs#17. So it "fails to fail".

@gzm0 gzm0 requested a review from sjrd January 17, 2022 19:55
@gzm0
Copy link
Contributor Author

gzm0 commented Jan 17, 2022

Ready for review, but needs to wait for scala-js/scala-js-js-envs#18

Comment on lines +36 to +39
@(Rule @scala.annotation.meta.getter)
val tempFolder = new TemporaryFolder()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something standard that I should know about, or does this deserve a comment? (I feel like it could be the former.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a standard JUnit thing. A JUnit rule essentially encapsulates test fixtures (@Before and @After).

Comment on lines 55 to 78
val output = tempFolder.newFolder().toPath

val env = new NodeJSEnv

testLink(classDefs, MainTestModuleInitializers,
linkerConfig, PathOutputDirectory(output)).flatMap { _ =>
val run = env.start(Seq(Input.ESModule(output.resolve("main.mjs"))), RunConfig())

run.future.finallyWith(Future(run.close()))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this section is a good candidate to be extracted in a method testLinkdAndRun or something like that, doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed. I'll probably use the TestKit from JSEnv so that it can take care of all the I/O handling and what not (otherwise, we'll spam the test stdout).

@@ -979,7 +979,8 @@ object Build {
).settings(
libraryDependencies ++= Seq(
"com.google.javascript" % "closure-compiler" % "v20211201",
"com.google.jimfs" % "jimfs" % "1.1" % "test"
"com.google.jimfs" % "jimfs" % "1.1" % "test",
"org.scala-js" %% "scalajs-env-nodejs" % "1.2.1" % "test"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"org.scala-js" %% "scalajs-env-nodejs" % "1.2.1" % "test"
"org.scala-js" %% "scalajs-env-nodejs" % "1.2.1" % "test",

gzm0 added a commit to gzm0/scala-js-js-envs that referenced this pull request Jan 22, 2022
Downstream tests (notably
scala-js/scala-js#4623) can profit from the
ability to abstract over an input kind.
@gzm0 gzm0 changed the title WIP Fix #4616: Proper static dependency tracking for jl.Class Fix #4616: Proper static dependency tracking for jl.Class Jan 31, 2022
@gzm0 gzm0 requested a review from sjrd January 31, 2022 05:57
Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The upgrade to the minor version 1.3.0 of js-envs means that we need to bump our minor version too, as a first commit. Otherwise LGTM.

@gzm0
Copy link
Contributor Author

gzm0 commented Feb 4, 2022

Rebased onto main. Version got bumped in #4634.

@sjrd sjrd merged commit 0de7d1b into scala-js:main Feb 4, 2022
@gzm0 gzm0 deleted the fix-get-class branch February 6, 2022 17:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CallinggetClass with SmallestModules module split style causes reference error
2 participants