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

Sizeof support #284

Merged
merged 5 commits into from
Aug 16, 2024
Merged

Sizeof support #284

merged 5 commits into from
Aug 16, 2024

Conversation

0xF6
Copy link
Member

@0xF6 0xF6 commented Aug 16, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new methods for enhanced type-checking, including HasObjectOrClass and IsNullType.
    • Added functionality to handle SizeOfFunctionExpression in type determination and IL code emission.
  • Bug Fixes

    • Improved error handling for existing methods related to IL code emission, enhancing robustness.
  • Tests

    • Added new tests for sizeof functionality to ensure accurate parsing and validation.
  • Chores

    • Updated execution flow for better performance in the test suite by adopting asynchronous practices.

@0xF6 0xF6 added the area-compiler Area of compiler staff label Aug 16, 2024
@0xF6 0xF6 requested a review from code-maid August 16, 2024 00:54
@0xF6 0xF6 self-assigned this Aug 16, 2024
Copy link
Contributor

coderabbitai bot commented Aug 16, 2024

Walkthrough

The recent changes enhance the functionality of the VeinTypeCode and G_Emitters classes by introducing new methods for type checking and IL code emission. Improvements include better error handling and type resolution for various expressions, particularly regarding the sizeof functionality. Testing has also been expanded to ensure robustness in syntax parsing. This shift towards more nuanced type handling and asynchronous execution improves both maintainability and performance within the codebase.

Changes

Files Change Summary
runtime/common/reflection/VeinTypeCode.cs Added HasObjectOrClass method to check if an instance represents a class or object.
runtime/ishtar.generator/generators/emitters.cs Introduced EmitSizeOf for calculating type size; refactored EmitTypeOf, EmitNameOf, and EmitTypeIs for better error handling.
runtime/ishtar.generator/generators/operators.cs Modified EmitBinaryExpression for enhanced handling of null types; added IsNullType extension method for checking NullClass types.
runtime/ishtar.generator/generators/types.cs Extended DetermineType method to support SizeOfFunctionExpression, returning VeinTypeCode.TYPE_I4.
test/vc_test/Features/EtherealFunctionTest.cs Added SizeOfTest method and test case for validating sizeof expression parsing.
test/vc_test/FullSTDCompilation.cs Removed ColorShim.Apply() from Setup; changed Compile method to use asynchronous execution with RunAsync(...).Result.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Compiler
    participant ILGenerator
    participant TypeChecker

    User->>Compiler: Request to compile code
    Compiler->>TypeChecker: Determine types in code
    TypeChecker->>TypeChecker: Check for SizeOfFunctionExpression
    TypeChecker-->>Compiler: Return TypeCode
    Compiler->>ILGenerator: Emit IL code based on types
    ILGenerator->>ILGenerator: Handle null checks and emit size
    ILGenerator-->>Compiler: Return emitted IL
    Compiler-->>User: Compilation complete
Loading

🐰 In a world of code so bright,
A rabbit hops with pure delight.
New checks for types and sizes grand,
Emitters dance at our command!
With tests that leap and bounds they take,
A happy tune for code's sweet sake! 🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (3)
runtime/ishtar.generator/generators/emitters.cs (3)

77-101: Consider clarifying the error message for generics.

The error message for using sizeof with generics could be more informative. Consider specifying that the limitation is temporary and will be addressed in future updates.

- context.LogError($"sizeof cannot use with generics [limitation is temporary, awaiting natural structs and fully generics implementation].", sizeOf);
+ context.LogError($"'sizeof' cannot be used with generic types. This limitation is temporary and will be resolved with future support for natural structs and full generics.", sizeOf);

102-124: Enhance error message specificity for missing type arguments.

The error message for missing type arguments could specify that a single type argument is required.

- context.LogError($"as type required type argument", nameOf);
+ context.LogError($"'typeof' requires a single type argument.", nameOf);

145-154: Enhance error message specificity for missing type arguments.

The error message for missing type arguments could specify that a single type argument is required.

- context.LogError($"type is required single type argument", typeOf);
+ context.LogError($"'type is' requires a single type argument.", typeOf);
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between b87dc5c and 35ea11e.

