Skip to content

Bridging: Bridge some basic classes like swift::SourceLoc directly #82665

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
merged 8 commits into from
Jul 16, 2025

Conversation

AnthonyLatsis
Copy link
Collaborator

No description provided.

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please test Windows

1 similar comment
@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please test Windows

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please test Windows

StringRef str() const {
return StringRef(Start.Value.getPointer(), ByteLength);
}
StringRef str() const { return StringRef(Start.Pointer, ByteLength); }
Copy link
Member

Choose a reason for hiding this comment

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

What an evil method 😬 All the usages should use SourceManager::extractText() instead. (Not in this PR)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

😅

Copy link
Member

@rintaro rintaro left a comment

Choose a reason for hiding this comment

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

Just a small comment. Otherwise, Looks good to me.

l = l.advanced(by: pound.trimmedLength.utf8Length)
l = l.advanced(by: pound.trailingTriviaLength.utf8Length)
l = l.advanced(by: node.openingQuote.leadingTriviaLength.utf8Length)
l = l.advanced(by: Int32(pound.trimmedLength.utf8Length))
Copy link
Member

Choose a reason for hiding this comment

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

CInt is more robust. But I think it's reasonable to change the C++ side to accept size_t instead of int

Copy link
Collaborator Author

@AnthonyLatsis AnthonyLatsis Jul 15, 2025

Choose a reason for hiding this comment

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

There are a couple of places where we advance by a negative offset. I did try switching to intptr_t, but that required some additional static casts that I chose to reserved for a subsequent PR, in calls that rely on unsigned -> int wrapping, as in loc.getAdvancedLoc(-presumedLoc.getColumn() + 1).

Copy link
Contributor

@hamishknight hamishknight Jul 15, 2025

Choose a reason for hiding this comment

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

You could also use ssize_t which is both signed and imports as Int

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I tried intptr_t because

typedef intptr_t SwiftInt;
typedef uintptr_t SwiftUInt;

I’m tempted to move these to Basic/SwiftBridging.h and use SwiftInt for consistency.

@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test

@AnthonyLatsis
Copy link
Collaborator Author

Thank you, Rintaro!

@AnthonyLatsis AnthonyLatsis enabled auto-merge July 15, 2025 20:37
@AnthonyLatsis
Copy link
Collaborator Author

@swift-ci please smoke test Windows

@AnthonyLatsis AnthonyLatsis merged commit 90f9fce into main Jul 16, 2025
3 checks passed
@AnthonyLatsis AnthonyLatsis deleted the jepa4 branch July 16, 2025 07:27
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