Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Local type synonyms#3897

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
rhendric wants to merge2 commits intopurescript:master
base:master
Choose a base branch
Loading
fromrhendric:local-type-synonyms-native

Conversation

rhendric
Copy link
Member

@rhendricrhendric commentedJun 5, 2020
edited
Loading

This is an implementation of#3708 (the ‘native’ implementation; I've abandoned the desugaring approach). I consider it largely if not entirely complete; there may be bugs but in a couple of years of using this atop various versions of PureScript I haven't encountered them. It's only a draft because we haven't arrived at a consensus that#3708 should be implemented.

(Previously this initial comment was a plea for help with an issue that has long since been resolved; anyone who's really curious can look through the edit history but I felt it was misleading to have that be the initial representation of this PR at the current time.)

Closes#3708.

paluh and sigma-andex reacted with heart emoji
@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch 2 times, most recently froma186be0 to4068600CompareJune 5, 2020 03:09
@natefaubion
Copy link
Contributor

For things like this, I recommend using thedebug functions inTypeChecker.Monad, specifically for thisdebugSubstitution, which will print out all the unification variables with either their kinds (if unsolved) or solutions (if solved). In this particular case, the substitution environment before kind checking that synonym is:

?2 = t4?3 = t4?4 :: Type

So the particular unification variable in the error definitely exists. The reason for the error is thatkindOfTypeSynonym callskindsOfAll, which is wrapped inwithFreshSubstitution.withFreshSubstitution sets up an empty substitution environment. You want this for top-level declarations, but clearly not in this case. Your intuition is correct, in that we need to extract some of the logic into something appropriate for local synonyms.

The apparent complexity ofkindsOfAll comes from dealing with recursive type-level binding groups, which is not possible in a local context like this since we disallow recursive type synonyms altogether. Recursive binding groups need to be generalized correctly so that all the kind-polymorphism can be threaded around between them. We don't want to do any of that for local type synonyms. For the most part, you can just call callinferTypeSynonym directly. This will infer the kind of the body, and elaborate the rhs with kind applications. There is some setup though that's done, and a few post-inference checks to account for.

inferTypeSynonym assumes that there is a kind for the type synonym in the environment. For type synonymswithout explicit kind signatures, this should be a fresh unification variable.kindsOfAll sets this up usingexistingSignatureOrFreshKind.inferTypeSynonym will unify against whatever is in the environment.

ThecheckEscapedSkolems check is necessary, and it should already account for types in scope, so I think no changes are necessary here. This just ensures that there are no skolems left over that don't also have an appropriate entry in the type environment. I'm not positive that the main typechecker puts skolems in the type environment though, so that may need some validation.

I don't think thatcheckTypeQuantification is likely necessary. The purpose of this check is to make sure there are no unknowns leftoverafter generalization. This can happen when you have a closed kind application. A term-level analog islength [], wherelength must be instantiated with the type of[], which can be anything. At the kind-level this would be left as an unbound unification variable. I don't believe this would be observable for local type synonyms.

I'm going to guess thatcheckVisibleTypeQuantification is unnecessary. We don't currently support visible quantification. In top-level contexts however it's possible to require this through generalization. Since we are not generalizing local type synonyms, we can probably elide this check.

rhendric reacted with heart emoji

@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch from4068600 to24135e0CompareJune 30, 2020 04:54
@rhendric
Copy link
MemberAuthor

@natefaubion Thank you so much! That was immensely useful.

There are likely a few more edge cases that I haven't yet tested and fixed, but this is now mostly functional.

moduleName <- unsafeCheckCurrentModule
(kind', ty') <- warnAndRethrow (addHint (ErrorInTypeSynonym name) . addHint (positionedError ss)) $ do
checkDuplicateTypeArguments $ map fst args
traverse replaceAllTypeSynonyms . swap =<< kindOfLocalTypeSynonym moduleName (sa, name, args, ty)
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Does there need to be anintroduceSkolemScope in here? I tried it with and without and it didn't seem to make a difference on any tests I could come up with, but it seems to be paired with all the otherreplaceAllTypeSynonymss in this file.

@natefaubion
Copy link
Contributor

We need to support local synonyms in the shadowing lint for both:

  • type synonyms shadowing other type level names
  • type variables in type synonyms shadowing other type variables.

@rhendric
Copy link
MemberAuthor

For the first case:ShadowedName, or a new error constructor?

@natefaubion
Copy link
Contributor

If the types work out, I say reuse it, otherwise a new one.

@rhendric
Copy link
MemberAuthor

Warnings have been added! Most of them were not put in theLinter module proper, since quantifier type variables aren't associated with value declarations until the type checking phase. In theory I imagine this could be changed, but the existing type variable shadowing warning lives in the type checker so that's where I put the new warnings that use the same information. I hope that's reasonable.

@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch from9b529a0 to2a4666eCompareMay 27, 2021 23:43
@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch from2a4666e toe83181dCompareJune 18, 2021 17:23
@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch 2 times, most recently from56baea1 to953acb5CompareJuly 12, 2021 20:02
@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch from953acb5 to7a60917CompareDecember 11, 2021 21:21
@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch from7a60917 to06a803aCompareFebruary 27, 2022 05:28
@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch 2 times, most recently fromddfb171 to4f80996CompareDecember 9, 2022 00:03
@rhendricrhendric changed the titleSupport local type synonyms nativelyLocal type synonymsJan 19, 2023
@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch from4f80996 to01d8100CompareMarch 16, 2023 19:23
@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch from01d8100 toe15414cCompareJuly 23, 2023 20:52
@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch frome15414c to3e2e2a1CompareApril 16, 2024 03:25
@rhendricrhendricforce-pushed thelocal-type-synonyms-native branch from3e2e2a1 to84242a5CompareApril 16, 2024 19:29
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Feature: local type synonyms
2 participants
@rhendric@natefaubion

[8]ページ先頭

©2009-2025 Movatter.jp