fix: Ensure submodules compile before programs for LFortran direct mode (#1252)#1253
Open
ijatinydv wants to merge 1 commit intofortran-lang:mainfrom
Open
fix: Ensure submodules compile before programs for LFortran direct mode (#1252)#1253ijatinydv wants to merge 1 commit intofortran-lang:mainfrom
ijatinydv wants to merge 1 commit intofortran-lang:mainfrom
Conversation
778b021 to
27272f3
Compare
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.
Resolves #1252
Currently, FPM's topological sort allows programs and submodules sharing a parent module to be scheduled in the same OpenMP region. For compilers using direct compilation (like LFortran), this creates a race condition where the main program attempts to compile before all
.smodfiles are generated.The Fix
Added a post-resolution pass in
resolve_module_dependencies(fpm_targets.f90) that establishes a blanket dependency edge from allFPM_UNIT_PROGRAMandFPM_UNIT_TESTtargets to allFPM_UNIT_SUBMODULEtargets.Why a blanket rule instead of parent-matching?
Parent-matching fails on transitive dependencies (e.g.,
main -> mod_A -> mod_B -> submod_Bmisses the indirect submodule becausemodules_usedonly containsmod_A). Since programs and tests are terminal nodes in the build graph, adding blanket edges has zero performance cost and guarantees correct compilation order.Tests Added
Added 5 new tests to
test_module_dependencies.f90to verify:cc @certik