Skip to content

Commit 53e0787

Browse files
committed
inlining as before, though broken
1 parent 62edd61 commit 53e0787

File tree

2 files changed

+50
-26
lines changed

2 files changed

+50
-26
lines changed

src/compiler.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6768,6 +6768,8 @@ export class Compiler extends DiagnosticEmitter {
67686768
);
67696769
ctorInstance.set(CommonFlags.INSTANCE | CommonFlags.CONSTRUCTOR | CommonFlags.COMPILED);
67706770
classInstance.constructorInstance = ctorInstance;
6771+
var previousFunction = this.currentFunction;
6772+
this.currentFunction = ctorInstance;
67716773

67726774
// generate body
67736775
var module = this.module;
@@ -6799,6 +6801,7 @@ export class Compiler extends DiagnosticEmitter {
67996801
for (let i = 0; i < numParameters; ++i) {
68006802
operands[i + 1] = module.createGetLocal(i + 1, parameterTypes[i].toNativeType());
68016803
}
6804+
// TODO: base constructor might be inlined, but makeCallDirect can't do this
68026805
stmts.push(
68036806
module.createSetLocal(0,
68046807
this.makeCallDirect(assert(baseClass.constructorInstance), operands)
@@ -6818,16 +6821,19 @@ export class Compiler extends DiagnosticEmitter {
68186821
: module.createBlock(null, stmts, nativeSizeType)
68196822
);
68206823
ctorInstance.finalize(module, funcRef);
6824+
this.currentFunction = previousFunction;
68216825
return ctorInstance;
68226826
}
68236827

68246828
compileInstantiate(classInstance: Class, argumentExpressions: Expression[], reportNode: Node): ExpressionRef {
6829+
var ctor = this.ensureConstructor(classInstance, reportNode);
68256830
var expr = this.compileCallDirect(
6826-
this.ensureConstructor(classInstance, reportNode),
6831+
ctor,
68276832
argumentExpressions,
68286833
reportNode,
6829-
this.options.usizeType.toNativeZero(this.module)
6830-
// TODO: inlining
6834+
this.options.usizeType.toNativeZero(this.module),
6835+
ctor.hasDecorator(DecoratorFlags.INLINE)
6836+
// FIXME: trying to inline a constructor that doesn't return a custom value doesn't work
68316837
);
68326838
this.currentType = classInstance.type;
68336839
return expr;
@@ -7809,6 +7815,10 @@ export class Compiler extends DiagnosticEmitter {
78097815

78107816
/** Makes the initializers for a class's fields. */
78117817
makeFieldInitialization(classInstance: Class, stmts: ExpressionRef[] = []): ExpressionRef[] {
7818+
7819+
// must not be used in an inline context as it makes assumptions about local indexes
7820+
assert(!this.currentFunction.flow.is(FlowFlags.INLINE_CONTEXT));
7821+
78127822
if (classInstance.members) {
78137823
let module = this.module;
78147824
let nativeSizeType = this.options.nativeSizeType;
@@ -7833,6 +7843,8 @@ export class Compiler extends DiagnosticEmitter {
78337843
field.memoryOffset
78347844
));
78357845
} else {
7846+
// NOTE: if all fields have initializers then this way is best, but if they don't,
7847+
// it would be more efficient to categorically zero memory on allocation.
78367848
let parameterIndex = (<FieldDeclaration>field.prototype.declaration).parameterIndex;
78377849
stmts.push(module.createStore(fieldType.byteSize,
78387850
module.createGetLocal(0, nativeSizeType),

tests/compiler/std/pointer.untouched.wat

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1760,13 +1760,21 @@
17601760
(local $0 i32)
17611761
(local $1 i32)
17621762
(local $2 f32)
1763-
i32.const 0
1764-
i32.const 8
1765-
call $std/pointer/Pointer<Entry>#constructor
1763+
block $std/pointer/Pointer<Entry>#constructor|inlined.0 (result i32)
1764+
i32.const 0
1765+
set_local $0
1766+
i32.const 8
1767+
set_local $1
1768+
get_local $1
1769+
end
17661770
set_global $std/pointer/one
1767-
i32.const 0
1768-
i32.const 24
1769-
call $std/pointer/Pointer<Entry>#constructor
1771+
block $std/pointer/Pointer<Entry>#constructor|inlined.1 (result i32)
1772+
i32.const 0
1773+
set_local $1
1774+
i32.const 24
1775+
set_local $0
1776+
get_local $0
1777+
end
17701778
set_global $std/pointer/two
17711779
block $std/pointer/Pointer<Entry>#get:offset|inlined.0 (result i32)
17721780
get_global $std/pointer/one
@@ -2108,9 +2116,13 @@
21082116
call $~lib/env/abort
21092117
unreachable
21102118
end
2111-
i32.const 0
2112-
i32.const 0
2113-
call $std/pointer/Pointer<f32>#constructor
2119+
block $std/pointer/Pointer<f32>#constructor|inlined.0 (result i32)
2120+
i32.const 0
2121+
set_local $0
2122+
i32.const 0
2123+
set_local $1
2124+
get_local $1
2125+
end
21142126
set_global $std/pointer/buf
21152127
get_global $std/pointer/buf
21162128
i32.const 0
@@ -2150,11 +2162,11 @@
21502162
end
21512163
block $std/pointer/Pointer<f32>#get|inlined.0 (result f32)
21522164
get_global $std/pointer/buf
2153-
set_local $0
2154-
i32.const 0
21552165
set_local $1
2156-
get_local $0
2166+
i32.const 0
2167+
set_local $0
21572168
get_local $1
2169+
get_local $0
21582170
i32.const 4
21592171
i32.mul
21602172
i32.add
@@ -2173,11 +2185,11 @@
21732185
end
21742186
block $std/pointer/Pointer<f32>#get|inlined.1 (result f32)
21752187
get_global $std/pointer/buf
2176-
set_local $1
2177-
i32.const 1
21782188
set_local $0
2179-
get_local $1
2189+
i32.const 1
2190+
set_local $1
21802191
get_local $0
2192+
get_local $1
21812193
i32.const 4
21822194
i32.mul
21832195
i32.add
@@ -2222,13 +2234,13 @@
22222234
end
22232235
block
22242236
get_global $std/pointer/buf
2225-
set_local $0
2226-
i32.const 2
22272237
set_local $1
2238+
i32.const 2
2239+
set_local $0
22282240
f32.const 1.2999999523162842
22292241
set_local $2
2230-
get_local $0
22312242
get_local $1
2243+
get_local $0
22322244
i32.const 4
22332245
i32.mul
22342246
i32.add
@@ -2251,11 +2263,11 @@
22512263
end
22522264
block $std/pointer/Pointer<f32>#get|inlined.2 (result f32)
22532265
get_global $std/pointer/buf
2254-
set_local $1
2255-
i32.const 2
22562266
set_local $0
2257-
get_local $1
2267+
i32.const 2
2268+
set_local $1
22582269
get_local $0
2270+
get_local $1
22592271
i32.const 4
22602272
i32.mul
22612273
i32.add
@@ -2290,8 +2302,8 @@
22902302
call $std/pointer/Pointer<f32>#set:value
22912303
block $std/pointer/Pointer<f32>#get:value|inlined.0 (result f32)
22922304
get_global $std/pointer/buf
2293-
set_local $0
2294-
get_local $0
2305+
set_local $1
2306+
get_local $1
22952307
f32.load
22962308
br $std/pointer/Pointer<f32>#get:value|inlined.0
22972309
end

0 commit comments

Comments
 (0)