-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mangle exported names using node IDs rather than types
Use node IDs rather than types to ensure exported names are unique. duplicate symbol. Closes #2074.
- Loading branch information
1 parent
fc7fc90
commit c83d61d
Showing
3 changed files
with
20 additions
and
10 deletions.
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
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
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,11 @@ | ||
fn main(args: [str]) { | ||
let one = fn@() -> uint { | ||
enum r { a }; | ||
ret a as uint; | ||
}; | ||
let two = fn@() -> uint { | ||
enum r { a }; | ||
ret a as uint; | ||
}; | ||
one(); two(); | ||
} |
c83d61d
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.
We talked about this on IRC and I believe this is not the right thing to do, for two reasons: 1) it changes our versioning scheme, which relies on attaching type hashes to symbols; 2) using node id's creates an unstable public interface.
c83d61d
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 will investigate how naming works for nested functions, and figure out how to do that for enums as well, rather than using node IDs to uniqify.
c83d61d
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, there's actually a third reason (I know, this is horrible! marijn did this at one point too though, don't feel bad about it) which is that the C++ name-mangling rules we use for encoding paths as ::-separated names breaks if you have a path component that starts with a plain number (like a node ID). Plus as brson says, it breaks other aspects of linkage.
Maybe we need a big comment in the mangler: "never incorporate node IDs here; I know it's tempting, but don't do it!" :)
c83d61d
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.
The general technology to use in the backend for this is "mangled types when sufficient, sequential name-generators when necessary" (effectively gensyms). But the sequential generators are unsatisfying, as they produce a different form of unstable interface. Hopefully they don't infect too many exported names. Ideally you want names to derive from the identity of the item, either the programmer-provided path or the type or some other mostly-stable concept of identity, so that when unrelated things change, its name doesn't change as a side effect.