dlang-community / libdparse

Library for lexing and parsing D source code
https://libdparse.dlang.io
Boost Software License 1.0
115 stars 57 forks source link

make Statement, StatementNoCaseNoDefault and Declaration use SumType #489

Open WebFreak001 opened 1 year ago

WebFreak001 commented 1 year ago

old Declaration code used algebraic, which is more efficiently replaced with sumtype.

I replaced the mixin-generated properties with manual properties, since the code is very small for them anyway and helps them being shown in DCD

Since SumType works with well-defiend types, opEquals and visitIfNotNull was trivial to implement.

Saves around 0-3 MB of actual peak RAM in a ~170 MB test environment (could just be fluctuations how much it actually is, but it will definitely include some RAM savings, since we no longer store a bunch of nulls for common types)

Easy backwards-compatible improvement I think.

Made setters backwards-incompatible on purpose, since we don't want accidental assignment of 2 different types on the same sumtype.

codecov[bot] commented 1 year ago

Codecov Report

Merging #489 (7f7a9ce) into master (98bf0f4) will increase coverage by 0.04%. The diff coverage is 82.27%.

Additional details and impacted files [![Impacted file tree graph](https://codecov.io/gh/dlang-community/libdparse/pull/489/graphs/tree.svg?width=650&height=150&src=pr&token=VHoPCaUjPZ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dlang-community)](https://codecov.io/gh/dlang-community/libdparse/pull/489?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dlang-community) ```diff @@ Coverage Diff @@ ## master #489 +/- ## ========================================== + Coverage 83.49% 83.53% +0.04% ========================================== Files 11 11 Lines 8483 8541 +58 ========================================== + Hits 7083 7135 +52 - Misses 1400 1406 +6 ``` | [Impacted Files](https://codecov.io/gh/dlang-community/libdparse/pull/489?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dlang-community) | Coverage Δ | | |---|---|---| | [src/dparse/ast.d](https://codecov.io/gh/dlang-community/libdparse/pull/489?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dlang-community#diff-c3JjL2RwYXJzZS9hc3QuZA==) | `71.97% <80.82%> (+1.72%)` | :arrow_up: | | [src/dparse/parser.d](https://codecov.io/gh/dlang-community/libdparse/pull/489?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dlang-community#diff-c3JjL2RwYXJzZS9wYXJzZXIuZA==) | `91.43% <100.00%> (ø)` | | ------ [Continue to review full report in Codecov by Sentry](https://codecov.io/gh/dlang-community/libdparse/pull/489?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dlang-community). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dlang-community) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://codecov.io/gh/dlang-community/libdparse/pull/489?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dlang-community). Last update [98bf0f4...7f7a9ce](https://codecov.io/gh/dlang-community/libdparse/pull/489?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dlang-community). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dlang-community).