Skip to content

Conversation

CountBleck
Copy link
Member

Changes proposed in this pull request:
⯈ Add an alwaysInline builtin that inlines any inner function calls

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file
@CountBleck
Copy link
Member Author

@JairusSW let me know if anything else is desired for this builtin

Copy link
Member

@HerrCai0907 HerrCai0907 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the difference between inline and this builtin?

@CountBleck
Copy link
Member Author

@HerrCai0907 this gives you fine-grained control over when a function is inlined (by specifying it in the relevant call sites, instead of in the definition).

@JairusSW has an example as to how this would be useful in as-json.

@JairusSW
Copy link
Contributor

@CountBleck would it be possible to just rename it to inline()

@CountBleck
Copy link
Member Author

@CountBleck would it be possible to just rename it to inline()

I originally intended to name it inline, but I didn't want there to be a conflict with the @inline decorator in the TypeScript typings.

Copy link
Member

@HerrCai0907 HerrCai0907 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for implement part.
But I have some concern about design. I think we should avoid to pollute global scope. load / store / call_indirect can be mapped to low level wasm instruction directly so we keep them in global scope. But for alwaysInline and unchecked, I think we should place them in a special namespace or start with some special prefix.

For C++, std library used compiler-implemented function will start with __. some builtin function will start with __builtin. I wonder should we also do something like this?

e.g.
use this like

builtin_opt.unchecked(....) builtin_opt.alwaysInline(....);
@CountBleck
Copy link
Member Author

Sounds like a good idea, but I'm hesitant to rename/move unchecked since that would be a breaking change.

@HerrCai0907
Copy link
Member

Sounds like a good idea, but I'm hesitant to rename/move unchecked since that would be a breaking change.

At least we can start from alwaysInline

@MaxGraey
Copy link
Member

Sounds like a good idea, but I'm hesitant to rename/move unchecked since that would be a breaking change.

How about to use inlined(fn(...)) instead of alwaysInline(fn(...)). It's shorter and consistent with unchecked

@CountBleck
Copy link
Member Author

I'll do that. What do you think about a namespace for inlined/unchecked? We can alias export const unchecked = builtin_opt.unchecked; (or whatever the namespace would be called).

Copy link
Member

@HerrCai0907 HerrCai0907 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still have some concern about adding not so important function in global scope. It may break some code and it is quiet annoyed to find a new suitable function name for user.

Some search result from github, since AS does not have special language identifier, I search for all function named inlined in TS.
https://github.com/search?q=%22+inlined%28%22+language%3ATypeScript+&type=code

@CountBleck
Copy link
Member Author

Some search result from github

I also checked SourceGraph and can't get anything relevant. I'm not opposed to the namespace idea, but idk if it'd inconvenience users without much of a benefit.

@dcodeIO
Copy link
Member

dcodeIO commented Jan 17, 2025

Could this perhaps be a function associated with the existing inline decorator, say inline.always(...)?

@JairusSW
Copy link
Contributor

JairusSW commented Mar 4, 2025

Could this perhaps be a function associated with the existing inline decorator, say inline.always(...)?

I'd tend to agree with this approach, and it can be done like so:

/** Annotates a method, function or constant global as always inlined. */ declare function inline(...args: any[]): any; declare namespace inline { /** Annodates a function call as inlined */ function always(...args: any[]): any; }
@CountBleck
Copy link
Member Author

I didn't realize I left this hanging for so long, sorry!

This builtin operates similar to unchecked, by setting a new FlowFlag that is checked in makeCallDirect in the area where the @inline decorator is checked, thereby achieving the same functionality as it.
@CountBleck CountBleck merged commit 4e7734b into AssemblyScript:main Mar 10, 2025
14 checks passed
@CountBleck CountBleck deleted the inline-builtin branch August 5, 2025 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

5 participants