Remove error-prone source_id
from TypeEngine::insert()
and make inserting API more robust and less verbose
#5991
Labels
compiler: frontend
Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
compiler
General compiler. Should eventually become more specific as the issue is triaged
In the
TypeEngine::insert()
method, thesource_id
parameter makes sense and should be provided only for the types that can actually be defined in source files, e.g.,TypeInfo::Enum
orTypeInfo::Struct
. Actually, for such types it must be provided in order for garbage collection to work properly.For types like e.g.
TypeInfo::Array
thesource_id
makes no sense as well as for all the built in types. E.g. callingte.insert(engines, TypeInfo::Numeric, some_span.source_id())
makes no sense.The current signature of
insert()
is quite error-prone in that regard and verbose in many cases (e.g. inserting built-in types). The caller has to choose the validsource_id
(orNone
) although the choice is actually determined by the type being inserted. E.g. if we are inserting an enum thesource_id
must always come from the enum decl span. Currently, since we are inserting same types at various places, it is only the convention that makes thesource_id
always the same.Also, we have places in code where
source_id
should beNone
(insertingTypeInfo::Array
for example) but it is set to a value (source of the array element span in that particular case, although it makes no sense).Therefore, the proposal is to make the
insert()
API secure in regard tosource_id
and less verbose at the same time by:source_id
it from theinsert()
method and infer it based on the inserted type.engines.se().get_autogenerated_source_id(module_id)
)Unknown
or built-in types.The text was updated successfully, but these errors were encountered: