-
Notifications
You must be signed in to change notification settings - Fork 0
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
Name mangling #2
Draft
nailuj29
wants to merge
6
commits into
main
Choose a base branch
from
name-mangling
base: main
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
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bcd3710
Create 0000-name-mangling.md
nailuj29 6aaa7ce
Add PR link
nailuj29 bcd7260
Explain constant strings
nailuj29 d513861
Fix grammar error
nailuj29 7d5e1d5
Use numbers instead of bullets
nailuj29 af9d825
Fix the example mangling
nailuj29 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Name | ||
|
||
- Start Date: 2021-12-05 | ||
- RFC PR: [#2](https://github.com/boa-lang/rfcs/pull/2) | ||
- Implementation PR: (leave this empty) | ||
<!-- When when linking to the implementation PR, it should be done in the format of boa-lang/<repo>#<PR number> --> | ||
|
||
## Summary | ||
|
||
Defines how name mangling will work. | ||
|
||
## Basic example | ||
|
||
A method of the class `foo` with the signature `method(data: int) -> string` in the module `bar.baz` would be mangled to `boad2m3barm3bazc3fooi6methodp2t3i32t3i32r5string` | ||
## Motivation | ||
|
||
Most languages "mangle" names of symbols, in order to allow for things like namespacing, overloading, and class/struct methods. This RFC defines how Boa can mangle names | ||
|
||
## Detailed design | ||
|
||
For purposes of this RFC, "string" refers to a number n followed by n characters | ||
|
||
### Function name mangling | ||
A function name will be mangled according to the following scheme | ||
- Leader: always the constant string `boa` | ||
- Module: a mangled module name | ||
- Class (optional): the constant string `c` followed by a string representing the class name | ||
- Method type (Required if class exists): `i` (for instance methods) or `s` (for static methods) | ||
- Function name: a string representing the name of the function in Boa code | ||
- Parameters: the constant string `p` followed by Parameter Descriptors | ||
- Parameter Descriptors: the constant string `t` followed by a string representing the type name. If the type is a class, the class name is also mangled | ||
- Return type: the constant string `r` followed by the type name | ||
|
||
### Class name mangling: | ||
A class name will be mangled according to the following scheme: | ||
- Leader: always the constant string `boaclass` | ||
- Module: a mangled module name | ||
- Class name: the constant string `n` followed by a string representing the class name | ||
|
||
### Module name mangling: | ||
A module name is mangled according to the following scheme | ||
- Depth: the contstant string `d` followed by the modules "depth" (henceforth referred to as d) in the module tree. `std` has a depth of `1` and `std.math` has a depth of `2` | ||
- Module names: d repetitions of the following: the constant string `m` followed by a string representing the module name | ||
|
||
## Drawbacks | ||
|
||
- Generating a mangled name can be slightly costly, and can lead to confusing binaries. A possibility to disable mangling for certain symbols should be considered in the future | ||
|
||
## Alternatives | ||
|
||
No mangling: this dumps all functions into the same global namespace, and disallows duplicate named functions | ||
|
||
## Prior art | ||
Rust: https://rust-lang.github.io/rfcs/2603-rust-symbol-name-mangling-v0.html | ||
https://en.wikipedia.org/wiki/Name_mangling has many other examples |
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.
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.
that can be fixed by using things like underscores to act as a sort of whitespace
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.
Actually, if we choose to go that route, we could use whitespace as whitespace, but it may be a terrible idea
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.
I more meant that underscores can be a good replacement for actual spaces where spaces aren't allowed in names.
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.
Yeah, I was referring to the fact that symbols in the binary can have any name we want them to
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.
underscores def make it nicer, i agree with lyxal here
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.
Can you try to find some prior art that uses underscores? All I could find uses RLE.
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.
One other thing of note, humans likely wouldn't look at mangled names directly, they'd see it through something like https://github.com/luser/rustfilt