Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix decompilation of Kernel that causes syntax highlighting crashes #1877

Merged
merged 8 commits into from
Jan 15, 2021

Conversation

KronicDeth
Copy link
Owner

Fixes #1868

Changelog

Bug Fixes

  • Fix syntax highlighting stopping due to decompiling of Kernel failing caused by bugs introduced in Documentation Provider improvements #1834.
    Syntax highlighting could fail part way through a file when Kernel needed to be decompiled to resolve parts of the syntax. This would lead to the file to be colored above a certain point, but then the default gray after that point.

    • Connect compiled stubs to decompiled source by name/arity.
      Previously, when the decompiler didn't use the Docs, it was guaranteed that the PsiCompiled stubs would correlate, in-order, with the decompiled source call definitions, and so mirrors could be set by matching up the list of them in order. Since the Docs doesn't have to correspond to and doesn't correspond to the binary precisely for some BEAMs, most importantly, Elixir.Kernel.beam, the PsiCompiled stub and decompiled source is now matched by name and arity. This means some mirrors are missed, but no errors are produced.
    • Allow decompile source to map to entire arity range
      Since the decompile source from Docs can have default arguments the call definition clauses can have an arity range and not just a fixed arity, so all arities in the range need to be mappable to PsiCompiled functions.
    • Use correct macro for signature from Docs.
      Ensures that defmacro is used for macros instead of hard-coding def as in Documentation Provider improvements #1834.
    • Use ~S""" for docs from Docs chunk.
      The docs from the Docs chunk may contain interpolation in the code samples or #{ in regex examples, but these should not be treated as an interpolation start as the Docs format does not support interpolation. Anything that looks like interpolation in the docs text was actually escaped in the original docs, so also escape it here by using S""", which turns off interpolation.
    • Log an error if Code function can't be matched to decompiled source.
      Unlike the old InvalidMirrorException, this won't be an exception and the binary <-> decompile will still work for the other functions/macros in the file, so it will be a more graceful degradation.

Previously, when the decompiler didn't use the Docs chunk, it was guaranteed that the PsiCompiled stubs would correlate, in-order, with the decompiled source call definitions, and so mirrors could be set by matching up the list of them in order.  Since the Docs doesn't have to correspond to and doesn't correspond to the binary precisely for some BEAMs, most importantly, `Elixir.Kernel.beam`, the PsiCompiled stub and decompiled source is now matched by name and arity.   This means some mirrors are missed, but no errors are produced.
Since the decompile source from Docs can have default arguments the call definition clauses can have an arity range and not just a fixed arity, so all arities in the range need to be mappable to PsiCompiled functions.
Ensures that defmacro is used for macros instead of hard-coding `def` as before.
@KronicDeth KronicDeth added this to the 11.9.1 milestone Jan 15, 2021
@KronicDeth KronicDeth self-assigned this Jan 15, 2021
KronicDeth added a commit that referenced this pull request Jan 15, 2021
The docs from the docs chunk may contain interpolation in the code samples or `#{` in regex examples, but these should not be treated as an interpolation start as the docs format does not support interpolation.  Anything that looks like interpolation in the docs text was actually escaped in the original docs, so also escape it here by using `S"""`, which turns off interpolation.
Unlike the old `InvalidMirrorException`, this won't be an exception and the binary<->decompile will still work for the other functions/macros in the file, so it will be a more graceful degradation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
1 participant