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

VIP: Inlineable functions #1677

Open
charles-cooper opened this issue Nov 1, 2019 · 3 comments
Open

VIP: Inlineable functions #1677

charles-cooper opened this issue Nov 1, 2019 · 3 comments

Comments

@charles-cooper
Copy link
Member

charles-cooper commented Nov 1, 2019

Simple Summary

Allow functions to be inlined

Motivation

Private functions are expensive because of frame switching. Allowing functions to be inlineable allows us to skip that overhead.

Specification

Add a decorator @inline which allows the user to force a function to be inlined. (In the future, the compiler could theoretically use heuristics to decide whether or not to inline a function but that is out of this scope). @inline is only compatible with @private functions. When the compiler sees that it should inline the code but with new variable names and so forth.

(Note: parameters should either not be writeable or pass-by-copy)

example:

@private
@inline 
def priv():
  x: uint256 = 1
  return x + 2
@public
def foo():
  return self.priv() + 3

should have roughly the same output as

@public
def foo():
  priv_x: uint256 = 1
  return (priv_x + 2) + 3

Backwards Compatibility

No incompatibilities

Dependencies

No known dependencies

Copyright

Copyright and related rights waived via CC0

@fubuloubu
Copy link
Member

fubuloubu commented Nov 1, 2019

The name-mangling on private variables should make it not possible to write a variable in the enclosing function that would override that behavior.

Otherwise, all for this. Our private functions suck.

@jacqueswww
Copy link
Contributor

jacqueswww commented Nov 5, 2019

This is a good idea, to be fair: @fubuloubu Our private functions are efficient in certain cases where inline functions ones wouldn't be again. Also inline increases bytecode very quickly.

The cool thing about this is that the base for this functionality already occurs in sqrt ;)

@charles-cooper
Copy link
Member Author

charles-cooper commented Feb 21, 2025

this is added in #4481

cf. also #4478 which performs automatic inlining. so i'm not sure we actually need user-tunable inlines anymore -- we should wait 1-2 release cycles for user feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants