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

Tail Call Optimization attribute and modifier #103

Closed
wants to merge 5 commits into from

Conversation

griotspeak
Copy link

Add a @tailrec attribute and tail modifier allowing the compiler to emit errors when tail call optimization will not be used.

@kostiakoval
Copy link
Collaborator

Is there are See swift-evolution thread for where this features was discussed? Can you include it ?

"Swift-evolution thread: link to the discussion thread for that proposal" in template.md

@griotspeak
Copy link
Author

Thanks for pointing that out.

@LarsJK
Copy link

LarsJK commented Feb 12, 2016

Could you add newlines above and below the Alternatives considered section?

Also i'm not sure I understand the Proposed Solution.

It was my understanding that the tail modifier would be a modifier on the return statement where you do the tail call.

func sumRecursively(numbers: [Int], _ total: Int = 0) -> Int {
    guard let head = numbers.first else {
        return total
    }

    let tail = Array(numbers.dropFirst())

    tail return sumRecursively(tail, head + total)
}

Example taken from natashatherobot.com..

And i thought the @tailrec function attribute was only needed on a public API that wants to be externally tail-callable.

Can`t think of an example of that..

@lattner
Copy link
Collaborator

lattner commented Jun 19, 2016

@griotspeak It was great to meet you TJ! I'm sorry that this is not in scope for Swift 3, but there will certainly be another release...

@DougGregor
Copy link
Member

I'm closing out PRs for proposals that are out of scope for Swift 4 stage 1. When we open up the process to the point where this proposal can be in scope, please re-open the pull request.

@DougGregor DougGregor closed this Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants