From: Joel Brobecker <brobecker@adacore.com>
To: Tom Tromey <tom@tromey.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA] Add inclusive range support for Rust
Date: Wed, 25 Apr 2018 16:52:00 -0000 [thread overview]
Message-ID: <20180425165205.cwkvthuotlpaq67z@adacore.com> (raw)
In-Reply-To: <20180329201609.13699-1-tom@tromey.com>
On Thu, Mar 29, 2018 at 02:16:09PM -0600, Tom Tromey wrote:
> Rust recently stabilized the inclusive range feature:
>
> https://github.com/rust-lang/rust/issues/28237
>
> An inclusive range is an expression like "..= EXPR" or "EXPR ..=
> EXPR". It is like an ordinary range, except the upper bound is
> inclusive, not exclusive.
>
> This patch adds support for this feature to gdb.
>
> Regression tested on x86-64 Fedora 26.
>
> Note that review is required because this patch touches some non-Rust
> code.
>
> 2018-03-29 Tom Tromey <tom@tromey.com>
>
> PR rust/22545:
> * rust-lang.c (rust_inclusive_range_type_p): New function.
> (rust_range): Handle inclusive ranges.
> (rust_compute_range): Likewise.
> * rust-exp.y (struct rust_op) <inclusive>: New field.
> (DOTDOTEQ): New constant.
> (range_expr): Add "..=" productions.
> (operator_tokens): Add "..=" token.
> (ast_range): Add "inclusive" parameter.
> (convert_ast_to_expression) <case OP_RANGE>: Handle inclusive
> ranges.
> * parse.c (operator_length_standard) <case OP_RANGE>: Handle new
> bounds values.
> * expression.h (enum range_type) <NONE_BOUND_DEFAULT_INCLUSIVE,
> LOW_BOUND_DEFAULT_INCLUSIVE>: New constants.
> * expprint.c (print_subexp_standard): Handle new bounds values.
> (dump_subexp_body_standard): Likewise.
I'm not sure I'm competent to review, but once I understand better
the existing enums for enum range_type, I think I'll be able to
officially approve.
A couple of comments below.
> @@ -1102,12 +1109,18 @@ dump_subexp_body_standard (struct expression *exp,
> case LOW_BOUND_DEFAULT:
> fputs_filtered ("Range '..EXP'", stream);
> break;
> + case LOW_BOUND_DEFAULT_INCLUSIVE:
> + fputs_filtered ("Range '..=EXP'", stream);
> + break;
> case HIGH_BOUND_DEFAULT:
> fputs_filtered ("Range 'EXP..'", stream);
> break;
> case NONE_BOUND_DEFAULT:
> fputs_filtered ("Range 'EXP..EXP'", stream);
> break;
> + case NONE_BOUND_DEFAULT_INCLUSIVE:
> + fputs_filtered ("Range 'EXP..=EXP'", stream);
> + break;
> default:
> fputs_filtered ("Invalid Range!", stream);
> break;
This is my opinion, so please feel free to disagree:
Using the rust-like syntax in the _INCLUSIVE cases ('=EXP') can be
a bit mysterious to someone not familiar with Rust. Or is it something
that's more widespread than I thought? If you agree, I'd like to
suggest we generate the range using the standard mathematical
notations instead, so it's language-agnostic and unequivocal.
We'd be changing it for all cases so that we always know whether
the bounds are inclusive or exclusive.
> diff --git a/gdb/expression.h b/gdb/expression.h
> index 7abd7f7503..86ee698aed 100644
> --- a/gdb/expression.h
> +++ b/gdb/expression.h
> @@ -150,15 +150,18 @@ extern void dump_prefix_expression (struct expression *, struct ui_file *);
>
> /* In an OP_RANGE expression, either bound could be empty, indicating
> that its value is by default that of the corresponding bound of the
> - array or string. So we have four sorts of subrange. This
> - enumeration type is to identify this. */
> -
> + array or string. Also, the upper end of the range can be exclusive
> + or inclusive. So we have six sorts of subrange. This enumeration
> + type is to identify this. */
> +
> enum range_type
> {
> BOTH_BOUND_DEFAULT, /* "(:)" */
> LOW_BOUND_DEFAULT, /* "(:high)" */
> HIGH_BOUND_DEFAULT, /* "(low:)" */
> - NONE_BOUND_DEFAULT /* "(low:high)" */
> + NONE_BOUND_DEFAULT, /* "(low:high)" */
> + NONE_BOUND_DEFAULT_INCLUSIVE, /* Rust "low..=high" */
> + LOW_BOUND_DEFAULT_INCLUSIVE, /* Rust "..=high" */
> };
Just a note to refer to my earlier email asking about the meaning
the previously existing enums (inclusive or exclusive), and perhaps
a suggestion to adjust the documentation above to make it unequivocal
by using the mathematical notation for each and everyone of them.
--
Joel
next prev parent reply other threads:[~2018-04-25 16:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-29 20:16 Tom Tromey
2018-04-17 19:48 ` Tom Tromey
2018-04-25 15:33 ` Tom Tromey
2018-04-25 16:04 ` Joel Brobecker
2018-04-25 16:27 ` Joel Brobecker
2018-04-26 19:51 ` Tom Tromey
2018-04-25 16:52 ` Joel Brobecker [this message]
2018-04-26 20:16 ` Tom Tromey
2018-04-27 19:13 ` Joel Brobecker
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=20180425165205.cwkvthuotlpaq67z@adacore.com \
--to=brobecker@adacore.com \
--cc=gdb-patches@sourceware.org \
--cc=tom@tromey.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