Skip to content

refactor(warpforthc): deslop the compiler driver - #135

Merged
tetsuo-cpp merged 6 commits into
canonfrom
claude/warpforthc-compiler-deslopping-dc5e96
Oct 24, 2026
Merged

tetsuo-cpp merged 6 commits into
canonfrom
claude/warpforthc-compiler-deslopping-dc5e96

Conversation

@tetsuo-cpp

@tetsuo-cpp tetsuo-cpp commented Oct 24, 2026 •

Copy link
Copy Markdown
Owner

Cleans up the warpforthc driver and the PTX extractor it calls, and fixes a parser bug found along the way. Each change is its own commit.

User-visible changes

  • One error per failed word. The parser reported a second, bogus unknown word error after a parameter or shared-memory name used inside a word, and after I/J/K used outside enough loops. emitOperation returned nullptr both for unknown words and for words it had already diagnosed. Now it emits the unknown-word error itself. The three existing error tests gain CHECK-NOT: unknown word, and they fail without the fix.
  • No trailing summary lines. warpforthc no longer prints failed to parse Forth source or compilation pipeline failed after the located diagnostic that already explains the failure. Every pass failure path ends in applyPartialConversion or an upstream pass, and both emit their own errors.
  • PTX extraction errors go through diagnostics. extractPTXFromModule now uses module.emitError instead of llvm::errs(), and drops the run warpforth-opt hint, which was wrong under warpforthc. New test: test/Translation/MLIRToPTX/no-binary-error.mlir.
  • File-open errors now read cannot open input file '<path>': ... (from MLIR's openInputFile/openOutputFile). They used to say could not open.

Internal changes

  • The driver no longer re-inserts the five dialects parseForthSource already loads, and drops the four headers kept only for that.
  • The mlir-to-ptx registration uses the typed TranslateFromMLIRRegistration overload in place of a hand-written ModuleOp cast.
  • Step-narrating comments and one stray brace pair are removed.

Verification

  • check-warpforth: 135/135 pass.
  • warpforthc output on every test/Pipeline/*.forth file is byte-identical to the output before this branch.
  • I ran the missing-input, unwritable-output, stdin-input and parse-error paths by hand.
  • Local check-clang-tidy (Homebrew clang-tidy 21) flags llvm-prefer-static-over-anonymous-namespace in ForthToMemRef.cpp and ForthToGPU.cpp. This branch doesn't touch either file. IWYU isn't installed locally, so CI will be the first IWYU run on the include changes.

emitOperation returned nullptr both for unknown words and for words it had
already diagnosed (parameter or shared names inside a word, I/J/K outside
enough loops). The caller treated every nullptr as unknown, so those cases
printed a second, misleading "unknown word" error. emitOperation now emits
the unknown-word diagnostic itself, so nullptr always means already reported.
The parser and the pipeline passes already report located diagnostics
through the SourceMgr handler, so the trailing "failed to parse Forth
source" and "compilation pipeline failed" lines only repeated them.
parseForthSource already loads the Forth, arith, cf, func and memref
dialects it emits. The driver's own registry.insert repeated that list
and kept four headers alive only for it.
openInputFile and openOutputFile already handle stdin/stdout and format
the error with the path, replacing two hand-written open-and-report
blocks.
The four step comments restated the next line, and one sat above the
registry setup rather than the parse. The last single-statement if kept
braces that no other if in the file uses.
extractPTXFromModule wrote straight to llvm::errs(), bypassing the
diagnostic handler, and its hint to run warpforth-opt was wrong when
warpforthc was the caller. It now uses module.emitError. The mlir-to-ptx
registration passes the function to the typed TranslateFromMLIRRegistration
overload, which does the ModuleOp cast and error itself.
@tetsuo-cpp
tetsuo-cpp enabled auto-merge (rebase) October 24, 2026 11:20
@tetsuo-cpp
tetsuo-cpp merged commit eaf49a8 into canon Oct 24, 2026
1 check passed
@tetsuo-cpp
tetsuo-cpp deleted the claude/warpforthc-compiler-deslopping-dc5e96 branch October 24, 2026 11:27
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