Closed Bug 1773324 Opened 3 years ago Closed 3 years ago

Avoid needing JSContext directly for parser to report errors

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
105 Branch
Tracking Status
firefox105 --- fixed

People

(Reporter: tcampbell, Assigned: bthrall)

References

Details

Attachments

(25 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

In order to support parsing-to-stencil without a JSContext, we need to clean up error reporting. Fortunately this is already somewhat abstracted because helper-threads cannot allocate ErrorObjects but they checks around this still use the JSContext.

There will still be some non-trivial refactoring in ErrorReporting.cpp for these errors though.

Assignee: nobody → bthrall
Status: NEW → ASSIGNED

The type of the allocator will be varying separately from the type of the context.

Depends on D149996

This allows the Parser creator to provide the ErrorContext appropriate
for the situation (main thread or helper thread). For now, we just use
a flexible implementation.

I think the lifetime of the ErrorContext is the same as the Parser, so
putting the ErrorContext on the stack when the Parser is, too, should be
safe.

Depends on D150641

I could get rid of OffThreadErrorContext::cx_ by subclassing from
MallocProvider, but I don't think that would work since
OffThreadErrorContext has a vtable and MallocProvider does a
static_cast to get the client pointer.

OffThreadFrontendErrors moved to ErrorContext.h to avoid
recursive header inclusion.

Depends on D150644

This will allowe us to gather the errors after parsing without
needing a separate OffThreadFrontendErrors member.

Depends on D150645

Flags: needinfo?(arai.unmht)

Fixes jit-test. Probably needs coordination with ESMification efforts.

It looks like JS::CompileModule() would be called from the main thread, so
it should use GeneralErrorContext.

Depends on D150644

ErrorAllocator is an adapter that allows MallocProvider to delegate
to polymorphic Contexts. MallocProvider provides a well-known interface,
but doesn't support polymorphism, so we resort to templating and adapters
like this.

JS::CharsToNewUTF8CharsZ() needs a definition in CharacterEncoding.cpp,
so for now I explicitly instantiate it for ErrorAllocator<JSContext>.
A better solution would be to move the definition to a header, but that's
a bigger task.

Depends on D150648

Flags: needinfo?(arai.unmht)

ReportErrorVA(), ReportErrorNumberVA(), and ReportErrorNumberUCArray(), and
ReportErrorNumberUTF8Array() use JSContext for rooting, so they will have to be
called from the main thread. The only reason to pass ErrorContext to them would
be for consistency with the other error reporting functions.

Depends on D151179

ErrorAllocator was only ever used with ErrorContext, so no need for templating.

linkWithJSContext() better describes what it is doing, since JSContext needs its
errors_ field filled in, at least until we can replace it with a different
allocator for functions that are called during compilation.

getAllocator() is a convenience so we don't have to add a separate allocator
parameter everywhere we pass an ErrorContext and also need an allocator.

Depends on D151608

This removes a lot of plumbing allocators through function parameters but still
maintains the ErrorContext and allocator as separate concepts.

At this point, there is no need for the type or instances of ErrorContext and
ErrorAllocator to vary independently.

Depends on D151609

Depends on D151610

"GenericErrorContext" hasn't been an appropriate name since 6b27a74292dc.

Depends on D151612

At the cost of moving the filled-in CompileError into the allocated space for OffThreadErrorContext.

Depends on D151667

hadErrors() is more descriptive than errors().empty().

Access to the pending errors list is pushed down to OffThreadErrorContext,
because that's the only context where it is used.

Depends on D151668

Depends on D151670

Moving recordErrors in DelazifyTask::Create() to after the allocation of the
task allows us to use the ErrorContext in the task to store the errors instead
of having to move them into the task later, and we only miss the allocation of
the task itself (which wasn't recorded in the errors anyway).

Depends on D151671

Attachment #9282381 - Attachment description: WIP: Bug 1773324 - Separate use of JSContext for allocation into its own parameter → Bug 1773324 - Separate use of JSContext for allocation into its own parameter r=arai
Attachment #9282382 - Attachment description: WIP: Bug 1773324 - Add ErrorReportMixin::getAllocator() → Bug 1773324 - Add ErrorReportMixin::getAllocator() r=arai
Attachment #9283501 - Attachment description: WIP: Bug 1773324 - Introduce ErrorContext for handling error reports. → Bug 1773324 - Introduce ErrorContext for handling error reports. r=arai
Attachment #9283502 - Attachment description: WIP: Bug 1773324 - Provide Parser ErrorContext as a constructor parameter. → Bug 1773324 - Provide Parser ErrorContext as a constructor parameter. r=arai
Attachment #9283503 - Attachment description: WIP: Bug 1773324 - Plumb ErrorContext parameter out to where main vs. helper thread is known → Bug 1773324 - Plumb ErrorContext parameter out to where main vs. helper thread is known r=arai
Attachment #9283504 - Attachment description: WIP: Bug 1773324 - Intro OffThreadErrorContext for off-thread compilation → Bug 1773324 - Intro OffThreadErrorContext for off-thread compilation r=arai
Attachment #9284397 - Attachment description: WIP: Bug 1773324 - Pass ErrorContext parameter to CompileModuleToStencil functions → Bug 1773324 - Pass ErrorContext parameter to CompileModuleToStencil functions r=arai
Attachment #9283505 - Attachment description: WIP: Bug 1773324 - Support pending errors in OffThreadErrorContext → Bug 1773324 - Support pending errors in OffThreadErrorContext r=arai
Attachment #9283506 - Attachment description: WIP: Bug 1773324 - Pull OffThreadErrorContext to ParseTask member → Bug 1773324 - Pull OffThreadErrorContext to ParseTask member r=arai
Attachment #9283507 - Attachment description: WIP: Bug 1773324 - Report errors from ParseTask back to JSContext → Bug 1773324 - Report errors from ParseTask back to JSContext r=arai
Attachment #9283508 - Attachment description: WIP: Bug 1773324 - Add test covering reporting off-thread compilation errors → Bug 1773324 - Add test covering reporting off-thread compilation errors r=arai
Attachment #9284398 - Attachment description: WIP: Bug 1773324 - Replace ErrorReporting allocator with ErrorAllocator → Bug 1773324 - Replace ErrorReporting allocator with ErrorAllocator r=arai
Attachment #9285106 - Attachment description: WIP: Bug 1773324 - Remove ErrorReporting dependency on JSContext for GC-safe callback → Bug 1773324 - Remove ErrorReporting dependency on JSContext for GC-safe callback r=arai
Attachment #9285107 - Attachment description: WIP: Bug 1773324 - Remove template from ErrorAllocator, add ErrorContext::getAllocator(), rename OffThreadErrorContext::linkWithJSContext() → Bug 1773324 - Remove template from ErrorAllocator, add ErrorContext::getAllocator(), rename OffThreadErrorContext::linkWithJSContext() r=arai
Attachment #9285108 - Attachment description: WIP: Bug 1773324 - Access ErrorAllocator via ErrorContext accessor → Bug 1773324 - Access ErrorAllocator via ErrorContext accessor r=arai
Attachment #9285109 - Attachment description: WIP: Bug 1773324 - Fix typo → Bug 1773324 - Fix typo r=arai
Attachment #9285110 - Attachment description: WIP: Bug 1773324 - Move implementations for ErrorContext to their own file → Bug 1773324 - Move implementations for ErrorContext to their own file r=arai
Attachment #9285201 - Attachment description: WIP: Bug 1773324 - Rename MainThreadErrorContext → Bug 1773324 - Rename MainThreadErrorContext r=arai
Attachment #9285202 - Attachment description: WIP: Bug 1773324 - Simplify reporting errors to ErrorContext → Bug 1773324 - Simplify reporting errors to ErrorContext r=arai
Attachment #9285203 - Attachment description: WIP: Bug 1773324 - Add ErrorContext::hadErrors() and organize methods → Bug 1773324 - Add ErrorContext::hadErrors() and organize methods r=arai
Attachment #9285204 - Attachment description: WIP: Bug 1773324 - Rename onAllocationOverflow() to match naming of onOutOfMemory() → Bug 1773324 - Rename onAllocationOverflow() to match naming of onOutOfMemory() r=arai
Attachment #9285205 - Attachment description: WIP: Bug 1773324 - Clean up unneeded code → Bug 1773324 - Clean up unneeded code r=arai
Attachment #9285564 - Attachment description: WIP: Bug 1773324 - Support off-thread delazification using ErrorContext → Bug 1773324 - Support off-thread delazification using ErrorContext r=arai

addPendingCompileError() is replaced by OffThreadErrorContext::reportError().

Depends on D151878

Blocks: 1781008
Pushed by bthrall@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/5369fa38a413 Separate use of JSContext for allocation into its own parameter r=arai https://hg.mozilla.org/integration/autoland/rev/b31863ca872e Add ErrorReportMixin::getAllocator() r=arai https://hg.mozilla.org/integration/autoland/rev/61e92a33c07d Introduce ErrorContext for handling error reports. r=arai https://hg.mozilla.org/integration/autoland/rev/b6f70c94d870 Provide Parser ErrorContext as a constructor parameter. r=arai https://hg.mozilla.org/integration/autoland/rev/cf0dada16695 Plumb ErrorContext parameter out to where main vs. helper thread is known r=arai https://hg.mozilla.org/integration/autoland/rev/c3d1f8ea4873 Intro OffThreadErrorContext for off-thread compilation r=arai https://hg.mozilla.org/integration/autoland/rev/4bc7da9d66df Pass ErrorContext parameter to CompileModuleToStencil functions r=arai https://hg.mozilla.org/integration/autoland/rev/86c6381232c7 Support pending errors in OffThreadErrorContext r=arai https://hg.mozilla.org/integration/autoland/rev/bb106324e318 Pull OffThreadErrorContext to ParseTask member r=arai https://hg.mozilla.org/integration/autoland/rev/aef2d3304fc6 Report errors from ParseTask back to JSContext r=arai https://hg.mozilla.org/integration/autoland/rev/6c044f146772 Add test covering reporting off-thread compilation errors r=arai https://hg.mozilla.org/integration/autoland/rev/ed424d92b1c2 Replace ErrorReporting allocator with ErrorAllocator r=arai https://hg.mozilla.org/integration/autoland/rev/d4df7e3387c4 Remove ErrorReporting dependency on JSContext for GC-safe callback r=arai https://hg.mozilla.org/integration/autoland/rev/e31782ad0907 Remove template from ErrorAllocator, add ErrorContext::getAllocator(), rename OffThreadErrorContext::linkWithJSContext() r=arai https://hg.mozilla.org/integration/autoland/rev/e2184ca5ef0f Access ErrorAllocator via ErrorContext accessor r=arai https://hg.mozilla.org/integration/autoland/rev/99db76fde555 Fix typo r=arai https://hg.mozilla.org/integration/autoland/rev/2588027facdf Move implementations for ErrorContext to their own file r=arai https://hg.mozilla.org/integration/autoland/rev/0b9187cc4be4 Rename MainThreadErrorContext r=arai https://hg.mozilla.org/integration/autoland/rev/0cb5b56b74fb Simplify reporting errors to ErrorContext r=arai https://hg.mozilla.org/integration/autoland/rev/f3c25d3a623c Add ErrorContext::hadErrors() and organize methods r=arai https://hg.mozilla.org/integration/autoland/rev/10d24e14a707 Rename onAllocationOverflow() to match naming of onOutOfMemory() r=arai https://hg.mozilla.org/integration/autoland/rev/67dcf42b40bd Clean up unneeded code r=arai https://hg.mozilla.org/integration/autoland/rev/01aa3be551d3 Support off-thread delazification using ErrorContext r=arai https://hg.mozilla.org/integration/autoland/rev/da28877d8368 Remove dead JSContext methods for helper threads r=arai https://hg.mozilla.org/integration/autoland/rev/dea62af6ee07 Pass ErrorContext down through Smoosh functions r=arai
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 105 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: