Skip to content

Decouple quoted Type interface from encoding V2 #9535

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

Conversation

nicolasstucki
Copy link
Contributor

Before, quoted.Type was defined as

// old
class Type[X <: AnyKind]:
  type T = X

Where T is the proper type of the instance of a Type. This is the type used for all operations within the compiler.

The only purpose of the type X was to be able to write context bounds as [X: Type] and staged types Type[X] instead of
Type { type T = X }.
Unfortunately, the type X makes the assumption that X is known, which implies that instances of Type with unknown types need to be encoded with a whildcard type.
A val t: Type[?] = ... is unusable as we cannot heal staged wildcard types, even though we do have a t.T which can be handled.

Now, we change the definition of Type to only have the type member and rename it to QuotedType.

// new
class QuotedType:
  type T <: AnyKind

This solves the aforementioned limitations with unkown staged types.
Now we are also able to remove the wildcard from QuoteContext.tasty.Type.seal and the result can be used in quotes.

To keep the context bound syntax and provide more descriptive name for the concept, we defined the quoted.Type type alias.

type Type[X <: AnyKind] = QuotedType { type T = X }

Alternative to #9485. This one does not affect the user interface.

@nicolasstucki nicolasstucki changed the title Decouple quoted Type interface from encoding Decouple quoted Type interface from encoding V2 Aug 11, 2020
@nicolasstucki nicolasstucki force-pushed the decouple-quoted-type-interface-from-encoding-2 branch from 22c2f31 to 3b27d0b Compare August 11, 2020 15:43
@nicolasstucki nicolasstucki self-assigned this Aug 11, 2020
Before, `quoted.Type` was defined as

```scala
// old
class Type[X <: AnyKind]:
  type T = X
```

Where `T` is the proper type of the instance of a `Type`. This is the type used for all operations within the compiler.

The only purpose of the type `X` was to be able to write context bounds as `[X: Type]` and staged types `Type[X]` instead of
`Type { type T = X }`.
Unfortunately, the type `X` makes the assumption that `X` is known, which implies that instances of `Type` with unknown types need to be encoded with a whildcard type.
A `val t: Type[?] = ...` is unusable as we cannot heal staged wildcard types, even though we do have a `t.T` which can be handled.

Now, we change the definition of `Type` to only have the type member and rename it to `QuotedType`.
```scala
// new
class QuotedType:
  type T <: AnyKind
```

This solves the aforementioned limitations with unkown staged types.
Now we are also able to remove the wildcard from `QuoteContext.tasty.Type.seal` and the result can be used in quotes.

To keep the context bound syntax and provide more descriptive name for the concept, we defined the `quoted.Type` type alias.

```scala
type Type[X <: AnyKind] = QuotedType { type T = X }
```
@nicolasstucki nicolasstucki force-pushed the decouple-quoted-type-interface-from-encoding-2 branch from 3b27d0b to 8536c98 Compare August 11, 2020 16:53
@nicolasstucki nicolasstucki marked this pull request as ready for review August 11, 2020 18:26
@smarter
Copy link
Member

smarter commented Aug 11, 2020

A val t: Type[?] = ... is unusable as we cannot heal staged wildcard types

What's special about types with wildcards that prevents them from being healed compared to types with abstract type members?

@nicolasstucki
Copy link
Contributor Author

We do not have a way to recover the tag in some situations as we cannot do an implicit search on Type[?] not recover the tag from the path of the type.

@smarter
Copy link
Member

smarter commented Aug 11, 2020

as we cannot do an implicit search on Type[?]

Does that change if you replace Type{?] by QuotedType? I don't really understand where the difference is.

@nicolasstucki
Copy link
Contributor Author

The issue is that in the first one $t might be kept as t.T or might be dealiased to ? (or one of its bounds) which we cannot recover from. In contrast, the second will always be t.T, even if we do not know more about the type.

@smarter
Copy link
Member

smarter commented Aug 11, 2020

might be dealiased to ? (or one of its bounds)

Where does that happen? That seems very wrong to me: a wildcard is a form of existential, it cannot be dealiased in any way without breaking soundness

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.

3 participants