forked from apache/tvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Bugfix][TVMScript] Capture fails if var appears only in annotation (a…
…pache#14849) Consider the case below: ```python dtype = "float32" @T.prim_func: def f( A: T.Buffer((1, ), dtype), B: T.Buffer((1, ), dtype), ): ... ``` The variable `dtype` only appears in the type annotation of the function being parsed. In this case, the python interpreter will evaluate the annotation first before invoking the decorator, and thus if `dtype` doesn't appear in the function body, it will not be considered as being captured by the function itself. As a result, `inspect` module will be unable to supply the value of `dtype` during parsing, leading to failure. This PR fixes the bug by maintaining a copy of function annotations that are already parsed. Whenever expression evaluation fails during parsing, it falls back to using the copy that is evaluated by python interpreter.
- Loading branch information
Showing
6 changed files
with
122 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
"""Error classes for diagnostics.""" | ||
from . import doc | ||
|
||
|
||
class ParserError(Exception): | ||
"""Error class for diagnostics.""" | ||
|
||
def __init__(self, node: doc.AST, msg: str): | ||
super().__init__(msg) | ||
self.node = node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters