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

[FIRRTL] Handle flips in const connections #5210

Merged
merged 2 commits into from
May 17, 2023
Merged

Conversation

trilorez
Copy link
Contributor

Addresses #5209

I can also update areTypesWeaklyEquivalent, although const types were introduced into the firrtl spec in the same version that removed partial connection, so I suppose I can leave it. Or I can remove all of the const logic it has to clean things up.

@trilorez trilorez requested a review from youngar May 17, 2023 02:11
@youngar
Copy link
Member

youngar commented May 17, 2023

I think we still accept partial connects, its probably best to update areTypesWeaklyEquivalent until all callers are fully removed.


// -----

/// Non-const doube flip types cannot be connected to const.
Copy link
Member

Choose a reason for hiding this comment

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

s/doube/double

Comment on lines 712 to 727
// If the types are trivially equal, return true.
if (destFType == srcFType)
return true;
// If the types are trivially equal, return true as long as outer constness is
// compatible.
if (destFType == srcFType) {
if (destOuterTypeIsConst == srcOuterTypeIsConst)
return true;
if (destFType.isGround())
return !destOuterTypeIsConst || srcOuterTypeIsConst;
}
Copy link
Member

Choose a reason for hiding this comment

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

Hmm maybe we should just get rid of the early break. I think I added this recently, and introduced the bug of ignoring the outer const type. If we ever push const to the leaves or something like that, then maybe we can introduce the early break again, wdyt?

Also I suggest we add a test case for this because I keep thinking we can add this trivial early break. Its now covered by the flip test cases you added, but the most basic test might be:

/// Const types cannot be connected to non-const types.

firrtl.circuit "test" {
firrtl.module @test(in %in   : !firrtl.const.bundle<a: uint<1>>,
                    out %out : !firrtl.bundle<a: uint<1>>) {
  // expected-error @+1 {{type mismatch}}
  firrtl.connect %out, %in : !firrtl.bundle<a: uint<1>>, !firrtl.const.bundle<a: uint<1>>
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, the outer constness gets kind of unwieldy, I like your suggestion of keeping things in one place for ground types.
Removed, and added test case (I assume you accidentally wrote the valid version).

Comment on lines 739 to 741
// A 'const' ground destination requires a 'const' source.
if (destType.isGround() && destIsConst && !srcIsConst)
return false;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should keep all the ground-related logic grouped at the end? The current logic down below sort of looks wrong to me if this were to fall through:

  // Ground types can be connected if they are the same, or the source type is
  // a const version of the destination type.
  return destType == srcType || destType == srcType.getConstType(false);

Should this be something like:

if (destIsConst && !srcIsConst)
    return false;
return destType.getConst(false) == srcType.getConst(false);

// OR:

auto realDestType = destType.getConstType(destIsConst);
return realDestType == srcType.getConstType(true) ||  realDestType == srcType.getConstType(false);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I grouped the ground stuff at the end, and I also moved the reset-type tests below the aggregates as well.

Also fix a partial connect reset flip edge case
@trilorez
Copy link
Contributor Author

I updated areTypesWeaklyEquivalent. Const parser support isn't in yet, I can add const partial connect tests on the parsing pr.
I also noticed an edge case where flips weren't being taken into account for ResetType, so I fixed that and added a test.

Copy link
Member

@youngar youngar left a comment

Choose a reason for hiding this comment

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

🥳

@trilorez trilorez merged commit 9d51934 into main May 17, 2023
@trilorez trilorez deleted the dev/trilorez/const-flip branch May 17, 2023 04:42
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.

2 participants