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

[TIR] Add spans to all ExprNodes #6860

Merged
merged 2 commits into from Nov 11, 2020
Merged

Conversation

tkonolige
Copy link
Contributor

Add optional spanning information to BaseExprNode. This PR does not fill in this spanning information.

@jroesch @junrushao1994

@junrushao
Copy link
Member

CC: @spectrometerHBH

Copy link
Contributor

@giuseros giuseros left a comment

Choose a reason for hiding this comment

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

Hi @tkonolige ,
Is this related with the Synr change #6797 ? I am wondering if, from an high level, there is any other alternative than passing the span object, at construction, in the ExprNodes. If I understand correctly this is a sort of debugging utility. What if in the future we will need more debugging utilities? Wouldn't it be better to create like a DebugInfo struct that contains the span? Another alternative would be to have a debug-table with ExprNode -> DebugInfo, like a symbol table for debugging.

src/tir/op/op.cc Outdated Show resolved Hide resolved
src/ir/expr.cc Outdated Show resolved Hide resolved
@tkonolige
Copy link
Contributor Author

@giuseros This is related to #6797. The goal is to use tvmscript to provide line numbers for TIR. In the future we would like all TIR nodes to have span information. This PR is also related to #6274 in which spanning information was added to all relay nodes.

You'll have to ask @jroesch about the why we are using Spans vs a more complex DebugInfo struct. I know in the future we may want more complex debugging info.

@giuseros
Copy link
Contributor

giuseros commented Nov 6, 2020

@tkonolige is there an RFC (or anything similar) discussing these interface changes with an evaluation of the alternative designs?

@tkonolige
Copy link
Contributor Author

@giuseros This is the RFC that covers all error handling: https://discuss.tvm.apache.org/t/rfc-meta-rfc-3-pronged-plan-for-improving-error-messages-in-tvm. This PR is really just a continuation of #6274.

@giuseros
Copy link
Contributor

giuseros commented Nov 6, 2020

Well, I meant an RFC discussing this interface change. In general, I think those interface changes should be first discussed in the discuss forum, and their implementation should then be discussed in the PR. Probably the same applies to the Relay PR you mentioned.

Anyway, I am OK in continuing the interface discussion here. I think that adding a single span parameter to all the Expr nodes risks of polluting the interface (especially if, as you said, in the future more info will be needed). Is it possible to wrap the span at least in a DebugInfo structure? What are the deltas of this approach ?

@jroesch
Copy link
Member

jroesch commented Nov 6, 2020

@giuseros The entire Relay AST has had spans for the entire existence of the IR, this change is a follow-on from UnifiedIR refactors where we make things more consistent.

The span design originates (or Location) style of diagnostics is the style adopted by many modern compilers including Rust, and MLIR. The reason to have spans directly on the AST is the same reason to have type information they are important fields and having them be "intrinsic" vs. "extrinsic" properties.

In my exp. working on compilers having things exist in global stateful maps which must be kept in sync introduces complexity as the global state must be passed everywhere and you have to be very careful at which time you read from the maps. For example propagating span information inside of a pass which builds new AST fragments is easy as you can directly build span information from existing spans.

If we want to attach more meta-data for diagnostics I think we should attach that information to the diagnostic objects instead of attaching them to the spans/ast nodes directly. The diagnostics correspond to a location where some information was generated and the spans are indexes into the source representation.

@giuseros
Copy link
Contributor

giuseros commented Nov 6, 2020

Hi @jroesch ,
Thanks for the detailed explanation! I still think that it would have been very nice to have this explanation on the forum (also for future reference and future changes). For this change, if we commit to not adding more to the AST, I am happy to approve!

Copy link
Contributor

@giuseros giuseros left a comment

Choose a reason for hiding this comment

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

LGTM after discussion about the interface change with @tkonolige and @jroesch

Add optional spanning information to BaseExprNode. This PR does not fill
in this spanning information.
@tqchen tqchen merged commit aea74f0 into apache:main Nov 11, 2020
@tqchen
Copy link
Member

tqchen commented Nov 11, 2020

Thanks @tkonolige @giuseros @jroesch

@tkonolige tkonolige deleted the span_all_things branch November 11, 2020 01:18
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Dec 2, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Dec 4, 2020
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Dec 4, 2020
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

5 participants