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.
Change all the subprocess calls in boot.py to check whether they succeeded,
and set the script status appropriately.
In particular, when our unit tests fail, we need the script to exit
with a failure code so that we actually notice on Travis.
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.
BailErrorStrategy is supposed to throw an error that's different from
the ordinary recognition error, specifically so that it can be handled
differently by client code. This was not ported over from Java correctly.
Fix this by moving parseCancellation from ANTLRError to ANTLRException,
adding its RecognitionException argument, and throwing it from the
two handlers in BailErrorStrategy.
Also remove ANTLRException.cannotInvokeStartRule, which is unused.
(The Java runtime uses it when ParseTreePatternMatcher throws a generic
exception, but we don't have that.)