-
Notifications
You must be signed in to change notification settings - Fork 107
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
Conversation
I'm planning to add my porting of |
d743f4e
to
17e4743
Compare
export abstract class PredictionContext implements Equatable { | ||
@NotNull | ||
static get EMPTY_LOCAL(): PredictionContext { | ||
return PredictionContext.LOAD_LOCAL_CONTEXT(); |
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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.
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 I think that this would allow you to do away with |
@sharwell, I created branch |
@BurtHarris Any objection to implementing that as a follow-up to this one (essentially fixing #58)? |
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. |
PredictionContext instances are immutable once created, right? |
} | ||
|
||
get(key: K): V { | ||
let [k, v] = this.backingStore.get([key, null]) || [undefined, undefined]; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
They are supposed to be, yes. |
OK. LGTM. The only thing I might change is declaring the members like |
private equalsImpl(other: ArrayPredictionContext, visited: JavaSet<PredictionContextCache.IdentityCommutativePredictionContextOperands>): boolean { | ||
let selfWorkList: PredictionContext[] = []; | ||
let otherWorkList: PredictionContext[] = []; | ||
selfWorkList.unshift(this); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Tests all currently fail, remove stubbed outPredictionContextCache
andPredictionContext
when imports are ready.Edit: Tests are now passing.