Skip to content
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

Adjust polymorphicInstance() #14635

Merged
merged 4 commits into from
Nov 1, 2023

Conversation

cameel
Copy link
Member

@cameel cameel commented Oct 23, 2023

The PR addresses #14510 (comment) and #14510 (comment).

We discussed this last week on the call - unifyGeneralized() was a part of some idea that was not fully realized in the end and all we really need is just a call to TypeEnvironment::fresh(). That's what polymorphicInstance() does now.

The PR also adds some tests covering the uses of fresh() and polymorphicInstances(). This shows that the PR does not break things both here and with my subsequent changes in #14606.

@cameel cameel requested a review from ekpyron October 23, 2023 16:03
@cameel cameel self-assigned this Oct 23, 2023
@cameel cameel requested a review from matheusaaguiar October 23, 2023 16:10
@ekpyron
Copy link
Member

ekpyron commented Oct 23, 2023

The funny thing is: the last thing I did before pushing the prototype was to do the exact opposite :-) - i.e. to introduce polymorphicInstance in the first place in order to isolate the occurrances of fresh() to make it easier to replace them by a mechanism accounting for #14606

@cameel
Copy link
Member Author

cameel commented Oct 23, 2023

Why would it be any easier to replace polymorphicInstance() than to replace fresh()?

@ekpyron
Copy link
Member

ekpyron commented Oct 23, 2023

Why would it be any easier to replace polymorphicInstance() than to replace fresh()?

The point was to collect all instances of refreshening for the purpose of generating a polymorphic schema of a global definition and then checking what's left.

Also: producing a freshened type is a technical operation on the type - producing a polymorphic instance of a global type scheme is a semantic description of what's happening.

@ekpyron
Copy link
Member

ekpyron commented Oct 23, 2023

Also: producing a freshened type is a technical operation on the type - producing a polymorphic instance of a global type scheme is a semantic description of what's happening.

Based on that I'd actually not remove it. (Removing the entire function that gives the operation that happens here a descriptive name is quite different from removing the additional type variable it unnecessarily introduces :-))

@cameel cameel force-pushed the new-analysis-remove-polymorphic-instance branch from 58e6b99 to 2ab295f Compare October 27, 2023 15:03
@cameel cameel changed the title Replace polymorphicInstance() with fresh() Adjust polymorphicInstance() Oct 27, 2023
@cameel
Copy link
Member Author

cameel commented Oct 27, 2023

polymorphicInstance() restored.

@cameel cameel force-pushed the new-analysis-remove-polymorphic-instance branch from 2ab295f to 781a73b Compare October 30, 2023 11:52
@cameel
Copy link
Member Author

cameel commented Oct 30, 2023

I need reapproval. Only pushed a small stylistic tweak.

@cameel cameel requested a review from ekpyron October 30, 2023 12:16
@ekpyron
Copy link
Member

ekpyron commented Oct 30, 2023

Before we merge new changes, we first need to clean up the mess in the base branch.

@cameel cameel force-pushed the new-analysis-remove-polymorphic-instance branch 2 times, most recently from a9bf87f to bc86754 Compare October 30, 2023 16:02
@cameel cameel force-pushed the new-analysis-remove-polymorphic-instance branch 2 times, most recently from acef62d to 8c31a4f Compare October 30, 2023 18:39
@cameel cameel force-pushed the new-analysis-remove-polymorphic-instance branch from 8c31a4f to 5db6e6c Compare November 1, 2023 11:28
@cameel cameel force-pushed the new-analysis-remove-polymorphic-instance branch from 5db6e6c to 0162b8e Compare November 1, 2023 11:30
@cameel
Copy link
Member Author

cameel commented Nov 1, 2023

#14570 (comment)

It may actually make sense to just rename polymorphicInstance to generalize.

I wanted to merge this already, but in that case maybe I should still change it before I do?

@ekpyron
Copy link
Member

ekpyron commented Nov 1, 2023

I wanted to merge this already, but in that case maybe I should still change it before I do?

No hurry, just bringing up the option.

@@ -481,7 +480,10 @@ experimental::Type TypeInference::handleIdentifierByReferencedDeclaration(langut
else if (dynamic_cast<FunctionDefinition const*>(&_declaration))
return polymorphicInstance(*declarationAnnotation.type);
else if (dynamic_cast<TypeClassDefinition const*>(&_declaration))
return polymorphicInstance(*declarationAnnotation.type);
{
solAssert(TypeEnvironmentHelpers{*m_env}.typeVars(*declarationAnnotation.type).empty());
Copy link
Member

Choose a reason for hiding this comment

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

Wait, what? That doesn't seem right - shouldn't there be exactly one variable in there?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, no, this is term context, so the use of the type class name as a special concrete type with its functions attached as members... I hope the distinction will become clearer after the upcoming refactors, we'll see.

Copy link
Member Author

Choose a reason for hiding this comment

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

So fine with merging the PR?

@cameel cameel merged commit 5f43e35 into newAnalysis Nov 1, 2023
1 check passed
@cameel cameel deleted the new-analysis-remove-polymorphic-instance branch November 1, 2023 19:13
cameel added a commit that referenced this pull request Dec 8, 2023
…ic-instance

Adjust `polymorphicInstance()`
cameel added a commit that referenced this pull request Dec 13, 2023
…ic-instance

Adjust `polymorphicInstance()`
cameel added a commit that referenced this pull request Dec 13, 2023
…ic-instance

Adjust `polymorphicInstance()`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants