Skip to content

frontend: Group Array Type#976

Draft
rascmatt wants to merge 3 commits into
masterfrom
feature/group-array-type
Draft

frontend: Group Array Type#976
rascmatt wants to merge 3 commits into
masterfrom
feature/group-array-type

Conversation

@rascmatt

@rascmatt rascmatt commented May 22, 2026

Copy link
Copy Markdown
Contributor

The group definition's name can be used in expressions (within group annotations) to access the matched instructions / operations at runtime. In addition it exposes a length and bitLength field.

VLIW.length // number of instructions in the group
VLIW.bitLength // number of bits in the group

VLIW(1) // the second instruction in the group
VLIW(VLIW.length - 1) // the last instruction in the group

I introduced a more general 'ArrayType' for such group references. In this case we're able to upper-bound the length and bitLength, so we can also give these properties a UIntType type with some maximal width.

@rascmatt rascmatt self-assigned this May 22, 2026
@github-actions github-actions Bot added enhancement New feature or request lcb This is LCB related frontend This is frontend related iss This is ISS related labels May 22, 2026
@rascmatt rascmatt force-pushed the feature/group-array-type branch 3 times, most recently from b57ba75 to 1e86643 Compare May 24, 2026 07:45
@rascmatt rascmatt marked this pull request as ready for review May 24, 2026 07:54
@rascmatt rascmatt requested review from Jozott00 and flofriday May 24, 2026 07:54
@Jozott00

Copy link
Copy Markdown
Contributor

I'll wait with the review until #918 got merged, so it becomes easier to see this PR's changes.

@rascmatt rascmatt force-pushed the feature/group-array-type branch from 1e86643 to 19f1b2b Compare May 25, 2026 07:28

@Jozott00 Jozott00 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is unrelated to VIAM or ISS, I’ll leave the approval to @flofriday.

@rascmatt rascmatt marked this pull request as draft May 25, 2026 08:28
@rascmatt

Copy link
Copy Markdown
Contributor Author

It will need to be added to the VIAM as well, but I didn't get to that yet. I switched it to a Draft PR, and amend it later.

@flofriday flofriday left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks pretty good.
I obviously don't get why there is a need for the ArrayType 😅
Or how the groups work and I also couldn't find a lot in our documentation.

Maybe you can explain it in a comment and then disregard all the other comments.

Comment on lines +44 to +50
// error: Invalid annotation expression
// ╭── test/resources/frontend-snapshots/typechecker/invalidGroupReference.vadl:27:13
// │
// 27 │ [assert : VLIW.a = 0b0]
// │ ^^^^^^^^^^^^ Unable to determine type
// │
// help: Check additional errors which may have caused the type to be missing

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: I don't like this error, I think we can completely remove it as it doesn't add any useful information.

// 27 │ [assert : VLIW.a = 0b0]
// │ ^^^^^^
// │
// Arrays only have the fields `length` or `bitLength`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: Will this also be called an "Array" in the docs? Or is it something more specific like a Group Array?

I'm mostly asking because it could be confusing for users to name them Array when they only exist in a subsection of the language when the more useful analog from other languages is a Tensor.

Comment on lines +40 to +41
// Intersection format `(AType ∩ BType)` doesn't have any field with this name
// help: Did you maybe mean one of: a, b

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

**praise This is very readable, and a great error message. 🎉

// 27 │ [assert : VLIW(1)(2).a = 0b0]
// │ ^^^^^^^
// │
// Type `a: Bits<20>, b: Bits<5>` cannot be indexed or sliced

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor: I don't love the Type description, maybe GroupType<a: Bits<20>, b: Bits<5>> makes it clearer?
I think we have something similar for FormatTypes.

public static ArrayType array(Type elementType, UIntType lengthType, UIntType bitLengthType) {
var hash = Objects.hash(elementType, lengthType, bitLengthType);
return arrayTypes
.computeIfAbsent(hash, k -> new ArrayType(elementType, lengthType, bitLengthType));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

issue: This has hash-collisions. You need to wrap the contents in a datastructure, like a Triple.


private final ConstantEvaluator constantEvaluator;

public GroupExprLengthCollector(ConstantEvaluator constantEvaluator) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: Maybe this too should be a private constructor.


private final ConstantEvaluator constantEvaluator;

public GroupExprBitLengthCollector(ConstantEvaluator constantEvaluator) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: Same private constructor here.

}

Type currType = typeBeforeSlice;
SourceLocation targetLoc = expr.location();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nitpick: Calculating expression can be expensive in hot loops so let's add it to the only branch where we actually need it when there is an issue we need to report.

In general we optimize for the case where no errors occur.


if (!(currType instanceof BitsType) && !(currType instanceof TensorType)
&& !(currType instanceof ArrayType)) {
var loc = expr.target.location().join(targetLoc.location());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

minor: The .location() call is redundant on targetLoc.location() as it's already a SourceLocation.

};
} else {
addErrorAndStopChecking(error("Cannot resolve `%s`".formatted(fieldName), expr)
throw addErrorAndStopChecking(error("Cannot resolve `%s`".formatted(fieldName), expr)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: Is there a reason you added the throw?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request frontend This is frontend related iss This is ISS related lcb This is LCB related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants