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

Optimization Feature - Step Functions: Type Hints #493

Open
thantos opened this issue Sep 11, 2022 · 0 comments
Open

Optimization Feature - Step Functions: Type Hints #493

thantos opened this issue Sep 11, 2022 · 0 comments

Comments

@thantos
Copy link
Collaborator

thantos commented Sep 11, 2022

In the ASL transpiler, it is common to check the type of a value before acting on it.

For example, when adding two values, we check to see if they are both numbers, both string and then coerce whichever the algorithm says to do.

When we have literal values, we know their type and can act accordingly, but when we have jsonPath (references) we cannot assume their types.

If we add typeHint to the ASLGraph.JsonPath object and then populate it when it we produce JsonPath objects, we could avoid runtime checks.

Example:

`a ${b}` + 1
TemplateExpr(StirngLiteral("a "), Ident(b)) => Pass(States.Format('a {}', $.b)) => { jsonPath: heap1.str }
BinaryOp({ jsonPath: heap1.str }, NumberLiteral(1), '+') 
   => Check if left is a string or number 
     => if number => Pass(States.MathAdd($heap1.str, 1)
     => if string => Pass(States.Format('{}1', $heap1.str))

If we the TemplateExpr logic instead returns { jsonPath: "heap1.str", typeHint: "String" }, we can now do

TemplateExpr(StirngLiteral("a "), Ident(b)) => Pass(States.Format('a {}', $.b)) => { jsonPath: "heap1.str", typeHint: "String" }
BinaryOp({ jsonPath: heap1.str, typeHint: "String" }, NumberLiteral(1), '+') => Pass(States.Format('{}1', $heap1.str))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant