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

Implement prim 'has default value' #26678

Closed
wants to merge 4 commits into from

Conversation

riftEmber
Copy link
Member

No description provided.

@riftEmber
Copy link
Member Author

Closing as unintentionally duplicating work from #26679 (oof, my bad)

@riftEmber riftEmber closed this Feb 7, 2025
@riftEmber riftEmber deleted the prim-type-has-default branch February 7, 2025 21:37
@riftEmber riftEmber restored the prim-type-has-default branch February 7, 2025 21:37
DanilaFe added a commit that referenced this pull request Feb 10, 2025
This PR implements the `type has default value` primitive. For the most
part, I attempted to mimic the approach used by production. This for the
most part boils down to checking fields then invoking `init()`, except
for some special cases like array types (which are default-initializable
if their elements are) and classes (which are always
default-initializable if they are nilable, and never otherwise).

There's some trickiness involved: "default initialization" sometimes
involves invoking `init` with some actuals. Specifically, in the case of
generic types, each `type` and `param` substitution gets turned into an
actual to resolve the corresponding initializer. This enables resolving
initializers that only require types / params that are already provided
as substitutions for the type. To implement this, extract existing logic
for adding substitutions as actuals from `Resolver.cpp` (for its use in
`new` resolution) and share it with the new initializer call builder and
existing logic in `call-init-deinit.cpp`

While this PR generally follows the production compiler's behavior,
following a comparison with #26678 I noticed some dd behaviors. Most
notably, default generic types such as `numeric` are treated as having a
default initializer. these cases likely don't occur in practice because
they are wrapped in function calls (and thus, only things that
instantiate these types are actually fed to the primitive). Thus, I
chose to match Anna's approach and mark those as generic.

Reviewed by @riftEmber -- thanks!

## Testing
- [x] dyno tests
- [x] paratest
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.

1 participant