Skip to content

Move the details of C99 identifier mangling out of ProjectModel #544

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

Merged

Conversation

abertelrud
Copy link
Contributor

Move the details of C99 identifier mangling out of ProjectModel and down into Basic. It looks as if at some point this was meant to be able to fail because it might remove all the characters and end up with an empty string, but now that it replaces characters it doesn't seem possible for it to end up with an empty string assuming it was given a non-empty string.

@aciidgh
Copy link
Contributor

aciidgh commented Jul 25, 2016

I wonder if this should be in utilities


/// Creates a string that contains only value C99 characters.
/// FIXME: We will likely want a better name...
public func mangledForC99() -> String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should probably be named to follow "C99ExtendedIdentifier" which is the technical standard it follows.

@ddunbar
Copy link
Contributor

ddunbar commented Jul 25, 2016

The previous version would throw if the result was an empty string, because it doesn't mangle the first character (IIRC)?

@abertelrud
Copy link
Contributor Author

@aciidb0mb3r Yes, Utilities would probably be better. I put it together with the shell escaping code, but Utilities is probably a better home for both of them.

@abertelrud
Copy link
Contributor Author

@ddunbar I addressed this in the commit message actually. It looked like the code had originally been written to potentially remove invalid characters, which could lead to an empty string even when the input wasn't empty. But at least in the sate of the code as I found it, that couldn't happen, since it always replaced unsupported scalars with _. Also, the error being thrown was project-model related and not about C99 identifier mangling in general. We can make it throw again, but I think the better thing to do is to either: a) precondition that the string isn't empty, or b) make sure the output string is never empty. If the point here is to take an arbitrary input string and make it valid C99, it doesn't seem that throwing is a good solution.

@abertelrud
Copy link
Contributor Author

And as I mentioned, I don't think it would actually ever throw, because it no longer makes the string shorter.

@ddunbar
Copy link
Contributor

ddunbar commented Jul 25, 2016

Ah, I see your point. I do remember it doing that at one point, it must have changed (for all I know it might have been me that changed it at some point).

@abertelrud
Copy link
Contributor Author

abertelrud commented Jul 25, 2016

@aciidb0mb3r @ddunbar Do you think this should be in Utilities instead? If so, shouldn't the shell-escaping code also move to Utilities?

@aciidgh
Copy link
Contributor

aciidgh commented Jul 26, 2016

I do think this should be in Utilities because this is not general enough for basic. I am not sure about shell escaping, It feels like a Basic thing but I wouldn't mind it being in utilities.

@ddunbar
Copy link
Contributor

ddunbar commented Jul 26, 2016

I agree Utilities seems better although I would feel much happier about that if we had a good name for Utilities.

@abertelrud
Copy link
Contributor Author

Ok. I will move this to Utilities and possibly move ShellEscaping in a separate PR.

@abertelrud
Copy link
Contributor Author

This got stalled, going to make the discussed changes, test, and merge this now. I am not going to rename Utilities at the moment, would be a different PR.

@abertelrud
Copy link
Contributor Author

@swift-ci please test

@abertelrud
Copy link
Contributor Author

(that test was requested to see if the CI incremental-build changes are working — I know this still needs to be rebased)

@abertelrud
Copy link
Contributor Author

@swift-ci please test linux

@abertelrud
Copy link
Contributor Author

@swift-ci please test linux platform

@abertelrud
Copy link
Contributor Author

@swift-ci please test

@abertelrud abertelrud force-pushed the factor-out-c99-identifier-mangling branch from 2da3d8f to f7fd7a1 Compare August 1, 2016 18:22
@abertelrud
Copy link
Contributor Author

@swift-ci please test

@abertelrud
Copy link
Contributor Author

I've moved it to Utilities now. I'll also add a performance test, but wanted to update the PR and kick off the correctness testing.

@abertelrud
Copy link
Contributor Author

Hmm, those failures suggest that not all the diffs got pushed to the PR (I specifically fixed the problem it's erroring out about). Investigating.

… down into `Utility`. It looks as if at some point this was meant to be able to fail because it might remove all the characters and end up with an empty string, but now that it replaces characters it doesn't seem possible for it to end up with an empty string assuming it was given a non-empty string. Instead we just define it to never generate an empty string if given a non-empty string. It will continue to be the caller's responsibility to check separately for non-empty strings, for which it is likely to want different errors anyway (e.g. reporting a missing module name as different from a malformed module name or whatever).
@abertelrud abertelrud force-pushed the factor-out-c99-identifier-mangling branch from f7fd7a1 to 24aaf6e Compare August 1, 2016 20:27
@abertelrud
Copy link
Contributor Author

Turns out I hadn't pushed the latest changes. Testing again.

@abertelrud
Copy link
Contributor Author

@swift-ci please test

@abertelrud
Copy link
Contributor Author

The Linux failure is puzzling, since apparently the build and the tests all succeeded. The failure seems to be in the automation that happens after that.

@abertelrud
Copy link
Contributor Author

I'll do some more local testing before merging.

@abertelrud abertelrud merged commit c9bdf38 into swiftlang:master Aug 2, 2016
@abertelrud abertelrud deleted the factor-out-c99-identifier-mangling branch August 2, 2016 18:50
XCTAssertEqual("1".mangledToC99ExtendedIdentifier(), "_")
XCTAssertEqual("1foo".mangledToC99ExtendedIdentifier(), "_foo")

// FIXME: There are lots more interesting test cases to add here.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finally a chance to use emoji in swiftpm source code 😀

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.

3 participants