-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Use loadname local replace loadname free #2006
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
| @@ -680,11 +682,11 @@ impl SymbolTableBuilder { | |||
| self.scan_expressions(vals, context)?; | |||
| } | |||
| Subscript { a, b } => { | |||
| self.scan_expression(a, context)?; | |||
| self.scan_expression(a, &ExpressionContext::Load)?; | |||
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.
compiler/src/symboltable.rs
Outdated
| @@ -276,6 +276,8 @@ impl<'a> SymbolTableAnalyzer<'a> { | |||
| fn analyze_unknown_symbol(&self, symbol: &mut Symbol) { | |||
| if symbol.is_assigned || symbol.is_parameter { | |||
| symbol.scope = SymbolScope::Local; | |||
| } else if symbol.is_referenced { | |||
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 am not sure about the correctness of this treatment.
|
Looks like global scope names in nested closures aren't getting resolved correctly? |
Yes, the error is same as before. |
import symtable
content = open("Lib/functools.py").read()
table = symtable.symtable(content, "?", "exec")
// True in python
// False in RustPython
table.lookup("singledispatch").get_namespace().lookup("object").is_global()
""" |
|
RustPython‘s LoadLocal is not same as cpython's LoadFast. def f():
ch = chr (100)
if ch == 'd':
chr = ch
return chr
"""
Bytecode:
2 0 LOAD_FAST 0 (chr)
2 LOAD_CONST 1 (100)
4 CALL_FUNCTION 1
6 STORE_FAST 1 (ch)
3 8 LOAD_FAST 1 (ch)
10 LOAD_CONST 2 ('d')
12 COMPARE_OP 2 (==)
14 POP_JUMP_IF_FALSE 20
4 16 LOAD_FAST 1 (ch)
18 STORE_FAST 0 (chr)
5 >> 20 LOAD_FAST 0 (chr)
22 RETURN_VALUE
"""Cpython analyze chr's scope is Local, and use LoadFast to load chr, but we can't load chr if we use LoadName local. |
|
@coolreader18 Current _codecss.py implemention is illegal in cpython. |
|
Hmm, that is tricky. Maybe we could do something in symtable to check if it's used global scope and then reassigned, to do a less optimized LoadName for it after? Or maybe we could just copy CPython's LoadFast, if feasible? |
|
@coolreader18 I think that modifying the symtable will destroy the compatibility with cpython. |
|
Oh, I think we sent our comments at the same time, I didn't see yours before I sent mine. Yeah, I think the "reference before assignment" error + editing _codecs.py is the best course of action; the original version was from a PyPy branch compatible w/ python2 and there's been issues that pop up with it whenever a new module is added that calls into a part of _codecs that we haven't fixed yet. |
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.
Great job!!




Fix #2005 .
Use load local replace load free.