Skip to content

Use symbolic names internally #2169

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 8 commits into from
May 7, 2017

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Apr 4, 2017

Change encoding to that symbolic operators are kept internally and are only emitted during the backend. The PR is based on #2128 of which it is the logical conclusion.

@@ -571,8 +571,8 @@ class Namer { typer: Typer =>

/** Create links between companion object and companion class */
def createLinks(classTree: TypeDef, moduleTree: TypeDef)(implicit ctx: Context) = {
val claz = ctx.effectiveScope.lookup(classTree.name.encode)
val modl = ctx.effectiveScope.lookup(moduleTree.name.encode)
val claz = ctx.denotNamed(classTree.name).symbol
Copy link
Member

Choose a reason for hiding this comment

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

Why does denotNamed makes sense here? I changed it to effectiveScope.lookup in b641181 assuming it was the right thing to do. Doesn't using denotNamed means that we could find a companion in an outer scope which would be very wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll revert that change.

@felixmulder felixmulder added this to the 0.1 Tech Preview milestone Apr 4, 2017
@odersky odersky force-pushed the change-late-op-encoding branch from 7c71b08 to 6868f97 Compare April 7, 2017 09:08
@odersky
Copy link
Contributor Author

odersky commented Apr 8, 2017

Status: I went over the whole PR documenting and polishing. Awaiting the backend to be made available so that we can apply the necessary changes to it.

@odersky odersky force-pushed the change-late-op-encoding branch 3 times, most recently from 0dbb1de to 1a264e1 Compare April 10, 2017 14:36
EXPANDEDPREFIX Length qualified_NameRef selector_NameRef
TRAITSETTER Length qualified_NameRef selector_NameRef
UNIQUE Length separator_NameRef uniqid_Nat underlying_NameRef?
DEFAULTGETTER Length underlying_NameRef index_Nat
Copy link
Member

Choose a reason for hiding this comment

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

Incorrect indentation here and below.

Copy link
Member

Choose a reason for hiding this comment

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

Indentation still broken.

@odersky odersky force-pushed the change-late-op-encoding branch from 1a264e1 to 081a781 Compare April 11, 2017 12:08
@DarkDimius
Copy link
Contributor

Awaiting the backend to be made available so that we can apply the necessary changes to it.

PRs by @smarter are all in and the backend has been moved to https://github.com/lampepfl/scala/.

@odersky odersky force-pushed the change-late-op-encoding branch from 081a781 to ac1415f Compare April 28, 2017 11:55
@odersky
Copy link
Contributor Author

odersky commented Apr 28, 2017

The only remaining test failure is:

Failed tests:
[error] 	xsbt.ExtractUsedNamesSpecification

I have no idea what that is and can't find the string "ExtractUsedNamesSpecification" anywhere in the repo. @smarter or @felixmulder can you help?

@smarter
Copy link
Member

smarter commented Apr 28, 2017

Some tests contain mangled name ($eq, $qmark, ...) which are now returned unmangled. It's safe to change the test to use the unmangled name.

@odersky
Copy link
Contributor Author

odersky commented Apr 28, 2017

@smarter Thanks! I have tried to change to symbolic names.

@smarter
Copy link
Member

smarter commented Apr 28, 2017

@odersky By the way, the report at the end of the CI output was not helpful here (since this is a regular JUnit test not part of the compiler test framework), but if you search for "ExtractUsedNamesSpecification" in the CI output, you'll find a much more detailed explanation of what failed.

@odersky
Copy link
Contributor Author

odersky commented Apr 28, 2017

Seems to all work out now. Ready for review.

@smarter
Copy link
Member

smarter commented Apr 28, 2017

Can you rebase now that #2322 has been merged?

@odersky odersky force-pushed the change-late-op-encoding branch from 6005b22 to 49b8df2 Compare April 28, 2017 15:55
@odersky
Copy link
Contributor Author

odersky commented Apr 28, 2017

Rebased

@odersky odersky changed the title [WIP] Use symbolic names internally Use symbolic names internally Apr 29, 2017
@odersky odersky force-pushed the change-late-op-encoding branch 3 times, most recently from e5f97e3 to 719e7c8 Compare May 6, 2017 13:36
@smarter
Copy link
Member

smarter commented May 6, 2017

There's a commit called "Invalide fullName cache when name changes" (7593cf3) that doesn't seem to have anything do with cache invalidation. Did that change appear in another commit, was it lost, or intentionally dropped?

@@ -244,7 +244,8 @@ class CompilationTests extends ParallelTesting {
}.map(_.checkCompile()).foreach(_.delete())
}

@Test def bytecodeIdempotency: Unit = {
/** Add a `z` so that hey run last. TODO: Only run them selectively? */
Copy link
Member

Choose a reason for hiding this comment

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

typo: hey -> they

val thisKind = this.info.kind
thisKind == kind ||
!thisKind.definesNewName && thisKind.tag > kind.tag && underlying.is(kind)
}

@sharable // because it's just a cache for performance
private[Names] var myMangledString: String = null
Copy link
Member

Choose a reason for hiding this comment

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

This should be private[this]

apply(original, index)
}
else name
}
}

