Skip to content
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

checker: reduce sym resolution calls on infix checking #22476

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions vlib/v/checker/infix.v
Original file line number Diff line number Diff line change
Expand Up @@ -306,23 +306,21 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
right_sym = c.table.sym(unwrapped_right_type)
if mut right_sym.info is ast.Alias && (right_sym.info.language != .c
&& c.mod == c.table.type_to_str(unwrapped_right_type).split('.')[0]
&& (c.table.sym(right_sym.info.parent_type).is_primitive()
|| c.table.sym(right_sym.info.parent_type).kind == .enum)) {
right_sym = c.table.sym(right_sym.info.parent_type)
&& (right_final_sym.is_primitive() || right_final_sym.kind == .enum)) {
right_sym = right_final_sym
}
if mut left_sym.info is ast.Alias && (left_sym.info.language != .c
&& c.mod == c.table.type_to_str(unwrapped_left_type).split('.')[0]
&& (c.table.sym(left_sym.info.parent_type).is_primitive()
|| c.table.sym(left_sym.info.parent_type).kind == .enum)) {
left_sym = c.table.sym(left_sym.info.parent_type)
&& (left_final_sym.is_primitive() || left_final_sym.kind == .enum)) {
left_sym = left_final_sym
}

if c.pref.translated && node.op in [.plus, .minus, .mul]
&& unwrapped_left_type.is_any_kind_of_pointer()
&& unwrapped_right_type.is_any_kind_of_pointer() {
return_type = left_type
} else if !c.pref.translated && left_sym.info is ast.Alias
&& !(c.table.sym(left_sym.info.parent_type).is_primitive()) {
&& !left_final_sym.is_primitive() {
if left_sym.has_method(node.op.str()) {
if method := left_sym.find_method(node.op.str()) {
return_type = method.return_type
Expand All @@ -347,7 +345,7 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {
}
}
} else if !c.pref.translated && right_sym.info is ast.Alias
&& !(c.table.sym(right_sym.info.parent_type).is_primitive()) {
&& !right_final_sym.is_primitive() {
if right_sym.has_method(node.op.str()) {
if method := right_sym.find_method(node.op.str()) {
return_type = method.return_type
Expand Down Expand Up @@ -477,15 +475,13 @@ fn (mut c Checker) infix_expr(mut node ast.InfixExpr) ast.Type {

left_sym = c.table.sym(unwrapped_left_type)
right_sym = c.table.sym(unwrapped_right_type)
if left_sym.info is ast.Alias
&& c.table.sym(left_sym.info.parent_type).is_primitive() {
if left_sym.info is ast.Alias && left_final_sym.is_primitive() {
if left_sym.has_method(node.op.str()) {
if method := left_sym.find_method(node.op.str()) {
return_type = method.return_type
}
}
} else if right_sym.info is ast.Alias
&& c.table.sym(right_sym.info.parent_type).is_primitive() {
} else if right_sym.info is ast.Alias && right_final_sym.is_primitive() {
if right_sym.has_method(node.op.str()) {
if method := right_sym.find_method(node.op.str()) {
return_type = method.return_type
Expand Down
Loading