[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Xen Coding style and clang-format


  • To: "jbeulich@xxxxxxxx" <jbeulich@xxxxxxxx>, "George.Dunlap@xxxxxxxxxx" <George.Dunlap@xxxxxxxxxx>
  • From: Anastasiia Lukianenko <Anastasiia_Lukianenko@xxxxxxxx>
  • Date: Fri, 16 Oct 2020 09:42:39 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qd9ee9EFA7w7Qmj4sWQdYGIWRmp9LafewTNB9lkRU/A=; b=GCRWDYNOeQA7+NSEQb2Z1ch+meKl0lZOoU7GtauTvI8Qcf+Aj5r16VkBbZ/sIvUFM2W2ie+RHbVfEjTrZzRN05l3zHy5ICj5U7IXuouFqV1FYrLrvrrQ4+g32H/aiAaiVlJXkihceRZHER8bPG2VZP5jPeEZAyRweaJNPoJGUuJQ+fzfRk4dCSl53KsK5Znvo2i6amNzL/9ZCpTT+Th27fUfvYgSLJ6t05OSuXYu2itAO2RiouNeoqQ2IEqT1i1Ii3rJ8e1+wTSPKqlcZcY506wrCobNxh/jfdMx5lple3yposCykXDmdggtdOeqG9cWtrLr9b0m2dcJwMsQuhZpnA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=acRhFdRKanqCUF+cwpVzwBU+TYb8n5QOngg83+7K9hd4FSIsxsGp9M5itoBZJ9XBo1+ehRqDGwDf1Q/hoOtMsRmLje2dSjpjGJwAc2JJldVyhB8sj5gDIftb+oYHdAr9pn1cebGWkb6syL4vq+tyLgmDi/cwqWLUSPb7lMMcf4E3o+4BKijCs1LcwWS0lZOhVKJxZtyjeYdxMF35ItT7ax3qmtLmFHVB1kCQbqQu4qoY4MMzoDPPBb/aqZ1cQm9XEieMHOmaCSFYXb7V9wOoFb6vxRYpubqTKS/VGPxDyQNVP95aRLLfIJq7kEvb4siMwrxVz0a3DCXUlGziaCi91w==
  • Authentication-results: suse.com; dkim=none (message not signed) header.d=none;suse.com; dmarc=none action=none header.from=epam.com;
  • Cc: Artem Mygaiev <Artem_Mygaiev@xxxxxxxx>, "vicooodin@xxxxxxxxx" <vicooodin@xxxxxxxxx>, "julien@xxxxxxx" <julien@xxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "committers@xxxxxxxxxxxxxx" <committers@xxxxxxxxxxxxxx>, "viktor.mitin.19@xxxxxxxxx" <viktor.mitin.19@xxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Fri, 16 Oct 2020 09:42:47 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHWlwq4nKYEhMN38U+xmvwRsutq+amA8joAgAAHUgCAAXyKAIAAENkAgAlxpgCACF7sgIABM44AgASIOQA=
  • Thread-topic: Xen Coding style and clang-format

Hi all,

On Tue, 2020-10-13 at 14:30 +0200, Jan Beulich wrote:
> On 12.10.2020 20:09, George Dunlap wrote:
> > > On Oct 7, 2020, at 11:19 AM, Anastasiia Lukianenko <
> > > Anastasiia_Lukianenko@xxxxxxxx> wrote:
> > > So I want to know if the community is ready to add new formatting
> > > options and edit old ones. Below I will give examples of what
> > > corrections the checker is currently making (the first variant in
> > > each
> > > case is existing code and the second variant is formatted by
> > > checker).
> > > If they fit the standards, then I can document them in the coding
> > > style. If not, then I try to configure the checker. But the idea
> > > is
> > > that we need to choose one option that will be considered
> > > correct.
> > > 1) Function prototype when the string length is longer than the
> > > allowed
> > > -static int __init
> > > -acpi_parse_gic_cpu_interface(struct acpi_subtable_header
> > > *header,
> > > -                             const unsigned long end)
> > > +static int __init acpi_parse_gic_cpu_interface(
> > > +    struct acpi_subtable_header *header, const unsigned long
> > > end)
> > 
> > Jan already commented on this one; is there any way to tell the
> > checker to ignore  this discrepancy?
> > 
> > If not, I think we should just choose one; I’d go with the latter.

