From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124162 invoked by alias); 12 Jul 2016 00:53:59 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 123917 invoked by uid 89); 12 Jul 2016 00:53:59 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 spammy=Box, beta X-HELO: mail-wm0-f47.google.com Received: from mail-wm0-f47.google.com (HELO mail-wm0-f47.google.com) (74.125.82.47) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 12 Jul 2016 00:53:48 +0000 Received: by mail-wm0-f47.google.com with SMTP id o80so4069823wme.1 for ; Mon, 11 Jul 2016 17:53:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=AtD/x76bAfQs7xCB8nNs9dIjD2lzyKHy7JugNSJ7zfc=; b=Aargrqe8YTC7mGXZ7FiIMZmoDvvPEkqRjq2ouF6AkVFSx8uY3EB3Ho8zuTQz5CznOK oKu7w6N/QCifRed38q/vnP+lW7tQr3raoBXJAOuav9brY6OtPqbtUN8n0XODBR9OA+4y p2fdMAmlhi3pduS++f+/ma2Rm2aoWIfshTxAwktP4aZogWdrx7pm2lGmQgKpFXjaFy4X xHI2zlpAO8aYPSYcdVaAyqMFBPU5ztdsTgSjuygSVCJJozlUBkzJRZvSGQBIxOBiHVjn +Zazxg7bTYgsFffKOaJniECbA/aM4LgXCdicX7gxsh6gFZkkY0yEyta2it6Zc9aeNtb3 C+ng== X-Gm-Message-State: ALyK8tIgXIxccygjOFqbWpd/M2RejM5KtYowGm/D4RH5ydzp3NbXthxi9yu8jyr33quoIGfOl9HTH8+QnyvDqVJ5 X-Received: by 10.194.87.202 with SMTP id ba10mr2057898wjb.18.1468284825845; Mon, 11 Jul 2016 17:53:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.28.36.215 with HTTP; Mon, 11 Jul 2016 17:53:26 -0700 (PDT) In-Reply-To: <1468271438-5389-1-git-send-email-tom@tromey.com> References: <1468271438-5389-1-git-send-email-tom@tromey.com> From: Manish Goregaokar Date: Tue, 12 Jul 2016 00:53:00 -0000 Message-ID: Subject: Re: [FYI] Allow empty struct expressions in Rust To: Tom Tromey Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2016-07/txt/msg00124.txt.bz2 This lgtm. I don't think we should bother trying to differentiate between Unit, Unit{}, and Unit(). -Manish On Tue, Jul 12, 2016 at 2:40 AM, Tom Tromey wrote: > I learned recently that empty struct expressions, like "X{}", have been > promoted from experimental to stable in Rust. This patch changes the > Rust expression parser to allow this case. > > New test case included. > Built and regtested on x86-64 Fedora 23, using Rust 1.11 beta. > > I plan to check this in after a reasonable interval. > > 2016-07-11 Tom Tromey > > * rust-lang.c (rust_tuple_struct_type_p): Return false for empty > structs. > * rust-exp.y (struct_expr_list): Allow empty elements. > > 2016-07-11 Tom Tromey > > * gdb.rust/simple.rs (main): Use empty struct expression. > * gdb.rust/simple.exp: Add tests for empty struct expression. > --- > gdb/ChangeLog | 6 ++++++ > gdb/rust-exp.y | 10 +++++++--- > gdb/rust-lang.c | 5 ++++- > gdb/testsuite/ChangeLog | 5 +++++ > gdb/testsuite/gdb.rust/simple.exp | 3 +++ > gdb/testsuite/gdb.rust/simple.rs | 1 + > 6 files changed, 26 insertions(+), 4 deletions(-) > > diff --git a/gdb/ChangeLog b/gdb/ChangeLog > index 92c1337..dd678f5 100644 > --- a/gdb/ChangeLog > +++ b/gdb/ChangeLog > @@ -1,3 +1,9 @@ > +2016-07-11 Tom Tromey > + > + * rust-lang.c (rust_tuple_struct_type_p): Return false for empty > + structs. > + * rust-exp.y (struct_expr_list): Allow empty elements. > + > 2016-07-07 Walfred Tedeschi > > * cp-namespace.c (cp_lookup_bare_symbol): Initialize > diff --git a/gdb/rust-exp.y b/gdb/rust-exp.y > index aeb6058..443c356 100644 > --- a/gdb/rust-exp.y > +++ b/gdb/rust-exp.y > @@ -428,10 +428,14 @@ struct_expr_tail: > } > ; > > -/* S{} is documented as valid but seems to be an unstable feature, so > - it is left out here. */ > struct_expr_list: > - struct_expr_tail > + /* %empty */ > + { > + VEC (set_field) **result > + = OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *); > + $$ = result; > + } > +| struct_expr_tail > { > VEC (set_field) **result > = OBSTACK_ZALLOC (&work_obstack, VEC (set_field) *); > diff --git a/gdb/rust-lang.c b/gdb/rust-lang.c > index 17b20c6..6e317fb 100644 > --- a/gdb/rust-lang.c > +++ b/gdb/rust-lang.c > @@ -294,7 +294,10 @@ rust_underscore_fields (struct type *type, int offset) > int > rust_tuple_struct_type_p (struct type *type) > { > - return rust_underscore_fields (type, 0); > + /* This is just an approximation until DWARF can represent Rust more > + precisely. We exclude zero-length structs because they may not > + be tuple structs, and there's no way to tell. */ > + return TYPE_NFIELDS (type) > 0 && rust_underscore_fields (type, 0); > } > > /* Return true if a variant TYPE is a tuple variant, false otherwise. */ > diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog > index b6f21d7..2eba208 100644 > --- a/gdb/testsuite/ChangeLog > +++ b/gdb/testsuite/ChangeLog > @@ -1,3 +1,8 @@ > +2016-07-11 Tom Tromey > + > + * gdb.rust/simple.rs (main): Use empty struct expression. > + * gdb.rust/simple.exp: Add tests for empty struct expression. > + > 2016-07-07 Walfred Tedeschi > > * gdb.fortran/derived-types.exp (result_line, result_line_2): > diff --git a/gdb/testsuite/gdb.rust/simple.exp b/gdb/testsuite/gdb.rust/simple.exp > index 32b3785..5e00b03 100644 > --- a/gdb/testsuite/gdb.rust/simple.exp > +++ b/gdb/testsuite/gdb.rust/simple.exp > @@ -55,7 +55,10 @@ gdb_test "print *(&c as *mut i32)" " = 0" > > gdb_test "print j" " = simple::Unit" > gdb_test "ptype j" " = struct simple::Unit" > +gdb_test "print j2" " = simple::Unit" > +gdb_test "ptype j2" " = struct simple::Unit" > gdb_test "print simple::Unit" " = simple::Unit" > +gdb_test "print simple::Unit{}" " = simple::Unit" > > gdb_test "print g" " = \\(u8 \\(\\*\\)\\\[6\\\]\\) $hex b\"hi bob\"" > gdb_test "ptype g" " = u8 \\(\\*\\)\\\[6\\\]" > diff --git a/gdb/testsuite/gdb.rust/simple.rs b/gdb/testsuite/gdb.rust/simple.rs > index 4980826..eeff3d7 100644 > --- a/gdb/testsuite/gdb.rust/simple.rs > +++ b/gdb/testsuite/gdb.rust/simple.rs > @@ -81,6 +81,7 @@ fn main () { > let i = ["whatever"; 8]; > > let j = Unit; > + let j2 = Unit{}; > > let k = SpaceSaver::Nothing; > let l = SpaceSaver::Thebox(9, Box::new(1729)); > -- > 2.5.5 >