Skip to content

[libc][docs] Generate docs for signal.h & optimized is_implemented func #88028

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

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

simonzgx
Copy link
Contributor

@simonzgx simonzgx commented Apr 8, 2024

Fixes #87835

This patch added the documentation for the POSIX functions
according to n3096 Section 7.14, and gives the docgen.py script a
more elegant is_implemented function.

Copy link

github-actions bot commented Apr 8, 2024

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@simonzgx simonzgx changed the title [libc][docs] Generate docs for signal.h & optimized is_implemented func (#87835) [libc][docs] Generate docs for signal.h & optimized is_implemented func Apr 8, 2024
@llvmbot llvmbot added the libc label Apr 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Apr 8, 2024

@llvm/pr-subscribers-libc

Author: Xu Zhang (simonzgx)

Changes

Fixes #87835


Full diff: https://github.com/llvm/llvm-project/pull/88028.diff

3 Files Affected:

  • (added) libc/docs/signal.rst (+41)
  • (modified) libc/utils/docgen/docgen.py (+13-4)
  • (added) libc/utils/docgen/signal.json (+21)
diff --git a/libc/docs/signal.rst b/libc/docs/signal.rst
new file mode 100644
index 00000000000000..a994645ce3c260
--- /dev/null
+++ b/libc/docs/signal.rst
@@ -0,0 +1,41 @@
+signal.h Functions
+==================
+
+.. list-table::
+  :widths: auto
+  :align: center
+  :header-rows: 1
+
+  * - Function
+    - Implemented
+    - Standard
+  * - kill
+    - |check|
+    -
+  * - raise
+    - |check|
+    - 7.14.2.1
+  * - sigaction
+    - |check|
+    -
+  * - sigaddset
+    - |check|
+    -
+  * - sigaltstack
+    - |check|
+    -
+  * - sigdelset
+    - |check|
+    -
+  * - sigemptyset
+    - |check|
+    -
+  * - sigfillset
+    - |check|
+    -
+  * - signal
+    - |check|
+    - 7.14.1.1
+  * - sigprocmask
+    - |check|
+    -
diff --git a/libc/utils/docgen/docgen.py b/libc/utils/docgen/docgen.py
index 7411b4506f082f..213ed7e6cc5ec8 100755
--- a/libc/utils/docgen/docgen.py
+++ b/libc/utils/docgen/docgen.py
@@ -23,12 +23,21 @@ def load_api(hname: str) -> Dict:
 # TODO: we may need to get more sophisticated for less generic implementations.
 # Does libc/src/{hname minus .h suffix}/{fname}.cpp exist?
 def is_implemented(hname: str, fname: str) -> bool:
-    return Path(
+    path = Path(
         Path(__file__).parent.parent.parent,
         "src",
-        hname.rstrip(".h"),
-        fname + ".cpp",
-    ).exists()
+        hname.rstrip(".h")
+    )
+    source_file_name = fname + ".cpp"
+    if path.joinpath(source_file_name).exists():
+        return True
+    
+    # Attempt to search in the subfolders with 1-depth.
+    for sub_dir in path.iterdir():
+        if (sub_dir.joinpath(source_file_name)).exists():
+            return True
+
+    return False
 
 
 def print_functions(header: str, functions: Dict):
diff --git a/libc/utils/docgen/signal.json b/libc/utils/docgen/signal.json
new file mode 100644
index 00000000000000..366fb87d0a293a
--- /dev/null
+++ b/libc/utils/docgen/signal.json
@@ -0,0 +1,21 @@
+{
+  "macros": [
+    "__STDC_VERSION_FENV_H__"
+  ],
+  "functions": {
+    "kill": null,
+    "sigaction": null,
+    "sigaddset": null,
+    "sigaltstack": null,
+    "sigdelset": null,
+    "sigemptyset": null,
+    "sigfillset": null,
+    "sigprocmask": null,
+    "signal": {
+      "defined": "7.14.1.1"
+    },
+    "raise": {
+      "defined": "7.14.2.1"
+    }
+  }
+}
\ No newline at end of file

@simonzgx simonzgx marked this pull request as draft April 8, 2024 18:27
@nickdesaulniers nickdesaulniers self-requested a review April 8, 2024 18:51
@simonzgx simonzgx marked this pull request as ready for review April 8, 2024 18:55
"sigdelset": null,
"sigemptyset": null,
"sigfillset": null,
"sigprocmask": null,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I was thinking about these POSIX defined functions (none of this needs to be solved in this PR, but is perhaps worth thinking about how we can do something better for POSIX functions in the future).

It is possible to create a hyperlink to a page about them, example: https://pubs.opengroup.org/onlinepubs/009604499/functions/kill.html

Perhaps we either add more specialized handling of the 'defined' field to support URLs, or use a different field. IDK yet.

Comment on lines 35 to 37
# Attempt to search in the subfolders with 1-depth.
for sub_dir in path.iterdir():
if (sub_dir.joinpath(source_file_name)).exists():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant. Last week I was wondering about this since we have some cases where the subdir is a target ISA like x86_64, aarch64, etc. (i.e. src/math/, and other cases we have an OS like linux, darwin, windows (i.e. src/__support/OSUtil).

I guess src/__support/OSUtil and src/sys are cases where we'd need to recurse deeper. But for now, I'm happy with this addition. It makes sense to retain the TODO at the top of this function since we'll probably be revisiting this imminently.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just update the patch and now we can recursively search through all the subdirectories.

@simonzgx simonzgx force-pushed the add_docs_for_signal branch 2 times, most recently from 9f5784e to 08d9480 Compare April 8, 2024 19:46
@simonzgx simonzgx force-pushed the add_docs_for_signal branch 3 times, most recently from d02a2a8 to ca093c6 Compare April 9, 2024 01:53
@simonzgx simonzgx force-pushed the add_docs_for_signal branch from ca093c6 to 9a82d2b Compare April 9, 2024 02:42
Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the patch! Need me to merge?

@simonzgx
Copy link
Contributor Author

simonzgx commented Apr 9, 2024

thanks for the patch! Need me to merge?

Sure, thanks for your help!

@nickdesaulniers nickdesaulniers merged commit 7ab7e7a into llvm:main Apr 11, 2024
Copy link

@simonzgx Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[libc][docs] generate docs for signal.h
3 participants