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

internal: don't instantiate concepts when lifting types #861

Merged

Conversation

zerbina
Copy link
Collaborator

@zerbina zerbina commented Aug 26, 2023

Summary

Don't instantiate invocations of generic concepts when lifting types
(liftParamType). Instead, only turn the invocation into a
tyUserTypeClassInst type.

This removes a usage of semtypinst's "meta-types allowed" mode, and is
thus a step towards removing the latter.

Details

Instead of using instGenericContainer(allowedMetaTypes = true) for
lifting the invocation of generic concepts into a tyUserTypeClassInst,
the invocation is now copied, transitioned to a tyUserTypeClassInst,
and then has the underlying tyUserTypeClass the invocation applies to
added as the last element.

The above is not the same as what instGenericContainer did. Most
importantly, generic invocations used as arguments to the invocation
are not instantiated. In practice, this means that a parameter type like
Concept[Generic[T]] will reach typeRel and subsequently
matchUserTypeClass as

(UserTypeClassInst (...) (GenericInvocation (...) (...)) (...))

instead of as

(UserTypeClassInst (...) (GenericInst (...) (...) (...)) (...))

The tyGenericInvocation has the tfHasMeta flag included and a
tyInferred is thus later created when matching against the concept,
which is correct. Since typeRel does support resolving tyInferred
types that have a tyGenericInvocation as the base, this doesn't cause
problems.

Summary
=======

Don't instantiate invocations of generic concepts when lifting types
(`liftParamType`). Instead, only turn the invocation into a
`tyUserTypeClassInst` type.

This removes a usage of `semtypinst`'s "meta-types allowed" mode, and is
thus a step towards removing the latter.

Details
=======

Instead of using `instGenericContainer(allowedMetaTypes = true)` for
lifting the invocation of generic concepts into a `tyUserTypeClassInst`,
the invocation is now copied, transitioned to a `tyUserTypeClassInst`,
and then has the underlying `tyUserTypeClass` the invocation applies to
added as the last element.

The above is **not** the same as what `instGenericContainer` did. Most
importantly, generic invocations used as arguments to the invocation
are not instantiated. In practice, this means that a parameter type like
`Concept[Generic[T]]` will reach `typeRel` and subsequently
`matchUserTypeClass` as

 `(UserTypeClassInst (...) (GenericInvocation (...) (...)) (...))`

instead of as

`(UserTypeClassInst (...) (GenericInst (...) (...) (...)) (...))`

The `tyGenericInvocation` has the `tfHasMeta` flag included and a
`tyInferred` is thus later created when matching against the concept,
which is correct. Since `typeRel` does support resolving `tyInferred`
types that have a `tyGenericInvocation` as the base, this doesn't cause
problems.
@zerbina zerbina added compiler/sem Related to semantic-analysis system of the compiler simplification Removal of the old, unused, unnecessary or un/under-specified language features. labels Aug 26, 2023
@zerbina zerbina requested a review from saem August 26, 2023 22:46
@zerbina zerbina linked an issue Aug 26, 2023 that may be closed by this pull request
5 tasks
Copy link
Collaborator

@saem saem left a comment

Choose a reason for hiding this comment

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

Hopefully I'm following along correctly, but given the change, if we're doing a sigmatch, then we're deferring instantiation until we're actually comparing an argument and parameter. This seems entirely correct, as we're not losing information/making the decision too quickly, as we're aiming for "late static binding".

@saem
Copy link
Collaborator

saem commented Aug 28, 2023

/merge

@github-actions
Copy link

Merge requested by: @saem

Contents after the first section break of the PR description has been removed and preserved below:


@chore-runner chore-runner bot added this pull request to the merge queue Aug 28, 2023
Merged via the queue into nim-works:devel with commit afaea9c Aug 28, 2023
18 checks passed
@zerbina zerbina deleted the dont-instantiate-concepts-when-lifting branch August 29, 2023 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/sem Related to semantic-analysis system of the compiler simplification Removal of the old, unused, unnecessary or un/under-specified language features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

simplify instantiation of generic types (semtypinst)
2 participants