mirror of
https://github.com/fluencelabs/assemblyscript
synced 2025-04-25 23:12:19 +00:00
Also handle indirect recursive inlining
This commit is contained in:
parent
4b8500355a
commit
1928f46cb9
2
dist/assemblyscript.js
vendored
2
dist/assemblyscript.js
vendored
File diff suppressed because one or more lines are too long
2
dist/assemblyscript.js.map
vendored
2
dist/assemblyscript.js.map
vendored
File diff suppressed because one or more lines are too long
@ -265,8 +265,8 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
currentFunction: Function;
|
currentFunction: Function;
|
||||||
/** Current outer function in compilation, if compiling a function expression. */
|
/** Current outer function in compilation, if compiling a function expression. */
|
||||||
currentOuterFunction: Function | null = null;
|
currentOuterFunction: Function | null = null;
|
||||||
/** Current inline function in compilation. */
|
/** Current inline functions stack. */
|
||||||
currentInlineFunction: Function | null = null;
|
currentInlineFunctions: Function[] = [];
|
||||||
/** Current enum in compilation. */
|
/** Current enum in compilation. */
|
||||||
currentEnum: Enum | null = null;
|
currentEnum: Enum | null = null;
|
||||||
/** Current type in compilation. */
|
/** Current type in compilation. */
|
||||||
@ -5259,20 +5259,16 @@ export class Compiler extends DiagnosticEmitter {
|
|||||||
// Inline if explicitly requested
|
// Inline if explicitly requested
|
||||||
if (inline) {
|
if (inline) {
|
||||||
assert(!instance.is(CommonFlags.TRAMPOLINE)); // doesn't make sense
|
assert(!instance.is(CommonFlags.TRAMPOLINE)); // doesn't make sense
|
||||||
if (instance === this.currentInlineFunction) {
|
if (this.currentInlineFunctions.includes(instance)) {
|
||||||
// skip inlining when trying to inline a function into itself and print a warning when
|
this.warning(
|
||||||
// instead compiling the function the normal way.
|
DiagnosticCode.Function_0_cannot_be_inlined_into_itself,
|
||||||
if (instance === this.currentFunction) {
|
reportNode.range, instance.internalName
|
||||||
this.warning(
|
);
|
||||||
DiagnosticCode.Function_0_cannot_be_inlined_into_itself,
|
|
||||||
reportNode.range, instance.internalName
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
this.currentInlineFunction = instance;
|
this.currentInlineFunctions.push(instance);
|
||||||
let ret = this.compileCallInlineUnchecked(instance, argumentExpressions, reportNode, thisArg);
|
let expr = this.compileCallInlineUnchecked(instance, argumentExpressions, reportNode, thisArg);
|
||||||
this.currentInlineFunction = null;
|
this.currentInlineFunctions.pop();
|
||||||
return ret;
|
return expr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,16 @@
|
|||||||
(type $v (func))
|
(type $v (func))
|
||||||
(memory $0 0)
|
(memory $0 0)
|
||||||
(export "foo" (func $inlining-recursive/foo))
|
(export "foo" (func $inlining-recursive/foo))
|
||||||
|
(export "baz" (func $inlining-recursive/baz))
|
||||||
|
(export "bar" (func $inlining-recursive/bar))
|
||||||
(export "memory" (memory $0))
|
(export "memory" (memory $0))
|
||||||
(func $inlining-recursive/foo (; 0 ;) (type $v)
|
(func $inlining-recursive/foo (; 0 ;) (type $v)
|
||||||
(call $inlining-recursive/foo)
|
(call $inlining-recursive/foo)
|
||||||
)
|
)
|
||||||
|
(func $inlining-recursive/baz (; 1 ;) (type $v)
|
||||||
|
(call $inlining-recursive/bar)
|
||||||
|
)
|
||||||
|
(func $inlining-recursive/bar (; 2 ;) (type $v)
|
||||||
|
(call $inlining-recursive/baz)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
@ -1,4 +1,18 @@
|
|||||||
|
// direct
|
||||||
|
|
||||||
@inline
|
@inline
|
||||||
export function foo(): void {
|
export function foo(): void {
|
||||||
foo();
|
foo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// indirect
|
||||||
|
|
||||||
|
@inline
|
||||||
|
export function bar(): void {
|
||||||
|
baz();
|
||||||
|
}
|
||||||
|
|
||||||
|
@inline
|
||||||
|
export function baz(): void {
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
@ -3,10 +3,22 @@
|
|||||||
(global $HEAP_BASE i32 (i32.const 8))
|
(global $HEAP_BASE i32 (i32.const 8))
|
||||||
(memory $0 0)
|
(memory $0 0)
|
||||||
(export "foo" (func $inlining-recursive/foo))
|
(export "foo" (func $inlining-recursive/foo))
|
||||||
|
(export "baz" (func $inlining-recursive/baz))
|
||||||
|
(export "bar" (func $inlining-recursive/bar))
|
||||||
(export "memory" (memory $0))
|
(export "memory" (memory $0))
|
||||||
(func $inlining-recursive/foo (; 0 ;) (type $v)
|
(func $inlining-recursive/foo (; 0 ;) (type $v)
|
||||||
(block $inlining-recursive/foo|inlined.0
|
(block $inlining-recursive/foo|inlined.0
|
||||||
(call $inlining-recursive/foo)
|
(call $inlining-recursive/foo)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
(func $inlining-recursive/baz (; 1 ;) (type $v)
|
||||||
|
(call $inlining-recursive/bar)
|
||||||
|
)
|
||||||
|
(func $inlining-recursive/bar (; 2 ;) (type $v)
|
||||||
|
(block $inlining-recursive/baz|inlined.0
|
||||||
|
(block $inlining-recursive/bar|inlined.0
|
||||||
|
(call $inlining-recursive/baz)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user