ast: cleanup in generic_insts_to_concrete() (#14724)

master
yuyi 2022-06-09 04:17:03 +08:00 committed by GitHub
parent 8563696476
commit e6580fefaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 17 deletions

View File

@ -1947,12 +1947,12 @@ pub fn (mut t Table) replace_generic_type(typ Type, generic_types []Type) {
// generic struct instantiations to concrete types // generic struct instantiations to concrete types
pub fn (mut t Table) generic_insts_to_concrete() { pub fn (mut t Table) generic_insts_to_concrete() {
for mut typ in t.type_symbols { for mut sym in t.type_symbols {
if typ.kind == .generic_inst { if sym.kind == .generic_inst {
info := typ.info as GenericInst info := sym.info as GenericInst
parent := t.type_symbols[info.parent_idx] parent := t.type_symbols[info.parent_idx]
if parent.kind == .placeholder { if parent.kind == .placeholder {
typ.kind = .placeholder sym.kind = .placeholder
continue continue
} }
match parent.info { match parent.info {
@ -1982,15 +1982,15 @@ pub fn (mut t Table) generic_insts_to_concrete() {
parent_info.concrete_types = info.concrete_types.clone() parent_info.concrete_types = info.concrete_types.clone()
parent_info.fields = fields parent_info.fields = fields
parent_info.parent_type = new_type(info.parent_idx).set_flag(.generic) parent_info.parent_type = new_type(info.parent_idx).set_flag(.generic)
typ.info = Struct{ sym.info = Struct{
...parent_info ...parent_info
is_generic: false is_generic: false
concrete_types: info.concrete_types.clone() concrete_types: info.concrete_types.clone()
fields: fields fields: fields
parent_type: new_type(info.parent_idx).set_flag(.generic) parent_type: new_type(info.parent_idx).set_flag(.generic)
} }
typ.is_pub = true sym.is_pub = true
typ.kind = parent.kind sym.kind = parent.kind
parent_sym := t.sym(parent_info.parent_type) parent_sym := t.sym(parent_info.parent_type)
for method in parent_sym.methods { for method in parent_sym.methods {
@ -2034,7 +2034,7 @@ pub fn (mut t Table) generic_insts_to_concrete() {
param.typ = pt param.typ = pt
} }
} }
typ.register_method(method) sym.register_method(method)
} }
mut all_methods := parent.methods mut all_methods := parent.methods
for imethod in imethods { for imethod in imethods {
@ -2044,7 +2044,7 @@ pub fn (mut t Table) generic_insts_to_concrete() {
} }
} }
} }
typ.info = Interface{ sym.info = Interface{
...parent_info ...parent_info
is_generic: false is_generic: false
concrete_types: info.concrete_types.clone() concrete_types: info.concrete_types.clone()
@ -2052,9 +2052,9 @@ pub fn (mut t Table) generic_insts_to_concrete() {
methods: imethods methods: imethods
parent_type: new_type(info.parent_idx).set_flag(.generic) parent_type: new_type(info.parent_idx).set_flag(.generic)
} }
typ.is_pub = true sym.is_pub = true
typ.kind = parent.kind sym.kind = parent.kind
typ.methods = all_methods sym.methods = all_methods
} else { } else {
util.verror('generic error', 'the number of generic types of interface `$parent.name` is inconsistent with the concrete types') util.verror('generic error', 'the number of generic types of interface `$parent.name` is inconsistent with the concrete types')
} }
@ -2078,8 +2078,8 @@ pub fn (mut t Table) generic_insts_to_concrete() {
} }
for i in 0 .. variants.len { for i in 0 .. variants.len {
if variants[i].has_flag(.generic) { if variants[i].has_flag(.generic) {
sym := t.sym(variants[i]) t_sym := t.sym(variants[i])
if sym.kind == .struct_ && variants[i].idx() != info.parent_idx { if t_sym.kind == .struct_ && variants[i].idx() != info.parent_idx {
variants[i] = t.unwrap_generic_type(variants[i], generic_names, variants[i] = t.unwrap_generic_type(variants[i], generic_names,
info.concrete_types) info.concrete_types)
} else { } else {
@ -2091,7 +2091,7 @@ pub fn (mut t Table) generic_insts_to_concrete() {
} }
} }
} }
typ.info = SumType{ sym.info = SumType{
...parent_info ...parent_info
is_generic: false is_generic: false
concrete_types: info.concrete_types.clone() concrete_types: info.concrete_types.clone()
@ -2099,8 +2099,8 @@ pub fn (mut t Table) generic_insts_to_concrete() {
variants: variants variants: variants
parent_type: new_type(info.parent_idx).set_flag(.generic) parent_type: new_type(info.parent_idx).set_flag(.generic)
} }
typ.is_pub = true sym.is_pub = true
typ.kind = parent.kind sym.kind = parent.kind
} else { } else {
util.verror('generic error', 'the number of generic types of sumtype `$parent.name` is inconsistent with the concrete types') util.verror('generic error', 'the number of generic types of sumtype `$parent.name` is inconsistent with the concrete types')
} }