Skip to content

Restore Hex code paths without calling into Hex - #1269

Merged
ericmj merged 1 commit into
mainfrom
restore-hex-paths-in-converge
Oct 12, 2026
Merged

ericmj merged 1 commit into
mainfrom
restore-hex-paths-in-converge

Conversation

@ericmj

@ericmj ericmj commented Oct 12, 2026

Copy link
Copy Markdown
Member

Compiling on Elixir 1.15 and later prunes code paths, including the Hex archive's. #1118 restored them in Hex.RemoteConverger.converge/2 when Hex.Mix couldn't be loaded, but it called Hex.Stdlib.ensure_application!/1, which is in the same pruned archive and isn't loaded at that point. So mix do compile + deps.get still failed, with UndefinedFunctionError for Hex.Stdlib.ensure_application!/1 instead of the Hex.Mix error from #1109. This calls Mix.ensure_application!/1 directly. Elixir 1.15 added both the pruning and that function, so the call only runs where it exists.

I checked it with archives built from main and from this branch, in a project depending on jason, on Elixir 1.20.4 / OTP 29.1.1. mix do compile + deps.get --check-locked and mix do compile + deps.update jason raise with main and complete with this branch. There's no automated test because it needs an installed archive and a compile that prunes. Calling Mix.ensure_application!(:hex) in Hex's own test VM would load modules from whichever Hex archive is installed.

A failed resolution after compile still raises Protocol.UndefinedError, because the project's consolidated String.Chars has no impls for the vendored solver's structs. hexpm/hex_solver#60 fixes that and arrives with the next vendored hex_solver release.

The Code.ensure_loaded?(Hex.Mix) guard from #1118 stays. If Hex.Mix was loaded before compiling, for example in mix do deps.get + compile + deps.get, the paths aren't restored, and a Hex module that wasn't loaded yet would still fail to load.

Compiling prunes code paths, including the Hex archive's, so
`mix do compile + deps.get` couldn't load Hex modules. The fix for that
called Hex.Stdlib.ensure_application!/1 to restore the paths, but
Hex.Stdlib is in the pruned archive and wasn't loaded yet, so it raised
UndefinedFunctionError instead. Call Mix.ensure_application!/1
directly.
@ericmj
ericmj merged commit 4a58e9d into main Oct 12, 2026
22 checks passed
@ericmj
ericmj deleted the restore-hex-paths-in-converge branch October 12, 2026 22:50
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