[SOT] Guard dict itself in dict.get
#71223
Merged
+26
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR Category
Execute Infrastructure
PR Types
Bug fixes
Description
当
MIN_GRAPH_SIZE=10
时,这里我们生成的字节码如下:这里连续 load 两次
x
,这是因为x
和y
都是同一个对象None
,是LOAD_CONST
产生的,这里没什么问题但是生成的 guard 却只是
lambda frame: id(type(frame.f_locals['x'])) == 94068900165056 and frame.f_locals['x'] == None
这里明显有一个问题,就是
y
无论是什么都会命中 guard,而且这里生成的代码全是 loadx
,因此后面当y
传入和x
不一样的值时就出问题了其实这里本质问题是缺失了
kwargs
的 guard,这里d.get(key, default)
等价于d[key] if key in d else default
,这里控制流 condkey in d
应该加到 guard 里,而这里我们是没有加的这里我们当然可以构造
key in d
的 Variable 并将其 guard 住,但我们这里使用了一个简单的方式,直接 guard 住d
和key
,d
是新加的,key
在getitem
时会自动 guard 住未来我们可以实现 polyfill 的 dispatch 机制,将
d.get(key, default)
派发到d[key] if key in d else default
,以自动记录这里的key in d
到 guardPCard-66972