3434import com .oracle .graal .python .builtins .objects .object .PythonObject ;
3535import com .oracle .graal .python .builtins .objects .type .LazyPythonClass ;
3636import com .oracle .graal .python .nodes .SpecialMethodNames ;
37+ import com .oracle .graal .python .nodes .attributes .WriteAttributeToDynamicObjectNode ;
3738import com .oracle .graal .python .nodes .generator .GeneratorFunctionRootNode ;
3839import com .oracle .truffle .api .Assumption ;
3940import com .oracle .truffle .api .CompilerAsserts ;
@@ -49,8 +50,8 @@ public class PFunction extends PythonObject {
4950 private static final Object [] EMPTY_DEFAULTS = new Object [0 ];
5051 private final String name ;
5152 private final String enclosingClassName ;
52- private final Assumption codeStableAssumption = Truffle .getRuntime ().createAssumption ("function code unchanged for " + getQualifiedName () );
53- private final Assumption defaultsStableAssumption = Truffle .getRuntime ().createAssumption ("function defaults unchanged " + getQualifiedName () );
53+ private final Assumption codeStableAssumption = Truffle .getRuntime ().createAssumption ();
54+ private final Assumption defaultsStableAssumption = Truffle .getRuntime ().createAssumption ();
5455 private final PythonObject globals ;
5556 private final PCell [] closure ;
5657 private final boolean isStatic ;
@@ -64,6 +65,11 @@ public PFunction(LazyPythonClass clazz, String name, String enclosingClassName,
6465
6566 public PFunction (LazyPythonClass clazz , String name , String enclosingClassName , RootCallTarget callTarget , PythonObject globals , Object [] defaultValues , PKeyword [] kwDefaultValues ,
6667 PCell [] closure ) {
68+ this (clazz , name , enclosingClassName , callTarget , globals , defaultValues , kwDefaultValues , closure , null );
69+ }
70+
71+ public PFunction (LazyPythonClass clazz , String name , String enclosingClassName , RootCallTarget callTarget , PythonObject globals , Object [] defaultValues , PKeyword [] kwDefaultValues ,
72+ PCell [] closure , WriteAttributeToDynamicObjectNode writeAttrNode ) {
6773 super (clazz );
6874 this .name = name ;
6975 this .code = new PCode (PythonBuiltinClassType .PCode , callTarget );
@@ -73,13 +79,17 @@ public PFunction(LazyPythonClass clazz, String name, String enclosingClassName,
7379 this .defaultValues = defaultValues == null ? EMPTY_DEFAULTS : defaultValues ;
7480 this .kwDefaultValues = kwDefaultValues == null ? PKeyword .EMPTY_KEYWORDS : kwDefaultValues ;
7581 this .closure = closure ;
76- addDefaultConstants (this . getStorage (), name , enclosingClassName );
82+ addDefaultConstants (writeAttrNode , getStorage (), name , enclosingClassName );
7783 }
7884
79- @ TruffleBoundary
80- private static void addDefaultConstants (DynamicObject storage , String name , String enclosingClassName ) {
81- storage .define (__NAME__ , name );
82- storage .define (__QUALNAME__ , enclosingClassName != null ? enclosingClassName + "." + name : name );
85+ private static void addDefaultConstants (WriteAttributeToDynamicObjectNode writeAttrNode , DynamicObject storage , String name , String enclosingClassName ) {
86+ if (writeAttrNode != null ) {
87+ writeAttrNode .execute (storage , __NAME__ , name );
88+ writeAttrNode .execute (storage , __QUALNAME__ , enclosingClassName != null ? enclosingClassName + "." + name : name );
89+ } else {
90+ storage .define (__NAME__ , name );
91+ storage .define (__QUALNAME__ , enclosingClassName != null ? enclosingClassName + "." + name : name );
92+ }
8393 }
8494
8595 public boolean isStatic () {
0 commit comments