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

Variant Unboxing #209

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open

Variant Unboxing #209

wants to merge 40 commits into from

Conversation

btwj
Copy link
Contributor

@btwj btwj commented Nov 6, 2023

This PR enables (with the -unbox-variants flag) the ability to unbox ADTs, both at the parent level and at a per-case level.
For now, these ADTs are normalized by greedily packing fields into the fewest scalars possible, and then attaching an extra scalar representing the tag.

Todo:

  • Add more tests for large ADTs
  • Add unit tests for VariantSolver

@btwj btwj changed the title [wip] Variant Solving [wip] Variant Unboxing Nov 6, 2023
aeneas/src/ssa/SsaOptimizer.v3 Outdated Show resolved Hide resolved
aeneas/src/ir/Normalization.v3 Outdated Show resolved Hide resolved
var variantSolver: VariantSolver;

new() {
variantSolver = VariantSolver.new(config, this, true);
Copy link
Owner

Choose a reason for hiding this comment

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

I generally like splitting this out into a separate file, but the two are now intertwined in a way that is confusing. Any thoughts how we can improve this? E.g. splitting out just the part that is shared between logic here and there into a separate reusable piece?

aeneas/src/ir/SsaNormalizer.v3 Outdated Show resolved Hide resolved
aeneas/src/ir/SsaNormalizer.v3 Outdated Show resolved Hide resolved
aeneas/src/ir/SsaNormalizer.v3 Outdated Show resolved Hide resolved
aeneas/src/ir/SsaNormalizer.v3 Outdated Show resolved Hide resolved
aeneas/src/ir/SsaNormalizer.v3 Outdated Show resolved Hide resolved
aeneas/src/ir/SsaNormalizer.v3 Outdated Show resolved Hide resolved
aeneas/src/ir/VariantSolver.v3 Show resolved Hide resolved
@btwj btwj force-pushed the variant-solver branch 3 times, most recently from a0e04be to a58574b Compare November 17, 2023 22:29
@btwj btwj force-pushed the variant-solver branch 2 times, most recently from 9891a2c to 4315b77 Compare November 27, 2023 20:18
@btwj btwj requested a review from titzer November 27, 2023 20:48
@btwj btwj marked this pull request as ready for review November 29, 2023 06:46
case Y(x: int);
}

def eq(a: A00, b: A00) -> bool {
Copy link
Owner

Choose a reason for hiding this comment

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

This can just be def eq = A00.==.

var a00_y2: A00 = A00.Y(12);
var a00_y3: A00 = A00.Y(13);

if (!eq(a00_x, a00_x2)) return -1;
Copy link
Owner

Choose a reason for hiding this comment

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

It's generally better to have a test take an (integer) argument and then switch on it, returning a different value for each input. Then the first line of the file can list all the inputs and expected outputs. This helps speed up debugging a little, because when the test fails, the test framework will tell you which input it failed on. Also, the test is simpler and less code, because it doesn't even do equality checking for expected result, it just returns a result.

@@ -0,0 +1,23 @@
//@execute =0
Copy link
Owner

Choose a reason for hiding this comment

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

Can we move all of these into test/variants/

@btwj
Copy link
Contributor Author

btwj commented Dec 2, 2023

@titzer I've gone ahead and added #unboxed to type Operand here, it bootstraps now!

Also fixed a bug in the existing compiler that I discovered while writing extra tests: equality for boxed variants in tuples wasn't normalized correctly, e.g. if U was a boxed variant, the instruction OverloadedEq<(U, U)> ended up becoming normalized wrongly as VariantEq<U> when it should've become CallVariantSelector<U>[==]. See test/variants/eq00.v3 for an example that crashes the old compiler.

Separately, the equality code for U wasn't deemed reachable from OverloadedEq<(U, U)> because getEquality doesn't recurse into the nested types if the type was a tuple, I've added that as well.

@btwj btwj changed the title [wip] Variant Unboxing Variant Unboxing Dec 2, 2023
@btwj btwj requested a review from titzer December 2, 2023 08:44
@btwj btwj force-pushed the variant-solver branch 2 times, most recently from 757d09f to edf6b0b Compare January 29, 2024 22:54
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

2 participants