Skip to content

Conversation

@AjayBrahmakshatriya
Copy link
Collaborator

This is a major change to the internals of BuildIt's dyn_var type and part of the user facing API. Traditionally, for second stage expressions, BuildIt used two main types - dyn_var and builder. While dyn_var is what users declared variables with, builder was the result type for all operators (binary, unary, function call, sq bkt etc). This had a couple of issues -

  1. The intermediate expressions were not typed. This is usually not an issue. However we are trying to implement wrapper types that combine static_var and dyn_var into one and the intermediates would be needed to be typed for that.
  2. Use of auto broke everything. If you did auto x = y + z; x would now be on type builder which is a lightweight handle around the expression. Use of x would now basically substitute the instructions everywhere, which breaks semantics.

We now changed this design to entirely rid of the builder type. dyn_var now can hold intermediate expressions along side standalone variables. They always had this mode for the (cast) operator, but that is the default now for all intermediates.
This however messes with operators returns a little since RVO could erroneously merge declarations with their initialization and we have no control over that. We could do something like dyn_var_mimic (old solution) but that will have the auto problem again. So we use a clever trick of returning dyn_var& instead. This disables RVO and everything works. However to return a lvalue-ref, the returning object needs to be live after the return, so we move the allocation to a separate arena. This arena minimizes the overheads of allocation while avoiding leaks. The operators like binary ops and unary ops refer to the return type of the operators on the stripped type to determine the return type.

Finally, we take this opportunity to remove support for deprecated features like inheriting from dyn_var or my_dyn_var etc. dyn_var is the ONLY way to use dyn_var now. We should probably make it final, but reserving that for later.

A lot of samples have been moved around because of removing deprecated features.

@AjayBrahmakshatriya AjayBrahmakshatriya merged commit 42080ca into BuildIt-lang:master Dec 25, 2025
3 checks passed
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