Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Doc-comments edge-cases not indexed  #353

Open

Description

@Fomys

Hi, I just found few documentation that are not indexed by elixir:

https://elixir.bootlin.com/linux/v6.12.1/source/mm/util.c#L55 - Because of "noinline"?

https://elixir.bootlin.com/linux/v6.12.1/source/mm/util.c#L817 - Because the name in kdoc is wrong?

Thanks
Louis Chauvet

Activity

  1. tleb commented on Nov 25, 2024

    @tleb
    Member

    Can you explicit what is missing? I guess you are talking about arguments not being tagged as references but I am not sure.

    For the first link it would be char and s.
    For the second link it would be n and size.

    Thanks!


    edit: no, it seems you are talking about doc comments. That is related to find-file-doc-comments.pl, which we don't know much about. We need to look into it.

  2. cxw42 commented on Nov 25, 2024

    @cxw42
    Contributor

    For the second one, I think it is because of the name mismatch. The code looks for a matching name as a shortcut to avoid needing a full C parser.

    qr{^$comment_leader\Q$definition_name\E(?:\h|\(|:|$)};

  3. cxw42 commented on Nov 25, 2024

    @cxw42
    Contributor

    For the first one, it might be that the ctags invocation needs to be updated.

    my @ctags = qx{ ctags -x --c-kinds=+p-m --language-force=C "$filename" |

  4. tleb commented on Nov 26, 2024

    @tleb
    Member

    For the first one, it might be that the ctags invocation needs to be updated.

    Indeed the ctags inside the Docker container doesn't give an entry for strdup. Inside the Docker container:

    Details
    $ git -C elixir rev-parse --short HEAD
    5fe2a8e
    
    $ docker build -t elixir -f ./elixir/docker/Dockerfile ./elixir
    ...
    
    $ docker run --rm -it --entrypoint /bin/bash elixir
    
    # wget -O util.c "https://elixir.bootlin.com/linux/v6.12.1/source/mm/util.c?raw"
    
    # ctags -x --c-kinds=+p-m --language-force=C util.c | grep ^strdup
    
    # ctags --version
    Universal Ctags 5.9.0, Copyright (C) 2015 Universal Ctags Team
    Universal Ctags is derived from Exuberant Ctags.
    Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
      Compiled: Sep  3 2021, 18:12:18
      URL: https://ctags.io/
      Optional compiled features: +wildcards, +regex, +gnulib_regex, +iconv, +option-directory, +xpath, +json, +interactive, +sandbox, +yaml, +packcc, +optscript
    

    Compared to a recent ctags (the one used by the prod server):

    Details
    $ wget -O util.c "https://elixir.bootlin.com/linux/v6.12.1/source/mm/util.c?raw"
    
    $ $ctags -x --c-kinds=+p-m --language-force=C util.c  | grep -w ^kstrdup
    kstrdup          function     55 util.c           char *kstrdup(const char *s, gfp_t gfp)
    
    $ $ctags --version
    Universal Ctags 6.1.0, Copyright (C) 2015-2023 Universal Ctags Team
    Universal Ctags is derived from Exuberant Ctags.
    Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
      Compiled: Nov  8 2024, 17:48:48
      URL: https://ctags.io/
      Output version: 0.0
      Optional compiled features: +wildcards, +regex, +gnulib_regex, +iconv, +option-directory, +yaml, +packcc, +optscript, +pcre2
    

    This is an issue with the universal-ctags packaged by Debian Bookworm:

    $ docker run --rm -it --entrypoint /bin/bash debian:bookworm
    # apt-get update && apt-get upgrade -y && apt-get install -y wget universal-ctags
    # wget -O util.c "https://elixir.bootlin.com/linux/v6.12.1/source/mm/util.c?raw"
    # ctags -x --c-kinds=+p-m --language-force=C util.c | grep ^strdup
    

    It doesn't work with debian:testing nor debian:unstable. The debian package index agrees (all have the same version).

    So prod server has a recent ctags that works fine, but the initial indexing has been done inside the Docker container. That means blobs that didn't change are wrong in the latest version. To address this, we should:

    1. fix the docker image to have a recent enough universal-ctags version and,
    2. do a full reindex.

    For (1) we could either switch distro, sideload universal-ctags or compile it manually.

  5. tleb commented on Nov 26, 2024

    @tleb
    Member

    For the second one, I think it is because of the name mismatch. The code looks for a matching name as a shortcut to avoid needing a full C parser.

    For this one, I am wondering if we could ignore finding a declaration/prototype below that matches the name. If we take declarations from linux/mm/util.c, there are quite a few that follow the $a_noprof with $a being declared as a wrapper macro in header files, adding some safety/profiling code surrounding the function call.

    I cannot think of places where not checking the declaration below would be an issue.

  6. cxw42 commented on Nov 28, 2024

    @cxw42
    Contributor

    @tleb Thanks for the research on the first one!

    Re. the second one, I don't recall why I added that check. I think it might have been to avoid indexing doc comments belonging to things other than functions. E.g., a doc comment for a macro, then the macro, then a function --- we don't want the doc comment associated with the function.

  7. tleb commented on Nov 28, 2024

    @tleb
    Member

    I am wondering if we could change the approach completely:

    • Find lines like /**,
    • Keep matches where the next line is * $ident - ...,
    • Keep matches were we have a definition for $ident in the database.

    Benefits:

    • Script doesn't have to call ctags,
    • We take into account doccomments which aren't located next to the definitions (ie the current issue),
    • Simpler implementation.

    Downfalls:

    • False positives? Those should be mitigated by the database definition check.
    • False negatives? Is the above too restrictive for doc comments? It might be specific to C kernel code standards for example, and different in other projects.
  8. Fomys commented on Feb 12, 2025

    @Fomys
    ContributorAuthor

    I think your approach may work, especially since some functions are not marked as documented because there are macro in-between, like this: https://elixir.bootlin.com/linux/v6.13.2/source/kernel/trace/trace.c#L3407-L3428 (function found, but not its documentation)

  9. changed the title [-]Documentation not indexed[/-] [+]Doc-comments edge-cases not indexed [/+] on Feb 12, 2025
  10. fstachura commented on Feb 13, 2025

    @fstachura
    Collaborator

    I wanted to note that the kernel docs parsing script recognizes mentioned symbols.

    ./scripts/kernel-doc ./mm/util.c

    Details
    (...)
    .. c:function:: char * kstrdup (const char *s, gfp_t gfp)
    
       allocate space for and copy an existing string
    
    .. container:: kernelindent
    
      **Parameters**
    
      ``const char *s``
        the string to duplicate
    
      ``gfp_t gfp``
        the GFP mask used in the kmalloc() call when allocating memory
    
      **Return**
    
      newly allocated copy of **s** or ``NULL`` in case of error
    (...)
    

    ./scripts/kernel-doc ./kernel.trace/trace.c

    Details
    .. c:function:: int trace_array_printk (struct trace_array *tr, unsigned long ip, const char *fmt, ...)
    
       Print a message to a specific instance
    
    .. container:: kernelindent
    
      **Parameters**
    
      ``struct trace_array *tr``
        The instance trace_array descriptor
    
      ``unsigned long ip``
        The instruction pointer that this is called from.
    
      ``const char *fmt``
        The format to print (printf format)
    
      ``...``
        variable arguments
    
      **Description**
    
      If a subsystem sets up its own instance, they have the right to
      printk strings into their tracing instance buffer using this
      function. Note, this function will not write into the top level
      buffer (use trace_printk() for that), as writing into the top level
      buffer should only have events that can be individually disabled.
      trace_printk() is only used for debugging a kernel, and should not
      be ever incorporated in normal use.
      
      trace_array_printk() can be used, as it will not add noise to the
      top level tracing buffer.
      
      Note, trace_array_init_printk() must be called on **tr** before this
      can be used.
    

    Many functions in mm/util.c file have a _noprof suffix, it seems that it's dropped in the doccomments parser https://lore.kernel.org/all/20240326054149.2121-1-rdunlap@infradead.org/
    ./scripts/kernel-doc ./mm/util.c

    Details
    (...)
    .. c:function:: void * vcalloc (size_t n, size_t size)
    
       allocate and zero memory for a virtually contiguous array.
    
    .. container:: kernelindent
    
      **Parameters**
    
      ``size_t n``
        number of elements.
    
      ``size_t size``
        element size.
    (...)
    
  11. added
    indexing
    on Feb 21, 2025
  12. added theissue type on Feb 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    indexing

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions