Skip to content

add topic06 deliverable - #20

Open
2813183274-cloud wants to merge 2 commits into
ScratchV-Compiler:mainfrom
2813183274-cloud:topic06
Open

add topic06 deliverable #20
2813183274-cloud wants to merge 2 commits into
ScratchV-Compiler:mainfrom
2813183274-cloud:topic06

Conversation

@2813183274-cloud

Copy link
Copy Markdown

No description provided.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

🤖 AI Code Review

共审查 10 个变更文件
⚠️ 另有 19 个文件超过上限(最多 10 个)未审查

📁 ScratchV-topic06-deliverable/.github/workflows/benchmark.yml

🔴 Missing dependency caching — Each run downloads pip packages from scratch, adding ~1-2 min. Use actions/cache with pip and setup-python’s cache option.

🟡 Duplicate triggerspush + pull_request runs the same commit twice on PR pushes. Consider pull_request only, or restrict push to main.

🟡 No workflow timeout — Benchmark may hang indefinitely. Add timeout-minutes: 30 to the job or step.

🟡 Hardcoded benchmark argument--benchmark 3 is opaque. Use a workflow input or environment variable to make it configurable.

💭 Artifact file resolution — If reports/ files are missing, the step still succeeds but uploads nothing. Add if-no-files-found: error to catch failures early.


📁 ScratchV-topic06-deliverable/LICENSE

无问题。


📁 ScratchV-topic06-deliverable/README.md

🟡 表述模糊 — "3个branch中的三个if分支" 含义不清,建议改为"3个分支相关的测试用例(其中3个if分支调用tinyfive时目前还不通过)"。

🟡 补丁安装步骤缺失 — 只给出了两个PR链接,未说明如何应用(如 cherry-pick、等待合并、或手动打补丁),建议补充具体操作步骤。

🟡 --benchmark 参数说明不完整 — 文档说"重复运行每个用例并统计平均指令数",但未解释参数 3 的含义(重复次数),建议明确:--benchmark N 表示重复运行 N 次求平均。

💭 基线文件用途未说明 — 更新基线后 reports/benchmark_baseline.json 的作用未提及,建议简要说明其用于后续性能对比。


📁 ScratchV-topic06-deliverable/reports/benchmark_baseline.json

🔴 Missing newline at end of file — 文件末尾没有换行符。虽然不影响 JSON 解析,但违背 POSIX 标准,可能导致工具链问题。

🟡 Branch 类别的 avg_instr_count 为 0.0if_else, if_relu, if_then 的指令计数均为 0.0,可能意味着基准测试未捕获到分支指令,或实现有误(如全部被优化掉)。建议核实基准测试方法,确保分支指令被正确测量。

💭 缺少元数据 — 基线文件没有包含生成时间、工具版本、硬件信息等元数据,不利于后续复现和对比。建议在 JSON 顶层增加 metadata 字段。


📁 ScratchV-topic06-deliverable/reports/report.html

🔴 硬编码绝对路径暴露内部结构 — 第 10 行(summary 区块)中 D:\PycharmProjects\ScratchV\... 泄露了开发者本地目录。建议:使用相对路径或仅显示测试目录名称(如 tests_main),或直接去掉这一行。

🟡 相对图片路径可能失效 — 第 9 行 <img src="course_report_instructions.png"> 使用相对路径,但未确认该文件是否随报告一起分发或存在于同一目录。建议:明确图片路径(如 reports/课程版指令数图表.png)或内联 Base64 图片,避免报告移植后图片缺失。

🟡 “变化率(%)”列全为 0.00 — 所有用例变化率均为 0,且“是否退化”全为 False。若报告用于比较基线,则当前数据无实际意义;若未做比较,建议隐藏该列或其标题,避免误导读者。

🟡 “模拟后端”列全为 “none” — 若所有测试均使用默认后端,可考虑删除该列以减少表格宽度,或改为有意义的默认值描述(如“默认”)。

💭 表格样式可优化 — 第 4 行 table { font-size: 13px; } 在大量列(12列)时可能导致内容拥挤,建议允许 white-space: nowrap 或为特定列设置最小宽度,并考虑响应式滚动。

💭 缺少 标签 — 移动端访问时表格可能溢出,建议添加 <meta name="viewport" content="width=device-width, initial-scale=1.0">

💭 “总耗时(s)”列包含编译+模拟+其他开销 — 从数据看,总耗时远大于编译+模拟耗时之和(如 if_else 行:0.0512+5.0168≈5.068,但总耗时 20.09),说明“总耗时”包含多次重复运行或额外开销,应明确标题或添加注释。


📁 ScratchV-topic06-deliverable/reports/report.md

🔴 失败用例性能数据误导 — 三个超时用例(if_else, if_relu, if_then)指令数为0,基线为0,变化率0.00%,标记为未退化。实际测试失败,有效指令数不可用,不应进行性能比较。建议跳过或标记为N/A。

🔴 绝对路径泄露 — 报告中所有汇编文件路径、测试目录、基线文件均为 D:\PycharmProjects\ScratchV\... 绝对路径。不可移植,且暴露文件系统结构。应改为相对路径或仅文件名。

🟡 失败用例缺乏诊断信息 — 超时原因未说明。建议在用例详情或概览中增加“失败原因”字段(如:模拟器无限循环、代码生成死循环等),或提供模拟器日志链接。

🟡 性能退化分析对无效数据无意义 — 失败用例的退化阈值和变化率字段应显示为“N/A”,避免误导读者认为性能正常。

