Skip to content
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

Permit trivial TRVE usage in jass input #893

Merged
merged 7 commits into from Jul 27, 2021
Merged

Permit trivial TRVE usage in jass input #893

merged 7 commits into from Jul 27, 2021

Conversation

Frotty
Copy link
Member

@Frotty Frotty commented Sep 27, 2019

did this for w3p, should work?
Needs some fixing and a test for compiler use.

@Frotty Frotty requested a review from peq September 27, 2019 17:19
Copy link
Collaborator

@peq peq left a comment

Choose a reason for hiding this comment

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

The optimizer is not the only point where variable names might be changed.

  • There might be places where we add a scope name. For example a static variable x in class A would get a name like A_x if I remember correctly.
  • In the translation to Jass names are made unique if they are not. This might also affect global variables.

So I am not sure, if this PR would fix TRVE for all cases. Maybe you can do some tests. It's probably enough for the case of global Jass variables, which should be the most common use of TRVE.

@Frotty
Copy link
Member Author

Frotty commented Oct 6, 2019

Okay I added 2 jass unit tests and did some real world map tests.
This works for direct usage or simply wrapped (hooked) usage.
And yes, the point of this is mainly to support legacy/vJass scripts, not to allow it in wurst.

@Frotty Frotty requested a review from peq October 6, 2019 15:35
@coveralls
Copy link

coveralls commented Oct 6, 2019

Coverage Status

Coverage increased (+0.06%) to 63.289% when pulling 22d4e36 on trve-support into ac55dd4 on master.

@Frotty Frotty changed the title WIP: attempt to permit TRVE usage Permit trivial TRVE usage in jass input Oct 6, 2019
@Frotty
Copy link
Member Author

Frotty commented Jan 3, 2020

I have been using this impl in w3protect for some time - so far without issues. I would like to merge it at some point. I think we should only allow it in Jass though, to prevent the issues discussed.

@Frotty
Copy link
Member Author

Frotty commented Jan 31, 2020

@peq anything stopping this from being merged?

Copy link
Collaborator

@peq peq left a comment

Choose a reason for hiding this comment

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

I guess that some more checks are required for this to work reliably. For example there might be two variables with the same name in Wurst and the compiler will rename one to avoid the conflict.

It would be cleaner to add a special construct to the Im like we did for ExecuteFunc.

However, if you just want this to optimize Gui maps, then you can merge it after the static var is gone.

public void TriggerRegisterVariableEvent(IlConstHandle trigger, ILconstString varName, IlConstHandle opcode, ILconstReal limitval) {
TriggerMock triggerMock = (TriggerMock) trigger.getObj();
// TODO
// triggerMock.registerEvent();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this should just be an empty mock, so remove the Todo?

replacements.add(Pair.create(e, Collections.singletonList(e.getRight())));
}
} else if (e.getLeft() instanceof ImVarArrayAccess) {
ImVarArrayAccess va = (ImVarArrayAccess) e.getLeft();
if (!trans.getReadVariables().contains(va.getVar())) {
if (!trans.getReadVariables().contains(va.getVar()) && !TRVEHelper.protectedVariables.contains(va.getVar().getName())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would it be possible to just count TRVE as a read?

Copy link
Member Author

Choose a reason for hiding this comment

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

how?

import java.util.HashSet;

public class TRVEHelper {
public static final HashSet<String> protectedVariables = new HashSet<>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't use static variables with mutable state.

Copy link
Member Author

Choose a reason for hiding this comment

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

You didn't answer last time. I can't add it as variable to the ImTranslator because I need it in the validator. You want it in the outer scope of that?

WLogger.info("keep: " + varName.getValS());
return;
} else if (e.getArgs().get(1) instanceof ExprVarAccess) {
// Check if this is a two line hook... thanks Bribe
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this for a specific bj function? Maybe add a comment...

Copy link
Member Author

Choose a reason for hiding this comment

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

This is for single nested calls iirc to detect them as statically resolvable. bribe used to use it in his damage engine.

function myfunc (with same params and return typ)
    TriggerRegisterVariableEvent(...)

A bit bad solution maybe :D

@Frotty Frotty merged commit e7c26d3 into master Jul 27, 2021
@Frotty Frotty deleted the trve-support branch July 27, 2021 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants