Compiler refactor: extract type_from_dependencies
#12437
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Two places in the code had a similar logic: computing a node's type from its dependencies. One of the branches actually involved a bit of duplicate logic: checking for the dependencies size first, but then
Type.merge(...)
also checks for the size again.This PR moves that logic to a helper method:
type_from_dependencies
. We could simply callType.merge(dependencies)
instead, but for later refactors I have in mind overridingtype_from_dependencies
for some specific AST nodes. For example, anif
node is currently bound to itsthen
andelse
nodes, putting them in thedependencies
array. But that's not needed: we could overridetype_from_dependencies
forIf
to return the type union of thethen
andelse
node. That way we don't need to store an array of two elements independencies
for everyif
in the program.However, I'd like to do those optimizations in a separate PR to keep things small and easier to review.