Skip to content

Commit 067c5b6

Browse files
authored
cgen,ast: fix interface conversion codegen race issue (fix #22640, #17943) (#22655)
1 parent be0de59 commit 067c5b6

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

vlib/v/ast/types.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub mut:
191191
methods []Fn
192192
embeds []Type
193193
// `I1 is I2` conversions
194-
conversions map[int][]Type
194+
conversions shared map[int][]Type
195195
// generic interface support
196196
is_generic bool
197197
generic_types []Type

vlib/v/gen/c/cgen.v

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7598,10 +7598,12 @@ fn (mut g Gen) as_cast(node ast.AsCast) {
75987598
g.write(')')
75997599

76007600
mut info := expr_type_sym.info as ast.Interface
7601-
if node.typ !in info.conversions {
7602-
left_variants := g.table.iface_types[expr_type_sym.name]
7603-
right_variants := g.table.iface_types[sym.name]
7604-
info.conversions[node.typ] = left_variants.filter(it in right_variants)
7601+
lock info.conversions {
7602+
if node.typ !in info.conversions {
7603+
left_variants := g.table.iface_types[expr_type_sym.name]
7604+
right_variants := g.table.iface_types[sym.name]
7605+
info.conversions[node.typ] = left_variants.filter(it in right_variants)
7606+
}
76057607
}
76067608
expr_type_sym.info = info
76077609
} else if mut expr_type_sym.info is ast.Interface && node.expr_type != node.typ {

vlib/v/gen/c/infix.v

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -776,18 +776,19 @@ fn (mut g Gen) gen_interface_is_op(node ast.InfixExpr) {
776776
right_sym := g.table.sym(node.right_type)
777777

778778
mut info := left_sym.info as ast.Interface
779-
780-
common_variants := info.conversions[node.right_type] or {
781-
left_variants := g.table.iface_types[left_sym.name]
782-
right_variants := g.table.iface_types[right_sym.name]
783-
c := left_variants.filter(it in right_variants)
784-
info.conversions[node.right_type] = c
785-
c
786-
}
787-
left_sym.info = info
788-
if common_variants.len == 0 {
789-
g.write('false')
790-
return
779+
lock info.conversions {
780+
common_variants := info.conversions[node.right_type] or {
781+
left_variants := g.table.iface_types[left_sym.name]
782+
right_variants := g.table.iface_types[right_sym.name]
783+
c := left_variants.filter(it in right_variants)
784+
info.conversions[node.right_type] = c
785+
c
786+
}
787+
left_sym.info = info
788+
if common_variants.len == 0 {
789+
g.write('false')
790+
return
791+
}
791792
}
792793
g.write('I_${left_sym.cname}_is_I_${right_sym.cname}(')
793794
if node.left_type.is_ptr() {

0 commit comments

Comments
 (0)