oracle / graalpython

A Python 3 implementation built on GraalVM
Other
1.2k stars 104 forks source link

'dir()' and 'locals()' triggers a deopt #296

Closed kfirt closed 1 year ago

kfirt commented 1 year ago

https://graalvm.slack.com/archives/CNA7PDH2N/p1667328289760519

@Test public void testDeopt(){ String workflowScript = """ def enrich(input:dict, func_name:str):

            def kuku(name:str):
                return "kuku"

            if func_name not in dir():
                raise NameError(f"Function name was not found in the current script.")
            return "bar"
        """;

ctx.eval("python", workflowScript);
final Value member = ctx.getBindings("python").getMember("enrich");
IntStream.range(0, 1_000).forEach(i -> member.execute(Map.of("source", i), "kuku"));

}