-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Keep track of container types in assignments #15215
base: master
Are you sure you want to change the base?
Conversation
Introduce runtime checks to ensure any assignment to an existing item of a dictionary or list takes into account the member type. Closes vim#15208
I've been playing around with the patch. Haven't been able to slip anything past it. Tried with both I took a quick look at the patch; don't claim to fully understand it. But here's a few things that caught my attention. In eval.c there's About the names of the new methods, I ran a performance test, This is based on var ln: list<number> = [1, 2, 3]
var la: list<any> = [ 'a', ln]
def ListAssign()
var xxx: any = la[1]
xxx[1] = 3 ###-F
enddef The statement in question disassembles as
Don't have instuction level profiling (briefly talked to Bram about it, but never got there). Assuming that each of the four instructions takes the same amount of time without this patch (which is probably not valid, STOREINDEX is probably the slowest, but gives a feel), we can compute that STOREINDEX takes around twice as long. NO CHECK
WITH CHECK
|
Something I didn't think to examine is the following case. The compiler can determine that no type checking is needed. So no runtime check is needed and it shouldn't suffer performance degradation. In this case there's
|
Wow, I didn't realize how simple it was to reproduce. Without this patch there's
with output showing a corrupted list
|
This case
where the compiler knows that the types are OK also has the performance degradation. I'm starting to think of this as a compiler, not runtime, bug. Shouldn't/couldn't the compiler add a @yegappan Any thoughts on compiler vs runtime and how to detect the situations vulnerable to corruption? |
I guess at runtime if the target is |
At the entry to The assignment appears two more times after this first time. It seems like they are not needed. |
Introduce runtime checks to ensure any assignment to an existing item of a dictionary or list takes into account the member type.
Closes #15208
The
vim9execute.c
part can be reviewed by comparing the new functions withlist_append_tv
anddict_add_tv
that are used in the else branch. Theeval.c
is sligtly more involved but is essentially the same but for the expression evaluator.