Skip to content

New semantic analyzer: fix recursive type aliases #7091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 1, 2019

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jun 28, 2019

This fixes maximum iteration count errors.

Recursive type aliases still don't work and the behavior is a
regression from the old semantic analyzer. Previously they were
truncated, but now they aren't supported at all. We could perhaps hack
something similar to what we used to have, but I don't think that it's
urgent.

This also breaks some use cases where "semi-recursive" type aliases
were supported previously. The support mechanism caused infinite
expansion for actual recursive type aliases. I couldn't come up with a
simple way to support both, so I decided to prioritize fixing infinite
expansion, as they have a worse impact on user experience.

Work towards #6445.

This fixes maximum iteration count errors.

Recursive type aliases still don't work and the behavior is a
regression from the old semantic analyzer. Previously they were
truncated, but now they aren't supported at all. We could perhaps hack
something similar to what we used to have, but I don't think that it's
urgent.

This also breaks some use cases where "semi-recursive" type aliases
were supported previously. The support mechanism caused infinite
expansion for actual recursive type aliases. I couldn't come up with a
simple way to support both, so I decided to prioritize fixing infinite
expansion, as they have a worse impact on user experience.

Work towards #6445.
@JukkaL JukkaL requested a review from ilevkivskyi June 28, 2019 12:50
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, the regression is a bit sad, but I can live with this.

@@ -2347,7 +2347,7 @@ def check_and_set_up_type_alias(self, s: AssignmentStmt) -> bool:
self.analyze_alias(rvalue, allow_placeholder=True)
if not res:
return False
if self.found_incomplete_ref(tag) or isinstance(res, PlaceholderType):
if self.found_incomplete_ref(tag) or has_placeholder(res):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment that we should only prohibit top-level placeholders as in base classes and NewTypes in long term, and this is a temporary measure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment.

main:4: error: Cannot resolve name "B" (possible cyclic definition)
main:4: error: Cannot resolve name "C" (possible cyclic definition)
main:7: note: Revealed type is 'Any'
main:8: note: Revealed type is 'Any'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like all new failures in this file are because of the problem with nested placeholders. Please add a comment in the existing issue mentioning this, and add links to the issue in these tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new issues about this: #7111

@JukkaL JukkaL merged commit 6f54a6f into master Jul 1, 2019
@ilevkivskyi ilevkivskyi deleted the semanal-recursive-alias branch September 12, 2019 10:02
@ilevkivskyi ilevkivskyi restored the semanal-recursive-alias branch September 12, 2019 10:03
@ilevkivskyi ilevkivskyi deleted the semanal-recursive-alias branch September 12, 2019 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants