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

[Swift] Migrate Swift runtime to Swift 5. #2686

Merged
merged 4 commits into from Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions .travis.yml
Expand Up @@ -74,42 +74,42 @@ matrix:
- clang-3.7
- os: osx
compiler: clang
osx_image: xcode10.1
osx_image: xcode10.2
env:
- TARGET=cpp
- GROUP=LEXER
stage: extended-test
- os: osx
compiler: clang
osx_image: xcode10.1
osx_image: xcode10.2
env:
- TARGET=cpp
- GROUP=PARSER
stage: extended-test
- os: osx
compiler: clang
osx_image: xcode10.1
osx_image: xcode10.2
env:
- TARGET=cpp
- GROUP=RECURSION
stage: extended-test
- os: osx
compiler: clang
osx_image: xcode10.1
osx_image: xcode10.2
env:
- TARGET=swift
- GROUP=LEXER
stage: main-test
- os: osx
compiler: clang
osx_image: xcode10.1
osx_image: xcode10.2
env:
- TARGET=swift
- GROUP=PARSER
stage: main-test
- os: osx
compiler: clang
osx_image: xcode10.1
osx_image: xcode10.2
env:
- TARGET=swift
- GROUP=RECURSION
Expand All @@ -122,19 +122,19 @@ matrix:
- GROUP=ALL
stage: extended-test
- os: osx
osx_image: xcode10.1
osx_image: xcode10.2
env:
- TARGET=dotnet
- GROUP=LEXER
stage: extended-test
- os: osx
osx_image: xcode10.1
osx_image: xcode10.2
env:
- TARGET=dotnet
- GROUP=PARSER
stage: extended-test
- os: osx
osx_image: xcode10.1
osx_image: xcode10.2
env:
- TARGET=dotnet
- GROUP=RECURSION
Expand Down
2 changes: 1 addition & 1 deletion .travis/run-tests-swift.sh
Expand Up @@ -6,7 +6,7 @@ set -euo pipefail
# here since environment variables doesn't pass
# across scripts
if [ $TRAVIS_OS_NAME == "linux" ]; then
export SWIFT_VERSION=swift-4.2.1
export SWIFT_VERSION=swift-5.0.1
export SWIFT_HOME=$(pwd)/swift/$SWIFT_VERSION-RELEASE-ubuntu16.04/usr/bin/
export PATH=$SWIFT_HOME:$PATH

