Skip to content

Elixir code pruning is breaking a compile time conditional in Evision.Wx #335

Description

@vaddio-mjohnson

The module Evision.Wx has a compile time conditional check of Code.ensure_loaded?(:wx_object). If this returns true, we get the regular implementation of the module, and if it returns false, we get an implementation where all of the functions raise a RuntimeError with the message ":wx_object is not available, please ensure :wx_object was compiled with the application.".

Despite having Erlang/Elixir compiled with wxWidgets support, and :wx in the :extra_applications of my project, the Evision.Wx functions still raise this error. I believe this is happening because Elixir 1.15 added "code pruning", where unused dependencies are pruned at compile time to speed up compilation. Since wx is not a dependency of Evision, it is getting pruned, causing Code.ensure_loaded?(:wx_object) to always return false, whether or not there is wx support. This basically makes the Evision.Wx module entirely unusable in Elixir >= 1.15.

The only workaround I've found within my project is to set prune_code_paths: false in my mix project configuration. However, this solution is not ideal since the 1.15 changelog states that: "doing so may lead to runtime bugs that are only manifested inside a mix release."

I was able to solve this problem in the Evision library by adding {:wx, optional: true} to the list of dependencies in the Evision mix.exs file. I tried this solution on a whim, and was a bit surprised it actually worked. I wasn't aware you could include Erlang built-in applications in the dependency list. If this was the intended workaround, why wasn't it mentioned in the 1.15 changelog or anywhere in the Elixir docs?

For reference, I'm using Elixir 1.18 and Erlang 26 (compiled with wxWidgets support).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions