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

Should we allow extension structs with multiple fields? #2371

Closed
Tracked by #2360
leafpetersen opened this issue Jul 29, 2022 · 2 comments
Closed
Tracked by #2360

Should we allow extension structs with multiple fields? #2371

leafpetersen opened this issue Jul 29, 2022 · 2 comments
Assignees
Labels
data-classes extension-types inline-classes Cf. language/accepted/future-releases/inline-classes/feature-specification.md structs

Comments

@leafpetersen
Copy link
Member

leafpetersen commented Jul 29, 2022

In the extension struct proposal (#2360), I propose extension structs as a way to support wrapper-less views on an underlying representation (see the meta-issue for linked context). In the proposal, I only allow a single field to be declared on the extension struct. This is so that the extension struct may be represented at runtime simply as the value of that field. There are two ways that we could consider allowing multiple fields:

  • We could say that extension structs with multiple fields get wrapped into a container object (essentially auto-boxing).
  • We could say that an extension struct with multiple fields is simply an unboxed aggregate, which is not a subtype of Object, but which represents the equivalent of a raw C struct, with move semantics.

The former is unappealing to me, since the entire goal of this feature is to avoid implicit wrapping.

The second has some appeal, but feels somewhat under-motivated.

This issue is for discussion and feedback on this.

@leafpetersen
Copy link
Member Author

@lrhn
Copy link
Member

lrhn commented Jul 31, 2022

An extension struct is not a struct. It's a view.
When we get records, you can make a view on a tuple if that's what you want.

I see no motivating reason to allow it directly in an extension struct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data-classes extension-types inline-classes Cf. language/accepted/future-releases/inline-classes/feature-specification.md structs
Projects
None yet
Development

No branches or pull requests

3 participants