• Connor Abbott's avatar
    nir/algebraic: Rewrite bit-size inference · 29a1450e
    Connor Abbott authored
    Before this commit, there were two copies of the algorithm: one in C,
    that we would use to figure out what bit-size to give the replacement
    expression, and one in Python, that emulated the C one and tried to
    prove that the C algorithm would never fail to correctly assign
    bit-sizes. That seemed pretty fragile, and likely to fall over if we
    make any changes. Furthermore, the C code was really just recomputing
    more-or-less the same thing as the Python code every time. Instead, we
    can just store the results of the Python algorithm in the C
    datastructure, and consult it to compute the bitsize of each value,
    moving the "brains" entirely into Python. Since the Python algorithm no
    longer has to match C, it's also a lot easier to change it to something
    more closely approximating an actual type-inference algorithm. The
    algorithm used is based on Hindley-Milner, although deliberately
    weakened a little. It's a few more lines than the old one, judging by
    the diffstat, but I think it's easier to verify that it's correct while
    being as general as possible.
    
    We could split this up into two changes, first making the C code use the
    results of the Python code and then rewriting the Python algorithm, but
    since the old algorithm never tracked which variable each equivalence
    class, it would mean we'd have to add some non-trivial code which would
    then get thrown away. I think it's better to see the final state all at
    once, although I could also try splitting it up.
    
    v2:
    - Replace instances of "== None" and "!= None" with "is None" and
    "is not None".
    - Rename first_src to first_unsized_src
    - Only merge the destination with the first unsized source, since the
    sources have already been merged.
    - Add a comment explaining what nir_search_value::bit_size now means.
    v3:
    - Fix one last instance to use "is not" instead of !=
    - Don't try to be so clever when choosing which error message to print
    based on whether we're in the search or replace expression.
    - Fix trailing whitespace.
    Reviewed-by: Jason Ekstrand's avatarJason Ekstrand <jason@jlekstrand.net>
    Reviewed-by: Dylan Baker's avatarDylan Baker <dylan@pnwbakers.com>
    29a1450e
Name
Last commit
Last update
bin Loading commit data...
build-support Loading commit data...
docs Loading commit data...
doxygen Loading commit data...
include Loading commit data...
m4 Loading commit data...
scons Loading commit data...
scripts Loading commit data...
src Loading commit data...
.dir-locals.el Loading commit data...
.editorconfig Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
Android.common.mk Loading commit data...
Android.mk Loading commit data...
CleanSpec.mk Loading commit data...
Makefile.am Loading commit data...
README.rst Loading commit data...
REVIEWERS Loading commit data...
SConstruct Loading commit data...
VERSION Loading commit data...
appveyor.yml Loading commit data...
autogen.sh Loading commit data...
common.py Loading commit data...
configure.ac Loading commit data...
install-gallium-links.mk Loading commit data...
install-lib-links.mk Loading commit data...
meson.build Loading commit data...
meson_options.txt Loading commit data...