checker,cgen: use faster `sym.idx == ast.error_type_idx` integer comparisons, instead of `sym.name == "IError"`
parent
62032c43db
commit
4c7cdd2a2d
|
@ -87,8 +87,8 @@ pub fn (mut c Checker) check_types(got ast.Type, expected ast.Type) bool {
|
||||||
}
|
}
|
||||||
if expected.has_flag(.optional) {
|
if expected.has_flag(.optional) {
|
||||||
sym := c.table.sym(got)
|
sym := c.table.sym(got)
|
||||||
if (sym.kind == .interface_ && sym.name == 'IError')
|
if sym.idx == ast.error_type_idx || got in [ast.none_type, ast.error_type] {
|
||||||
|| got in [ast.none_type, ast.error_type] {
|
// IErorr
|
||||||
return true
|
return true
|
||||||
} else if !c.check_basic(got, expected.clear_flag(.optional)) {
|
} else if !c.check_basic(got, expected.clear_flag(.optional)) {
|
||||||
return false
|
return false
|
||||||
|
|
|
@ -1375,7 +1375,8 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
|
||||||
method := c.table.find_method_with_embeds(typ_sym, imethod.name) or {
|
method := c.table.find_method_with_embeds(typ_sym, imethod.name) or {
|
||||||
// >> Hack to allow old style custom error implementations
|
// >> Hack to allow old style custom error implementations
|
||||||
// TODO: remove once deprecation period for `IError` methods has ended
|
// TODO: remove once deprecation period for `IError` methods has ended
|
||||||
if inter_sym.name == 'IError' && (imethod.name == 'msg' || imethod.name == 'code') {
|
if inter_sym.idx == ast.error_type_idx
|
||||||
|
&& (imethod.name == 'msg' || imethod.name == 'code') {
|
||||||
c.note("`$styp` doesn't implement method `$imethod.name` of interface `$inter_sym.name`. The usage of fields is being deprecated in favor of methods.",
|
c.note("`$styp` doesn't implement method `$imethod.name` of interface `$inter_sym.name`. The usage of fields is being deprecated in favor of methods.",
|
||||||
pos)
|
pos)
|
||||||
continue
|
continue
|
||||||
|
@ -1421,7 +1422,8 @@ fn (mut c Checker) type_implements(typ ast.Type, interface_type ast.Type, pos to
|
||||||
if utyp != ast.voidptr_type {
|
if utyp != ast.voidptr_type {
|
||||||
// >> Hack to allow old style custom error implementations
|
// >> Hack to allow old style custom error implementations
|
||||||
// TODO: remove once deprecation period for `IError` methods has ended
|
// TODO: remove once deprecation period for `IError` methods has ended
|
||||||
if inter_sym.name == 'IError' && (ifield.name == 'msg' || ifield.name == 'code') {
|
if inter_sym.idx == ast.error_type_idx
|
||||||
|
&& (ifield.name == 'msg' || ifield.name == 'code') {
|
||||||
// do nothing, necessary warnings are already printed
|
// do nothing, necessary warnings are already printed
|
||||||
} else {
|
} else {
|
||||||
// <<
|
// <<
|
||||||
|
|
|
@ -2046,7 +2046,7 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw ast.Type, expected_typ
|
||||||
g.write('.msg))')
|
g.write('.msg))')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if got_sym.kind == .none_ && exp_sym.name == 'IError' {
|
if got_sym.kind == .none_ && exp_sym.idx == ast.error_type_idx {
|
||||||
g.expr(expr)
|
g.expr(expr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -5488,7 +5488,7 @@ static inline __shared__$interface_name ${shared_fn_name}(__shared__$cctype* x)
|
||||||
// >> Hack to allow old style custom error implementations
|
// >> Hack to allow old style custom error implementations
|
||||||
// TODO: remove once deprecation period for `IError` methods has ended
|
// TODO: remove once deprecation period for `IError` methods has ended
|
||||||
// fix MSVC not handling empty struct inits
|
// fix MSVC not handling empty struct inits
|
||||||
if methods.len == 0 && interface_name == 'IError' {
|
if methods.len == 0 && isym.idx == ast.error_type_idx {
|
||||||
methods_struct.writeln('\t\t._method_msg = NULL,')
|
methods_struct.writeln('\t\t._method_msg = NULL,')
|
||||||
methods_struct.writeln('\t\t._method_code = NULL,')
|
methods_struct.writeln('\t\t._method_code = NULL,')
|
||||||
}
|
}
|
||||||
|
|
|
@ -153,7 +153,8 @@ fn (mut g Gen) match_expr_sumtype(node ast.MatchExpr, is_expr bool, cond_var str
|
||||||
typ := branch.exprs[sumtype_index] as ast.TypeNode
|
typ := branch.exprs[sumtype_index] as ast.TypeNode
|
||||||
branch_sym := g.table.sym(g.unwrap_generic(typ.typ))
|
branch_sym := g.table.sym(g.unwrap_generic(typ.typ))
|
||||||
g.write('${dot_or_ptr}_typ == _${sym.cname}_${branch_sym.cname}_index')
|
g.write('${dot_or_ptr}_typ == _${sym.cname}_${branch_sym.cname}_index')
|
||||||
} else if branch.exprs[sumtype_index] is ast.None && sym.name == 'IError' {
|
} else if branch.exprs[sumtype_index] is ast.None
|
||||||
|
&& sym.idx == ast.error_type_idx {
|
||||||
g.write('${dot_or_ptr}_typ == _IError_None___index')
|
g.write('${dot_or_ptr}_typ == _IError_None___index')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue