elixir-lang/elixir

Crash in protocol consolidation on current main

Closed this issue · 2 comments

Elixir and Erlang/OTP versions

Erlang/OTP 26 [erts-14.2.5.4] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:1] [jit]

Elixir 1.19.0-dev (8e4d2cd) (compiled with Erlang/OTP 26)

Operating system

any

Current behavior

Reproducible on elixir_sense branch elixir-lsp/elixir_sense#299

** (EXIT from #PID<0.98.0>) an exception was raised:
    ** (MatchError) no match of right hand side value: %{attributes: [dialyzer: {:nowarn_function, [__protocol__: 1, impl_for: 1, impl_for!: 1]}, __protocol__: [fallback_to_any: false]], line: 3, module: Hex.Solver.Constraint, file: "/hex/lib/hex/solver/constraint.ex", deprecated: [], unreachable: [], struct: nil, after_verify: [], defines_behaviour: true, definitions: [{{:union, 2}, :def, [line: 13, context: Protocol], [{[line: 13, context: Protocol], [{:term, [version: 0, line: 13, counter: {Hex.Solver.Constraint, 62}], Protocol}, {:arg2, [version: 1, line: 13, counter: {Hex.Solver.Constraint, 62}], Protocol}], [], {{:., [line: 13], [{:impl_for!, [line: 13], [{:term, [version: 0, line: 13, counter: {Hex.Solver.Constraint, 62}], Protocol}]}, :union]}, [line: 13], [{:term, [version: 0, line: 13, counter: {Hex.Solver.Constraint, 62}], Protocol}, {:arg2, [version: 1, line: 13, counter: {Hex.Solver.Constraint, 62}], Protocol}]}}]}, {{:struct_impl_for, 1}, :defp, [line: 3, context: Protocol], [{[line: 3, context: Protocol], [{:struct, [version: 0, line: 3, context: Protocol, imports: [{1, Kernel}, {2, Kernel}]], Protocol}], [], {:=, [line: 3], [{:target, [version: 2, line: 3], Protocol}, {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [{{:., [line: 3], [Module, :concat]}, [line: 3], [Hex.Solver.Constraint, {:struct, [version: 0, line: 3, context: Protocol, imports: [{1, Kernel}, {2, Kernel}]], Protocol}]}]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}]}}]}, {{:intersect, 2}, :def, [line: 12, context: Protocol], [{[line: 12, context: Protocol], [{:term, [version: 0, line: 12, counter: {Hex.Solver.Constraint, 54}], Protocol}, {:arg2, [version: 1, line: 12, counter: {Hex.Solver.Constraint, 54}], Protocol}], [], {{:., [line: 12], [{:impl_for!, [line: 12], [{:term, [version: 0, line: 12, counter: {Hex.Solver.Constraint, 54}], Protocol}]}, :intersect]}, [line: 12], [{:term, [version: 0, line: 12, counter: {Hex.Solver.Constraint, 54}], Protocol}, {:arg2, [version: 1, line: 12, counter: {Hex.Solver.Constraint, 54}], Protocol}]}}]}, {{:impl_for!, 1}, :def, [line: 3, context: Protocol], [{[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [], {:case, [line: 3], [{:impl_for, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}, [do: [{:->, [line: 3], [[{:when, [line: 3], [{:x, [version: 1, line: 3, counter: {Hex.Solver.Constraint, 116}], Kernel}, {{:., [line: 3], [:erlang, :orelse]}, [line: 3], [{{:., [line: 3], [:erlang, :"=:="]}, [line: 3], [{:x, [...], ...}, false]}, {{:., [line: 3], [:erlang, ...]}, [line: 3], [{:x, ...}, nil]}]}]}], {{:., [line: 3], [:erlang, :error]}, [line: 3], [{{:., [line: 3], [Protocol.UndefinedError, :exception]}, [line: 3], [[protocol: Hex.Solver.Constraint, value: {:data, [version: 0, line: 3], Protocol}]]}]}]}, {:->, [line: 3], [[{:x, [version: 2, line: 3, counter: {Hex.Solver.Constraint, 116}], Kernel}], {:x, [version: 2, line: 3, counter: {Hex.Solver.Constraint, 116}], Kernel}]}]]]}}]}, {{:impl_for, 1}, :def, [line: 3, context: Protocol], [{[line: 3, context: Protocol], [{:%, [line: 3], [{:struct, [version: 0, line: 3, context: Protocol, imports: [{1, Kernel}, {2, Kernel}]], Protocol}, {:%{}, [line: 3], []}]}], [], {:struct_impl_for, [line: 3], [{:struct, [version: 0, line: 3, context: Protocol, imports: [{1, Kernel}, {2, Kernel}]], Protocol}]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_tuple]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.Tuple]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_atom]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.Atom]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_list]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.List]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_map]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.Map]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_bitstring]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.BitString]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_integer]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.Integer]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_float]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.Float]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_function]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.Function]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_pid]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.PID]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_port]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.Port]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, line: 3], Protocol}], {:module, [version: 1, line: 3], Protocol}]}, {:->, [line: 3], [[error: {:_, [line: 3], Protocol}], nil]}]]]}}, {[line: 3, context: Protocol], [{:data, [version: 0, line: 3], Protocol}], [{{:., [line: 3], [:erlang, :is_reference]}, [line: 3], [{:data, [version: 0, line: 3], Protocol}]}], {:case, [line: 3], [{{:., [line: 3], [Code, :ensure_compiled]}, [line: 3], [Hex.Solver.Constraint.Reference]}, [do: [{:->, [line: 3], [[module: {:module, [version: 1, ...], Protocol}], {:module, [version: 1, ...], Protocol}]}, {:->, [line: 3], [[error: {:_, [...], ...}], nil]}]]]}}, {[line: 3, context: Protocol], [{:_, [line: 3], Protocol}], [], nil}]}, {{:empty?, 1}, :def, [line: 7, context: Protocol], [{[line: 7, context: Protocol], [{:term, [version: 0, line: 7, counter: {Hex.Solver.Constraint, 14}], Protocol}], [], {{:., [line: 7], [{:impl_for!, [line: 7], [{:term, [version: 0, line: 7, counter: {Hex.Solver.Constraint, 14}], Protocol}]}, :empty?]}, [line: 7], [{:term, [version: 0, line: 7, counter: {Hex.Solver.Constraint, 14}], Protocol}]}}]}, {{:difference, 2}, :def, [line: 11, context: Protocol], [{[line: 11, context: Protocol], [{:term, [version: 0, line: 11, counter: {Hex.Solver.Constraint, 46}], Protocol}, {:arg2, [version: 1, line: 11, counter: {Hex.Solver.Constraint, 46}], Protocol}], [], {{:., [line: 11], [{:impl_for!, [line: 11], [{:term, [version: 0, line: 11, counter: {Hex.Solver.Constraint, 46}], Protocol}]}, :difference]}, [line: 11], [{:term, [version: 0, line: 11, counter: {Hex.Solver.Constraint, 46}], Protocol}, {:arg2, [version: 1, line: 11, counter: {Hex.Solver.Constraint, 46}], Protocol}]}}]}, {{:compare, 2}, :def, [line: 14, context: Protocol], [{[line: 14, context: Protocol], [{:term, [version: 0, line: 14, counter: {Hex.Solver.Constraint, 70}], Protocol}, {:arg2, [version: 1, line: 14, counter: {Hex.Solver.Constraint, 70}], Protocol}], [], {{:., [line: 14], [{:impl_for!, [line: 14], [{:term, [version: 0, line: 14, counter: {Hex.Solver.Constraint, 70}], Protocol}]}, :compare]}, [line: 14], [{:term, [version: 0, line: 14, counter: {Hex.Solver.Constraint, 70}], Protocol}, {:arg2, [version: 1, line: 14, counter: {Hex.Solver.Constraint, 70}], Protocol}]}}]}, {{:any?, 1}, :def, [line: 6, context: Protocol], [{[line: 6, context: Protocol], [{:term, [version: 0, line: 6, counter: {Hex.Solver.Constraint, 6}], Protocol}], [], {{:., [line: 6], [{:impl_for!, [line: 6], [{:term, [version: 0, line: 6, counter: {Hex.Solver.Constraint, 6}], Protocol}]}, :any?]}, [line: 6], [{:term, [version: 0, line: 6, counter: {Hex.Solver.Constraint, 6}], Protocol}]}}]}, {{:allows_any?, 2}, :def, [line: 9, context: Protocol], [{[line: 9, context: Protocol], [{:term, [version: 0, line: 9, counter: {Hex.Solver.Constraint, 30}], Protocol}, {:arg2, [version: 1, line: 9, counter: {Hex.Solver.Constraint, 30}], Protocol}], [], {{:., [line: 9], [{:impl_for!, [line: 9], [{:term, [version: 0, line: 9, counter: {Hex.Solver.Constraint, 30}], Protocol}]}, :allows_any?]}, [line: 9], [{:term, [version: 0, line: 9, counter: {Hex.Solver.Constraint, 30}], Protocol}, {:arg2, [version: 1, line: 9, counter: {Hex.Solver.Constraint, 30}], Protocol}]}}]}, {{:allows_all?, 2}, :def, [line: 10, context: Protocol], [{[line: 10, context: Protocol], [{:term, [version: 0, line: 10, counter: {Hex.Solver.Constraint, 38}], Protocol}, {:arg2, [version: 1, line: 10, counter: {Hex.Solver.Constraint, 38}], Protocol}], [], {{:., [line: 10], [{:impl_for!, [line: 10], [{:term, [version: 0, line: 10, counter: {Hex.Solver.Constraint, 38}], Protocol}]}, :allows_all?]}, [line: 10], [{:term, [version: 0, line: 10, counter: {Hex.Solver.Constraint, 38}], Protocol}, {:arg2, [version: 1, line: 10, counter: {Hex.Solver.Constraint, 38}], Protocol}]}}]}, {{:allows?, 2}, :def, [line: 8, context: Protocol], [{[line: 8, context: Protocol], [{:term, [version: 0, line: 8, counter: {Hex.Solver.Constraint, 22}], Protocol}, {:arg2, [version: 1, line: 8, counter: {Hex.Solver.Constraint, 22}], Protocol}], [], {{:., [line: 8], [{:impl_for!, [line: 8], [{:term, [version: 0, line: 8, counter: {Hex.Solver.Constraint, 22}], Protocol}]}, :allows?]}, [line: 8], [{:term, [version: 0, line: 8, counter: {Hex.Solver.Constraint, 22}], Protocol}, {:arg2, [version: 1, line: 8, counter: {Hex.Solver.Constraint, 22}], Protocol}]}}]}, {{:__protocol__, 1}, :def, [line: 3, context: Protocol], [{[line: 3, context: Protocol], [:module], [], Hex.Solver.Constraint}, {[line: 3, context: Protocol], [:functions], [], [allows?: 2, allows_all?: 2, allows_any?: 2, any?: 1, compare: 2, difference: 2, empty?: 1, intersect: 2, union: 2]}, {[line: 3, context: Protocol], [:consolidated?], [], false}, {[line: 3, context: Protocol], [:impls], [], :not_consolidated}]}], impls: [], compile_opts: [:debug_info, {:inline, [struct_impl_for: 1]}], relative_file: "lib/hex/solver/constraint.ex", uses_behaviours: []}
        (elixir 1.19.0-dev) lib/protocol.ex:576: Protocol.beam_protocol/1
        (elixir 1.19.0-dev) lib/protocol.ex:563: Protocol.consolidate/2
        (mix 1.19.0-dev) lib/mix/compilers/protocol.ex:153: Mix.Compilers.Protocol.consolidate_each/4
        (elixir 1.19.0-dev) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
        (elixir 1.19.0-dev) lib/task/supervised.ex:36: Task.Supervised.reply/4

Expected behavior

no crash

Reinstalling hex does not fix the issue

This is because of prune_code_paths being false, which means precompiled Hex entries are consolidated too.