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

Fix DateTime and TimeSpan type creation #3081

Closed
wants to merge 1 commit into from

Conversation

josesimoes
Copy link
Member

@josesimoes josesimoes commented Jan 27, 2025

Description

  • Rework data type lookup table to proper flags and no relocation handler.
  • Update declaration of NewObject in both classes. Now take a stack pointer instead of a Heap Block.
  • Fix Convert.NativeToDateTime().

Motivation and Context

How Has This Been Tested?

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dev Containers (changes related with Dev Containers, has no impact on code or features)
  • Dependencies/declarations (update dependencies or assembly declarations and changes associated, has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).

Summary by CodeRabbit

  • Refactor
    • Updated method signatures for DateTime and TimeSpan object creation to use stack frame references
    • Modified data type handling for DateTime and TimeSpan with optimization flags
    • Simplified object instantiation process across multiple system components

- Rework data type lookup table to proper flags and no relocation handler.
- Update declaration of NewObject in both classes. Now take a stack pointer instead of a Heap Block.
- Fix Convert.NativeToDateTime().
@josesimoes josesimoes added the Area: Common libs Everything related with common libraries label Jan 27, 2025
Copy link

coderabbitai bot commented Jan 27, 2025

Walkthrough

The pull request introduces changes to the Common Language Runtime (CLR) library, focusing on method signatures and object creation mechanisms. The modifications primarily affect DateTime and TimeSpan classes across multiple source files. The key change involves updating method signatures from using CLR_RT_HeapBlock references to CLR_RT_StackFrame, streamlining object instantiation processes. Additionally, type system lookup entries for these data types have been updated, removing relocation function pointers and adding optimization flags.

Changes

File Change Summary
src/CLR/CorLib/corlib_native.h Method signatures updated for NewObject in Library_corlib_native_System_TimeSpan and Library_corlib_native_System_DateTime
src/CLR/CorLib/corlib_native_System_Convert.cpp Modified object creation logic using stack directly
src/CLR/CorLib/corlib_native_System_DateTime.cpp Updated NewObject method signature and simplified object creation process
src/CLR/CorLib/corlib_native_System_TimeSpan.cpp Changed NewObject method to use CLR_RT_StackFrame and simplified object instantiation
src/CLR/Core/TypeSystemLookup.cpp Updated data type entries for DATATYPE_DATETIME and DATATYPE_TIMESPAN with new flags and removed relocation pointers

Possibly related PRs

Suggested Labels

Type: enhancement


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 35df688 and 9a592ef.

📒 Files selected for processing (5)
  • src/CLR/CorLib/corlib_native.h (3 hunks)
  • src/CLR/CorLib/corlib_native_System_Convert.cpp (2 hunks)
  • src/CLR/CorLib/corlib_native_System_DateTime.cpp (4 hunks)
  • src/CLR/CorLib/corlib_native_System_TimeSpan.cpp (2 hunks)
  • src/CLR/Core/TypeSystemLookup.cpp (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: nf-interpreter (Check_Code_Style)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ST_NUCLEO64_F091RC)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALX)
  • GitHub Check: nf-interpreter (Nightly build) (Build_STM32_targets ORGPAL_PALTHREE)
  • GitHub Check: nf-interpreter (Nightly build) (Check_Build_Options)
  • GitHub Check: nf-interpreter (Check_Build_Options)
🔇 Additional comments (6)
src/CLR/CorLib/corlib_native_System_TimeSpan.cpp (1)

181-190: LGTM! Correct implementation for value type allocation.

The changes properly implement stack-based allocation for TimeSpan value type, replacing the previous heap-based allocation. The implementation correctly:

  1. Uses stack.PushValue() for allocation
  2. Sets appropriate type flags for DATATYPE_TIMESPAN
  3. Clears the data before returning
src/CLR/CorLib/corlib_native_System_DateTime.cpp (1)

183-190: LGTM! Consistent implementation with TimeSpan.

The DateTime NewObject implementation correctly mirrors the TimeSpan changes, maintaining consistency in how value types are allocated from the stack.

src/CLR/CorLib/corlib_native_System_Convert.cpp (1)

539-539: LGTM! Correctly adapted to new DateTime creation pattern.

The change properly uses the new stack-based DateTime creation pattern, maintaining consistency with the updated NewObject implementation.

src/CLR/CorLib/corlib_native.h (2)

470-470: LGTM! Signature correctly updated for TimeSpan.

The TimeSpan NewObject declaration properly reflects the change to stack-based allocation.


499-499: LGTM! Signature correctly updated for DateTime.

The DateTime NewObject declaration properly reflects the change to stack-based allocation, maintaining consistency with TimeSpan.

src/CLR/Core/TypeSystemLookup.cpp (1)

85-86: LGTM! The changes align with value type semantics.

The modifications correctly:

  1. Remove relocation handlers since DateTime and TimeSpan are value types
  2. Add optimization flags to improve performance
  3. Maintain proper type flags for signed integer-based value types

Let's verify that these types are consistently treated as value types across the codebase:

✅ Verification successful

✅ DateTime and TimeSpan changes are correctly implemented as value types

The verification confirms:

  • Consistent value type semantics across native implementations
  • Proper direct storage without heap allocations
  • Correct optimization flags for performance
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any inconsistent handling of DateTime/TimeSpan as reference types
# Look for patterns that might treat these as heap objects

# Search for DateTime/TimeSpan allocation patterns
ast-grep --pattern 'new DateTime($$$)' 
ast-grep --pattern 'new TimeSpan($$$)'

# Search for references to these types
rg -l "DateTime|TimeSpan" --type cpp --type h

Length of output: 4431


Script:

#!/bin/bash
# Check native implementations and heap block handling
rg -A 5 "DATATYPE_(DATETIME|TIMESPAN)" src/CLR/CorLib/corlib_native_System_DateTime.cpp src/CLR/CorLib/corlib_native_System_TimeSpan.cpp src/CLR/Include/nanoCLR_Runtime__HeapBlock.h

# Check type system registration
rg -A 5 "DateTime|TimeSpan" src/CLR/Core/TypeSystem.cpp

Length of output: 2199


Script:

#!/bin/bash
# Check heap block and value type handling
rg -A 10 "struct CLR_RT_HeapBlock" src/CLR/Include/nanoCLR_Runtime__HeapBlock.h

# Check for value type handling patterns
ast-grep --pattern 'struct NumericByRef {
  $$$
}'

Length of output: 8268

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

@josesimoes
Copy link
Member Author

Superseded by #3084.

@josesimoes josesimoes closed this Jan 29, 2025
@josesimoes josesimoes deleted the fix-value-types branch January 29, 2025 04:00
@nfbot nfbot added invalid and removed Type: bug Area: Common libs Everything related with common libraries labels Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants