public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Merge #870
@ 2022-06-08 11:59 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 11:59 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:b21caeb3af4313016afeb94a91956e8fc4c2656d
commit b21caeb3af4313016afeb94a91956e8fc4c2656d
Merge: 03e56b51815 93554f3bce5
Author: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Date: Fri Jan 14 15:49:07 2022 +0000
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>
Diff:
gcc/rust/Make-lang.in | 4 +-
gcc/rust/ast/rust-item.h | 7 +-
gcc/rust/backend/rust-compile-base.h | 11 +-
gcc/rust/backend/rust-compile-context.h | 6 +-
gcc/rust/backend/rust-compile-expr.cc | 235 +++++++++-
gcc/rust/backend/rust-compile-expr.h | 81 +---
gcc/rust/backend/rust-compile-implitem.h | 4 +-
gcc/rust/backend/rust-compile-item.h | 89 +++-
gcc/rust/backend/rust-compile-pattern.cc | 33 +-
gcc/rust/backend/rust-compile-resolve-path.cc | 23 +-
gcc/rust/backend/rust-compile-stmt.h | 4 +-
gcc/rust/backend/rust-compile-type.cc | 14 +-
gcc/rust/backend/rust-compile-type.h | 5 +-
gcc/rust/backend/rust-compile.cc | 90 +++-
gcc/rust/backend/rust-constexpr.cc | 428 ++++++++++++++++++
.../rust-constexpr.h} | 39 +-
gcc/rust/hir/rust-ast-lower-base.h | 3 +
gcc/rust/hir/rust-ast-lower-item.h | 5 +-
gcc/rust/hir/rust-ast-lower.cc | 28 ++
gcc/rust/hir/tree/rust-hir-expr.h | 170 +++++--
gcc/rust/hir/tree/rust-hir-item.h | 6 +-
gcc/rust/hir/tree/rust-hir.h | 69 ++-
gcc/rust/rust-backend.h | 5 -
gcc/rust/rust-gcc.cc | 42 +-
gcc/rust/rust-session-manager.cc | 4 -
gcc/rust/typecheck/rust-hir-const-fold-base.h | 54 ---
gcc/rust/typecheck/rust-hir-const-fold.cc | 138 ------
gcc/rust/typecheck/rust-hir-const-fold.h | 499 ---------------------
gcc/rust/typecheck/rust-hir-type-check-enumitem.h | 20 +-
gcc/rust/typecheck/rust-hir-type-check-expr.h | 149 +++---
gcc/rust/typecheck/rust-hir-type-check-implitem.h | 3 -
gcc/rust/typecheck/rust-hir-type-check-stmt.h | 5 +-
gcc/rust/typecheck/rust-hir-type-check-toplevel.h | 3 -
gcc/rust/typecheck/rust-hir-type-check-type.cc | 23 +
gcc/rust/typecheck/rust-hir-type-check.cc | 23 -
gcc/rust/typecheck/rust-tyty-cast.h | 16 +-
gcc/rust/typecheck/rust-tyty-cmp.h | 7 -
gcc/rust/typecheck/rust-tyty-coercion.h | 16 +-
gcc/rust/typecheck/rust-tyty-rules.h | 16 +-
gcc/rust/typecheck/rust-tyty.cc | 15 +-
gcc/rust/typecheck/rust-tyty.h | 54 ++-
gcc/testsuite/rust/compile/arrays2.rs | 3 +-
gcc/testsuite/rust/execute/torture/const_fold1.rs | 13 +
gcc/testsuite/rust/execute/torture/const_fold2.rs | 16 +
44 files changed, 1350 insertions(+), 1128 deletions(-)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 11:59 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 11:59 [gcc/devel/rust/master] Merge #870 Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).