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

Modularized generated lib file #985

Closed
wants to merge 2 commits into from
Closed

Conversation

dansteren
Copy link
Contributor

@dansteren dansteren commented Apr 7, 2023

Reduced collisions with user-defined names by

  • moving most of our code into modules where it can't conflict with user-defined code
  • removing as many use statements as possible

Modules:

  • javascript
  • ref_cells
  • randomness
  • vm_value_conversion
  • ic_object
  • stable_b_tree_map

Note: now that everything is in it's own module, we can use use statements, just not at the global level. Also, methods like those on the ic_object no longer need to be prefixed.

Depends on demergent-labs/cdk_framework#64

@dansteren dansteren self-assigned this Apr 7, 2023
- Move javascript into module
- Move ref_cells into module
- Make module for random
- Scope ref cells module to crate
- Scope javascript module to crate
- Scope random module to crate
- Start moving everything to user_defined module
- All user-defined code in module
- Move vm_value_conversion into module
- Move relevant traits to vm_value_conversion module
- Move relevant traits to vm_value_conversion module
- Create module for ic object
- Move StableBTreeMap ref cells into module
- Remove extra use statements
- Add macro for creating StableBTreeMap types
- Make impls into a macro
- Move ic_object module generation
- Remove `_azle_ic` prefixes now that everything's in the ic obj module
  The reason for having all the _azle_ic prefixes was because we didn't
  want these to clash with user-defined functions. Now that all IC
  object functions are in a separate module, this isn't a problem.
- Bump CDK Framework
- Correct typo in ref-cell name
- Create helper methods for common ref_cells
- Make _azle_unwrap_boa_result the method `or_trap`
- Make utils module
- Abstract calling global js functions
- Fix service calls
@dansteren dansteren changed the title Reduced name collisions Modularized generated lib file Apr 10, 2023
@dansteren
Copy link
Contributor Author

This undertaking was abandoned for now in favor of prefixing everything. I hit a wall with undrestanding when to prefix things with crate:: and when not too. Particularly, there are a few types in the service_wrapper functions and in ic.reply that need to have the datatype that they are convert vm values into. Those values are sometimes builtins (e.g. i8, String, ()), sometimes from candid (e.g. candid::Reserved), and sometimes user-defined and should be prefixed with crate crate::SomeUserDefinedRecord.

This is further complicated by the fact that type parameters may also fall into those same categories. So sometimes we would generate Ok(crate::Ok) when really it should have been the global Ok.

Figuring out what each value is, where it comes from, and whether it needs to be module-namespace qualified get really complicated and we couldn't figure out a quick easy way to do this. Especially because sometimes a type does need to be qualified when it shows up in one module, but not when present in another.

For all these reasons we've decided to abandon using modules for now. Instead we will namespace qualify everything, rename all imported traits, prefix user-defined variables, and not have use statements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Prefix everything to prevent clashes with user-defined items
1 participant