From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: David Malcolm Newsgroups: gmane.emacs.bugs Subject: bug#25987: 25.2; support gcc fixit notes Date: Mon, 12 Oct 2020 18:27:29 -0400 Message-ID: <26f277bb345f10efe6340ac4074960905064fc97.camel@redhat.com> References: <87lgsj1jle.fsf@tromey.com> <1521218887.2913.237.camel@redhat.com> <83muz7pyde.fsf@gnu.org> <83o8lf9p68.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-n3E9E9o33IMfHcokYE/T" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="30327"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.36.5 (3.36.5-1.fc32) Cc: 25987@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Oct 13 00:28:11 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kS6Ic-0007mX-8a for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 13 Oct 2020 00:28:10 +0200 Original-Received: from localhost ([::1]:58792 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kS6Ib-0006N6-4G for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 12 Oct 2020 18:28:09 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:35114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kS6IU-0006Mr-1B for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2020 18:28:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60957) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kS6IT-00081I-Ol for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2020 18:28:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kS6IT-000817-Jy for bug-gnu-emacs@gnu.org; Mon, 12 Oct 2020 18:28:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: David Malcolm Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 12 Oct 2020 22:28:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 25987 X-GNU-PR-Package: emacs Original-Received: via spool by 25987-submit@debbugs.gnu.org id=B25987.160254166130791 (code B ref 25987); Mon, 12 Oct 2020 22:28:01 +0000 Original-Received: (at 25987) by debbugs.gnu.org; 12 Oct 2020 22:27:41 +0000 Original-Received: from localhost ([127.0.0.1]:44270 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kS6I8-00080Y-Qn for submit@debbugs.gnu.org; Mon, 12 Oct 2020 18:27:41 -0400 Original-Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:38344) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kS6I4-00080N-6e for 25987@debbugs.gnu.org; Mon, 12 Oct 2020 18:27:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602541656; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kv5M84xSoWNJu92zJFPbJ7C4dOnMchJdRfsA+3OjzGw=; b=YDhGwUucR28Vcs2DdhHwW6obDFiWDOu/gh6ajl6lYzc7687sxtqyKbZG2vQ5hT2TznIA21 kxE+aK9WrWPa2jVWdcMWzDkEBayY9OLlOUph60mBYvDvJ99RVxPepD70BUrJr6TmI/IJn9 xUDOLXtixrNUk26nlOA/pS3DTq8rBRg= Original-Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-11-EJO9qhY1Ph2WaERuUN-OcA-1; Mon, 12 Oct 2020 18:27:31 -0400 X-MC-Unique: EJO9qhY1Ph2WaERuUN-OcA-1 Original-Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A71C4185A0C4; Mon, 12 Oct 2020 22:27:30 +0000 (UTC) Original-Received: from ovpn-112-135.phx2.redhat.com (ovpn-112-135.phx2.redhat.com [10.3.112.135]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F6C510013DB; Mon, 12 Oct 2020 22:27:29 +0000 (UTC) In-Reply-To: <83o8lf9p68.fsf@gnu.org> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dmalcolm@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:190363 Archived-At: --=-n3E9E9o33IMfHcokYE/T Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit On Tue, 2020-10-06 at 21:37 +0300, Eli Zaretskii wrote: > > From: David Malcolm > > Cc: 25987@debbugs.gnu.org > > Date: Tue, 06 Oct 2020 14:17:55 -0400 > > > > In GCC 11 we've revamped the column number handling in how we emit > > diagnostics; see: > > > > https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555632.html > > > > GCC 11 diagnostics now (by default) should use actual column > > numbers, > > rather than byte counts. > > That's good news, thanks. > > > We haven't changed -fdiagnostics-parseable-fixits; it still emits > > its > > range information in terms of byte offsets (and e.g. Eclipse > > already > > consumes that option); this is bug-for-bug compatible with clang, I > > believe (which had that option first). > > So fixit hints will still count bytes? Or will GCC 11 emit such > hints even without -fdiagnostics-parseable-fixits on the command > line? > > > Note that characters != columns, or, at least, we have to be > > careful > > about what we mean. Consider the case of 🙂 aka SLIGHTLY SMILING > > FACE > > (U+1F642) which is a single unicode code point, but occupies two > > columns, with its UTF-8 encoding requiring four bytes. > > > > When I type it into an Emacs buffer, and look at the column number > > I > > see that Emacs appears to treat the character as occupying two > > columns. > > Is that the kind of column numbering you would want for machine- > > readable fix-it hints? > > Yes. Emacs computes the width of each character by using UCD, the > Unicode Character Database (specifically, the EastAsianWidth.txt file > that is part of the UCD). If GCC gets its column counts from a > similar DB, then it will match what Emacs does. > > > Similarly, the column numbering emitted by GCC 11 diagnostics is > > affected by tab characters as tab stops, which seems to reflect > > Emacs > > behavior as well. > > Yes. > > > I can add an additional option for fix-it hints that's similar to > > -fdiagnostics-parseable-fixits, but with a different output format > > (or > > to add an argument to that option, perhaps). > > If an option is needed for getting the hints, then a special option > which reports columns in hints will be appreciated, as it will make > the Emacs support for processing those hints 100% accurate and devoid > of encoding guesswork. > > > Before I do that, I wanted to check that it would be consumable by > > Emacs. What works for you? Would it help to send the proposed GCC > > patch to this bug address (or to the emacs-devel list?). > > I don't know how many people here build their own GCC, and thus could > try the patch, but if sending the patch is not too much trouble, > perhaps posting it on emacs-devel would be a good idea. If you do > that, please cite this bug report, so that people who try that could > respond here with their experience. > > > Alternatively, we already have a JSON output option (-fdiagnostics- > > format=json); perhaps something like that could be used? > > Emacs can parse JSON. What are the pros and cons of the JSON > alternative wrt to the text alternative? The existing "-fdiagnostics-format=json" GCC option replaces the existing diagnostic output with a big blob of JSON to stderr, all on one line. Although I implemented it, I now feel it to be rather half- baked. I like how -fdiagnostics-parseable-fixits adds extra lines of output, with a prefix that's ought to be easy to detect. BTW, does Emacs set anything in the environment that GCC could detect? > > Feature freeze for GCC 11 is about a month away; I'd love for Emacs > > to > > be able to consume GCC fix-it hints (and have GCC and Emacs fix my > > typos for me) > > Agreed; let's try to make that happen. I put together a test file showing various features to try to ensure that GCC and Emacs interoperate on this. I'm attaching it. This can also be seen on Compiler Explorer at: https://godbolt.org/z/zazejq which adds the existing -fdiagnostics-parseable-fixits -fdiagnostics-generate-patch options. Ideas for other test cases are most welcome. Does Emacs have an automated test suite that could test this feature? A long-postponed goal for me for GCC's testsuite is to ensure that fix- it hints apply and actually fix the problem (clang's testsuite has tests that verify this for clang's fix-it hints). Another complication to consider: the locations in a fix-it hint refer to the original source file, before any changes are made. If the user interface supports the user e.g. clicking on fix-it hints and selectively apply them one by one, then after each fix-it hint is applied, all locations after that point potentially need to be "fixed up" somehow, to reflect the changes to the buffer. GCC's own code implements this in gcc/edit-context.{c|h}, for implementing - fdiagnostics-generate-patch, which applies all fix-its "atomically" - but the use-case I thinking of involves clicking on fix-it hints one- by-one in the compilation buffer, perhaps replacing the fix-it output with an "Apply fix" button. (to cover this case I made sure the demo file contained examples of a fix-it hint that adds a line, and one that has multiple fix-it hints on the same line). Thoughts? Dave --=-n3E9E9o33IMfHcokYE/T Content-Disposition: attachment; filename="demo.c" Content-Type: text/x-csrc; name="demo.c"; charset="UTF-8" Content-Transfer-Encoding: base64 LyogQSBkdW1teSBpbmNsdWRlLCB0byBvZmZzZXQgdGhlIGZpeC1pdCBpbmNsdWRlIGluIHRlc3Rf MSBiZWxvdy4gICovCiNpbmNsdWRlIDxzdGRpby5oPgoKc3RydWN0IHZlcnQKewogIGludCBjb2xv cjs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