Expand Down
1 change: 1 addition & 0 deletions contributors.txt
Expand Up @@ -233,3 +233,4 @@ YYYY/MM/DD, github id, Full name, email
2019/09/28, lmy269, Mingyang Liu, lmy040758@gmail.com
2019/10/31, a-square, Alexei Averchenko, lex.aver@gmail.com
2019/11/11, foxeverl, Liu Xinfeng, liuxf1986[at]gmail[dot]com
2019/11/18, mlilback, Mark Lilback, mark@lilback.com
Expand Up @@ -133,7 +133,7 @@ open func emit() -> Token {
private func handleAcceptPositionForIdentifier() -> Bool {
let tokenText = getText()
var identifierLength = 0
while ((identifierLength \< tokenText.characters.count) && isIdentifierChar(tokenText[tokenText.characters.index(tokenText.startIndex, offsetBy: identifierLength)])) {
while ((identifierLength \< tokenText.count) && isIdentifierChar(tokenText[tokenText.index(tokenText.startIndex, offsetBy: identifierLength)])) {
identifierLength += 1
}

Expand All @@ -147,8 +147,8 @@ private func handleAcceptPositionForIdentifier() -> Bool {
}

private func handleAcceptPositionForKeyword(_ keyword:String) -> Bool {
if getInputStream()!.index() > _tokenStartCharIndex + keyword.characters.count {
let offset = keyword.characters.count - 1
if getInputStream()!.index() > _tokenStartCharIndex + keyword.count {
let offset = keyword.count - 1
(getInterpreter() as! PositionAdjustingLexerATNSimulator).resetAcceptPosition(getInputStream()!, _tokenStartCharIndex + offset, _tokenStartLine, _tokenStartCharPositionInLine + offset)
return true
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/Swift/Sources/Antlr4/DiagnosticErrorListener.swift
Expand Up @@ -101,7 +101,7 @@ public class DiagnosticErrorListener: BaseErrorListener {
let decision: Int = dfa.decision
let ruleIndex: Int = dfa.atnStartState.ruleIndex!

var ruleNames: [String] = recognizer.getRuleNames()
let ruleNames: [String] = recognizer.getRuleNames()
if ruleIndex < 0 || ruleIndex >= ruleNames.count {
return String(decision)
}
Expand Down
2 changes: 1 addition & 1 deletion runtime/Swift/Sources/Antlr4/Parser.swift
Expand Up @@ -941,7 +941,7 @@ open class Parser: Recognizer<ParserATNSimulator> {

public func getRuleInvocationStack(_ p: RuleContext?) -> [String] {
var p = p
var ruleNames = getRuleNames()
let ruleNames = getRuleNames()
var stack = [String]()
while let pWrap = p {
// compute what follows who invoked us
Expand Down
2 changes: 2 additions & 0 deletions runtime/Swift/Sources/Antlr4/UnbufferedCharStream.swift
Expand Up @@ -343,6 +343,8 @@ fileprivate struct UInt8StreamIterator: IteratorProtocol {
return nil
case .opening, .open, .reading:
break
@unknown default:
fatalError()
}

let count = stream.read(&buffer, maxLength: buffer.count)
Expand Down
6 changes: 2 additions & 4 deletions runtime/Swift/Sources/Antlr4/VocabularySingle.swift
Expand Up @@ -155,11 +155,9 @@ public class Vocabulary: Hashable {
return String(tokenType)
}

public var hashValue: Int {
return Unmanaged.passUnretained(self).toOpaque().hashValue
// return unsafeAddress(of: self).hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(ObjectIdentifier(self))
}

}

public func ==(lhs: Vocabulary, rhs: Vocabulary) -> Bool {
Expand Down
24 changes: 10 additions & 14 deletions runtime/Swift/Sources/Antlr4/atn/ATNConfig.swift
Expand Up @@ -126,20 +126,11 @@ public class ATNConfig: Hashable, CustomStringConvertible {
}
}

///
/// An ATN configuration is equal to another if both have
/// the same state, they predict the same alternative, and
/// syntactic/semantic contexts are the same.
///

public var hashValue: Int {
var hashCode = MurmurHash.initialize(7)
hashCode = MurmurHash.update(hashCode, state.stateNumber)
hashCode = MurmurHash.update(hashCode, alt)
hashCode = MurmurHash.update(hashCode, context)
hashCode = MurmurHash.update(hashCode, semanticContext)
return MurmurHash.finish(hashCode, 4)

public func hash(into hasher: inout Hasher) {
hasher.combine(state.stateNumber)
hasher.combine(alt)
hasher.combine(context)
hasher.combine(semanticContext)
}

public var description: String {
Expand All @@ -166,6 +157,11 @@ public class ATNConfig: Hashable, CustomStringConvertible {
}
}

///
/// An ATN configuration is equal to another if both have
/// the same state, they predict the same alternative, and
/// syntactic/semantic contexts are the same.
///
public func ==(lhs: ATNConfig, rhs: ATNConfig) -> Bool {

if lhs === rhs {
Expand Down
12 changes: 6 additions & 6 deletions runtime/Swift/Sources/Antlr4/atn/ATNConfigSet.swift
Expand Up @@ -203,16 +203,16 @@ public final class ATNConfigSet: Hashable, CustomStringConvertible {
return false
}

public var hashValue: Int {
public func hash(into hasher: inout Hasher) {
if isReadonly() {
if cachedHashCode == -1 {
cachedHashCode = configsHashValue//configs.hashValue ;
cachedHashCode = configsHashValue
}

return cachedHashCode
hasher.combine(cachedHashCode)
}
else {
hasher.combine(configsHashValue)
}

return configsHashValue // configs.hashValue;
}

private var configsHashValue: Int {
Expand Down
4 changes: 2 additions & 2 deletions runtime/Swift/Sources/Antlr4/atn/ATNDeserializer.swift
Expand Up @@ -78,8 +78,8 @@ public class ATNDeserializer {
///
internal func isFeatureSupported(_ feature: UUID, _ actualUuid: UUID) -> Bool {
let supported = ATNDeserializer.SUPPORTED_UUIDS
guard let featureIndex = supported.index(of: feature),
let actualIndex = supported.index(of: actualUuid) else {
guard let featureIndex = supported.firstIndex(of: feature),
let actualIndex = supported.firstIndex(of: actualUuid) else {
return false
}
return actualIndex >= featureIndex
Expand Down
5 changes: 2 additions & 3 deletions runtime/Swift/Sources/Antlr4/atn/ATNState.swift
Expand Up @@ -123,11 +123,10 @@ public class ATNState: Hashable, CustomStringConvertible {
public internal(set) final var nextTokenWithinRule: IntervalSet?


public var hashValue: Int {
return stateNumber
public func hash(into hasher: inout Hasher) {
hasher.combine(stateNumber)
}


public func isNonGreedyExitState() -> Bool {
return false
}
Expand Down
22 changes: 7 additions & 15 deletions runtime/Swift/Sources/Antlr4/atn/LexerATNConfig.swift
Expand Up @@ -72,22 +72,14 @@ public class LexerATNConfig: ATNConfig {
return passedThroughNonGreedyDecision
}

override
/*public func hashCode() -> Int {

}*/
public var hashValue: Int {
var hashCode = MurmurHash.initialize(7)
hashCode = MurmurHash.update(hashCode, state.stateNumber)
hashCode = MurmurHash.update(hashCode, alt)
hashCode = MurmurHash.update(hashCode, context)
hashCode = MurmurHash.update(hashCode, semanticContext)
hashCode = MurmurHash.update(hashCode, passedThroughNonGreedyDecision ? 1 : 0)
hashCode = MurmurHash.update(hashCode, lexerActionExecutor)
return MurmurHash.finish(hashCode, 6)

public override func hash(into hasher: inout Hasher) {
hasher.combine(state.stateNumber)
hasher.combine(alt)
hasher.combine(context)
hasher.combine(semanticContext)
hasher.combine(passedThroughNonGreedyDecision)
hasher.combine(lexerActionExecutor)
}

}

//useless
Expand Down
2 changes: 1 addition & 1 deletion runtime/Swift/Sources/Antlr4/atn/LexerAction.swift
Expand Up @@ -56,7 +56,7 @@ public class LexerAction: Hashable {
fatalError(#function + " must be overridden")
}

public var hashValue: Int {
public func hash(into hasher: inout Hasher) {
fatalError(#function + " must be overridden")
}

Expand Down
6 changes: 2 additions & 4 deletions runtime/Swift/Sources/Antlr4/atn/LexerActionExecutor.swift
Expand Up @@ -176,11 +176,9 @@ public class LexerActionExecutor: Hashable {
}


public var hashValue: Int {
return self.hashCode
public func hash(into hasher: inout Hasher) {
hasher.combine(hashCode)
}


}

public func ==(lhs: LexerActionExecutor, rhs: LexerActionExecutor) -> Bool {
Expand Down
9 changes: 3 additions & 6 deletions runtime/Swift/Sources/Antlr4/atn/LexerChannelAction.swift
Expand Up @@ -63,12 +63,9 @@ public final class LexerChannelAction: LexerAction, CustomStringConvertible {
}


override
public var hashValue: Int {
var hash = MurmurHash.initialize()
hash = MurmurHash.update(hash, getActionType().rawValue)
hash = MurmurHash.update(hash, channel)
return MurmurHash.finish(hash, 2)
public override func hash(into hasher: inout Hasher) {
hasher.combine(getActionType())
hasher.combine(channel)
}

public var description: String {
Expand Down
13 changes: 3 additions & 10 deletions runtime/Swift/Sources/Antlr4/atn/LexerCustomAction.swift
Expand Up @@ -92,24 +92,17 @@ public final class LexerCustomAction: LexerAction {
try lexer.action(nil, ruleIndex, actionIndex)
}

override
public var hashValue: Int {
var hash = MurmurHash.initialize()
hash = MurmurHash.update(hash, getActionType().rawValue)
hash = MurmurHash.update(hash, ruleIndex)
hash = MurmurHash.update(hash, actionIndex)
return MurmurHash.finish(hash, 3)
public override func hash(into hasher: inout Hasher) {
hasher.combine(ruleIndex)
hasher.combine(actionIndex)
}

}

public func ==(lhs: LexerCustomAction, rhs: LexerCustomAction) -> Bool {

if lhs === rhs {
return true
}


return lhs.ruleIndex == rhs.ruleIndex
&& lhs.actionIndex == rhs.actionIndex
}
13 changes: 3 additions & 10 deletions runtime/Swift/Sources/Antlr4/atn/LexerIndexedCustomAction.swift
Expand Up @@ -96,24 +96,17 @@ public final class LexerIndexedCustomAction: LexerAction {
}


public override var hashValue: Int {
var hash = MurmurHash.initialize()
hash = MurmurHash.update(hash, offset)
hash = MurmurHash.update(hash, action)
return MurmurHash.finish(hash, 2)
public override func hash(into hasher: inout Hasher) {
hasher.combine(offset)
hasher.combine(action)
}


}

public func ==(lhs: LexerIndexedCustomAction, rhs: LexerIndexedCustomAction) -> Bool {

if lhs === rhs {
return true
}


return lhs.offset == rhs.offset
&& lhs.action == rhs.action

}
13 changes: 4 additions & 9 deletions runtime/Swift/Sources/Antlr4/atn/LexerModeAction.swift
Expand Up @@ -62,25 +62,20 @@ public final class LexerModeAction: LexerAction, CustomStringConvertible {
public func execute(_ lexer: Lexer) {
lexer.mode(mode)
}
override
public var hashValue: Int {
var hash = MurmurHash.initialize()
hash = MurmurHash.update(hash, getActionType().rawValue)
hash = MurmurHash.update(hash, mode)
return MurmurHash.finish(hash, 2)

public override func hash(into hasher: inout Hasher) {
hasher.combine(mode)
}

public var description: String {
return "mode(\(mode))"
}
}

public func ==(lhs: LexerModeAction, rhs: LexerModeAction) -> Bool {

if lhs === rhs {
return true
}


return lhs.mode == rhs.mode

}