/** The kind of names that also encode a variance: 0 for contravariance, 1 for covariance. */
Copy link
Member

Choose a reason for hiding this comment

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

-1 for contravariance, not 0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's 0 now.

EXPANDEDPREFIX Length qualified_NameRef selector_NameRef
TRAITSETTER Length qualified_NameRef selector_NameRef
UNIQUE Length separator_NameRef uniqid_Nat underlying_NameRef?
DEFAULTGETTER Length underlying_NameRef index_Nat
Copy link
Member

Choose a reason for hiding this comment

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

Indentation still broken.

@smarter
Copy link
Member

smarter commented May 6, 2017

This isn't necessary for this PR to get in, but I think it would be great if we used different types for encoded and decoded names, to make sure we don't use one instead of the other. This should be possible now that we have a clearer picture of when things should be encoded/decoded.

@odersky
Copy link
Contributor Author

odersky commented May 6, 2017

There's a commit called "Invalide fullName cache when name changes" (7593cf3) that doesn't seem to have anything do with cache invalidation. Did that change appear in another commit, was it lost, or intentionally dropped?

That was intentionally dropped because it's now redundant. We found a way to do it without changing the name so no invalidation is necessary.

odersky added 2 commits May 7, 2017 11:37
They take up time and should fail only rarely.
@odersky odersky force-pushed the change-late-op-encoding branch from cca78ff to c6dafba Compare May 7, 2017 09:37
For many kinds this is needed because creation of a name kind involves
a side effect, namely registering the name kind.

If we delay this we might get a crash on unpickling because a tag is not set yet.
This was observed when compiling the collection strawman test.
@smarter
Copy link
Member

smarter commented May 7, 2017

From http://dotty-ci.epfl.ch/lampepfl/dotty/2165/3:

[error] Test dotty.tools.dotc.CompilationTests.compilePos failed: java.lang.AssertionError: Expected no errors when compiling, but found: 0, took 54.642 sec

That's a weird error message, /cc @felixmulder

@felixmulder
Copy link
Contributor

My guess is that an assertion fired, but unsure. I'd have to investigate

The previous change hid the refinements of `info` and apply/unapply.
Turning SimpleNameKind and SignedNameKind back into objects fixes that.
Neither name kind installs anything as a side effect so turning them into
objects is OK.
@odersky
Copy link
Contributor Author

odersky commented May 7, 2017

Some interesting developments. Making all names strict uncovered a bug in avoid which is minimized in 6e3f325. It's fixed now. I experimented with making avoid an approximating typemap, but did not succeed. The current state is in staging/wip-avoid-as-approx-typemap.

@@ -61,8 +61,7 @@ object NameKinds {
def infoString: String
}

/** The kind of SimpleNames */
val SimpleNameKind = new NameKind(UTF8) { self =>
object SimpleNameKind extends NameKind(UTF8) { self =>
Copy link
Member

Choose a reason for hiding this comment

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

I think ultimately, we should just make the name registration thread-safe, it doesn't cost much and it's much easier to reason about than remembering which NameKinds have side-effects, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But this is another issue. The problem was not threading but the fact that the registration was not performed at all, since objects are lazy.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I see, indeed that's different. If we had enums we could iterate over the namekinds to register them maybe :).

@smarter smarter merged commit 1014af3 into scala:master May 7, 2017
@allanrenucci allanrenucci deleted the change-late-op-encoding branch December 14, 2017 16:58
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.

4 participants