diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-01-14 15:49:07 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-14 15:49:07 +0000 |
commit | b21caeb3af4313016afeb94a91956e8fc4c2656d (patch) | |
tree | 03b1cac2b3442af423cd565b0168682e6d4541b3 /gcc/rust/util/rust-hir-map.h | |
parent | 03e56b5181506a4e6cdb9fe86c543a57840e54c3 (diff) | |
parent | 93554f3bce5bd42d8671559a774818767979cdae (diff) | |
download | gcc-b21caeb3af4313016afeb94a91956e8fc4c2656d.zip gcc-b21caeb3af4313016afeb94a91956e8fc4c2656d.tar.gz gcc-b21caeb3af4313016afeb94a91956e8fc4c2656d.tar.bz2 |
Merge #870
870: Add constant folding to const functions r=philberty a=philberty
In Rust the ArrayType has a constant capacity constraint, which means it
allows for bounds checking at compile time as no variable-length arrays are
allowed. In order to typecheck this case we had a constant folding pass as
part of the type checking system which generated gcc tree's for the IR
and enforced the constant checking along the way.
GCC with optimizations turned on is capable of constant folding/propogating
the compilation unit fully, but we need a method that works regardless of
middlle-end optimizations to fold constant expressions at the front-end,
turns out the CPP front-end already does this via its constexpr
mechanism to ensure that these _do_ fold correctly. Another major reason
to do this change is that the original const fold pass was a striped down
copy of what the backend is _already_ doing which is creating a duplication
of the code generation pass. With this all unified into the code generation
pass all we need to do is port over gcc/cp/constexpr.c to enforce the const
rules fully but at the GCC tree level not at the typed HIR level.
Now that we have unified the pass when we hit a const function we can
simply emit a normal GCC function and outside of const expressions GCC
will simply emit a normal CallExpr and depending on optimization level
fully optimize this. If we are in a ConstDecl we will follow the
rust-constexpr.cc and fold the values or error_mark_node with an apropriate
error. By reusing the CPP constexpr code we _know_ it works so reusing it
as much as possible is a good idea in general for this front-end.
Fixes #799
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/util/rust-hir-map.h')
0 files changed, 0 insertions, 0 deletions