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

Potential optimisation for addition #109

Closed
TheCodedOne opened this issue Sep 10, 2021 · 2 comments
Closed

Potential optimisation for addition #109

TheCodedOne opened this issue Sep 10, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@TheCodedOne
Copy link

TheCodedOne commented Sep 10, 2021

Is your feature request related to a problem? Please describe.
When doing additive assignment it compiles to something needlessly long sometimes

Describe the solution you'd like
compiler could automatically figure out a simpler addition format

$ a = 0
a+=1
a+=1
a+=1
a+=1
a+=1
a+=1
a+=1
a+=1
a+=1
a+=1
a+=1
a+=1

$ b = 0
b+=a
b+=1
b+=2

compiles to

a=0 a+=1 a+=1 a+=1 a+=1 a+=1 a+=1 a+=1 a+=1 a+=1 a+=1 a+=1 a+=1
b=0 b+=a b+=1 b+=2

realistically could be turned into

a=0+1+1+1+1+1+1+1+1+1+1+1+1
b=0+a+1+2

or further into

a=12
b=a+3

Additional context
It's probably reliant on the type system (#48) for it to be able to work correctly.

It's also a very weird case, there's always the option of just manually making sure your additions are as optimised as they can be, which is obviously the preferred way anyway, however depending on the complexity of implementation could be worth the potential for optimisations

@TheCodedOne TheCodedOne added the enhancement New feature or request label Sep 10, 2021
@dbaumgarten
Copy link
Owner

What you are suggesting is basically a subest of the feature suggested in #52 .

That would be a relatively safe way to create expressions of optimal length. Automatically splitting large expressions into smaller once, would be an alternative, but could result in a lot of unexpected timing-behaviour.
Having large expressions defined as multiple small assignments, which are then combined into a minimal amount of expressions seems much safer.

The only hard part about this is, that merging the assignments must be postponed until it is known how much space is left on the previous line, so that it results in the maximum code-density.

I think that might even be possible without a type-system.

@dbaumgarten
Copy link
Owner

In an effort to clean up a little, I am closing this as a duplicate of #52

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants