[torque] The first part of a TSA-backend for Torque [v8/v8 : main]

0 views
Skip to first unread message

Nico Hartmann (Gerrit)

unread,
Jan 7, 2026, 10:15:51 AM (2 days ago) Jan 7
to AyeAye, V8 LUCI CQ, v8-flag...@chromium.org, was...@google.com, dmercadi...@chromium.org, v8-re...@googlegroups.com, victorgo...@chromium.org

Nico Hartmann added 2 comments

Patchset-level comments
File-level comment, Patchset 20:
Nico Hartmann . resolved

Let's get started with this.

TSAGenerator is still highly incomplete with lots of TODOs. A number of pieces are copy-and-pasted from other visitors (implementation visitor or declaration visitor) and I left quite some stuff behind #if 0 for now, because that way it is easier for me to see what's still missing in those cases and since the entire thing is a 1-person experimental project right now, I don't see any issues with leaving a bit of a mess that is to be completed and cleaned up in follow-up work.

File BUILD.gn
Line 463, Patchset 20: v8_enable_experimental_tq_to_tsa = true
Nico Hartmann . unresolved

TODO: Revert before landing.

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: Ia669532827b133f68e110cbf982b3119378e1953
Gerrit-Change-Number: 7021934
Gerrit-PatchSet: 22
Gerrit-Owner: Nico Hartmann <nicoha...@chromium.org>
Gerrit-Reviewer: Nico Hartmann <nicoha...@chromium.org>
Gerrit-Comment-Date: Wed, 07 Jan 2026 15:15:46 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Nico Hartmann (Gerrit)

unread,
Jan 7, 2026, 10:18:52 AM (2 days ago) Jan 7
to Darius Mercadier, AyeAye, V8 LUCI CQ, v8-flag...@chromium.org, was...@google.com, dmercadi...@chromium.org, v8-re...@googlegroups.com, victorgo...@chromium.org
Attention needed from Darius Mercadier

Nico Hartmann added 1 comment

Patchset-level comments
Nico Hartmann . resolved

Let's get started with this.

TSAGenerator is still highly incomplete with lots of TODOs. A number of pieces are copy-and-pasted from other visitors (implementation visitor or declaration visitor) and I left quite some stuff behind #if 0 for now, because that way it is easier for me to see what's still missing in those cases and since the entire thing is a 1-person experimental project right now, I don't see any issues with leaving a bit of a mess that is to be completed and cleaned up in follow-up work.

Nico Hartmann
A right, and what is complete for now is the `ToString` builtin
```
TS_BUILTIN(ToString, StringBuiltinsAssemblerTS) {
auto context = Parameter<Context>(Descriptor::kContext);
auto o = Parameter<JSAny>(Descriptor::kO);
Return(ToStringImpl(context, o));
}
```
and the required `ToStringImpl` macro, which looks like that:
```
template <typename Next>
class TorqueGeneratedStringBuiltinsReducer : public Next {
public:
BUILTIN_REDUCER(TorqueGeneratedStringBuiltins)
  V<String> ToStringImpl(V<Context> context, V<JSAny> o) {
Label<String> _return(this);
    ScopedVar<JSAny> result(this, o);
WHILE(true) {
TYPESWITCH(result) {
CASE_(V<Number>, num): {
GOTO(_return, __ NumberToString(num));
}
CASE_(V<String>, str): {
GOTO(_return, str);
}
CASE_(V<Oddball>, oddball): {
GOTO(_return, __ LoadField(oddball, FIELD(Oddball, to_string_)));
}
CASE_(V<JSReceiver>, receiver): {
result = __ NonPrimitiveToPrimitive_String_Inline(context, receiver);
CONTINUE;
}
CASE_(V<Symbol>, _): {
__ ThrowTypeError(context, MessageTemplate::kSymbolToString);
}
CASE_(V<JSAny>, _): {
GOTO(_return, __ template CallRuntime<runtime::ToString>(context, {{}, result}));
}
}
}
__ Unreachable();
    BIND(_return, return_value);
return return_value;
}

};
```

Open in Gerrit

Related details

Attention is currently required from:
  • Darius Mercadier
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: Ia669532827b133f68e110cbf982b3119378e1953
Gerrit-Change-Number: 7021934
Gerrit-PatchSet: 22
Gerrit-Owner: Nico Hartmann <nicoha...@chromium.org>
Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Reviewer: Nico Hartmann <nicoha...@chromium.org>
Gerrit-Attention: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Comment-Date: Wed, 07 Jan 2026 15:18:48 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Nico Hartmann <nicoha...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy

Darius Mercadier (Gerrit)

unread,
Jan 8, 2026, 4:58:37 AM (yesterday) Jan 8
to Nico Hartmann, AyeAye, V8 LUCI CQ, v8-flag...@chromium.org, was...@google.com, dmercadi...@chromium.org, v8-re...@googlegroups.com, victorgo...@chromium.org
Attention needed from Nico Hartmann

Darius Mercadier voted and added 5 comments

Votes added by Darius Mercadier

Code-Review+1

5 comments

Patchset-level comments
File-level comment, Patchset 22 (Latest):
Darius Mercadier . resolved

lgtm

File src/torque/ast-desugaring.cc
Line 12, Patchset 22 (Latest):
Darius Mercadier . unresolved

So why do you need this? Looks like this usually happens in the Torque Parser, but for TSA you desugar later? Why not use the TYPESWITCH of TSA? (maybe add a comment explaining when/why you need to desugar typeswitches)

Line 41, Patchset 22 (Latest): // const x2 : T2 = cast<T2>(%assume_impossible<T1>(_value));
Darius Mercadier . unresolved

nit: you're missing an `otherwise _NextCase` at the end of this line

Line 81, Patchset 22 (Latest): if (cases[i].name) name = *cases[i].name;
Darius Mercadier . unresolved

Seems superfluous

File src/torque/tsa-generator.cc
Line 768, Patchset 22 (Latest): // TODO(nicohartmann): Handle simple cases where this can be avoided.
Darius Mercadier . unresolved

What do you mean "cases where this can be avoided"?

Open in Gerrit

Related details

Attention is currently required from:
  • Nico Hartmann
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: Ia669532827b133f68e110cbf982b3119378e1953
Gerrit-Change-Number: 7021934
Gerrit-PatchSet: 22
Gerrit-Owner: Nico Hartmann <nicoha...@chromium.org>
Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Reviewer: Nico Hartmann <nicoha...@chromium.org>
Gerrit-Attention: Nico Hartmann <nicoha...@chromium.org>
Gerrit-Comment-Date: Thu, 08 Jan 2026 09:58:32 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Nico Hartmann (Gerrit)

unread,
Jan 8, 2026, 7:54:28 AM (22 hours ago) Jan 8
to Darius Mercadier, AyeAye, V8 LUCI CQ, v8-flag...@chromium.org, was...@google.com, dmercadi...@chromium.org, v8-re...@googlegroups.com, victorgo...@chromium.org
Attention needed from Darius Mercadier

Nico Hartmann added 4 comments

File src/torque/ast-desugaring.cc
Darius Mercadier . unresolved

So why do you need this? Looks like this usually happens in the Torque Parser, but for TSA you desugar later? Why not use the TYPESWITCH of TSA? (maybe add a comment explaining when/why you need to desugar typeswitches)

Nico Hartmann

There used to not exist an ast node representing a `typeswitch` in Torque, but the parser immediately desugared this into a chain of `try { ... = Cast<Type>(value) otherwise Next; }` and it's very hard to turn this back into a nice TSA `TYPESWITCH` from that, so in order to map the torque code as close as possible to TSA, I introduced a new ast node for typeswitches which can then be consumed by the TSAGenerator and will only be lowered later (for the CSA generation to preserve the original behavior).

Side note: Initially, the idea was to have this order of events:
`Parser -> TSAGeneration -> Desugaring -> CSAGeneration` and hence there was a dedicated phase for desugaring high-level nodes (currently only typeswitch). However, in the meantime I had to give up on that strategy because part of the CSA stuff needs to run before TSAGeneration, which doesn't work like that in a single pipeline anymore. In the new setup, Torque is invoked twice (once for CSA and once for TSA), so it would now be enough to desugar/or not in the parser depending on the run, because the TSA run ends after TSAGeneration and doesn't need to lower the graph for anything else anymore.

If this strategy works for the rest of the TSA backend, I will eventually put this back into the parser potentially (and the AstVisitor will also be obsolete then), but I will keep it for a little while in case I run into other issues where delayed desugaring helps.

Line 41, Patchset 22: // const x2 : T2 = cast<T2>(%assume_impossible<T1>(_value));
Darius Mercadier . resolved

nit: you're missing an `otherwise _NextCase` at the end of this line

Nico Hartmann

Done

Line 81, Patchset 22: if (cases[i].name) name = *cases[i].name;
Darius Mercadier . resolved

Seems superfluous

Nico Hartmann

Done

File src/torque/tsa-generator.cc
Line 768, Patchset 22: // TODO(nicohartmann): Handle simple cases where this can be avoided.
Darius Mercadier . unresolved

What do you mean "cases where this can be avoided"?

Nico Hartmann

```
macro MyFavouriteConstant(): int32 { return 42; }
```

would currently generate something like
```
Label<Word32> _return(this);
GOTO(_return, 42);
BIND(_return, return_value);
return return_value;
```
and it would be nice to just emit
```
return __ Word32Constant(42);
```
for that instead. (So that's macros with a single return at the very end basically).

Open in Gerrit

Related details

Attention is currently required from:
  • Darius Mercadier
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: v8/v8
Gerrit-Branch: main
Gerrit-Change-Id: Ia669532827b133f68e110cbf982b3119378e1953
Gerrit-Change-Number: 7021934
Gerrit-PatchSet: 23
Gerrit-Owner: Nico Hartmann <nicoha...@chromium.org>
Gerrit-Reviewer: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Reviewer: Nico Hartmann <nicoha...@chromium.org>
Gerrit-Attention: Darius Mercadier <dmerc...@chromium.org>
Gerrit-Comment-Date: Thu, 08 Jan 2026 12:54:23 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Darius Mercadier <dmerc...@chromium.org>
satisfied_requirement
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages