-
Notifications
You must be signed in to change notification settings - Fork 19
classmethod-on-type fold: require an exact classmethod #1377
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
pyre/bench/synth/wrapper_subclass_get_override.cranelift.jitstats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| bridges_compiled=0 | ||
| descr_set_absent=0 | ||
| descr_set_ambiguous=0 | ||
| descr_set_stale_absent=0 | ||
| fbw_blackhole_adopted_multi_frame=0 | ||
| fbw_blackhole_adopted_single_frame=0 | ||
| fbw_rolled_back_with_effects=0 | ||
| fbw_store_journal_rollback_failed=0 | ||
| field_pos_attached_misplaced=0 | ||
| field_pos_spec_misplaced=0 | ||
| guard_failures=6 | ||
| internal_compile_panics=0 | ||
| loops_aborted=0 | ||
| loops_compiled=6 | ||
| retraces_compiled=0 |
15 changes: 15 additions & 0 deletions
15
pyre/bench/synth/wrapper_subclass_get_override.dynasm.jitstats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| bridges_compiled=0 | ||
| descr_set_absent=0 | ||
| descr_set_ambiguous=0 | ||
| descr_set_stale_absent=0 | ||
| fbw_blackhole_adopted_multi_frame=0 | ||
| fbw_blackhole_adopted_single_frame=0 | ||
| fbw_rolled_back_with_effects=0 | ||
| fbw_store_journal_rollback_failed=0 | ||
| field_pos_attached_misplaced=0 | ||
| field_pos_spec_misplaced=0 | ||
| guard_failures=6 | ||
| internal_compile_panics=0 | ||
| loops_aborted=0 | ||
| loops_compiled=6 | ||
| retraces_compiled=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| # `typeobject.py descr_getattribute` resolves an attribute through | ||
| # `type(descr).__get__`, so a `classmethod` / `staticmethod` SUBCLASS that | ||
| # overrides `__get__` binds through that override. A fold that unwraps | ||
| # `w_function` in its place calls the wrapped callable directly and never | ||
| # reaches the override, which is why every wrapper type test is exact. | ||
| # | ||
| # One loop per fold that unwraps a wrapper — class receiver, instance | ||
| # receiver, and the `__getattr__` hook's two arms — each reading through a | ||
| # direct call so the fold is the shape that records, not a lambda's | ||
| # megamorphic call site. Every loop must report the OVERRIDE. | ||
| # Sized for the fold, not for throughput: the declining path runs the whole | ||
| # descriptor protocol per iteration, so this costs far more per `N` than a | ||
| # folded loop. Every loop still compiles at N=2000, leaving a wide margin. | ||
| N = 100000 | ||
|
|
||
|
|
||
| class GetOverridingClassMethod(classmethod): | ||
| def __get__(self, obj, cls=None): | ||
| return overridden | ||
|
|
||
|
|
||
| class GetOverridingStaticMethod(staticmethod): | ||
| def __get__(self, obj, cls=None): | ||
| return overridden | ||
|
|
||
|
|
||
| def overridden(*args): | ||
| return 'override' | ||
|
|
||
|
|
||
| def wrapped_class(cls, x): | ||
| return 'wrapped' | ||
|
|
||
|
|
||
| def wrapped_static(x): | ||
| return 'wrapped' | ||
|
|
||
|
|
||
| class Attrs: | ||
| cm = GetOverridingClassMethod(wrapped_class) | ||
| sm = GetOverridingStaticMethod(wrapped_static) | ||
|
|
||
|
|
||
| class ClassHook: | ||
| __getattr__ = GetOverridingClassMethod(wrapped_class) | ||
|
|
||
|
|
||
| class StaticHook: | ||
| __getattr__ = GetOverridingStaticMethod(wrapped_static) | ||
|
|
||
|
|
||
| def classmethod_on_type(): | ||
| seen = None | ||
| i = 0 | ||
| while i < N: | ||
| seen = Attrs.cm(i) | ||
| i += 1 | ||
| print('classmethod on type', seen) | ||
|
|
||
|
|
||
| def staticmethod_on_type(): | ||
| seen = None | ||
| i = 0 | ||
| while i < N: | ||
| seen = Attrs.sm(i) | ||
| i += 1 | ||
| print('staticmethod on type', seen) | ||
|
|
||
|
|
||
| def classmethod_on_instance(): | ||
| obj = Attrs() | ||
| seen = None | ||
| i = 0 | ||
| while i < N: | ||
| seen = obj.cm(i) | ||
| i += 1 | ||
| print('classmethod on instance', seen) | ||
|
|
||
|
|
||
| def staticmethod_on_instance(): | ||
| obj = Attrs() | ||
| seen = None | ||
| i = 0 | ||
| while i < N: | ||
| seen = obj.sm(i) | ||
| i += 1 | ||
| print('staticmethod on instance', seen) | ||
|
|
||
|
|
||
| def classmethod_getattr_hook(): | ||
| obj = ClassHook() | ||
| seen = None | ||
| i = 0 | ||
| while i < N: | ||
| seen = obj.missing | ||
| i += 1 | ||
| print('classmethod getattr hook', seen) | ||
|
|
||
|
|
||
| def staticmethod_getattr_hook(): | ||
| obj = StaticHook() | ||
| seen = None | ||
| i = 0 | ||
| while i < N: | ||
| seen = obj.missing | ||
| i += 1 | ||
| print('staticmethod getattr hook', seen) | ||
|
|
||
|
|
||
| classmethod_on_type() | ||
| staticmethod_on_type() | ||
| classmethod_on_instance() | ||
| staticmethod_on_instance() | ||
| classmethod_getattr_hook() | ||
| staticmethod_getattr_hook() | ||
15 changes: 15 additions & 0 deletions
15
pyre/bench/synth/wrapper_subclass_get_override.wasm.jitstats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| bridges_compiled=0 | ||
| descr_set_absent=0 | ||
| descr_set_ambiguous=0 | ||
| descr_set_stale_absent=0 | ||
| fbw_blackhole_adopted_multi_frame=0 | ||
| fbw_blackhole_adopted_single_frame=0 | ||
| fbw_rolled_back_with_effects=0 | ||
| fbw_store_journal_rollback_failed=0 | ||
| field_pos_attached_misplaced=0 | ||
| field_pos_spec_misplaced=0 | ||
| guard_failures=6 | ||
| internal_compile_panics=0 | ||
| loops_aborted=0 | ||
| loops_compiled=6 | ||
| retraces_compiled=0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win
Verify that benchmark output is enforced.
The six paths only print
seen. If the synth harness does not compare stdout, a binding regression can pass without failing the benchmark. Add assertions forseen == 'override', or verify that the harness treats unexpected output as a failure.Also applies to: 61-67, 70-77, 80-87, 90-97, 100-107
🤖 Prompt for AI Agents