-
-
Notifications
You must be signed in to change notification settings - Fork 272
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wasm gc: add classes that are not directly reachable, but are mention…
…ed in method signatures Rationale: it can be that some function `foo` declares that it takes class C, but class C is never reachable from code (e.g. never get instantiated, and `foo` only takes nulls). In this case it can be that class C has no representation in Wasm module, which can lead to type validation errors.
- Loading branch information
1 parent
7fdaf3c
commit 6a2bd3e
Showing
2 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
core/src/main/java/org/teavm/backend/wasm/gc/WasmGCSignatureDependencyListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2025 Alexey Andreev. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.teavm.backend.wasm.gc; | ||
|
||
import org.teavm.dependency.AbstractDependencyListener; | ||
import org.teavm.dependency.DependencyAgent; | ||
import org.teavm.dependency.FieldDependency; | ||
import org.teavm.dependency.MethodDependency; | ||
import org.teavm.model.ValueType; | ||
|
||
public class WasmGCSignatureDependencyListener extends AbstractDependencyListener { | ||
@Override | ||
public void methodReached(DependencyAgent agent, MethodDependency method) { | ||
for (var i = 0; i < method.getMethod().parameterCount(); ++i) { | ||
linkType(agent, method.getMethod().parameterType(i)); | ||
} | ||
linkType(agent, method.getMethod().getResultType()); | ||
} | ||
|
||
@Override | ||
public void fieldReached(DependencyAgent agent, FieldDependency field) { | ||
linkType(agent, field.getField().getType()); | ||
} | ||
|
||
private void linkType(DependencyAgent agent, ValueType type) { | ||
if (type instanceof ValueType.Object) { | ||
agent.linkClass(((ValueType.Object) type).getClassName()); | ||
} else if (type instanceof ValueType.Array) { | ||
linkType(agent, ((ValueType.Array) type).getItemType()); | ||
} | ||
} | ||
} |