Files selected for processing (6)
  • runtime/common/reflection/VeinTypeCode.cs (1 hunks)
  • runtime/ishtar.generator/generators/emitters.cs (3 hunks)
  • runtime/ishtar.generator/generators/operators.cs (2 hunks)
  • runtime/ishtar.generator/generators/types.cs (1 hunks)
  • test/vc_test/Features/EtherealFunctionTest.cs (2 hunks)
  • test/vc_test/FullSTDCompilation.cs (3 hunks)
Additional comments not posted (7)
test/vc_test/Features/EtherealFunctionTest.cs (2)

19-21: LGTM!

The SizeOfTest method correctly tests the parsing of the sizeof<bool>() expression using the Syntax.ethereal_function_expression method.


38-38: Test case addition approved.

The addition of the sizeof test case to the All method enhances the test coverage for the sizeof<Type>() expression.

runtime/common/reflection/VeinTypeCode.cs (1)

225-226: LGTM!

The HasObjectOrClass method correctly identifies VeinTypeCode instances that represent either a class or an object.

runtime/ishtar.generator/generators/emitters.cs (1)

72-73: Addition of SizeOfFunctionExpression handling is appropriate.

The inclusion of SizeOfFunctionExpression enhances the macro emission capabilities by supporting size calculations.

runtime/ishtar.generator/generators/types.cs (1)

194-195: Support for SizeOfFunctionExpression is well-integrated.

The handling of SizeOfFunctionExpression in DetermineType appropriately returns VeinTypeCode.TYPE_I4, aligning with the expected behavior for size calculations.

runtime/ishtar.generator/generators/operators.cs (2)

55-56: Enhancements to handle null types in binary expressions are effective.

The added logic in EmitBinaryExpression to handle null types improves robustness and aligns with expected behavior for object and class comparisons.


86-87: Introduction of IsNullType utility method is beneficial.

The IsNullType method provides a clear and concise way to check for null types, enhancing code readability and maintainability.

@@ -55,7 +55,7 @@ public void Compile()
AppFlags.Set(ApplicationFlag.use_predef_array_type_initer, true);
var project = VeinProject.LoadFrom(project_file);
var settings = new CompileSettings();
var targets = CompilationTask.Run(project.WorkDir, settings);
var targets = CompilationTask.RunAsync(project.WorkDir, settings).Result;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider using await instead of .Result for asynchronous calls.

Using .Result on an asynchronous method can lead to blocking and potential deadlocks. Consider using await to handle the asynchronous call more effectively, assuming the method can be made asynchronous.

- var targets = CompilationTask.RunAsync(project.WorkDir, settings).Result;
+ var targets = await CompilationTask.RunAsync(project.WorkDir, settings);

Note: This change would require the method to be marked as async and return a Task.

Committable suggestion was skipped due to low confidence.

Comment on lines +129 to +141
var context = gen.ConsumeFromMetadata<GeneratorContext>("context");

// TODO, validate exist variable\field\method\class\etc
if (nameOf.Expression is AccessExpressionSyntax nameof_exp1)
if (!nameOf.Expression.IsDefined)
{
context.LogError($"nameof required single type argument", nameOf);
throw new SkipStatementException();
}
if (nameOf.Expression.Get() is AccessExpressionSyntax nameof_exp1)
return gen.Emit(OpCodes.LDC_STR, nameof_exp1.Right.ToString());
if (nameOf.Expression is IdentifierExpression nameof_exp2)
if (nameOf.Expression.Get() is IdentifierExpression nameof_exp2)
return gen.Emit(OpCodes.LDC_STR, nameof_exp2.ToString());
var ctx = gen.ConsumeFromMetadata<GeneratorContext>("context");
ctx.LogError($"Target expression is not valid named expression.", nameOf);
context.LogError($"Target expression is not valid named expression.", nameOf);
Copy link
Contributor

Choose a reason for hiding this comment

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

Reminder: Complete validation for EmitNameOf.

The TODO comment indicates that additional validation is needed for variable, field, method, and class existence.

Do you want me to help implement this validation or open a GitHub issue to track this task?

@0xF6 0xF6 merged commit d049c38 into master Aug 16, 2024
4 of 5 checks passed
@0xF6 0xF6 deleted the feature/sizeof-expression branch August 16, 2024 01:01
@vein-lang vein-lang locked and limited conversation to collaborators Aug 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-compiler Area of compiler staff
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant