Skip to content

Ruby: RBI library changes to support models-as-data model generation #9932

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

Merged
merged 5 commits into from
Sep 22, 2022

Conversation

alexrford
Copy link
Contributor

These changes are mostly in service of better parameter type modelling - they should make more sense in the context of the models-as-data manager PR for a Ruby typegraph implementation.

@alexrford alexrford added no-change-note-required This PR does not need a change note Ruby labels Jul 31, 2022
@alexrford alexrford force-pushed the ruby/rbi-typegraph-fixes branch from 0cbe921 to 52305da Compare September 19, 2022 20:04
@alexrford alexrford marked this pull request as ready for review September 19, 2022 20:04
@alexrford alexrford requested a review from a team as a code owner September 19, 2022 20:04
@calumgrant calumgrant requested a review from aibaars September 20, 2022 08:43
Copy link
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

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

Looks fine, but I have some questions still.

/**
* Gets a fully qualified name for this constant.
*/
string getAQualifiedName() { none() }
Copy link
Contributor

Choose a reason for hiding this comment

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

The change looks fine; however getAQualifiedName is not used in this pull request so I wonder why you are changing this here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I was using this in an earlier revision of https://github.com/github/codeql-model-manager/pull/5 to get qualified names for general ConstantAccesses, but changed how this is implemented so this predicate isn't required. I'll drop it from this PR.

}
// TODO: get associated method to which this can be passed
// TODO: widen type for procs/blocks
override MethodBase getAssociatedMethod() { none() }
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this return Callable for procs/blocks/lambdas?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'd probably want this to return a BlockParameter, e.g. in:

  sig do
    params(
      a: String,
      block: T.nilable(T.proc.params(b: Integer).void)
    ).void
  end
  def blk_nilable_method(a, &block); end

the T.proc call corresponds to the &block parameter of blk_nilable_method, whereas the sig call corresponds to the blk_nilable_method definition itself. So we maybe need something like newtype TTypedCallable = TypedMethod(MethodBase m) or TypedBlock(BlockParameter b) or maybe to add another predicate BlockParameter getAssociatedBlockParameter() to the SignatureCall abstract class and in practice only one of getAssociatedMethod() and getAssociatedBlockParameter() will have a value.

// explicitly exclude keyword parameters
not this.getAssociatedParameter(result.getName()) instanceof KeywordParameter and
// and exclude block arguments
not isBlockParamName(result.getName())
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be not result instanceof BlockArgument instead? Or is using blk and block the way that RBI models block arguments and parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point - I think in this case we have something like:

  sig do
    params(
      a: String,
      block: T.nilable(T.proc.params(b: Integer).void)
    ).void
  end
  def blk_nilable_method(a, &block); end

so the argument here is block: T.nilable(T.proc.params(b: Integer).void) which is not a BlockArgument, but the associated parameter is &block so we can check if that is a BlockParameter instead which seems neater and less fragile.

Copy link
Contributor

@aibaars aibaars left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@alexrford alexrford merged commit 140458b into github:main Sep 22, 2022
@alexrford alexrford deleted the ruby/rbi-typegraph-fixes branch September 22, 2022 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-change-note-required This PR does not need a change note Ruby
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants