Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring how optional params work (#505)
Previously, functions with optional parameters would have an additional "mask" parameter at the end which would indicate to if-statements contained within the body of the function whether or not to reassign parameters to their default values if they were omitted. This resulted in a lot of bloated logic within the compiler, and also a performance cost since each time a function with optional parameters was called, those if-statements would run even if all values were passed. The new approach is to compile a separate function instance for each combination of optional parameters, which ultimately calls the base function and passes in the default values for the missing parameters. This allows all decisions to happen at compile-time rather than at runtime, and it's also a LOT simpler to reason about within the compiler itself. The change was also made for types with optional fields, and I also updated enum variants to be able to have optional fields as well. This also has the added benefit of being able to remove the `Pointer.null()` default field value for `String#_buf` (which is a relic of a previous version of the prelude).
- Loading branch information