If it turns out to make the checker more flexible, then I will try to
add both options as correct.

> > 
> > > 2) Wrapping an operation to a new line when the string length is
> > > longer
> > > than the allowed
> > > -    status = acpi_get_table(ACPI_SIG_SPCR, 0,
> > > -                            (struct acpi_table_header **)&spcr);
> > > +    status =
> > > +        acpi_get_table(ACPI_SIG_SPCR, 0, (struct
> > > acpi_table_header
> > > **)&spcr);
> > 
> > Personally I prefer the first version.
> 
> Same here.

Until I found a way to save the first option, I think this case may
remain in the opinion of the author.

> 
> > > 3) Space after brackets
> > > -    return ((char *) base + offset);
> > > +    return ((char *)base + offset);
> > 
> > This seems like a good change to me.
> > 
> > > 4) Spaces in brackets in switch condition
> > > -    switch ( domctl->cmd )
> > > +    switch (domctl->cmd)
> > 
> > This is explicitly against the current coding style.

Fixed this in the new version of checker.

> > 
> > > 5) Spaces in brackets in operation
> > > -    imm = ( insn >> BRANCH_INSN_IMM_SHIFT ) &
> > > BRANCH_INSN_IMM_MASK;
> > > +    imm = (insn >> BRANCH_INSN_IMM_SHIFT) &
> > > BRANCH_INSN_IMM_MASK;
> > 
> > I *think* this is already the official style.
> > 
> > > 6) Spaces in brackets in return
> > > -        return ( !sym->name[2] || sym->name[2] == '.' );
> > > +        return (!sym->name[2] || sym->name[2] == '.');
> > 
> > Similarly, I think this is already the official style.
> > 
> > > 7) Space after sizeof
> > > -    clean_and_invalidate_dcache_va_range(new_ptr, sizeof
> > > (*new_ptr) *
> > > len);
> > > +    clean_and_invalidate_dcache_va_range(new_ptr,
> > > sizeof(*new_ptr) *
> > > len);
> > 
> > I think this is correct.
> 
> I agree with George on all of the above.
> 
> > > 8) Spaces before comment if it’s on the same line
> > > -    case R_ARM_MOVT_ABS: /* S + A */
> > > +    case R_ARM_MOVT_ABS:    /* S + A */
> > > 
> > > -    if ( tmp == 0UL )       /* Are any bits set? */
> > > -        return result + size;   /* Nope. */
> > > +    if ( tmp == 0UL )         /* Are any bits set? */
> > > +        return result + size; /* Nope. */
> > 
> > Seem OK to me.
> 
> I don't think we have any rules how far apart a comment needs
> to be; I don't think there should be any complaints or
> "corrections" here.
> 
> > > 9) Space after for_each_vcpu
> > > -        for_each_vcpu(d, v)
> > > +        for_each_vcpu (d, v)
> > 
> > Er, not sure about this one.  This is actually a macro; but
> > obviously it looks like for ( ).
> > 
> > I think Jan will probably have an opinion, and I think he’ll be
> > back tomorrow; so maybe wait just a day or two before starting to
> > prep your series.
> 
> This makes it look like Linux style. In Xen it ought to be one
> of
> 
>         for_each_vcpu(d, v)
>         for_each_vcpu ( d, v )
> 
> depending on whether the author of a change considers
> for_each_vcpu an ordinary identifier or kind of a keyword.
> 
> > > 10) Spaces in declaration
> > > -    union hsr hsr = { .bits = regs->hsr };
> > > +    union hsr hsr = {.bits = regs->hsr};
> > 
> > I’m fine with this too.
> 
> I think we commonly put the blanks there that are being suggested
> to get dropped, so I'm not convinced this is a change we would
> want the tool making or suggesting.
> 
> Jan

Thanks for your advices, which helped me improve the checker. I
understand that there are still some disagreements about the
formatting, but as I said before, the checker cannot be very flexible
and take into account all the author's ideas.
I suggest using the
checker not as a mandatory check, but as an indication to the author of
possible formatting errors that he can correct or ignore.

I attached the new version of Xen checker below with updated
clang version from 9.0 to 12.0 and with minor fixes.
(branch xen-clang-format_12)
https://github.com/xen-troops/llvm-project/tree/xen-clang-format_12

If during the using and testing the tool new inconsistencies are found,
I am ready to fix them.

Regards,
Anastasiia

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.