-
Notifications
You must be signed in to change notification settings - Fork 94
interpreter: Use symboltable lookup in the interpreter #4101
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
Conversation
With this change, xdsl-run doesn't find the main entry point when it is nested deeper than the top-level module. For example, here: builtin.module {
riscv.assembly_section ".data" {
...
}
riscv.assembly_section ".text" {
riscv.directive ".globl" "main"
riscv.directive ".p2align" "2"
riscv_func.func @main() {
...
}
}
}
I think this currently only happens with the riscv dialect. |
else: | ||
raise InterpretationError(f'Could not find symbol "{symbol}"') | ||
def get_op_for_symbol(self, symbol: str | SymbolRefAttr) -> Operation: | ||
op = SymbolTable.lookup_symbol(self.module, symbol) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not exactly the same lookup, as the interpreter maintains a lookup via the symbol_table
property.
When using the SymbolTable.lookup_symbol
you indicate the operation from where to start the search and move "outwards"; here this seems to go straight to the containing module.
Not sure why something like this wouldn't do the trick? (haven't tested it):
if isinstance(symbol, SymbolRefAttr):
symbol = symbol.string_value()
if symbol in self.symbol_table:
return self.symbol_table[symbol]
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see what you're saying. So this lookup should start looking at the level of the call site.
Simply converting to string does not suffice. The symbol_table
does not contain the full nested symbol refs, but rather, only the tail of a symbol path. A call to a nested symbol "@parent::@child"
will not be found in the map because it only contains "@child"
currently.
If I understand correctly, in general you can't have a simple mapping from unique string to operation because, depending on scope, a symbol has a different name.
All this is under the assumption that symbols can shadow each other, i.e.
func @symbol
module @parent {
func @symbol
}
Not entirely sure that is true though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I see; that lookup as you described happens via the SymbolTable::lookup
; to me then sounds like the interpreter lookup needs a fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to get the current operation being handled by the interpreter, some sort of program counter. If not I can add it and use that value instead of self.module
to seed the lookup?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definitely seems like an upgrade in functionality and we need to figure out how to fix riscv to make it work properly with these symbols. The existing symbol table helper should be deleted IMO and just replaced with this, the clients might as well call it directly, and give the relevant root op. I can see how to refactor RISC-V here to work better, and that seems like a pre-requisite to merging this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I'd rather use the same lookup structure, and we have that via the SymbolTable
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've fixed the remaining failing tests, I forgot to update during my symbol table implementation for riscv_func, now everything seems to work!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a dedent
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4101 +/- ##
==========================================
- Coverage 88.98% 88.98% -0.01%
==========================================
Files 326 326
Lines 44585 44576 -9
Branches 5493 5489 -4
==========================================
- Hits 39676 39666 -10
Misses 3553 3553
- Partials 1356 1357 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@jumerckx could you please add two minimal tests for the lines missing code coverage before you merge? |
Oh actually I just realized that we should add a test for the reason we're adding this functionality, which is a nested symbol. Should be GTG after that. |
I added a test but it also depends on func dialect. |
This is to support nested
SymbolRefAttr
s.