Skip to content

Invalidate package objects transitively in name hashing #2432

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

Merged
merged 3 commits into from
Feb 3, 2016

Conversation

gkossakowski
Copy link
Contributor

Modify invalidatedPackageObjects to look for package objects that
transitively inherit from an invalidated class instead of just inheriting
directly. This is the correct behavior that should have been implemented
in the first place. The bug comes from a subtle copy&paste mistake. The old
implementation used publicInherited relation and new one looks identical
but uses inheritance relation. The difference is that publicInherited
was a relation that was expanded transitively along inheritance chain but
inheritance is not. We have to perform the transitive walk in
IncrementalNameHashing.invalidatedPackageObjects implementation.

Mark pkg-self test as passing.

Fixes #2326

The previous version of `pkg-self` covered scenario where a package object
inherited directly from a class that is being modified and recompiled in
subsequent steps. The sbt#2326 shows that name hashing fails to handle
a package object that inherits indirectly from a modified class. In that
case, name hashing fails to invalidate the source file that defines the
package object.
This commit expands `pkg-self` with a class B that inherits from modified
class `A` and makes package object inherit from B. We mark that test as
pending to show that this indeed trigger the bug in name hashing.
To aid debugging, modify Relations.toString to include `inheritance` in
addition to already printed `memberRef` relation.

Modify it for both name hashing and old implementation.
Modify `invalidatedPackageObjects` to look for package objects that
transitively inherit from an invalidated class instead of just inheriting
directly. This is the correct behavior that should have been implemented
in the first place. The bug comes from a subtle copy&paste mistake. The old
implementation used `publicInherited` relation and new one looks identical
but uses `inheritance` relation. The difference is that `publicInherited`
was a relation that was expanded transitively along inheritance chain but
`inheritance` is not. We have to perform the transitive walk in
`IncrementalNameHashing.invalidatedPackageObjects` implementation.

Mark `pkg-self` test as passing.

Fixes sbt#2326
@typesafe-tools
Copy link

Can one of the admins verify this patch?

invalidated flatMap relations.inheritance.internal.reverse filter { _.getName == "package.scala" }
transitiveDeps(invalidated)(relations.inheritance.internal.reverse).filter {
_.getName == "package.scala"
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I realize it's not new to this commit, but what is the basis for this filter? It's not supposed to be a correctness requirement that package objects be defined in files called package.scala. It is (according to the scala specification) a convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it was a quick hack. @Duhemm's idea would fix it for good.

@Duhemm
Copy link
Contributor

Duhemm commented Feb 3, 2016

LGTM.

@paulp's comment is right. Maybe that we should add a flag isPackageObject, similar to hasMacro, and rely on that rather than the filename?

@gkossakowski
Copy link
Contributor Author

@Duhemm: yes, that's a good way to implement package object handling. Would you like to give it a try?

@Duhemm
Copy link
Contributor

Duhemm commented Feb 3, 2016

@gkossakowski Sure!

Duhemm added a commit that referenced this pull request Feb 3, 2016
Invalidate package objects transitively in name hashing
@Duhemm Duhemm merged commit a58eff8 into sbt:0.13 Feb 3, 2016
@gkossakowski
Copy link
Contributor Author

great, small suggestion for implementation: introduce hasPackageObject to APIs that checks the flag in the Source object. This way the particular mechanism of storing that information can be hidden and changed later on. E.g. I'll need to change it for #1104.

@paulp
Copy link
Contributor

paulp commented Feb 3, 2016

Note if you haven't already that _.getName == "package.scala" occurs more than one place in the sbt source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants