-
Notifications
You must be signed in to change notification settings - Fork 29
Recognize client-local native values in optimizer locality analysis #1221
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
Changes from all commits
72069bb
d395113
ab48151
49ed91f
baba1e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,14 +17,57 @@ | |
|
|
||
| /** | ||
| * Conservative, flow-insensitive analysis for values and functions which may | ||
| * depend on {@code GetLocalPlayer()}. | ||
| * depend on client-local native values such as {@code GetLocalPlayer()} or | ||
| * camera state. | ||
| * | ||
| * Optimizers use this analysis as a barrier. False positives only cost an | ||
| * optimization; false negatives could move synchronized work into a | ||
| * client-local control-flow region. | ||
| */ | ||
| public final class LocalPlayerContextAnalyzer { | ||
|
|
||
| /** | ||
| * Native return values which may differ between clients during the same | ||
| * synchronized execution without requiring user code to mutate local state. | ||
| * Event responses are synchronized, while handles and UI/audio/visual state | ||
| * made local by user code remain the user's responsibility. | ||
| */ | ||
| private static final Set<String> CLIENT_LOCAL_VALUE_SOURCES = Set.of( | ||
| // Player identity and values explicitly documented as asynchronous. | ||
| "GetLocalPlayer", | ||
| "GetLocationZ", | ||
|
|
||
| // Camera state belongs to the local client's camera. | ||
| "GetCameraMargin", | ||
| "GetCameraBoundMinX", | ||
| "GetCameraBoundMinY", | ||
| "GetCameraBoundMaxX", | ||
| "GetCameraBoundMaxY", | ||
| "GetCameraField", | ||
| "GetCameraTargetPositionX", | ||
| "GetCameraTargetPositionY", | ||
| "GetCameraTargetPositionZ", | ||
| "GetCameraTargetPositionLoc", | ||
| "GetCameraEyePositionX", | ||
| "GetCameraEyePositionY", | ||
| "GetCameraEyePositionZ", | ||
| "GetCameraEyePositionLoc", | ||
|
|
||
| // Localized data may vary with the client's language. | ||
| "GetLocalizedString", | ||
| "GetLocalizedHotkey", | ||
| "GetObjectName", | ||
|
Comment on lines
+56
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When clients use different UI skins, AGENTS.md reference: AGENTS.md:L63-L63 Useful? React with 👍 / 👎. |
||
|
|
||
| // Reforged client-local world and client state. | ||
| "BlzGetLocalUnitZ", | ||
|
Frotty marked this conversation as resolved.
|
||
| "BlzGetUnitZ", | ||
| "BlzGetLocalClientWidth", | ||
| "BlzGetLocalClientHeight", | ||
| "BlzIsLocalClientActive", | ||
| "BlzGetMouseFocusUnit", | ||
|
Frotty marked this conversation as resolved.
|
||
| "BlzGetLocale" | ||
| ); | ||
|
|
||
| private final Set<ImVar> localPlayerDependentVars = | ||
| Collections.newSetFromMap(new IdentityHashMap<>()); | ||
| private final Set<ImFunction> localPlayerDependentReturns = | ||
|
|
@@ -75,7 +118,7 @@ public boolean isLocalPlayerDependent(Element element) { | |
| } | ||
| if (element instanceof ImFunctionCall) { | ||
| ImFunctionCall call = (ImFunctionCall) element; | ||
| if (isGetLocalPlayer(call.getFunc()) | ||
| if (isClientLocalValueSource(call.getFunc()) | ||
| || localPlayerDependentReturns.contains(call.getFunc())) { | ||
| return true; | ||
| } | ||
|
|
@@ -98,12 +141,12 @@ public boolean isLocalPlayerDependent(Element element) { | |
|
|
||
| public boolean functionUsesLocalPlayer(ImFunction function) { | ||
| return function != null | ||
| && (isGetLocalPlayer(function) || functionsUsingLocalPlayer.contains(function)); | ||
| && (isClientLocalValueSource(function) || functionsUsingLocalPlayer.contains(function)); | ||
| } | ||
|
|
||
| public boolean functionInliningIsLocalPlayerSensitive(ImFunction function) { | ||
| return function != null | ||
| && (isGetLocalPlayer(function) | ||
| && (isClientLocalValueSource(function) | ||
| || functionsDirectlyUsingLocalPlayer.contains(function) | ||
| || localPlayerDependentReturns.contains(function)); | ||
| } | ||
|
|
@@ -113,15 +156,15 @@ public boolean isLocalPlayerDependent(ImVar variable) { | |
| } | ||
|
|
||
| public boolean isLocalPlayerSource(ImFunction function) { | ||
| return isGetLocalPlayer(function); | ||
| return isClientLocalValueSource(function); | ||
| } | ||
|
|
||
| private void analyze(ImProg prog) { | ||
| sourceFacts.add(unknownDispatchSource); | ||
| for (ImFunction function : ImHelper.calculateFunctionsOfProg(prog)) { | ||
| returnFact(function); | ||
| useFact(function); | ||
| if (isGetLocalPlayer(function)) { | ||
| if (isClientLocalValueSource(function)) { | ||
| addLocalPlayerSource(function); | ||
| } else if (!function.isNative()) { | ||
| indexElement(function.getBody(), function, entryControlFact(function)); | ||
|
|
@@ -298,7 +341,7 @@ private void indexFunctionCall(ImFunctionCall call, ImFunction owner, Object con | |
| if (!called.isNative()) { | ||
| addEnclosingControlDependency(controlContext, entryControlFact(called)); | ||
| } | ||
| if (isGetLocalPlayer(called)) { | ||
| if (isClientLocalValueSource(called)) { | ||
| functionsDirectlyUsingLocalPlayer.add(owner); | ||
| addLocalPlayerSource(called); | ||
| } | ||
|
|
@@ -508,9 +551,9 @@ private Fact(FactKind kind, Object subject) { | |
| } | ||
| } | ||
|
|
||
| private static boolean isGetLocalPlayer(ImFunction function) { | ||
| private static boolean isClientLocalValueSource(ImFunction function) { | ||
| return function != null | ||
| && function.isNative() | ||
| && "GetLocalPlayer".equals(function.getName()); | ||
| && CLIENT_LOCAL_VALUE_SOURCES.contains(function.getName()); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.