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

DCE Removing Commands #27

Open
Vurv78 opened this issue May 13, 2021 · 2 comments
Open

DCE Removing Commands #27

Vurv78 opened this issue May 13, 2021 · 2 comments
Labels

Comments

@Vurv78
Copy link

Vurv78 commented May 13, 2021

Dunno if you'd consider this an issue, but with --dce full commands get removed, maybe there's a way through the Compiler/Context class or something to stop this automatically.

It confused me for a while and some people might want to use dce everywhere else without putting @:keep on their CommandBot class / all of the commands.

@RaidAndFade
Copy link
Owner

That's natural, your command is considered "Dead code" because it is not referenced during compile time. @:keep is the correct resolution.

Alternatively, don't do --dce at all, since realistically it wont help much in an app like this

@Vurv78
Copy link
Author

Vurv78 commented Oct 22, 2021

Yes, but the problem is that this is unclear and confusing to deal with.
It could easily be fixed just by adding @:keepSub to the CommandBot parent class.

Ideally you would make a macro like this (Unfinished code. Think you'd just use https://api.haxe.org/haxe/macro/Compiler.html?#keep)?

@:autoBuild(KeepCommands.keep())
class CommandBot {}

class Test extends CommandBot {
	static function main() {
		// Setup
	}

	@Command
	function ping(message) {
		message.react("");
		message.reply({content: "Pong!"});
	}
}
import haxe.macro.Context;
import haxe.macro.Expr;

class KeepCommands {
	macro static function keep():Array<Field> {
		final t = Context.getLocalType();
		switch (t) {
			case TInst(typ, params):
				// Check for functions that have @Command metadata, and @:keep them
			default:
				// Compile error
				throw "";
		}
		return null;
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants