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

Inline variable code action #3935

Open
lpil opened this issue Dec 2, 2024 · 7 comments
Open

Inline variable code action #3935

lpil opened this issue Dec 2, 2024 · 7 comments
Labels
help wanted Contributions encouraged priority:medium

Comments

@lpil
Copy link
Member

lpil commented Dec 2, 2024

An action that inlines a variable that is used once

pub fn main() {
  let value = [1, 2, 3]
  list.map(value, run)
  #        ^^^^^
}
pub fn main() {
  list.map([1, 2, 3], run)
}
@lpil lpil added help wanted Contributions encouraged priority:medium labels Dec 2, 2024
@GearsDatapacks
Copy link
Member

The compiler could also perform this optimisation automatically

@lpil
Copy link
Member Author

lpil commented Dec 2, 2024

Not sure what you mean, sorry. What optimisation?

@GearsDatapacks
Copy link
Member

Inlining variables. It's not much of an optimisation by itself, but it allows for further optimisations (just like function inlining).
For example:

let a = 1
a + 2

Becomes:

1 + 2

Which the compiler should be able to infer as (although it doesn't currently):

3

@giacomocavalieri
Copy link
Member

Yeah but I think it's also very much a stylistic choice so having a code action to do it would be really nice

@GearsDatapacks
Copy link
Member

Certainly

@lpil
Copy link
Member Author

lpil commented Dec 3, 2024

I'm not sure what the motivation is there. An optimising compiler may perform that action if it expects that structure to be able to apply later optimisations, but we don't implement any optimisations, and if we did it may not benefit from this.

@GearsDatapacks
Copy link
Member

Yeah perhaps it isn't useful right now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions encouraged priority:medium
Projects
None yet
Development

No branches or pull requests

3 participants