public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] Merge #834
@ 2022-06-08 11:56 Thomas Schwinge
  0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 11:56 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:768f926074a27a7b1a2179613eeeb8291648b8a7

commit 768f926074a27a7b1a2179613eeeb8291648b8a7
Merge: 3629645386a e0588300adc
Author: bors[bot] <26634292+bors[bot]@users.noreply.github.com>
Date:   Thu Dec 16 10:23:26 2021 +0000

    Merge #834
    
    834: Add enum code generation r=philberty a=philberty
    
    This adds a naieve first pass approach to enum type code generation. The
    original idea was to use GCC's QUAL_UNION_TYPE but I have ran into issues
    with the DECL_QUALIFIER as my understanding of how this works is incorrect.
    
    This takes an enum such as:
    
    ```rust
    enum AnEnum {
      A,
      B,
      C (char),
      D (x: i64, y: i64),
    }
    ```
    
    And turns this into one big union consisting of all fields as RECORD_TYPES.
    
    ```c
    union AnEnum {
      record A { RUST$ENUM$DISR };
      record B { RUST$ENUM$DISR };
      record C { RUST$ENUM$DISR, char };
      record D { RUST$ENUM$DISR, i64, i64};
    }
    ```
    
    see: https://github.com/bminor/binutils-gdb/blob/527b8861cd472385fa9160a91dd6d65a25c41987/gdb/dwarf2/read.c#L9010-L9241
    
    With the RUST$ENUM$DISR being the first field in all of the records this
    means the alignment allows for indirect memory access of the struct to
    use it as a qualifier field to figure out which variant is currently in
    use. The data-less varients use their generated discriminat value during
    type-checking the data variants use their HIR ID for their discriminant.
    
    This will likely get redone to get improved GDB integration/updated to use
    the QUAL_UNION_TYPE when we learn how to do this properly.
    
    Fixes #79
    
    
    Co-authored-by: Philip Herron <philip.herron@embecosm.com>

Diff:

 gcc/rust/backend/rust-compile-expr.cc         | 187 +++++++++++++++-----------
 gcc/rust/backend/rust-compile-expr.h          |  86 ++++++++++--
 gcc/rust/backend/rust-compile-resolve-path.cc |  49 ++++++-
 gcc/rust/backend/rust-compile-type.cc         | 166 ++++++++++++++++++++---
 gcc/rust/backend/rust-compile-type.h          |   2 +
 gcc/rust/backend/rust-compile.cc              |   4 +-
 gcc/rust/rust-backend.h                       |   4 +-
 gcc/rust/rust-gcc.cc                          | 111 +++++++++------
 gcc/rust/typecheck/rust-tyty.h                |   8 +-
 gcc/testsuite/rust/compile/torture/enum1.rs   |  13 ++
 10 files changed, 475 insertions(+), 155 deletions(-)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-06-08 11:56 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:56 [gcc/devel/rust/master] Merge #834 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).