38
38
import com .oracle .graal .python .parser .ExecutionCellSlots ;
39
39
import com .oracle .graal .python .runtime .PythonContext ;
40
40
import com .oracle .graal .python .runtime .object .PythonObjectFactory ;
41
+ import com .oracle .truffle .api .Assumption ;
42
+ import com .oracle .truffle .api .CompilerDirectives ;
41
43
import com .oracle .truffle .api .RootCallTarget ;
44
+ import com .oracle .truffle .api .Truffle ;
42
45
import com .oracle .truffle .api .TruffleLanguage .ContextReference ;
43
46
import com .oracle .truffle .api .frame .VirtualFrame ;
44
47
import com .oracle .truffle .api .nodes .ExplodeLoop ;
@@ -57,6 +60,9 @@ public class FunctionDefinitionNode extends ExpressionDefinitionNode {
57
60
@ Child private WriteAttributeToDynamicObjectNode writeNameNode = WriteAttributeToDynamicObjectNode .create ();
58
61
@ Child private PythonObjectFactory factory = PythonObjectFactory .create ();
59
62
63
+ private final Assumption sharedCodeStableAssumption = Truffle .getRuntime ().createAssumption ("shared code stable assumption" );
64
+ private final Assumption sharedDefaultsStableAssumption = Truffle .getRuntime ().createAssumption ("shared defaults stable assumption" );
65
+
60
66
public FunctionDefinitionNode (String functionName , String enclosingClassName , ExpressionNode doc , ExpressionNode [] defaults , KwDefaultExpressionNode [] kwDefaults ,
61
67
RootCallTarget callTarget ,
62
68
DefinitionCellSlots definitionCellSlots , ExecutionCellSlots executionCellSlots ) {
@@ -94,7 +100,26 @@ public Object execute(VirtualFrame frame) {
94
100
Object [] defaultValues = computeDefaultValues (frame );
95
101
PKeyword [] kwDefaultValues = computeKwDefaultValues (frame );
96
102
PCell [] closure = getClosureFromGeneratorOrFunctionLocals (frame );
97
- return withDocString (frame , factory ().createFunction (functionName , enclosingClassName , callTarget , PArguments .getGlobals (frame ), defaultValues , kwDefaultValues , closure , writeNameNode ));
103
+ Assumption codeStableAssumption ;
104
+ Assumption defaultsStableAssumption ;
105
+ if (CompilerDirectives .inCompiledCode ()) {
106
+ codeStableAssumption = getSharedCodeStableAssumption ();
107
+ defaultsStableAssumption = getSharedDefaultsStableAssumption ();
108
+ } else {
109
+ codeStableAssumption = Truffle .getRuntime ().createAssumption ();
110
+ defaultsStableAssumption = Truffle .getRuntime ().createAssumption ();
111
+ }
112
+ return withDocString (frame , factory ().createFunction (functionName , enclosingClassName , callTarget , PArguments .getGlobals (frame ), defaultValues , kwDefaultValues , closure , writeNameNode ,
113
+ codeStableAssumption , defaultsStableAssumption ));
114
+
115
+ }
116
+
117
+ private Assumption getSharedDefaultsStableAssumption () {
118
+ return sharedDefaultsStableAssumption ;
119
+ }
120
+
121
+ private Assumption getSharedCodeStableAssumption () {
122
+ return sharedCodeStableAssumption ;
98
123
}
99
124
100
125
@ ExplodeLoop
0 commit comments