-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
_Generic() is not handled on elixir.bootlin.com #237
Comments
_Generic is never listed by ctags (because it's a keyword and it's not redefined anywhere in the code), therefore it's not in the definitions database and references to it are not recorded. Handling this would probably need to be special-cased in the code. |
My understand is this:
I don't see any ctags kind that supports it. I tested using a short
That would mean we would need to contribute to ctags or add custom parsing. I'm not sure parsing C is something we want to get into. Also, is this feature useful? I'd say no. But I might be biased because I have a copy of the kernel on my machine and can always grep from there if I need non keywords (which I also do to look for strings for example, which are not indexed by Elixir either). |
I disagree. Yes, first of all we should consider Elixir service to be detached from whatever developer has, I often access it via my phone. Do I have a kernel Git source tree there? Nope, and 99.99+% of users of such a use case won't have it either. Yeah, I understand that ideally it's probably a |
I see your reasoning.
Something odd:
It might be only a bug/exception with
|
But ctags only lists these keywords because they are redefined as something else (label, member name...) somewhere in the kernel. See:
But no else or return for example. |
How can ctags be aware of those definitions? It gets passed a file in Take |
Ctags is only used to parse definitions. References are parsed with a different, simpler method. Ctags is not involved when the database of references is updated. See https://github.com/bootlin/elixir/blob/master/update.py#L237 For references, a simple tokenizer is ran: https://github.com/bootlin/elixir/blob/master/script.sh#L97 References update (for a particular tag) runs only after definitions update is done. |
Ah, that tokenizer was the part I was missing, thanks! The conditional statement in Then to address # This is what we currently have in update.py.
if (db.defs.exists(tok) and
not ( (idx*idx_key_mod + line_num) in defs_idxes and
defs_idxes[idx*idx_key_mod + line_num] == tok ) and
(family != 'M' or tok.startswith(b'CONFIG_'))):
# add reference
pass
# First refactor to simplify. I _think_ this is equivalent.
def_exists = db.defs.exists(tok)
i = idx*idx_key_mod + line_num
if def_exists and defs_idxes.get(i) != tok and (family != 'M' or tok.startswith(b'CONFIG_')):
# add reference
pass
# Now add logic. I haven't tested this code. Also it could be slow.
compiler_tokens = [b'_Generic', b'_Atomic', b'_Static_assert'] # etc.
accept_tok = db.defs.exists(tok) or (family == 'C' and tok in compiler_tokens)
i = idx*idx_key_mod + line_num
if accept_tok and defs_idxes.get(i) != tok and (family != 'M' or tok.startswith(b'CONFIG_')):
# add reference
pass Some notes about this:
What do you think about this solution? |
Do you mean that there could be a problem with assembler files?
I heard that Linux heavily relies on GCC extensions, and while I don't have much experience with the codebase, I would guess that those are never defined in a way that would be picked up by ctags. See for example __builtin_unreachable:
Your solution definitely makes sense. Are you planning to open a PR? Or should I do it? |
Yes, sorry, I forget giving precise thoughts. There is an edge-case with assembly files but I don't see how it could be an issue. Something else: we also must not forget to handle C++ properly, which I guess has many compiler-provided identifiers.
Indeed I went looking into GCC and I found a reserved words list (eg contains
I cannot allocate much time to this. Can you continue the investigation and send a PR? Thanks! |
Thanks, folks, for this investigation! Hopefully we will get something out sooner than later. |
There is no references to
_Generic()
. Since new kernel releases will more and more rely on the macros with this feature be enabled, it would be nice to at least have a list of the users of it in the source code.The text was updated successfully, but these errors were encountered: