compiler: Incorrect code gen for anon switch with default field
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- compilers
调研方向
Start with the anonymous switch and default condition in data/bedrock/1.18.0/protocol.json at lines 6571-6617, then reproduce the generated packet_command_block_update code shown in the issue. Trace the compiler path that expands anonymous switch fields; done means the default branch is emitted once rather than rereading minecart_entity_runtime_id for each following field, while the non-default examples remain correct.
由索引模型根据 Issue 内容生成。
描述
above uses an anonymous switch field with a default condition, but the compiler generates code that repeatedly reads the default condition (minecart_entity_runtime_id):
packet_command_block_update: (buffer, offset) => {
let { value: is_block, size: is_blockSize } = (ctx.bool)(buffer, offset)
let { value: position, size: positionSize } = ((buffer, offset) => {
switch (is_block) {
case true: return (ctx.BlockCoordinates)(buffer, offset)
default: return ((buffer, offset) => {
let { value: minecart_entity_runtime_id, size: minecart_entity_runtime_idSize } = (ctx.varint64)(buffer, offset) // <==
return { value: { minecart_entity_runtime_id }, size: minecart_entity_runtime_idSize}
})(buffer, offset)
}
})(buffer, offset + is_blockSize)
let { value: mode, size: modeSize } = ((buffer, offset) => {
switch (is_block) {
case true: return ((buffer, offset) => {
const { value, size } = (ctx.varint)(buffer, offset)
return { value: {"0":"impulse","1":"repeat","2":"chain"}[value] || value, size }
})(buffer, offset)
default: return ((buffer, offset) => {
let { value: minecart_entity_runtime_id, size: minecart_entity_runtime_idSize } = (ctx.varint64)(buffer, offset)
return { value: { minecart_entity_runtime_id }, size: minecart_entity_runtime_idSize}
})(buffer, offset)
}
})(buffer, offset + is_blockSize + positionSize)
let { value: needs_redstone, size: needs_redstoneSize } = ((buffer, offset) => {
switch (is_block) {
case true: return (ctx.bool)(buffer, offset)
default: return ((buffer, offset) => {
let { value: minecart_entity_runtime_id, size: minecart_entity_runtime_idSize } = (ctx.varint64)(buffer, offset)
return { value: { minecart_entity_runtime_id }, size: minecart_entity_runtime_idSize}
})(buffer, offset)
}
})(buffer, offset + is_blockSize + positionSize + modeSize)
let { value: conditional, size: conditionalSize } = ((buffer, offset) => {
switch (is_block) {
case true: return (ctx.bool)(buffer, offset)
default: return ((buffer, offset) => {
let { value: minecart_entity_runtime_id, size: minecart_entity_runtime_idSize } = (ctx.varint64)(buffer, offset)
return { value: { minecart_entity_runtime_id }, size: minecart_entity_runtime_idSize}
})(buffer, offset)
}
})(buffer, offset + is_blockSize + positionSize + modeSize + needs_redstoneSize)
let { value: minecart_entity_runtime_id, size: minecart_entity_runtime_idSize } = ((buffer, offset) => {
switch (is_block) {
default: return (ctx.varint64)(buffer, offset)
}
})(buffer, offset + is_blockSize + positionSize + modeSize + needs_redstoneSize + conditionalSize)
not using an anon field or not using default generates correct code, e.g.
let { value: data, size: dataSize } = ((buffer, offset) => {
switch (is_block) {
case true: return ((buffer, offset) => {
let { value: position1, size: position1Size } = (ctx.BlockCoordinates)(buffer, offset)
let { value: mode1, size: mode1Size } = ((buffer, offset) => {
const { value, size } = (ctx.varint)(buffer, offset)
return { value: {"0":"impulse","1":"repeat","2":"chain"}[value] || value, size }
})(buffer, offset + position1Size)
let { value: needs_redstone, size: needs_redstoneSize } = (ctx.bool)(buffer, offset + position1Size + mode1Size)
let { value: conditional, size: conditionalSize } = (ctx.bool)(buffer, offset + position1Size + mode1Size + needs_redstoneSize)
return { value: { position: position1, mode: mode1, needs_redstone, conditional }, size: position1Size + mode1Size + needs_redstoneSize + conditionalSize}
})(buffer, offset)
default: return ((buffer, offset) => {
let { value: minecart_entity_runtime_id, size: minecart_entity_runtime_idSize } = (ctx.varint64)(buffer, offset)
return { value: { minecart_entity_runtime_id }, size: minecart_entity_runtime_idSize}
})(buffer, offset)
}
})(buffer, offset + is_blockSize)
- 主要语言
- JavaScript
- 星标
- 35
- 派生
- 27
- 平均合并
- 4 天 10 小时
- 30 天内合并 PR
- 3
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ProtoDef-io/node-protodef 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 35/100
ProtoDef-io/node-protodef#156 · 1 条评论 ·
-
难度 5/5 一周以上 新手友好度 25/100
ProtoDef-io/node-protodef#150 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 35/100
ProtoDef-io/node-protodef#139 · 1 条评论 ·
-
enhancement
难度 4/5 3-5 天 新手友好度 35/100
ProtoDef-io/node-protodef#128 · 2 条评论 ·
-
How it works?未关闭
难度 3/5 1-2 天 新手友好度 20/100
ProtoDef-io/node-protodef#116 ·
查看 ProtoDef-io/node-protodef 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 60/100
quarto-dev/quarto-cli#15042 ·
维护者通常 1 天内回复
-
OpenCode install copies the Pi harness directory (`.pi/`) into the OpenCode config root可能已有人在做 @gaurav0107 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 条评论 ·
维护者通常 3 天内回复
-
Docs viewer: inverted grey colormap, Phantom CT window -20 to 35 HU, smoothing up to 40 mm可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭area: docs enhancement
难度 2/5 1-3 小时 新手友好度 64/100
PyTomography/PyTomography#331 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
pnpm/get.pnpm.io#68 ·