Skip to content

cleaning up how we check for TupleExpressions with a single item#1197

Merged
Janther merged 4 commits intomainfrom
exploring-tuples-with-single-expression
Jul 21, 2025
Merged

cleaning up how we check for TupleExpressions with a single item#1197
Janther merged 4 commits intomainfrom
exploring-tuples-with-single-expression

Conversation

@Janther
Copy link
Copy Markdown
Member

@Janther Janther commented Jul 9, 2025

There is a tricky way to check if a TupleExpression has a single item since a TupleValue can have an Expression or be undefined. However by the nature of a TupleExpression if there is only 1 TupleValue, then it will always have an Expression.
This is very difficult to express in typescript therefor there are a few non-null assertions we were using.

To clean this I added a single function to src/slang-nodes/TupleValues.ts to return the single expression contained. If it has multiple or 0 it will default to undefined.

This avoids multiple checks and navigation down the chain like this this.operand.variant.items.items[0].expression!

…o we minimise the amount of chained accesses and as a bonus removing the non-null assertions
@Janther Janther requested a review from fvictorio July 9, 2025 19:37
@Janther Janther added the performance Results in smaller size, better memory usage, or faster execution label Jul 9, 2025
@Janther Janther force-pushed the exploring-tuples-with-single-expression branch from 295a97a to d51cf49 Compare July 10, 2025 12:57
@@ -24,9 +24,9 @@ function isEndOfChain(
path: AstPath<StrictAstNode>
): boolean {
for (
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Here I'm just getting rid of the non-null assertions

@Janther Janther merged commit 1eca28a into main Jul 21, 2025
7 checks passed
@Janther Janther deleted the exploring-tuples-with-single-expression branch July 21, 2025 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Results in smaller size, better memory usage, or faster execution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants