Bridging from NSString to String in Swift 5 is a transcoding operation, so
it is expensive. Use String(describing:) instead of NSStringFromClass
to avoid this cost.
This switches from using the deprecated hashValue to hash(into:).
It also switches from using index to firstIndex (matching the change in
the standard library).
In the test template, we switch to using String directly instead of
String.characters.
This also switches all the Travis macOS tests to use the Xcode 10.2 / Mojave
image and changes the Linux Swift tests to download Swift 5.0.1.
This was brought over from the Java runtime in the initial port, but there
it was used as an array capacity hint. We're not using it in Swift so
this is useless.
This is a subclass that only exists to have a different constructor. There
is no need for this construction in Swift, since we have named parameters,
so we can remove the entire subclass and make ATNConfigSet final instead.
This was always clearly a possibility, looking at the body of the method.
The newly-enabled performance tests expose this bug (and I don't know how
we've gotten away with it otherwise for so long).
The Java runtime also returns null at this point.
The ATNState hashValue and == override are just using the stateNumber field, so
using the Int directly is equivalent, and saves bouncing through those methods.
This also seems to be a correctness issue with the new Hashable protocol changes in
Swift 4.2 (though I admit that I don't know why).
Remove PredictionMode.getStateToAltMap, which was just a stub onto
ATNConfigSet.getStateToAltMap and didn't seem to be doing anything useful.
Avoid adding to closureBusy before all ATNConfig properties are set.
This fixes#2372.
This is a port of c8805ab from the Java runtime. That was PR #1955.
Suppress "Optional" in the output when printing a value in the tests and
some debugging messages.
This is a change in behavior in Swift 4.2 (SE-0054) that implicitly
unwrapped optionals are now seen as plain Optional at runtime, and so
print doesn't implicitly unwrap them any more.
This was working before because calling hashValue on a boxed UInt32 gave
back the value itself. This is apparently no longer true.
It's not something we should have been doing anyway. We were needlessly
boxing the intermediate hash values, and passing them into a generic
method, just to unbox them again.
Fix this by creating a helper method, and calling that directly when
updating intermediate hash values.
This is three instances of flatMap changing to compactMap, and
one instance of UnsafeMutablePointer.deallocate(capacity:) changing
to UnsafeMutablePointer.deallocate().
Remove HashMap, and replace all uses of it with dictionaries. There's
no need for us to have a custom HashMap implementation (mirroring the Java
standard library) when Swift's standard dictionaries work just fine.
Fix Parser.bypassAltsAtnCache. This was declared as a Parser instance
variable, when in the Java runtime it is static (and therefore the cache
outlives the Parser instances). It was also being handled in a
thread-unsafe manner, because the cache was being read outside of the
mutex that was supposed to be protecting it. Fix both issues by moving
the cache and the mutex so that they are static to the Parser module and
rewriting getATNWithBypassAlts.
Remove Parser.decisionToDFAMutex. The Java code uses a synchronized block
on ParserATNSimulator.decisionToDFA, but the translation to Swift had put
a mutex in Parser. The decisionToDFA value is shared between Parser,
ParserATNSimulator, and the generated parser, so a mutex in
ParserATNSimulator isn't blocking all possible accesses, so it's useless.
Since this is only code for debugging anyway, just remove the useless mutex
and simplify getDFAStrings and dumpDFA.