💭 图表引用不完整 — 报告引用 course_report_instructions.png,但该图片未嵌入或确认路径。建议确保图片存在,或移除引用仅保留Mermaid图表。Mermaid图表x轴标签过长,建议旋转或缩写。

💭 “模拟后端”列值不统一 — 失败用例显示“timeout”,其他为“none”。timeout是状态而非后端类型。建议为模拟后端另设列,或使用“none”表示无模拟,超时作为单独状态列。

💭 详细部分与表格信息冗余 — 每个用例详细部分重复了表格中的多数字段(编译耗时、模拟耗时等)。建议精简为仅在表格中展示,详细部分只保留描述、预期/实际输出等非表格信息。


📁 ScratchV-topic06-deliverable/requirements-topic06.txt

🟡 Suggestion: Pin dependency versions — Unpinned dependencies may cause unpredictable builds. Consider adding version constraints (e.g., pytest>=7.0,<8).

🟡 Suggestion: Verify tinyfive — This package is not widely known; ensure it is spelled correctly and exists in PyPI to avoid pip install failures.


📁 ScratchV-topic06-deliverable/run_tests.py

🔴 严重代码重复generate_report_text 被定义了 3 次,write_html_report 被定义了 2 次,generate_report_text_cn 被定义了 2 次,write_html_report_cn 被定义了 2 次,write_report 被定义了 2 次。这些函数内容几乎完全相同,只有细微的列名或字段差异。这会导致维护困难、bug 难以排查,且文件膨胀到 1481 行。
Suggestion: 将所有报告生成逻辑合并到一个函数(例如 generate_report),通过参数(如 languageinclude_benchmarkinclude_timing)控制输出格式。删除所有重复定义。

🔴 write_report 函数被覆盖 — 第 1290 行和 1430 行各定义了一个 write_report,后者覆盖前者。但前者在文件中间被定义,且功能不完整(只写 Markdown,不生成图表和 HTML),若被意外调用会导致报告不完整。
Suggestion: 只保留最后的 write_report,删除前面的重复定义。

🟡 run_simulation 错误处理不完整 — 第 82 行,当 completed.returncode != 0 时,只返回 (completed.stderr or completed.stdout or "simulation failed").strip()。这可能会丢失实际的错误信息(例如 stderr 为空但 stdout 有错误信息)。
Suggestion: 返回完整的错误信息,例如 f"stderr: {completed.stderr}\nstdout: {completed.stdout}"

🟡 benchmark_counts 未检查 run_simulation 返回的 success — 第 1445 行,在 benchmark 循环中直接取 instr_count,如果某次模拟失败(返回 success: False),instr_count 可能为 0,导致平均值失真。
Suggestion: 只统计成功的模拟结果,或至少记录失败次数。

💭 辅助函数 _markdown_cell 定义位置混乱 — 定义在文件中间(第 1180 行),但被 generate_report_text 等函数调用。虽然 Python 允许,但不利于阅读。
Suggestion: 将 _markdown_cell 移到文件顶部附近,与其他辅助函数一起。

💭 run_simulation 使用内联代码字符串 — 虽然安全,但可读性差。可以考虑将模拟逻辑提取为独立函数,或在 subprocess.run 中直接调用 scratchv.simulator.tinyfive.verify_assembly
Suggestion: 重构为 subprocess.run([sys.executable, "-m", "scratchv.simulator.tinyfive", str(asm_file)]) 如果该模块支持 CLI,否则保持现状但添加注释。


📁 ScratchV-topic06-deliverable/setup.py

🔴 Missing required metadatasetup() called without arguments. This will fail because setuptools requires at least name (and often version, packages). Add name, version, packages, install_requires, etc. depending on the project.


📁 ScratchV-topic06-deliverable/tests_main/activation/add_relu_relu.dsl

🔴 Missing Input Definition — 文件未定义 inputbias 的来源。若依赖外部上下文,建议添加注释说明,否则可能因隐式依赖导致可读性或测试不确定性。

🟡 Redundant ReLU — 连续两次 relu 是幂等的:relu(relu(x)) = relu(x)。若为测试特定场景(如中间值检查),建议添加注释说明意图;否则可直接省略第二个 relu 以简化。



⚠️ 未审查的文件

  • ScratchV-topic06-deliverable/tests_main/activation/add_relu_relu.meta.json
  • ScratchV-topic06-deliverable/tests_main/activation/relu_add.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/relu_add.meta.json
  • ScratchV-topic06-deliverable/tests_main/activation/relu_only.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/relu_only.meta.json
  • ScratchV-topic06-deliverable/tests_main/activation/relu_twice.dsl
  • ScratchV-topic06-deliverable/tests_main/activation/relu_twice.meta.json
  • ScratchV-topic06-deliverable/tests_main/branch/if_else.dsl
  • ScratchV-topic06-deliverable/tests_main/branch/if_else.meta.json
  • ScratchV-topic06-deliverable/tests_main/branch/if_relu.dsl
  • ScratchV-topic06-deliverable/tests_main/branch/if_relu.meta.json
  • ScratchV-topic06-deliverable/tests_main/branch/if_then.dsl
  • ScratchV-topic06-deliverable/tests_main/branch/if_then.meta.json
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain.dsl
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain.meta.json
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain_3.dsl
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_chain_3.meta.json
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_fan_in_4.dsl
  • ScratchV-topic06-deliverable/tests_main/elementwise/add_fan_in_4.meta.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant