Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: Manish Goregaokar <manish@mozilla.com>
Cc: gdb-patches@sourceware.org,  Tom Tromey <tom@tromey.com>
Subject: Re: [PATCH] Add support for untagged unions
Date: Mon, 31 Oct 2016 03:13:00 -0000	[thread overview]
Message-ID: <87shrdus79.fsf@tromey.com> (raw)
In-Reply-To: <CAFOnWk=gVjBMMNrR1m16Wri62ZgUNAS_7q+MJDk_QYxPjECezQ@mail.gmail.com>	(Manish Goregaokar's message of "Fri, 28 Oct 2016 18:02:12 -0700")

>>>>> "Manish" == Manish Goregaokar <manish@mozilla.com> writes:

Manish> Rust supports untagged unions (C unions) now (using the same
Manish> syntax as structs but with `union` instead of `struct` in the
Manish> declaration).  These are mainly used for FFI.

Thank you.

Manish> No tests because stable Rust doesn't have these yet. Let me know
Manish> if I should add them.

I think they're necessary but I want to understand the options.

Is it hard to determine if rustc supports unions?
Is there some flag that must be passed?

I suppose one idea would be to feature test rustc in the test suite,
then change the new tests to be unsupported if this fails.  And, if a
flag is needed, pass it -- but go back once the feature hits stable and
remove the flag?

I think the essentials of the patch are fine.

Manish>     * rust-lang.c (rust_union_is_untagged): Add function to
Manish>     check if a union is an untagged unioni
Manish>     * rust-lang.c (rust_val_print): Handle printing of untagged union values

Just the first entry needs the "* FILENAME" bit.

Manish> +/* Whether or not a TYPE_CODE_UNION value is an untagged union
Manish> +   as opposed to being a regular Rust enum.  */
Manish> +static bool
Manish> +rust_union_is_untagged(struct type *type) {

This has various style issues.

Thanks for using bool.

Manish> +     Since the field bit positions overlap in the debuginfo,
Manish> +     the code for printing a union is same as that for a struct,
Manish> +     the only difference is that the input type will have overlapping
Manish> +     fields.  */
Manish> +  if (rust_union_is_untagged (type))
Manish> +      goto struct_val;

I think it'd be better to turn the specific case's body into a helper
function.  I'd like to get rid of a lot of these gotos; and I also plan
to remove as many cleanups as possible from the rust code in gdb...

Manish> +  /* This code path is also used by unions.  */
Manish> +  if (TYPE_CODE (type) == TYPE_CODE_STRUCT)
Manish> +      fputs_filtered ("struct ", stream);
Manish> +  else
Manish> +    fputs_filtered ("union ", stream);
Manish> +
Manish>      if (TYPE_TAG_NAME (type) != NULL)

Indentation of that addition looks wrong.

Manish> +      /* Field access in structs and untagged unions works like C.  */
Manish>          *pos = pc;

Same here.

Tom


  parent reply	other threads:[~2016-10-31  3:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-29  1:02 Manish Goregaokar
2016-10-29  1:07 ` Manish Goregaokar
2016-10-31  3:13 ` Tom Tromey [this message]
2016-10-31  3:42   ` Manish Goregaokar
     [not found]     ` <CAFOnWk=Fe7UrrN1dLgWhzmnmhUzPbAQPfyXGLNqHnnej_gdciw@mail.gmail.com>
     [not found]       ` <87bmxy7r8y.fsf@tromey.com>
     [not found]         ` <CAFOnWkkUibsZKsqFrwGv1kpJ52mNiDYCEEpc5utO1=LLh6W+XQ@mail.gmail.com>
2016-11-03 21:33           ` Tom Tromey
2016-11-03 22:47             ` Manish Goregaokar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87shrdus79.fsf@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    --cc=manish@mozilla.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox