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

Support frontend type check for If/While statements #3633

Closed
strongoier opened this issue Nov 27, 2021 · 3 comments · Fixed by #3875
Closed

Support frontend type check for If/While statements #3633

strongoier opened this issue Nov 27, 2021 · 3 comments · Fixed by #3875
Assignees
Labels
feature request Suggest an idea on this project

Comments

@strongoier
Copy link
Contributor

Concisely describe the proposed feature
We have the following test:

# @ti.test(arch=ti.cpu)
# def test_ternary_op():
# @ti.kernel
# def select():
# a = 1.1
# b = 3
# c = 3.6
# d = b if a else c
#
# with pytest.raises(TypeError,
# match="for 'select': 'f32', 'i32' and 'f32'"):
# select()
, which was commented in #3441. This was because IfExp was expanded to regular If statements in our new AST builder in #3299, and we didn't have type checks for the conditions of If/While statements.

To make the type error messages for If/While statements as easy to read as normal expressions, and to uncomment the above test, we'd better support frontend type check for If/While statements.

@strongoier strongoier added the feature request Suggest an idea on this project label Nov 27, 2021
@k-ye k-ye added this to To do in Lang Features & Python via automation Nov 27, 2021
@re-xyr
Copy link
Contributor

re-xyr commented Nov 28, 2021

Do we also need to typecheck other statements such as FrontendSNodeOpStmt or FrontendForStmt?

@re-xyr
Copy link
Contributor

re-xyr commented Nov 28, 2021

I found that Chi IR also has a typechecking pass in transforms/type_check.cpp. Does this mean after adding typechecking for frontend IR, we'll have two sets of typechecking mechanisms? This looks kind of redundant.

@strongoier
Copy link
Contributor Author

Currently transforms/type_check.cpp does the following:

  1. Check type errors;
  2. Add implicit casting;
  3. Fix some wrong types set by other passes.

However, we need to clearly separate user errors from compiler internal errors. Otherwise, neither users nor compiler developers can easily diagnose problems they meet.

Currently we are moving 1 to the frontend, and we just align the behavior with transforms/type_check.cpp for now. For example, begin/end of FrontendForStmt will be automatically cast, so we don't force them to be integers.

I believe in the next step we also need to move 2 to the frontend. And for 3, we need to fix our compiler implementation and finally turn this pass into an optional pure verification pass.

@strongoier strongoier moved this from To do to In progress in Lang Features & Python Dec 30, 2021
re-xyr added a commit to re-xyr/taichi that referenced this issue Jan 7, 2022
re-xyr added a commit to re-xyr/taichi that referenced this issue Jan 9, 2022
@strongoier strongoier removed this from In progress in Lang Features & Python Jan 10, 2022
Compiler Frontend & Middle-end automation moved this from In progress to Done Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Suggest an idea on this project
Development

Successfully merging a pull request may close this issue.

2 participants