-
Notifications
You must be signed in to change notification settings - Fork 427
Show callstack in browser upon REPL crashes #2021
Conversation
src/utils/generator.js
Outdated
@@ -253,10 +253,11 @@ class ModifiedBindingEntry extends GeneratorEntry { | |||
containingGenerator === this.containingGenerator, | |||
"This entry requires effects to be applied and may not be moved" | |||
); | |||
invariant(this.modifiedBinding.value === this.newValue); | |||
invariant(this.modifiedBinding.value === this.newValue, "ModifiedBinding's value has been improperly modified."); |
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.
This is a good example of an utterly useless comment. Much better (and much harder) is to write a comment that explains to a reader of the code why this invariant is expected to hold. In terms of debug logging, for those who care about such things, it would be better to include information about the two values.
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.
Great job!
scripts/test-runner.js
Outdated
@@ -286,6 +286,7 @@ function runTest(name, code, options: PrepackOptions, args) { | |||
options.invariantLevel = code.includes("// omit invariants") || args.verbose ? 0 : 99; | |||
if (code.includes("// emit concrete model")) options.emitConcreteModel = true; | |||
if (code.includes("// exceeds stack limit")) options.maxStackDepth = 10; | |||
if (code.includes("// heapGraphFilePath")) options.heapGraphFormat = "VISJS"; |
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 is not a file path, you are using VISJS format here. I would call "// heap graph" instead of heapGraphFilePath
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.
Will do. I put it like that originally to avoid confusion with the actual flag (the flag itself is --heapGraphFilePath
so I kept it the same)
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.
Yeah, heapGraphFilePath
is a command line level option not actually the engine/serializer level option, which is heapGraphFormat
. But either way, we are just trying to enable heap graph and do not care about the output in this test.
src/serializer/serializer.js
Outdated
@@ -182,6 +182,9 @@ export class Serializer { | |||
additionalFunctionValuesAndEffects, | |||
referentializer | |||
); | |||
// Copying dERB map so cache lookup returns the same object, and the subsequent |
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.
I would write the comment like: ModifiedBindingEntry caches the state from declarativeEnvironmentRecordsBindings during visitor so we have to pass the same cache to future visitors.
src/utils/generator.js
Outdated
this.residualFunctionBinding = residualBinding; | ||
this.modifiedBinding.value = newValue; |
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.
Is this change really needed? Looks a bit scary to me. I'd rather do less state mutation on the side than more.
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.
Without it, we run into the following problem:
In the provided example
(function () {
let a = __abstract("number", "a");
let b, c;
global.f = function() {
b = a + 42;
c = a + 42;
}
__optimize(f);
})();
when the ModifiedBindingEntry
does the .visitModifiedBinding
, there is a .visitEquivalentValue(newValue)
call on the new value, and the returned newValue may not match the original (it's replaced by the "equivalent" value if one is found). This happens to us in this test case because of the
b = a + 42;
c = a + 42;
since the a + 42
look the same. The assignment realigns the state to what is expected by the invariant assertion.
This problem actually seems to be at least somewhat independent of the problem caused by the cache/ResidualFunctionBinding, but it was in the same code area and also causes the code to crash.
It seems that the more fundamental issue is that we're re-traversing a the heap, which has some sort of assumption that it won't be re-traversed.
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.
which has some sort of assumption that it won't be re-traversed.
Yes, that's the underlying problem here...
While the introduced assignment makes the invariant violation go away, it changes what happens during the next visiting, which is bad.
The right thing to do would be to stop mutating state on the side in these GeneratorEntry's, they should be just values. Instead, build up new data structure in the visitor, a mapping of GeneratorEntry to something --- whatever mutable state there was, and pass that on to the next phase that really needs it, and just throw it away after the ResidualHeapGraphVisitor
.
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.
@yinghuitan was saying then that it might be easier to detect and reject calls to __optimize()
when the --heapGraphFilePath
flag is given, since the two haven't been made to work together yet. Would that be a more relevant solution?
src/serializer/serializer.js
Outdated
if (additionalFunctionValuesAndEffects.size > 0) { | ||
let diagnostic = new CompilerDiagnostic( | ||
"Using __optimize with --heapGraphFilePath flag is not currently supported", | ||
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.
Wasn't sure what to give these fields since they're not really applicable. Suggestions?
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.
If the new approach is now to fail with an error, then this would make our website REPL unusable as soon as __optimize is used.
Some heuristics could be used in the website code to disable the heap graph if the text contains the word __optimize. I am not a fan of that complicated working around the actual issue, but still better than crashing.
… callstacks along with error message (for all errors) in repl
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.
Awesome! Much better REPL diagnostics experience.
You may want to retitle the PR since we are not fixing crash anymore.
scripts/test-runner.js
Outdated
@@ -286,6 +286,7 @@ function runTest(name, code, options: PrepackOptions, args) { | |||
options.invariantLevel = code.includes("// omit invariants") || args.verbose ? 0 : 99; | |||
if (code.includes("// emit concrete model")) options.emitConcreteModel = true; | |||
if (code.includes("// exceeds stack limit")) options.maxStackDepth = 10; | |||
if (code.includes("// heapGraph")) options.heapGraphFormat = "VISJS"; |
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.
I do not think we need this change anymore.
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.
@trueadm is landing this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Fixing some incompatibility between heapGraph and
__optimize()
.Essence of the issue was an implicit assumption that only one visitor would visit certain entries.
Original Issue: #1732