-
Notifications
You must be signed in to change notification settings - Fork 2
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
[Test] C-API #4
Draft
st0012
wants to merge
91
commits into
master
Choose a base branch
from
c-api
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[Test] C-API #4
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'll leave this PR open because |
Initial template for C structs Use allocator in node constructors
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]> Add linked list implementation Signed-off-by: Alexandre Terrasa <[email protected]> Type `Class#super_class` field Signed-off-by: Alexandre Terrasa <[email protected]> Type fields of `RBS::Types::Block` Signed-off-by: Alexandre Terrasa <[email protected]> Type `block` fields Signed-off-by: Alexandre Terrasa <[email protected]> Type `RBS::Types::Proc#self_type` field Signed-off-by: Alexandre Terrasa <[email protected]> Refactor `parse_function` Signed-off-by: Alexandre Terrasa <[email protected]> Copy value in `rbs_struct_to_ruby_value` Remove usages of `rbs_loc` from `parser.c` Extract `rbs_location.h` Migrate `RBS::Types::Function::Param` fields Signed-off-by: Alexandre Terrasa <[email protected]> Type `RBS::Types::UntypedFunction` fields Signed-off-by: Alexandre Terrasa <[email protected]> Type fields of `RBS::AST::TypeParam` Signed-off-by: Alexandre Terrasa <[email protected]> Type some more fields of `RBS::AST::Members::Attr` Signed-off-by: Alexandre Terrasa <[email protected]> Type fields in `RBS::AST::Members::MethodDefinition` Signed-off-by: Alexandre Terrasa <[email protected]> Type `RBS::AST::Directives::Use::SingleClause#new_name` Signed-off-by: Alexandre Terrasa <[email protected]> Type `RBS::Namespace#absolute` Signed-off-by: Alexandre Terrasa <[email protected]> Temporary handle nil types Signed-off-by: Alexandre Terrasa <[email protected]> Handle `bool` type Signed-off-by: Alexandre Terrasa <[email protected]> Type all fields of `RBS::Types::Variable` Signed-off-by: Alexandre Terrasa <[email protected]> Migrate `RBS::TypeName` Signed-off-by: Alexandre Terrasa <[email protected]> Migrate `parse_use_clauses` Signed-off-by: Alexandre Terrasa <[email protected]> Migrate `class_instance_name` Signed-off-by: Alexandre Terrasa <[email protected]> Handle overloads as a rbs_node_list Signed-off-by: Alexandre Terrasa <[email protected]> Remove more `builds_ruby_object_internally` flags Signed-off-by: Alexandre Terrasa <[email protected]> Invert `builds_ruby_object_internally` default value Signed-off-by: Alexandre Terrasa <[email protected]> Introduce `rbs_location_t` Signed-off-by: Alexandre Terrasa <[email protected]> Store C structs instead of Ruby `VALUE`s Introduce +rbs_ast_symbol_t and migrate to it Signed-off-by: Alexandre Terrasa <[email protected]> Remove ZzzTmpNotImplemented node Signed-off-by: Alexandre Terrasa <[email protected]> Remove one more instance of EMPTY_ARRAY Signed-off-by: Alexandre Terrasa <[email protected]> Migrate from VALUE array to rbs_node_list_t Signed-off-by: Alexandre Terrasa <[email protected]> Migrate `method_params` from taking a VALUE arrays Signed-off-by: Alexandre Terrasa <[email protected]> Migrate `parse_type_list` from taking a VALUE array Signed-off-by: Alexandre Terrasa <[email protected]> Forward all C-typed params as-is Get types on constructor params Handle mix of C types and Ruby VALUE Move Ruby object construction into `new` functions Conditionally construct `ruby_value` internally Type Attr* field `ivar_name` Signed-off-by: Alexandre Terrasa <[email protected]> Add `AST::Bool` Signed-off-by: Alexandre Terrasa <[email protected]> Use two less VALUE values Signed-off-by: Alexandre Terrasa <[email protected]> Use more instance of `bool` Signed-off-by: Alexandre Terrasa <[email protected]> Add Hash implementation Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]> Use C hash for `check_key_duplication` Signed-off-by: Alexandre Terrasa <[email protected]> Use C hash to represent Record fields Signed-off-by: Alexandre Terrasa <[email protected]> Migrate `memo` to using a C hash Signed-off-by: Alexandre Terrasa <[email protected]> Uses C hashes for keyword parameters Signed-off-by: Alexandre Terrasa <[email protected]> Remove parser call to `todo!` Signed-off-by: Alexandre Terrasa <[email protected]> Remove calls to `rbs_struct_to_ruby_value` Signed-off-by: Alexandre Terrasa <[email protected]> TMP symbol Signed-off-by: Alexandre Terrasa <[email protected]> Replace 2 fake nodes by one Signed-off-by: Alexandre Terrasa <[email protected]> Set fields for `Record::FieldType` Signed-off-by: Alexandre Terrasa <[email protected]> Make comment use a `rbs_ast_comment_t` instead of a `VALUE` Signed-off-by: Alexandre Terrasa <[email protected]> Add `rbs_ast_string_t` Add `rbs_ast_integer_t` Migrate `literal` to store C nodes Remove `cached_ruby_string` Remove useless templating stuff Signed-off-by: Alexandre Terrasa <[email protected]> Remove `cached_ruby_value` from `rbs_node_list` Signed-off-by: Alexandre Terrasa <[email protected]> Remove `cached_ruby_value` from `rbs_hash` Signed-off-by: Alexandre Terrasa <[email protected]> Add `rbs_string`, and use it for annotations Add `rbs_ast_symbol_t` to model symbols in the AST Co-Authored-By: Alexander Momchilov <[email protected]>
And rename it to `class_constants` to disambiguate it from `rbs_constant_id`, `rbs_constant_pool`, etc.
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]> Do not create comments using a VALUE Use a rbs_string instead Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
Signed-off-by: Alexandre Terrasa <[email protected]>
vasprintf is not available on all platforms (e.g. Windows). So we should switch to vsnprintf even tho it'd complicate the code a bit.
This commit addresses several compatibility issues with MSVC compiler: 1. Updated NODISCARD macro in defines.h to use MSVC-specific _Check_return_ attribute instead of GCC/Clang's __attribute__((warn_unused_result)). 2. Fixed variable-length array (VLA) parameter in rbs_parser_declare_type_variables function. Changed from `const char *variables[count]` to `const char **variables` since VLAs are not supported in MSVC. 3. Added the declaration of rbs_parser_declare_type_variables to parserstate.h to ensure proper function prototyping. 4. Rename `error` label to `error_handling` to avoid syntax error on mswin. These changes maintain the same functionality while ensuring compatibility with MSVC, allowing the RBS extension to build successfully on Windows.
This code was added for easier debugging but it's not needed anymore and would fail memory leak checks.
Rename alloc_location to rbs_location_new Use rbs_location_current_token when possible
* Make rbs_loca_add* methods take allocator * Remove unnecessary rbs_new_loc_range helper function * Make rbs_loc_alloc_children allocate through allocator * Rename check_children_cap to ensure_children_capacity * Implement rbs_allocator_realloc function * Reorganize location children functions * Update src/rbs_location.c Co-authored-by: Alexandre Terrasa <[email protected]> --------- Co-authored-by: Alexandre Terrasa <[email protected]>
* Remove unnecessary re-allocations from child-adding functions We always pre-allocate enough space for a location's children with `rbs_loc_alloc_children` in `parser.c`. So we should never hit the case where we need to re-allocate the children array. This change removes the unnecessary re-allocations and makes the code simpler. * Update src/rbs_location.c Co-authored-by: Alexander Momchilov <[email protected]> --------- Co-authored-by: Alexander Momchilov <[email protected]>
* Allocate parser error with allocator * Allocate parse result with allocator
Since we don't manually allocate/free strings anymore, we don't need the string type enum and all the complexity that comes with it.
* Remove unnecessary rbs_buffer_init_with_capacity function * Manage buffer allocation with allocator * Set default capacity for buffer to 128 Most comments are less than 128 bytes, so this should help reduce memory waste. See #13 (comment)
Add `rbs_allocator_alloc_many` to avoid unnecessary 0 initialization on memory
### Avoid declaring unused `node` variables in `rbs_node_destroy`'s template Such declarations will fail Sorbet's compiler: ``` prism/templates/src/ast.c.erb:203:31: error: unused variable 'node' [-Werror,-Wunused-variable] rbs_ast_annotation_t *node = (rbs_ast_annotation_t *)any_node; ^ prism/templates/src/ast.c.erb:203:28: error: unused variable 'node' [-Werror,-Wunused-variable] rbs_ast_comment_t *node = (rbs_ast_comment_t *)any_node; ^ prism/templates/src/ast.c.erb:203:28: error: unused variable 'node' [-Werror,-Wunused-variable] rbs_ast_integer_t *node = (rbs_ast_integer_t *)any_node; ^ prism/templates/src/ast.c.erb:203:27: error: unused variable 'node' [-Werror,-Wunused-variable] rbs_ast_string_t *node = (rbs_ast_string_t *)any_node; ^ ``` ### Use `size_t` instead of `int` for `capacity` in `rbs_loc_alloc_children` This fixes a warning about comparing `int` and `size_t` in `rbs_loc_alloc_children`'s assertion. ### Avoid declaring the `max` variable that's just used in assertions When the `assert` is stripped out, the variable becomes unused and triggers a warning. ``` external/rbs_parser/src/rbs_location.c:8:10: warning: unused variable 'max' [-Wunused-variable] size_t max = sizeof(rbs_loc_entry_bitmap) * 8; ^ ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.