Open Bug 1410184 Opened 7 years ago Updated 23 hours ago

[META] Investigate replacing the JS CSS lexer

Categories

(DevTools :: Inspector, task, P3)

task

Tracking

(Not tracked)

ASSIGNED

People

(Reporter: jryans, Assigned: nchevobbe)

References

(Depends on 4 open bugs, Blocks 2 open bugs)

Details

(Keywords: meta, Whiteboard: [designer-tools][stylo-])

Attachments

(1 obsolete file)

In bug 1265787, we landed a JS version of Gecko's CSS lexer, so that the inspector could use it when running in a tab.

Now that the platform is moving towards Stylo, it would be good to adapt this to be based on Stylo's lexer instead.

At the same time, it would also be an interesting test case for compiling Rust to WebAssembly, which should improve speed over the pure JS version we have today.
Whiteboard: [designer-tools]
status-firefox57=wontfix unless someone thinks this bug should block 57
Assignee: nobody → jryans
Status: NEW → ASSIGNED
Tagging this bug "[stylo-]" to remove it from Style bug triage queries because this is not a Stylo bug.
Whiteboard: [designer-tools] → [designer-tools][stylo-]
Slowly making some progress on this task.  The Rust WASM tooling advances quickly, so I had been waiting a bit to let it mature first.

I hit a conflict between wasm-bindgen and cssparser while exploring this, but I have sent a PR to workaround it:

https://github.com/rustwasm/wasm-bindgen/pull/165
Product: Firefox → DevTools
No longer blocks: stylo-everywhere
No longer blocks: 1418874
After thinking about bug 1410716 a bit more, I think it is pretty likely that changing to use WASM for the lexer would regress that bug to some extent, because WASM cannot access normal JS objects, and thus we have to duplicate the CSS content into WASM's memory before invoking it.

And I think a proper solution to that bug is to construct lexer only once for each stylesheet, so that we don't repeatedly duplicate the content. That would probably be a prerequisite to this bug then.
Depends on: 1410716
Assignee: jryans → nobody
Status: ASSIGNED → NEW
Severity: normal → S3

In some early analysis for Bug 1836873 , I came across our JS-written CSS lexer again, which I guess should be modified to account for the new syntax added for CSS Nesting.

I was wondering if that would be a good time to try to revive this specific bug instead of replicating work that was already done on the platform.
Another solution that we could consider is to allow (privileged) JS to directly call the Stylo Lexer, so we won't have to go through the WASM conversion (at the time this bug was created, we wanted to get rid of privileged code in DevTools, but this isn't the case anymore).

Emilio, what do you think about this? Does this sounds like something that would be hard to do/not worth the benefit?

Flags: needinfo?(emilio)

What kind of API would you need from the platform? cssparser is rather standalone so compiling to wasm shouldn't be hard in theory... But if a WebIDL/XPIDL api is simpler that's fine too. Do you just want a tokenized range of source text? Something else

Flags: needinfo?(emilio) → needinfo?(nchevobbe)

(In reply to Emilio Cobos Álvarez (:emilio) from comment #6)

What kind of API would you need from the platform? cssparser is rather standalone so compiling to wasm shouldn't be hard in theory... But if a WebIDL/XPIDL api is simpler that's fine too. Do you just want a tokenized range of source text? Something else

Yeah a tokenizer would be great so we can replace https://searchfox.org/mozilla-central/rev/27e4816536c891d85d63695025f2549fd7976392/devtools/shared/css/parsing-utils.js#42-111

Flags: needinfo?(nchevobbe)
See Also: → 1840320
See Also: → 1265787
Summary: Investigate replacing the JS CSS lexer with Stylo's lexer in WebAssembly → Investigate replacing the JS CSS lexer
Blocks: 1410716
No longer depends on: 1410716
Blocks: 1875992
Type: enhancement → task
Blocks: 1644138
Assignee: nobody → nchevobbe
Status: NEW → ASSIGNED

I have a somewhat working c++/rust implementation to iterate over the tokens so I could see the impact on getRuleText, which currently uses the lexer (won't be the case after Bug 1882964 , but this is an easy way to assert the impact):

Depends on: 1887638

Comment on attachment 9387991 [details]
Bug 1410184 - [devtools] Add InspectorUtils.getCSSParser method. r=emilio.

Revision D202909 was moved to bug 1887638. Setting attachment 9387991 [details] to obsolete.

Attachment #9387991 - Attachment is obsolete: true
Depends on: 1888353
Depends on: 1888363
Depends on: 1888441
Depends on: 1888607
Depends on: 1888609
Depends on: 1888615
Depends on: 1889871
Depends on: 1889875
Depends on: 1889920
Depends on: 1889938
Depends on: 1890493
Depends on: 1890552
No longer blocks: 1644138
Keywords: meta
Summary: Investigate replacing the JS CSS lexer → [META] Investigate replacing the JS CSS lexer
Depends on: 1892895
Depends on: 1892897
Depends on: 1892923
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: