Repository navigation
fix(mlir): resolve bundle imports with the C bundle's resolver - #1557
Merged
Merged
Conversation
mlir_bundle.flow carried its own copy of the Python module resolver. It refused the `..` string import that lib/stdlib/bytebuf.flow uses to reach compiler/src/bytebuf.flow, and it did not search FLOWC_DIR, so a string import rooted at the repository (tools/flow_cli/sys.flow) did not resolve. 64 programs the C backend builds stopped at "import that does not resolve". resolve.flow now exports flowc_resolve_module_import, the unsafe-path check plus flowc_resolve_import_at, and flowc_resolve_gather calls it. The MLIR bundle resolves every import through it with the C bundle's search directory (FLOWC_DIR, else FLOWC_ROOT, else the working directory) and project root, and drops its own resolver. The fixture compiler/fixtures/mlir/imports_resolve.flow imports both forms; the old flowc refuses it.
… unblocks parity_mlir --record, kept to the fixture and the 8 corpus programs the old flowc refused with "import that does not resolve" (std.bytebuf, std.regex and their importers, and a dotted import). No recorded digest moved.
godofecht
force-pushed
the
fix/mlir-import-resolution
branch
from
October 14, 2026 11:48
a799841 to
27e9c34
Compare
This was referenced Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Cause
compiler/src/mlir_bundle.flowhad its own copy of the retired Python module resolver. It differed from the C bundle in two ways:..part.lib/stdlib/bytebuf.flowreaches the compiler's byte buffer asimport "../../compiler/src/bytebuf.flow". The C resolver allows that inside lib/stdlib and lib/runtime (flowc_resolve_unsafe_import). So every program that imports std.bytebuf, std.regex or std.process failed.flow compilesets FLOWC_DIR to the distribution root, soimport "tools/flow_cli/sys.flow"resolves for C. The MLIR path only tried the module's directory, the stdlib,packages/and the project root.64 programs that the C backend builds stopped at
flowc mlir: unsupported: import that does not resolve.Fix
resolve.flowexportsflowc_resolve_module_import: the unsafe-path check, thenflowc_resolve_import_at.flowc_resolve_gathernow calls it, with the same behaviour as before.mlir_bundle.flowresolves every import through that function. It uses the C bundle's search directory (FLOWC_DIR, else FLOWC_ROOT, which the MLIR driver sets to the same root, else.) and project root. Its own resolver is gone, along with its flow.toml reader, its stdlib-root logic and the refusal of programs that have no flow.toml. That is about 330 lines.Regression test
compiler/fixtures/mlir/imports_resolve.flowimports"compiler/fixtures/mlir/mlir_dep.flow"(rooted at the repository) andstd.bytebuf. The old flowc refuses it withimport that does not resolve at line 6. The new one emits it, and it runs with12 / 8 / 1, exit 0.Baseline and after (mlir_vs_c, macOS arm64, LLVM 22.1.7, --jobs 8)
All 64 programs now resolve. 5 of them are now "same", plus the new fixture.
The other 59 now stop at later, separate causes:
field through a pointer static. These are mostly tools that import tools/flow_cli/sys.flow.redefinition of symbol named 'X'. This is the follow-up fix onfix/mlir-bundle-dup-symbols.top-level let.extern type.No program that was "same" at baseline is a real regression. The full run showed 4 programs that were not "same":
--only. They are load flakes at --jobs 8.The floor in compiler/mlir_vs_c/floor.txt is not raised.
Gates
flowc: PASSbootstrap_from_c.sh --regen(fixed point at gen2), then--verify: ALL PASSRegenerated state
compiler/bootstrap/flowc_stage_a.candflowc_stage_a, in their own last commit.parity_mlir --record, trimmed by hand to the new fixture's.mlir/.outand 8 new corpus.txt digests. Those 8 are lib/stdlib/bytebuf.flow, lib/stdlib/regex.flow, tests/lang/test_stdlib_bytebuf.flow, tests/lang/test_stdlib_regex.flow, tests/lang/test_import_normalized_path.flow, tests/fixtures/modules/dotpath/m/a.flow and the two cross_harness benchmarks. The old flowc refused each of them. No existing digest moved. The record also added 11 programs that the old flowc already accepted (main drift). I left those out.Risk
[paths] stdliboverride and the compilerpackages/fallback for string imports had no C counterpart, and no corpus program uses them.packages/does not exist in the tree.lib/stdlibin the C resolver is relative to the working directory, as it is forflow compile.This touches compiler/, so it needs review by a human CODEOWNER. Please do not enqueue it.