Navigation Menu

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

[SR-198] Please coalesce #file, #line, #function, etc #42820

Open
swift-ci opened this issue Dec 11, 2015 · 4 comments
Open

[SR-198] Please coalesce #file, #line, #function, etc #42820

swift-ci opened this issue Dec 11, 2015 · 4 comments
Labels
compiler The Swift compiler in itself feature A feature request or implementation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-198
Radar None
Original Reporter erica (JIRA User)
Type New Feature
Additional Detail from JIRA
Votes 2
Component/s
Labels New Feature
Assignee None
Priority Medium

md5: d7dc4b9f9982a5639872d1a119a2cac7

Issue Description:

A single SOURCE_LOC struct could do the job nicely.

cite: http://twitter.com/jckarter/status/675418743221043201

@swift-ci
Copy link
Collaborator Author

Comment by Andrew Bennett (JIRA)

public struct SourceLocation: CustomDebugStringConvertible {
 init(file: String = __FILE__, line: Int = __LINE__, column: Int = __COLUMN__, function: String = __FUNCTION__) {
     self.file = file
     self.line = line
     self.column = column
     self.function = function
 }

 public let file: String
 public let line: Int
 public let column: Int
 public let function: String

 public var debugDescription: String {
     return "\(function) @ \(file):\(line):\(column)"
 }
}

@swift-ci
Copy link
Collaborator Author

Comment by Andrew Bennett (JIRA)

Usage:

let location = SourceLocation()
print("\(location)")
print("\(location.file)")

@jckarter
Copy link
Member

Interesting, bnut (JIRA User). We could make this a library feature if the language rules for expanding __FILE__ as default values applied at depth, so that func foo(sourceLoc: SourceLocation = SourceLocation()) would instantiate SourceLocation()'s own defaulted arguments from the caller's source location.

@swift-ci
Copy link
Collaborator Author

Comment by Marc Knaup (JIRA)

Wouldn't that result in the binary containing ALL information (file, line, column and function) even if I am only interested in a single item (e.g. just the line number)? I don't think that such a behavior would be desired.

If that problem can be avoided then I'd like to also request two additional elements:

  • module: the containing Swift module's name

  • type: if you just have the function name you can't tell whether it's a global function, a specific type's function and which type's function. A single Swift file can contain multiple types. `type` could be the demangled name of the function's containing type. nil or empty if it's a global function.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added feature A feature request or implementation compiler The Swift compiler in itself and removed new feature labels Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself feature A feature request or implementation
Projects
None yet
Development

No branches or pull requests

3 participants