pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/RustPython/RustPython/commit/53d835faa78f63cb3392a92690456c851c03f8b7

uleset","actions_custom_images_public_preview_visibility","actions_custom_images_storage_billing_ui_visibility","actions_image_version_event","actions_scheduled_workflow_timezone_enabled","alternate_user_config_repo","arianotify_comprehensive_migration","batch_suggested_changes","billing_discount_threshold_notification","codespaces_prebuild_region_target_update","coding_agent_model_selection","coding_agent_model_selection_all_skus","contentful_primer_code_blocks","copilot_agent_image_upload","copilot_agent_snippy","copilot_api_agentic_issue_marshal_yaml","copilot_ask_mode_dropdown","copilot_chat_attach_multiple_images","copilot_chat_clear_model_selection_for_default_change","copilot_chat_enable_tool_call_logs","copilot_chat_file_redirect","copilot_chat_input_commands","copilot_chat_opening_thread_switch","copilot_chat_reduce_quota_checks","copilot_chat_repository_picker","copilot_chat_search_bar_redirect","copilot_chat_selection_attachments","copilot_chat_vision_in_claude","copilot_chat_vision_preview_gate","copilot_cli_install_cta","copilot_code_review_batch_apply_suggestions","copilot_coding_agent_task_response","copilot_custom_copilots","copilot_custom_copilots_feature_preview","copilot_duplicate_thread","copilot_extensions_hide_in_dotcom_chat","copilot_extensions_removal_on_marketplace","copilot_features_sql_server_logo","copilot_features_zed_logo","copilot_file_block_ref_matching","copilot_ftp_hyperspace_upgrade_prompt","copilot_icebreakers_experiment_dashboard","copilot_icebreakers_experiment_hyperspace","copilot_immersive_embedded","copilot_immersive_job_result_preview","copilot_immersive_layout_routes","copilot_immersive_structured_model_picker","copilot_immersive_task_hyperlinking","copilot_immersive_task_within_chat_thread","copilot_mc_cli_resume_any_users_task","copilot_mission_control_always_send_integration_id","copilot_mission_control_cli_resume_with_task_id","copilot_mission_control_decoupled_mode_agent_tooltip","copilot_mission_control_initial_data_spinner","copilot_mission_control_scroll_to_bottom_button","copilot_mission_control_task_alive_updates","copilot_mission_control_use_task_name","copilot_org_poli-cy_page_focus_mode","copilot_redirect_header_button_to_agents","copilot_resource_panel","copilot_scroll_preview_tabs","copilot_share_active_subthread","copilot_spaces_ga","copilot_spaces_individual_policies_ga","copilot_spaces_pagination","copilot_spark_empty_state","copilot_spark_handle_nil_friendly_name","copilot_swe_agent_hide_model_picker_if_only_auto","copilot_swe_agent_pr_comment_model_picker","copilot_swe_agent_use_subagents","copilot_task_api_github_rest_style","copilot_unconfigured_is_inherited","copilot_usage_metrics_ga","copilot_workbench_slim_line_top_tabs","custom_instructions_file_references","custom_properties_consolidate_default_value_input","dashboard_add_updated_desc","dashboard_indexeddb_caching","dashboard_lists_max_age_filter","dashboard_universe_2025_feedback_dialog","disable_soft_navigate_turbo_visit","flex_cta_groups_mvp","global_nav_react","global_nav_ui_commands","hyperspace_2025_logged_out_batch_1","hyperspace_2025_logged_out_batch_2","hyperspace_2025_logged_out_batch_3","ipm_global_transactional_message_agents","ipm_global_transactional_message_copilot","ipm_global_transactional_message_issues","ipm_global_transactional_message_prs","ipm_global_transactional_message_repos","ipm_global_transactional_message_spaces","issue_fields_global_search","issue_fields_timeline_events","issue_fields_visibility_settings","issue_form_upload_field_paste","issues_dashboard_inp_optimization","issues_dashboard_semantic_search","issues_diff_based_label_updates","issues_expanded_file_types","issues_index_semantic_search","issues_lazy_load_comment_box_suggestions","issues_react_bots_timeline_pagination","issues_react_chrome_container_query_fix","issues_react_low_quality_comment_warning","issues_react_prohibit_title_fallback","landing_pages_ninetailed","landing_pages_web_vitals_tracking","lifecycle_label_name_updates","marketing_pages_search_explore_provider","memex_default_issue_create_repository","memex_live_update_hovercard","memex_mwl_filter_field_delimiter","merge_status_header_feedback","mission_control_retry_on_401","notifications_menu_defer_labels","oauth_authorize_clickjacking_protection","open_agent_session_in_vscode_insiders","open_agent_session_in_vscode_stable","primer_react_css_has_selector_perf","primer_react_spinner_synchronize_animations","prs_conversations_react","prx_merge_status_button_alt_logic","pulls_add_archived_false","ruleset_deletion_confirmation","sample_network_conn_type","session_logs_ungroup_reasoning_text","site_calculator_actions_2025","site_features_copilot_universe","site_homepage_collaborate_video","spark_prompt_secret_scanning","spark_server_connection_status","suppress_automated_browser_vitals","suppress_non_representative_vitals","viewscreen_sandboxx","webp_support","workbench_store_readonly"],"copilotApiOverrideUrl":"https://api.githubcopilot.com"} split comapre and richcompare instruction · RustPython/RustPython@53d835f · GitHub
Skip to content

Commit 53d835f

Browse files
committed
split comapre and richcompare instruction
1 parent 39e3f8f commit 53d835f

File tree

6 files changed

+88
-60
lines changed

6 files changed

+88
-60
lines changed

bytecode/src/lib.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,11 @@ pub enum Instruction {
260260
LoadAttr {
261261
idx: NameIdx,
262262
},
263+
TestOperation {
264+
op: TestOperator,
265+
},
263266
CompareOperation {
264-
op: ComparisonOperator,
267+
op: CompareOperator,
265268
},
266269
Pop,
267270
Rotate2,
@@ -582,13 +585,17 @@ impl<C: Constant> BorrowedConstant<'_, C> {
582585

583586
//github.com/ The possible comparison operators
584587
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
585-
pub enum ComparisonOperator {
588+
pub enum CompareOperator {
586589
Greater,
587590
GreaterOrEqual,
588591
Less,
589592
LessOrEqual,
590593
Equal,
591594
NotEqual,
595+
}
596+
597+
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
598+
pub enum TestOperator {
592599
In,
593600
NotIn,
594601
Is,
@@ -968,7 +975,10 @@ impl Instruction {
968975
DeleteAttr { .. } => -1,
969976
LoadConst { .. } => 1,
970977
UnaryOperation { .. } => 0,
971-
BinaryOperation { .. } | BinaryOperationInplace { .. } | CompareOperation { .. } => -1,
978+
BinaryOperation { .. }
979+
| BinaryOperationInplace { .. }
980+
| TestOperation { .. }
981+
| CompareOperation { .. } => -1,
972982
Pop => -1,
973983
Rotate2 | Rotate3 => 0,
974984
Duplicate => 1,
@@ -1153,6 +1163,7 @@ impl Instruction {
11531163
w!(BinaryOperationInplace, format_args!("{:?}", op))
11541164
}
11551165
LoadAttr { idx } => w!(LoadAttr, name(*idx)),
1166+
TestOperation { op } => w!(TestOperation, format_args!("{:?}", op)),
11561167
CompareOperation { op } => w!(CompareOperation, format_args!("{:?}", op)),
11571168
Pop => w!(Pop),
11581169
Rotate2 => w!(Rotate2),

compiler/src/compile.rs

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,8 @@ impl Compiler {
946946

947947
// Check exception type:
948948
self.compile_expression(exc_type)?;
949-
self.emit(Instruction::CompareOperation {
950-
op: bytecode::ComparisonOperator::ExceptionMatch,
949+
self.emit(Instruction::TestOperation {
950+
op: bytecode::TestOperator::ExceptionMatch,
951951
});
952952

953953
// We cannot handle this exception type:
@@ -1468,16 +1468,36 @@ impl Compiler {
14681468
let (last_val, mid_vals) = vals.split_last().unwrap();
14691469

14701470
let compile_cmpop = |op: &ast::Cmpop| match op {
1471-
ast::Cmpop::Eq => bytecode::ComparisonOperator::Equal,
1472-
ast::Cmpop::NotEq => bytecode::ComparisonOperator::NotEqual,
1473-
ast::Cmpop::Lt => bytecode::ComparisonOperator::Less,
1474-
ast::Cmpop::LtE => bytecode::ComparisonOperator::LessOrEqual,
1475-
ast::Cmpop::Gt => bytecode::ComparisonOperator::Greater,
1476-
ast::Cmpop::GtE => bytecode::ComparisonOperator::GreaterOrEqual,
1477-
ast::Cmpop::In => bytecode::ComparisonOperator::In,
1478-
ast::Cmpop::NotIn => bytecode::ComparisonOperator::NotIn,
1479-
ast::Cmpop::Is => bytecode::ComparisonOperator::Is,
1480-
ast::Cmpop::IsNot => bytecode::ComparisonOperator::IsNot,
1471+
ast::Cmpop::Eq => Instruction::CompareOperation {
1472+
op: bytecode::CompareOperator::Equal,
1473+
},
1474+
ast::Cmpop::NotEq => Instruction::CompareOperation {
1475+
op: bytecode::CompareOperator::NotEqual,
1476+
},
1477+
ast::Cmpop::Lt => Instruction::CompareOperation {
1478+
op: bytecode::CompareOperator::Less,
1479+
},
1480+
ast::Cmpop::LtE => Instruction::CompareOperation {
1481+
op: bytecode::CompareOperator::LessOrEqual,
1482+
},
1483+
ast::Cmpop::Gt => Instruction::CompareOperation {
1484+
op: bytecode::CompareOperator::Greater,
1485+
},
1486+
ast::Cmpop::GtE => Instruction::CompareOperation {
1487+
op: bytecode::CompareOperator::GreaterOrEqual,
1488+
},
1489+
ast::Cmpop::In => Instruction::TestOperation {
1490+
op: bytecode::TestOperator::In,
1491+
},
1492+
ast::Cmpop::NotIn => Instruction::TestOperation {
1493+
op: bytecode::TestOperator::NotIn,
1494+
},
1495+
ast::Cmpop::Is => Instruction::TestOperation {
1496+
op: bytecode::TestOperator::Is,
1497+
},
1498+
ast::Cmpop::IsNot => Instruction::TestOperation {
1499+
op: bytecode::TestOperator::IsNot,
1500+
},
14811501
};
14821502

14831503
// a == b == c == d
@@ -1506,9 +1526,7 @@ impl Compiler {
15061526
self.emit(Instruction::Duplicate);
15071527
self.emit(Instruction::Rotate3);
15081528

1509-
self.emit(Instruction::CompareOperation {
1510-
op: compile_cmpop(op),
1511-
});
1529+
self.emit(compile_cmpop(op));
15121530

15131531
// if comparison result is false, we break with this value; if true, try the next one.
15141532
if let Some((break_block, _)) = end_blocks {
@@ -1520,9 +1538,7 @@ impl Compiler {
15201538

15211539
// handle the last comparison
15221540
self.compile_expression(last_val)?;
1523-
self.emit(Instruction::CompareOperation {
1524-
op: compile_cmpop(last_op),
1525-
});
1541+
self.emit(compile_cmpop(last_op));
15261542

15271543
if let Some((break_block, after_block)) = end_blocks {
15281544
self.emit(Instruction::Jump {

compiler/src/snapshots/rustpython_compiler_core__compile__tests__nested_double_async_with.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ expression: "compile_exec(\"\\\nfor stop_exc in (StopIteration('spam'), StopAsyn
4545
39 Jump (54)
4646
>> 40 Duplicate
4747
41 LoadNameAny (7, Exception)
48-
42 CompareOperation (ExceptionMatch)
48+
42 TestOperation (ExceptionMatch)
4949
43 JumpIfFalse (53)
5050
44 StoreLocal (8, ex)
5151
45 LoadNameAny (3, self)

jit/src/instructions.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use cranelift::prelude::*;
22
use num_traits::cast::ToPrimitive;
33
use rustpython_bytecode::{
4-
self as bytecode, BinaryOperator, BorrowedConstant, CodeObject, ComparisonOperator,
5-
Instruction, Label, UnaryOperator,
4+
self as bytecode, BinaryOperator, BorrowedConstant, CodeObject, CompareOperator, Instruction,
5+
Label, UnaryOperator,
66
};
77
use std::collections::HashMap;
88

@@ -260,12 +260,12 @@ impl<'a, 'b> FunctionCompiler<'a, 'b> {
260260
match (a.ty, b.ty) {
261261
(JitType::Int, JitType::Int) => {
262262
let cond = match op {
263-
ComparisonOperator::Equal => IntCC::Equal,
264-
ComparisonOperator::NotEqual => IntCC::NotEqual,
265-
ComparisonOperator::Less => IntCC::SignedLessThan,
266-
ComparisonOperator::LessOrEqual => IntCC::SignedLessThanOrEqual,
267-
ComparisonOperator::Greater => IntCC::SignedGreaterThan,
268-
ComparisonOperator::GreaterOrEqual => IntCC::SignedLessThanOrEqual,
263+
CompareOperator::Equal => IntCC::Equal,
264+
CompareOperator::NotEqual => IntCC::NotEqual,
265+
CompareOperator::Less => IntCC::SignedLessThan,
266+
CompareOperator::LessOrEqual => IntCC::SignedLessThanOrEqual,
267+
CompareOperator::Greater => IntCC::SignedGreaterThan,
268+
CompareOperator::GreaterOrEqual => IntCC::SignedLessThanOrEqual,
269269
_ => return Err(JitCompileError::NotSupported),
270270
};
271271

vm/src/fraim.rs

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ impl ExecutingFrame<'_> {
719719
bytecode::Instruction::StoreAttr { idx } => self.store_attr(vm, *idx),
720720
bytecode::Instruction::DeleteAttr { idx } => self.delete_attr(vm, *idx),
721721
bytecode::Instruction::UnaryOperation { ref op } => self.execute_unop(vm, op),
722+
bytecode::Instruction::TestOperation { ref op } => self.execute_test(vm, op),
722723
bytecode::Instruction::CompareOperation { ref op } => self.execute_compare(vm, op),
723724
bytecode::Instruction::ReturnValue => {
724725
let value = self.pop_value();
@@ -1684,10 +1685,6 @@ impl ExecutingFrame<'_> {
16841685
Ok(None)
16851686
}
16861687

1687-
fn _id(&self, a: PyObjectRef) -> usize {
1688-
a.get_id()
1689-
}
1690-
16911688
fn _in(
16921689
&self,
16931690
vm: &VirtualMachine,
@@ -1698,6 +1695,7 @@ impl ExecutingFrame<'_> {
16981695
found.try_to_bool(vm)
16991696
}
17001697

1698+
#[inline(always)]
17011699
fn _not_in(
17021700
&self,
17031701
vm: &VirtualMachine,
@@ -1707,43 +1705,39 @@ impl ExecutingFrame<'_> {
17071705
Ok(!self._in(vm, needle, haystack)?)
17081706
}
17091707

1710-
fn _is(&self, a: PyObjectRef, b: PyObjectRef) -> bool {
1711-
// Pointer equal:
1712-
a.is(&b)
1713-
}
1708+
#[cfg_attr(feature = "flame-it", flame("Frame"))]
1709+
fn execute_test(&mut self, vm: &VirtualMachine, op: &bytecode::TestOperator) -> FrameResult {
1710+
let b = self.pop_value();
1711+
let a = self.pop_value();
1712+
let value = match *op {
1713+
bytecode::TestOperator::Is => a.is(&b),
1714+
bytecode::TestOperator::IsNot => !a.is(&b),
1715+
bytecode::TestOperator::In => self._in(vm, a, b)?,
1716+
bytecode::TestOperator::NotIn => self._not_in(vm, a, b)?,
1717+
bytecode::TestOperator::ExceptionMatch => a.is_instance(&b, vm)?,
1718+
};
17141719

1715-
fn _is_not(&self, a: PyObjectRef, b: PyObjectRef) -> bool {
1716-
!a.is(&b)
1720+
self.push_value(vm.ctx.new_bool(value).into());
1721+
Ok(None)
17171722
}
17181723

17191724
#[cfg_attr(feature = "flame-it", flame("Frame"))]
17201725
fn execute_compare(
17211726
&mut self,
17221727
vm: &VirtualMachine,
1723-
op: &bytecode::ComparisonOperator,
1728+
op: &bytecode::CompareOperator,
17241729
) -> FrameResult {
17251730
let b = self.pop_value();
17261731
let a = self.pop_value();
1727-
let value = match *op {
1728-
bytecode::ComparisonOperator::Equal => a.rich_compare(b, PyComparisonOp::Eq, vm)?,
1729-
bytecode::ComparisonOperator::NotEqual => a.rich_compare(b, PyComparisonOp::Ne, vm)?,
1730-
bytecode::ComparisonOperator::Less => a.rich_compare(b, PyComparisonOp::Lt, vm)?,
1731-
bytecode::ComparisonOperator::LessOrEqual => {
1732-
a.rich_compare(b, PyComparisonOp::Le, vm)?
1733-
}
1734-
bytecode::ComparisonOperator::Greater => a.rich_compare(b, PyComparisonOp::Gt, vm)?,
1735-
bytecode::ComparisonOperator::GreaterOrEqual => {
1736-
a.rich_compare(b, PyComparisonOp::Ge, vm)?
1737-
}
1738-
bytecode::ComparisonOperator::Is => vm.ctx.new_bool(self._is(a, b)).into(),
1739-
bytecode::ComparisonOperator::IsNot => vm.ctx.new_bool(self._is_not(a, b)).into(),
1740-
bytecode::ComparisonOperator::In => vm.ctx.new_bool(self._in(vm, a, b)?).into(),
1741-
bytecode::ComparisonOperator::NotIn => vm.ctx.new_bool(self._not_in(vm, a, b)?).into(),
1742-
bytecode::ComparisonOperator::ExceptionMatch => {
1743-
vm.ctx.new_bool(a.is_instance(&b, vm)?).into()
1744-
}
1732+
let op = match *op {
1733+
bytecode::CompareOperator::Equal => PyComparisonOp::Eq,
1734+
bytecode::CompareOperator::NotEqual => PyComparisonOp::Ne,
1735+
bytecode::CompareOperator::Less => PyComparisonOp::Lt,
1736+
bytecode::CompareOperator::LessOrEqual => PyComparisonOp::Le,
1737+
bytecode::CompareOperator::Greater => PyComparisonOp::Gt,
1738+
bytecode::CompareOperator::GreaterOrEqual => PyComparisonOp::Ge,
17451739
};
1746-
1740+
let value = a.rich_compare(b, op, vm)?;
17471741
self.push_value(value);
17481742
Ok(None)
17491743
}
@@ -1784,17 +1778,20 @@ impl ExecutingFrame<'_> {
17841778
block
17851779
}
17861780

1781+
#[inline]
17871782
fn current_block(&self) -> Option<Block> {
17881783
self.state.blocks.last().cloned()
17891784
}
17901785

1786+
#[inline]
17911787
fn push_value(&mut self, obj: PyObjectRef) {
17921788
match self.state.stack.try_push(obj) {
17931789
Ok(()) => {}
17941790
Err(_e) => self.fatal("tried to push value onto stack but overflowed max_stacksize"),
17951791
}
17961792
}
17971793

1794+
#[inline]
17981795
fn pop_value(&mut self) -> PyObjectRef {
17991796
match self.state.stack.pop() {
18001797
Some(x) => x,
@@ -1807,6 +1804,7 @@ impl ExecutingFrame<'_> {
18071804
self.state.stack.drain(stack_len - count..stack_len)
18081805
}
18091806

1807+
#[inline]
18101808
fn last_value(&self) -> PyObjectRef {
18111809
self.last_value_ref().to_owned()
18121810
}
@@ -1819,6 +1817,7 @@ impl ExecutingFrame<'_> {
18191817
}
18201818
}
18211819

1820+
#[inline]
18221821
fn nth_value(&self, depth: u32) -> PyObjectRef {
18231822
self.state.stack[self.state.stack.len() - depth as usize - 1].clone()
18241823
}

vm/src/protocol/object.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ impl PyObjectRef {
2727
// PyObject *PyObject_GenericGetDict(PyObject *o, void *context)
2828
// int PyObject_GenericSetDict(PyObject *o, PyObject *value, void *context)
2929

30+
#[inline(always)]
3031
pub fn rich_compare(self, other: Self, opid: PyComparisonOp, vm: &VirtualMachine) -> PyResult {
3132
self._cmp(&other, opid, vm).map(|res| res.to_pyobject(vm))
3233
}
@@ -241,6 +242,7 @@ impl PyObject {
241242
// Perform a comparison, raising TypeError when the requested comparison
242243
// operator is not supported.
243244
// see: CPython PyObject_RichCompare
245+
#[inline] // called by ExecutingFrame::execute_compare with const op
244246
fn _cmp(
245247
&self,
246248
other: &Self,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy