-
Notifications
You must be signed in to change notification settings - Fork 6
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
Sizeof support #284
Conversation
WalkthroughThe recent changes enhance the functionality of the Changes
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
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this 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
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 thesizeof<bool>()
expression using theSyntax.ethereal_function_expression
method.
38-38
: Test case addition approved.The addition of the
sizeof
test case to theAll
method enhances the test coverage for thesizeof<Type>()
expression.runtime/common/reflection/VeinTypeCode.cs (1)
225-226
: LGTM!The
HasObjectOrClass
method correctly identifiesVeinTypeCode
instances that represent either a class or an object.runtime/ishtar.generator/generators/emitters.cs (1)
72-73
: Addition ofSizeOfFunctionExpression
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 forSizeOfFunctionExpression
is well-integrated.The handling of
SizeOfFunctionExpression
inDetermineType
appropriately returnsVeinTypeCode.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 ofIsNullType
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; |
There was a problem hiding this comment.
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.
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); |
There was a problem hiding this comment.
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?
Summary by CodeRabbit
New Features
HasObjectOrClass
andIsNullType
.SizeOfFunctionExpression
in type determination and IL code emission.Bug Fixes
Tests
sizeof
functionality to ensure accurate parsing and validation.Chores