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

Port PredictionContext along with tests #36

Merged
merged 13 commits into from
Oct 8, 2016
Merged

Port PredictionContext along with tests #36

merged 13 commits into from
Oct 8, 2016

Conversation

BurtHarris
Copy link
Collaborator

@BurtHarris BurtHarris commented Oct 6, 2016

Tests all currently fail, remove stubbed out PredictionContextCache and PredictionContext when imports are ready.

Edit: Tests are now passing.

@sharwell
Copy link
Member

sharwell commented Oct 6, 2016

I'm planning to add my porting of PredictionContext to this branch so we can review everything at once.

export abstract class PredictionContext implements Equatable {
@NotNull
static get EMPTY_LOCAL(): PredictionContext {
return PredictionContext.LOAD_LOCAL_CONTEXT();
Copy link
Member

Choose a reason for hiding this comment

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

📝 Need to file an issue to revisit performance of these "constants".

Copy link
Member

Choose a reason for hiding this comment

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

➡️ Filed #58


private static createSingletonPredictionContext(parent: PredictionContext, returnState: number): PredictionContext {
let SingletonPredictionContext: typeof SPC = require('./SingletonPredictionContext');
return new SingletonPredictionContext.SingletonPredictionContext(parent, returnState);
Copy link
Member

Choose a reason for hiding this comment

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

📝 TypeScript reports an error on this line, but this form is actually required for the code to work.

@sharwell sharwell changed the title Port of TestGraphNodes, with stubbed out classes Port PredictionContext along with tests Oct 8, 2016
assert(returnState != EMPTY_FULL_STATE_KEY && returnState != EMPTY_LOCAL_STATE_KEY);
constructor(@NotNull parent: PredictionContext, returnState: number) {
super(PredictionContext.calculateSingleHashCode(parent, returnState));
// assert(returnState != PredictionContext.EMPTY_FULL_STATE_KEY && returnState != PredictionContext.EMPTY_LOCAL_STATE_KEY);
Copy link
Member

Choose a reason for hiding this comment

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

📝 The assertions in this class are located in performance-critical code.

@BurtHarris
Copy link
Collaborator Author

BurtHarris commented Oct 8, 2016

I'm still reviewing to get a better understanding of how it's supposed to work. None the less, with the compile errors it still generates, it doesn't feel solid.

Without fully understanding completely, it still seems to me that this application of optional modules isn't at all what was intended for the feature. I would think it cleaner to package EmptyPredictionContext as a non-exported class in module PredictionContext.ts. It looks like the same could work for ArrayPredictionContext and SingletonPredictionContext as well.

I think that this would allow you to do away with LOAD_FULL_CONTEXT() and LOAD_LOCAL_CONTEXT(), but suggest we do this on a code-clarity basis, rather than just the performance of it.

@BurtHarris
Copy link
Collaborator Author

BurtHarris commented Oct 8, 2016

@sharwell, I created branch predictionContext with that refactoring done. Have a look and see what you think. Should be a clean merge into this branch, and reduces the surface area. One trick that let me do this was putting the PredictionContext class at the top of the file, and the PredictionContext namespace at the bottom, so that the other classes were "done" before I needed to use them to initialize the constants.

@sharwell
Copy link
Member

sharwell commented Oct 8, 2016

@BurtHarris Any objection to implementing that as a follow-up to this one (essentially fixing #58)?

@BurtHarris
Copy link
Collaborator Author

I guess not, but I'm still reviewing this one. One other thing I noticed was that the Visual Studio project hasn't been updated to include the newly-ported files, but that can wait too.

@BurtHarris
Copy link
Collaborator Author

PredictionContext instances are immutable once created, right?

}

get(key: K): V {
let [k, v] = this.backingStore.get([key, null]) || [undefined, undefined];
Copy link
Member

Choose a reason for hiding this comment

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

💡 It would be better to write this in a way that avoids the fallback allocation. See #59.

}

put(key: K, value: V): V {
let element: [K, V] = this.backingStore.get([key, value]) || [undefined, undefined];
Copy link
Member

Choose a reason for hiding this comment

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

💡 It would be better to write this in a way that avoids the fallback allocation. See #59.

}

putIfAbsent(key: K, value: V): V {
let element: [K, V] = this.backingStore.get([key, value]) || [undefined, undefined];
Copy link
Member

Choose a reason for hiding this comment

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

💡 It would be better to write this in a way that avoids the fallback allocation. See #59.

@@ -60,7 +68,7 @@ export class TestGraphNodes {
}

@Test test_$_$_fullctx(): void {
let r: PredictionContext = contextCache.join(PredictionContext.EMPTY_FULL,
let r: PredictionContext = this.contextCache.join(PredictionContext.EMPTY_FULL,
PredictionContext.EMPTY_FULL);
console.log(toDOTString(r));
Copy link
Member

@sharwell sharwell Oct 8, 2016

Choose a reason for hiding this comment

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

📝 Forgot to comment this console.log out.

@sharwell
Copy link
Member

sharwell commented Oct 8, 2016

PredictionContext instances are immutable once created, right?

They are supposed to be, yes.

@BurtHarris
Copy link
Collaborator Author

BurtHarris commented Oct 8, 2016

OK. LGTM. The only thing I might change is declaring the members like cachedHashCode as private readonly. That would flag any violations of the immutability, but that too can be an enhancement. Shall I merge it?

private equalsImpl(other: ArrayPredictionContext, visited: JavaSet<PredictionContextCache.IdentityCommutativePredictionContextOperands>): boolean {
let selfWorkList: PredictionContext[] = [];
let otherWorkList: PredictionContext[] = [];
selfWorkList.unshift(this);
Copy link
Member

Choose a reason for hiding this comment

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

❗ The original code used the work lists as a stack not a queue. This operation should be push so the corresponding pop below is LIFO instead of FIFO.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good. I'm going to the airport to pick up my daughter who's been traveling in Europe. You can go ahead and merge this when you are done.

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.

None yet

2 participants