|
145 | 145 | import com.oracle.graal.python.lib.PyObjectLookupAttr;
|
146 | 146 | import com.oracle.graal.python.nodes.PGuards;
|
147 | 147 | import com.oracle.graal.python.nodes.SpecialAttributeNames;
|
| 148 | +import com.oracle.graal.python.nodes.attributes.ReadAttributeFromDynamicObjectNode; |
148 | 149 | import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
|
| 150 | +import com.oracle.graal.python.nodes.attributes.WriteAttributeToDynamicObjectNode; |
149 | 151 | import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
|
150 | 152 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
151 | 153 | import com.oracle.graal.python.nodes.object.GetDictIfExistsNode;
|
|
163 | 165 | import com.oracle.truffle.api.dsl.Cached;
|
164 | 166 | import com.oracle.truffle.api.dsl.Cached.Exclusive;
|
165 | 167 | import com.oracle.truffle.api.dsl.Fallback;
|
| 168 | +import com.oracle.truffle.api.dsl.GenerateCached; |
| 169 | +import com.oracle.truffle.api.dsl.GenerateInline; |
166 | 170 | import com.oracle.truffle.api.dsl.Specialization;
|
167 | 171 | import com.oracle.truffle.api.library.CachedLibrary;
|
168 | 172 | import com.oracle.truffle.api.nodes.Node;
|
169 | 173 | import com.oracle.truffle.api.object.DynamicObjectLibrary;
|
| 174 | +import com.oracle.truffle.api.object.HiddenKey; |
170 | 175 | import com.oracle.truffle.api.profiles.InlinedConditionProfile;
|
171 | 176 | import com.oracle.truffle.api.strings.TruffleString;
|
172 | 177 |
|
@@ -712,27 +717,61 @@ static long get(PBaseSet object,
|
712 | 717 | }
|
713 | 718 | }
|
714 | 719 |
|
| 720 | + @GenerateInline |
| 721 | + @GenerateCached(false) |
| 722 | + abstract static class GetSliceField extends Node { |
| 723 | + abstract Object execute(Node inliningTarget, PSlice object, HiddenKey key, Object value); |
| 724 | + |
| 725 | + @Specialization |
| 726 | + static Object get(Node inliningTarget, PSlice object, HiddenKey key, Object value, |
| 727 | + @Cached(inline = false) ReadAttributeFromDynamicObjectNode read, |
| 728 | + @Cached(inline = false) WriteAttributeToDynamicObjectNode write, |
| 729 | + @Cached PythonCextBuiltins.PromoteBorrowedValue promote) { |
| 730 | + Object promotedValue = read.execute(object, key); |
| 731 | + if (promotedValue == PNone.NO_VALUE) { |
| 732 | + promotedValue = promote.execute(inliningTarget, value); |
| 733 | + if (promotedValue == null) { |
| 734 | + return value; |
| 735 | + } |
| 736 | + write.execute(object, key, promotedValue); |
| 737 | + } |
| 738 | + return promotedValue; |
| 739 | + } |
| 740 | + } |
| 741 | + |
715 | 742 | @CApiBuiltin(ret = PyObjectBorrowed, args = {PySliceObject}, call = Ignored)
|
716 | 743 | abstract static class Py_get_PySliceObject_start extends CApiUnaryBuiltinNode {
|
| 744 | + private static final HiddenKey START_KEY = new HiddenKey("promoted_start"); |
| 745 | + |
717 | 746 | @Specialization
|
718 |
| - static Object doStart(PSlice object) { |
719 |
| - return object.getStart(); |
| 747 | + static Object doStart(PSlice object, |
| 748 | + @Bind("this") Node inliningTarget, |
| 749 | + @Cached GetSliceField getSliceField) { |
| 750 | + return getSliceField.execute(inliningTarget, object, START_KEY, object.getStart()); |
720 | 751 | }
|
721 | 752 | }
|
722 | 753 |
|
723 | 754 | @CApiBuiltin(ret = PyObjectBorrowed, args = {PySliceObject}, call = Ignored)
|
724 | 755 | abstract static class Py_get_PySliceObject_step extends CApiUnaryBuiltinNode {
|
| 756 | + private static final HiddenKey STEP_KEY = new HiddenKey("promoted_step"); |
| 757 | + |
725 | 758 | @Specialization
|
726 |
| - static Object doStep(PSlice object) { |
727 |
| - return object.getStep(); |
| 759 | + static Object doStep(PSlice object, |
| 760 | + @Bind("this") Node inliningTarget, |
| 761 | + @Cached GetSliceField getSliceField) { |
| 762 | + return getSliceField.execute(inliningTarget, object, STEP_KEY, object.getStep()); |
728 | 763 | }
|
729 | 764 | }
|
730 | 765 |
|
731 | 766 | @CApiBuiltin(ret = PyObjectBorrowed, args = {PySliceObject}, call = Ignored)
|
732 | 767 | abstract static class Py_get_PySliceObject_stop extends CApiUnaryBuiltinNode {
|
| 768 | + private static final HiddenKey STOP_KEY = new HiddenKey("promoted_stop"); |
| 769 | + |
733 | 770 | @Specialization
|
734 |
| - static Object doStop(PSlice object) { |
735 |
| - return object.getStop(); |
| 771 | + static Object doStop(PSlice object, |
| 772 | + @Bind("this") Node inliningTarget, |
| 773 | + @Cached GetSliceField getSliceField) { |
| 774 | + return getSliceField.execute(inliningTarget, object, STOP_KEY, object.getStop()); |
736 | 775 | }
|
737 | 776 | }
|
738 | 777 |
|
|
0 commit comments