google / google/heir

pipelines should abort after the current pass if it created errors

Open
#2,000 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
MLIR
Stars
906
Forks
171
Avg merge
4d 12h
Merged PRs (30d)
32

Description

Currently, most HEIR passes will not `SignalPassFailure()` (which, by default, aborts the rest of the pipeline) even when they throw a hard error. This means that we're passing confirmed-to-be-invalid IR to the next pass, which might then choke/crash (not sure if this is what causes #1992 but it clearly accounts for _many_ of the crashes/stackdumps we see when trying to compile something not-yet-supported.

Unfortunately, it doesn't seem very easy to `SignalPassFailure()` in many of our passes, as it's not generally available inside Patterns, nor does the Pass usually get notified about emitError's happening inside Patterns. Instead, it seems like we need to add some PassInstrumentation that registers a DiagnosticHandler that watches for hard errors and can update some kind of `pass_procuced_errors" variable which we can then use to decide whether or not the pass should signal failure after having applied its patterns.

The straightforward but annoying way to do is would be to simply add this logic to all our passes. Alternatively, we could introduce a new base class with this logic baked in and have our Passes inherit from that? Finally, there might also be a way to register pass instrumentation via a `PassManager`, but the way we currently do `heir-opt.cpp` only gives us an `OpPassManager` which doesn't have that feature...

PS: I'm not suggesting to abort the entire compilation after the _first_ error, a pass that's able to produce many errors without crashing/running into issues can still do that, it's just that we'd stop going down the pipeline after the first pass with errors.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.