Repository navigation
Annotate an impossible 'X is not defined' with why module resolution missed - #550
Draft
Jarred-Sumner wants to merge 3 commits into
Draft
Jarred-Sumner wants to merge 3 commits into
Jarred-Sumner wants to merge 3 commits into
Conversation
…missed When get_from_scope is about to throw ReferenceError for a name and a JSModuleEnvironment on the function's scope chain imports or declares a binding with the same text, the error should not have been possible. In that case append a short, fixed-vocabulary suffix to the message that says which invariant is broken: whether the record resolves the name now, whether the import entry is present by pointer but missed by the hash lookup (damaged table or hash word), whether an entry with equal text but a different StringImpl exists (two atoms), whether the identifier is the atom the table holds for its text, and the same for the exporter's export entries and the environment's symbol table. Only the throw path is touched and only when a module environment is on the chain and one of those checks fires, so ordinary undefined-global errors are unchanged. Every field is a small enum so telemetry that only keeps a hash of the message can still recover it.
Preview Builds
|
op_check_tdz names the binding by its source text. If that text is an import or module-scope binding of a module environment on the function's scope chain, look at the slot it resolves to now: a non-empty slot means the read that fed the check produced a wrong value, and an empty slot in a module that finished evaluating without error means the environment was damaged. Ordinary TDZ (a lexical binding read before its declaration ran, a binding of a module still evaluating in a cycle) is unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Field telemetry from
--compile --bytecode --splittingapps occasionally showsReferenceError: X is not definedfor a name the throwing module imports (or declares), sometimes after the same binding resolved for over an hour in the same process. For an import used inside a module function the engine can only produce that error ifAbstractModuleRecord::resolveImportmisses both when the CodeBlock is linked and on every dynamic re-resolve afterwards, and by construction (pointer-identical atoms, immutable import/export tables) it should not. We have not been able to reproduce it, so this makes the next field occurrence self-describing.When
get_from_scope(LLInt, Baseline, and DFG'sGetDynamicVar) is about to throw for a name and aJSModuleEnvironmenton the function's scope chain imports or declares a binding with the same text, the message gets a suffix such aswhich distinguishes: the record resolves the name now but the op was linked unresolved (
imp=0withrtunresolved); the import entry is present by linear scan but the hash lookup misses it (ptrimp=1,hashimp=0— damaged bucket array / map headerhdr=0/ key hash wordheq=0); an entry with equal text but a differentStringImpl(txtimp=1— two atoms, plus whether the identifier is the atom the table holds for its text,intable); the exporter's export table in the same terms (xptr/xhash/xtxt/xenv); and the module environment's own symbol table (sym/txtsym) for module-levelvars.Only the throw path is touched, and only when a module environment is on the chain and one of the checks fires, so ordinary undefined-global errors (including inside modules) are byte-for-byte unchanged — verified with plain and
--compile --bytecode --splittingbuilds. Every field is a small enum so telemetry that only keeps a hash of the message can still brute-force it. Exercised end to end with a temporary fault injection that makestryGetImportEntrymiss one name (not included).Second commit: the same for TDZ.
op_check_tdznames the binding by its source text; if that text is an import or module-scope binding of a module environment on the function's scope chain, the slot it resolves to is inspected now and the message is annotated only when it is non-empty (the read that fed the check was wrong) or empty although its module finished evaluating without error (the environment was damaged):Ordinary TDZ (a lexical binding read before its declaration ran, an import of a module still evaluating in a cycle) is unchanged — verified with a cyclic-import case. Motivated by field rows where an import of a plain hoisted
functionthrew TDZ hours into a process.