-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dyno: implement "is default initializable" (#26679)
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
- Loading branch information
Showing
10 changed files
with
326 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.