Skip to content
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

[Lang] Support format printing with format specifiers in str.format() and f-strings (Don't merge) #7468

Closed
wants to merge 40 commits into from

Conversation

dream189free
Copy link
Contributor

@dream189free dream189free commented Mar 1, 2023

Issue: #5949

Brief Summary

Since the cpu, CUDA and Vulkan backends all support C-style printf, this PR adds support for formatting print with various format specifiers using Python f-strings or str.format() method.

This PR extracts the format specifier from the Python AST, passes it to the C++ IR builder, and eventually generates the appropriate format specifier during codegen, with respect to

  1. specifiers specified by the user,
  2. the data type inferred by taichi, and
  3. the capability of the backend.

This PR can be broken down into the following ones:

  1. Extract format specifier from Python AST.
  2. Add support for positional arguments in formatted printing.
  3. Merge format specifier during codegen and pass it to the backends.
  4. Add format string sanitizer for vulkan backend.

TODO:

  1. Add offline_cache related logic.
  2. Describe in the documentation how to use formatted printing.
  3. Add Python unit tests involving printf flags and width specifier.

@netlify
Copy link

netlify bot commented Mar 1, 2023

Deploy Preview for docsite-preview ready!

Name Link
🔨 Latest commit 5629d1f
🔍 Latest deploy log https://app.netlify.com/sites/docsite-preview/deploys/640009151a8c49000853f1ad
😎 Deploy Preview https://deploy-preview-7468--docsite-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@CLAassistant
Copy link

CLAassistant commented Mar 1, 2023

CLA assistant check
All committers have signed the CLA.

@dream189free dream189free requested a review from jim19930609 March 2, 2023 03:51
@dream189free dream189free marked this pull request as ready for review March 2, 2023 03:51
@dream189free dream189free marked this pull request as draft March 6, 2023 14:38
@dream189free dream189free changed the title [Lang] Support format printing with format specifiers in str.format() and f-strings [Lang] Support format printing with format specifiers in str.format() and f-strings (Don't merge) Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants