Skip to content
This repository has been archived by the owner on Jan 22, 2022. It is now read-only.

Constant folding optimizations #107

Open
MerlinVR opened this issue Aug 9, 2021 · 2 comments
Open

Constant folding optimizations #107

MerlinVR opened this issue Aug 9, 2021 · 2 comments
Assignees
Milestone

Comments

@MerlinVR
Copy link
Owner

MerlinVR commented Aug 9, 2021

C# requires basic constant folding for things like numeric types in order to handle correct implicit casting.

For instance byte myByte = 4 needs to be able to infer that the 4 is a byte, and not an int. Basic math operations also need to be valid here, so you need to be able to handle byte myByte = 2 + 3

Basic constant folding on built-in types is handled at the moment.

The plan to reach completion on this task is to add this handling to all extern expressions that can be considered constant. So, for example you could write:

Vector3 myUpVector = Vector3.up * 5;

And it would compile to a vector stored on the heap as (0, 5.0, 0) which at runtime would be compiled to a COPY from the heap constant to myUpVector

@MerlinVR MerlinVR created this issue from a note in UdonSharp 1.0 (Partially Implemented) Aug 9, 2021
@MerlinVR MerlinVR self-assigned this Aug 9, 2021
@MerlinVR MerlinVR added this to the UdonSharp 1.0 milestone Aug 9, 2021
@MerlinVR
Copy link
Owner Author

MerlinVR commented Aug 9, 2021

#20 and #23 should be fixed by this as-is at the moment. These issues should be closed when this is fully implemented and verified.

@MerlinVR
Copy link
Owner Author

The example case with "constant" properties and fields is now handled so Vector3 myUpVector = Vector3.up * 5; does now get stored as just (0, 5.0, 0). Though this handling still needs to be extended to methods taking constant operands for types like Vector and Mathf.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
UdonSharp 1.0
Partially Implemented
Development

No branches or pull requests

1 participant