Register imported libraries in dependency order (#3620)

block_mark_referenced walks the joined block backwards and skips the
body of any definition not yet marked referenced, so a library must
precede its importers.  f58787c41 registered a library before walking
its dependencies, to have somewhere to keep the `loading` flag, which
reversed that order and made block_drop_unreferenced free definitions
that are still referenced through bound_by.

Keep the libraries being loaded on a stack threaded through the
load_library frames instead, so registration can move back after the
dependency walk.
This commit is contained in:
itchyny authored and GitHub committed 2026-09-18 22:27:54 +09:00
1 parent e371bfaa92
commit 12cdd950e9
7 files changed
+59 -23

No files matched your search

+17
View File
@@ -1950,6 +1950,23 @@ import "shadow1" as f; import "shadow2" as f; import "shadow1" as e; [e::e, f::e
null
[2,3]
# A module reached only through another module must be linked before its
# importers, or dead-code elimination drops the definitions that only the
# importer's body references (#3597)
include "deep1"; f
null
[1,[21,3],[22,3,1]]
# ... including when the shared dependency is pulled in first by an importer
# whose own definitions end up unused, in either import order
import "deep2a" as a; import "deep2b" as b; b::f
null
[22,3,1]
import "deep2b" as b; import "deep2a" as a; b::f
null
[22,3,1]
%%FAIL
module (.+1); 0
jq: error: Module metadata must be constant at <top-level>, line 1, column 8: