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] Print void types correctly in Rust
Date: Mon, 27 Jun 2016 16:15:00 -0000 [thread overview]
Message-ID: <8760suk3qg.fsf@tromey.com> (raw)
In-Reply-To: <CAFOnWk=UXb+EkAB6P=a2T4xNn_k5FveoVKv7ZsGN7-yUh7o8_w@mail.gmail.com> (Manish Goregaokar's message of "Mon, 27 Jun 2016 21:22:33 +0530")
>>>>> "Manish" == Manish Goregaokar <manish@mozilla.com> writes:
Manish> Rust prefers to not specify the return type of a function when it is unit
Manish> (`()`). The type is also referred to as "void" in debuginfo but not in actual
Manish> usage, so we should never be printing "void" when the language is Rust.
Thanks for finding and fixing this.
The patch looks good overall but I have a few questions and some nits.
Manish> * rust-lang.c: Print unit types as "()"
Manish> * rust-lang.c: Omit return type for functions returning unit
A ChangeLog entry is supposed to refer to function and variable names,
so more like:
* rust-lang.c (rust_decorations): Spell "void" as "()".
(rust_print_type): Likewise.
...
Manish> + /* Rust calls the unit type "void" in its debuginfo,
Manish> + but we don't want to print it as that. */
Manish> + if (TYPE_CODE (type) == TYPE_CODE_VOID)
Manish> + fputs_filtered ("()", stream);
Manish> + else
Manish> + fputs_filtered (TYPE_NAME (type), stream);
This is fine but there is another case in rust_val_print:
case TYPE_CODE_INT:
/* Recognize the unit type. */
if (TYPE_UNSIGNED (type) && TYPE_LENGTH (type) == 0
&& TYPE_NAME (type) != NULL && strcmp (TYPE_NAME (type), "()") == 0)
{
fputs_filtered ("()", stream);
break;
}
goto generic_print;
... I wonder if that is something that changed after 1.8, or if it's the
case that the unit type can be represented in multiple ways. (Or maybe
this only handles the unit type constructed by rust_language_arch_info?)
Anyway I wonder if a case like this is needed in rust_print_type, or if
the one in rust_val_print can be removed or changed.
Manish> + if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
Manish> + {
Manish> + fputs_filtered (" -> ", stream);
Manish> + rust_print_type (TYPE_TARGET_TYPE (type), "", stream, -1, 0, flags);
This should be formatted like:
+ if (TYPE_CODE (TYPE_TARGET_TYPE (type)) != TYPE_CODE_VOID)
+ {
+ fputs_filtered (" -> ", stream);
+ rust_print_type (TYPE_TARGET_TYPE (type), "", stream, -1, 0, flags);
Manish> +// Empty function, should not have "void"
Manish> +// or "()" in its return type
Manish> +fn empty() {
I'm curious what happens if it does say "-> ()"?
Tom
next prev parent reply other threads:[~2016-06-27 16:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-27 15:52 Manish Goregaokar
2016-06-27 16:15 ` Tom Tromey [this message]
2016-06-27 16:25 ` Manish Goregaokar
2016-06-27 16:35 ` Tom Tromey
2016-06-27 16:26 ` Tom Tromey
2016-06-27 16:53 ` 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=8760suk3qg.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